From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <1320433713.81220.YahooMailNeo@domain.hid> Date: Fri, 4 Nov 2011 12:08:33 -0700 (PDT) From: Tom Z MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="943903729-1584326518-1320433713=:81220" Subject: [Xenomai-help] 0 CPU time problem Reply-To: Tom Z List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "xenomai@xenomai.org" --943903729-1584326518-1320433713=:81220 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi All,=0A=0AI am trying to measure the CPU time consumed by a function foo= (), and here is how I do it:=0A=0Avoid foo(){=0A=A0=A0=A0=A0=A0=A0=A0 struc= t timespec tp1, tp2;=0A=A0=A0=A0=A0=A0=A0=A0 clock_gettime(CLOCK_PROCESS_CP= UTIME_ID, &tp);=0A=0A=A0=A0=A0 =A0=A0=A0 //Computation goes here=0A=0A=0A= =A0=A0=A0 =A0=A0=A0 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp2);=0A=A0=A0= =A0 =A0=A0=A0 //The CPU time is given between the difference between tp2 an= d tp 1=0A=0A}=0A=0A=0AThe program is running on Ubuntu 10.10, and the kerne= l is 2.6.37 patched with Xenomai 2.5.6=0A=0A=0AHere is what I observed:=0A= =0A1) If foo() is running in the Linux domain (i.e., called by a regular Li= nux process), the CPU time obtained by the above method looks normal, and t= he mean CPU time of 25000 invocations of foo() is 10 ms.=0A=0A2) If foo() i= s running in the primary domain (i.e., called by a Xenomai task spawned by = rt_task_create() and rt_task_start()), then *most of the time*, the CPU tim= e also looks as normal as the result in 1), and the mean CPU time is also a= bout 10 ms. However, I also noticed that sometimes the CPU time obtained by= the above method is 0. This zero value did not appear often, and out of 25= 000 invocations of foo(), I noticed that there is only 1 invocation of foo(= ) where the CPU time is 0. BTW, the Xenomai task's priority is 99.=0A=0AWha= t causes this 0 CPU time in the primary domain? Is there something wrong wi= th my method to measure the CPU time?=0A=0AThanks,=0ATom=0A --943903729-1584326518-1320433713=:81220 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Hi All,

I am trying to measure the CPU time consumed by a function= foo(), and here is how I do it:

void foo(){
=
        struct timespec tp1, tp2;
        clock_gettime(CLOCK_PRO= CESS_CPUTIME_ID, &tp);

&nb= sp;       //Computation= goes here

<= span class=3D"tab">     &nbs= p;  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp2);
     &= nbsp;  //The CPU time is given between the difference between tp2 and = tp 1
}


The progr= am is running on Ubuntu 10.10, and the kernel is 2.6.37 patched with Xenoma= i 2.5.6


Here is what I observed:
1) If foo() is running in the Linux domain (i.e., called by a r= egular Linux process), the CPU time obtained by the above method looks norm= al, and the mean CPU time of 25000 invocations of foo() is 10 ms.
=
2) If foo() is running in the primary domain (i.e., called by a Xenoma= i task spawned by rt_task_create() and rt_task_start()), then *most of the = time*, the CPU time also looks as normal as the result in 1), and the mean = CPU time is also about 10 ms. However, I also noticed that sometimes the CP= U time obtained by the above method is 0. This zero value did not appear of= ten, and out of 25000 invocations of foo(), I noticed that there is only 1 = invocation of foo() where the CPU time is 0. BTW, the Xenomai task's priority is 99.

What causes this 0 CPU time in th= e primary domain? Is there something wrong with my method to measure the CP= U time?

Thanks,
Tom
--943903729-1584326518-1320433713=:81220-- From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4EB43B3E.806@domain.hid> Date: Fri, 04 Nov 2011 20:21:34 +0100 From: Gilles Chanteperdrix MIME-Version: 1.0 References: <1320433713.81220.YahooMailNeo@domain.hid> In-Reply-To: <1320433713.81220.YahooMailNeo@domain.hid> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai-help] 0 CPU time problem List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Tom Z Cc: "xenomai@xenomai.org" On 11/04/2011 08:08 PM, Tom Z wrote: > Hi All, > > I am trying to measure the CPU time consumed by a function foo(), and > here is how I do it: > > void foo(){ struct timespec tp1, tp2; > clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp); > > //Computation goes here > > > clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp2); //The CPU time is > given between the difference between tp2 and tp 1 > > } > > > The program is running on Ubuntu 10.10, and the kernel is 2.6.37 > patched with Xenomai 2.5.6 > > > Here is what I observed: > > 1) If foo() is running in the Linux domain (i.e., called by a regular > Linux process), the CPU time obtained by the above method looks > normal, and the mean CPU time of 25000 invocations of foo() is 10 > ms. > > 2) If foo() is running in the primary domain (i.e., called by a > Xenomai task spawned by rt_task_create() and rt_task_start()), then > *most of the time*, the CPU time also looks as normal as the result > in 1), and the mean CPU time is also about 10 ms. However, I also > noticed that sometimes the CPU time obtained by the above method is > 0. This zero value did not appear often, and out of 25000 invocations > of foo(), I noticed that there is only 1 invocation of foo() where > the CPU time is 0. BTW, the Xenomai task's priority is 99. > > What causes this 0 CPU time in the primary domain? Is there something > wrong with my method to measure the CPU time? We do not know what skin you use, we will assume that you use Xenomai posix skin, so, compile with the right flags. CLOCK_PROCESS_CPUTIME_ID is not implemented for xenomai posix skin, so, clock_gettime probably returns an error, and the struct timespec is unchanged. If somehow the glibc clock_gettime is used, and this call does not cause a system call, then all bets are off, and even a lockup could happen. -- Gilles. From mboxrd@z Thu Jan 1 00:00:00 1970 References: <1320433713.81220.YahooMailNeo@domain.hid> <4EB43B3E.806@domain.hid> Message-ID: <1320440601.64091.YahooMailNeo@domain.hid> Date: Fri, 4 Nov 2011 14:03:21 -0700 (PDT) From: Tom Z In-Reply-To: <4EB43B3E.806@domain.hid> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-1180850466-2057196594-1320440601=:64091" Subject: Re: [Xenomai-help] 0 CPU time problem Reply-To: Tom Z List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gilles Chanteperdrix Cc: "xenomai@xenomai.org" ---1180850466-2057196594-1320440601=:64091 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable "We do not know what skin you use, we will assume that you use Xenomaiposix= skin, so, compile with the right flags."=0AHere is how I build my program,= say, fooTest:=0Agcc -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -Wal= l -pipe -D__XENO__ -lnative -L/usr/xenomai/lib -lxenomai -lpthread -lnative= -lrtdk fooTest.c -o fooTest=0A=0A=0A"CLOCK_PROCESS_CPUTIME_ID is not imple= mented for xenomai posix skin, so,=0Aclock_gettime probably returns an erro= r, and the struct timespec is=0Aunchanged.=0AIf somehow the glibc clock_get= time is used, and this call does not cause=0Aa system call, then all bets a= re off, and even a lockup could happen."=0AThanks for explaining this. So c= an I trust the CPU time I obtained with my method when the function is runn= ing in the primary mode? It seems you explanation implies that the results = I obtained are not reliable, if so, are there other reliable ways to obtain= the CPU time?=0A=0A=0AWith many thanks,=0ATom=0A=0A=0A____________________= ____________=0AFrom: Gilles Chanteperdrix =0ATo: Tom Z =0ACc: "xenomai@xenomai.org" =0ASent: Friday, 4 November 2011 2:21 PM=0ASubject: Re: [Xenomai-h= elp] 0 CPU time problem=0A=0AOn 11/04/2011 08:08 PM, Tom Z wrote:=0A> Hi Al= l,=0A> =0A> I am trying to measure the CPU time consumed by a function foo(= ), and=0A> here is how I do it:=0A> =0A> void foo(){ struct timespec tp1, t= p2; =0A> clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);=0A> =0A> //Computati= on goes here=0A> =0A> =0A> clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp2); /= /The CPU time is=0A> given between the difference between tp2 and tp 1=0A> = =0A> }=0A> =0A> =0A> The program is running on Ubuntu 10.10, and the kernel= is 2.6.37=0A> patched with Xenomai 2.5.6=0A> =0A> =0A> Here is what I obse= rved:=0A> =0A> 1) If foo() is running in the Linux domain (i.e., called by = a regular=0A> Linux process), the CPU time obtained by the above method loo= ks=0A> normal, and the mean CPU time of 25000 invocations of foo() is 10=0A= > ms.=0A> =0A> 2) If foo() is running in the primary domain (i.e., called b= y a=0A> Xenomai task spawned by rt_task_create() and rt_task_start()), then= =0A> *most of the time*, the CPU time also looks as normal as the result=0A= > in 1), and the mean CPU time is also about 10 ms. However, I also=0A> not= iced that sometimes the CPU time obtained by the above method is=0A> 0. Thi= s zero value did not appear often, and out of 25000 invocations=0A> of foo(= ), I noticed that there is only 1 invocation of foo() where=0A> the CPU tim= e is 0. BTW, the Xenomai task's priority is 99.=0A> =0A> What causes this 0= CPU time in the primary domain? Is there something=0A> wrong with my metho= d to measure the CPU time?=0A=0AWe do not know what skin you use, we will a= ssume that you use Xenomai=0Aposix skin, so, compile with the right flags.= =0A=0ACLOCK_PROCESS_CPUTIME_ID is not implemented for xenomai posix skin, s= o,=0Aclock_gettime probably returns an error, and the struct timespec is=0A= unchanged.=0A=0AIf somehow the glibc clock_gettime is used, and this call d= oes not cause=0Aa system call, then all bets are off, and even a lockup cou= ld happen.=0A=0A-- =0A=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= Gilles. ---1180850466-2057196594-1320440601=:64091 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
"We do not know what skin you use, = we will assume that you use Xenomai posix skin, so, compile with the right = flags."
Here is how I build my program, say, fooTest:
gcc -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -Wa= ll -pipe -D__XENO__ -lnative -L/usr/xenomai/lib -lxenomai -lpthread -lnativ= e -lrtdk fooTest.c -o fooTest

"CLOCK_PROCESS_CPUTIME_ID is not implemented for xenoma= i posix skin, so,
clock_gettime probably returns an error, and the struc= t timespec is
unchanged.
If somehow the glibc clock_gettime is used, = and this call does not cause
a system call, then all bets are off, and e= ven a lockup could happen."
Thanks for explaining this. So can I trust the CPU time I obtained with my method when the function is running = in the primary mode? It seems you explanation implies that the results I ob= tained are not reliable, if so, are there other reliable ways to obtain the= CPU time?

With many thanks,
Tom
=

= From: Gilles Chanteperdrix = <gilles.chanteperdrix@xenomai.org>
To: Tom Z <tomz30@domain.hid>
Cc: "xenomai@xenomai.org" <xenomai@xenomai.org= na.org>
Sent: Friday= , 4 November 2011 2:21 PM
Subject:= Re: [Xenomai-help] 0 CPU time problem

On 11/04/2011 08:08 PM= , Tom Z wrote:
> Hi All,
>
> I am trying to measure the = CPU time consumed by a function foo(), and
> here is how I do it:
= >
> void foo(){ struct timespec tp1, tp2;
> clock_gettime(= CLOCK_PROCESS_CPUTIME_ID, &tp);
>
> //Computation goes her= e
>
>
> clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp= 2); //The CPU time is
> given between the difference between tp2 and = tp 1
>
> }
>
>
> The program is running on= Ubuntu 10.10, and the kernel is 2.6.37
> patched with Xenomai 2.5.6<= br>>
>
> Here is what I observed:
>
> 1) If f= oo() is running in the Linux domain (i.e., called by a regular
> Linu= x process), the CPU time obtained by the above method looks
> normal,= and the mean CPU time of 25000 invocations of foo() is 10
> ms.
>
> 2) If foo() is running in the primary domain (i.e., c= alled by a
> Xenomai task spawned by rt_task_create() and rt_task_sta= rt()), then
> *most of the time*, the CPU time also looks as normal a= s the result
> in 1), and the mean CPU time is also about 10 ms. Howe= ver, I also
> noticed that sometimes the CPU time obtained by the abo= ve method is
> 0. This zero value did not appear often, and out of 25= 000 invocations
> of foo(), I noticed that there is only 1 invocation= of foo() where
> the CPU time is 0. BTW, the Xenomai task's priority= is 99.
>
> What causes this 0 CPU time in the primary domain?= Is there something
> wrong with my method to measure the CPU time?
We do not know what skin you use, we will assume that you use Xenomai=
posix skin, so, compile with the right flags.

CLOCK_PROCESS_CPUT= IME_ID is not implemented for xenomai posix skin, so,
clock_gettime probably returns an error, and the struct timespec is=
unchanged.

If somehow the glibc clock_gettime is used, and this = call does not cause
a system call, then all bets are off, and even a loc= kup could happen.

--
            &= nbsp;                    =                     &nbs= p;         Gilles.


= ---1180850466-2057196594-1320440601=:64091-- From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4EB45AF6.60304@domain.hid> Date: Fri, 04 Nov 2011 22:36:54 +0100 From: Gilles Chanteperdrix MIME-Version: 1.0 References: <1320433713.81220.YahooMailNeo@domain.hid> <4EB43B3E.806@domain.hid> <1320440601.64091.YahooMailNeo@domain.hid> In-Reply-To: <1320440601.64091.YahooMailNeo@domain.hid> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai-help] 0 CPU time problem List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Tom Z Cc: "xenomai@xenomai.org" On 11/04/2011 10:03 PM, Tom Z wrote: > > We do not know what skin you use, we will assume that you use > > Xenomai posix skin, so, compile with the right flags. > > Here is how I > build my program, say, fooTest: gcc -I/usr/xenomai/include > -D_GNU_SOURCE -D_REENTRANT -Wall -pipe -D__XENO__ -lnative > -L/usr/xenomai/lib -lxenomai -lpthread -lnative -lrtdk fooTest.c -o > fooTest You are using the native skin then. > > CLOCK_PROCESS_CPUTIME_ID is not implemented for xenomai posix skin, > > so, clock_gettime probably returns an error, and the struct timespec > > is unchanged. If somehow the glibc clock_gettime is used, and this > > call does not cause a system call, then all bets are off, and even a > > lockup could happen. > > Thanks for explaining this. So can I trust the > CPU time I obtained with my method when the function is running in > the primary mode? It seems you explanation implies that the results I > obtained are not reliable, if so, are there other reliable ways to > obtain the CPU time? No, CLOCK_PROCESS_CPUTIME is a clock implemented by the Linux kernel, so, it does not see the time spent in primary mode. If the foo function does not suspend, you can use rt_timer_tsc(), but the answer is no, there is currently no way to get the cpu time used when in primary mode. -- Gilles. From mboxrd@z Thu Jan 1 00:00:00 1970 References: <1320433713.81220.YahooMailNeo@domain.hid> <4EB43B3E.806@domain.hid> <1320440601.64091.YahooMailNeo@domain.hid> <4EB45AF6.60304@domain.hid> Message-ID: <1320460319.56312.YahooMailNeo@domain.hid> Date: Fri, 4 Nov 2011 19:31:59 -0700 (PDT) From: Tom Z In-Reply-To: <4EB45AF6.60304@domain.hid> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="573995543-253283875-1320460319=:56312" Subject: Re: [Xenomai-help] 0 CPU time problem Reply-To: Tom Z List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gilles Chanteperdrix Cc: "xenomai@xenomai.org" --573995543-253283875-1320460319=:56312 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi Gilles,=0A=0A"No, CLOCK_PROCESS_CPUTIME is a clock implemented by the Li= nux kernel,=0Aso, it does not see the time spent in primary mode. If the fo= o function=0Adoes not suspend, you can use rt_timer_tsc(), but the answer i= s no,=0Athere is currently no way to get the cpu time used when in primary = mode."=0AThanks a lot for the explanation. It seems my understanding on how= Xenomai works was incorrect. I thought that if a task, say, myRTTask() is = spawned by rt_task_create() and rt_task_start(), then=A0myRTTask() will alw= ays run in the primary mode, so if myRTTask() calls foo(), then foo() will = be running in the primary mode all the time. The correct fact is, myRTTask(= ) could be running in either the primary mode or the secondary mode, right?= This arises my another question, if foo() uses some third party libraries = (with source code available), how can I tell what parts of foo() will be ru= nning in the primary mode, and what parts will be in the secondary mode? Ar= e there principles for deciding whether the code is in the primary mode or = the secondary mode?=0A=0A=0AThanks again for your patient help.=0A=0ATom=0A= =0A=0A________________________________=0AFrom: Gilles Chanteperdrix =0ATo: Tom Z =0ACc: "xenomai-h= elp@domain.hid" =0ASent: Friday, 4 November 2011 4:36 PM= =0ASubject: Re: [Xenomai-help] 0 CPU time problem=0A=0AOn 11/04/2011 10:03 = PM, Tom Z wrote:=0A> > We do not know what skin you use, we will assume tha= t you use=0A> > Xenomai posix skin, so, compile with the right flags.=0A>= =0A> Here is how I=0A> build my program, say, fooTest: gcc -I/usr/xenomai/i= nclude=0A> -D_GNU_SOURCE -D_REENTRANT -Wall -pipe -D__XENO__ -lnative=0A> -= L/usr/xenomai/lib -lxenomai -lpthread -lnative -lrtdk fooTest.c -o=0A> fooT= est=0A=0AYou are using the native skin then.=0A=0A> > CLOCK_PROCESS_CPUTIME= _ID is not implemented for xenomai posix skin,=0A> > so, clock_gettime prob= ably returns an error, and the struct timespec=0A> > is unchanged. If someh= ow the glibc clock_gettime is used, and this=0A> > call does not cause a sy= stem call, then all bets are off, and even a=0A> > lockup could happen.=0A>= =0A> Thanks for explaining this. So can I trust the=0A> CPU time I obtained= with my method when the function is running in=0A> the primary mode? It se= ems you explanation implies that the results I=0A> obtained are not reliabl= e, if so, are there other reliable ways to=0A> obtain the CPU time?=0A=0ANo= , CLOCK_PROCESS_CPUTIME is a clock implemented by the Linux kernel,=0Aso, i= t does not see the time spent in primary mode. If the foo function=0Adoes n= ot suspend, you can use rt_timer_tsc(), but the answer is no,=0Athere is cu= rrently no way to get the cpu time used when in primary mode.=0A=0A-- =0A= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Gilles. --573995543-253283875-1320460319=:56312 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Gilles,
"No, CLOCK_PROCESS_CPUTIME is a clock= implemented by the Linux kernel,
so, it does not see the time spent in = primary mode. If the foo function
does not suspend, you can use rt_timer= _tsc(), but the answer is no,
there is currently no way to get the cpu t= ime used when in primary mode."
Thanks a lot for the explanation.= It seems my understanding on how Xenomai works was incorrect. I thought th= at if a task, say, myRTTask() is spawned by rt_task_create() and rt_task_st= art(), then myRTTask() will always run in the primary mode, so if myRT= Task() calls foo(), then foo() will be running in the primary mode all the = time. The correct fact is, myRTTask() could be running in either the primar= y mode or the secondary mode, right? This arises my another question, if foo() uses some third party libraries (with source code available), how ca= n I tell what parts of foo() will be running in the primary mode, and what = parts will be in the secondary mode? Are there principles for deciding whet= her the code is in the primary mode or the secondary mode?
Thanks again for your patient help.
Tom

From: Gilles Chanteperdrix <g= illes.chanteperdrix@domain.hid>
Cc: "xenomai@xenomai.org" <xenomai@xenomai.org= g>
Sent: Friday, 4 N= ovember 2011 4:36 PM
Subject: = Re: [Xenomai-help] 0 CPU time problem

On 11/04/2011 10:03 PM,= Tom Z wrote:
> > We do not know what skin you use, we will assume= that you use
> > Xenomai posix skin, so, compile with the right f= lags.
>
> Here is how I
> build my program, say, fooTest:= gcc -I/usr/xenomai/include
> -D_GNU_SOURCE -D_REENTRANT -Wall -pipe = -D__XENO__ -lnative
> -L/usr/xenomai/lib -lxenomai -lpthread -lnative= -lrtdk fooTest.c -o
> fooTest

You are using the native skin t= hen.

> > CLOCK_PROCESS_CPUTIME_ID is not implemented for xenom= ai posix skin,
> > so, clock_gettime probably returns an error, an= d the struct timespec
> > is unchanged. If somehow the glibc clock= _gettime is used, and this
> > call does not cause a system call, = then all bets are off, and even a
> > lockup could happen.
>
> Thanks for explaining this. So can I trust the
= > CPU time I obtained with my method when the function is running in
= > the primary mode? It seems you explanation implies that the results I<= br>> obtained are not reliable, if so, are there other reliable ways to<= br>> obtain the CPU time?

No, CLOCK_PROCESS_CPUTIME is a clock im= plemented by the Linux kernel,
so, it does not see the time spent in pri= mary mode. If the foo function
does not suspend, you can use rt_timer_ts= c(), but the answer is no,
there is currently no way to get the cpu time= used when in primary mode.

--
         = ;                     &nb= sp;                     &= nbsp;           Gilles.


--573995543-253283875-1320460319=:56312-- From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4EB51D8E.9020609@domain.hid> Date: Sat, 05 Nov 2011 12:27:10 +0100 From: Philippe Gerum MIME-Version: 1.0 References: <1320433713.81220.YahooMailNeo@domain.hid> <4EB43B3E.806@domain.hid> <1320440601.64091.YahooMailNeo@domain.hid> <4EB45AF6.60304@domain.hid> In-Reply-To: <4EB45AF6.60304@domain.hid> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai-help] 0 CPU time problem List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xenomai@xenomai.org, tomz30@domain.hid On 11/04/2011 10:36 PM, Gilles Chanteperdrix wrote: > On 11/04/2011 10:03 PM, Tom Z wrote: >>> We do not know what skin you use, we will assume that you use >>> Xenomai posix skin, so, compile with the right flags. >> >> Here is how I >> build my program, say, fooTest: gcc -I/usr/xenomai/include >> -D_GNU_SOURCE -D_REENTRANT -Wall -pipe -D__XENO__ -lnative >> -L/usr/xenomai/lib -lxenomai -lpthread -lnative -lrtdk fooTest.c -o >> fooTest > > You are using the native skin then. > >>> CLOCK_PROCESS_CPUTIME_ID is not implemented for xenomai posix skin, >>> so, clock_gettime probably returns an error, and the struct timespec >>> is unchanged. If somehow the glibc clock_gettime is used, and this >>> call does not cause a system call, then all bets are off, and even a >>> lockup could happen. >> >> Thanks for explaining this. So can I trust the >> CPU time I obtained with my method when the function is running in >> the primary mode? It seems you explanation implies that the results I >> obtained are not reliable, if so, are there other reliable ways to >> obtain the CPU time? > > No, CLOCK_PROCESS_CPUTIME is a clock implemented by the Linux kernel, > so, it does not see the time spent in primary mode. If the foo function > does not suspend, you can use rt_timer_tsc(), but the answer is no, > there is currently no way to get the cpu time used when in primary mode. > There is one, but deeply buried in the API basement, via rt_task_inquire(): RT_TASK_INFO info; RTIME start; ret = rt_task_inquire(NULL, &info); /* NULL means current task */ if (ret) goto Houston_handles_the_problem; start = info.exectime; ... do work .... ret = rt_task_inquire(NULL, &info); delta = info.exectime - start; /* elapsed CPU time in ns */ rt_task_inquire() will beget a syscall each time invoked though, so it does have some overhead. You need CONFIG_XENO_OPT_STATS enabled in your Kconfig for this feature (defaults to on). -- Philippe. From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4EB53B0C.7060303@domain.hid> Date: Sat, 05 Nov 2011 14:33:00 +0100 From: Gilles Chanteperdrix MIME-Version: 1.0 References: <1320433713.81220.YahooMailNeo@domain.hid> <4EB43B3E.806@domain.hid> <1320440601.64091.YahooMailNeo@domain.hid> <4EB45AF6.60304@domain.hid> <1320460319.56312.YahooMailNeo@domain.hid> In-Reply-To: <1320460319.56312.YahooMailNeo@domain.hid> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai-help] 0 CPU time problem List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Tom Z Cc: "xenomai@xenomai.org" On 11/05/2011 03:31 AM, Tom Z wrote: > Hi Gilles, > > > No, CLOCK_PROCESS_CPUTIME is a clock implemented by the Linux > > kernel, so, it does not see the time spent in primary mode. If the > > foo function does not suspend, you can use rt_timer_tsc(), but the > > answer is no, there is currently no way to get the cpu time used > > when in primary mode. > > Thanks a lot for the explanation. It seems my understanding on how > Xenomai works was incorrect. I thought that if a task, say, > myRTTask() is spawned by rt_task_create() and rt_task_start(), then > myRTTask() will always run in the primary mode, so if myRTTask() > calls foo(), then foo() will be running in the primary mode all the > time. The correct fact is, myRTTask() could be running in either the > primary mode or the secondary mode, right? This arises my another > question, if foo() uses some third party libraries (with source code > available), how can I tell what parts of foo() will be running in the > primary mode, and what parts will be in the secondary mode? Are there > principles for deciding whether the code is in the primary mode or > the secondary mode? Hi, it would be nice if you could quote and wrap mails as is usual on public mailing lists. Every Linux system call causes a switch to secondary mode, as well as every call to a xenomai system call documented as such. For instance, if you look at rt_queue_create documentation, you see: Environments: This service can be called from: * Kernel module initialization/cleanup code * User-space task (switches to secondary mode) If you want to detect unwanted mode switches to secondary mode, you can use rt_task_set_mode with the T_WARNSW bit, as is demonstrated in the example: examples/native/sigdebug.c in xenomai sources tree. -- Gilles.