Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp483191rdf; Tue, 21 Nov 2023 07:54:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHd6kK9+nMKdmChvugCVjhgiZ8Hiyuu98W/taGWzyvcqKjLGwr1BzlJfAt3zJs/wxB8fCv/ X-Received: by 2002:a17:902:70c8:b0:1cc:ef37:664a with SMTP id l8-20020a17090270c800b001ccef37664amr8178249plt.31.1700582067976; Tue, 21 Nov 2023 07:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700582067; cv=none; d=google.com; s=arc-20160816; b=cV0Bw05GneMqbx3ZBNyc66c2YZ3mui+xVApURARWerBpH752ZGblQQn4GEInvIO5I1 sKzJmj4VeYMh81/BVfcHgQcpcsBdRHM6HRZqJKxq/xSnSsbaL3eiID5I9bUHdL503zao iFe4ZFU0+FncZ43+Y1PfgN6EwqSB7I4lSLrz9xolSCVsdkWMiPD3HT5fVb4DkC/b0xRH zd0RFFy6XPD4YyDDrnl72IGCRKn5A72eEhbFljtA5Eay/Z4hEl0qWDNEZ5IG4gLqsfb6 zuir80HeZMbDkrBfGbn9VYtx/csTKOqNhz+f/7b7IwpXpOfnhylHrDQzkT6hgKgWeHtF 71+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=WM8RBD24I+GSJEnmq+FQOaawbyQ65A4r8lJCGT08A4w=; fh=IPk8TAKCt3+SMZa+xKx+VhLUV46crqtVEfdba4xzsx0=; b=ZdznYtVa5GoEQLsHcKoy4M1WL6UMpCs/VpO4XS3XAwH9EjjJ0cQjuaEVElNfA/b57m Gasf7xok5VqL1JUEQqNftKULVDiFUcMM4umPrPHVWm9je+OZktG8PekXu/4F3TT2396h tM2nF5ahaaAR/694EekA/hi911+68qISA6paby53tNwsNeL4aNdgLuPY2qtQVoa37odN N+370PJaR45pqYv2jDpi8nCka+XbVz0ZZHZeyoWuzBC9CAeUl4LvwP8v6nXlddMjwlB/ kTBIFwpSCSYDhTX6WHkypLS+gpGzASENKm6ae2Skk1tEPs6nYSwnd3EFQddQJ5ff9nad bV9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A4xoftpB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b1-20020a170903228100b001cf677b6c36si3299017plh.281.2023.11.21.07.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 07:54:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A4xoftpB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3FCFD80323D8; Tue, 21 Nov 2023 07:54:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234629AbjKUPyC (ORCPT + 99 others); Tue, 21 Nov 2023 10:54:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234642AbjKUPyA (ORCPT ); Tue, 21 Nov 2023 10:54:00 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5422199 for ; Tue, 21 Nov 2023 07:53:50 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 527F8C433C7; Tue, 21 Nov 2023 15:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700582030; bh=SoS9Ag1+RqC2NSBHSqQi1wvuc0Z8QYMVBqZbJL+ARpo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A4xoftpBz4krbCJ+RVWs2QWqiTqBBrpytVL5qOIIlmgZhqbid6GcrhnDd/MFhk7qO NFQMMBXQrCAW3TegL2vXnU60F8qnK05nICHTWatU4oKdUSLalu0puc6pR6WonuWIpx pIqztTOPO3k+MpE358j9gn5vYTsrLwf6Cr4x1GD4G5loQDlzDo2fg8vL1PRE+HegRK 5+fJvFoaOt6DOh0YjpVBNFbhlfv7mL4Cu+r+NeoyOyRFpWDd4HtL7quXDvJnRjdWlV lWWgxdfgUMptOVtJP30JjtiguMxflbDtsxcHXnlOqpyMHiD0B2AOQ+6zh8tWazMmii sCNG4BC4n0yJQ== Date: Tue, 21 Nov 2023 15:53:44 +0000 From: Will Deacon To: Yury Norov Cc: linux-kernel@vger.kernel.org, Mark Rutland , linux-arm-kernel@lists.infradead.org, Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov Subject: Re: [PATCH 07/34] perf/arm: optimize opencoded atomic find_bit() API Message-ID: <20231121155344.GB1938@willie-the-truck> References: <20231118155105.25678-1-yury.norov@gmail.com> <20231118155105.25678-8-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231118155105.25678-8-yury.norov@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 21 Nov 2023 07:54:11 -0800 (PST) On Sat, Nov 18, 2023 at 07:50:38AM -0800, Yury Norov wrote: > Switch subsystem to use atomic find_bit() or atomic iterators as > appropriate. > > Signed-off-by: Yury Norov > --- > drivers/perf/arm-cci.c | 23 +++++------------------ > drivers/perf/arm-ccn.c | 10 ++-------- > drivers/perf/arm_dmc620_pmu.c | 9 ++------- > drivers/perf/arm_pmuv3.c | 8 ++------ > 4 files changed, 11 insertions(+), 39 deletions(-) > > diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c > index 61de861eaf91..70fbf9d09d37 100644 > --- a/drivers/perf/arm-cci.c > +++ b/drivers/perf/arm-cci.c > @@ -320,12 +320,8 @@ static int cci400_get_event_idx(struct cci_pmu *cci_pmu, > return CCI400_PMU_CYCLE_CNTR_IDX; > } > > - for (idx = CCI400_PMU_CNTR0_IDX; idx <= CCI_PMU_CNTR_LAST(cci_pmu); ++idx) > - if (!test_and_set_bit(idx, hw->used_mask)) > - return idx; > - > - /* No counters available */ > - return -EAGAIN; > + idx = find_and_set_bit(hw->used_mask, CCI_PMU_CNTR_LAST(cci_pmu) + 1); CCI400_PMU_CNTR0_IDX is defined as 1, so isn't this wrong? [...] > diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c > index 30cea6859574..e41c84dabc3e 100644 > --- a/drivers/perf/arm_dmc620_pmu.c > +++ b/drivers/perf/arm_dmc620_pmu.c > @@ -303,13 +303,8 @@ static int dmc620_get_event_idx(struct perf_event *event) > end_idx = DMC620_PMU_MAX_COUNTERS; > } > > - for (idx = start_idx; idx < end_idx; ++idx) { > - if (!test_and_set_bit(idx, dmc620_pmu->used_mask)) > - return idx; > - } > - > - /* The counters are all in use. */ > - return -EAGAIN; > + idx = find_and_set_next_bit(dmc620_pmu->used_mask, end_idx, start_idx); It might just be me, but I'd find this a tonne easier to read if you swapped the last two arguments around so that the offset came before the limit in the new function. Will