Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8712874rwb; Tue, 13 Dec 2022 09:31:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+4if0JvJlR4zoI7A5w4Lvz443fnmM56+GRwiXwVlktQ/a1OeHDbzvU1k77T46Lq9PCt+G X-Received: by 2002:a17:902:eec6:b0:190:c7fc:f1b0 with SMTP id h6-20020a170902eec600b00190c7fcf1b0mr3296703plb.40.1670952680900; Tue, 13 Dec 2022 09:31:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670952680; cv=none; d=google.com; s=arc-20160816; b=Uah2LzBvwUrUeRwdahzjUMpVmCJtKP1saAHnga6R04/B+je2/8bp/O5ch514krUbc7 hNNe/doTnce0isBQxE77+YaYksGikxGPoCuIRbp+eZ4wK2QbFMWncw5S1U1bNEpWD5Bi eWYLcvNnzKSzSUKmquGhYTRFmNhZYwASHXHtaMQ1rpzNeVH9braxjOJLEQQxj/BmLCMW jgZoedQNHNo4Mm8j3/MvaZ6t5MUCxZqyaGmavX5LzASm9rnIkP+3B3z3zh9xoqYn1Y6w zB4hXdoz/vT9a52H3cjZRYlpuHdt6PAlpCp3BQsDr7kx1ORXWeQZZHEU6NvCoYrH89fC O5Cg== 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:dkim-signature; bh=wbQFyaeQ3XEAXhWOdQEYNCmIqs2vEtR7/9/GJv05CpI=; b=N/NUWjLcDDU51jihSknOzk8QJSY22cVhC68fmfwNdcwEo7SdyUwy5sOtXdqkKhsvBE cAdBgREiRu2clB300AbVk5MEFYfJSMIPXi9xRXqL27ZJWuMfNLGFfa7t5xJZlznmspL2 FMMfS4dD5Hps298RgNqqgvRr4P029lWMfvnuMuY4z2IghjMxr8lElLMaAeH//TjTbaIV 9wXrAzn/UNGqkMoZhUwxho3OdPQUQQzO+3lG0Uq3XQIguHkPDqAzImIKIwefR1tLRHUO 1Vm/jCOqD+Akp0nh/qp4dvWYilAFMGgLpgTRSyTEPWYCZyGLMOH58IMEcD4t0hjobvCn T1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=j4YWBLG1; 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 s11-20020a170902a50b00b00189e149a1bcsi325435plq.30.2022.12.13.09.31.11; Tue, 13 Dec 2022 09:31:20 -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; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=j4YWBLG1; 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 S231888AbiLMRNP (ORCPT + 72 others); Tue, 13 Dec 2022 12:13:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234027AbiLMRNN (ORCPT ); Tue, 13 Dec 2022 12:13:13 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FD796365 for ; Tue, 13 Dec 2022 09:13:12 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id h11so16331722wrw.13 for ; Tue, 13 Dec 2022 09:13:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wbQFyaeQ3XEAXhWOdQEYNCmIqs2vEtR7/9/GJv05CpI=; b=j4YWBLG15Slcs0Fq+ePqgTHB7thUqj9f5sCRbYQb15sZmW4s9FkW1yZFt19E0CTt0B pR97bH1C14/EcQglaA6T0lcZttEOFhYUhL2Idbi+v02h74vYMdw8n14uI5VQgvrJz3AD 9dM8ve9EDypSt2MzAJrsAtME6KF5qRDSYqpo+rKBAibwjVGYB/EO/9zRMWOyNICOAxbK l/4R5a7tQQABMY2lIo+5DkOYEfdwnvrFt5FiZox7KF8oQv1JR6XeWipJ/Fq+qdHT44Al NVpKfxqMDMFyLomvAXAAgRv0PQqIM5shQOgQpPOfUvmHUmkoF0OkSaK3gPBdLYXWlZO3 +kkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wbQFyaeQ3XEAXhWOdQEYNCmIqs2vEtR7/9/GJv05CpI=; b=x7FHAwk8bA6tXaD/fsnhQ7XTcA0iYneoxORBqVmjFTljH8k7qwIZiplxRN473oOzeS 7kL4Gl8imW8eIbHwPiDn0dCI3QZOjb1tPorxq+fm/HAt39S157a639KIVc5QvPZYVDpw L3V9KYYQ2wcVXE0KRhfKJAtcXB8lZIxefI+CpRDjQi2SrboSA1bv22VKfX6gTJ6LiqLA lOBiSsiaylLG2qr25DT1NQx+Vm1hRgH3c7XvOaS0ORNSoOwI7gTC+NfmJUpJ/ePc3Xok LVdCs+oMqW6YLYXZO8TKkr5uuwjR0M+Mu6AMXbg7B7DTQalLvrmDOuRfOVFMn+L4IDlQ aWXQ== X-Gm-Message-State: ANoB5pktcw4CDbg8cJZqRPwxR1cWWmS7Hz95qg7IKcYBaI9ujVIuFIou bStsWdLQbgeS/4qKpsW/seeNPdEjIz71thfW X-Received: by 2002:a5d:5108:0:b0:242:1ce8:c51c with SMTP id s8-20020a5d5108000000b002421ce8c51cmr15560798wrt.45.1670951590848; Tue, 13 Dec 2022 09:13:10 -0800 (PST) Received: from blmsp ([2001:4091:a245:805c:8713:84e4:2a9e:cbe8]) by smtp.gmail.com with ESMTPSA id c2-20020a5d4f02000000b00241cfe6e286sm277400wru.98.2022.12.13.09.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 09:13:10 -0800 (PST) Date: Tue, 13 Dec 2022 18:13:09 +0100 From: Markus Schneider-Pargmann To: Marc Kleine-Budde 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: <20221213171309.c4nrdhwjj2ivrqim@blmsp> References: <20221116205308.2996556-1-msp@baylibre.com> <20221116205308.2996556-4-msp@baylibre.com> <20221201111450.fpadmwscjyhefs2u@pengutronix.de> <20221202083740.moa7whqd52oasbar@blmsp> <20221202144630.l4jil6spb4er5vzk@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221202144630.l4jil6spb4er5vzk@pengutronix.de> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Fri, Dec 02, 2022 at 03:46:30PM +0100, Marc Kleine-Budde wrote: > On 02.12.2022 09:37:40, Markus Schneider-Pargmann wrote: > > Hi Marc, > > > > 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 easily > > > > trackable information and cache them internally. This saves multiple > > > > reads. > > > > > > > > Transmit FIFO put index is cached, this is increased for every time we > > > > enqueue a transmit request. > > > > > > > > The transmits in flight is cached as well. With each transmit request it > > > > is increased when reading the finished transmit event it is decreased. > > > > > > > > A submit limit is cached to avoid submitting too many transmits at once, > > > > either because the TX FIFO or the TXE FIFO is limited. This is currently > > > > done very conservatively as the minimum of the fifo sizes. This means we > > > > can reach FIFO full events but won't drop anything. > > > > > > You have a dedicated in_flight variable, which is read-modify-write in 2 > > > different code path, i.e. this looks racy. > > > > True, of course, thank you. Yes I have to redesign this a bit for > > concurrency. > > > > > 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. > > > > 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? I am currently using 13 for TXB, TXE and RXF0. Best, Markus