From patchwork Thu Jun 20 17:56:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13706199 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 7EC73C2BB85 for ; Thu, 20 Jun 2024 17:58:12 +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=6bzcYC+7QMJSAq6nbwz/pdTxPIFYLtbDE2ea+6aoErY=; b=1jJGkDm/oGyp9cTpUsGZmiXijT YqfMJyAntBBT/idhasTH05YS9XFD9MHNVIKVmbXtjGgFUsNlZEWB0wQMX2bj7qgHvsnRY6LGbBVNe Y5ZITPQqfMF36B5ndy6P5jylDs2poFv9AyJ11k8nRfHN4kb26mIcZTWqqZRcBhqNGRTEd3qz6acq7 iojz58iGJ/URbF5nPIxtcN7fP3sEjcjxDc3xx4BapBEVg/Kh61VO8peUhTjR6nNNsHGNMpJTj3+kT TUqb1Rpe5Hbqvc2mpY8SrHF9yRGRzj0b4W68ksUocKtFVsHIiyMDl5NWyVVEmBAL1WEStiwQXFhpK m4vURwtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM2r-00000006Aft-2fBo; Thu, 20 Jun 2024 17:58:01 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM2O-00000006AGv-2ffq for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 17:57:41 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-6c5a6151ff8so903761a12.2 for ; Thu, 20 Jun 2024 10:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906251; x=1719511051; 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=6bzcYC+7QMJSAq6nbwz/pdTxPIFYLtbDE2ea+6aoErY=; b=fWh3RKYodvtqfZ6j016BgRWmCVVcWMyUVvtkrW6K8/SW2M1k+u6H6k8FVOFxaic6as kJ+Hi4AyKNgWp2FtiRzgCwB9pPBtowVWtFyTdN4nzZ3yR7dwNDl57/yb1Msyf56A0hF2 esq9c+qUmDyGV0Ne1WbrvPdMgxg3p54aBIuOImgbmH3PgTUR02wnPLOJbrv2XVaIfSSU AKNgemP+DUgB+tCTqO09vSRGnEhzV3h5U7g9lzPba7kyDxlatc2VgjNPcJIDCjcNmTiN ne5bpuF3P8LyG6wjCbMoU5BviGM85CGlp9/EFrZpOe9i7htCpgPCWCVUNkAH29GoMQzH 0mTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906251; x=1719511051; 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=6bzcYC+7QMJSAq6nbwz/pdTxPIFYLtbDE2ea+6aoErY=; b=mJRhb8yFhRsHGHIOQHkZZxF+J8y8enu0WyElHarp38F6gWOiFcdTo2vFpPMv9h/6Tp SFPSKENsG9+FCSmEMcEomF2ONfkE9OMUkL7HtpakWPcij0+UhzyVlC3xb+/h02nOZO9n ByI7L0VXUsc9lwhytPHClGKscaQeVJV8Qr+F1BUOpr+dzl9wHBYKgryUuwSUUaqMCvIs 3BZNPK22bwcIHyVLqwtqCwBlwA1IWfbQodrX1KdvaWezJu7q8p06RtPNodhLFNVTJylr W+H4KESpilK/LotTFdWtiBCJMN3jA4daOhR7s6ByYMUzzUrVSseVhXkSrUe5bltTk6fK 88Ug== X-Forwarded-Encrypted: i=1; AJvYcCVyK/RkAcU0pf5etS/GGVirAwiAdZIMJvy48pDOtMWM12J7Gt38eZYhdS0z3+2BnfeQLPuVPhXID8lWMf7kkBKem6cJuNrjrCdpwTE2ugYFnPPVtTg= X-Gm-Message-State: AOJu0YzDipioPoZ/bePyZeaBMjRSuqiSx5eV3lELge/OnNpIfWL5cK4S qU6oRLijURVBOBTsWM75HbCQX9VDjqRmy4MpwhVsE2NxLQQcVGD5 X-Google-Smtp-Source: AGHT+IGzyYHmrHK4/S/CrwdNkwiA+pUDJ3yDivu3+UrGd8HpzK6oOgREUf8KUPo9rqfklDv5mSyQmQ== X-Received: by 2002:a17:90b:4d8a:b0:2c8:84b:8286 with SMTP id 98e67ed59e1d1-2c8084b834dmr1256023a91.37.1718906251564; Thu, 20 Jun 2024 10:57:31 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c7e53e0743sm2004328a91.15.2024.06.20.10.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:57:31 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, 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 08/40] perf/arm: use atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:31 -0700 Message-ID: <20240620175703.605111-9-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_105732_934608_81F0144C X-CRM114-Status: GOOD ( 17.62 ) 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 Simplify subsystem by use atomic find_bit() or atomic API where applicable. CC: Will Deacon Signed-off-by: Yury Norov --- drivers/perf/arm-cci.c | 25 +++++++------------------ drivers/perf/arm-ccn.c | 11 +++-------- drivers/perf/arm_dmc620_pmu.c | 10 +++------- drivers/perf/arm_pmuv3.c | 9 +++------ 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c index c76bac668dea..4c5d23942352 100644 --- a/drivers/perf/arm-cci.c +++ b/drivers/perf/arm-cci.c @@ -4,6 +4,7 @@ // Author: Punit Agrawal , Suzuki Poulose #include +#include #include #include #include @@ -318,12 +319,9 @@ static int cci400_get_event_idx(struct cci_pmu *cci_pmu, return CCI400_PMU_CYCLE_CNTR_IDX; } - for (idx = CCI400_PMU_CNTR0_IDX; idx <= CCI_PMU_CNTR_LAST(cci_pmu); ++idx) - if (!test_and_set_bit(idx, hw->used_mask)) - return idx; - - /* No counters available */ - return -EAGAIN; + idx = find_and_set_next_bit(hw->used_mask, CCI_PMU_CNTR_LAST(cci_pmu) + 1, + CCI400_PMU_CNTR0_IDX); + return idx < CCI_PMU_CNTR_LAST(cci_pmu) + 1 ? idx : -EAGAIN; } static int cci400_validate_hw_event(struct cci_pmu *cci_pmu, unsigned long hw_event) @@ -792,13 +790,8 @@ static int pmu_get_event_idx(struct cci_pmu_hw_events *hw, struct perf_event *ev if (cci_pmu->model->get_event_idx) return cci_pmu->model->get_event_idx(cci_pmu, hw, cci_event); - /* Generic code to find an unused idx from the mask */ - for (idx = 0; idx <= CCI_PMU_CNTR_LAST(cci_pmu); idx++) - if (!test_and_set_bit(idx, hw->used_mask)) - return idx; - - /* No counters available */ - return -EAGAIN; + idx = find_and_set_bit(hw->used_mask, CCI_PMU_CNTR_LAST(cci_pmu) + 1); + return idx < CCI_PMU_CNTR_LAST(cci_pmu) + 1 ? idx : -EAGAIN; } static int pmu_map_event(struct perf_event *event) @@ -851,12 +844,8 @@ static void pmu_free_irq(struct cci_pmu *cci_pmu) { int i; - for (i = 0; i < cci_pmu->nr_irqs; i++) { - if (!test_and_clear_bit(i, &cci_pmu->active_irqs)) - continue; - + for_each_test_and_clear_bit(i, &cci_pmu->active_irqs, cci_pmu->nr_irqs) free_irq(cci_pmu->irqs[i], cci_pmu); - } } static u32 pmu_read_counter(struct perf_event *event) diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c index 86ef31ac7503..bd66d90dfda6 100644 --- a/drivers/perf/arm-ccn.c +++ b/drivers/perf/arm-ccn.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -580,15 +581,9 @@ static const struct attribute_group *arm_ccn_pmu_attr_groups[] = { static int arm_ccn_pmu_alloc_bit(unsigned long *bitmap, unsigned long size) { - int bit; - - do { - bit = find_first_zero_bit(bitmap, size); - if (bit >= size) - return -EAGAIN; - } while (test_and_set_bit(bit, bitmap)); + int bit = find_and_set_bit(bitmap, size); - return bit; + return bit < size ? bit : -EAGAIN; } /* All RN-I and RN-D nodes have identical PMUs */ diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c index 7e5f1d4fca0f..f41cc2ee9564 100644 --- a/drivers/perf/arm_dmc620_pmu.c +++ b/drivers/perf/arm_dmc620_pmu.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -303,13 +304,8 @@ static int dmc620_get_event_idx(struct perf_event *event) end_idx = DMC620_PMU_MAX_COUNTERS; } - for (idx = start_idx; idx < end_idx; ++idx) { - if (!test_and_set_bit(idx, dmc620_pmu->used_mask)) - return idx; - } - - /* The counters are all in use. */ - return -EAGAIN; + idx = find_and_set_next_bit(dmc620_pmu->used_mask, end_idx, start_idx); + return idx < end_idx ? idx : -EAGAIN; } static inline diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c index 23fa6c5da82c..f3b20a3b1d9c 100644 --- a/drivers/perf/arm_pmuv3.c +++ b/drivers/perf/arm_pmuv3.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -903,13 +904,9 @@ static irqreturn_t armv8pmu_handle_irq(struct arm_pmu *cpu_pmu) static int armv8pmu_get_single_idx(struct pmu_hw_events *cpuc, struct arm_pmu *cpu_pmu) { - int idx; + int idx = find_and_set_next_bit(cpuc->used_mask, cpu_pmu->num_events, ARMV8_IDX_COUNTER0); - for (idx = ARMV8_IDX_COUNTER0; idx < cpu_pmu->num_events; idx++) { - if (!test_and_set_bit(idx, cpuc->used_mask)) - return idx; - } - return -EAGAIN; + return idx < cpu_pmu->num_events ? idx : -EAGAIN; } static int armv8pmu_get_chain_idx(struct pmu_hw_events *cpuc,