Received: by 10.192.165.148 with SMTP id m20csp3880926imm; Mon, 30 Apr 2018 07:58:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq3Bb8CpWJ0knwkfNO1GigWUsRdhEijDx3TzJpLixifOaduZk3qwqvg5gvko2g54tnIcAjg X-Received: by 10.98.196.19 with SMTP id y19mr12306462pff.97.1525100316286; Mon, 30 Apr 2018 07:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525100316; cv=none; d=google.com; s=arc-20160816; b=it6m68A3AAPVKGjS8asLn42/o5V/+jO1iVssExIHBzCRFZnvvolIAArandG2C/MMfb a+LkjTgzTbtQ3DJWZCzF8RlLYr3zOZXyAqWpdmDg9Vmxd94aJBVyw66phcgic3I9SEHU WxPqzRnRn65U7mxVJSL0CExq4c19B3BPvpiXTZC8wtOerdIgeUrpfAmDE5Ay14sqOzJV 2enOYa1IYAuM6+kDSZrW7yCBDxo5fKgYXUB4r2VEBL8JEEZck8TuJAWmjw9UIJM2UgzF D/RdbGmviJL+n+r7K5Cg/g+C6Mwox5dNEFyfhx3OygtZzMGgvq92hAEOJd9Mw6eJzzin xOpg== 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=G71Q2+BYKVYzt309ct9Pa3OzRte+vGtslkS0sjb0+U0=; b=HPCvZwwziApNr0ybBNqdXh5h6Nc9zvfzoF1E8qkUQwbuKXHTTqHn0nW/fS0PFUcC0x kgANgjqq1pqIaw5mwlMMDt/vZ4Sz0863trPQ2wpszokWH2h56t/BRU7DdoWlYXN6o53a iEy/YAxwrtaGf/Bm7O1wUKleCmyASRX8CD9afjx3BoYhLUsQ/pHj/qHWAdZONB5AtcNX hnMpBEjlB35VH/cavvOw9ELRZH1aCaQCJhsLA6FOmaNqCMXLOH6YxmCPhwYRs/UhHGBK X5VG6X/dOLw4D+9wXsyR87M8XVxr9PYCltjs56nptHAZ8yfKjrDDVg6VNAcdvOTrroIc WVkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C2BhGwkz; 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 s23-v6si510359plr.458.2018.04.30.07.58.22; Mon, 30 Apr 2018 07:58:36 -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=C2BhGwkz; 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 S1754768AbeD3O5a (ORCPT + 99 others); Mon, 30 Apr 2018 10:57:30 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34084 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754434AbeD3O5C (ORCPT ); Mon, 30 Apr 2018 10:57:02 -0400 Received: by mail-pg0-f65.google.com with SMTP id p10-v6so6489624pgn.1 for ; Mon, 30 Apr 2018 07:57:02 -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=G71Q2+BYKVYzt309ct9Pa3OzRte+vGtslkS0sjb0+U0=; b=C2BhGwkz4P1RxBBM/1ce5BiWOMqHgvkU75sUDZ8VDKijuUK9o3RfwA45Ta07H9ZHfP 8HEuNBwazgtcI91BAYsGM5/EsAPT8zsBj4hCarlMf07yoYL8m1NCExfOMFEJ5uXAgp+7 jFMK/+xP0EgikjDdLOrDZBUDXO8QbM8dT5Laf/0SZ96+WMiuxcPWZVBAbSoJ6o93g82i 7oh7jY/Dh8glYXU1ji5e8VEtldCHUO6DYnuF6ST/5ILeNc779SEKeMnlfoeKVQ948Pf5 tzoHSxOIxBNf2Q5YKmIPHJ4Dtlx4TtibCA/ENBH+VZ2qBuIhVWwulzZ2j/ltVJmeSmpG XcPQ== 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=G71Q2+BYKVYzt309ct9Pa3OzRte+vGtslkS0sjb0+U0=; b=Tnm9SOjvsZDYMB48mRaoQKhFCZy5laqcF9of4wesNroZdpQ9tV2virptsefVNEi+rV c6DqhhBmcrmu5RT4MUlvMRlrv/AbIcn5nei3kCDxepUZGTK+Q7sdh/F33tBwLL6BBBFT Xoy76VcStmaCRUFnZeSrM8oM9qC9auvw4dWdt3Oydqkzr/FEY8IFUuxzrR8LNmkc0hAp mItR5XlP1XS9mXmI0KUrNBUTJpTHWqaZlxJzJhVPepxhwjWBM8T+Fe9Ixw9CGoVoqJ8k XX/RWYqyoG7xHDM++vxIc2z9u3r/NRwKxOUlWZiBjrqNNdHAw/ABZfSDHHpGnzj3hQJu n5Vw== X-Gm-Message-State: ALQs6tBFjcRtyT+deKS2VFknTdNHET9FJU0W3G08xYWO+hBLGqYUHOq9 cFhHjLlc+pk/hTaiSXFcEJE= X-Received: by 2002:a17:902:d882:: with SMTP id b2-v6mr12633352plz.381.1525100222239; Mon, 30 Apr 2018 07:57:02 -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.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 07:57:01 -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 14/15] tty: hvc: introduce the hv_ops.flush operation for hvc drivers Date: Tue, 1 May 2018 00:55:57 +1000 Message-Id: <20180430145558.4308-15-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 Use .flush to wait for drivers to flush their console outside of the spinlock, to reduce lock/irq latencies. Flush the hvc console driver after each write, which can help messages make it out to the console after a crash. Signed-off-by: Nicholas Piggin --- drivers/tty/hvc/hvc_console.c | 35 +++++++++++++++++++++++++++++++++-- drivers/tty/hvc/hvc_console.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 6131d5084c42..5414c4a87bea 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -110,6 +110,29 @@ static struct hvc_struct *hvc_get_by_index(int index) return hp; } +static int __hvc_flush(const struct hv_ops *ops, uint32_t vtermno, bool wait) +{ + if (wait) + might_sleep(); + + if (ops->flush) + return ops->flush(vtermno, wait); + return 0; +} + +static int hvc_console_flush(const struct hv_ops *ops, uint32_t vtermno) +{ + return __hvc_flush(ops, vtermno, false); +} + +/* + * Wait for the console to flush before writing more to it. This sleeps. + */ +static int hvc_flush(struct hvc_struct *hp) +{ + return __hvc_flush(hp->ops, hp->vtermno, true); +} + /* * Initial console vtermnos for console API usage prior to full console * initialization. Any vty adapter outside this range will not have usable @@ -155,8 +178,12 @@ static void hvc_console_print(struct console *co, const char *b, if (r <= 0) { /* throw away characters on error * but spin in case of -EAGAIN */ - if (r != -EAGAIN) + if (r != -EAGAIN) { i = 0; + } else { + hvc_console_flush(cons_ops[index], + vtermnos[index]); + } } else if (r > 0) { i -= r; if (i > 0) @@ -164,6 +191,7 @@ static void hvc_console_print(struct console *co, const char *b, } } } + hvc_console_flush(cons_ops[index], vtermnos[index]); } static struct tty_driver *hvc_console_device(struct console *c, int *index) @@ -513,8 +541,11 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count spin_unlock_irqrestore(&hp->lock, flags); - if (count) + if (count) { + if (hp->n_outbuf > 0) + hvc_flush(hp); cond_resched(); + } } /* diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h index ea63090e013f..e9319954c832 100644 --- a/drivers/tty/hvc/hvc_console.h +++ b/drivers/tty/hvc/hvc_console.h @@ -54,6 +54,7 @@ struct hvc_struct { struct hv_ops { int (*get_chars)(uint32_t vtermno, char *buf, int count); int (*put_chars)(uint32_t vtermno, const char *buf, int count); + int (*flush)(uint32_t vtermno, bool wait); /* Callbacks for notification. Called in open, close and hangup */ int (*notifier_add)(struct hvc_struct *hp, int irq); -- 2.17.0