Yes, one can use 'nice' to modify the priority of a process, which indirectly set a timeslice value for all the real-time round-robin threads belong to that process. The shortfall is each real-time round-robin threads of a process can not have its own timeslice. It would be nice to have extention to the POSIX thread priority scheduling APIs to control timeslice of individual threads.
I did a quick look at 2.6 kernel source linux/kernel/sched.c:
/*
* BASE_TIMESLICE scales user-nice values [ -20 ... 19 ]
* to time slice values.
*
* The higher a thread's priority, the bigger timeslices
* it gets during one round of execution. But even the lowest
* priority thread gets MIN_TIMESLICE worth of execution time.
*
* task_timeslice() is the interface that is used by the scheduler.
*/
#define BASE_TIMESLICE(p) (MIN_TIMESLICE + \
((MAX_TIMESLICE - MIN_TIMESLICE) * \
(MAX_PRIO-1 - (p)->static_prio) / (MAX_USER_PRIO-1)))
static unsigned int task_timeslice(task_t *p)
{
return BASE_TIMESLICE(p);
}
In function "scheduler_tick", I found the timeslice of the rond-robin thread is re-evaluated as follow:
/*
* RR tasks need a special form of timeslice management.
* FIFO tasks have no timeslices.
*/
if ((p->policy == SCHED_RR) && !--p->time_slice) {
p->time_slice = task_timeslice(p);
p->first_time_slice = 0;
set_tsk_need_resched(p);
/* put it at the end of the queue: */
dequeue_task(p, rq->active);
enqueue_task(p, rq->active);
}
seem like somehow if we can access to the thread static_priority, perhaps we can control the timeslice of individual round-robin thread.
|