Received: by 10.192.165.148 with SMTP id m20csp3879873imm; Mon, 30 Apr 2018 07:57:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZomsMUAEaDFqAvQ3l1pf4TcQOF6kufisERJkwZXY1OrFsOO87Zwq2XSMos/hvyH+UDGtQgq X-Received: by 2002:a17:902:96a:: with SMTP id 97-v6mr12996000plm.266.1525100253271; Mon, 30 Apr 2018 07:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525100253; cv=none; d=google.com; s=arc-20160816; b=GpW3AlnYongRepQzHnZayGU2Z9Ygf5sRdOroNw3EOsQa0dFs2GltAtNtzFDEHqs75l sxGyOnw4BS7Li/0K3/TRbFpHvzvc+axZ4ru4Xb5KM49TC6OCAi3wIbzkDYDKmoHq05fj pHdELVT8xld+dqKqwqqVc+cDxOKDuQj5tXn8GQMMqvDKrdwKaqPXebn7zsJP64Ud/F1o DQt2IOpXLlBzyEpOxbt+hTv7s6K72xM8MHg+Tfpjx9dMbN4MMACWbGJnO1ZQQnKHg2kX a0elFRCVROx1227nYLAyVp+jJizJl5VUsBHCNUkq1WnuXnO4wDD8kxdho7AGGwEIypJ0 VVfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qOZJfLQ9RKZlBI+cfjMORT8Zm26ghIRtsA4lRvp0+jY=; b=rUNk/xOPlkPKdM2ZyLPqqdtVLFz16PLk8kFuCpS1Yy6e2g0rvHz1n4NKqNklae9iHn GjfY5vu8ksmc/mZUAM6xq3CkPoN4CEsHTPH2LPEUCEdiyl90cfTiQ+plHMu2ieQbLqPr hCW0Y8y6GXOxYYaeF/OVzhrH0I7BsOml6JGDXodZDBsTaYMpvfeBmaM/UuE90AFilOEW 8lrZxr1kZk3mcnMYZ7+hsQ3hJDfV4oKIs275Ne9inNxZrKjJ5JdmDtY+lACYnSaqADsB lpvRXHFDxtluy/xtFkP7GPIexzZvzCHBWzhfVZZICeB5LoSJ78263TzvmZxZfN5/r1PV 3lHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=umAtw1tW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi12-v6si3086292plb.546.2018.04.30.07.57.19; Mon, 30 Apr 2018 07:57:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=umAtw1tW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754716AbeD3O44 (ORCPT + 99 others); Mon, 30 Apr 2018 10:56:56 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:39316 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754434AbeD3O4v (ORCPT ); Mon, 30 Apr 2018 10:56:51 -0400 Received: by mail-pg0-f67.google.com with SMTP id b9-v6so6479248pgf.6 for ; Mon, 30 Apr 2018 07:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qOZJfLQ9RKZlBI+cfjMORT8Zm26ghIRtsA4lRvp0+jY=; b=umAtw1tWj1iv8Dublw2GLdtByXdCDAg4ZPWLmDig3mXavCuVWQ78onSm+CgXx25T3G ccZvLyXW4jUVYXG7GC3nqu536gT/n5RHa6s4ngQpe6gV0kSJ/6cP5PV/ZYmGfc6A3toe IW4jWCQ7hfDdKDYh4A9pdRkH05y5IkeMMznD7gF6J20i8adamT6cHbv2Wm9qceR7Zo94 LHxRSBDErtayYwWGR9k10Mzzo3atwvA9RNvblcE9PV+Ki65Zw3UYSYMlSh1JhEM5i8wB noOpFTEgMAE9NLdPFjuDsbBe3u/ZXpq/e1VjsgDj6yO8/EjAJNZrsA/DlkmvcpLWYIET Pxvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qOZJfLQ9RKZlBI+cfjMORT8Zm26ghIRtsA4lRvp0+jY=; b=WMltfZlR/GWVIDWe5UGMp8kZOwLxaeg2ljCfTME17mko7SoKLTs+UdT9oL2FeMELVS KnfdF4fs0C0+PF+nDXDbU5kVS361cSf6Hz441qY+1LiGJeBJrAyxpLUUc4jzFyYI9hfJ af4pNzoS3FZCxTV2dhSYtM0h6j3p4dpyF+463aW6GRfZXG37WqEP+fwq+rWwy8IBdN5A k/tFedIWLj62Qrfd2F876R6sfoasO4NpyGcE3JA988J0lFfPHeGUqpTely3guev5z2Tn r0IQWndyeoRwpFCM3Kmz3Y6w4IMQvo4N/HpkR3aHcX6cMmGssT6t7mBxIBagawrH2WOE /RTg== X-Gm-Message-State: ALQs6tAIX2qX7BbUB70Opw4dGvQWJPdAN3mitgnKxtP68U7docYQYfNa vW8awP6x3LH11BfVLqCL9xPoZA== X-Received: by 10.98.152.29 with SMTP id q29mr12285387pfd.65.1525100210778; Mon, 30 Apr 2018 07:56:50 -0700 (PDT) Received: from roar.au.ibm.com (59-102-70-78.tpgi.com.au. [59.102.70.78]) by smtp.gmail.com with ESMTPSA id a12sm19132534pfe.78.2018.04.30.07.56.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 07:56:49 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Cc: Nicholas Piggin , Benjamin Herrenschmidt , Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org Subject: [PATCH 11/15] tty: hvc: hvc_poll break hv read loop Date: Tue, 1 May 2018 00:55:54 +1000 Message-Id: <20180430145558.4308-12-npiggin@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430145558.4308-1-npiggin@gmail.com> References: <20180430145558.4308-1-npiggin@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid looping with the spinlock held while there is read data being returned from the hv driver. Instead note if the entire size returned by tty_buffer_request_room was read, and request another read poll. This limits the critical section lengths, and provides more even service to other consoles in case there is a pathological condition. Signed-off-by: Nicholas Piggin --- drivers/tty/hvc/hvc_console.c | 88 ++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index fddb63322c67..745ac220fce8 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -592,7 +592,7 @@ static u32 timeout = MIN_TIMEOUT; int hvc_poll(struct hvc_struct *hp) { struct tty_struct *tty; - int i, n, poll_mask = 0; + int i, n, count, poll_mask = 0; char buf[N_INBUF] __ALIGNED__; unsigned long flags; int read_total = 0; @@ -618,7 +618,7 @@ int hvc_poll(struct hvc_struct *hp) /* Now check if we can get data (are we throttled ?) */ if (tty_throttled(tty)) - goto throttled; + goto out; /* If we aren't notifier driven and aren't throttled, we always * request a reschedule @@ -627,56 +627,58 @@ int hvc_poll(struct hvc_struct *hp) poll_mask |= HVC_POLL_READ; /* Read data if any */ - for (;;) { - int count = tty_buffer_request_room(&hp->port, N_INBUF); - /* If flip is full, just reschedule a later read */ - if (count == 0) { + count = tty_buffer_request_room(&hp->port, N_INBUF); + + /* If flip is full, just reschedule a later read */ + if (count == 0) { + poll_mask |= HVC_POLL_READ; + goto out; + } + + n = hp->ops->get_chars(hp->vtermno, buf, count); + if (n <= 0) { + /* Hangup the tty when disconnected from host */ + if (n == -EPIPE) { + spin_unlock_irqrestore(&hp->lock, flags); + tty_hangup(tty); + spin_lock_irqsave(&hp->lock, flags); + } else if ( n == -EAGAIN ) { + /* + * Some back-ends can only ensure a certain min + * num of bytes read, which may be > 'count'. + * Let the tty clear the flip buff to make room. + */ poll_mask |= HVC_POLL_READ; - break; } + goto out; + } - n = hp->ops->get_chars(hp->vtermno, buf, count); - if (n <= 0) { - /* Hangup the tty when disconnected from host */ - if (n == -EPIPE) { - spin_unlock_irqrestore(&hp->lock, flags); - tty_hangup(tty); - spin_lock_irqsave(&hp->lock, flags); - } else if ( n == -EAGAIN ) { - /* - * Some back-ends can only ensure a certain min - * num of bytes read, which may be > 'count'. - * Let the tty clear the flip buff to make room. - */ - poll_mask |= HVC_POLL_READ; - } - break; - } - for (i = 0; i < n; ++i) { + for (i = 0; i < n; ++i) { #ifdef CONFIG_MAGIC_SYSRQ - if (hp->index == hvc_console.index) { - /* Handle the SysRq Hack */ - /* XXX should support a sequence */ - if (buf[i] == '\x0f') { /* ^O */ - /* if ^O is pressed again, reset - * sysrq_pressed and flip ^O char */ - sysrq_pressed = !sysrq_pressed; - if (sysrq_pressed) - continue; - } else if (sysrq_pressed) { - handle_sysrq(buf[i]); - sysrq_pressed = 0; + if (hp->index == hvc_console.index) { + /* Handle the SysRq Hack */ + /* XXX should support a sequence */ + if (buf[i] == '\x0f') { /* ^O */ + /* if ^O is pressed again, reset + * sysrq_pressed and flip ^O char */ + sysrq_pressed = !sysrq_pressed; + if (sysrq_pressed) continue; - } + } else if (sysrq_pressed) { + handle_sysrq(buf[i]); + sysrq_pressed = 0; + continue; } -#endif /* CONFIG_MAGIC_SYSRQ */ - tty_insert_flip_char(&hp->port, buf[i], 0); } - - read_total += n; +#endif /* CONFIG_MAGIC_SYSRQ */ + tty_insert_flip_char(&hp->port, buf[i], 0); } - throttled: + if (n == count) + poll_mask |= HVC_POLL_READ; + read_total = n; + + out: /* Wakeup write queue if necessary */ if (hp->do_wakeup) { hp->do_wakeup = 0; -- 2.17.0