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--