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, 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) From patchwork Thu Jun 20 17:56:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13706202 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 D42ABC2BA1A for ; Thu, 20 Jun 2024 17:59:09 +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=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=FVRB/LnGLBQUnkE/Rs06iVVHTa ZtfE46urZ9xlH2rBZW9AQtmGME/VUXZxM2ZUtLViIMGks8Z4DYTVY9ICyTK6OvorxNZTdjJy0v7bp k7WQRjALhwQ+dbj5PKkhh8kBWdH4AkCPJ/SqY81VlUF9e5B+AIiWXRGX2sZPr1fjNdwNx9b4h8z3l Mz9OKJWHu6EXDAByPr5F56HXd51Gb5SmCFOo6ZCvKw1keEGFe5gi9XT42cpjhSOqxaGuV95NmlVgB ECveBFtCBhgDtNoqwqh3YR2S/6RZ1zFbB5JZ8RDtZP0ntQWB0nyF0TbkBEtF+k+KNIfo6VaruGBns XrrLn0gA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM3j-00000006BCG-2M8t; Thu, 20 Jun 2024 17:58:55 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM2u-00000006Ahv-1scc for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 17:58:11 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-701b0b0be38so1100097b3a.0 for ; Thu, 20 Jun 2024 10:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906283; x=1719511083; 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=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=mHIgfF0EzJ2IsoSU2xVh/5fhHDS2ZoNuJFLckDd1BoRbXJZx1vDC2qEE253wH/CwvG SUE1O+c3TBbuXJTQUIbllYgvyCZBmEHjCOZccETBY+L5NrYvXPxXKagxQGhbfChXvY2H Awfu4tsr18/e91fbsx2ssd2MQ+OkTwUUnNwKKWQgGB2Jsr+oUQ4kxn4RUqNcKmpTtY+z 7cEGChbEH6uKCpcuu+sbSJth0taVXrxv/P5xiPmvyT5pFpfVTSM93dhA0wb0zZ4cHn/j bDGIrHYZZ4/TcNMdW7do8JI4xzt7kGrxZp/t4zGNw6lqihl345lsC0JNMFSfAbvLCVVv 7PKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906283; x=1719511083; 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=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=ae+E7S4O8ABfH8PzIJP1QN8Z+WeTLPB8Wn0dSbHtFlbo+b/qqj+i0cgRxOJSOJtJC6 y/2BaDKSLBk5S1amX0dHMwXe55xlCP6lV7xhiwtu+EXUTaeFhuJexKQUbu23V0drqTio A+dJJJzQN5q5fSwYRO23sDL7JIH5BytBi6k9+tE8hPWQSWWs8a+/pD+kQcG40s9dj++J iX2dvVpUwfFeRH2mdmotoqfVNyOYc4CygsrTn4RN79Ofz6DfP8imkCXdovSxiIIVDYEJ bTetZXoT5F4NzxmuckK9Fy1cY15zMQOx4+g/fFK6VJQfrvrpUt3XpHB3EVR/RCnt3kYA n/uQ== X-Forwarded-Encrypted: i=1; AJvYcCUmkGBsQSQqvBP68GGs5ZaA0lYXO4M9InULfEIU0J86BWE4s4waJwfaA275OqmmLBvPKZX8PD7GQ84lKUY56zPo6HRavre9fyyMqpEQ0TvdZrwVvic= X-Gm-Message-State: AOJu0YyWvy1nB/74Hko06nzWugYPRh83L4PFXaXJmxIp0DXpLg3o95w3 DofLmZNCBa0cuct1DtVgBxrltl82zoDmOvJZM8PCEIlKz9DxAh5U X-Google-Smtp-Source: AGHT+IFuFY8WsrUaBevsclcxusM/Sc7ZvIAfPxrnCGbXlGrdTSyKJ0ahnS/qbGoRPvPpSuP7Wt6hDQ== X-Received: by 2002:a05:6a00:4d07:b0:706:3514:2d6c with SMTP id d2e1a72fcca58-70635142dd9mr3899791b3a.29.1718906283409; Thu, 20 Jun 2024 10:58:03 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb6adb5sm12628100b3a.155.2024.06.20.10.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:02 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Will Deacon , Robin Murphy , Joerg Roedel , Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 19/40] iommu: optimize subsystem by using atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:42 -0700 Message-ID: <20240620175703.605111-20-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_105804_785601_E61E0315 X-CRM114-Status: GOOD ( 15.33 ) 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 __arm_smmu_alloc_bitmap() and msm_iommu_alloc_ctx() by using a dedicated API, and make them nice one-liner wrappers. While here, refactor msm_iommu_attach_dev() and msm_iommu_alloc_ctx() so that error codes don't mismatch. Signed-off-by: Yury Norov --- drivers/iommu/arm/arm-smmu/arm-smmu.h | 11 +++-------- drivers/iommu/msm_iommu.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 4765c6945c34..c74d0300b64b 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -455,15 +456,9 @@ struct arm_smmu_impl { static inline int __arm_smmu_alloc_bitmap(unsigned long *map, int start, int end) { - int idx; + int idx = find_and_set_next_bit(map, end, start); - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return idx < end ? idx : -ENOSPC; } static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, int n) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 989e0869d805..4299e6a5b2ec 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -185,17 +186,9 @@ static const struct iommu_flush_ops msm_iommu_flush_ops = { .tlb_add_page = __flush_iotlb_page, }; -static int msm_iommu_alloc_ctx(unsigned long *map, int start, int end) +static int msm_iommu_alloc_ctx(struct msm_iommu_dev *iommu) { - int idx; - - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return find_and_set_bit(iommu->context_map, iommu->ncb); } static void msm_iommu_free_ctx(unsigned long *map, int idx) @@ -418,10 +411,8 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) ret = -EEXIST; goto fail; } - master->num = - msm_iommu_alloc_ctx(iommu->context_map, - 0, iommu->ncb); - if (IS_ERR_VALUE(master->num)) { + master->num = msm_iommu_alloc_ctx(iommu); + if (master->num >= iommu->ncb) { ret = -ENODEV; goto fail; }