[v3,09/35] drivers/perf: optimize ali_drw_get_counter_idx() by using find_and_set_bit()
Message ID | 20231212022749.625238-10-yury.norov@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7469468vqy; Mon, 11 Dec 2023 18:28:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6IIdy1dhNIpaa6vNA6BTj8iQy9wzsgSTPw7XACNFZICtpyWU7aDPNRadPErTc5K3vvOsY X-Received: by 2002:a05:6a20:bf10:b0:190:a85:c042 with SMTP id gc16-20020a056a20bf1000b001900a85c042mr6687781pzb.119.1702348117010; Mon, 11 Dec 2023 18:28:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702348116; cv=none; d=google.com; s=arc-20160816; b=wflsEclz8mXD/Uda39HWOdCQqyUQthjGJW921zM6SPMCJlEvLEW2pQlImQ2UIhxufP FSSGlrSEAm4N5oXJzXXFmZlr0Z9sNtx6ts/VO5ytZVFJeHomfC/TftL/veV31klegHeu LmHzdBAhEeQjxTLdfBzTj8O604E83gSMdv0p/bRwCuBw/h2MUGfPX8Gd41s/ssAqSNQP dM7xsKUj4xpywzSg/U82vmEzuZpuhNYNsibTlIusO7xCQTOEIiXL7N+WZzWorKP1ncdv uwz2Js1VK3CUGf4VY8vlPz3RZdCYwrOBDZtkncRAyDbaeY5FkHwNnVz10Vv7bpU65p8N pAgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wOtgtWtIwGwJ1G9iBa8c13QOAAJ/9MITwOIhxFkc4ng=; fh=1EViu0/j/vX2yGB9Ufg5tfTc4itqx9d5bLCQ1jM8OSo=; b=nweN8zpz7dlKBydVU0sYGNAYa6Gh0rI3z/HYHLe3cpufrBxTrZ13vTJgt2/WvlaWLW hof5QIhdOJxegs/44m+Y/h4WvSt4Om0dwgGNkkWttcyqQsL4DWLVeEFejlefJ4I3gXTJ zdNesK2TgBMjR24W/RRy0QsIXuM3K5nR5t4F/JQRtFD+80KbrOm4q9LnfTerLey6uEg4 VUT3lMj4+/Z20D2WL0/Ut3X5iiF8jTBQ5AuSS5W0/jGIrvunjrYl9qocttae1Lt5ZpYz 3Ifyc5A2k4PAfr1gQNRIBCmOoeTVbHRvkcnqTY1+cUVSjUs7sOjUmVbf+EfmPE0nf0gy sJlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PPYYK6gZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id fm4-20020a056a002f8400b006ce79a76cb0si6832882pfb.137.2023.12.11.18.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:36 -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=@gmail.com header.s=20230601 header.b=PPYYK6gZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0394F8057993; Mon, 11 Dec 2023 18:28:34 -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 S1345753AbjLLC2Y (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Mon, 11 Dec 2023 21:28:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345712AbjLLC2C (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 11 Dec 2023 21:28:02 -0500 Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32BC9D5 for <linux-kernel@vger.kernel.org>; Mon, 11 Dec 2023 18:28:09 -0800 (PST) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5e1a3199f6bso6896777b3.0 for <linux-kernel@vger.kernel.org>; Mon, 11 Dec 2023 18:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348087; x=1702952887; darn=vger.kernel.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=PPYYK6gZjHpPN8gqQDwq9laUoxLJR5BRssNuC2urGmIwyElRbozZHvRUtt7/86JBhD xh1ZhXO/RKkAe2UzeroXBrd7WDIfnsKn1Nls2ux1an1mb0WJy3B002kFekxqyJb9MS/E Pk4bdzOU9/39GVQADWfzVii6riDnuYgOA5A5PTAalneKSG6dWSqPYMMNPMAlLPaE55hP g0BMXbfZ3cDz8fXBQ53z7qPeeiBvwJtIWCmlQA+Zt1EOXJF+MIxASO9BJdHL581CEmdv eNhj9IueQdDR+yAZhFcnsz0HwgJyur8mw7jLiseLClTgLAzdMhLyfqTVYlVDkxy5yWsn Yp4w== 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=wCOgN6buPNynnODnf6ARhk9O4ZQMBqxyMhfGXMLq6+gUEYuudkz3NKlolhvSmdVeF5 MfeeGC0MeIqL4HtU27m47wtCOVOvI4W/QyReOIIRhFUkzTphNqLCWJ6oFf+FnDcM9hvR EWaOA9up6Ggm+xEP5wC0yQdPadqRLzRcVLSZzEfIizLn5sr6DOW6GINBuKDj/jE+1gd5 k+mWelQzoxpCKO40cQHAJufxwHXTxXnZGrN3h8vn8NZOvQPWLDfS0vFeDgJM9upzR0QL mdh+r7xEHnqh09RjNMa4Ww/8ppyGxmk1oc0l4mvoCWEsLtemFrRBCzcpQM8FMmTp8lfB zEBw== X-Gm-Message-State: AOJu0Yyw8P6yV2uVl0wm05UoXZcAR7uPDdtwVRsnF2t59fHo7i84wlYI u19vyEcKZWlJ/rv2jpEL+mvHpByDzRx1aw== 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 <yury.norov@gmail.com> To: linux-kernel@vger.kernel.org, Shuai Xue <xueshuai@linux.alibaba.com>, Will Deacon <will@kernel.org>, Mark Rutland <mark.rutland@arm.com>, linux-arm-kernel@lists.infradead.org Cc: Yury Norov <yury.norov@gmail.com>, Jan Kara <jack@suse.cz>, Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>, Matthew Wilcox <willy@infradead.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>, Alexey Klimov <klimov.linux@gmail.com>, Bart Van Assche <bvanassche@acm.org>, Sergey Shtylyov <s.shtylyov@omp.ru> 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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: <linux-kernel.vger.kernel.org> 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]); Mon, 11 Dec 2023 18:28:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785041379544364535 X-GMAIL-MSGID: 1785041379544364535 |
Series |
bitops: add atomic find_bit() operations
|
|
Commit Message
Yury Norov
Dec. 12, 2023, 2:27 a.m. UTC
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 <yury.norov@gmail.com> Acked-by: Will Deacon <will@kernel.org> --- 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)