Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4375735rdb; Mon, 11 Dec 2023 18:28:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvNGQDqDW7TK2LZhVARN6ZXJWb/7y6Mx1omqc8HPoZ6Ak3/tzBDzlxBMbZSvB+vo0Kq3O8 X-Received: by 2002:a05:6902:e0e:b0:db7:efed:4dd3 with SMTP id df14-20020a0569020e0e00b00db7efed4dd3mr4096614ybb.15.1702348138070; Mon, 11 Dec 2023 18:28:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702348138; cv=none; d=google.com; s=arc-20160816; b=XPr+hM96Rr3bOJJHbOhnvWcBLrYmBZJ4a8bvkv1gd1pD4kCazv1qJKXPirZe99xZ/1 gtKePJUZsaeeJn+etby+JkIgeGbANhSNWbkR41Z2MnqQt51XkXPmInMJ4JND8ni9JNBb P+zRerYfC/6pjvOgbyiGEhStVYoWgE5cWN63uxtGGz6YBQepIqZqSR7jbERtexCTm5WW wvgt798Yz9K7qYHGnY2marftHDEvXe2PKVoOVbGaCJSDjzkmfbjNZZE9/IrMQpLeByoG V3FMHnlczc4KnnLvLv1F5SMYeQ5cA0ZKep+ON8Qmv5sLDWeLIE0Afevw332Az+YJo2od xbsA== 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=2PPaj8bONHO84DcPLdZn/HzTWIYQqNGS4xiypCmsJDM=; fh=2GD2vy+HX/dHeXa4+RJL+m+Da9dxct7dx3HQA832/jc=; b=pQ9Du+fjd/JdXtF3RuENxBXFRtogwXQlhKbTEkdh08Cm0Iou0TcFfw/ZyL2MrI+NZK pD1WC6kZ/wIJQAqljXYKVeSGcE9CJqrAa0w4+E2AO33bTeON18jXvavGLoL6I46hGRlX j5COYh7q56y269kILYaQjhv6IJHOMAfgr6U1BTbcFUJSzFZCblzOkkqgSuIj9AAuC3GJ 7lwXZ9PqXSREGA506T+y58H6j5qkW3TUdfREw4L9KzpIcKx6WVS8zwYHjjL0y7vsUaVq clEkaf6pQIOibFO3R95Q1J6dPrkoXExSN3o69OwH/srtI5QfQpMtJ7Sg8wUV+2+PVtTH pQzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EeT0ewIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id z7-20020a17090abd8700b0028a2692fae7si6859414pjr.152.2023.12.11.18.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:28:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EeT0ewIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id BB95F8051A87; Mon, 11 Dec 2023 18:28:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345697AbjLLC2a (ORCPT + 99 others); Mon, 11 Dec 2023 21:28:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345730AbjLLC2M (ORCPT ); Mon, 11 Dec 2023 21:28:12 -0500 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-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> 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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 18:28:55 -0800 (PST) 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 --- 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; } /* -- 2.40.1