From: torbenh <torbenh@gmx.de>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Dario Faggioli <raistlin@linux.it>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel <linux-kernel@vger.kernel.org>,
john.stultz@linaro.org, roland@redhat.com,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Stanislaw Gruszka <sgruszka@redhat.com>,
Dhaval Giani <dhaval.giani@gmail.com>,
Randy Dunlap <rdunlap@xenotime.net>
Subject: Re: [PATCH resend] Reading POSIX CPU timer from outside the process.
Date: Thu, 30 Dec 2010 18:45:29 +0100 [thread overview]
Message-ID: <20101230174529.GE2086@siel.b> (raw)
In-Reply-To: <20101229132130.GA16349@redhat.com>
On Wed, Dec 29, 2010 at 02:21:30PM +0100, Oleg Nesterov wrote:
> On 12/28, Dario Faggioli wrote:
> >
> > On Tue, 2010-12-28 at 17:38 +0100, Oleg Nesterov wrote:
> >
> > > > rcu_read_lock();
> > > > p = find_task_by_vpid(pid);
> > > > - if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
> > > > - same_thread_group(p, current) : has_group_leader_pid(p))) {
> > > > + if (!p || (CPUCLOCK_PERTHREAD(which_clock) &&
> > > > + same_thread_group(p, current) && !has_group_leader_pid(p)))
> > > > error = -EINVAL;
> > > > - }
> > > > rcu_read_unlock();
> > >
> > > How so? For example, with this change
> > > clock_getres(MAKE_THREAD_CPUCLOCK(pid_of_sub_thread)) won't work, no?
> > >
> > I tested all the clock_getres() calls that came to my mind (at least the
> > one that are possible from an userspace program), and they always worked
> > because of this (still in check_clock):
> >
> > const pid_t pid = CPUCLOCK_PID(which_clock);
> >
> > if (pid == 0)
> > return 0;
> >
> > Which triggers all the times,
>
> No, please note pid_of_sub_thread above.
>
> > The whole point was about, given the current implementation of
> > clock_getcpuclockid done by glibc, can we remove that "failed with
> > success" (showed in the changelog) thing and come up with some
> > meaningful clockid for that situation? It's more than possible for the
> > answer to be no!!! :-P
>
> I think we should change glibc if clock_getcpuclockid() doesn't work,
> please see below.
http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_getcpuclockid.3.html
this one works.
ok... it takes a pthread_t for identifying the thread.
but it works.
>
> > > I think, if we want to remove this limitation, we need something
> > > like the patch below. If it doesn't help, we should fix glibc.
> > >
> > > --- x/kernel/posix-cpu-timers.c
> > > +++ x/kernel/posix-cpu-timers.c
> > > @@ -39,10 +39,8 @@ static int check_clock(const clockid_t w
> > >
> > > rcu_read_lock();
> > > p = find_task_by_vpid(pid);
> > > - if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
> > > - same_thread_group(p, current) : has_group_leader_pid(p))) {
> > > + if (!p || !(CPUCLOCK_PERTHREAD(which_clock) || has_group_leader_pid(p)))
> > > error = -EINVAL;
> > > - }
> > > rcu_read_unlock();
> > >
> > Which won't work because CPUCLOCK_PERTHREAD(which_clock) is always false
> > in this case.
>
> I guess, this is because glibc passes MAKE_PROCESS_CLOCK() id, right?
> But we shouldn't add the hacks to the kernel to hide the limitations
> in glibc.
>
> > BTW, again, I see your point, the fix might need to happen at glibc
> > level. I'll check that and come back if I find something interesting.
>
> Yes, please.
>
>
> BTW. What is the test-case? I am looking at http://gitorious.org/clockid,
> I guess it is clockid.c...
>
> You do not need clock_getcpuclockid() at all. In fact I do not really
> understand what this helper should actually do, probably it is only
> needed to validate the pid. You can simply use MAKE_THREAD_CPUCLOCK()
> to sample a single thread via clock_gettime().
>
> IOW. Unless I missed something, with this patch, the only problem
> is that getcpuclockid() always assumes MAKE_PROCESS_CPUCLOCK(),
> I do not think this is the kernel problem.
>
> Oleg.
>
--
torben Hohn
next prev parent reply other threads:[~2010-12-30 17:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-23 16:21 [PATCH] Read THREAD_CPUTIME clock from other processes Dario Faggioli
2010-12-23 16:44 ` Oleg Nesterov
2010-12-23 17:38 ` Dario Faggioli
2010-12-23 18:12 ` Oleg Nesterov
2010-12-24 11:36 ` Dario Faggioli
2010-12-23 17:21 ` Randy Dunlap
2010-12-23 17:43 ` Dario Faggioli
2010-12-28 10:55 ` [PATCH resend] Reading POSIX CPU timer from outside the process Dario Faggioli
2010-12-28 16:38 ` Oleg Nesterov
2010-12-28 21:38 ` Dario Faggioli
2010-12-29 13:21 ` Oleg Nesterov
2010-12-29 14:10 ` Dario Faggioli
2010-12-29 18:30 ` Oleg Nesterov
2010-12-30 17:45 ` torbenh [this message]
2011-01-04 11:01 ` Dario Faggioli
2011-01-06 16:06 ` torbenh
2011-01-07 19:28 ` [PATCH] Read THREAD_CPUTIME clock from other processes Roland McGrath
2011-01-07 19:35 ` Oleg Nesterov
2011-01-07 19:50 ` Roland McGrath
2011-01-07 19:49 ` Oleg Nesterov
2011-01-07 19:58 ` Roland McGrath
2011-01-07 19:56 ` Peter Zijlstra
2011-01-08 11:12 ` Dario Faggioli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101230174529.GE2086@siel.b \
--to=torbenh@gmx.de \
--cc=dhaval.giani@gmail.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=raistlin@linux.it \
--cc=rdunlap@xenotime.net \
--cc=roland@redhat.com \
--cc=sgruszka@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox