[Freemint-list] Broken udelay() for m68000

Vincent Rivière vincent.riviere at freesbee.fr
Sun Oct 15 12:01:38 MSD 2017


On 14/10/2017 at 05:20, Miro Kropáček wrote:
> # if defined (__M68020__)
 > ...
> # else /* M68000 */
>         __delay(usecs); /* Sigh */
> # endif

I see in sys/mint/arch\delay.h that udelay() is implemented differently on 
ColdFire: in that case, it is a library call. On 680x0 CPU, it is an inline 
function. I suppose that the library call is avoided on 680x0 to avoid 
adding extra delay due to function call overhead.

As udelay() is for microsecond delays, which are very short, I understand 
that it uses dirty CPU loops instead of timers. But as long as loops are 
properly calibrated, that should be OK.

But as MiKRO pointed out, using #ifdef inside inline functions is a bad 
thing. A kernel module (or any user program) compiled for 68000 should work 
equally well on 68060.

So there are 2 possibles scenarios:

1) Make udelay() a library call for 680x0, like ColdFire. But that will add 
extra delays, which may be unwanted. Assuming that the library function is 
*dynamically* routed to an internal kernel function, and not a static 
library implementation. I have some doubts on the last point.

2) Inside inline udelay(), replace #ifdef by runtime CPU tests. I'm unsure 
how to test that from kernel modules.

Anyway, good catch. The current code can't be reliable if 68000 kernel 
modules are used on higher CPU.

-- 
Vincent Rivière


More information about the Freemint-list mailing list