Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp238062pxk; Thu, 1 Oct 2020 00:48:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr6yNmf/qlAWQ7PKSR6u7PNiQIq24uHlU3MUemvw4YXDi5NbSnMYhQPGFlYcNnwMbcqy6i X-Received: by 2002:a17:906:d787:: with SMTP id pj7mr6523768ejb.340.1601538521360; Thu, 01 Oct 2020 00:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601538521; cv=none; d=google.com; s=arc-20160816; b=UW8nc0tGjtxukL9wWcyZU6+ToCdWQxJ4LbiWFLqNVE3kEPoku4CK7CmzHJnkHRlqcs us9HywuR3gqaPP7EK/+N9b8t/+7PNSO0N573B/zXuXg4eDggCRZU/SYgR/WUuduwa3Gx lb3YBu+jn6v92VIsLmqd1/FxMKzKqzpTAx10cyNIsdGdo4epmigBTKRK7+cKB2e8ckHm wzheSGQ+t5GLytjqBvRdFxqLfIR6xEUP5U2teXhwqHkxkF3wFUiHC9Hq4X5rbMgEuy+t FE/JClhDWWUAl0HILi53uuOXTpSNr0SHL+O7I3gw7fE2VdJASmz84gRoHPXPcMQiPlTP S/5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+eH9es234mYEIAlDVSDqtT4+ZWM5jnVxpkIJgBTgT/Q=; b=HhmMSP8L0jLtgcs9Vx8lYA+Oz0lctiSM8bP2bKUHM4rMhIy+rhdA1JSal/Op7JmcIA DkWyTxOtFBbx74BjpTmWUZNanVCxCB7dMp6zojTA4u7Yw5t1878xssqFG+UFyjC5SG3l nYL/aDaWLbCmXwK0YNZxL+5t4UP6iU50OgJ4pIy4n2LYrzGKk+uJImNaYyqp579Mosfi QOOY+FBT7VA29VbceI2Tq10Pv2Seg9ZydrX+RHeIoZVJ3oTfDdB6eUV+fFzk774rUVes s5z2ZKxGl1tY7zEJDBj5q9NH067vfW9iIZdBhOWARz3+v5K/xNZNRYKtNz3bIUiDeNvX KQ0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si2781999edv.590.2020.10.01.00.48.18; Thu, 01 Oct 2020 00:48:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731336AbgJAHoY (ORCPT + 99 others); Thu, 1 Oct 2020 03:44:24 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:50805 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbgJAHoV (ORCPT ); Thu, 1 Oct 2020 03:44:21 -0400 X-Originating-IP: 86.206.245.199 Received: from localhost (lfbn-tou-1-420-199.w86-206.abo.wanadoo.fr [86.206.245.199]) (Authenticated sender: thomas.petazzoni@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 0D7FDFF80B; Thu, 1 Oct 2020 07:44:17 +0000 (UTC) From: Thomas Petazzoni To: Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Jan=20Kundr=C3=A1t?= , Mark Brown , Andy Shevchenko , linux-spi@vger.kernel.org, Thomas Petazzoni Subject: [PATCH v2] serial: max310x: rework RX interrupt handling Date: Thu, 1 Oct 2020 09:44:15 +0200 Message-Id: <20201001074415.349739-1-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Flag: yes X-Spam-Level: ************************** X-GND-Spam-Score: 400 X-GND-Status: SPAM Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the RX interrupt logic uses the RXEMPTY interrupt, with the RXEMPTYINV bit set, which means we get an RX interrupt as soon as the RX FIFO is non-empty. However, with the MAX310X having a FIFO of 128 bytes, this makes very poor use of the FIFO: we trigger an interrupt as soon as the RX FIFO has one byte, which means a lot of interrupts, each only collecting a few bytes from the FIFO, causing a significant CPU load. Instead this commit relies on two other RX interrupt events: - MAX310X_IRQ_RXFIFO_BIT, which triggers when the RX FIFO has reached a certain threshold, which we define to be half of the FIFO size. This ensure we get an interrupt before the RX FIFO fills up. - MAX310X_LSR_RXTO_BIT, which triggers when the RX FIFO has received some bytes, and then no more bytes are received for a certain time. Arbitrarily, this time is defined to the time is takes to receive 4 characters. On a Microchip SAMA5D3 platform that is receiving 20 bytes every 16ms over one MAX310X UART, this patch has allowed to reduce the CPU consumption of the interrupt handler thread from ~25% to 6-7%. Signed-off-by: Thomas Petazzoni --- Changes since v1: - Fix missing space when closing a comment --- drivers/tty/serial/max310x.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 8434bd5a8ec7..21130af106bb 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -1056,9 +1056,9 @@ static int max310x_startup(struct uart_port *port) max310x_port_update(port, MAX310X_MODE1_REG, MAX310X_MODE1_TRNSCVCTRL_BIT, 0); - /* Configure MODE2 register & Reset FIFOs*/ - val = MAX310X_MODE2_RXEMPTINV_BIT | MAX310X_MODE2_FIFORST_BIT; - max310x_port_write(port, MAX310X_MODE2_REG, val); + /* Reset FIFOs */ + max310x_port_write(port, MAX310X_MODE2_REG, + MAX310X_MODE2_FIFORST_BIT); max310x_port_update(port, MAX310X_MODE2_REG, MAX310X_MODE2_FIFORST_BIT, 0); @@ -1086,8 +1086,27 @@ static int max310x_startup(struct uart_port *port) /* Clear IRQ status register */ max310x_port_read(port, MAX310X_IRQSTS_REG); - /* Enable RX, TX, CTS change interrupts */ - val = MAX310X_IRQ_RXEMPTY_BIT | MAX310X_IRQ_TXEMPTY_BIT; + /* + * Let's ask for an interrupt after a timeout equivalent to + * the receiving time of 4 characters after the last character + * has been received. + */ + max310x_port_write(port, MAX310X_RXTO_REG, 4); + + /* + * Make sure we also get RX interrupts when the RX FIFO is + * filling up quickly, so get an interrupt when half of the RX + * FIFO has been filled in. + */ + max310x_port_write(port, MAX310X_FIFOTRIGLVL_REG, + MAX310X_FIFOTRIGLVL_RX(MAX310X_FIFO_SIZE / 2)); + + /* Enable RX timeout interrupt in LSR */ + max310x_port_write(port, MAX310X_LSR_IRQEN_REG, + MAX310X_LSR_RXTO_BIT); + + /* Enable LSR, RX FIFO trigger, CTS change interrupts */ + val = MAX310X_IRQ_LSR_BIT | MAX310X_IRQ_RXFIFO_BIT | MAX310X_IRQ_TXEMPTY_BIT; max310x_port_write(port, MAX310X_IRQEN_REG, val | MAX310X_IRQ_CTS_BIT); return 0; -- 2.26.2