Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp368464rwb; Thu, 1 Dec 2022 03:18:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cP3mlfO20p8zmXFYKdx3jqQehBvOWkxTivCEX2oTCU8Raf7vEkBstlkV6bI6N9mbKNDOO X-Received: by 2002:a17:906:715a:b0:7bf:b6d7:63b9 with SMTP id z26-20020a170906715a00b007bfb6d763b9mr16534758ejj.238.1669893521403; Thu, 01 Dec 2022 03:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669893521; cv=none; d=google.com; s=arc-20160816; b=qanZ5RkPRH/Z1E0V6l2G6Qdbi/C1LbWj4AksDlO9qLeEHG9RP2iXvUYI9WXJk7jJnO K22V4PlboGowifG0rycAzRu3Nn1CC66G6Rq0kGuw9MDAITwX2SfwIlqqhrLYj+zGb8qB 8v0+mVCzfvgGU+gtAex/ZxE+XCduz6Dl0CE/YPX9WHXvD5hV9iTB2jf6PBmAabUUtXdg r6NmB1SJVLSKcftLAhKgIPZBeEtr56M2OW2WYqPv9HMHbXHnet/jFp3i0E2a25hy+ite 6rzON+BgbxDxdh/wPrteu+o6dSbqApBgn8xTU1Uo9jIBBw+a9OOAw/8pwNYXInlyoWlC NFAQ== 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=3n/k+1TqbNbk3XruAjVDKWfZ9x2e5CAo+VCQq43cL5Q=; b=wYNHg+YHgfd+NaP7D+ANUyAPJvCUTTnhDqnncDUzHXYNx6sV7Z5+PRdQ63ES1SEv6b 8yVTWCYVEYoW+NesS26fjk59s0y8nmCBN6rKdXO0UfTMHmTJf3OF78G6j4/06gOOLtaP IFsY47mvVYlyiX24VXUZTr3QAE61T//q8cndcY2AfkCmR7/S3PDp28M6vKFOdCrbMsXx k4MkmVbzVJCF4R62zRS9avxabLoP/mTipYVrw0z+LU/K81UtNYSggPxJ1AJDKDLstLqV +pcW34fLmHuMv9lSTO0gB2XHOx6FCY5XdoLc+eWOB43ToF+fETPaca0hfoNRRIE8TRuT 9fHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=Yy+5OGwx; 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 gn10-20020a1709070d0a00b0078c0c866a18si4062158ejc.19.2022.12.01.03.18.21; Thu, 01 Dec 2022 03:18:41 -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=Yy+5OGwx; 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 S229732AbiLAKM3 (ORCPT + 82 others); Thu, 1 Dec 2022 05:12:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbiLAKM0 (ORCPT ); Thu, 1 Dec 2022 05:12:26 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3743D248F4 for ; Thu, 1 Dec 2022 02:12:23 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id x17so1875433wrn.6 for ; Thu, 01 Dec 2022 02:12:23 -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=3n/k+1TqbNbk3XruAjVDKWfZ9x2e5CAo+VCQq43cL5Q=; b=Yy+5OGwxesewEX3E7NwiCzowvW3JAXr/Si1kYURjyXQ+pX2gDkAbHON4dXQ0wEniyL bEGAUrFRVZKutqLTLQyP4iPS3yG07Y3X5+Qcl67+wCFgxweehXruJ/fYVXBLxlhHwRQ7 GzU0lXJTDp6NtZIrDc2tIzFjm7JuqkqjU/BP9Be/J/mZ5ZZgy8P9cpWJf0LlgUN2s5Jw bMP7FCVp7HKi/+mK+G12RfRYb0C5Q3cdRM5/Auub8gmzRE3T1x4F42lPBF7YwuYULmkF 9t3dU5yn7gkF4zjVhEpdD7rVTqGyv0GVjxoxgSNUpAIyycFavzS7GVJ45rgQVhAwC9/L b1Mg== 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=3n/k+1TqbNbk3XruAjVDKWfZ9x2e5CAo+VCQq43cL5Q=; b=kPhDxnwQJJ6sX3wsbhf1+21NVXGAUh1rxhVrZH7LanNe1wT5oMelYOMEJ7yafOWaoR huoJX5L50YfBr4zTA9yU0mLBtWpMRMWVlWNifZLrgKh5snwsw75IlczzV6OBuOQyCCU4 kL7b6j/xhL1fmZW88JSIsNPNUd3obaidtuSMJRZNssLuxe2bse+1y5qPwdTI/hzgIxUZ 1z/vqZ79Rb7XJDR9jUu56uv5SzHOkDylpejXMR6tiJ8hGAnwMVnZ4SbGH+FUjYR4PRml AVzqSQfdDCB0CqIYdoj0dNjE1l29F/J8hWpKmRviSeCwtOL78ybltxgJt1SzKdUQx+u4 LZaQ== X-Gm-Message-State: ANoB5pkIO0w8lyChjew/cIPe3liKGZ4M+gU3UOLWvYhE+kLHvWjyxkhY jMagK3akd1KPi2eSF5u6LpW1Sg== X-Received: by 2002:adf:de88:0:b0:242:15d5:7dd1 with SMTP id w8-20020adfde88000000b0024215d57dd1mr12631670wrl.207.1669889541664; Thu, 01 Dec 2022 02:12:21 -0800 (PST) Received: from blmsp ([185.238.219.84]) by smtp.gmail.com with ESMTPSA id d8-20020a05600c34c800b003cf4eac8e80sm5938699wmq.23.2022.12.01.02.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 02:12:21 -0800 (PST) Date: Thu, 1 Dec 2022 11:12:20 +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 04/15] can: m_can: Use transmit event FIFO watermark level interrupt Message-ID: <20221201101220.r63fvussavailwh5@blmsp> References: <20221116205308.2996556-1-msp@baylibre.com> <20221116205308.2996556-5-msp@baylibre.com> <20221130171715.nujptzwnut7silbm@pengutronix.de> <20221201082521.3tqevaygz4nhw52u@blmsp> <20221201090508.jh5iymwmhs3orb2v@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221201090508.jh5iymwmhs3orb2v@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=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 HI Marc, On Thu, Dec 01, 2022 at 10:05:08AM +0100, Marc Kleine-Budde wrote: > On 01.12.2022 09:25:21, Markus Schneider-Pargmann wrote: > > Hi Marc, > > > > Thanks for reviewing. > > > > On Wed, Nov 30, 2022 at 06:17:15PM +0100, Marc Kleine-Budde wrote: > > > On 16.11.2022 21:52:57, Markus Schneider-Pargmann wrote: > > > > Currently the only mode of operation is an interrupt for every transmit > > > > event. This is inefficient for peripheral chips. Use the transmit FIFO > > > > event watermark interrupt instead if the FIFO size is more than 2. Use > > > > FIFOsize - 1 for the watermark so the interrupt is triggered early > > > > enough to not stop transmitting. > > > > > > > > Note that if the number of transmits is less than the watermark level, > > > > the transmit events will not be processed until there is any other > > > > interrupt. This will only affect statistic counters. Also there is an > > > > interrupt every time the timestamp wraps around. > > > > > > > > Signed-off-by: Markus Schneider-Pargmann > > > > > > Please make this configurable with the ethtool TX IRQ coalescing > > > parameter. Please setup an hwtimer to enable the regular interrupt after > > > some configurable time to avoid starving of the TX complete events. > > > > I guess hwtimer==hrtimer? > > Sorry, yes! > > > I thought about setting up a timer but decided against it as the TX > > completion events are only used to update statistics of the interface, > > as far as I can tell. I can implement a timer as well. > > It's not only statistics, the sending socket can opt in to receive the > sent CAN frame on successful transmission. Other sockets will (by > default) receive successful sent CAN frames. The idea is that the other > sockets see the same CAN bus, doesn't matter if they are on a different > system receiving the CAN frame via the bus or on the same system > receiving the CAN frame as soon it has been sent to the bus. Thanks for explaining. I wasn't aware of that. I agree on the timer then. > > > For the upcoming receive side patch I already added a hrtimer. I may try > > to use the same timer for both directions as it is going to do the exact > > same thing in both cases (call the interrupt routine). Of course that > > depends on the details of the coalescing support. Any objections on > > that? > > For the mcp251xfd I implemented the RX and TX coalescing independent of > each other and made it configurable via ethtool's IRQ coalescing > options. > > The hardware doesn't support any timeouts and only FIFO not empty, FIFO > half full and FIFO full IRQs and the on chip RAM for mailboxes is rather > limited. I think the mcan core has the same limitations. Yes and no, the mcan core provides watermark levels so it has more options, but there is no hardware timer as well (at least I didn't see anything usable). > > The configuration for the mcp251xfd looks like this: > > - First decide for classical CAN or CAN-FD mode > - configure RX and TX ring size > 9263c2e92be9 ("can: mcp251xfd: ring: add support for runtime configurable RX/TX ring parameters") > For TX only a single FIFO is used. > For RX up to 3 FIFOs (up to a depth of 32 each). > FIFO depth is limited to power of 2. > On the mcan cores this is currently done with a DT property. > Runtime configurable ring size is optional but gives more flexibility > for our use-cases due to limited RAM size. > - configure RX and TX coalescing via ethtools > Set a timeout and the max CAN frames to coalesce. > The max frames are limited to half or full FIFO. mcan can offer more options for the max frames limit fortunately. > > How does coalescing work? > > If coalescing is activated during reading of the RX'ed frames the FIFO > not empty IRQ is disabled (the half or full IRQ stays enabled). After > handling the RX'ed frames a hrtimer is started. In the hrtimer's > functions the FIFO not empty IRQ is enabled again. My rx path patches are working similarly though not 100% the same. I will adopt everything and add it to the next version of this series. > > I decided not to call the IRQ handler from the hrtimer to avoid > concurrency, but enable the FIFO not empty IRQ. mcan uses a threaded irq and I found this nice helper function I am currently using for the receive path. irq_wake_thread() It is not widely used so I hope this is fine. But this hopefully avoids the concurrency issue. Also I don't need to artificially create an IRQ as you do. > > > > I've implemented this for the mcp251xfd driver, see: > > > > > > 656fc12ddaf8 ("can: mcp251xfd: add TX IRQ coalescing ethtool support") > > > 169d00a25658 ("can: mcp251xfd: add TX IRQ coalescing support") > > > 846990e0ed82 ("can: mcp251xfd: add RX IRQ coalescing ethtool support") > > > 60a848c50d2d ("can: mcp251xfd: add RX IRQ coalescing support") > > > 9263c2e92be9 ("can: mcp251xfd: ring: add support for runtime configurable RX/TX ring parameters") > > > > Thanks for the pointers. I will have a look and try to implement it > > similarly. > > If you want to implement runtime configurable ring size, I created a > function to help in the calculation of the ring sizes: > > a1439a5add62 ("can: mcp251xfd: ram: add helper function for runtime ring size calculation") > > The code is part of the mcp251xfd driver, but is prepared to become a > generic helper function. The HW parameters are described with struct > can_ram_config and use you can_ram_get_layout() to get a valid RAM > layout based on CAN/CAN-FD ring size and coalescing parameters. Thank you. I think configurable ring sizes are currently out of scope for me as I only have limited time for this. Thank you Marc! Best, Markus