Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2238364rwb; Fri, 2 Dec 2022 07:15:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ka8nppHcQUcnf/mJW3zlkos4Q4qEfUDvh7aDule0aiZx10/27iihyLmrCO3+RBigQm4DT X-Received: by 2002:aa7:ca4c:0:b0:46c:24fc:ba0f with SMTP id j12-20020aa7ca4c000000b0046c24fcba0fmr3406366edt.140.1669994153461; Fri, 02 Dec 2022 07:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669994153; cv=none; d=google.com; s=arc-20160816; b=y8L+vOuI2xMtcOLGzXqNlTLFBoBSUDfk+nI8nL+QanggJs/z/+p0T9+PgBBWNEj0VP BaEE8r+r7sYIpWA2l1zBE2LxydDl2u0IAleE+3f57bKeFeim6mozDjnADaJr3zeo9PKX f5OkV/nBl7RdsqHM3PLBZOL2649OExRQHdHjLeuCB/rnWhFQRiOxYrK8If1r7tQub5pj HN0oK73WF8pDQjGKkTF4B/8YrK5TPobpu85V3L7+O6qHEZjPbdeFJeLS4c7E4KY5vBNs TT9XkB4aBUX4DPM5NqEp84fR/L9w0WlV1u/Otmf/dHLlRH07TFxJ3BcQTigy88cdvhnY kpcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+yM6uzqWlcQHnwf9EkJa4vUsGzCYM7FhbIoUivFc/4Y=; b=ySy77NtzgGIvhIuIkdBdi7EK5lbF8fbTEmNVOgdXzcMm4p3ITJOx8nA5cCRBhWpmz4 RGbQfSpApFAy1bz4nFmBhVxsFjs4Q7gmvmHA3hhiKWm3tpQDr1SBMo9lG86+NsUWFT0a 4toJOZ7o27qXoXqwPk3WvPmX8SZpxllqMRZP+63z/9wOPE57IdwsPs/119twnjfMtmYZ ZeM2bnkC5o81Y272Pp0AhGhl3pvKikl4tvPMbR/lc2y8uJsHW8ppefUv/GgF/iWfgFfS egyZqP+SRRjw/QM4+Y0OEq0jF80XepG0yT6fpg2d+IATeCvKPX0IDvw65y2B11S5dXU2 PIvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a50950f000000b004626d7caf42si5588035eda.270.2022.12.02.07.15.32; Fri, 02 Dec 2022 07:15:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233532AbiLBOqt (ORCPT + 83 others); Fri, 2 Dec 2022 09:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232265AbiLBOqq (ORCPT ); Fri, 2 Dec 2022 09:46:46 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208A8C2D3E for ; Fri, 2 Dec 2022 06:46:46 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p17JJ-0002Ij-Ga; Fri, 02 Dec 2022 15:46:41 +0100 Received: from pengutronix.de (unknown [IPv6:2a03:f580:87bc:d400:63a6:d4c5:22e2:f72a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 6A01413172B; Fri, 2 Dec 2022 14:46:39 +0000 (UTC) Date: Fri, 2 Dec 2022 15:46:30 +0100 From: Marc Kleine-Budde To: Markus Schneider-Pargmann Cc: Chandrasekar Ramakrishnan , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/15] can: m_can: Cache tx putidx and transmits in flight Message-ID: <20221202144630.l4jil6spb4er5vzk@pengutronix.de> References: <20221116205308.2996556-1-msp@baylibre.com> <20221116205308.2996556-4-msp@baylibre.com> <20221201111450.fpadmwscjyhefs2u@pengutronix.de> <20221202083740.moa7whqd52oasbar@blmsp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ixaicbn435jko43j" Content-Disposition: inline In-Reply-To: <20221202083740.moa7whqd52oasbar@blmsp> X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ixaicbn435jko43j Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 02.12.2022 09:37:40, Markus Schneider-Pargmann wrote: > Hi Marc, >=20 > On Thu, Dec 01, 2022 at 12:14:50PM +0100, Marc Kleine-Budde wrote: > > On 16.11.2022 21:52:56, Markus Schneider-Pargmann wrote: > > > On peripheral chips every read/write can be costly. Avoid reading eas= ily > > > trackable information and cache them internally. This saves multiple > > > reads. > > >=20 > > > Transmit FIFO put index is cached, this is increased for every time we > > > enqueue a transmit request. > > >=20 > > > The transmits in flight is cached as well. With each transmit request= it > > > is increased when reading the finished transmit event it is decreased. > > >=20 > > > A submit limit is cached to avoid submitting too many transmits at on= ce, > > > either because the TX FIFO or the TXE FIFO is limited. This is curren= tly > > > done very conservatively as the minimum of the fifo sizes. This means= we > > > can reach FIFO full events but won't drop anything. > >=20 > > You have a dedicated in_flight variable, which is read-modify-write in 2 > > different code path, i.e. this looks racy. >=20 > True, of course, thank you. Yes I have to redesign this a bit for > concurrency. >=20 > > If you allow only power-of-two FIFO size, you can use 2 unsigned > > variables, i.e. a head and a tail pointer. You can apply a mask to get > > the index to the FIFO. The difference between head and tail is the fill > > level of the FIFO. See mcp251xfd driver for this. >=20 > Maybe that is a trivial question but what's wrong with using atomics > instead? I think it's Ok to use an atomic for the fill level. The put index doesn't need to be. No need to cache the get index, as it's in the same register as the fill level. As the mcp251xfd benefits from caching both indexes, a head and tail pointer felt like the right choice. As both are only written in 1 location, no need for atomics or locking. > The tcan mram size is limited to 2048 so I would like to avoid limiting > the possible sizes of the tx fifos. What FIFO sizes are you using currently? Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --ixaicbn435jko43j Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEBsvAIBsPu6mG7thcrX5LkNig010FAmOKD8QACgkQrX5LkNig 011nRggApqQ6QLzpNnhi7K+OdMn/p9UPZnTesrpUao+VEKOrPhAeHqJKnNqbxQAx SZBcx39+DMalId+KYY93FB5Y7TxqBAGafQjIhK+DIezdKPybIXsBapR5HmHzmchk 0oDptBDm/fxWa4akqiGOkucBXXPufVFZqWp3JDhvZkm+cN5PtwAxOJXjt5a77Op8 FBkIjiH3xt35Qbj7wjGl7XiH59QJJNakBkwiBRTXAcbzUEVgeqE9grhHJK8lmXuT 8FMXWHzOmVgpxU+LzuzrJrwjEGom6itXWzGrwTMq/y2Qw/xNXxDS1/na4ovFtNJD i2JW1ba6cSM0WYYBtDJOaFoa6AqgiQ== =mbq6 -----END PGP SIGNATURE----- --ixaicbn435jko43j--