Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1427447rdg; Sat, 14 Oct 2023 01:32:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGV7zfazSnPrjm/KQbQX2uQ3WMwHB7/xrA3yHhkHP+bs5xuWY2Z52nFjh+vTW0M/RQfTvqO X-Received: by 2002:a17:902:8f8b:b0:1c5:f0fd:51be with SMTP id z11-20020a1709028f8b00b001c5f0fd51bemr27386556plo.69.1697272330107; Sat, 14 Oct 2023 01:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697272330; cv=none; d=google.com; s=arc-20160816; b=Ep2S0Wg2fqy/HolMJO7BETGTTrSpFppNGoKJnWRsY9SXRQWBwzHjQXJJRXdbsoMdQU 2dSq4At1U8oIOqTKyYwjsDp7j+cyhA4lKAXZQpWV+/PthEJZPbByFBAkKzqNV3ZhAxQJ /r7Sxw+gj5dyLcmxx3kTqPExQlOTNdwkM8pIXMqFxLyVPJNqfLqnzFovNKWNWMPX8tji cMC/ARtUleDs8sRK+DrYTfTgXPiCXnkL4SRjrhQVZCwNZRDbm9L4w6CnlyVdUQbN3lqG EhxIH4G4cwjsFnk6/Iazst5PCX/IFGHClFKDnk6Pi1dq2Dkq1YFrRSfWD+zacifN4Ukt nbdg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lsTkinutB/dPxs5j/wMFHjfKPGzWlLayoh/HbqYxoqo=; fh=SPiAvvsuOi6mW9E8hVmmJW4uSm5J3/ue8qwNnt0PWE0=; b=EoI9kGO1plBmUUUh4uxefMOkYp+JNWx2cIwUP5wZGYmLGhjSAlU1/mLNnbiWRcbUdY ETxXPLesD2CaNPhpD+vBmZPhlTLp2p2aaxq9K2fqqASUyZi3andQgoi2E80Xeb5IZeaL AVQuiBoMGsEiWSvCvR1lySU0e1uBFlNWISpabqstMbto+QYrbTcvDQTipAtuN8UDKZyh oKnE1rlFtfr1AKI+efpW7K+kkP0W6NVV8rogk1f9i8zppkLwuZ8mNYmRhSg0YjzAH7Qt 9EuwcaIPoSuT36N5j4rJHWkn/2yHMnEN4Mjzs4WpAJ6z5aJdCjUKnGDNnX3L4dxWTgKn sMXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mess.org header.s=2020 header.b=ijIzx2jp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mess.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t12-20020a170902e84c00b001c62e2ce6a7si5063553plg.445.2023.10.14.01.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 01:32:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@mess.org header.s=2020 header.b=ijIzx2jp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mess.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 97574809A7BE; Sat, 14 Oct 2023 01:32:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232912AbjJNIbw (ORCPT + 99 others); Sat, 14 Oct 2023 04:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231377AbjJNIbv (ORCPT ); Sat, 14 Oct 2023 04:31:51 -0400 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C129FBB; Sat, 14 Oct 2023 01:31:49 -0700 (PDT) Received: by gofer.mess.org (Postfix, from userid 1000) id C3E3F1000C4; Sat, 14 Oct 2023 09:31:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mess.org; s=2020; t=1697272307; bh=XsNGeilpUplKizUnx/qOZo3xjouGfDpjsPn9CRnokek=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ijIzx2jp1WzMQE8iElh52WDBYVSbJDBeO1DyETXybgvzCjWPMwTQS+kVSG6n01uIC JregG6Q8mt6N3OHGp5WlfhmpQ5mweHFRlpXKZOAUCjCfsMEMYxzZtdc6sByDkXo711 hw5OlA+64xysXPTSEPrvog3wnoYHQduGR2IdTxb+bQcqkyc3fIPqBvL9DGii1Qh38f 6slXu0E8lJAkO2BkUYb2b3lFSZeedXhzPIVlHT6FRuNrYgDqk9Veuh+87MDNB6Ha5e BkW1ctXpq4VRFh4IC/R9ZRg3dJNT9skMTn8XXbNnY5/M4edMabuCoutNWzQ6k6x4CL Yu3FZ/rbjCuuw== Date: Sat, 14 Oct 2023 09:31:47 +0100 From: Sean Young To: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Cc: Thierry Reding , linux-media@vger.kernel.org, Ivaylo Dimitrov , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] pwm: make it possible to apply pwm changes in atomic context Message-ID: References: <9c0f1616fca5b218336b9321bfefe7abb7e1749f.1697193646.git.sean@mess.org> <20231013180449.mcdmklbsz2rlymzz@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231013180449.mcdmklbsz2rlymzz@pengutronix.de> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 14 Oct 2023 01:32:07 -0700 (PDT) Hello, On Fri, Oct 13, 2023 at 08:04:49PM +0200, Uwe Kleine-K?nig wrote: > On Fri, Oct 13, 2023 at 05:34:34PM +0200, Thierry Reding wrote: > > On Fri, Oct 13, 2023 at 03:58:30PM +0100, Sean Young wrote: > > > On Fri, Oct 13, 2023 at 01:51:40PM +0200, Thierry Reding wrote: > > > > On Fri, Oct 13, 2023 at 11:46:14AM +0100, Sean Young wrote: > > > > [...] > > > > > diff --git a/include/linux/pwm.h b/include/linux/pwm.h > > > > > index d2f9f690a9c1..93f166ab03c1 100644 > > > > > --- a/include/linux/pwm.h > > > > > +++ b/include/linux/pwm.h > > > > > @@ -267,6 +267,7 @@ struct pwm_capture { > > > > > * @get_state: get the current PWM state. This function is only > > > > > * called once per PWM device when the PWM chip is > > > > > * registered. > > > > > + * @atomic: can the driver execute pwm_apply_state in atomic context > > > > > * @owner: helps prevent removal of modules exporting active PWMs > > > > > */ > > > > > struct pwm_ops { > > > > > @@ -278,6 +279,7 @@ struct pwm_ops { > > > > > const struct pwm_state *state); > > > > > int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, > > > > > struct pwm_state *state); > > > > > + bool atomic; > > > > > struct module *owner; > > > > > }; > > > > > > > > As I mentioned earlier, this really belongs in struct pwm_chip rather > > > > than struct pwm_ops. I know that Uwe said this is unlikely to happen, > > > > and that may be true, but at the same time it's not like I'm asking > > > > much. Whether you put this in struct pwm_ops or struct pwm_chip is > > > > about the same amount of code, and putting it into pwm_chip is much > > > > more flexible, so it's really a no-brainer. > > > > > > Happy to change this of course. I changed it and then changed it back after > > > Uwe's comment, I'll fix this in the next version. > > > > > > One tiny advantage is that pwm_ops is static const while pwm_chip is > > > allocated per-pwm, so will need instructions for setting the value. Having > > > said that, the difference is tiny, it's a single bool. > > > > Yeah, it's typically a single assignment, so from a code point of view > > it should be pretty much the same. I suppose from an instruction level > > point of view, yes, this might add a teeny-tiny bit of overhead. > > > > On the other hand it lets us do interesting things like initialize > > chip->atomic = !regmap_might_sleep() for those drivers that use regmap > > and then not worry about it any longer. Sure. > > Given that, I'm also wondering if we should try to keep the terminology > > a bit more consistent. "Atomic" is somewhat overloaded because ->apply() > > and ->get_state() are part of the "atomic" PWM API (in the sense that > > applying changes are done as a single, atomic operation, rather than in > > the sense of "non-sleeping" operation). Good point. > > So pwm_apply_state_atomic() is then doubly atomic, which is a bit weird. > > On the other hand it's a bit tedious to convert all existing users to > > pwm_apply_state_might_sleep(). > > > > Perhaps as a compromise we can add pwm_apply_state_might_sleep() and > > make pwm_apply_state() a (deprecated) alias for that, so that existing > > drivers can be converted one by one. > > To throw in my green for our bike shed: I'd pick > > pwm_apply_state_cansleep() > > to match what gpio does (with gpiod_set_value_cansleep()). (Though I > have to admit that semantically Thierry's might_sleep is nicer as it > matches might_sleep().) I have to agree here. "can" is shorter and clearer than "might", since "can" expresses capability. Having said that the mixture of nomenclature is not great, so there is very little between them. > If we don't want to have an explicit indicator for the atomic/fast > variant (again similar to the gpio framework), maybe we can drop > "_state" which I think is somehow redundant and go for: > > pwm_apply (fast) > pwm_apply_cansleep (sleeping) > pwm_apply_state (compat alias for pwm_apply_cansleep()) > > (maybe replace cansleep with might_sleep). This is very nice. :) There are callsites in 15 files, might as well rename it and do away with pwm_apply_state() > Similar for pwm_get_state() > we could use the opportunity and make > > pwm_get() > > actually call ->get_state() and introduce > > pwm_get_lastapplied() > > with the semantic of todays pwm_get_state(). Do we need a > pwm_get_cansleep/might_sleep()? Not all drivers implement .get_state(), how would we handle those? Thanks, Sean