From patchwork Tue Dec 12 02:27:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13488389 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 58295C4167B for ; Tue, 12 Dec 2023 02:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t62fQ26j44P9FWgebRPfzPEhUmZkBYy7N0zDfJbY3eo=; b=JxZUQ5FJfH778+ y4THlby3jF359Jl0iZ44wzbKGttgehIDhMLjJz8Yx0W9yeXmbPZoCJ51R8qy2ERhybXWprfxikgPd GbResv4wHml6maTppcN3f213DN1JoOdt+iSw/AotMepQxQgAxI1iWSbx+WF++6hBWy2ZY2LvLMnBN zvoB55vHlZYhh9aehqXSjcZaXmEI2mu3Ud6p9/PrSyjMBbtaafexkNdIyLK1XCsp0JsTB9R5Zw9jv ENNlGfqyc2hzTvNb1ucsvmfkHVTf5GIVI8Ts5l//Yo3sojFg9es4HVoscUCXSvE2oKegBKHNSuDJn Yh1c3JYrz3P9CcoqbjHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCsVN-00AWYr-0B; Tue, 12 Dec 2023 02:28:17 +0000 Received: from mail-yw1-x112c.google.com ([2607:f8b0:4864:20::112c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCsVE-00AWRC-17 for linux-arm-kernel@lists.infradead.org; Tue, 12 Dec 2023 02:28:10 +0000 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5e1e656d019so1708247b3.1 for ; Mon, 11 Dec 2023 18:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348087; x=1702952887; 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=wOtgtWtIwGwJ1G9iBa8c13QOAAJ/9MITwOIhxFkc4ng=; b=AaCYffX2rm8r9++709fwh4mu3nCO6lDTR36QYP5mBIycqXAdEpP40rFagpkO81oO8k MJMpJrv7qmX0XZsD5QjWrGkEH9EyloLxdyu1dGNSBqsQif2dL1uUIyzVkep66p7IqsC4 q3Rnd12qozkVLF98NqCdHZnEHJufdcwnQ4RteGTM+YC5d2CJZTBUAhSonh7UG8FeDws/ 5UKlTHaSdJT2ovPtrA6opfeL3uyAiBxOSfm12nDA1Dsos3d7sLeGN7mVjSdNF4ujV3u2 sn8xWPkKGTR8gfIz+C02hwZoiq0Jw0Mvrkdx+7umD3Fg8LEQxAjSzY73nylDvPTpXsEI MHjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702348087; x=1702952887; 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=wOtgtWtIwGwJ1G9iBa8c13QOAAJ/9MITwOIhxFkc4ng=; b=aDQBacpKZ3XnJqsL78i7hJLSowo8pNQni3eeCL4wN8J1n6BZJzYiAhxcGsGJ9T0jxq y91QzFbcVak58IQ8IvssciXSMzr8dVTM4EOTashd66M1nGSxKUzHD3hUbrd+TlnzLqFX 6LLXeJUyskhnEv6yYTBSIDSfEsPw9Ip5eA/rRUqaVDmexHknHw8PIPqoNupVsv7o5E47 9uNQu2vK3YSyMnlYKlGQgKvOEuyJNUcEKyaO/f1qauMmNJWIRX9vcLZ/QhHrdfGde9ss ClQSTfgZGDsMRYE0XBUw13xY4/GgcYxkjgZVqdm6ZL9WQNF/e64Uxbn4Q3SP0wCcoSgc IemQ== X-Gm-Message-State: AOJu0YxLngFt9qZo8AvdutHu6yHGpSC6JXOEA9J9GmExqQTuSRdoBN0e gEAVTFPsxuYYvWh9weOKIsg= X-Google-Smtp-Source: AGHT+IG3JcQqqXUlvmV9E4Jq3lvTw/W0aG3auxyNSagyZtjyoh921YIZwuIwFilGsSDgtbh9RCNWpQ== X-Received: by 2002:a81:7c89:0:b0:5d7:1941:2c2f with SMTP id x131-20020a817c89000000b005d719412c2fmr4754793ywc.92.1702348087359; Mon, 11 Dec 2023 18:28:07 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id a200-20020a0dd8d1000000b005d35a952324sm3449101ywe.56.2023.12.11.18.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:07 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Shuai Xue , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov , Bart Van Assche , Sergey Shtylyov Subject: [PATCH v3 09/35] drivers/perf: optimize ali_drw_get_counter_idx() by using find_and_set_bit() Date: Mon, 11 Dec 2023 18:27:23 -0800 Message-Id: <20231212022749.625238-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212022749.625238-1-yury.norov@gmail.com> References: <20231212022749.625238-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-20231211_182808_460202_C2C11EF5 X-CRM114-Status: GOOD ( 12.92 ) 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 | 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)