* One Interrupted Threads per Interrupt line?
@ 2011-06-04 11:48 Monica Puig-Pey
2011-06-04 12:03 ` I/O operations priority in RTOS Monica Puig-Pey
0 siblings, 1 reply; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-04 11:48 UTC (permalink / raw)
To: linux-rt-users, linux-kernel
Hi,
I'm using Ubuntu 10.04 with the 2.6.31-11-rt patch installed. I'm
developing a PCI device driver using hardware interrupts.
I read in the “Internals of the RT Patch” document
(http://www.kernel.org/doc/ols/2007/ols2007v2-pages-161-172.pdf ) that
when a device driver requests an IRQ, a thread is created to service
this interrupt line (Threaded interrupts). Only ONE thread can be
created per interrupt line, so shared interrupts are still handled by a
single thread.
My driver requests IRQ 16, which is shared with others handlers. Typing
on the shell $ps -eo pid,pri,rtprio,cmd I can see my driver requesting
irq 16 and with 50 RTPRIO. At the same time I can see the others drivers
requesting IRQ 16 with different real time priorities than mine( 80, 85,
50). Does this mean that there are more than ONE Threaded Interrupts for
IRQ 16? or it's just the thread priority when running each handler for
IRQ 16?
Finally, how could I change the 50 RT PRIO for my handler pci_9111?
Here you have the shell:
PID PRI RTPRIO CMD
658 120 80 [irq/16-uhci_hcd]
3852 125 85 [irq/16-HDA Inte]
4303 90 50 [irq/16-radeon@p]
5863 90 50 [irq/16-pci_9111]
5865 19 - ps -eo pid,pri,rtprio,cmd
Thank you very much,
Mónica
^ permalink raw reply [flat|nested] 14+ messages in thread
* I/O operations priority in RTOS
2011-06-04 11:48 One Interrupted Threads per Interrupt line? Monica Puig-Pey
@ 2011-06-04 12:03 ` Monica Puig-Pey
2011-06-04 12:30 ` kernel threads in drivers using the RT patch Monica Puig-Pey
0 siblings, 1 reply; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-04 12:03 UTC (permalink / raw)
To: linux-rt-users, linux-kernel
Hello,
I'm studying how to develop drivers in a real time OS and how do they
work. I'm using Ubuntu 10.04 with the 2.6.31-11-rt patch installed.
I would like to know the priority when executing open(), read(), write()
and close() operations.
In my example the thread which is using the driver runs with 10 RTPRIO,
but I don't know what happens in kernel context with the priority when
running the I/O operations.
Thank you for your help, I don't know where to learn about this.
Mónica
^ permalink raw reply [flat|nested] 14+ messages in thread
* kernel threads in drivers using the RT patch
2011-06-04 12:03 ` I/O operations priority in RTOS Monica Puig-Pey
@ 2011-06-04 12:30 ` Monica Puig-Pey
2011-06-06 11:47 ` Changing Kernel thread priorities Monica Puig-Pey
0 siblings, 1 reply; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-04 12:30 UTC (permalink / raw)
To: linux-rt-users, linux-kernel
Hello,
I'm studying how to develop drivers in a real time OS and how do they
work. I'm using Ubuntu 10.04 with the 2.6.31-11-rt patch installed.
I'm trying to run a kernel thread from my driver (kernel context). I
create the kthread in the module_init, I change its real time priority
and then make it run .
Code shown below:
thread_handler=*(struct task_struct *)kthread_create(my_tasklet_handler,
(void*)&datos,"thread_handler");
if (IS_ERR(&thread_handler)){
return PTR_ERR(&thread_handler);
printk(KERN_WARNING "<pci> (init_module) Error creating Thread
handler\n");
}
params->sched_priority=20;
result = sched_setscheduler(&thread_handler, SCHED_FIFO, params);
result=wake_up_process(&thread_handler);
Params is global struct sched_param * and struct thread_handler a
global task_struct.
I stop the Kthread in the module_exit using
res=kthread_stop(&thread_handler);
The kthread "thread_handler" has a while (1) loop and it is stopped in a
semaphore, waiting for the interrupt handler. When it wakes up each time
it calls kthread_should_stop() and depending on that break out of the
loop or run.
My problem is, when trying to establish the rtprio kthread, the whole
computer get blocked and I only can restart it. If I delete this part,
then kthread runs, and works well. With the ps command I can see it has
a 24 NON real time priority. Then the problem come when uninstalling my
module with rmmod. In the kthread_stop function, everything gets blocked.
Could someone tell what am I doing wrong? Or just give me some help
about kernel threads in the RT Patch?
Thanks a lot
Mónica
^ permalink raw reply [flat|nested] 14+ messages in thread
* Changing Kernel thread priorities
2011-06-04 12:30 ` kernel threads in drivers using the RT patch Monica Puig-Pey
@ 2011-06-06 11:47 ` Monica Puig-Pey
2011-06-06 11:54 ` Rolando Martins
2011-06-06 18:20 ` Armin Steinhoff
0 siblings, 2 replies; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-06 11:47 UTC (permalink / raw)
To: linux-rt-users, linux-kernel
I am writing a driver which has one kernel thread associated with it.
I want to change the priority of this thread, so that I can specify the
order in which it is scheduled following an interrupt.
I'm using:
sched_setscheduler(struct task_struct *, int, struct sched_param *);
but it doesn't work. I tried to change the priority from the
init_module, and also from the Kernel Thread, but there is no way.
Kernel version is 2.6.31-11-rt
What do I call to change a kernel thread priority?
Thanks you very much
Mónica
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-06 11:47 ` Changing Kernel thread priorities Monica Puig-Pey
@ 2011-06-06 11:54 ` Rolando Martins
2011-06-06 11:58 ` Monica Puig-Pey
2011-06-06 18:20 ` Armin Steinhoff
1 sibling, 1 reply; 14+ messages in thread
From: Rolando Martins @ 2011-06-06 11:54 UTC (permalink / raw)
To: Monica Puig-Pey; +Cc: linux-rt-users, linux-kernel
Hi,
I use the following:
PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
print $1; }' | xargs echo)
for i in $PIDs
do
ret=$(chrt -f -p 99 $i)
done
This will change the kernel thread associated with an irq handler to
RT FIFO prio 99.
Just change the script to your specific interrupt.
Hope it helps,
Rolando
On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey <puigpeym@unican.es> wrote:
> I am writing a driver which has one kernel thread associated with it.
> I want to change the priority of this thread, so that I can specify the
> order in which it is scheduled following an interrupt.
> I'm using:
>
> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>
> but it doesn't work. I tried to change the priority from the init_module,
> and also from the Kernel Thread, but there is no way.
>
> Kernel version is 2.6.31-11-rt
>
> What do I call to change a kernel thread priority?
>
> Thanks you very much
>
> Mónica
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-06 11:54 ` Rolando Martins
@ 2011-06-06 11:58 ` Monica Puig-Pey
2011-06-06 16:49 ` Mark Hounschell
0 siblings, 1 reply; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-06 11:58 UTC (permalink / raw)
To: Rolando Martins; +Cc: linux-rt-users, linux-kernel
El 06/06/11 13:54, Rolando Martins escribió:
> Hi,
> I use the following:
>
> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
> print $1; }' | xargs echo)
> for i in $PIDs
> do
> ret=$(chrt -f -p 99 $i)
> done
>
> This will change the kernel thread associated with an irq handler to
> RT FIFO prio 99.
> Just change the script to your specific interrupt.
>
> Hope it helps,
> Rolando
>
> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey<puigpeym@unican.es> wrote:
>> I am writing a driver which has one kernel thread associated with it.
>> I want to change the priority of this thread, so that I can specify the
>> order in which it is scheduled following an interrupt.
>> I'm using:
>>
>> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>>
>> but it doesn't work. I tried to change the priority from the init_module,
>> and also from the Kernel Thread, but there is no way.
>>
>> Kernel version is 2.6.31-11-rt
>>
>> What do I call to change a kernel thread priority?
>>
>> Thanks you very much
>>
>> Mónica
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
I need to change the priority from inside the driver, when creating the
kernel thread.
Your script is useful but it is done in user context,
Any other help please?
Mónica
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-06 11:58 ` Monica Puig-Pey
@ 2011-06-06 16:49 ` Mark Hounschell
2011-06-07 8:40 ` Monica Puig-Pey
0 siblings, 1 reply; 14+ messages in thread
From: Mark Hounschell @ 2011-06-06 16:49 UTC (permalink / raw)
To: Monica Puig-Pey; +Cc: Rolando Martins, linux-rt-users, linux-kernel
On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
> El 06/06/11 13:54, Rolando Martins escribió:
>> Hi,
>> I use the following:
>>
>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>> print $1; }' | xargs echo)
>> for i in $PIDs
>> do
>> ret=$(chrt -f -p 99 $i)
>> done
>>
>> This will change the kernel thread associated with an irq handler to
>> RT FIFO prio 99.
>> Just change the script to your specific interrupt.
>>
>> Hope it helps,
>> Rolando
>>
>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey<puigpeym@unican.es>
>> wrote:
>>> I am writing a driver which has one kernel thread associated with it.
>>> I want to change the priority of this thread, so that I can specify the
>>> order in which it is scheduled following an interrupt.
>>> I'm using:
>>>
>>> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>>>
>>> but it doesn't work. I tried to change the priority from the
>>> init_module,
>>> and also from the Kernel Thread, but there is no way.
>>>
>>> Kernel version is 2.6.31-11-rt
>>>
>>> What do I call to change a kernel thread priority?
>>>
>>> Thanks you very much
>>>
>>> Mónica
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe
>>> linux-rt-users" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>
> I need to change the priority from inside the driver, when creating the
> kernel thread.
> Your script is useful but it is done in user context,
> Any other help please?
What I do is record the PID of the thread in the driver, then create an
IOCTL for your driver that user land can call that either returns the
PID so you can do it in user land, or cause the IOCTL code to do it in
the driver.
The same can be done with the affinity of the IRQ if you record the IRQ
number.
Mark
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-06 11:47 ` Changing Kernel thread priorities Monica Puig-Pey
2011-06-06 11:54 ` Rolando Martins
@ 2011-06-06 18:20 ` Armin Steinhoff
1 sibling, 0 replies; 14+ messages in thread
From: Armin Steinhoff @ 2011-06-06 18:20 UTC (permalink / raw)
To: Monica Puig-Pey; +Cc: linux-rt-users, linux-kernel
Monica Puig-Pey wrote:
> I am writing a driver which has one kernel thread associated with it.
> I want to change the priority of this thread, so that I can specify
> the order in which it is scheduled following an interrupt.
> I'm using:
>
> sched_setscheduler(struct task_struct *, int, struct sched_param *);
> -> sys_sched_setscheduler
http://ftp.au.debian.org/linux-mandocs/2.6.0-test7-full/sys_sched_setscheduler.html
Hope this helps ..
--Armin
>
> but it doesn't work. I tried to change the priority from the
> init_module, and also from the Kernel Thread, but there is no way.
>
> Kernel version is 2.6.31-11-rt
>
> What do I call to change a kernel thread priority?
>
> Thanks you very much
>
> Mónica
>
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-rt-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-06 16:49 ` Mark Hounschell
@ 2011-06-07 8:40 ` Monica Puig-Pey
2011-06-07 9:14 ` Mark Hounschell
0 siblings, 1 reply; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-07 8:40 UTC (permalink / raw)
To: markh; +Cc: Rolando Martins, linux-rt-users, linux-kernel
El 06/06/11 18:49, Mark Hounschell escribió:
> On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
>> El 06/06/11 13:54, Rolando Martins escribió:
>>> Hi,
>>> I use the following:
>>>
>>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>>> print $1; }' | xargs echo)
>>> for i in $PIDs
>>> do
>>> ret=$(chrt -f -p 99 $i)
>>> done
>>>
>>> This will change the kernel thread associated with an irq handler to
>>> RT FIFO prio 99.
>>> Just change the script to your specific interrupt.
>>>
>>> Hope it helps,
>>> Rolando
>>>
>>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey<puigpeym@unican.es>
>>> wrote:
>>>> I am writing a driver which has one kernel thread associated with it.
>>>> I want to change the priority of this thread, so that I can specify the
>>>> order in which it is scheduled following an interrupt.
>>>> I'm using:
>>>>
>>>> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>>>>
>>>> but it doesn't work. I tried to change the priority from the
>>>> init_module,
>>>> and also from the Kernel Thread, but there is no way.
>>>>
>>>> Kernel version is 2.6.31-11-rt
>>>>
>>>> What do I call to change a kernel thread priority?
>>>>
>>>> Thanks you very much
>>>>
>>>> Mónica
>>>>
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe
>>>> linux-rt-users" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>
>>
>> I need to change the priority from inside the driver, when creating the
>> kernel thread.
>> Your script is useful but it is done in user context,
>> Any other help please?
>
> What I do is record the PID of the thread in the driver, then create an
> IOCTL for your driver that user land can call that either returns the
> PID so you can do it in user land, or cause the IOCTL code to do it in
> the driver.
>
> The same can be done with the affinity of the IRQ if you record the IRQ
> number.
>
> Mark
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-rt-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
But I don't have de PID of my Kthread, I only have the task_struc * that
gives me the function:
struct task_struct *kthread_create(int (*threadfn)(void *data),
void *data,
const char namefmt[], ...)
How could I get the PID, and which function should I use in the IOCTL
(kernel context) for changing its priority?
Thank you so much for your help
Mónica
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-07 8:40 ` Monica Puig-Pey
@ 2011-06-07 9:14 ` Mark Hounschell
2011-06-07 9:46 ` Mark Hounschell
0 siblings, 1 reply; 14+ messages in thread
From: Mark Hounschell @ 2011-06-07 9:14 UTC (permalink / raw)
To: Monica Puig-Pey; +Cc: markh, Rolando Martins, linux-rt-users, linux-kernel
On 06/07/2011 04:40 AM, Monica Puig-Pey wrote:
> El 06/06/11 18:49, Mark Hounschell escribió:
>> On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
>>> El 06/06/11 13:54, Rolando Martins escribió:
>>>> Hi,
>>>> I use the following:
>>>>
>>>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>>>> print $1; }' | xargs echo)
>>>> for i in $PIDs
>>>> do
>>>> ret=$(chrt -f -p 99 $i)
>>>> done
>>>>
>>>> This will change the kernel thread associated with an irq handler to
>>>> RT FIFO prio 99.
>>>> Just change the script to your specific interrupt.
>>>>
>>>> Hope it helps,
>>>> Rolando
>>>>
>>>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey<puigpeym@unican.es>
>>>> wrote:
>>>>> I am writing a driver which has one kernel thread associated with it.
>>>>> I want to change the priority of this thread, so that I can specify the
>>>>> order in which it is scheduled following an interrupt.
>>>>> I'm using:
>>>>>
>>>>> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>>>>>
>>>>> but it doesn't work. I tried to change the priority from the
>>>>> init_module,
>>>>> and also from the Kernel Thread, but there is no way.
>>>>>
>>>>> Kernel version is 2.6.31-11-rt
>>>>>
>>>>> What do I call to change a kernel thread priority?
>>>>>
>>>>> Thanks you very much
>>>>>
>>>>> Mónica
>>>>>
>>>>> --
>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>> linux-rt-users" in
>>>>> the body of a message to majordomo@vger.kernel.org
>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>
>>>
>>> I need to change the priority from inside the driver, when creating the
>>> kernel thread.
>>> Your script is useful but it is done in user context,
>>> Any other help please?
>>
>> What I do is record the PID of the thread in the driver, then create an
>> IOCTL for your driver that user land can call that either returns the
>> PID so you can do it in user land, or cause the IOCTL code to do it in
>> the driver.
>>
>> The same can be done with the affinity of the IRQ if you record the IRQ
>> number.
>>
>> Mark
>> --
>> To unsubscribe from this list: send the line "unsubscribe
>> linux-rt-users" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> But I don't have de PID of my Kthread, I only have the task_struc * that
> gives me the function:
>
> struct task_struct *kthread_create(int (*threadfn)(void *data),
> void *data,
> const char namefmt[], ...)
>
> How could I get the PID, and which function should I use in the IOCTL
> (kernel context) for changing its priority?
>
The PID can be obtained from within the interrupt handler its self via
current->pid.
Obviously an interrupt has to occur first but after one interrupt you have it.
Actually I had forgot how I handled this. Where I change the RT priority
and cpu affinity is in what used to be called the Bottom Half and the IOCTL
referred to above simply tells the BH to do it and with what values.
Regards
Mark
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-07 9:14 ` Mark Hounschell
@ 2011-06-07 9:46 ` Mark Hounschell
2011-06-07 18:34 ` Monica Puig-Pey
0 siblings, 1 reply; 14+ messages in thread
From: Mark Hounschell @ 2011-06-07 9:46 UTC (permalink / raw)
To: Monica Puig-Pey
Cc: dmarkh, markh, Rolando Martins, linux-rt-users, linux-kernel
On 06/07/2011 05:14 AM, Mark Hounschell wrote:
> On 06/07/2011 04:40 AM, Monica Puig-Pey wrote:
>> El 06/06/11 18:49, Mark Hounschell escribió:
>>> On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
>>>> El 06/06/11 13:54, Rolando Martins escribió:
>>>>> Hi,
>>>>> I use the following:
>>>>>
>>>>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>>>>> print $1; }' | xargs echo)
>>>>> for i in $PIDs
>>>>> do
>>>>> ret=$(chrt -f -p 99 $i)
>>>>> done
>>>>>
>>>>> This will change the kernel thread associated with an irq handler to
>>>>> RT FIFO prio 99.
>>>>> Just change the script to your specific interrupt.
>>>>>
>>>>> Hope it helps,
>>>>> Rolando
>>>>>
>>>>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey<puigpeym@unican.es>
>>>>> wrote:
>>>>>> I am writing a driver which has one kernel thread associated with it.
>>>>>> I want to change the priority of this thread, so that I can specify the
>>>>>> order in which it is scheduled following an interrupt.
>>>>>> I'm using:
>>>>>>
>>>>>> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>>>>>>
>>>>>> but it doesn't work. I tried to change the priority from the
>>>>>> init_module,
>>>>>> and also from the Kernel Thread, but there is no way.
>>>>>>
>>>>>> Kernel version is 2.6.31-11-rt
>>>>>>
>>>>>> What do I call to change a kernel thread priority?
>>>>>>
>>>>>> Thanks you very much
>>>>>>
>>>>>> Mónica
>>>>>>
>>>>>> --
>>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>>> linux-rt-users" in
>>>>>> the body of a message to majordomo@vger.kernel.org
>>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>>
>>>>
>>>> I need to change the priority from inside the driver, when creating the
>>>> kernel thread.
>>>> Your script is useful but it is done in user context,
>>>> Any other help please?
>>>
>>> What I do is record the PID of the thread in the driver, then create an
>>> IOCTL for your driver that user land can call that either returns the
>>> PID so you can do it in user land, or cause the IOCTL code to do it in
>>> the driver.
>>>
>>> The same can be done with the affinity of the IRQ if you record the IRQ
>>> number.
>>>
>>> Mark
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe
>>> linux-rt-users" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>> But I don't have de PID of my Kthread, I only have the task_struc * that
>> gives me the function:
>>
>> struct task_struct *kthread_create(int (*threadfn)(void *data),
>> void *data,
>> const char namefmt[], ...)
>>
>> How could I get the PID, and which function should I use in the IOCTL
>> (kernel context) for changing its priority?
>>
>
> The PID can be obtained from within the interrupt handler its self via
> current->pid.
> Obviously an interrupt has to occur first but after one interrupt you have it.
>
> Actually I had forgot how I handled this. Where I change the RT priority
> and cpu affinity is in what used to be called the Bottom Half and the IOCTL
> referred to above simply tells the BH to do it and with what values.
>
In interrupt handler code snippet:
struct task_struct *TSK;
struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
TSK = current;
Code snippet from BH:
if (((rtom_rtprio != 0) &&
(rtom_rtprio != PARAM.sched_priority)) ||
(my_rtom_rtprio[BOARD] != rtom_rtprio)) {
PARAM.sched_priority = rtom_rtprio;
my_rtom_rtprio[COUNT] = rtom_rtprio;
sched_setscheduler(TSK, SCHED_FIFO, &PARAM);
set_cpus_allowed(TSK, rtom_devices[BOARD].irq_cpu_mask);
rtom_devices[BOARD].irq_task_pid = TSK->pid;
}
rtom_rtprio and irq_cpu_mask are set by userland via an IOCTL. An interrupt
must occur for this to happen and my BOARD never shares IRQs.
Mark
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-07 9:46 ` Mark Hounschell
@ 2011-06-07 18:34 ` Monica Puig-Pey
2011-06-07 18:55 ` Mark Hounschell
0 siblings, 1 reply; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-07 18:34 UTC (permalink / raw)
To: dmarkh; +Cc: markh, Rolando Martins, linux-rt-users, linux-kernel
El 07/06/11 11:46, Mark Hounschell escribió:
> On 06/07/2011 05:14 AM, Mark Hounschell wrote:
>> On 06/07/2011 04:40 AM, Monica Puig-Pey wrote:
>>> El 06/06/11 18:49, Mark Hounschell escribió:
>>>> On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
>>>>> El 06/06/11 13:54, Rolando Martins escribió:
>>>>>> Hi,
>>>>>> I use the following:
>>>>>>
>>>>>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>>>>>> print $1; }' | xargs echo)
>>>>>> for i in $PIDs
>>>>>> do
>>>>>> ret=$(chrt -f -p 99 $i)
>>>>>> done
>>>>>>
>>>>>> This will change the kernel thread associated with an irq handler to
>>>>>> RT FIFO prio 99.
>>>>>> Just change the script to your specific interrupt.
>>>>>>
>>>>>> Hope it helps,
>>>>>> Rolando
>>>>>>
>>>>>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey
>>>>>> wrote:
>>>>>>> I am writing a driver which has one kernel thread associated with
>>>>>>> it.
>>>>>>> I want to change the priority of this thread, so that I can
>>>>>>> specify the
>>>>>>> order in which it is scheduled following an interrupt.
>>>>>>> I'm using:
>>>>>>>
>>>>>>> sched_setscheduler(struct task_struct *, int, struct sched_param *);
>>>>>>>
>>>>>>> but it doesn't work. I tried to change the priority from the
>>>>>>> init_module,
>>>>>>> and also from the Kernel Thread, but there is no way.
>>>>>>>
>>>>>>> Kernel version is 2.6.31-11-rt
>>>>>>>
>>>>>>> What do I call to change a kernel thread priority?
>>>>>>>
>>>>>>> Thanks you very much
>>>>>>>
>>>>>>> Mónica
>>>>>>>
>>>>>>> --
>>>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>>>> linux-rt-users" in
>>>>>>> the body of a message to majordomo@vger.kernel.org
>>>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>>>
>>>>>
>>>>> I need to change the priority from inside the driver, when creating
>>>>> the
>>>>> kernel thread.
>>>>> Your script is useful but it is done in user context,
>>>>> Any other help please?
>>>>
>>>> What I do is record the PID of the thread in the driver, then create an
>>>> IOCTL for your driver that user land can call that either returns the
>>>> PID so you can do it in user land, or cause the IOCTL code to do it in
>>>> the driver.
>>>>
>>>> The same can be done with the affinity of the IRQ if you record the IRQ
>>>> number.
>>>>
>>>> Mark
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe
>>>> linux-rt-users" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>> But I don't have de PID of my Kthread, I only have the task_struc * that
>>> gives me the function:
>>>
>>> struct task_struct *kthread_create(int (*threadfn)(void *data),
>>> void *data,
>>> const char namefmt[], ...)
>>>
>>> How could I get the PID, and which function should I use in the IOCTL
>>> (kernel context) for changing its priority?
>>>
>>
>> The PID can be obtained from within the interrupt handler its self via
>> current->pid.
>> Obviously an interrupt has to occur first but after one interrupt you
>> have it.
>>
>> Actually I had forgot how I handled this. Where I change the RT priority
>> and cpu affinity is in what used to be called the Bottom Half and the
>> IOCTL
>> referred to above simply tells the BH to do it and with what values.
>>
>
> In interrupt handler code snippet:
>
> struct task_struct *TSK;
> struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
>
> TSK = current;
>
> Code snippet from BH:
>
> if (((rtom_rtprio != 0) &&
> (rtom_rtprio != PARAM.sched_priority)) ||
> (my_rtom_rtprio[BOARD] != rtom_rtprio)) {
>
> PARAM.sched_priority = rtom_rtprio;
> my_rtom_rtprio[COUNT] = rtom_rtprio;
> sched_setscheduler(TSK, SCHED_FIFO, &PARAM);
>
> set_cpus_allowed(TSK, rtom_devices[BOARD].irq_cpu_mask);
> rtom_devices[BOARD].irq_task_pid = TSK->pid;
> }
>
> rtom_rtprio and irq_cpu_mask are set by userland via an IOCTL. An
> interrupt must occur for this to happen and my BOARD never shares IRQs.
>
> Mark
>
Thanks, your idea seems to be very useful to me. I was doing it very
similar, but I didn't use the "current" variable to know the task_struct *.
I have tried your suggestion on an easy example, but it didn't work.
Insmod returns through the kernel
[11334.895499] kthread: Unknown symbol sched_setscheduler
Code shown below:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/ioport.h>
#include <linux/wait.h>
#include <linux/kthread.h>
#include <asm/io.h>
#include <linux/sched.h>
struct task_struct *ts;
int thread(void *data)
{
struct task_struct *TSK;
struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
TSK = current;
PARAM.sched_priority = 50;
sched_setscheduler(TSK, SCHED_FIFO, &PARAM); // <-- unknown symbol??
while(1){
printk("Hi I am kernel thread!\n");
msleep(100);
if (kthread_should_stop())
break;
}
return 0;
}
int init_module(void)
{
printk(KERN_INFO "init_module() called\n");
ts=kthread_run(thread,NULL,"kthread");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "cleanup_module() called\n");
kthread_stop(ts);
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-07 18:34 ` Monica Puig-Pey
@ 2011-06-07 18:55 ` Mark Hounschell
2011-06-10 10:12 ` Monica Puig-Pey
0 siblings, 1 reply; 14+ messages in thread
From: Mark Hounschell @ 2011-06-07 18:55 UTC (permalink / raw)
To: Monica Puig-Pey; +Cc: dmarkh, Rolando Martins, linux-rt-users, linux-kernel
On 06/07/2011 02:34 PM, Monica Puig-Pey wrote:
> El 07/06/11 11:46, Mark Hounschell escribió:
>> On 06/07/2011 05:14 AM, Mark Hounschell wrote:
>>> On 06/07/2011 04:40 AM, Monica Puig-Pey wrote:
>>>> El 06/06/11 18:49, Mark Hounschell escribió:
>>>>> On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
>>>>>> El 06/06/11 13:54, Rolando Martins escribió:
>>>>>>> Hi,
>>>>>>> I use the following:
>>>>>>>
>>>>>>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>>>>>>> print $1; }' | xargs echo)
>>>>>>> for i in $PIDs
>>>>>>> do
>>>>>>> ret=$(chrt -f -p 99 $i)
>>>>>>> done
>>>>>>>
>>>>>>> This will change the kernel thread associated with an irq handler to
>>>>>>> RT FIFO prio 99.
>>>>>>> Just change the script to your specific interrupt.
>>>>>>>
>>>>>>> Hope it helps,
>>>>>>> Rolando
>>>>>>>
>>>>>>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey
>>>>>>> wrote:
>>>>>>>> I am writing a driver which has one kernel thread associated with
>>>>>>>> it.
>>>>>>>> I want to change the priority of this thread, so that I can
>>>>>>>> specify the
>>>>>>>> order in which it is scheduled following an interrupt.
>>>>>>>> I'm using:
>>>>>>>>
>>>>>>>> sched_setscheduler(struct task_struct *, int, struct sched_param
>>>>>>>> *);
>>>>>>>>
>>>>>>>> but it doesn't work. I tried to change the priority from the
>>>>>>>> init_module,
>>>>>>>> and also from the Kernel Thread, but there is no way.
>>>>>>>>
>>>>>>>> Kernel version is 2.6.31-11-rt
>>>>>>>>
>>>>>>>> What do I call to change a kernel thread priority?
>>>>>>>>
>>>>>>>> Thanks you very much
>>>>>>>>
>>>>>>>> Mónica
>>>>>>>>
>>>>>>>> --
>>>>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>>>>> linux-rt-users" in
>>>>>>>> the body of a message to majordomo@vger.kernel.org
>>>>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>>>>
>>>>>>
>>>>>> I need to change the priority from inside the driver, when creating
>>>>>> the
>>>>>> kernel thread.
>>>>>> Your script is useful but it is done in user context,
>>>>>> Any other help please?
>>>>>
>>>>> What I do is record the PID of the thread in the driver, then
>>>>> create an
>>>>> IOCTL for your driver that user land can call that either returns the
>>>>> PID so you can do it in user land, or cause the IOCTL code to do it in
>>>>> the driver.
>>>>>
>>>>> The same can be done with the affinity of the IRQ if you record the
>>>>> IRQ
>>>>> number.
>>>>>
>>>>> Mark
>>>>> --
>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>> linux-rt-users" in
>>>>> the body of a message to majordomo@vger.kernel.org
>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>
>>>> But I don't have de PID of my Kthread, I only have the task_struc *
>>>> that
>>>> gives me the function:
>>>>
>>>> struct task_struct *kthread_create(int (*threadfn)(void *data),
>>>> void *data,
>>>> const char namefmt[], ...)
>>>>
>>>> How could I get the PID, and which function should I use in the IOCTL
>>>> (kernel context) for changing its priority?
>>>>
>>>
>>> The PID can be obtained from within the interrupt handler its self via
>>> current->pid.
>>> Obviously an interrupt has to occur first but after one interrupt you
>>> have it.
>>>
>>> Actually I had forgot how I handled this. Where I change the RT priority
>>> and cpu affinity is in what used to be called the Bottom Half and the
>>> IOCTL
>>> referred to above simply tells the BH to do it and with what values.
>>>
>>
>> In interrupt handler code snippet:
>>
>> struct task_struct *TSK;
>> struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
>>
>> TSK = current;
>>
>> Code snippet from BH:
>>
>> if (((rtom_rtprio != 0) &&
>> (rtom_rtprio != PARAM.sched_priority)) ||
>> (my_rtom_rtprio[BOARD] != rtom_rtprio)) {
>>
>> PARAM.sched_priority = rtom_rtprio;
>> my_rtom_rtprio[COUNT] = rtom_rtprio;
>> sched_setscheduler(TSK, SCHED_FIFO, &PARAM);
>>
>> set_cpus_allowed(TSK, rtom_devices[BOARD].irq_cpu_mask);
>> rtom_devices[BOARD].irq_task_pid = TSK->pid;
>> }
>>
>> rtom_rtprio and irq_cpu_mask are set by userland via an IOCTL. An
>> interrupt must occur for this to happen and my BOARD never shares IRQs.
>>
>> Mark
>>
>
> Thanks, your idea seems to be very useful to me. I was doing it very
> similar, but I didn't use the "current" variable to know the task_struct *.
>
> I have tried your suggestion on an easy example, but it didn't work.
> Insmod returns through the kernel
>
> [11334.895499] kthread: Unknown symbol sched_setscheduler
>
> Code shown below:
>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/ioport.h>
>
> #include <linux/wait.h>
> #include <linux/kthread.h>
> #include <asm/io.h>
> #include <linux/sched.h>
>
>
> struct task_struct *ts;
>
> int thread(void *data)
> {
> struct task_struct *TSK;
> struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
> TSK = current;
>
> PARAM.sched_priority = 50;
> sched_setscheduler(TSK, SCHED_FIFO, &PARAM); // <-- unknown symbol??
>
> while(1){
> printk("Hi I am kernel thread!\n");
> msleep(100);
> if (kthread_should_stop())
> break;
> }
> return 0;
> }
>
>
> int init_module(void)
> {
> printk(KERN_INFO "init_module() called\n");
> ts=kthread_run(thread,NULL,"kthread");
> return 0;
> }
>
> void cleanup_module(void)
> {
> printk(KERN_INFO "cleanup_module() called\n");
> kthread_stop(ts);
> }
> .
>
In kernel/sched.c
EXPORT_SYMBOL_GPL(sched_setscheduler);
If your driver is not GPL, you can't use it.
Mark
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Changing Kernel thread priorities
2011-06-07 18:55 ` Mark Hounschell
@ 2011-06-10 10:12 ` Monica Puig-Pey
0 siblings, 0 replies; 14+ messages in thread
From: Monica Puig-Pey @ 2011-06-10 10:12 UTC (permalink / raw)
To: markh; +Cc: dmarkh, linux-rt-users, linux-kernel
El 07/06/11 20:55, Mark Hounschell escribió:
> On 06/07/2011 02:34 PM, Monica Puig-Pey wrote:
>> El 07/06/11 11:46, Mark Hounschell escribió:
>>> On 06/07/2011 05:14 AM, Mark Hounschell wrote:
>>>> On 06/07/2011 04:40 AM, Monica Puig-Pey wrote:
>>>>> El 06/06/11 18:49, Mark Hounschell escribió:
>>>>>> On 06/06/2011 07:58 AM, Monica Puig-Pey wrote:
>>>>>>> El 06/06/11 13:54, Rolando Martins escribió:
>>>>>>>> Hi,
>>>>>>>> I use the following:
>>>>>>>>
>>>>>>>> PIDs=$(ps -eLo pid,cls,rtprio,pri,nice,cmd | grep -i "irq" | awk '{
>>>>>>>> print $1; }' | xargs echo)
>>>>>>>> for i in $PIDs
>>>>>>>> do
>>>>>>>> ret=$(chrt -f -p 99 $i)
>>>>>>>> done
>>>>>>>>
>>>>>>>> This will change the kernel thread associated with an irq
>>>>>>>> handler to
>>>>>>>> RT FIFO prio 99.
>>>>>>>> Just change the script to your specific interrupt.
>>>>>>>>
>>>>>>>> Hope it helps,
>>>>>>>> Rolando
>>>>>>>>
>>>>>>>> On Mon, Jun 6, 2011 at 12:47 PM, Monica Puig-Pey
>>>>>>>> wrote:
>>>>>>>>> I am writing a driver which has one kernel thread associated with
>>>>>>>>> it.
>>>>>>>>> I want to change the priority of this thread, so that I can
>>>>>>>>> specify the
>>>>>>>>> order in which it is scheduled following an interrupt.
>>>>>>>>> I'm using:
>>>>>>>>>
>>>>>>>>> sched_setscheduler(struct task_struct *, int, struct sched_param
>>>>>>>>> *);
>>>>>>>>>
>>>>>>>>> but it doesn't work. I tried to change the priority from the
>>>>>>>>> init_module,
>>>>>>>>> and also from the Kernel Thread, but there is no way.
>>>>>>>>>
>>>>>>>>> Kernel version is 2.6.31-11-rt
>>>>>>>>>
>>>>>>>>> What do I call to change a kernel thread priority?
>>>>>>>>>
>>>>>>>>> Thanks you very much
>>>>>>>>>
>>>>>>>>> Mónica
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>>>>>> linux-rt-users" in
>>>>>>>>> the body of a message to majordomo@vger.kernel.org
>>>>>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>>>>>
>>>>>>>
>>>>>>> I need to change the priority from inside the driver, when creating
>>>>>>> the
>>>>>>> kernel thread.
>>>>>>> Your script is useful but it is done in user context,
>>>>>>> Any other help please?
>>>>>>
>>>>>> What I do is record the PID of the thread in the driver, then
>>>>>> create an
>>>>>> IOCTL for your driver that user land can call that either returns the
>>>>>> PID so you can do it in user land, or cause the IOCTL code to do
>>>>>> it in
>>>>>> the driver.
>>>>>>
>>>>>> The same can be done with the affinity of the IRQ if you record the
>>>>>> IRQ
>>>>>> number.
>>>>>>
>>>>>> Mark
>>>>>> --
>>>>>> To unsubscribe from this list: send the line "unsubscribe
>>>>>> linux-rt-users" in
>>>>>> the body of a message to majordomo@vger.kernel.org
>>>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>>
>>>>> But I don't have de PID of my Kthread, I only have the task_struc *
>>>>> that
>>>>> gives me the function:
>>>>>
>>>>> struct task_struct *kthread_create(int (*threadfn)(void *data),
>>>>> void *data,
>>>>> const char namefmt[], ...)
>>>>>
>>>>> How could I get the PID, and which function should I use in the IOCTL
>>>>> (kernel context) for changing its priority?
>>>>>
>>>>
>>>> The PID can be obtained from within the interrupt handler its self via
>>>> current->pid.
>>>> Obviously an interrupt has to occur first but after one interrupt you
>>>> have it.
>>>>
>>>> Actually I had forgot how I handled this. Where I change the RT
>>>> priority
>>>> and cpu affinity is in what used to be called the Bottom Half and the
>>>> IOCTL
>>>> referred to above simply tells the BH to do it and with what values.
>>>>
>>>
>>> In interrupt handler code snippet:
>>>
>>> struct task_struct *TSK;
>>> struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
>>>
>>> TSK = current;
>>>
>>> Code snippet from BH:
>>>
>>> if (((rtom_rtprio != 0) &&
>>> (rtom_rtprio != PARAM.sched_priority)) ||
>>> (my_rtom_rtprio[BOARD] != rtom_rtprio)) {
>>>
>>> PARAM.sched_priority = rtom_rtprio;
>>> my_rtom_rtprio[COUNT] = rtom_rtprio;
>>> sched_setscheduler(TSK, SCHED_FIFO, &PARAM);
>>>
>>> set_cpus_allowed(TSK, rtom_devices[BOARD].irq_cpu_mask);
>>> rtom_devices[BOARD].irq_task_pid = TSK->pid;
>>> }
>>>
>>> rtom_rtprio and irq_cpu_mask are set by userland via an IOCTL. An
>>> interrupt must occur for this to happen and my BOARD never shares IRQs.
>>>
>>> Mark
>>>
>>
>> Thanks, your idea seems to be very useful to me. I was doing it very
>> similar, but I didn't use the "current" variable to know the
>> task_struct *.
>>
>> I have tried your suggestion on an easy example, but it didn't work.
>> Insmod returns through the kernel
>>
>> [11334.895499] kthread: Unknown symbol sched_setscheduler
>>
>> Code shown below:
>>
>> #include <linux/module.h>
>> #include <linux/kernel.h>
>> #include <linux/ioport.h>
>>
>> #include <linux/wait.h>
>> #include <linux/kthread.h>
>> #include <asm/io.h>
>> #include <linux/sched.h>
>>
>>
>> struct task_struct *ts;
>>
>> int thread(void *data)
>> {
>> struct task_struct *TSK;
>> struct sched_param PARAM = {.sched_priority = MAX_RT_PRIO };
>> TSK = current;
>>
>> PARAM.sched_priority = 50;
>> sched_setscheduler(TSK, SCHED_FIFO, &PARAM); // <-- unknown symbol??
>>
>> while(1){
>> printk("Hi I am kernel thread!\n");
>> msleep(100);
>> if (kthread_should_stop())
>> break;
>> }
>> return 0;
>> }
>>
>>
>> int init_module(void)
>> {
>> printk(KERN_INFO "init_module() called\n");
>> ts=kthread_run(thread,NULL,"kthread");
>> return 0;
>> }
>>
>> void cleanup_module(void)
>> {
>> printk(KERN_INFO "cleanup_module() called\n");
>> kthread_stop(ts);
>> }
>> .
>>
>
> In kernel/sched.c
>
> EXPORT_SYMBOL_GPL(sched_setscheduler);
>
> If your driver is not GPL, you can't use it.
>
> Mark
I did it, it worked!!! thank you so much!!!!! :)
--
__________________________________________________________________________________
Mónica Puig-Pey González E-mail: puigpeym@unican.es
Grupo de Computadores y Tiempo Real, Departamento de Electrónica y
Computadores.
Facultad de Ciencias - Universidad de Cantabria
Av. de los Castros s/n. 39005 - Santander, España
__________________________________________________________________________________
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2011-06-10 10:11 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-04 11:48 One Interrupted Threads per Interrupt line? Monica Puig-Pey
2011-06-04 12:03 ` I/O operations priority in RTOS Monica Puig-Pey
2011-06-04 12:30 ` kernel threads in drivers using the RT patch Monica Puig-Pey
2011-06-06 11:47 ` Changing Kernel thread priorities Monica Puig-Pey
2011-06-06 11:54 ` Rolando Martins
2011-06-06 11:58 ` Monica Puig-Pey
2011-06-06 16:49 ` Mark Hounschell
2011-06-07 8:40 ` Monica Puig-Pey
2011-06-07 9:14 ` Mark Hounschell
2011-06-07 9:46 ` Mark Hounschell
2011-06-07 18:34 ` Monica Puig-Pey
2011-06-07 18:55 ` Mark Hounschell
2011-06-10 10:12 ` Monica Puig-Pey
2011-06-06 18:20 ` Armin Steinhoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).