public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Ivo Sieben <meltedpianoman@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-serial@vger.kernel.org, linux-rt-users@vger.kernel.org,
	Alan Cox <alan@linux.intel.com>,
	Greg KH <gregkh@linuxfoundation.org>
Subject: Re: [PATCH-v2] tty: Use raw spin lock to protect RX flip buffer
Date: Tue, 9 Oct 2012 19:43:49 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.02.1210091934010.10988@ionos> (raw)
In-Reply-To: <1349781313-8670-1-git-send-email-meltedpianoman@gmail.com>

On Tue, 9 Oct 2012, Ivo Sieben wrote:
> The "normal" spin lock that guards the RX flip buffer is replaced by a raw
> spin lock.
> 
> On a PREEMP_RT system this prevents unwanted scheduling overhead when data is
> read at the same time as data is being received: while RX IRQ threaded handling
> is busy a TTY read call is performed from a RT priority > threaded IRQ priority.
> The read call tries to take the flip buffer spin lock (held by the threaded IRQ)
> which blocks and causes a context switch to/from the threaded IRQ handler until
> the spin lock is unlocked.
> 
> On a 200 MHz AT91SAM9261 processor setup this fixes about 100us of scheduling
> overhead on the TTY read call.

Cute, but ...
 
> Signed-off-by: Ivo Sieben <meltedpianoman@gmail.com>
> ---
> 
> @Thomas Gleixner & Steven Rostedt:
> Alan Cox has responded to this patch: "I've no real opinion on the spin/raw_spin
> choices as it's basically an RT question not a tty one so if the rt folks are
> happy with it so am I." Do you agree?
> 
> v2:
> Patch was based on another - abandoned - patch om mine, what introduced a bug in
> the tty_schedule_flip() function. Fixed this and rebased it on the latest kernel
> tree.
> 
> 
>  drivers/tty/tty_buffer.c |   44 ++++++++++++++++++++++----------------------
>  include/linux/kbd_kern.h |    4 ++--
>  include/linux/tty.h      |    2 +-
>  2 files changed, 25 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
> index 91e326f..70cf324 100644
> --- a/drivers/tty/tty_buffer.c
> +++ b/drivers/tty/tty_buffer.c
> @@ -135,20 +135,20 @@ static void __tty_buffer_flush(struct tty_struct *tty)
>  void tty_buffer_flush(struct tty_struct *tty)
>  {
>  	unsigned long flags;
> -	spin_lock_irqsave(&tty->buf.lock, flags);
> +	raw_spin_lock_irqsave(&tty->buf.lock, flags);
>  
>  	/* If the data is being pushed to the tty layer then we can't
>  	   process it here. Instead set a flag and the flush_to_ldisc
>  	   path will process the flush request before it exits */
>  	if (test_bit(TTY_FLUSHING, &tty->flags)) {
>  		set_bit(TTY_FLUSHPENDING, &tty->flags);
> -		spin_unlock_irqrestore(&tty->buf.lock, flags);
> +		raw_spin_unlock_irqrestore(&tty->buf.lock, flags);
>  		wait_event(tty->read_wait,
>  				test_bit(TTY_FLUSHPENDING, &tty->flags) == 0);
>  		return;
>  	} else
>  		__tty_buffer_flush(tty);

__tty_buffer_flush() can call tty_buffer_free() which in turn can call
kfree(), which is a nono on RT with preemption and interrupts
disabled. Enabling CONFIG_DEBUG_ATOMIC_SLEEP and extensive testing
should have told you that.

I did not look at the other places where this lock is used, but I
suspect there is more fallout lurking.

Thanks,

	tglx

  reply	other threads:[~2012-10-09 17:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-24  9:24 [PATCH] tty: Use raw spin lock to protect RX flip buffer Ivo Sieben
2012-10-09 11:15 ` [PATCH-v2] " Ivo Sieben
2012-10-09 17:43   ` Thomas Gleixner [this message]
2012-10-16  6:55     ` Ivo Sieben

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=alpine.LFD.2.02.1210091934010.10988@ionos \
    --to=tglx@linutronix.de \
    --cc=alan@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=meltedpianoman@gmail.com \
    --cc=rostedt@goodmis.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