[PLUG] Linux process scheduling

Larry Brigman larry.brigman at gmail.com
Thu Feb 16 02:12:51 UTC 2006


On 2/15/06, Terry Griffin <griffint at pobox.com> wrote:
> Larry Brigman wrote:
> > On 2/15/06, Terry Griffin <griffint at pobox.com> wrote:
> >> Larry Brigman inquired:
>
> Hmm. What kernel version is this?

2.6.15-1.1830_FC4smp

>
> For regular (SCHED_OTHER) processes the time slice is directly
> related to the nice level. Nicer processes get shorter time slices
> before they must surrender the CPU to other processes. No
> SCHED_OTHER process may be preempted by another SCHED_OTHER process.
> However a SCHED_RR or SCHED_FIFO process will preempt SCHED_OTHER
> process before their time slice is done. So a SCHED_RR process
> should wake up from a sleep with fairly good accuracy.
>
> I don't know of any way to change the default time slice (or the
> default nice level) without modifying the kernel. Be warned that
> tweaking the scheduler leads to unintended consequences more often
> than not. See MAX_TIMESLICE and MIN_TIMESLICE in sched.c. The default
> nice level is zero. I don't think there's a macro for it.
>
> A preemptive kernel might help. Without a preemptive kernel a
> SCHED_RR process can't preempt a SCHED_OTHER process while the
> SCHED_OTHER process is executing in kernel space. It must wait
> until it returns to user space. With a preemptive kernel the
> SCHED_RR process would be able to preempt the SCHED_OTHER process
> while it was still in kernel space.
>

I did find the HZ value in the .config file.  It is set to 250.  This
explains why I am jumping
between ~8ms and almost none.  It is the interaction of the program
with nanosleep.
nanosleep with values >1ms (or is that 2) will not return for at least
the default time slice
if they are running sched_other which is the default scheduler.
(Please correct me if
I am wrong).

Using select() with no file descriptor and a timeout value returns 1ms
too soon or 1ms too
late.  So select timeout seems to have a different timing method.

It still does not explain why when I changed to SCHED_RR or SCHED_FIFO I didn't
get better results. Maybe nanosleep does not change it's behavior when
the scheduler
is changed.

Does anyone know if the posix high resolution timers have been added
to the kernel and
which version?  I would be happy just to get down to < 10 microsecond
process wakeup
accuracy.



More information about the PLUG mailing list