Delay functions

Timers are useful when the timeout period is relatively long; in all other use cases where a shorter duration is desired, delay functions are used instead. While working with hardware such as storage devices (namely flash memory and EEPROM), it's is very crucial for the device driver to wait until the device finishes the hardware operations such as writing and erasing, which in most cases is in the range of a few microseconds to milliseconds. Going ahead and executing other instructions without waiting for the hardware to complete such operations would result in unpredictable read/write operations and data corruption. In cases such as these, delay functions come in handy. The kernel provides such short delays by means of the ndelay(), udelay(), and mdelay() routines and macro, which receive arguments in nanoseconds, microseconds, and milliseconds, respectively.

The following functions can be found in include/linux/delay.h:

static inline void ndelay(unsigned long x)
{
        udelay(DIV_ROUND_UP(x, 1000));
}

These functions can be found in arch/ia64/kernel/time.c:

static void
ia64_itc_udelay (unsigned long usecs)
{
        unsigned long start = ia64_get_itc();
        unsigned long end = start + usecs*local_cpu_data->cyc_per_usec;

        while (time_before(ia64_get_itc(), end))
                cpu_relax();
}

void (*ia64_udelay)(unsigned long usecs) = &ia64_itc_udelay;

void
udelay (unsigned long usecs)
{
        (*ia64_udelay)(usecs);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.29.89