From patchwork Tue Dec 12 02:27:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13488333 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EeT0ewIv" Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57808DB; Mon, 11 Dec 2023 18:28:10 -0800 (PST) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-5e1a2253045so6490097b3.2; Mon, 11 Dec 2023 18:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348089; x=1702952889; 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=2PPaj8bONHO84DcPLdZn/HzTWIYQqNGS4xiypCmsJDM=; b=EeT0ewIvIPYinBZYW6XCaUORYpOhz3jr3Z0GrxT/kf4OVCroVDB6tyMkj66+RRHzqM YmvftBXHOj9dQ7XYG6QcYxFMG1HCU7CZQm1kbLG0UTskk1gvX4myd+1PFk+et4UjnJWl FJZJLN6toQuu2l/jvRqfJsqEOtQT6x5GIj49i+Z3kLh+i49OOQmwzAhOHUlRv9p0EiFF UYmsEYTj0PdAGEMr6mWBrPqi7nZj28KRJ+jETrJ7YBuslj957L7+BD7Vi58dLswi9VgO suCPXi+W6taNzRlhJrJGGj+J2RLZmx8z1zeDh1BVT9sCrHX2bKTEKWIuMmFjWs4UIq+N 5/ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702348089; x=1702952889; 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=2PPaj8bONHO84DcPLdZn/HzTWIYQqNGS4xiypCmsJDM=; b=B1GN6upNiIbnwH5D39OmDD1HD+jr+oyM1RFtgE+tYs+JyoNf5BWWY6W3AlKuTJ5dPh Lj7d0frHanBn+v61bexfqzIbdbKhMS8nSAzrhsfma9Cx0KMq8TJNKtasUXnMzc4M2P+q S5RlnlhMYTfGR3+NtZlI09aikaAdqPXQkaEIWQqUH7/ITxMUIYh0PVyZ3loEqGRrkqBq r617LQw2381cSyRD1mVZeDDZJ8EpGYWO+5nnmNt47leCx3o6othkkmxoeuQ5NOP0EU/L XsHfuF6PIga2rn2JtGIOrJdgkGzxps93VEeiAklbxq/95B+jVI8W73eE5jmW/X4Gr0f9 WT8Q== X-Gm-Message-State: AOJu0YxmZMuGuOQXLj5f/mABk/AjDzrBOufgfoTNR4E9X5PrPXjchs6/ aZR8+dU4h/DZc+Kf4Ex96jL/dJr519Vm9w== X-Google-Smtp-Source: AGHT+IFfVJcg/DUfJP67/YgD49DyRzNNSoiDPbtETNKOnY44IEAlaTBX9EewmceS0nAr7MYstmZuAw== X-Received: by 2002:a0d:cc8e:0:b0:5d3:8400:ba9 with SMTP id o136-20020a0dcc8e000000b005d384000ba9mr4160620ywd.48.1702348088892; Mon, 11 Dec 2023 18:28:08 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id u13-20020a81a50d000000b005cc8b377fe9sm3395652ywg.121.2023.12.11.18.28.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:08 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Fenghua Yu , Dave Jiang , Vinod Koul , dmaengine@vger.kernel.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 10/35] dmaengine: idxd: optimize perfmon_assign_event() Date: Mon, 11 Dec 2023 18:27:24 -0800 Message-Id: <20231212022749.625238-11-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> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(), and make a nice one-liner. Signed-off-by: Yury Norov Reviewed-by: Dave Jiang Acked-by: Vinod Koul Reviewed-by: Fenghua Yu --- drivers/dma/idxd/perfmon.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c index fdda6d604262..4dd9c0d979c3 100644 --- a/drivers/dma/idxd/perfmon.c +++ b/drivers/dma/idxd/perfmon.c @@ -134,13 +134,9 @@ static void perfmon_assign_hw_event(struct idxd_pmu *idxd_pmu, static int perfmon_assign_event(struct idxd_pmu *idxd_pmu, struct perf_event *event) { - int i; - - for (i = 0; i < IDXD_PMU_EVENT_MAX; i++) - if (!test_and_set_bit(i, idxd_pmu->used_mask)) - return i; + int i = find_and_set_bit(idxd_pmu->used_mask, IDXD_PMU_EVENT_MAX); - return -EINVAL; + return i < IDXD_PMU_EVENT_MAX ? i : -EINVAL; } /*