linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Hurley <peter@hurleysoftware.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Jiri Slaby" <jslaby@suse.cz>,
	"Christian Riesch" <christian.riesch@omicron.at>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	"Denis Du" <dudenis2000@yahoo.ca>,
	"Måns Rullgård" <mans@mansr.com>,
	"Peter Hurley" <peter@hurleysoftware.com>
Subject: [PATCH v3 5/6] n_tty: Fix PARMRK over-throttling
Date: Fri, 16 Jan 2015 15:05:38 -0500	[thread overview]
Message-ID: <1421438739-29672-6-git-send-email-peter@hurleysoftware.com> (raw)
In-Reply-To: <1421438739-29672-1-git-send-email-peter@hurleysoftware.com>

If PARMRK is enabled, the available read buffer space computation is
overly-pessimistic, which results in severely throttled i/o, even
in the absence of parity errors. For example, if the 4k read buffer
contains 1k processed data, the input worker will compute available
space of 333 bytes, despite 3k being available. At 1365 chars of
processed data, 0 space available is computed.

*Divide remaining space* by 3, truncating down (if left == 2, left = 0).

Reported-by: Christian Riesch <christian.riesch@omicron.at>

Conflicts:
	drivers/tty/n_tty.c

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
 drivers/tty/n_tty.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index f63b25b..7aeabb7 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1669,9 +1669,8 @@ n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
 
 	while (1) {
 		/*
-		 * When PARMRK is set, multiply read_cnt by 3, since each byte
-		 * might take up to three times as many spaces (depending on
-		 * its flags, e.g. parity error). [This calculation is wrong.]
+		 * When PARMRK is set, each input char may take up to 3 chars
+		 * in the read buf; reduce the buffer space avail by 3x
 		 *
 		 * If we are doing input canonicalization, and there are no
 		 * pending newlines, let characters through without limit, so
@@ -1683,13 +1682,10 @@ n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
 		 * read_tail (so this producer will not overwrite unread data)
 		 */
 		size_t tail = smp_load_acquire(&ldata->read_tail);
-		size_t head = ldata->read_head;
 
+		room = N_TTY_BUF_SIZE - (ldata->read_head - tail) - 1;
 		if (I_PARMRK(tty))
-			room = N_TTY_BUF_SIZE - (head - tail) * 3 - 1;
-		else
-			room = N_TTY_BUF_SIZE - (head - tail) - 1;
-
+			room /= 3;
 		if (room <= 0)
 			room = ldata->icanon && ldata->canon_head == tail;
 
-- 
2.2.2

  parent reply	other threads:[~2015-01-16 20:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13  1:47 [PATCH v2] n_tty: Fix unordered accesses to lockless read buffer Peter Hurley
2015-01-16 15:55 ` Peter Hurley
2015-01-16 20:05 ` [PATCH v3 0/6] N_TTY input path fixes Peter Hurley
2015-01-16 20:05   ` [PATCH v3 1/6] n_tty: Eliminate receive_room() from consumer/exclusive paths Peter Hurley
2015-01-16 20:05   ` [PATCH v3 2/6] n_tty: Fix throttle for canon lines > 3967 chars Peter Hurley
2015-01-16 20:05   ` [PATCH v3 3/6] n_tty: Simplify throttle threshold calculation Peter Hurley
2015-01-16 20:05   ` [PATCH v3 4/6] n_tty: Fix unordered accesses to lockless read buffer Peter Hurley
2015-01-16 20:05   ` Peter Hurley [this message]
2015-01-16 20:05   ` [PATCH v3 6/6] n_tty: Fix read buffer overwrite when no newline Peter Hurley

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=1421438739-29672-6-git-send-email-peter@hurleysoftware.com \
    --to=peter@hurleysoftware.com \
    --cc=christian.riesch@omicron.at \
    --cc=dudenis2000@yahoo.ca \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mans@mansr.com \
    /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).