reliable way to set a kernel thread priority

reliable way to set a kernel thread priority

Post by ask » Sat, 24 Sep 2005 23:25:16


I have researched for this for a while but not found a good answer for
it. Basic I create a kernel thread and I want set priority for it.

Some example I browse through is to change the current->rt_priority or
current->prio, directly. I found that is probably not righ, I saw
kernel crashes.

I look one example in kernel exmaple, function defined in sched.c

migration_thread(). This thread calls setscheduler() to set the
priority. In fact a bad idea, as setscheduler() itself calls
copy_from_user(), which expect some memory from user space.
migration_thread() does not even check the return of setscheduler() ,
so it does not really set the priority.

I cam mimic the implementation of setscheduler() but take out
copy_from_user(), it's really a pain in....

Why there is no such utility in the kernel? Point it to if you know
any. Also how migration_thread() is supposed to work in the kernel?
 
 
 

reliable way to set a kernel thread priority

Post by Kasper Dup » Sun, 25 Sep 2005 16:22:25


What kernel version?

--
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.

 
 
 

reliable way to set a kernel thread priority

Post by ask » Thu, 29 Sep 2005 06:45:59

2.4.20
 
 
 

reliable way to set a kernel thread priority

Post by Josef Moel » Thu, 29 Sep 2005 15:43:52


Nonono, that's absolutely the wrong answer.
The answer is ... is ... 43 oh sh*t I meant 41 ... or was it ...?

Please include some context when replying.
--
Josef Mlers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
 
 
 

reliable way to set a kernel thread priority

Post by Kasper Dup » Thu, 29 Sep 2005 15:53:38


I couldn't find any migration_thread in 2.4.20.

--
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.
 
 
 

reliable way to set a kernel thread priority

Post by ask » Fri, 07 Oct 2005 06:23:42

uname -a
Linux smurf7 2.4.21-32.0.1.ELsmp #1 SMP Tue May 17 17:52:23 EDT 2005
i686 i686

cat /usr/src/linux-2.4/kernel/sched.c | grep migration

task_t *migration_thread;
struct list_head migration_queue;
* (such as the load balancing or the thread migration code), lock
#define migration_thread(cpu) (cpu_int(cpu)->migration_thread)
#define migration_queue(cpu) (&cpu_int(cpu)->migration_queue)
* We wake up one of the migration threads (it
if (rq->cpu[0].migration_thread)

wake_up_process(rq->cpu[0].migration_thread);
* imbalance. Since we are the migration thread, try to
INIT_LIST_HEAD(&rq1->cpu[cpu2_idx].migration_queue);
* This is how migration works:
* 1) we queue a migration_req_t structure in the source CPU's
* runqueue and wake up that CPU's migration thread.
* 3) migration thread wakes up (implicitly it forces the migrated
* 4) it gets the migration request and checks whether the migrated
* 5) if it's in the wrong runqueue then the migration thread removes
* 6) migration thread up()s the semaphore.
* 7) we wake up and the migration is done.
} migration_req_t;
migration_req_t req;
list_add(&req.list, migration_queue(cpu));
wake_up_process(migration_thread(cpu));
} migration_startup_t;
* migration_task - this is a highprio system thread that performs
* thread migration by 'pulling' threads into the target runqueue.
static int migration_task(void * data)
migration_startup_t *startup = data;
sprintf(current->comm, "migration/%d", cpu);
migration_thread(cpu) = current;
migration_req_t *req;
head = migration_queue(cpu);
req = list_entry(head->next, migration_req_t, list);
* migration_call - callback that gets triggered when a CPU is added.
* Here we can start up the necessary migration thread for the new CPU.
void migration_call(void *hcpu)
migration_startup_t startup;
printk("Starting migration thread for cpu %li\n", (long)hcpu);
kernel_thread(migration_task, &startup, CLONE_KERNEL);
while (!migration_thread(cpu))
__init int migration_init(void)
migration_call((void *)(long)cpu);
INIT_LIST_HEAD(migration_queue(i));