busy looping in kernel, time question
    Dave Martindale 
    dave at onfcanim.UUCP
       
    Fri Apr 18 03:32:11 AEST 1986
    
    
  
In article <234 at Shasta.ARPA> alex at lancelot writes:
>
>	Assume I want to busy loop in the kernel for 100 milliseconds, how
>many times (approx) should I go around a loop which increments an int?
>
Do you *really* want to lock up the processor for that long?  sleep/wakeup
would make much better use of the processor.
But if your really want a busy loop, you realize that this depends on
what processor you are running on, which you didn't mention?  A Cray-2
and an 8088 can both run UNIX, but there is a fair difference in the number
of instructions they execute in 100 ms.
Tell you what.  Why not write a program like this:
	main(argc, argv)
	char **argv;
	{
		long i, limit, atol();
		limit = atol(argv[1]);
		for (i = 0; i < limit; i++)
			;
	}
Then run it until you find a value of the argument that gives an execution
time of 10 seconds.  Divide that number by 100, and you will know how many
times to go around a loop to get 100 milliseconds pretty accurately.
Seriously, wouldn't it have made more sense to just write the test program
and have your answer in 3 minutes, rather than posting an article that
several thousand people would read, particularly since they can't answer it
from the information given?
USENET is a wonderful resource for obtaining hard-to-find information.
I hate to see its effectiveness damaged by people using it as a crutch.
	Dave Martindale
    
    
More information about the Comp.unix.wizards
mailing list