linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* accounting for threads
@ 2001-06-13 22:19 J . A . Magallon
  0 siblings, 0 replies; 4+ messages in thread
From: J . A . Magallon @ 2001-06-13 22:19 UTC (permalink / raw)
  To: Lista Linux-Kernel

Hi.

First, sorry if this is a glibc issue. Just chose to ask here first.

I want to know the CPU time used by a POSIX-threaded program. I have tried
to use getrusage() with RUSAGE_SELF and RUSAGE_CHILDREN. Problem:
main thread just do nothing, spawns children and waits. And I get always
0 ru_utime.

I guess it can be because of 2 things:

- RUSAGE_CHILDREN only works for fork()'ed children (although in linux threads
and processes are the same). Perhaps fork() sets some kind of flag in
clone() for accounting.

- AFAIK, linux puts an intermediate 'thread controller'. That controller
uses no CPU time, and RUSAGE_CHILDREN gets only the first children level.

Any suggestion to mesaure threads CPU time ? I can't manage only with
wall-time, because I'm not sure to have all the box just for me.
And I would like also to mesaure system time to evaluate contention.

TIA

-- 
J.A. Magallon                           #  Let the source be with you...        
mailto:jamagallon@able.es
Linux Mandrake release 8.1 (Cooker) for i586
Linux werewolf 2.4.5-ac13 #1 SMP Sun Jun 10 21:42:28 CEST 2001 i686

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

* re: accounting for threads
  2001-06-19 14:53 Dan Kegel
  2001-06-19 14:57 ` J . A . Magallon
@ 2001-06-19 15:44 ` ognen
  1 sibling, 0 replies; 4+ messages in thread
From: ognen @ 2001-06-19 15:44 UTC (permalink / raw)
  To: Dan Kegel; +Cc: linux-kernel

On an unrelated note:

I noticed the quote below in your message. Is this a true quote or just a
joke going around? I have tried believing it is just a joke but I am
scared it is not.

Best regards,
Ognen

On Tue, 19 Jun 2001, Dan Kegel wrote:

[reply snipped]

>
>--
> "A Computer is a state machine.
>  Threads are for people who can't program state machines."
>	- Alan Cox








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

* Re: accounting for threads
  2001-06-19 14:53 Dan Kegel
@ 2001-06-19 14:57 ` J . A . Magallon
  2001-06-19 15:44 ` ognen
  1 sibling, 0 replies; 4+ messages in thread
From: J . A . Magallon @ 2001-06-19 14:57 UTC (permalink / raw)
  To: Dan Kegel; +Cc: jamagallon, linux-kernel @ vger . kernel . org


On 20010619 Dan Kegel wrote:
>
>Let me know if this helps.  And anyone else, let me know if there's a simpler
>way to do this.  Should LinuxThreads be doing this under the hood, so it can
>be a little closer to posix threads compliance?
>- Dan

He, I have just discovered that IRIX 6.2 times(2) also fails to account time for
threads. 6.4 works fine.

-- 
J.A. Magallon                           #  Let the source be with you...        
mailto:jamagallon@able.es
Linux Mandrake release 8.1 (Cooker) for i586
Linux werewolf 2.4.5-ac15 #2 SMP Sun Jun 17 02:12:45 CEST 2001 i686

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

* re: accounting for threads
@ 2001-06-19 14:53 Dan Kegel
  2001-06-19 14:57 ` J . A . Magallon
  2001-06-19 15:44 ` ognen
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Kegel @ 2001-06-19 14:53 UTC (permalink / raw)
  To: jamagallon, linux-kernel

"J . A . Magallon" <jamagallon@able.es> wrote:
> I want to know the CPU time used by a POSIX-threaded program. I have tried
> to use getrusage() with RUSAGE_SELF and RUSAGE_CHILDREN. Problem:
> main thread just do nothing, spawns children and waits. And I get always
> 0 ru_utime.
> 
> I guess it can be because of 2 things:
> 
> - RUSAGE_CHILDREN only works for fork()'ed children (although in linux threads
> and processes are the same). Perhaps fork() sets some kind of flag in
> clone() for accounting.
> 
> - AFAIK, linux puts an intermediate 'thread controller'. That controller
> uses no CPU time, and RUSAGE_CHILDREN gets only the first children level.
> 
> Any suggestion to mesaure threads CPU time ? I can't manage only with
> wall-time, because I'm not sure to have all the box just for me.
> And I would like also to mesaure system time to evaluate contention.

My post you replied to yesterday, subject "Re: getrusage vs /proc/pid/stat",
contains code that does what you want (it's also at http://www.kegel.com/lt.tar.gz).  
To use it, declare a variable
  LinuxTimes lt;
have each thread call lt.addSelf() once; then to measure the total CPU time
used by all those threads as a group, call lt.times() instead of times().
(On Solaris, you can continue to just call times(), you don't need lt at all.)
lt.times() is a simulation of the classical times() system call for LinuxThreads.

Let me know if this helps.  And anyone else, let me know if there's a simpler
way to do this.  Should LinuxThreads be doing this under the hood, so it can
be a little closer to posix threads compliance?
- Dan

-- 
"A computer is a state machine.
 Threads are for people who can't program state machines."
         - Alan Cox

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

end of thread, other threads:[~2001-06-19 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-13 22:19 accounting for threads J . A . Magallon
2001-06-19 14:53 Dan Kegel
2001-06-19 14:57 ` J . A . Magallon
2001-06-19 15:44 ` ognen

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