All of lore.kernel.org
 help / color / mirror / Atom feed
* domain switch
@ 2021-01-02 20:54 Leandro Bucci
  2021-01-02 23:06 ` steve freyder
  0 siblings, 1 reply; 8+ messages in thread
From: Leandro Bucci @ 2021-01-02 20:54 UTC (permalink / raw)
  To: xenomai

Hi, I wanted to know if there was a way to count the number of times a
domain switch happens.
For example the printf () function causes a domain switch, right?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-02 20:54 domain switch Leandro Bucci
@ 2021-01-02 23:06 ` steve freyder
  2021-01-03  1:29   ` Leandro Bucci
  2021-01-03 10:31   ` Philippe Gerum
  0 siblings, 2 replies; 8+ messages in thread
From: steve freyder @ 2021-01-02 23:06 UTC (permalink / raw)
  To: Leandro Bucci, xenomai

Right.


AKA, "mode switch", a switch from "primary mode" to "secondary mode", or 
vice versa.

One place you can find that information is in:

/proc/xenomai/sched/acct

there are two fields MSW, and CSW which count mode/context switches 
per-process. This requires an open, a read loop to locate the desired 
pid and extract the desired information, then either rewind or 
close/reopen to do it again - all of which will almost surely generate 
more mode/context switching.


On 1/2/2021 2:54 PM, Leandro Bucci via Xenomai wrote:
> Hi, I wanted to know if there was a way to count the number of times a
> domain switch happens.
> For example the printf () function causes a domain switch, right?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-02 23:06 ` steve freyder
@ 2021-01-03  1:29   ` Leandro Bucci
  2021-01-03 10:31   ` Philippe Gerum
  1 sibling, 0 replies; 8+ messages in thread
From: Leandro Bucci @ 2021-01-03  1:29 UTC (permalink / raw)
  To: steve freyder; +Cc: xenomai

Awesome, thanks!

Il dom 3 gen 2021, 00:06 steve freyder <steve@freyder.net> ha scritto:

> Right.
>
>
> AKA, "mode switch", a switch from "primary mode" to "secondary mode", or
> vice versa.
>
> One place you can find that information is in:
>
> /proc/xenomai/sched/acct
>
> there are two fields MSW, and CSW which count mode/context switches
> per-process.  This requires an open, a read loop to locate the desired pid
> and extract the desired information, then either rewind or close/reopen to
> do it again - all of which will almost surely generate more mode/context
> switching.
>
>
> On 1/2/2021 2:54 PM, Leandro Bucci via Xenomai wrote:
>
> Hi, I wanted to know if there was a way to count the number of times a
> domain switch happens.
> For example the printf () function causes a domain switch, right?
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-02 23:06 ` steve freyder
  2021-01-03  1:29   ` Leandro Bucci
@ 2021-01-03 10:31   ` Philippe Gerum
  2021-01-03 10:54     ` Leandro Bucci
  1 sibling, 1 reply; 8+ messages in thread
From: Philippe Gerum @ 2021-01-03 10:31 UTC (permalink / raw)
  To: steve freyder; +Cc: Leandro Bucci, xenomai


steve freyder via Xenomai <xenomai@xenomai.org> writes:

> Right.
>
>
> AKA, "mode switch", a switch from "primary mode" to "secondary mode",
> or vice versa.
>
> One place you can find that information is in:
>
> /proc/xenomai/sched/acct
>
> there are two fields MSW, and CSW which count mode/context switches
> per-process. This requires an open, a read loop to locate the desired 
> pid and extract the desired information, then either rewind or
> close/reopen to do it again - all of which will almost surely generate 
> more mode/context switching.
>

If that helps, there is also the option of getting the thread stats by
program, using int cobalt_thread_stat(pid_t pid, struct
cobalt_threadstat *stat), declared in sys/cobalt.h. pid refers to a
thread identifier (as obtained from gettid(2) in the context of the
target thread). It must refer to a Cobalt thread, otherwise the call
would fail with -ESRCH.

The mode switch count is present in the returned information block
(->msw). cobalt_thread_stat() would not cause any mode switch. It can be
called by any thread regardless of its type (i.e. regular or Cobalt).

-- 
Philippe.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-03 10:31   ` Philippe Gerum
@ 2021-01-03 10:54     ` Leandro Bucci
  2021-01-03 11:06       ` Philippe Gerum
  0 siblings, 1 reply; 8+ messages in thread
From: Leandro Bucci @ 2021-01-03 10:54 UTC (permalink / raw)
  To: Philippe Gerum, steve freyder, xenomai

is it possible to have the same thing for tasks instead of threads?

Il dom 3 gen 2021, 11:31 Philippe Gerum <rpm@xenomai.org> ha scritto:

>
> steve freyder via Xenomai <xenomai@xenomai.org> writes:
>
> > Right.
> >
> >
> > AKA, "mode switch", a switch from "primary mode" to "secondary mode",
> > or vice versa.
> >
> > One place you can find that information is in:
> >
> > /proc/xenomai/sched/acct
> >
> > there are two fields MSW, and CSW which count mode/context switches
> > per-process. This requires an open, a read loop to locate the desired
> > pid and extract the desired information, then either rewind or
> > close/reopen to do it again - all of which will almost surely generate
> > more mode/context switching.
> >
>
> If that helps, there is also the option of getting the thread stats by
> program, using int cobalt_thread_stat(pid_t pid, struct
> cobalt_threadstat *stat), declared in sys/cobalt.h. pid refers to a
> thread identifier (as obtained from gettid(2) in the context of the
> target thread). It must refer to a Cobalt thread, otherwise the call
> would fail with -ESRCH.
>
> The mode switch count is present in the returned information block
> (->msw). cobalt_thread_stat() would not cause any mode switch. It can be
> called by any thread regardless of its type (i.e. regular or Cobalt).
>
> --
> Philippe.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-03 10:54     ` Leandro Bucci
@ 2021-01-03 11:06       ` Philippe Gerum
  2021-01-03 11:20         ` Leandro Bucci
  0 siblings, 1 reply; 8+ messages in thread
From: Philippe Gerum @ 2021-01-03 11:06 UTC (permalink / raw)
  To: Leandro Bucci; +Cc: steve freyder, xenomai


Leandro Bucci <guestleandro11@gmail.com> writes:

> is it possible to have the same thing for tasks instead of threads?
>

task == thread

> Il dom 3 gen 2021, 11:31 Philippe Gerum <rpm@xenomai.org> ha scritto:
>
>>
>> steve freyder via Xenomai <xenomai@xenomai.org> writes:
>>
>> > Right.
>> >
>> >
>> > AKA, "mode switch", a switch from "primary mode" to "secondary mode",
>> > or vice versa.
>> >
>> > One place you can find that information is in:
>> >
>> > /proc/xenomai/sched/acct
>> >
>> > there are two fields MSW, and CSW which count mode/context switches
>> > per-process. This requires an open, a read loop to locate the desired
>> > pid and extract the desired information, then either rewind or
>> > close/reopen to do it again - all of which will almost surely generate
>> > more mode/context switching.
>> >
>>
>> If that helps, there is also the option of getting the thread stats by
>> program, using int cobalt_thread_stat(pid_t pid, struct
>> cobalt_threadstat *stat), declared in sys/cobalt.h. pid refers to a
>> thread identifier (as obtained from gettid(2) in the context of the
>> target thread). It must refer to a Cobalt thread, otherwise the call
>> would fail with -ESRCH.
>>
>> The mode switch count is present in the returned information block
>> (->msw). cobalt_thread_stat() would not cause any mode switch. It can be
>> called by any thread regardless of its type (i.e. regular or Cobalt).
>>
>> --
>> Philippe.
>>


-- 
Philippe.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-03 11:06       ` Philippe Gerum
@ 2021-01-03 11:20         ` Leandro Bucci
  2021-01-03 18:24           ` Leandro Bucci
  0 siblings, 1 reply; 8+ messages in thread
From: Leandro Bucci @ 2021-01-03 11:20 UTC (permalink / raw)
  To: Philippe Gerum, steve freyder, xenomai

perfect thank you so much for the explanation

Il dom 3 gen 2021, 12:06 Philippe Gerum <rpm@xenomai.org> ha scritto:

>
> Leandro Bucci <guestleandro11@gmail.com> writes:
>
> > is it possible to have the same thing for tasks instead of threads?
> >
>
> task == thread
>
> > Il dom 3 gen 2021, 11:31 Philippe Gerum <rpm@xenomai.org> ha scritto:
> >
> >>
> >> steve freyder via Xenomai <xenomai@xenomai.org> writes:
> >>
> >> > Right.
> >> >
> >> >
> >> > AKA, "mode switch", a switch from "primary mode" to "secondary mode",
> >> > or vice versa.
> >> >
> >> > One place you can find that information is in:
> >> >
> >> > /proc/xenomai/sched/acct
> >> >
> >> > there are two fields MSW, and CSW which count mode/context switches
> >> > per-process. This requires an open, a read loop to locate the desired
> >> > pid and extract the desired information, then either rewind or
> >> > close/reopen to do it again - all of which will almost surely generate
> >> > more mode/context switching.
> >> >
> >>
> >> If that helps, there is also the option of getting the thread stats by
> >> program, using int cobalt_thread_stat(pid_t pid, struct
> >> cobalt_threadstat *stat), declared in sys/cobalt.h. pid refers to a
> >> thread identifier (as obtained from gettid(2) in the context of the
> >> target thread). It must refer to a Cobalt thread, otherwise the call
> >> would fail with -ESRCH.
> >>
> >> The mode switch count is present in the returned information block
> >> (->msw). cobalt_thread_stat() would not cause any mode switch. It can be
> >> called by any thread regardless of its type (i.e. regular or Cobalt).
> >>
> >> --
> >> Philippe.
> >>
>
>
> --
> Philippe.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: domain switch
  2021-01-03 11:20         ` Leandro Bucci
@ 2021-01-03 18:24           ` Leandro Bucci
  0 siblings, 0 replies; 8+ messages in thread
From: Leandro Bucci @ 2021-01-03 18:24 UTC (permalink / raw)
  To: Philippe Gerum, xenomai, steve freyder

Sorry for the inconvenience,
I tried to write this code to report domain changes (or mode switch):

##############################################################
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <alchemy/task.h>
#include <alchemy/timer.h>


RT_TASK task;

void task_body(void *arg)
{

RT_TASK_INFO info;

printf("Hello\n");
rt_printf("ByeBye\n");
rt_task_inquire(NULL, &info);
rt_printf("mode switch = %d\n", info.stat.msw);
}

int main()
{
int err;

err = rt_task_create(&task, "mytask", 0, 1, 0);
if (err != 0){
fprintf(stderr, "failed to create task\n");
exit(EXIT_FAILURE);
}

err = rt_task_start(&task, &task_body, NULL);
if (err != 0){
fprintf(stderr, "failed to start task\n");
exit(EXIT_FAILURE);
}

pause();
exit(EXIT_SUCCESS);
}

######################################################################

but I get 0 as a result. How is this possible?

Il giorno dom 3 gen 2021 alle ore 12:20 Leandro Bucci <
guestleandro11@gmail.com> ha scritto:

> perfect thank you so much for the explanation
>
> Il dom 3 gen 2021, 12:06 Philippe Gerum <rpm@xenomai.org> ha scritto:
>
>>
>> Leandro Bucci <guestleandro11@gmail.com> writes:
>>
>> > is it possible to have the same thing for tasks instead of threads?
>> >
>>
>> task == thread
>>
>> > Il dom 3 gen 2021, 11:31 Philippe Gerum <rpm@xenomai.org> ha scritto:
>> >
>> >>
>> >> steve freyder via Xenomai <xenomai@xenomai.org> writes:
>> >>
>> >> > Right.
>> >> >
>> >> >
>> >> > AKA, "mode switch", a switch from "primary mode" to "secondary mode",
>> >> > or vice versa.
>> >> >
>> >> > One place you can find that information is in:
>> >> >
>> >> > /proc/xenomai/sched/acct
>> >> >
>> >> > there are two fields MSW, and CSW which count mode/context switches
>> >> > per-process. This requires an open, a read loop to locate the desired
>> >> > pid and extract the desired information, then either rewind or
>> >> > close/reopen to do it again - all of which will almost surely
>> generate
>> >> > more mode/context switching.
>> >> >
>> >>
>> >> If that helps, there is also the option of getting the thread stats by
>> >> program, using int cobalt_thread_stat(pid_t pid, struct
>> >> cobalt_threadstat *stat), declared in sys/cobalt.h. pid refers to a
>> >> thread identifier (as obtained from gettid(2) in the context of the
>> >> target thread). It must refer to a Cobalt thread, otherwise the call
>> >> would fail with -ESRCH.
>> >>
>> >> The mode switch count is present in the returned information block
>> >> (->msw). cobalt_thread_stat() would not cause any mode switch. It can
>> be
>> >> called by any thread regardless of its type (i.e. regular or Cobalt).
>> >>
>> >> --
>> >> Philippe.
>> >>
>>
>>
>> --
>> Philippe.
>>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-03 18:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-02 20:54 domain switch Leandro Bucci
2021-01-02 23:06 ` steve freyder
2021-01-03  1:29   ` Leandro Bucci
2021-01-03 10:31   ` Philippe Gerum
2021-01-03 10:54     ` Leandro Bucci
2021-01-03 11:06       ` Philippe Gerum
2021-01-03 11:20         ` Leandro Bucci
2021-01-03 18:24           ` Leandro Bucci

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.