* linux missing support for _POSIX_THREAD_CPUTIME? @ 2009-05-27 16:46 Chris Friesen 2009-05-27 16:56 ` Thomas Gleixner 2009-05-27 17:00 ` linux missing support for _POSIX_THREAD_CPUTIME ? Chris Friesen 0 siblings, 2 replies; 7+ messages in thread From: Chris Friesen @ 2009-05-27 16:46 UTC (permalink / raw) To: linux-kernel, tglx Hi all, POSIX defines optional support for clock ID values obtained by invoking pthread_getcpuclockid(). When passed to clock_gettime(), this allows the caller to request the CPU-time clock of an arbitrary thread within the same process as the caller. It appears that linux doesn't support this functionality--is that correct? Is there any plan to enable this? Is there any current way to obtain the runtime of a particular thread without knowing its tid (since the thread_id to tid mapping is known only to glibc)? Thanks, Chris ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: linux missing support for _POSIX_THREAD_CPUTIME? 2009-05-27 16:46 linux missing support for _POSIX_THREAD_CPUTIME? Chris Friesen @ 2009-05-27 16:56 ` Thomas Gleixner 2009-05-27 17:14 ` Chris Friesen 2009-05-27 17:49 ` Roland McGrath 2009-05-27 17:00 ` linux missing support for _POSIX_THREAD_CPUTIME ? Chris Friesen 1 sibling, 2 replies; 7+ messages in thread From: Thomas Gleixner @ 2009-05-27 16:56 UTC (permalink / raw) To: Chris Friesen; +Cc: LKML, Ulrich Drepper, Roland McGrath On Wed, 27 May 2009, Chris Friesen wrote: That's more a question for the glibc folks. CC'ed. > Hi all, > > POSIX defines optional support for clock ID values obtained by invoking > pthread_getcpuclockid(). When passed to clock_gettime(), this allows > the caller to request the CPU-time clock of an arbitrary thread within > the same process as the caller. > > It appears that linux doesn't support this functionality--is that > correct? Is there any plan to enable this? > > Is there any current way to obtain the runtime of a particular thread > without knowing its tid (since the thread_id to tid mapping is known > only to glibc)? > > Thanks, > > Chris > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: linux missing support for _POSIX_THREAD_CPUTIME? 2009-05-27 16:56 ` Thomas Gleixner @ 2009-05-27 17:14 ` Chris Friesen 2009-05-27 17:36 ` Thomas Gleixner 2009-05-27 17:49 ` Roland McGrath 1 sibling, 1 reply; 7+ messages in thread From: Chris Friesen @ 2009-05-27 17:14 UTC (permalink / raw) To: Thomas Gleixner; +Cc: LKML, Ulrich Drepper, Roland McGrath Thomas Gleixner wrote: > On Wed, 27 May 2009, Chris Friesen wrote: > > That's more a question for the glibc folks. CC'ed. Actually, I'm looking at the kernel code here. It looks like posix_cpu_clock_get() should be able to handle a per-task cpu clock for another thread within the same process. However, it's only ever called by thread_cpu_clock_get(), which hardcodes a clock_id of THREAD_CLOCK, which corresponds to the current thread. Similarly, invalid_clockid() will say that the clock_id is invalid if it's positive but greater than 15. If my math is right, this means that any pid > 2 will result in invalid_clockid() failing. Chris ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: linux missing support for _POSIX_THREAD_CPUTIME? 2009-05-27 17:14 ` Chris Friesen @ 2009-05-27 17:36 ` Thomas Gleixner 2009-05-27 20:00 ` Chris Friesen 0 siblings, 1 reply; 7+ messages in thread From: Thomas Gleixner @ 2009-05-27 17:36 UTC (permalink / raw) To: Chris Friesen; +Cc: LKML, Ulrich Drepper, Roland McGrath On Wed, 27 May 2009, Chris Friesen wrote: > Thomas Gleixner wrote: > > On Wed, 27 May 2009, Chris Friesen wrote: > > > > That's more a question for the glibc folks. CC'ed. > > Actually, I'm looking at the kernel code here. It looks like > posix_cpu_clock_get() should be able to handle a per-task cpu clock for > another thread within the same process. However, it's only ever called > by thread_cpu_clock_get(), which hardcodes a clock_id of THREAD_CLOCK, > which corresponds to the current thread. No, it's also called via the CLOCK_DISPATCH magic in posix_timers.c > Similarly, invalid_clockid() will say that the clock_id is invalid if > it's positive but greater than 15. If my math is right, this means that > any pid > 2 will result in invalid_clockid() failing. posix_cpu_clock_get() does: const pid_t pid = CPUCLOCK_PID(which_clock); CPUCLOCK_PID is defined as: #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) include/linux/posix-timers.h has the helper macros to build the clock_id value for posix_cpu_clock_get() #define MAKE_PROCESS_CPUCLOCK(pid, clock) \ ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) #define MAKE_THREAD_CPUCLOCK(tid, clock) \ MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) Hope that helps, tglx ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: linux missing support for _POSIX_THREAD_CPUTIME? 2009-05-27 17:36 ` Thomas Gleixner @ 2009-05-27 20:00 ` Chris Friesen 0 siblings, 0 replies; 7+ messages in thread From: Chris Friesen @ 2009-05-27 20:00 UTC (permalink / raw) To: Thomas Gleixner; +Cc: LKML, Ulrich Drepper, Roland McGrath Thomas Gleixner wrote: > On Wed, 27 May 2009, Chris Friesen wrote: > > >>Thomas Gleixner wrote: >> >>>On Wed, 27 May 2009, Chris Friesen wrote: >>> >>>That's more a question for the glibc folks. CC'ed. >> >>Actually, I'm looking at the kernel code here. It looks like >>posix_cpu_clock_get() should be able to handle a per-task cpu clock for >>another thread within the same process. However, it's only ever called >>by thread_cpu_clock_get(), which hardcodes a clock_id of THREAD_CLOCK, >>which corresponds to the current thread. > > > No, it's also called via the CLOCK_DISPATCH magic in posix_timers.c >>Similarly, invalid_clockid() will say that the clock_id is invalid if >>it's positive but greater than 15. If my math is right, this means that >>any pid > 2 will result in invalid_clockid() failing. Both invalid_clockid() and CLOCK_DISPATCH assume that the clock_id will be negative in order to call posix_cpu_clock_get(). In pthread_getcpuclockid() in glibc, I couldn't see how we were ending up with a negative clock_id. However, I finally clued in to the fact that there are multiple implementations of this function, and in one code path in one of the implementations we call MAKE_THREAD_CPUCLOCK() which can result in a negative clock_id. Thanks for the help. Chris ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: linux missing support for _POSIX_THREAD_CPUTIME? 2009-05-27 16:56 ` Thomas Gleixner 2009-05-27 17:14 ` Chris Friesen @ 2009-05-27 17:49 ` Roland McGrath 1 sibling, 0 replies; 7+ messages in thread From: Roland McGrath @ 2009-05-27 17:49 UTC (permalink / raw) To: Thomas Gleixner; +Cc: Chris Friesen, LKML, Ulrich Drepper > POSIX defines optional support for clock ID values obtained by invoking > pthread_getcpuclockid(). When passed to clock_gettime(), this allows > the caller to request the CPU-time clock of an arbitrary thread within > the same process as the caller. > > It appears that linux doesn't support this functionality--is that > correct? Is there any plan to enable this? glibc does implement pthread_getcpuclockid using the kernel support for it. It uses MAKE_THREAD_CPUCLOCK(tid, CPUCLOCK_SCHED) (see linux/posix-timers.h). > Is there any current way to obtain the runtime of a particular thread > without knowing its tid (since the thread_id to tid mapping is known > only to glibc)? You need a tid to construct the clock ID with MAKE_THREAD_CPUCLOCK(). The pthread_getcpuclockid function exists to do this for you when you are using pthreads. If you are not using pthreads, then certainly you have to figure out what a thread's tid is yourself. Thanks, Roland ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: linux missing support for _POSIX_THREAD_CPUTIME ? 2009-05-27 16:46 linux missing support for _POSIX_THREAD_CPUTIME? Chris Friesen 2009-05-27 16:56 ` Thomas Gleixner @ 2009-05-27 17:00 ` Chris Friesen 1 sibling, 0 replies; 7+ messages in thread From: Chris Friesen @ 2009-05-27 17:00 UTC (permalink / raw) To: tglx; +Cc: linux-kernel Chris Friesen wrote: > It appears that linux doesn't support this functionality--is that > correct? Is there any plan to enable this? In particular, it seems to fail the invalid_clockid() test. Is that function expecting the clock ID to be negative for this case? Thanks, Chris ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-05-27 20:00 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-05-27 16:46 linux missing support for _POSIX_THREAD_CPUTIME? Chris Friesen 2009-05-27 16:56 ` Thomas Gleixner 2009-05-27 17:14 ` Chris Friesen 2009-05-27 17:36 ` Thomas Gleixner 2009-05-27 20:00 ` Chris Friesen 2009-05-27 17:49 ` Roland McGrath 2009-05-27 17:00 ` linux missing support for _POSIX_THREAD_CPUTIME ? Chris Friesen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox