Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2776317pxv; Sun, 25 Jul 2021 05:17:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtbHGCSt4AOI7l8UnksduSPCmVmu3krb9qVA+iDR/uu8hneYVOVU5VapkPHUIuKRYCCvWP X-Received: by 2002:a05:6638:14c1:: with SMTP id l1mr11705458jak.97.1627215434121; Sun, 25 Jul 2021 05:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627215434; cv=none; d=google.com; s=arc-20160816; b=x8kSWMaMGIxFXBVQVEe0fhWCNTGd//ZVgFaEvEvL2z/71kgbWJ/QuBh10b+JJgsL9h x3jeVTHqgldmm6rdjAUqKDfKDu5BqvpYW4RKkKLlgFl8X1IMst0sGdV7AHue19r0S5rW yZrkwe4ZeUvUOCGWh2kkfn1phcEo9dtp9i8KcQ/qhCcwejkY0XHTXs+0bm+olFuHCIOo 0g+7o0DHWOxdaXJ43OVUSGH57uXjEBmM75t1ErFpTG5Zy4RReKod7SnJb19LafyVOBFk HCxFu+XAUga0Yj7bjMRZiGN+Cpn6SjOK5YjVnsrvcJYHqjn00Rq1BhRX9FT2tcYC84Dl nNog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yt9/oTHj8mLe3fC8cT0Qxcw3ic4D1wzxMFAtiuNobKY=; b=MNp/QPVgyxqL/niuHdcCapYWDzXGIoN1ArU6WzhKXqqrTSHNsRnVKQfuBhFQALka9y Xycgu6GRyaUKIT2HrSBVE0/thKbTsG4Tw3Bky7ZqXrMk3nCLJ80Fq1dc2gL8iMgFoIZg a3OT+LMMW3KZCVYQ2YfBFf9TmHUbavdcAaa1zdrsjdlOUAfrAIO6mvNev+KfLCgGauok oHn78BALtf4D4bhKu/GSyKqFs8gn41FBsFkcPOLK7CP3NLE8K0vW2oeb1ZKof3bNXIVh w8L4eZEDvKQUL/vrFYwBjuIuITbwL+hqto7kAhRMgR0GSt+zqbWLeZP0fytVvvigJSrv slig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aEDCgZvS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x14si40191610jab.2.2021.07.25.05.16.44; Sun, 25 Jul 2021 05:17:14 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aEDCgZvS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbhGYLeP (ORCPT + 99 others); Sun, 25 Jul 2021 07:34:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:48272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbhGYLd4 (ORCPT ); Sun, 25 Jul 2021 07:33:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E25B660F13; Sun, 25 Jul 2021 12:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627215265; bh=kduJYIait4oOIsS6HVhuBc3H0dAcsqPllKnu/62xyhk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aEDCgZvSpJ4h8nPjCc5kbRnzy+3EkYX/BsZhEO4Qpzl3kiWNTSp2pvPxrS+XB4Rjl qd5ND6aum7AA2J95mkpTZf8bgjnA962y/N+JSvRy9i2qbS8JjqL/OaU3HAzKyjwSqg WV//vN6q7GNCSyvf7lPa+cCe4gq5pPNPZe3j/x262DfG9JoQXpbuBolw8KGXl3ON6j Vw8WiV8AQvrX9NN1R7qPB6ONOkP3GRMbvJEaSkbzkKy1vntmFNcZGv/Bk3ay0C/36I BwbR6wvakHBCEKOUKu63xLjSeppFKiBJ5dA2IeRntMVnGEMD/tXaAJRzrUTQEBJjkS /25rUF9Ss6y/w== Received: by pali.im (Postfix) id 75CBF949; Sun, 25 Jul 2021 14:14:22 +0200 (CEST) Date: Sun, 25 Jul 2021 14:14:22 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Andrew Lunn Cc: Michael Turquette , Stephen Boyd , Rob Herring , Greg Kroah-Hartman , Gregory Clement , Sebastian Hesselbarth , Vladimir Vid , Marek =?utf-8?B?QmVow7pu?= , Geert Uytterhoeven , linux-clk@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 2/5] serial: mvebu-uart: implement UART clock driver for configuring UART base clock Message-ID: <20210725121422.26agyztfrsrn43xg@pali> References: <20210624224909.6350-1-pali@kernel.org> <20210717123829.5201-1-pali@kernel.org> <20210717123829.5201-3-pali@kernel.org> <20210717180540.ersg5bslik6ivjie@pali> <20210724094816.2y3peclaftx26kwj@pali> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Saturday 24 July 2021 18:33:33 Andrew Lunn wrote: > On Sat, Jul 24, 2021 at 11:48:16AM +0200, Pali Rohár wrote: > > On Saturday 17 July 2021 20:05:40 Pali Rohár wrote: > > > On Saturday 17 July 2021 19:26:51 Andrew Lunn wrote: > > > > On Sat, Jul 17, 2021 at 02:38:26PM +0200, Pali Rohár wrote: > > > > > @@ -445,6 +472,7 @@ static void mvebu_uart_shutdown(struct uart_port *port) > > > > > static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud) > > > > > { > > > > > unsigned int d_divisor, m_divisor; > > > > > + unsigned long flags; > > > > > u32 brdv, osamp; > > > > > > > > > > if (!port->uartclk) > > > > > @@ -463,10 +491,12 @@ static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud) > > > > > m_divisor = OSAMP_DEFAULT_DIVISOR; > > > > > d_divisor = DIV_ROUND_CLOSEST(port->uartclk, baud * m_divisor); > > > > > > > > > > + spin_lock_irqsave(&mvebu_uart_lock, flags); > > > > > > > > Hi Pali > > > > > > > > You only need spin_lock_irqsave() if you plan on taking the spinlock > > > > in an interrupt handler. It seems unlikely the baud rate will be > > > > changed in interrupt context? Please check, and then swap to plain > > > > spin_lock(). > > > > > > Hello! Ok, I will check it. > > > > Well, driver is already using spin_lock_irqsave() in all other > > functions. > > And some of those functions are called from interrupt context i > expect. For each lock you have, you need to decide if interrupt > context is an issue or not. spin_lock_irqsave() is more expansive, > since it has to disable interrupts, etc. It can upset real time > latency etc. So in the hot path, you want to try to avoid it, unless > you actually need it. But changing the baud rate is not the hot path, > it hardly every happens, so we can live with the unneeded overhead. It happens either one time during "device" probing (e.g. when connected bluetooth UART device want to use higher baudrate) or when user explicitly ask to change baudrate (e.g. when want to transfer files over UART via x/y/z-modem / kermit protocol). Or maybe if somebody wants to establish and use PPP network over UART. So it should not be a problem. > > And in linux/clk-provider.h is documented that drivers can call > > clk_enable() from an interrupt, so it means that spin_lock_irqsave() is > > really needed for mvebu_uart_lock. > > Sure, drivers can. But in this case, does a driver actually do that? > Does it change the baud rate in interrupt context? Looks like that changing baudrate not. But other places where this lock is used (e.g. in clk callbacks) can be called from interrupt context. But for baudrate change, I think it is not so common action, so there should not be issue with slightly higher overhead. > > > In other patches is updated function mvebu_uart_set_termios() which > > > verifies that you can set particular baudrate. > > Great. It is not clear from the patches or the commit message that > this has been considered. It is something worth mentioning, just to > avoid questions. This check was there also prior my patches. I only "extended" it to match what is supported by this patch series. > > > Also note that all A3720 boards have disabled UART2 in DTS. And I'm not > > > sure if there is somebody who uses UART2 or who uses both UARTs. > > That does not really matter. You should not regression a feature > because you think nobody is using it. I know. That is why I introduced code which recalculates divisors registers to not change baudrate of UART2 during loading of UART1 and also introduction of this clk subdriver with locks to prevent any regressions.