Dear all: I have some questions about kthread: 1. can we change kthread priority through user mode program? 2. I found some functions that may be helpful. sched_getscheduler sched_setscheduler When I use them in user mode, the return value of sched_setscheduler is fail. there is a thread talking about this, http://www.spinics.net/lists/linux-rt-users/msg06588.html What makes me confuse is "these 2 functions is used in user mode or kernel mode?" -- Regards, -- Regards, -- Regards,
Hi... On Sun, Jul 10, 2011 at is 17:27, loody <miloody@gmail.com> wrote:
Dear all: I have some questions about kthread: 1. can we change kthread priority through user mode program?
Theoritically you can, but only if the priority not fixed and/or you have required capability to do so
2. I found some functions that may be helpful. sched_getscheduler sched_setscheduler
When I use them in user mode, the return value of sched_setscheduler is fail.
did you do that as root? anything blocking you doing that withing SELinux or AppArmor policy?
there is a thread talking about this, http://www.spinics.net/lists/linux-rt-users/msg06588.html What makes me confuse is "these 2 functions is used in user mode or kernel mode?"
AFAIK they are user mode libc functions... -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
hi: 2011/7/11 Mulyadi Santosa <mulyadi.santosa@gmail.com>:
Hi...
On Sun, Jul 10, 2011 at is 17:27, loody <miloody@gmail.com> wrote:
Dear all: I have some questions about kthread: 1. can we change kthread priority through user mode program?
Theoritically you can, but only if the priority not fixed and/or you have required capability to do so
2. I found some functions that may be helpful. sched_getscheduler sched_setscheduler
When I use them in user mode, the return value of sched_setscheduler is fail.
did you do that as root? anything blocking you doing that withing SELinux or AppArmor policy? I execute it as root. what is "SELinux or AppArmor policy"?
there is a thread talking about this, http://www.spinics.net/lists/linux-rt-users/msg06588.html What makes me confuse is "these 2 functions is used in user mode or kernel mode?"
AFAIK they are user mode libc functions...
I found there are the same export_symbols in kernel. I use them to dynamically change the priority. It works but I found something interesting: 1. if thread use schedule algorithm of SCHED_NORMAL, it cannot change the priority. 2. can we set the priority to any number less than (MAX_USER_RT_PRIO-1)? ( I tried to set the priority as 99, but it fail) 3. can we get the name of thread from task_struct or pid? (I use "cat /proc/338/status", I can see the name of thread. But I look around the task_struct, I cannot find any name information in it.) Thanks for your kind help,
Hi Milody, On Sun, Jul 10, 2011 at 8:55 PM, loody <miloody@gmail.com> wrote: > hi: > > 2011/7/11 Mulyadi Santosa <mulyadi.santosa@gmail.com>: >> Hi... >> ...snip... >> AFAIK they are user mode libc functions... > I found there are the same export_symbols in kernel. > I use them to dynamically change the priority. > It works but I found something interesting: > 1. if thread use schedule algorithm of SCHED_NORMAL, it cannot change > the priority. > 2. can we set the priority to any number less than (MAX_USER_RT_PRIO-1)? > ( I tried to set the priority as 99, but it fail) You need to change the scheduling algorithim to be SCHED_FIFO or SCHED_RR in order to use the real-time priorities. > 3. can we get the name of thread from task_struct or pid? > (I use "cat /proc/338/status", I can see the name of thread. But I > look around the task_struct, I cannot find any name information in > it.) You can use the comm field from the task struct. This can be set using the prctl API and passing in PR_SET_NAME. You can see the task name by doing something like ps -T -o pid,ppid,user,time,comm Normally, ps shows the args column. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
hi: 2011/7/11 Dave Hylands <dhylands@gmail.com>: > Hi Milody, > > On Sun, Jul 10, 2011 at 8:55 PM, loody <miloody@gmail.com> wrote: >> hi: >> >> 2011/7/11 Mulyadi Santosa <mulyadi.santosa@gmail.com>: >>> Hi... >>> > > ...snip... > >>> AFAIK they are user mode libc functions... >> I found there are the same export_symbols in kernel. >> I use them to dynamically change the priority. >> It works but I found something interesting: >> 1. if thread use schedule algorithm of SCHED_NORMAL, it cannot change >> the priority. >> 2. can we set the priority to any number less than (MAX_USER_RT_PRIO-1)? >> ( I tried to set the priority as 99, but it fail) > > You need to change the scheduling algorithim to be SCHED_FIFO or > SCHED_RR in order to use the real-time priorities. I saw kernel restrict the algorithm as SCHED_FIFO and SCHED_RR to change the priority. What are the differences between rt_priority, prio, static_prio and normal_prio? sched_setscheduler seems only change rt_priority. normal_prio is MAX_RT_PRIO-1 - t_priority prio will be min(normal_prio, task_top_pi_waiter) what is the real priority that kthread runs after calling sched_setscheduler ? > >> 3. can we get the name of thread from task_struct or pid? >> (I use "cat /proc/338/status", I can see the name of thread. But I >> look around the task_struct, I cannot find any name information in >> it.) > > You can use the comm field from the task struct. This can be set using > the prctl API and passing in PR_SET_NAME. You can see the task name by > doing something like > > ps -T -o pid,ppid,user,time,comm > > Normally, ps shows the args column. > > -- > Dave Hylands > Shuswap, BC, Canada > http://www.davehylands.com > -- Regards,
Hi: 2011/7/11 loody <miloody@gmail.com>: > hi: > > > 2011/7/11 Dave Hylands <dhylands@gmail.com>: >> Hi Milody, >> >> On Sun, Jul 10, 2011 at 8:55 PM, loody <miloody@gmail.com> wrote: >>> hi: >>> >>> 2011/7/11 Mulyadi Santosa <mulyadi.santosa@gmail.com>: >>>> Hi... >>>> >> >> ...snip... >> >>>> AFAIK they are user mode libc functions... >>> I found there are the same export_symbols in kernel. >>> I use them to dynamically change the priority. >>> It works but I found something interesting: >>> 1. if thread use schedule algorithm of SCHED_NORMAL, it cannot change >>> the priority. >>> 2. can we set the priority to any number less than (MAX_USER_RT_PRIO-1)? >>> ( I tried to set the priority as 99, but it fail) >> >> You need to change the scheduling algorithim to be SCHED_FIFO or >> SCHED_RR in order to use the real-time priorities. > I saw kernel restrict the algorithm as SCHED_FIFO and SCHED_RR to > change the priority. > What are the differences between rt_priority, prio, static_prio and normal_prio? > sched_setscheduler seems only change rt_priority. > > normal_prio is MAX_RT_PRIO-1 - t_priority > prio will be min(normal_prio, task_top_pi_waiter) > > what is the real priority that kthread runs after calling sched_setscheduler ? > > >> >>> 3. can we get the name of thread from task_struct or pid? >>> (I use "cat /proc/338/status", I can see the name of thread. But I >>> look around the task_struct, I cannot find any name information in >>> it.) >> >> You can use the comm field from the task struct. This can be set using >> the prctl API and passing in PR_SET_NAME. You can see the task name by >> doing something like >> >> ps -T -o pid,ppid,user,time,comm >> >> Normally, ps shows the args column. >> >> -- Since there are below schedule algorithms in kernel, SCHED_NORMAL SCHED_FIFO SCHED_RR SCHED_BATCH when and how they circular around? or each of them has a fix cpu time slice to go through? BR, cckuo
On Mon, Jul 11, 2011 at 12:45 PM, loody <miloody@gmail.com> wrote:
> Hi:
>
> 2011/7/11 loody <miloody@gmail.com>:
>> hi:
>>
>>
>> 2011/7/11 Dave Hylands <dhylands@gmail.com>:
>>> Hi Milody,
>>>
>>> On Sun, Jul 10, 2011 at 8:55 PM, loody <miloody@gmail.com> wrote:
>>>> hi:
>>>>
>>>> 2011/7/11 Mulyadi Santosa <mulyadi.santosa@gmail.com>:
>>>>> Hi...
>>>>>
>>>
>>> ...snip...
>>>
>>>>> AFAIK they are user mode libc functions...
>>>> I found there are the same export_symbols in kernel.
>>>> I use them to dynamically change the priority.
>>>> It works but I found something interesting:
>>>> 1. if thread use schedule algorithm of SCHED_NORMAL, it cannot change
>>>> the priority.
>>>> 2. can we set the priority to any number less than
>>>> (MAX_USER_RT_PRIO-1)?
>>>> ( I tried to set the priority as 99, but it fail)
>>>
>>> You need to change the scheduling algorithim to be SCHED_FIFO or
>>> SCHED_RR in order to use the real-time priorities.
>> I saw kernel restrict the algorithm as SCHED_FIFO and SCHED_RR to
>> change the priority.
>> What are the differences between rt_priority, prio, static_prio and
>> normal_prio?
>> sched_setscheduler seems only change rt_priority.
>>
>> normal_prio is MAX_RT_PRIO-1 - t_priority
>> prio will be min(normal_prio, task_top_pi_waiter)
>>
>> what is the real priority that kthread runs after calling
>> sched_setscheduler ?
>>
>>
>>>
>>>> 3. can we get the name of thread from task_struct or pid?
>>>> (I use "cat /proc/338/status", I can see the name of thread. But I
>>>> look around the task_struct, I cannot find any name information in
>>>> it.)
>>>
>>> You can use the comm field from the task struct. This can be set using
>>> the prctl API and passing in PR_SET_NAME. You can see the task name by
>>> doing something like
>>>
>>> ps -T -o pid,ppid,user,time,comm
>>>
>>> Normally, ps shows the args column.
>>>
>>> --
> Since there are below schedule algorithms in kernel,
> SCHED_NORMAL
> SCHED_FIFO
> SCHED_RR
> SCHED_BATCH
> when and how they circular around?
> or each of them has a fix cpu time slice to go through?
The base scheduler code(kernel/sched.c) iterates over each scheduler
class(SCHED_NORMAL,SCHED_FIFO,SCHED_RR) in order of priority.The
highest priority scheduler class that has a runnable process wins.
below is the code.
/*
* Pick up the highest-prio task:
*/
static inline struct task_struct *
pick_next_task(struct rq *rq)
{
const struct sched_class *class;
struct task_struct *p;
/*
* Optimization: we know that if all tasks are in
* the fair class we can call that function directly:
*/
if (likely(rq->nr_running == rq->cfs.nr_running)) {
p = fair_sched_class.pick_next_task(rq);
if (likely(p))
return p;
}
class = sched_class_highest;
for ( ; ; ) {
p = class->pick_next_task(rq);
if (p)
return p;
/*
* Will never be NULL as the idle class always
* returns a non-NULL p:
*/
class = class->next;
}
}
> BR,
> cckuo
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
participants (4)
-
Dave Hylands -
loody -
Mulyadi Santosa -
santhosh kumars