Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp293184rwe; Fri, 14 Apr 2023 02:59:37 -0700 (PDT) X-Google-Smtp-Source: AKy350bWivwZQzjsSU+L22FGVJgxOZJLw3mgoyQSKzhuq/v1c6J9zYawolaezh4dpR40mSndiskc X-Received: by 2002:a17:90a:718b:b0:23d:816:faa9 with SMTP id i11-20020a17090a718b00b0023d0816faa9mr4959866pjk.12.1681466377035; Fri, 14 Apr 2023 02:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681466377; cv=none; d=google.com; s=arc-20160816; b=I5B/vHCc2xT06phkh6PSUj+Bi8volQx8eu0KO1SubntZiFqb/9nOytlTfwXGk/xPmm l1yigsz+sgu7OZNW6WMkFYUWX9bPSKiaY1W4nLLAz/HIZIz0Fvml03Ka1PBdVHB/M0jl mjbAF/tP41rNMMmP0U2UquEVfEzKs1j7azkA8nXKvwpvTZOjDjIoU1dLlT90/IaMBoVY O6ogzxv73bOLGtEpK3jyMvjkhywpgvAkYRsnDNpe/+Mjzt68PVG07EUbWseo56tJ+t+7 VMNX2sVzK1yWbaeaSdtC/LEwexwzj8oV05zADAsk4kYagaX7c87IvuZ49nNm+gch1lh6 g47w== 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:feedback-id:dkim-signature:dkim-signature; bh=IuAt25PuIwklRF6lreyCDjd9ANtwMrdRQyAe2Pl8oSw=; b=wCAEwdJ2S9IhMy3Wt76OlUvloGvJ8gnsXThhbSczEeUG9tElUnzQN0y/M1c/dl5Yil XeHXLgDNvbKa8oc1oIQ9XoaMOg21TQIGtfwzhtReyoFnh+LQMStY5o8h0Ozo5KQjQ6VG 8UXD7Co5i31g3vUwjIV+oJm5SGhBCZriNjuzMcEGu4YFMYBQiZDaIAdJf4XLw4GdSaTD b0DeSeI1hhmEhwEJVpNIiOUG4q75pou1AKzIh19EJoVPTd4QOnQEPr1w6c3PF9MSVWRi C5DuKXE+D6xPF5TJZUlxO3gWgCbLeOT0AKuP+Aj17pd3o66Dz32RXGQZlPCIQzlVK+gL N3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=mrubuJ3p; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=f9lXfpp0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r23-20020a170902be1700b00192721d6a97si4095532pls.499.2023.04.14.02.59.25; Fri, 14 Apr 2023 02:59:37 -0700 (PDT) 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=@cerno.tech header.s=fm2 header.b=mrubuJ3p; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=f9lXfpp0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbjDNJxS (ORCPT + 99 others); Fri, 14 Apr 2023 05:53:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjDNJxP (ORCPT ); Fri, 14 Apr 2023 05:53:15 -0400 Received: from wnew3-smtp.messagingengine.com (wnew3-smtp.messagingengine.com [64.147.123.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B42B9027; Fri, 14 Apr 2023 02:53:12 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.west.internal (Postfix) with ESMTP id AAF1D2B0679D; Fri, 14 Apr 2023 05:53:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 14 Apr 2023 05:53:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1681465989; x=1681473189; bh=IuAt25PuIwklRF6lreyCDjd9ANtwMrdRQyA e2Pl8oSw=; b=mrubuJ3pUqucxIgcnTobWejh8sU5RM2yjKfxicfUpurcdS1ql28 qJ9G2RMu2ZjVoCmC6mqz6pv3uMONr2INMhoUIg+GpvYE5kyNpclfREj/AXloLWJb sO705sT66L2P4AaMMTj5mvwJ6ZGkAo8ZiLjx8i0e5yPiNPayyrIV3gxpKq1nvQCH vmlXnAdJo7n86K+5D3Pw/qaX3J0tnvNR1YtTGdY+sbK6iaM/gjsHyABVz73w33wA JqFPRdoGRRmzAcs5beo+XbZ0+UN1HmQZegzWIW7lIuDftE90s9s0TKo1Wp6pY0+A 0AG5vP5Fi3RHpsABvcwuR41B9VERdJU1Bmw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1681465989; x=1681473189; bh=IuAt25PuIwklRF6lreyCDjd9ANtwMrdRQyA e2Pl8oSw=; b=f9lXfpp0A9wAwmAD81ZEwHm5nhO5d9rdbQud9QjZfrnmRZ35Ujc QfB+qB8Dxlcyn5SLuVim1cCnZn1/NDhaFK7RCaS8Xcr9d+V229M6RUfY7FuahDIa T1lbEZG6MnIxV7qBxXP3KXaRbCdZRkVfsVNJmgExeJ0KYmsEiKAZLhyj/nDoNPtY hjGWup1lSDzvwa71wfZVfcyMQCk5zHKlzGcd7C94vFnuuFpBYyj9mfjkawEFhsQF BcCQ7pfOEJvt4iPua7FcJjIofdpZC+/CorxEKtMqijppTh3slcnTIzPO7yL/B8ac icyBue5aKtJ5dkgvyCYM7N1sftyw0egiFDA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeltddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtqhfstddttddvnecuhfhrohhmpeforgig ihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrf grthhtvghrnhepgeehheeljeeftdektedvudejvdekueejkeevueektdeuvedthfeljeff gffhvdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Apr 2023 05:53:08 -0400 (EDT) Date: Fri, 14 Apr 2023 11:53:04 +0200 From: Maxime Ripard To: David Gow Cc: Matti Vaittinen , Brendan Higgins , Stephen Boyd , Shuah Khan , Daniel Latypov , Rae Moar , Benjamin Berg , Greg Kroah-Hartman , "Rafael J . Wysocki" , Heikki Krogerus , Jonathan Cameron , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Subject: Re: [RFC PATCH v2 1/3] kunit: Add kunit_add_action() to defer a call until test exit Message-ID: <7btnpvso6mwocb3vycxklcbq37bwdggpeuju3lp2aaye62jr7r@d27cuwze63bs> References: <20230331080411.981038-1-davidgow@google.com> <20230331080411.981038-2-davidgow@google.com> <20230404133231.ingzo7xy7lejpqqb@houat> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, Apr 05, 2023 at 03:47:55PM +0800, David Gow wrote: > On Tue, 4 Apr 2023 at 21:32, Maxime Ripard wrote: > > > > Hi David, > > > > Looks great, thanks for sending a second version > > > > On Fri, Mar 31, 2023 at 04:04:09PM +0800, David Gow wrote: > > > +/** > > > + * kunit_remove_action_token() - Cancel a deferred action. > > > + * @test: Test case the action is associated with. > > > + * @cancel_token: The cancellation token returned by kunit_add_actio= n() > > > + * > > > + * Prevent an action deferred using kunit_add_action() from executin= g when the > > > + * test ends. > > > + * > > > + * You can also use the (test, function, context) triplet to remove = an action > > > + * with kunit_remove_action(). > > > + */ > > > +void kunit_remove_action_token(struct kunit *test, struct kunit_acti= on_ctx *cancel_token); > > > > It's not clear to me why we still need the token. If > > kunit_remove_action() works fine, why would we need to store the token? > > > > Can't we just make kunit_add_action() return an int to indicate whether > > it failed or not, and that's it? > > >=20 > So the distinction here is that the (function, context) pair doesn't > uniquely identify an action, as you can add the same action multiple > times, with other actions interleaved. A token encodes _which_ of > these actions is being triggered/cancelled: the non-token variants > always cancel the most recent matching function. Without the token, > there's no way of removing an action "further down the stack". > Take, for example, two functions, add_one() and double(), which are > (*ctx)++ and (*ctx) *=3D 2, respectively. > int var =3D 0; > tok1 =3D kunit_add_action(test, add_one, &var); > kunit_add_action(test, double, &var); > tok3 =3D kunit_add_action(test, add_one, &var); >=20 > // The call: > kunit_remove_action(test, add_one, &var); > // is equivalent to > kunit_remove_action_token(test, tok3); > // and gives var =3D 1 as a final result >=20 > // If instead we want to remove the first add_one, we use: > kunit_remove_action_token(test, tok1); > // which cannot be done using kunit_remove_action() > // gives var =3D 2 instead. Sure, I still think we're kind of over-engineering this. request_irq, devm_add_action and drmm_add_action all use that the irq/device, address of the function and the context value to differentiate between instances, and we never had the need for any token despite having thousand of users. Given that actions are supposed to be unrolled in the opposite order, I think that removing the last action that match makes the most sense. > There's also a (minor) performance benefit to using the token > versions, as we don't need to do a (currently O(n)) search through the > list of KUnit resources to find the matching entry. I doubt too many > tests will defer enough to make this a problem. >=20 >=20 > That being said, given no-one actually needs this behaviour yet, it's > definitely something we could add later if it becomes necessary. I > doubt it'd be useful for most of the normal resource management > use-cases. Yeah, I guess it's the best approach for now. Thanks! Maxime