6bc Subj : Re: Solaris real-time thread capabilities To : comp.unix.solaris,comp.programming.threads From : Logan Shaw Date : Sat Sep 03 2005 04:37 am capnwhit@yahoo.com wrote: > ======== > QUESTION > ======== > How can I get 10 millisecond timing reliably on a 2 CPU UltraSPARC-II > 450MHz system? > (H) Using spin loop > ------------------------------------- > In desperation I have also tried using a spin loop using "gethrtime()" > in order to _NOT_ call nanosleep, as shown conceptually below: > > ---------- > t2 = gethrtime(); > while(t2 < target_time) > { > t1 = gethrtime(); > t2 = gethrtime(); > > diff = t2 - t1; > [...cut...] > } > ---------- > > In the above loop, the average difference between t1 and t2 is about > 1000 nanoseconds (this is good), but once in a while the difference > between t1 and t2 is 300,000,000 nanoseconds (this is bad)!!! If I had to guess (and a guess is exactly what it'd be), I would say that what's going on here is that your code is running as a user process, and every now and then there is a kernel thread that is a higher priority that runs and excludes your thread from the processor. If I recall correctly, the range of priorities for userspace threads is a subset of the range of priorities for kernel threads, so it is possible to have kernel threads that have a priority higher than your userspace thread, no matter how high you make its priority, and I believe that even applies if you make your thread a realtime thread. I've tried to find my Solaris 8 Internals book to confirm that, but I don't see it, and I don't have time to undertake a major excavation on my desk right now... ;-) - Logan . 0