teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0493-pty-optimize-read-loop.patch

Zbigniew Jędrzejewski-Szmek 62fe94
From 48fed5c55b5183e6d44702dfdccd3b5325d8689c Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek 62fe94
From: David Herrmann <dh.herrmann@gmail.com>
Zbigniew Jędrzejewski-Szmek 62fe94
Date: Fri, 3 Oct 2014 15:54:21 +0200
Zbigniew Jędrzejewski-Szmek 62fe94
Subject: [PATCH] pty: optimize read loop
Zbigniew Jędrzejewski-Szmek 62fe94
Zbigniew Jędrzejewski-Szmek 62fe94
As it turns out, I can actually send data to the pty faster than the
Zbigniew Jędrzejewski-Szmek 62fe94
terminal can read. Therefore, make sure we read as much data as possible
Zbigniew Jędrzejewski-Szmek 62fe94
but bail out early enough to not cause starvation.
Zbigniew Jędrzejewski-Szmek 62fe94
Zbigniew Jędrzejewski-Szmek 62fe94
Kernel TTY buffers are 4k, so reduce the overall buffer size, but read
Zbigniew Jędrzejewski-Szmek 62fe94
more than once if possible (up to 8 times sounds reasonable).
Zbigniew Jędrzejewski-Szmek 62fe94
---
Zbigniew Jędrzejewski-Szmek 62fe94
 src/shared/pty.c | 8 ++++----
Zbigniew Jędrzejewski-Szmek 62fe94
 1 file changed, 4 insertions(+), 4 deletions(-)
Zbigniew Jędrzejewski-Szmek 62fe94
Zbigniew Jędrzejewski-Szmek 62fe94
diff --git a/src/shared/pty.c b/src/shared/pty.c
Zbigniew Jędrzejewski-Szmek 62fe94
index adcb32d0be..52a426c0e1 100644
Zbigniew Jędrzejewski-Szmek 62fe94
--- a/src/shared/pty.c
Zbigniew Jędrzejewski-Szmek 62fe94
+++ b/src/shared/pty.c
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -67,7 +67,7 @@
Zbigniew Jędrzejewski-Szmek 62fe94
 #include "ring.h"
Zbigniew Jędrzejewski-Szmek 62fe94
 #include "util.h"
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
-#define PTY_BUFSIZE 16384
Zbigniew Jędrzejewski-Szmek 62fe94
+#define PTY_BUFSIZE 4096
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
 enum {
Zbigniew Jędrzejewski-Szmek 62fe94
         PTY_ROLE_UNKNOWN,
Zbigniew Jędrzejewski-Szmek 62fe94
@@ -305,11 +305,11 @@ static int pty_dispatch_read(Pty *pty) {
Zbigniew Jędrzejewski-Szmek 62fe94
         /*
Zbigniew Jędrzejewski-Szmek 62fe94
          * We're edge-triggered, means we need to read the whole queue. This,
Zbigniew Jędrzejewski-Szmek 62fe94
          * however, might cause us to stall if the writer is faster than we
Zbigniew Jędrzejewski-Szmek 62fe94
-         * are. Therefore, we read twice and if the second read still returned
Zbigniew Jędrzejewski-Szmek 62fe94
-         * data, we reschedule.
Zbigniew Jędrzejewski-Szmek 62fe94
+         * are. Therefore, try reading as much as 8 times (32KiB) and only
Zbigniew Jędrzejewski-Szmek 62fe94
+         * bail out then.
Zbigniew Jędrzejewski-Szmek 62fe94
          */
Zbigniew Jędrzejewski-Szmek 62fe94
 
Zbigniew Jędrzejewski-Szmek 62fe94
-        for (i = 0; i < 2; ++i) {
Zbigniew Jędrzejewski-Szmek 62fe94
+        for (i = 0; i < 8; ++i) {
Zbigniew Jędrzejewski-Szmek 62fe94
                 len = read(pty->fd, pty->in_buf, sizeof(pty->in_buf) - 1);
Zbigniew Jędrzejewski-Szmek 62fe94
                 if (len < 0) {
Zbigniew Jędrzejewski-Szmek 62fe94
                         if (errno == EINTR)