Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Number of CPU cycles used by a thread: Page 1 of 2 (30 Items)
   
Number of CPU cycles used by a thread  
Hello,

I cannot find from the documentation how to get the number of CPU cycles used by a specific thread during the last N 
microseconds, or since the last time I enter a specific function.
How to to that programmatically with QNX?

I'm also searching how to get the idle time programmatically.

Thank you for any help,
Greg
Re: Number of CPU cycles used by a thread  
Check out the ClockId() function (for use with ClockTime()). It will
give you the amount of time used by a particular thread. The value
returned is in nanoseconds, but the actually resolution is a timer
tick (default 1mS). The idle threads in the system are procnto tids 
1 through N, where N is the number of cpus in the system, so

	ClockTime(ClockId(1, 1), ....)
	ClockTime(ClockId(1, 2), ....)
	....

will give you the amount of idle time on each of the cpus.


On Wed, Jun 01, 2011 at 07:36:42AM -0400, Gregoire Banderet wrote:
> Hello,
> 
> I cannot find from the documentation how to get the number of CPU cycles
> used by a specific thread during the last N microseconds, or since the
> last time I enter a specific function.
> How to to that programmatically with QNX?
> 
> I'm also searching how to get the idle time programmatically.
> 
> Thank you for any help,
> Greg
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post86311
> 

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: Number of CPU cycles used by a thread  
Thnaks for the help.

ClockTime() works, but unfortunately I need a microsecond precision.
Is there another way to know programmatically how many CPU cycles my thread used during the last N microseconds?

Thank you,
Greg
Re: Number of CPU cycles used by a thread  
Resolution of system clock is controlled by ClockPeriod() call.
I doubt you will be able to set/run resolution of 1 mks though. As per manual, the lowest clock period that can 
currently be set on any machine is 10 microseconds.
Re: Number of CPU cycles used by a thread  
Sure.

I'm looking for another way. Decreasing the clock period is not a solution, the CPU load will increase too much.
Re: Number of CPU cycles used by a thread  
There simply is no another way. The kernel can't provide you with finer time resolution since it does not track it even 
for itself.
Re: Number of CPU cycles used by a thread  
It's the kernel job to schedule the execution of the threads. So I guess it knows which threads is running at any time.
When you use the system profiler in Momentics you see the execution of the threads, it's then easy to calculate the 
number of microseconds of execution for a specific thread within a given time slot. I just need that programatically.

I'm currently porting some code written for INTime. INTime can reports the number of CPU cycles consumed by a thread 
even with a clock period of 125us.
It will make me very sad if QNX couldn't do what INTime can :-)

-- Greg

RE: Number of CPU cycles used by a thread  
Are you looking for something like the ClockCycles() API call in your program?


-----Original Message-----
From: Gregoire Banderet [mailto:community-noreply@qnx.com] 
Sent: Thursday, October 20, 2011 5:10 AM
To: ostech-core_os
Subject: Re: Number of CPU cycles used by a thread

It's the kernel job to schedule the execution of the threads. So I guess it knows which threads is running at any time.
When you use the system profiler in Momentics you see the execution of the threads, it's then easy to calculate the 
number of microseconds of execution for a specific thread within a given time slot. I just need that programatically.

I'm currently porting some code written for INTime. INTime can reports the number of CPU cycles consumed by a thread 
even with a clock period of 125us.
It will make me very sad if QNX couldn't do what INTime can :-)

-- Greg





_______________________________________________

OSTech
http://community.qnx.com/sf/go/post89474
Re: Number of CPU cycles used by a thread  
How about the traceevent interrupt hook?  Then you can know everytime a different thread is scheduled.  I don't have the
 api in front if me right now, so I probably have the function name wrong. 

----- Original Message -----
From: Lichun Zhu [mailto:community-noreply@qnx.com]
Sent: Thursday, October 20, 2011 09:14 AM
To: ostech-core_os <post89479@community.qnx.com>
Subject: RE: Number of CPU cycles used by a thread

Are you looking for something like the ClockCycles() API call in your program?


-----Original Message-----
From: Gregoire Banderet [mailto:community-noreply@qnx.com] 
Sent: Thursday, October 20, 2011 5:10 AM
To: ostech-core_os
Subject: Re: Number of CPU cycles used by a thread

It's the kernel job to schedule the execution of the threads. So I guess it knows which threads is running at any time.
When you use the system profiler in Momentics you see the execution of the threads, it's then easy to calculate the 
number of microseconds of execution for a specific thread within a given time slot. I just need that programatically.

I'm currently porting some code written for INTime. INTime can reports the number of CPU cycles consumed by a thread 
even with a clock period of 125us.
It will make me very sad if QNX couldn't do what INTime can :-)

-- Greg





_______________________________________________

OSTech
http://community.qnx.com/sf/go/post89474




_______________________________________________

OSTech
http://community.qnx.com/sf/go/post89479
Re: RE: Number of CPU cycles used by a thread  
No. ClockCycles only reports the current CPU cycles counter value. The counter is global for all threads. I need one per
 thread.

Re: RE: Number of CPU cycles used by a thread  
Gregoire : have similar problem in my project ..let me know if u get the answer ..
try this might be helpful 
/*
 * The following program executes the program
 * specified by argv[1].  After the child program
 * is finished, the cpu statistics of the child are
 * printed.
 */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/times.h>

int main( int argc, char **argv )
  {
    struct tms childtim;

    system( argv[1] );
    times( &childtim );
    printf( "system time = %d\n", childtim.tms_cstime );
    printf( "user time   = %d\n", childtim.tms_cutime );
    return EXIT_SUCCESS;
  }

Re: RE: Number of CPU cycles used by a thread  
got something 

 http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/utilities/s/sin.html

sin

Display system information:

threads (or th)
    Show information about the threads of the displayed process. From the left, the columns show:

        Tid -- Thread ID
        Priority -- scheduling priority number and scheduling algorithm (see below)
        State -- current state of the thread (see below for possible states)
        Blocked -- the PID that this process is blocked on
        IP -- the EIP register set used by the displayed process
        CPU -- CPU occupancy time in milliseconds



try this ....
Re: RE: Number of CPU cycles used by a thread  
Also,

http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/utilities/p/pidin.html


times
    For each process displayed, show:

        start time -- the time and date that the process was started
        utime -- the number of CPU seconds consumed by the process
        stime -- the number of CPU seconds has consumed on behalf of the process
        cutime -- the number of CPU seconds consumed by the children of the process
        cstime -- the number of CPU seconds has consumed on behalf of the children of the process

    The times for the child processes are added to cutime and cstime only after the children terminate. 

ttimes (or tt)
    Show thread times. 

Regards,
Atul Kumbhar
Re: Number of CPU cycles used by a thread  
Hi Gregoire,
I got code for pidin ...



Attachment: Compressed file pidin code.zip 33.12 KB
Re: Number of CPU cycles used by a thread  
 Hi Gregoire,

here is sin...
Attachment: Compressed file sin code for qnx4.zip 22.61 KB
Re: Number of CPU cycles used by a thread  
 Hi Gregoire,

here is sin...


let me know when u calculate the thread usage...

Regards,
Atul Kumbhar
Attachment: Compressed file sin code for qnx4.zip 22.61 KB
Re: Number of CPU cycles used by a thread  
Hi,

Thanks a lot for all these informations.
I will start to look at it in a few days.

Regards,
Greg

On 10/22/2011 08:42, Atul Kumbhar wrote:
>   Hi Gregoire,
>
> here is sin...
>
>
> let me know when u calculate the thread usage...
>
> Regards,
> Atul Kumbhar
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post89555

Please be advised that this email may contain confidential 
information.  If you are not the intended recipient, please notify us 
by email by replying to the sender and delete this message.  The 
sender disclaims that the content of this email constitutes an offer 
to enter into, or the acceptance of, any agreement; provided that the 
foregoing does not invalidate the binding effect of any digital or 
other electronic reproduction of a manual signature that is included 
in any attachment.

Re: Number of CPU cycles used by a thread  
Hi,

I eventually have some time to look into this...

I followed the QNX documentation under "Controlling processes via the /proc filesystem",
and I use open/devctl, DCMD_PROC_STATUS and the member procfs_status.sutime.

Unfortunately sutime increases by step of the cycle time value :-(
That means I cannot reach the granularity (1 microseconds) I need...

-- Greg
Re: Number of CPU cycles used by a thread  
Hi,

I eventually have some time to look into this...

I followed the QNX documentation under "Controlling processes via the /proc filesystem",
and I use open/devctl, DCMD_PROC_STATUS and the member procfs_status.sutime.

Unfortunately sutime increases by step of the cycle time value :-(
That means I cannot reach the granularity (1 microseconds) I need...

-- Greg
Re: Number of CPU cycles used by a thread  
You can use system profiler, it will do a tracing with resolution of clockcycles, it has view that can aggregate data 
per thread on selected region

On 11/24/2011 09:24 AM, Gregoire Banderet wrote:
> Hi,
> 
> I eventually have some time to look into this...
> 
> I followed the QNX documentation under "Controlling processes via the /proc filesystem",
> and I use open/devctl, DCMD_PROC_STATUS and the member procfs_status.sutime.
> 
> Unfortunately sutime increases by step of the cycle time value :-(
> That means I cannot reach the granularity (1 microseconds) I need...
> 
> -- Greg
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post90277
> 
Re: Number of CPU cycles used by a thread  
Hi ,
you can read post89302 by Elena Laskavaia it worked for me....
Thanks Elena Laskavaia Mam .. :)

Regards,
Atul Kumbhar

> You can use system profiler, it will do a tracing with resolution of 
> clockcycles, it has view that can aggregate data per thread on selected region
> 
> 
> On 11/24/2011 09:24 AM, Gregoire Banderet wrote:
> > Hi,
> > 
> > I eventually have some time to look into this...
> > 
> > I followed the QNX documentation under "Controlling processes via the /proc 
> filesystem",
> > and I use open/devctl, DCMD_PROC_STATUS and the member procfs_status.sutime.
> 
> > 
> > Unfortunately sutime increases by step of the cycle time value :-(
> > That means I cannot reach the granularity (1 microseconds) I need...
> > 
> > -- Greg
> > 
> > 
> > 
> > _______________________________________________
> > 
> > OSTech
> > http://community.qnx.com/sf/go/post90277
> > 


RE: Number of CPU cycles used by a thread  
Hi,

I'm not profiling my QNX executable. I'm implementing a feature for a client. The timings values are then reported to a 
Windows IDE through TCP/IP.
The QNX executable is a multi-threaded virtual machine running the customer's PLC application. Our customers want to do 
some profiling of their application executed by the Virtual machine running on QNX.

That means I need timings values of a granularity of 1 microseconds and this profiling feature must not increase the CPU
 load (1 or 2 percent of CPU power is acceptable).
The system profiler is not available in customer site.

Is there any way to use the tracing API in order to gather threads data? Is there events for the start and end of 
execution for every threads?

-- Greg

> -----Message d'origine-----
> De : Elena Laskavaia [mailto:community-noreply@qnx.com]
> Envoyé : Thursday, November 24, 2011 19:11
> À : ostech-core_os
> Objet : Re: Number of CPU cycles used by a thread
> 
> You can use system profiler, it will do a tracing with resolution of clockcycles,
> it has view that can aggregate data per thread on selected region
> 
> On 11/24/2011 09:24 AM, Gregoire Banderet wrote:
> > Hi,
> >
> > I eventually have some time to look into this...
> >
> > I followed the QNX documentation under "Controlling processes via the
> > /proc filesystem", and I use open/devctl, DCMD_PROC_STATUS and the
> member procfs_status.sutime.
> >
> > Unfortunately sutime increases by step of the cycle time value :-(
> > That means I cannot reach the granularity (1 microseconds) I need...
> >
> > -- Greg
> >
> >
> >
> > _______________________________________________
> >
> > OSTech
> > http://community.qnx.com/sf/go/post90277
> >
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post90287
> 


Please be advised that this email may contain confidential 
information.  If you are not the intended recipient, please notify us 
by email by replying to the sender and delete this message.  The 
sender disclaims that the content of this email constitutes an offer 
to enter into, or the acceptance of, any agreement; provided that the 
foregoing does not invalidate the binding effect of any digital or 
other electronic reproduction of a manual signature that is included 
in any attachment.

Re: Number of CPU cycles used by a thread  
If you customer running instrumented kernel you can hook in to tracelogger API. You would need to enable events on when 
thread start/stop running and start tracelogging from the code of your utility, then run custom "traceprinter" to 
aggregate the data

On 11/25/2011 02:35 AM, Gregoire Banderet wrote:
> Hi,
> 
> I'm not profiling my QNX executable. I'm implementing a feature for a client. The timings values are then reported to 
a Windows IDE through TCP/IP.
> The QNX executable is a multi-threaded virtual machine running the customer's PLC application. Our customers want to 
do some profiling of their application executed by the Virtual machine running on QNX.
> 
> That means I need timings values of a granularity of 1 microseconds and this profiling feature must not increase the 
CPU load (1 or 2 percent of CPU power is acceptable).
> The system profiler is not available in customer site.
> 
> Is there any way to use the tracing API in order to gather threads data? Is there events for the start and end of 
execution for every threads?
> 
> -- Greg
> 
>> -----Message d'origine-----
>> De : Elena Laskavaia [mailto:community-noreply@qnx.com]
>> Envoyé : Thursday, November 24, 2011 19:11
>> À : ostech-core_os
>> Objet : Re: Number of CPU cycles used by a thread
>>
>> You can use system profiler, it will do a tracing with resolution of clockcycles,
>> it has view that can aggregate data per thread on selected region
>>
>> On 11/24/2011 09:24 AM, Gregoire Banderet wrote:
>>> Hi,
>>>
>>> I eventually have some time to look into this...
>>>
>>> I followed the QNX documentation under "Controlling processes via the
>>> /proc filesystem", and I use open/devctl, DCMD_PROC_STATUS and the
>> member procfs_status.sutime.
>>>
>>> Unfortunately sutime increases by step of the cycle time value :-(
>>> That means I cannot reach the granularity (1 microseconds) I need...
>>>
>>> -- Greg
>>>
>>>
>>>
>>> _______________________________________________
>>>
>>> OSTech
>>> http://community.qnx.com/sf/go/post90277
>>>
>>
>>
>>
>> _______________________________________________
>>
>> OSTech
>> http://community.qnx.com/sf/go/post90287
>>
> 
> 
> Please be advised that this email may contain confidential 
> information.  If you are not the intended recipient, please notify us 
> by email by replying to the sender and delete this message.  The 
> sender disclaims that the content of this email constitutes an offer 
> to enter into, or the acceptance of, any agreement; provided that the 
> foregoing does not invalidate the binding effect of any digital or 
> other electronic reproduction of a manual signature that is included 
> in any attachment.
> 
> 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post90295
Re: Number of CPU cycles used by a thread  
Please note that trying to take accurate timing measurements in a VM is 
not going to work very well!

On 11-11-25 11:53 AM, Elena Laskavaia wrote:
> If you customer running instrumented kernel you can hook in to tracelogger API. You would need to enable events on 
when thread start/stop running and start tracelogging from the code of your utility, then run custom "traceprinter" to 
aggregate the data
>
> On 11/25/2011 02:35 AM, Gregoire Banderet wrote:
>> Hi,
>>
>> I'm not profiling my QNX executable. I'm implementing a feature for a client. The timings values are then reported to
 a Windows IDE through TCP/IP.
>> The QNX executable is a multi-threaded virtual machine running the customer's PLC application. Our customers want to 
do some profiling of their application executed by the Virtual machine running on QNX.
>>
>> That means I need timings values of a granularity of 1 microseconds and this profiling feature must not increase the 
CPU load (1 or 2 percent of CPU power is acceptable).
>> The system profiler is not available in customer site.
>>
>> Is there any way to use the tracing API in order to gather threads data? Is there events for the start and end of 
execution for every threads?
>>
>> -- Greg
>>
>>> -----Message d'origine-----
>>> De : Elena Laskavaia [mailto:community-noreply@qnx.com]
>>> Envoyé : Thursday, November 24, 2011 19:11
>>> À : ostech-core_os
>>> Objet : Re: Number of CPU cycles used by a thread
>>>
>>> You can use system profiler, it will do a tracing with resolution of clockcycles,
>>> it has view that can aggregate data per thread on selected region
>>>
>>> On 11/24/2011 09:24 AM, Gregoire Banderet wrote:
>>>> Hi,
>>>>
>>>> I eventually have some time to look into this...
>>>>
>>>> I followed the QNX documentation under "Controlling processes via the
>>>> /proc filesystem", and I use open/devctl, DCMD_PROC_STATUS and the
>>> member procfs_status.sutime.
>>>> Unfortunately sutime increases by step of the cycle time value :-(
>>>> That means I cannot reach the granularity (1 microseconds) I need...
>>>>
>>>> -- Greg
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>>
>>>> OSTech
>>>> http://community.qnx.com/sf/go/post90277
>>>>
>>>
>>>
>>> _______________________________________________
>>>
>>> OSTech
>>> http://community.qnx.com/sf/go/post90287
>>>
>>
>> Please be advised that this email may contain confidential
>> information.  If you are not the intended recipient, please notify us
>> by email by replying to the sender and delete this message.  The
>> sender disclaims that the content of this email constitutes an offer
>> to enter into, or the acceptance of, any agreement; provided that the
>> foregoing does not invalidate the binding effect of any digital or
>> other electronic reproduction of a manual signature that is included
>> in any attachment.
>>
>>
>>
>>
>>
>> _______________________________________________
>>
>> OSTech
>> http://community.qnx.com/sf/go/post90295
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post90303

-- 
cburgess@qnx.com
RE: Number of CPU cycles used by a thread  
The VM takes the measurements, not a program running inside the VM.
Every 250us the VM executes a program and I would like to know how many CPU cycles were used for the execution of this 
program.

The VM is really not an issue, I talked about it to explain the situation at customer's site.
I'll look at TraceEvent API.

-- Greg

> -----Message d'origine-----
> De : Colin Burgess [mailto:community-noreply@qnx.com]
> Envoyé : Friday, November 25, 2011 17:57
> À : ostech-core_os
> Objet : Re: Number of CPU cycles used by a thread
> 
> Please note that trying to take accurate timing measurements in a VM is not
> going to work very well!
> 
> On 11-11-25 11:53 AM, Elena Laskavaia wrote:
> > If you customer running instrumented kernel you can hook in to
> > tracelogger API. You would need to enable events on when thread
> > start/stop running and start tracelogging from the code of your
> > utility, then run custom "traceprinter" to aggregate the data
> >
> > On 11/25/2011 02:35 AM, Gregoire Banderet wrote:
> >> Hi,
> >>
> >> I'm not profiling my QNX executable. I'm implementing a feature for a
> client. The timings values are then reported to a Windows IDE through
> TCP/IP.
> >> The QNX executable is a multi-threaded virtual machine running the
> customer's PLC application. Our customers want to do some profiling of their
> application executed by the Virtual machine running on QNX.
> >>
> >> That means I need timings values of a granularity of 1 microseconds and
> this profiling feature must not increase the CPU load (1 or 2 percent of CPU
> power is acceptable).
> >> The system profiler is not available in customer site.
> >>
> >> Is there any way to use the tracing API in order to gather threads data? Is
> there events for the start and end of execution for every threads?
> >>
> >> -- Greg
> >>
> >>> -----Message d'origine-----
> >>> De : Elena Laskavaia [mailto:community-noreply@qnx.com]
> >>> Envoyé : Thursday, November 24, 2011 19:11 À : ostech-core_os Objet
> >>> : Re: Number of CPU cycles used by a thread
> >>>
> >>> You can use system profiler, it will do a tracing with resolution of
> >>> clockcycles, it has view that can aggregate data per thread on
> >>> selected region
> >>>
> >>> On 11/24/2011 09:24 AM, Gregoire Banderet wrote:
> >>>> Hi,
> >>>>
> >>>> I eventually have some time to look into this...
> >>>>
> >>>> I followed the QNX documentation under "Controlling processes via
> >>>> the /proc filesystem", and I use open/devctl, DCMD_PROC_STATUS
> and
> >>>> the
> >>> member procfs_status.sutime.
> >>>> Unfortunately sutime increases by step of the cycle time value :-(
> >>>> That means I cannot reach the granularity (1 microseconds) I need...
> >>>>
> >>>> -- Greg
> >>>>
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>>
> >>>> OSTech
> >>>> http://community.qnx.com/sf/go/post90277
> >>>>
> >>>
> >>>
> >>> _______________________________________________
> >>>
> >>> OSTech
> >>> http://community.qnx.com/sf/go/post90287
> >>>
> >>
> >> Please be advised that this email may contain confidential
> >> information.  If you are not the intended recipient, please notify us
> >> by email by...
View Full Message