Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp483627rdf; Tue, 21 Nov 2023 07:55:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgRlJ1ginK2BGIbUdEH8h5qOfX9QGuO97WbF4BF/fnPbMjTBogJgPyp6ZIb7/UixcZRLqS X-Received: by 2002:a17:90b:4b45:b0:281:554d:b317 with SMTP id mi5-20020a17090b4b4500b00281554db317mr9117410pjb.38.1700582109380; Tue, 21 Nov 2023 07:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700582109; cv=none; d=google.com; s=arc-20160816; b=EHRnhgrPOfgD5hFau94xCvEO1F9M/Lc1cnaUc72yKN5IkrB+ixV/tXBwSvcyFP6Eb2 zsLwsh6QUzSot+9s/3IoRBL5CePaZWGKRHyjD+5CC2BJjYTBosUa6BRFzT77pW3lCWk9 3t0FiHwk4ARbpesNqWlZ9nSkJQliuW6EiUMrRYfTha/yNlXiFQpYwvr66OPgP4QQ6jiA xZuy2XSUL/bCzRZApQOzw44nLdHpQsp/4rFCRh9TCCUUamJRNGA49UKrUTXCeDSk+VY2 uRdy4h8seZpAexyedI1NXmNbzuOppu3BJfJeSwzOA2i5IaRdftmduvEs3Aer/n6Nme5n Ijfw== 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=1vtNGLZOy1Mqx7c11znip1Xf6y0TM2/O3Qtpf0vbjRI=; fh=DndKdAEvRmMnf6mAQVPO5f0DOZ77n6VRmlVSY0mozFI=; b=Z8sRUgK3gtvz/8xFLVjjJsqsRaMcpLvYDEVNDmab8M3IeqTNCw80DKLxW6JXB9jxfO AQlMcn34XVAstpUHYjN/kE0Jf3kXLUxVyfCoQSI5Czfs+uWO/RyoRZwV2Eytc/aZ/BbV vE6hmQhArddCHcjs2Pqeu2fgvx1ZQx90n98P3GUZfJGLR68FalhBMsiMqjS1gcK7N7xN wzwzCe8Q0trQRIICCgL3/7izOMcoWmLMVkXhdaYlnZ3y6YY86KrL7JQzDxswyBdBqeNu mR/5Pbb84b+UsWaIzyjBPpRRmkx3HBCS8PuciKrYhunKpHcdHtEhqjiDQLRwAv27hzVB ja0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FmG1JEOT; 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 e6-20020a17090a804600b0028516cc3884si6353994pjw.115.2023.11.21.07.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 07:55:09 -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=FmG1JEOT; 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 88C7B8031012; Tue, 21 Nov 2023 07:55:05 -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 S234634AbjKUPzB (ORCPT + 99 others); Tue, 21 Nov 2023 10:55:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234416AbjKUPzA (ORCPT ); Tue, 21 Nov 2023 10:55:00 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41146132 for ; Tue, 21 Nov 2023 07:54:57 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 602F7C433C8; Tue, 21 Nov 2023 15:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700582096; bh=nUNQwOHk4EELbIput1hMEvEcgZjaGuxBlZjCetzZAIY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FmG1JEOTrepgRO1Uwkv5Pi/eAe3djSEGUAhsS6kO3BfC5of3+YrT30v/wXDJDU1+z 5e7k9H1CC4PoUAx6DKYDACr7PKB+vPxX/RvBLeH0mrpY0zQaqdotr5R6oIqazwpvKG opTK/QY8os/L2fQXAXILGR82HUTxxHKRnm+vMskJ2wFmo7dBeWDE3JCVFviEjKIbVK YypKP2cszURHsv/cUz2of3HonbpVaYyxSZ0v8fmli48Z0rCTkUAANVuCOZ9Kmc0asX 3m24gMqKnoHHsco722BraL7TS5+Y5JHXaOTlx4a+wrhsIKlQ5ka7eWiFbkzsNWqTJG MNhH8x91xYVoQ== Date: Tue, 21 Nov 2023 15:54:50 +0000 From: Will Deacon To: Yury Norov Cc: linux-kernel@vger.kernel.org, Shuai Xue , 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 08/34] drivers/perf: optimize ali_drw_get_counter_idx() by using find_bit() Message-ID: <20231121155450.GC1938@willie-the-truck> References: <20231118155105.25678-1-yury.norov@gmail.com> <20231118155105.25678-9-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231118155105.25678-9-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:55:05 -0800 (PST) On Sat, Nov 18, 2023 at 07:50:39AM -0800, Yury Norov wrote: > The function searches used_mask for a set bit in a for-loop bit by bit. > We can do it faster by using atomic find_and_set_bit(). > > Signed-off-by: Yury Norov > --- > drivers/perf/alibaba_uncore_drw_pmu.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_uncore_drw_pmu.c > index 19d459a36be5..2a3b7701d568 100644 > --- a/drivers/perf/alibaba_uncore_drw_pmu.c > +++ b/drivers/perf/alibaba_uncore_drw_pmu.c > @@ -274,15 +274,9 @@ static const struct attribute_group *ali_drw_pmu_attr_groups[] = { > static int ali_drw_get_counter_idx(struct perf_event *event) > { > struct ali_drw_pmu *drw_pmu = to_ali_drw_pmu(event->pmu); > - int idx; > + int idx = find_and_set_bit(drw_pmu->used_mask, ALI_DRW_PMU_COMMON_MAX_COUNTERS); > > - for (idx = 0; idx < ALI_DRW_PMU_COMMON_MAX_COUNTERS; ++idx) { > - if (!test_and_set_bit(idx, drw_pmu->used_mask)) > - return idx; > - } > - > - /* The counters are all in use. */ > - return -EBUSY; > + return idx < ALI_DRW_PMU_COMMON_MAX_COUNTERS ? idx : -EBUSY; > } > > static u64 ali_drw_pmu_read_counter(struct perf_event *event) > -- > 2.39.2 Acked-by: Will Deacon Will