linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ivo Sieben <meltedpianoman@gmail.com>
Cc: linux-kernel@vger.kernel.org, Andi Kleen <andi@firstfloor.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-serial@vger.kernel.org, Alan Cox <alan@linux.intel.com>,
	Greg KH <gregkh@linuxfoundation.org>
Subject: Re: [REPOST-v2] sched: Prevent wakeup to enter critical section needlessly
Date: Mon, 19 Nov 2012 16:49:40 +0100	[thread overview]
Message-ID: <20121119154940.GA6354@redhat.com> (raw)
In-Reply-To: <CAMSQXEF9BGBVRRtuz88XFqVmPBdbWisepq4qjah3vM05_7hztw@mail.gmail.com>

On 11/19, Ivo Sieben wrote:
>
> Hi
>
> 2012/11/19 Oleg Nesterov <oleg@redhat.com>:
> >
> > I am wondering if it makes sense unconditionally. A lot of callers do
> >
> >         if (waitqueue_active(q))
> >                 wake_up(...);
> >
> > this patch makes the optimization above pointless and adds mb().
> >
> >
> > But I won't argue.
> >
> > Oleg.
> >
>
> This patch solved an issue for me that I had with the TTY line
> discipline idle handling:
> Testing on a PREEMPT_RT system with TTY serial communication. Each
> time the TTY line discipline is dereferenced the Idle handling wait
> queue is woken up (see function put_ldisc in /drivers/tty/tty_ldisc.c)
> However line discipline idle handling is not used very often so the
> wait queue is empty most of the time. But still the wake_up() function
> enters the critical section guarded by spin locks. This causes
> additional scheduling overhead when a lower priority thread has
> control of that same lock.
>
> The /drivers/tty/tty_ldisc.c did not use the waitqueue_active() call
> to check if the waitqueue was filled.... maybe I should solve this
> problem the other way around: and make tty_ldisc.c first do the
> waitqueue_active() call?

IMHO yes...

Because on a second thought I suspect this change is wrong.

Just for example, please look at kauditd_thread(). It does

	set_current_state(TASK_INTERRUPTIBLE);

	add_wait_queue(&kauditd_wait, &wait);

	if (!CONDITION)		// <-- LOAD
		schedule();

And the last LOAD can leak into the critical section protected by
wait_queue_head_t->lock, and it can be reordered with list_add()
inside this critical section. In this case we can race with wake_up()
unless it takes the same lock.

Oleg.


  reply	other threads:[~2012-11-19 15:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-24 13:06 [PATCH] RFC: sched: Prevent wakeup to enter critical section needlessly Ivo Sieben
2012-10-09 11:30 ` [REPOST] " Ivo Sieben
2012-10-09 13:37   ` Andi Kleen
2012-10-09 14:15     ` Peter Zijlstra
2012-10-09 15:17       ` Oleg Nesterov
2012-10-10 14:02         ` Andi Kleen
2012-10-18  8:30           ` [PATCH-v2] " Ivo Sieben
2012-10-25 10:12             ` [REPOST-v2] " Ivo Sieben
2012-11-19  7:30               ` Ivo Sieben
2012-11-19 10:20                 ` Preeti U Murthy
2012-11-19 15:10                 ` Oleg Nesterov
2012-11-19 15:34                   ` Ivo Sieben
2012-11-19 15:49                     ` Oleg Nesterov [this message]
2012-11-21 13:03                       ` Ivo Sieben
2012-11-21 13:47                         ` Alan Cox
2012-11-21 13:58                         ` Oleg Nesterov

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=20121119154940.GA6354@redhat.com \
    --to=oleg@redhat.com \
    --cc=alan@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=meltedpianoman@gmail.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).