On Sun, 11 Oct 1998, Glynn Clements wrote:
>> For a 130msec sleeping I coded ,as follow.
>> ----------------------------------------------------
>> inline void DelayExecution(void ){
>> int jif_delay = 13;
>> unsigned long j = jiffies + jif_delay;
>> current->timeout = j;
>> current->state = TASK_INTERRUPTIBLE;
>> schedule();
>> current->timeout = 0; /* reset the timeout */
^^^^^^^^^^^^^^^^^^^^
Not needed.
>> }
>> ------------------------------------------------------
>> But, what i really wanted is a code for 125 msecs or other msecs i
>> want.
>> So I thougt the defined HZ has to be changed as a 1000 (as you know,
>> 100 is a default).
>
>If you change the value of HZ, bad things may happen.
If bad things will happen you' ll found a bug in the kernel.
Alpha #defines HZ = 1024 and bad things don' t happen.
Sure a too high value could stall the machine (bad thing ;-) and a too low
one could decrease too much the scheduling frequency causing some strange
(not bad) things.
In general HZ depends on the hardware you are running on.
The more you set HZ high the more you' ll waste time in the scheduling
code.
>> to implement a exact delay time.
>
>You can't implement an exact delay time. You'll have to live with
>whatever delay you get, or switch to using a real-time OS.
Or use udelay() or use the rdtsc to measure how much cycles are passed.
Something like:
timeout = rdtsc() + 2000cycles;
while (rdtsc() < timout);
This would delay exactly 2000 cycles. This way you can get the precision
of the frequency of the CPU.
The differenced between udelay()/rdtsc() and the scheduling() method is
that the firsts will hang the machine for the delay time.
Andrea Arcangeli