linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* 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; 156+ 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] 156+ messages in thread
* Re: Alan Cox quote? (was: Re: accounting for threads)
@ 2001-06-19 19:48 Joerg Pommnitz
  2001-06-19 19:59 ` Alexander Viro
  0 siblings, 1 reply; 156+ messages in thread
From: Joerg Pommnitz @ 2001-06-19 19:48 UTC (permalink / raw)
  To: linux-kernel

 > But that foregoes the point that the code is far more complex and
 > harder to make 'obviously correct', a concept that *does* translate
 > well to userspace.

Check the state threads library from SGI:
http://oss.sgi.com/projects/state-threads/

It should provide the code clarity one is used from
"real" threads and the efficiency of a state machine.

Regards
  Joerg



=====
-- 
Regards
       Joerg


__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/

^ permalink raw reply	[flat|nested] 156+ messages in thread
* Re: Alan Cox quote? (was: Re: accounting for threads)
@ 2001-06-20 19:36 Rok Papež
  2001-06-20 20:16 ` Cort Dougan
  0 siblings, 1 reply; 156+ messages in thread
From: Rok Papež @ 2001-06-20 19:36 UTC (permalink / raw)
  To: linux-kernel

Hi!

It's hard not to reply to this kind of message but there is so much
"anti-thread hype" here that someone obviously has to stand up to it.
This reply isn't aimed just at Larry but at all the anti-thread-rant
people with 0 threads == 0 problems attitude.

On Tuesday 19 June 2001 18:09, Larry McVoy wrote:
>     "If you think you need threads then your processes are too fat"
>     ``Think of it this way: threads are like salt, not like pasta. You
>     like salt, I like salt, we all like salt. But we eat more pasta.''

Here are more from the same basket you obviously got the first quote from:

------------------------------------
Virtual memory is only for unskilled programmers who don't know how to use
overlays.
------------------------------------
Protected memory is a constant 10% CPU hog needed only by undisciplined
programmers who can't keep their memory writes in their own process space.
------------------------------------

> Threads are a really bad idea.

I could *say* the same about Alans co-routines and Async IO :-). But it
would be foolish of me to criticize something I haven't used.

There is more than one way how to skin a dinosaur. And threads are one
way of doing it. You don't like it ? FINE. But don't go bashing it.

Probably most people bash threads becouse of a silly way POSIX designed
(designed is an overstatement) their pthread API and becouse UNIX was
around before threads thus probably making every UNIX thread support a
hacked and not a designed tool.
Other OSes have certainly proven threads to be nice and usable.

And here is another one for you quotes page:
------------------------------------
If you can't stick your head out of your own backyard please... don't
go and crtiticize the world... :-)
------------------------------------

-- 
best regards,
Rok Papež.

^ permalink raw reply	[flat|nested] 156+ messages in thread
* Re: Alan Cox quote? (was: Re: accounting for threads)
@ 2001-06-22  5:19 Chester Lott
  0 siblings, 0 replies; 156+ messages in thread
From: Chester Lott @ 2001-06-22  5:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: rok.papez

Rok papez <rok.papez@kiss.uni-lj.si> wrote:
>On Tuesday 19 June 2001 18:09, Larry McVoy wrote:
>> "If you think you need threads then your processes are too fat"
>> ``Think of it this way: threads are like salt, not like pasta You
>> like salt, I like salt, we all like salt. But we eat more pasta.''

> Here are more from the same basket you obviously got the first 
> quote from:
[SNIP]
> Protected memory is a constant 10% CPU hog needed only by
undisciplined
> programmers who can't keep their memory writes in their own process
space.

Now that's the primary reason to avoid threads, IMO.  People
spent years trying to get protected memory; the only real
difference between threads and processes is that you throw
protected memory out the window.  Yes, the pthread API sucks;
yes, there are times when threads are appropriate.

If only:
1) Microsoft, Sun, and others didn't have such abysmal
context switch numbers that people view threads vs. 
processes as a performance argument;
2) MS didn't conflate fork() and exec() into one 
CreateProcess() call; and
3) Java and others exposed rational event-driven APIs that
didn't require multiple contexts of execution in weird places
(1.4 is finally fixing this one anyway)

then people might be able to really see that:
1) You usually don't need that many contexts of execution; and
2) Processes should be considered the primary COEs and threads
only used when you really need to share almost all of your
memory.

That's aside from all the arguments against multithreading
just based on elegance and code correctness POVs.  Even if
writing multithreaded code is marginally easier than writing
poll()-based code, actually debugging it is a royal PITA.
Coroutines (which aren't Alan's, Knuth had them long before
Alan and even he was just rehashing old news) and state
machines really are better in many cases.

About the only criticism I have of Alan's statement that
"threads are for people who can't program state machines" is
the implication that threads are an easier API to get right.
They aren't.  They seem that way, but by tossing protected
memory and introducing multiple COEs you get into a whole
world of non-obvious problems that are very difficult to
debug and often nearly impossible to reproduce in 
non-production environments.

The salt quote I like; it allows for the sparing use of
threads, but warns against their over(ab)use.

Ah, well.

  Sumner

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

^ permalink raw reply	[flat|nested] 156+ messages in thread
[parent not found: <Pine.GSO.4.21.0106211931180.209-100000@weyl.math.psu.edu.suse.lists.linux.kernel>]
* Re: Alan Cox quote? (was: Re: accounting for threads)
@ 2001-06-30  9:16 Jan Hudec
  0 siblings, 0 replies; 156+ messages in thread
From: Jan Hudec @ 2001-06-30  9:16 UTC (permalink / raw)
  To: linux-kernel

Hello,

> I am happy that processes in Linux are so marvelous. Linux does not need
> a decent POSIX threads implementation because the same functionality can
> be achived with processes. Do what you like, you write the kernel code.
> I could write my soft using fork special fetaures in Linux.
> But I want it to be portable. If threads in linux are so bad, it is bad
> luck for me. I will go slow. It its the only portable way todo afordable
> shared memory threading without filling your program of shm-xxxx.

AFAIK, there is a POSIX thread library (libpthread) for Linux, that wraps
clone calls in a way portable to other unices. It uses processes (with memory
sharing) from kernel point of view, but should look like POSIX threads from
application point of view.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

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

end of thread, other threads:[~2001-06-30  9:16 UTC | newest]

Thread overview: 156+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-19 14:53 accounting for threads Dan Kegel
2001-06-19 14:57 ` J . A . Magallon
2001-06-19 15:44 ` ognen
2001-06-19 15:58   ` Alan Cox quote? (was: Re: accounting for threads) Dan Kegel
2001-06-19 16:02     ` Ben Pfaff
2001-06-19 16:09     ` Larry McVoy
2001-06-19 16:26       ` Matthew Kirkwood
2001-06-19 16:52         ` Larry McVoy
2001-06-19 18:18           ` Rob Landley
2001-06-19 23:31           ` Timur Tabi
2001-06-20 11:52             ` Rob Landley
2001-06-20 21:20               ` Albert D. Cahalan
2001-06-20 18:12                 ` Rob Landley
2001-06-20 23:28                   ` Dan Podeanu
2001-06-21  0:42                   ` D. Stimits
2001-06-20 20:18                     ` Rob Landley
2001-06-21  1:57                       ` D. Stimits
2001-06-21 14:46                         ` Idea: Patches-from-linus mailing list? (Was Re: Alan Cox quote? (was: Re: accounting for threads)) Rob Landley
2001-06-21 14:02                   ` Alan Cox quote? (was: Re: accounting for threads) Jesse Pollard
2001-06-21 14:18                     ` Rob Landley
2001-06-22 14:46               ` Mikulas Patocka
2001-06-22 13:29                 ` Rob Landley
2001-06-24 21:41                   ` J . A . Magallon
2001-06-24 16:55                     ` Rob Landley
2001-06-24 22:30                       ` J . A . Magallon
2001-06-24 18:21                         ` Rob Landley
2001-06-25 13:48                           ` J . A . Magallon
2001-06-24 22:39                         ` Steven Walter
2001-06-24 23:50                         ` Larry McVoy
2001-06-24 20:24                           ` Rob Landley
2001-06-25  0:05                           ` J . A . Magallon
2001-06-25  0:32                             ` Gerhard Mack
2001-06-25  0:59                               ` Davide Libenzi
2001-06-25  2:18                         ` Galen Hancock
2001-06-20 14:59           ` Matthias Urlichs
2001-06-20 19:14           ` Victor Yodaiken
2001-06-20 21:01           ` RE:Why use threads ( was: Alan Cox quote?) David Schwartz
2001-06-20 21:26             ` Why " Victor Yodaiken
2001-06-20 22:18               ` David Schwartz
2001-06-20 22:41                 ` Davide Libenzi
2001-06-20 22:47                   ` [OT] " Jeff Garzik
2001-06-21  0:21                   ` David Schwartz
2001-06-21  0:56                     ` Davide Libenzi
2001-06-21  1:32                       ` David Schwartz
2001-06-21  2:22                         ` Davide Libenzi
2001-06-21  2:43                           ` David Schwartz
2001-06-21 16:10                             ` Davide Libenzi
2001-06-21 19:55                               ` Marco Colombo
2001-06-20 22:43                 ` Mike Castle
2001-06-21  1:43                   ` David Schwartz
2001-06-19 17:10       ` Alan Cox quote? (was: Re: accounting for threads) Matti Aarnio
2001-06-19 17:20       ` Mike Castle
2001-06-19 17:37         ` Larry McVoy
2001-06-19 17:45           ` Mike Castle
2001-06-19 19:38             ` Georg Nikodym
2001-06-19 19:56               ` Michael Meissner
2001-06-19 17:53           ` Steve Underwood
2001-06-19 19:01             ` Alan Cox
2001-06-20  2:57               ` Michael Rothwell
2001-06-20  3:04                 ` Larry McVoy
2001-06-20  3:38                   ` John R Lenton
2001-06-20 10:21                   ` john slee
2001-06-20 18:08                     ` Larry McVoy
2001-06-20 16:21                   ` Davide Libenzi
2001-06-20  9:14                 ` Alan Cox
2001-06-22  2:36                   ` Michael Rothwell
2001-06-19 18:08           ` Georg Nikodym
2001-06-19 20:57       ` David S. Miller
2001-06-19 21:15         ` David S. Miller
2001-06-20  0:04         ` Chris Ricker
2001-06-20  0:59           ` Robert Love
2001-06-19 17:36     ` Jonathan Lundell
2001-06-19 17:41       ` Larry McVoy
2001-06-19 21:11       ` Jonathan Lundell
2001-06-19 23:56         ` Jonathan Lundell
2001-06-20  0:19           ` Mike Castle
2001-06-20  0:28             ` Larry McVoy
2001-06-20  1:30               ` Ben Greear
2001-06-20  2:14                 ` Mike Castle
2001-06-20  9:00               ` Henning P. Schmiedehausen
2001-06-20 11:25                 ` [OT] Threads, inelegance, and Java Aaron Lehmann
2001-06-20 11:25                   ` Rob Landley
2001-06-20 17:36                     ` Martin Dalecki
2001-06-20 19:27                       ` Mike Harrold
2001-06-20 17:46                         ` Rob Landley
2001-06-20 19:53                         ` Martin Dalecki
2001-06-20 17:53                           ` Rob Landley
2001-06-21  7:45                             ` Albert D. Cahalan
2001-06-20 20:16                         ` Pete Zaitcev
2001-06-20 22:05                           ` Alan Cox
     [not found]                     ` <20010621000725.A24672@werewolf.able.es>
2001-06-20 19:15                       ` Rob Landley
2001-06-21  3:13                       ` Pete Zaitcev
2001-06-21 13:59                         ` Rob Landley
2001-06-21  9:40                       ` Jonathan Morton
2001-06-21 16:48                     ` Adam Sampson
2001-06-20 15:12                   ` Ben Greear
2001-06-20 15:44                     ` Russell Leighton
2001-06-20 16:32                       ` Davide Libenzi
2001-06-20 16:54                         ` Russell Leighton
2001-06-20 17:03                         ` Tony Hoyle
2001-06-20 15:10                           ` Rob Landley
2001-06-20 20:23                             ` Tony Hoyle
2001-06-21  8:12                               ` Henning P. Schmiedehausen
2001-06-20 20:40                             ` Richard B. Johnson
2001-06-20 20:48                               ` Tony Hoyle
2001-06-20 21:00                               ` Daniel Phillips
2001-06-20 21:06                                 ` Richard B. Johnson
2001-06-20 18:14                         ` Henning P. Schmiedehausen
2001-06-20 16:53                     ` Larry McVoy
2001-06-20 12:36                       ` Rob Landley
2001-06-20 21:14                     ` Aaron Lehmann
2001-06-20 18:09                   ` Henning P. Schmiedehausen
2001-06-20 19:05                   ` William T Wilson
2001-06-19 16:02   ` Alan Cox quote? (was: Re: accounting for threads) David S. Miller
2001-06-19 16:12     ` Padraig Brady
2001-06-19 19:10     ` bert hubert
2001-06-19 19:18       ` Alan Cox
2001-06-19 19:32         ` bert hubert
2001-06-19 19:43         ` Alexander Viro
2001-06-20 15:22         ` Jes Sorensen
2001-06-20 15:33           ` Alexander Viro
2001-06-20 15:59             ` Threads are processes that share more bert hubert
2001-06-20 16:15               ` Alexander Viro
2001-06-20 18:48               ` Martin Devera
2001-06-20 19:19                 ` Unknown PCI Net Device Greg Ingram
2001-06-20 22:53                   ` Andreas Dilger
2001-06-20 22:56                     ` Jeff Garzik
2001-06-20 23:00                     ` Alan Cox
2001-06-20 22:08               ` Threads are processes that share more Stephen Satchell
2001-06-20 22:14                 ` ognen
2001-06-20 23:10                 ` J . A . Magallon
2001-06-24 23:47                   ` Larry McVoy
2001-06-25  2:23                   ` David S. Miller
2001-06-20 16:39             ` Alan Cox quote? (was: Re: accounting for threads) george anzinger
2001-06-20 18:35               ` Alexander Viro
2001-06-21  4:11                 ` Rusty Russell
2001-06-21 23:37                   ` Alexander Viro
2001-06-21 23:55                     ` Alexander Viro
2001-06-22 14:53                     ` Richard Gooch
2001-06-20 16:40             ` Jes Sorensen
2001-06-20 20:09             ` Rob Landley
2001-06-20 19:05         ` Victor Yodaiken
2001-06-20 14:35       ` Mike Porter
2001-06-20 11:56         ` Rob Landley
2001-06-19 18:01   ` Alan Cox quote? Kai Henningsen
2001-06-19 18:49     ` Larry McVoy
2001-06-19 20:12     ` Henning P. Schmiedehausen
2001-06-19 21:12     ` Richard Gooch
2001-06-19 22:50       ` Henning P. Schmiedehausen
2001-06-19 19:48 Alan Cox quote? (was: Re: accounting for threads) Joerg Pommnitz
2001-06-19 19:59 ` Alexander Viro
2001-06-20 19:36 Rok Papež
2001-06-20 20:16 ` Cort Dougan
2001-06-22  5:19 Chester Lott
     [not found] <Pine.GSO.4.21.0106211931180.209-100000@weyl.math.psu.edu.suse.lists.linux.kernel>
2001-06-22  7:33 ` Andi Kleen
2001-06-30  9:16 Jan Hudec

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