public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: eranian@gmail.com
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Robert Richter <robert.richter@amd.com>,
	Paul Mackerras <paulus@samba.org>,
	Andi Kleen <andi@firstfloor.org>,
	Maynard Johnson <mpjohn@us.ibm.com>, Carl Love <cel@us.ibm.com>,
	Corey J Ashford <cjashfor@us.ibm.com>,
	Philip Mucci <mucci@eecs.utk.edu>,
	Dan Terpstra <terpstra@eecs.utk.edu>,
	perfmon2-devel <perfmon2-devel@lists.sourceforge.net>,
	Michael Kerrisk <mtk.manpages@googlemail.com>,
	oleg <oleg@redhat.com>
Subject: Re: perf_counters issue with self-sampling threads
Date: Wed, 29 Jul 2009 14:19:08 +0200	[thread overview]
Message-ID: <1248869948.6987.3083.camel@twins> (raw)
In-Reply-To: <7c86c4470907270951i48886d56g90bc198f26bb0716@mail.gmail.com>

On Mon, 2009-07-27 at 18:51 +0200, stephane eranian wrote:
> I believe there is a problem with the current perf_counters (PCL)
> code for self-sampling threads. The problem is related to sample
> notifications via signal.
> 
> PCL (just like perfmon) is using SIGIO, an asynchronous signal,
> to notify user applications of the availability of data in the event
> buffer.
> 
> POSIX does not mandate that asynchronous signals be delivered
> to the thread in which they originated. Any thread in the process
> may process the signal, assuming it does not have the signal
> blocked.

This signal stuff makes my head spin a little, however:

fcntl(2) for F_SETOWN says:

If a non-zero value is given to F_SETSIG  in  a  multi‐ threaded
process running with a threading library that supports thread groups
(e.g., NPTL),  then  a  positive value  given  to  F_SETOWN  has  a
different  meaning: instead of being a process ID identifying a whole
pro‐ cess,  it  is a thread ID identifying a specific thread within a
process.  Consequently, it may be necessary to pass  F_SETOWN  the
result of gettid(2) instead of get‐ pid(2) to get sensible results
when F_SETSIG  is  used.  (In  current  Linux  threading
implementations, a main thread’s thread ID is the same as its process
ID.  This means  that  a  single-threaded program can equally use
gettid(2) or getpid(2) in this scenario.)   Note,  how‐ ever,  that
the  statements  in  this paragraph do not apply to the SIGURG signal
generated  for  out-of-band data  on a socket: this signal is always
sent to either a process or a process group, depending  on  the  value
given  to  F_SETOWN.   Note  also  that Linux imposes a limit on the
number of real-time signals  that  may  be queued  to  a  process (see
getrlimit(2) and signal(7)) and if this limit is reached, then the
kernel  reverts to  delivering  SIGIO,  and this signal is delivered
to the entire process rather than to a specific thread.


Which seems to imply that when we feed fcntl(F_SETOWN) a TID instead of
a PID it should deliver SIGIO to the thread instead of the whole process
-- which, to me, seems a sane semantic.

However, 

  kill_fasync(SIGIO)
    __kill_fasync()
      send_sigio()
	/* if pid_type is a PIDTYPE_PID and pid a TID this should
           only iterate the one thread, I think */
        do_each_pid_task() {
          send_sigio_to_task();
        } while_each_pid_task();

where:

  send_sigio_to_task()
    group_send_sig_info()
      __group_send_sig_info()
        send_signal(.group = 1) /* uh-ow trouble */
          __send_signal()
            if (group)
               pending = &t->signal->shared_pending

which will result in the signal being send to the whole process anyway.


Now I was considering teaching send_sigio_to_task() to use
specific_send_sig_info() when fown->pid != fown->group_leader->pid or
something, but I'm not sure that won't break anything.

Alternatively, I've missed a detail and I either read the manpage wrong,
or the code, or both of them.




  parent reply	other threads:[~2009-07-29 12:16 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27 16:51 perf_counters issue with self-sampling threads stephane eranian
2009-07-27 16:56 ` Peter Zijlstra
2009-07-27 21:25 ` Andi Kleen
     [not found]   ` <7c86c4470907272213w2ee57080re50dd22a4d73a7e0@mail.gmail.com>
2009-07-28  8:51     ` stephane eranian
2009-07-28  8:56       ` Andi Kleen
2009-07-28  9:13         ` stephane eranian
2009-08-04 16:09     ` stephane eranian
2009-07-29 12:19 ` Peter Zijlstra [this message]
2009-07-29 12:37   ` stephane eranian
2009-07-29 12:46     ` Peter Zijlstra
2009-07-29 22:17   ` Oleg Nesterov
2009-07-30 11:31     ` Peter Zijlstra
2009-07-30 19:20       ` Oleg Nesterov
2009-07-30 20:00         ` Peter Zijlstra
2009-07-30 20:28           ` Oleg Nesterov
2009-07-30 21:09             ` stephane eranian
2009-07-31  8:35             ` [RFC][PATCH] fcntl: F_[SG]ETOWN_TID Peter Zijlstra
2009-07-31 14:01               ` stephane eranian
2009-07-31 20:52               ` Oleg Nesterov
2009-07-31 21:11               ` Andrew Morton
2009-08-01  1:27                 ` [PATCH 0/2] send_sigio/do_send_sig_info (Was: [RFC][PATCH] fcntl: F_[SG]ETOWN_TID) Oleg Nesterov
2009-08-03 15:48                   ` [PATCH 3/2] fcntl: F_[SG]ETOWN_TID Peter Zijlstra
2009-08-03 17:16                     ` Oleg Nesterov
2009-08-03 17:47                       ` Peter Zijlstra
2009-08-03 18:06                         ` Oleg Nesterov
2009-08-03 18:36                           ` Peter Zijlstra
2009-08-03 19:02                             ` Oleg Nesterov
2009-08-04 11:39                               ` [PATCH 3/2 -v3] fcntl: F_[SG]ETOWN_EX Peter Zijlstra
2009-08-04 16:20                                 ` Oleg Nesterov
2009-08-04 16:52                                   ` Peter Zijlstra
2009-08-04 17:19                                     ` Oleg Nesterov
2009-08-06 13:14                                       ` [PATCH 3/2 -v4] " Peter Zijlstra
2009-08-06 19:05                                         ` Oleg Nesterov
2009-08-07 12:10                                           ` stephane eranian
2009-08-01  1:28                 ` [PATCH 1/2] signals: introduce do_send_sig_info() helper Oleg Nesterov
2009-08-01  1:28                 ` [PATCH 2/2] signals: send_sigio: use do_send_sig_info() to avoid check_kill_permission() Oleg Nesterov
2009-08-03 12:53                 ` [RFC][PATCH] fcntl: F_[SG]ETOWN_TID stephane eranian
2009-08-09  5:46                   ` F_SETOWN_TID: F_SETOWN was thread-specific for a while Jamie Lokier
2009-08-10 12:22                     ` stephane eranian
2009-08-10 17:03                       ` Oleg Nesterov
2009-08-10 21:01                         ` stephane eranian
2009-08-17 17:16                           ` Oleg Nesterov
2009-08-17 17:40                             ` Oleg Nesterov
2009-08-17 22:26                             ` stephane eranian
2009-08-18 11:45                               ` Oleg Nesterov
2009-08-20 10:00                                 ` stephane eranian
2009-08-11 13:10                         ` Jamie Lokier
2009-08-17 17:05                           ` Oleg Nesterov
2009-08-03 15:21                 ` [RFC][PATCH] fcntl: F_[SG]ETOWN_TID Peter Zijlstra

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=1248869948.6987.3083.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=cel@us.ibm.com \
    --cc=cjashfor@us.ibm.com \
    --cc=eranian@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mpjohn@us.ibm.com \
    --cc=mtk.manpages@googlemail.com \
    --cc=mucci@eecs.utk.edu \
    --cc=oleg@redhat.com \
    --cc=paulus@samba.org \
    --cc=perfmon2-devel@lists.sourceforge.net \
    --cc=robert.richter@amd.com \
    --cc=terpstra@eecs.utk.edu \
    --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