Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1290680

Re: [PATCH 1/6] n_tty: Always wake up read()/poll() if new input

Path csiph.com!goblin2!goblin.stu.neva.ru!gothmog.csi.it!bofh.it!news.nic.it!robomod
From Peter Hurley <peter@hurleysoftware.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/6] n_tty: Always wake up read()/poll() if new input
Date Sun, 13 Dec 2015 21:00:02 +0100
Message-ID <qFkYi-4eF-3@gated-at.bofh.it> (permalink)
References <qF0Gd-8bC-3@gated-at.bofh.it> <qF0Ge-8bC-13@gated-at.bofh.it> <qFg8h-1aw-1@gated-at.bofh.it>
X-Original-To Johannes Stezenbach <js@sig21.net>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=hurleysoftware-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=JZmeJ2aU3PvTu7s9KMzOsXpmTZXwjpfaCZdpFAU7oJE=; b=meL/x5GW11VNQqHugooefnkG3zQZbWLBlSs8Gk7C312jcH+TJeWHnUNWT6bxk8XheG nk2rGpQu1RNVq3hig0dCV90Iu/iRYEWsXLtitOR2gUecJ9J/vJoQ2c/dyg1h/+FP5ktt EuSBtsIG36fKMEQ+HKJsyaXp7vp9UZf7ORee7rZ9A+8d7wrdfiCqFg/kRibguJZjFFQo uQZ/meN3ojQi7LHESpXAVRyhYtR3d51jvarKjizFPnyvBDABt7GzLwp21EZTyVX9HWIm N85P9h0jv8dKh/Fyt9r4j/iE+cDiNf5Wg64ZlcqtPoiiWAStd16I4EFkh+HWcwL5nnQx F15Q==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=JZmeJ2aU3PvTu7s9KMzOsXpmTZXwjpfaCZdpFAU7oJE=; b=fnrY3zSA3cNPROqSbJrNT/oMfJvJMilk+gDdC5v1p0PJksl6rFEYrOESmWOuDvIQpX EviXCMffmxOVuAzRfrx27RU7VkiBE6FwyehSfV7GY3MAfNzEBTnZeW1NTry3U8xVegUJ wDeoGsOp2K581qFZJPMx7Bt2CtdZWgWqrK3xnBo6MgH84uq2Rf8Tv8x6l1NQS5vyO7kh h+MWj4xVDgU5oTdhYo60enaVPjfyscDEjXbd91FiuriMLkHeybc+MCOdrd+OgXqnJJ8M vNEwqWYaKAobYkq+XkyHV/WhhebaVixnY9EQ0bFU2m7y35YUNpXX9syRd+Kvz7FnK2sx MGLQ==
X-Gm-Message-State ALoCoQkTHxvUWNwb3Jnw+gKyw8dQBtzWK+qvGtwZq/lp5sq9XnYmFlr141Rr7mzIzaJvJmwTcYTZ8ZXk6B1d5Mp/EqodL60xDw==
X-Received by 10.66.154.161 with SMTP id vp1mr40116907pab.25.1450036397710; Sun, 13 Dec 2015 11:53:17 -0800 (PST)
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 56
Organization linux.* mail to news gateway
X-Original-Cc Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jslaby@suse.cz>, linux-kernel@vger.kernel.org
X-Original-Date Sun, 13 Dec 2015 11:53:14 -0800
X-Original-Message-ID <566DCCAA.1020503@hurleysoftware.com>
X-Original-References <1449958599-5533-1-git-send-email-peter@hurleysoftware.com> <1449958599-5533-2-git-send-email-peter@hurleysoftware.com> <20151213144922.GA10204@sig21.net>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1290680

Show key headers only | View raw


Hi Johannes,

On 12/13/2015 06:49 AM, Johannes Stezenbach wrote:
> Hi Peter,
> 
> On Sat, Dec 12, 2015 at 02:16:34PM -0800, Peter Hurley wrote:
>> A read() in non-canonical mode when VMIN > 0 and VTIME == 0 does not
>> complete until at least VMIN chars have been read (or the user buffer is
>> full). In this infrequent read mode, n_tty_read() attempts to reduce
>> wakeups by computing the amount of data still necessary to complete the
>> read (minimum_to_wake) and only waking the read()/poll() when that much
>> unread data has been processed. This is the only read mode for which
>> new data does not necessarily generate a wakeup.
>>
>> However, this optimization is broken and commonly leads to hung reads
>> even though the necessary amount of data has been received. Since the
>> optimization is of marginal value anyway, just remove the whole
>> thing. This also remedies a race between a concurrent poll() and
>> read() in this mode, where the poll() can reset the minimum_to_wake
>> of the read() (and vice versa).
> ...
>> @@ -1632,7 +1631,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
>>  	/* publish read_head to consumer */
>>  	smp_store_release(&ldata->commit_head, ldata->read_head);
>>  
>> -	if ((read_cnt(ldata) >= ldata->minimum_to_wake) || L_EXTPROC(tty)) {
>> +	if (read_cnt(ldata)) {
>>  		kill_fasync(&tty->fasync, SIGIO, POLL_IN);
>>  		wake_up_interruptible_poll(&tty->read_wait, POLLIN);
>>  	}
> 
> Your patch looks fine, I just want to mention that there was
> some undocumented behaviour for async IO to take VMIN
> into account for deciding when to send SIGIO, but it was
> implemented incorrectly because minimum_to_wake was
> only updated in read() and poll(), not directly by the
> tcsetattr() ioctl.  I think your change does the right
> thing to fix this case, too.  I had to debug some
> proprietary code which dynamically changed VMIN based on
> expected message size and thus sometimes wasn't woken up,
> in the end we decided to keep VMIN=1 to solve it.

I considered re-implementing the minimum_to_wake mechanism
(in a race-free way) but I'm not sure it's worth the effort
(either in initial implementation time or in maintenance head-ache).
Now that termios changes are serialized with an active reader and the
input worker, it is at least possible.


Regards,
Peter Hurley
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/6] More n_tty fixes Peter Hurley <peter@hurleysoftware.com> - 2015-12-12 23:20 +0100
  [PATCH 6/6] n_tty: Remove tty count checks from unthrottle Peter Hurley <peter@hurleysoftware.com> - 2015-12-12 23:20 +0100
  [PATCH 4/6] tty: Fix ioctl(FIOASYNC) on hungup file Peter Hurley <peter@hurleysoftware.com> - 2015-12-12 23:20 +0100
  [PATCH 3/6] tty: Add fasync() hung up file operation Peter Hurley <peter@hurleysoftware.com> - 2015-12-12 23:20 +0100
  [PATCH 1/6] n_tty: Always wake up read()/poll() if new input Peter Hurley <peter@hurleysoftware.com> - 2015-12-12 23:20 +0100
    Re: [PATCH 1/6] n_tty: Always wake up read()/poll() if new input Johannes Stezenbach <js@sig21.net> - 2015-12-13 15:50 +0100
      Re: [PATCH 1/6] n_tty: Always wake up read()/poll() if new input Peter Hurley <peter@hurleysoftware.com> - 2015-12-13 21:00 +0100
  [PATCH 2/6] tty, n_tty: Remove fasync() ldisc notification Peter Hurley <peter@hurleysoftware.com> - 2015-12-12 23:20 +0100

csiph-web