From mboxrd@z Thu Jan 1 00:00:00 1970 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 02972C2BB3F for ; Sat, 18 Nov 2023 15:52:27 +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=vI03d4fLw1RP+AMK/qA8pK4omFuLZL4iJwApD2SREas=; b=Ks14xC0H77eMGN S+/oFV8z1SnhoO6x1H0cfpKk7aQBLrFITJiPZRAfjFaf4R+Y78g2/JsI1Ombv3YGctBImaeglf/Yz 4xcOpEJF74cPtxByoWhXzXYs+NVF1NhCMjn/MMFhxn6NV6WLgv0/NXiKuroaZ73Dxckcwh5eeRd0i 1Pt0UUiIHKAHmOHRSKA4Pxe4jmlPgjBtw3apbVS9QWU7okH6ingqSjJ6+v55A9pWiZWWbsGUEaMY6 tjwcy6BKPOYA3ugiUGGxCuMEtvxN5bX4fH2lmoW443ScrsdtAt1BiRkpfMutx0GsErrz6fz3jk0rW QzEnu5vrRXYBU64SkwjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r4Nbx-008lVk-31; Sat, 18 Nov 2023 15:51:57 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r4Nbv-008lTT-1p for linux-arm-kernel@lists.infradead.org; Sat, 18 Nov 2023 15:51:56 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5a86b6391e9so34001447b3.0 for ; Sat, 18 Nov 2023 07:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700322715; x=1700927515; 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=Faq88orJ2tLAcgJ6Ak512QARxmUWD9dLolef7kGFuP8=; b=ZBoPmrxKrFr8hq22N5TKQMrlWQjCiQ+8aOEpNwqTe9ecwbAy3jf/FwRZjNs3+HGnxk asMXXuDCPYsAfBrNt5I8FXR+gkn8cHcfMSKk1ui66K4iIpk0tceOe7DqaNavfR+IUG1U DLEXzsaVrrsz4mLmi/SHz8+A8nMeOkmBcti6SbMfGthY6XDeI1E3q9NS4aG77QUd3jdo cOKeAqIAfhv488srrEu2uC1CuXjKKHfK8GB+MmzLLTBbTbqJr3S1hPoOwrHoDEe9WR1f LEK5mpx4NV9JDQyscg4dMMs+0OD9mAmrwQOvoe3OBSqCw68RsAFDA/66nXKMMTXvNise 4pjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700322715; x=1700927515; 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=Faq88orJ2tLAcgJ6Ak512QARxmUWD9dLolef7kGFuP8=; b=FHq/+gGE/0w6faakekmQRoy6xAYShhS8qY8LiiXD8jvMxCMOGQ7kuN/RYPta0Nz3Kl imkrNYU7Z18xF7n1SbMcML8cWle+OnVDsma5JCEDX739bPHL4HMMT/Qzcq5BYld2oITN bWvyZXwJ/tXX3C2KA5uj2BMwfElqfL3phQUtXokOcuB21/Yr1wqdnr6ropyakwngonC9 trlYO9AFmyJfepoir53J05E+9g2MBFHg1SDXu2RH9UD0MAiGACXCBqqF7ahh2tDhgq7z w5NYT3YPZIioooCLdzr48NTOR/VXnU5qvJ8SP6Z02o1/MIyYmTQAxk2r8pnVIKUb4PQ1 2Ajw== X-Gm-Message-State: AOJu0YxxycC5i4OlP9dleZnUJBXS3pdspO4f1pdfMufxrRQDfC0+c02h AbWgCieDLQLIlc7f/0yJ/Q4= X-Google-Smtp-Source: AGHT+IEN5VHZ3duafcnm/k8t+mVTB/cJ3CeGZaVa462hMjL/JpTWc3yeLMLvRrae0wvqSgJiWcTX/g== X-Received: by 2002:a0d:cb0b:0:b0:5a7:dda6:cbaf with SMTP id n11-20020a0dcb0b000000b005a7dda6cbafmr2882441ywd.19.1700322714741; Sat, 18 Nov 2023 07:51:54 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:48a9:bd4c:868d:dc97]) by smtp.gmail.com with ESMTPSA id k186-20020a0dfac3000000b00559f1cb8444sm1186383ywf.70.2023.11.18.07.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:51:54 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Will Deacon , Mark Rutland , Marc Zyngier , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov Subject: [PATCH 31/34] drivers/perf: optimize m1_pmu_get_event_idx() by using find_bit() API Date: Sat, 18 Nov 2023 07:51:02 -0800 Message-Id: <20231118155105.25678-32-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231118155105.25678-1-yury.norov@gmail.com> References: <20231118155105.25678-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-20231118_075155_602960_31030EAF X-CRM114-Status: GOOD ( 13.42 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 bit in a for-loop bit by bit. We can do it faster by using atomic find_and_set_bit(). The comment to the function says that it searches for the first free counter, but obviously for_each_set_bit() searches for the first set counter. The following test_and_set_bit() tries to enable already set bit, which is weird. This patch, by using find_and_set_bit(), fixes this automatically. Fixes: a639027a1be1 ("drivers/perf: Add Apple icestorm/firestorm CPU PMU driver") Signed-off-by: Yury Norov --- drivers/perf/apple_m1_cpu_pmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/perf/apple_m1_cpu_pmu.c b/drivers/perf/apple_m1_cpu_pmu.c index cd2de44b61b9..2d50670ffb01 100644 --- a/drivers/perf/apple_m1_cpu_pmu.c +++ b/drivers/perf/apple_m1_cpu_pmu.c @@ -447,12 +447,8 @@ static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc, * counting on the PMU at any given time, and by placing the * most constraining events first. */ - for_each_set_bit(idx, &affinity, M1_PMU_NR_COUNTERS) { - if (!test_and_set_bit(idx, cpuc->used_mask)) - return idx; - } - - return -EAGAIN; + idx = find_and_set_bit(cpuc->used_mask, M1_PMU_NR_COUNTERS); + return idx < M1_PMU_NR_COUNTERS ? idx : -EAGAIN; } static void m1_pmu_clear_event_idx(struct pmu_hw_events *cpuc, -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel