Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4592279pxk; Wed, 30 Sep 2020 07:02:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRDO/FZcR8s47i7xHCz9BlhOYe4BKNkbv1o8hqqNhrlun2BDAHXxUonqXDEqN/mLmlPkMv X-Received: by 2002:aa7:c387:: with SMTP id k7mr2788513edq.242.1601474562517; Wed, 30 Sep 2020 07:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601474562; cv=none; d=google.com; s=arc-20160816; b=J95retXA9yXTvRAd4Px/wg60b2jo2T5Di4mjY9Y1fhUigBmbthISJ/NVQOTj4Y4LxM ke889EXp/L2YzTYqoD+bCTIFKidaKs/Wnn1kopwSci+hld6/IzLOrLDA9+2zGGhX+bSv 7erjOO+VBgYncyd3Pueyz/qS3GkmncMIRKzbg7svONmGA6y5vQ1/MzgR26Nnx1o+Vk+J Ew0AABagEuo+MP4/Ul+9uQBtkAjk4Fx8eJpqwOH9WcFN9BP8K3iJ72YX1BcgAHLajw4P u4obP9znIbzcEus+uJ/+ZxYDlGg2bKgEBXSXpc2szTDuZT8BvWdEzava5+NvCQFoxoeh ajWQ== 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=oChFHmPUlAsE7oFKbjVgWZllA0ThxU/HbSEh/5f+IVU=; b=flYKisBVrnhCQ0VMGX3mNQo+zhZXUJmuuj85hgLdhi7Uodsa0T9xsVlvD+rOy0+9bZ FQUTOKPgzm6xDoPvUh2mYIJf5H6eIBttXZefTkdgLz3/ekBnl0oueu3dRA/doFhaQrM3 o1YsG8Do4zQ7wJBmPtkJLDWUvCxS9P/1ktn8RnH9GxhE+H59RjGQJe3DW3hTzvJZV8fM eefwMXFlSyfT7EJ/xAEAs4ReL9Xn9rvVlgREA131pDt7ZXOlw5EUNptVu1EqNqcJrdpf LSFSgJFyAqUJsUiTpueBsJUoaGlIHq9AEXP6d25X0PBs6wj+VLS6jDjNb2rtGlQ/9cIu /KiQ== 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 x24si1137918eju.477.2020.09.30.07.02.17; Wed, 30 Sep 2020 07:02:42 -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 S1730294AbgI3N7h (ORCPT + 99 others); Wed, 30 Sep 2020 09:59:37 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:57198 "EHLO mslow2.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729903AbgI3N7h (ORCPT ); Wed, 30 Sep 2020 09:59:37 -0400 Received: from relay3-d.mail.gandi.net (unknown [217.70.183.195]) by mslow2.mail.gandi.net (Postfix) with ESMTP id C74DE3BA7E2; Wed, 30 Sep 2020 13:52:06 +0000 (UTC) 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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 0D7F260008; Wed, 30 Sep 2020 13:51:43 +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] serial: max310x: rework RX interrupt handling Date: Wed, 30 Sep 2020 15:51:37 +0200 Message-Id: <20200930135137.197592-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 --- 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 8434bd5a8ec78..a1c80850d77ed 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