From patchwork Thu Jun 20 17:56:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13706200 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD49BC2BA1A for ; Thu, 20 Jun 2024 17:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V5DGzLYbAUAdrqbJyW80kv/C/QU59EDA9QcwDgDhhzU=; b=RzaJFsIBeAl2Aw0MldnywycTSF 2XUCAY5sb/7fF2/PZQCOlqBNh3vUqL4YhQdP49mCTDQ8zp34SyLRBgylsQVC+aRm0G+wC0b8fCRhq GaJ9qTNjjRFfRzSVxTgbUI7x0mbqZyW4D3iltBMq1t1rWxbt/lZOjFNgpCj+G0+7XRaGHrHrrTfac XTBNov7aKgumcheFf+cRIL8taROOhL0zB1hy/4kzh+Uw5SD7YPbiPQhBOYmqeTeZL79OVIOcUuq9i Pz315ApnWkwDlBOuukMhTFgc5tbQx8Ll3d74GVITpYKPdS1jDPoes/R13VE4Q88fLeMu6BF7kyNFw M7WVVm3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM3d-00000006B7Y-3d6q; Thu, 20 Jun 2024 17:58:49 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM2R-00000006AJi-26Vb for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 17:57:43 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-6e4dbca52f0so945558a12.0 for ; Thu, 20 Jun 2024 10:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906254; x=1719511054; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V5DGzLYbAUAdrqbJyW80kv/C/QU59EDA9QcwDgDhhzU=; b=Z8SYGcZbtOxUz0wlF2D/KXn9tuKgNsQa513pQME6uYVvwXbThuKruDZs+ThgPSgdxu HZEHVbpR8k38WLNKyXofAsfgDbVlYShakCfAiWiC9KIxcHmT38iDGWlqYa/dA3pWKU64 s35hZP4PmnTLN7/VaoyXGLbm0IrEisG3Z2Ke+MfLgNRtQlRWQQVYhHKOvLQ/ld46Uz/U BhB+oZm0w84A2X8sYqMt+s1SY24R7px6ziSu+j5Pqn+N8OWc40ZCkL6RXULbTGqTPmXd +0miIWnOmpHspHxZmt34AV/cz6UN8GI9kKjw9iV67jqyu0kbRWLTzc0CjI4U+DRl8vR4 sytA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906254; x=1719511054; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V5DGzLYbAUAdrqbJyW80kv/C/QU59EDA9QcwDgDhhzU=; b=cqtffvWY/B9ACekZx632z/37Lrp4o55JSkCNuqtJadX2/EhGrIpdr2NtSEFDHdweze Il1gBcrpnOlk//IsmbmgLUQ9YbCO+rnErr/a5R6nnShppW231peEV3K4KpeerZi6CpWT oSCvmkPveNLTU5Xs6db2G7fvSpRuscyLwSotD/DwPnjKkY5MwGSXNJJdW2M/QcMIs3FP HzfbyoyqqGhT2X1JddPKefbuWG/4srQBO8mb6+GnGVzDEa9N+2/oMDA6+CjuGEX+gk// G5iJtwFOZzxV0KHiDBUbLTl4Xq5LeBblmZ6lHMVbDbSu4Qqee4sUpexzEzD9DvT6qG0u k9ew== X-Forwarded-Encrypted: i=1; AJvYcCV+6FLEUZGgYEtxq1eCrXtMMvmcXdkCMR40/zeAqut5vJysM7PWvXu7w6OvfvwqYcvVEl2DQAUwMDbuuh/xbJupLkTFag9oGc8Dv8GmOI4GaubLN+Y= X-Gm-Message-State: AOJu0YwxWFUgJAca5Bw53YYOZawHI78BMP+9FmvMScpShR3Ghh8/f3LY PaOwodrKelmGnX8XiOUVMcWHwqUuKaVTCsKWgIR7PIzMShmeb7vL X-Google-Smtp-Source: AGHT+IEumLOfgHy9ptSYIb80BMzk95Th2CfOVKwPVPTL9GX5qt4vT11e0BpVTPi3+WCx/rlRYbxNTg== X-Received: by 2002:a17:90a:e60d:b0:2c4:a7af:4d79 with SMTP id 98e67ed59e1d1-2c7b5c75d03mr5990223a91.11.1718906254495; Thu, 20 Jun 2024 10:57:34 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e5af9b5dsm1989603a91.43.2024.06.20.10.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:34 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Shuai Xue , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 09/40] drivers/perf: optimize ali_drw_get_counter_idx() by using find_and_set_bit() Date: Thu, 20 Jun 2024 10:56:32 -0700 Message-ID: <20240620175703.605111-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240620_105736_164778_2FB2333C X-CRM114-Status: GOOD ( 13.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The function searches used_mask for a set bit in a for-loop bit by bit. Simplify it by using atomic find_and_set_bit(). Signed-off-by: Yury Norov Acked-by: Will Deacon --- drivers/perf/alibaba_uncore_drw_pmu.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_uncore_drw_pmu.c index 38a2947ae813..1516f2c3d58f 100644 --- a/drivers/perf/alibaba_uncore_drw_pmu.c +++ b/drivers/perf/alibaba_uncore_drw_pmu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -266,15 +267,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)