public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Oleg Nesterov <oleg@redhat.com>
Cc: eranian@gmail.com, 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>,
	roland <roland@redhat.com>
Subject: Re: perf_counters issue with self-sampling threads
Date: Thu, 30 Jul 2009 13:31:25 +0200	[thread overview]
Message-ID: <1248953485.6391.41.camel@twins> (raw)
In-Reply-To: <20090729221703.GA25368@redhat.com>

On Thu, 2009-07-30 at 00:17 +0200, Oleg Nesterov wrote:
> (add Roland)

but you seem to have forgotten to actually edit the CC line, fixed
that ;-)

> On 07/29, Peter Zijlstra wrote:
> >
> > On Mon, 2009-07-27 at 18:51 +0200, stephane eranian wrote:
> > >
> > > 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.
> 
> Yes. I now nothing about POSIX, but this is what Linux does at least.
> I don't think we can/should change this behaviour.

Well, we have plenty exceptions to that rule already, we have itimer
extentions, tkill sys_rt_tgsigqueueinfo and plenty more..

> > 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.
> 
> Heh. Definitely this is not what Linux does ;)

Right, so the question is, did we ever? Why does the man page say this.

Looking at the .12 source (git start) we did:

  440 			if (!send_sig_info(fown->signum, &si, p))
  441 				break;
  442 		/* fall-through: fall back on the old plain SIGIO signal */
  443 		case 0:
  444 			send_group_sig_info(SIGIO, SEND_SIG_PRIV, p);

Which was 'corrected' in:

commit fc9c9ab22d5650977c417ef2032d02f455011b23
Author: Bharath Ramesh <bramesh@vt.edu>
Date:   Sat Apr 16 15:25:41 2005 -0700

    [PATCH] AYSNC IO using singals other than SIGIO

    A question on sigwaitinfo based IO mechanism in multithreaded applications.

    I am trying to use RT signals to notify me of IO events using RT signals
    instead of SIGIO in a multithreaded applications.  I noticed that there was
    some discussion on lkml during november 1999 with the subject of the
    discussion as "Signal driven IO".  In the thread I noticed that RT signals
    were being delivered to the worker thread.  I am running 2.6.10 kernel and
    I am trying to use the very same mechanism and I find that only SIGIO being
    propogated to the worker threads and RT signals only being propogated to
    the main thread and not the worker threads where I actually want them to be
    propogated too.  On further inspection I found that the following patch
    which I have attached solves the problem.

    I am not sure if this is a bug or feature in the kernel.


    Roland McGrath <roland@redhat.com> said:

    This relates only to fcntl F_SETSIG, which is a Linux extension.  So there is
    no POSIX issue.  When changing various things like the normal SIGIO signalling
    to do group signals, I was concerned strictly with the POSIX semantics and
    generally avoided touching things in the domain of Linux inventions.  That's
    why I didn't change this when I changed the call right next to it.  There is
    no reason I can see that F_SETSIG-requested signals shouldn't use a group
    signal like normal SIGIO does.  I'm happy to ACK this patch, there is nothing
    wrong with its change to the semantics in my book.  But neither POSIX nor I
    care a whit what F_SETSIG does.

    Signed-off-by: Andrew Morton <akpm@osdl.org>
    Signed-off-by: Linus Torvalds <torvalds@osdl.org>

> > 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.
> 
> I am not sure I understand the man above... But to me it looks like we
> should always send a private signal when fown->signum != 0 ?
> 
> The change should be simple, but as you pointed out we can break things.

Right, so the change I had in mind is like the below (except I don't
know if we can compare struct pid things by pointer value or if we
should look at the content).

In any case, we should either do something like the below (yay!), or
amend the manpage (Michael?) and introduce something like F_SETOWN2
which does have the below semantics :-(.

---
Index: linux-2.6/fs/fcntl.c
===================================================================
--- linux-2.6.orig/fs/fcntl.c
+++ linux-2.6/fs/fcntl.c
@@ -431,6 +431,16 @@ static void send_sigio_to_task(struct ta
 			       int fd,
 			       int reason)
 {
+	int (*send_sig)(int, struct siginfo *, struct task_struct *);
+
+	send_sig = group_send_sig_info;
+	/*
+	 * If the fown points to a specific TID instead of to a PID
+	 * we'll send the signal to the thread only.
+	 */
+	if (fown->pid_type == PIDTYPE_PID && fown->pid != task_tgid(p))
+		send_sig = send_sig_info;
+
 	/*
 	 * F_SETSIG can change ->signum lockless in parallel, make
 	 * sure we read it once and use the same value throughout.
@@ -461,11 +472,11 @@ static void send_sigio_to_task(struct ta
 			else
 				si.si_band = band_table[reason - POLL_IN];
 			si.si_fd    = fd;
-			if (!group_send_sig_info(signum, &si, p))
+			if (!send_sig(signum, &si, p))
 				break;
 		/* fall-through: fall back on the old plain SIGIO signal */
 		case 0:
-			group_send_sig_info(SIGIO, SEND_SIG_PRIV, p);
+			send_sig(SIGIO, SEND_SIG_PRIV, p);
 	}
 }
 



  reply	other threads:[~2009-07-30 11:28 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
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 [this message]
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=1248953485.6391.41.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=roland@redhat.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