Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1230496rdb; Sat, 18 Nov 2023 07:53:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4fgN7r1vbb9t8XUgjje8LGAB8xWGiYnsif027Jz4rxyXnlS909uEVOxf7zvdXzKx+gbuq X-Received: by 2002:a05:6808:19a2:b0:3ab:870d:2d49 with SMTP id bj34-20020a05680819a200b003ab870d2d49mr4154800oib.8.1700322831253; Sat, 18 Nov 2023 07:53:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700322831; cv=none; d=google.com; s=arc-20160816; b=QitazEJKkvB7urwmSSTMazI2RLf0Sgl8jdPafFRVJu3yASxwIMFoHHcAr1u804xYOx Q0/CB8P1rX6Uv//MOFb3U2GxN8XjY22Ncj0vAHlZibMQBCC7LJpqC4zdUCqSaHybovp2 uX63w5CxXXG2yMiC2lCfuc/tP/drk5qpvKcAWaFQWHE5CFay9cujU3aCIEAFNw7Qz96p lCjHLrKhP9Bt6RTs2ou7Zx15kUYqFQyhNjSEwG9WtyX6aUTCmlbnyT7MAw+IJE5lsiya d9JIS0OwG0hVDhGq1xthRYAdzDq1YcHGzM6jvC0DsZjz3B4+iEm2t5uT0Cg1Wxa8A6xn maaA== 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=1vgDBzQP5sgQpLZgXf8Y/I5f9ETKynbv5QtuyG4UrSA=; fh=TxaAaaZdzBgBLHJ63uZmZgTOY0EHpWDRcpT1wBmtlwI=; b=KPd8G7WXe/jd8vJdB4W2QtZr3Z+gqyp/lyH+zyr9jPq3xoENyCUSK1P3tLqAvDtlcv U7OgVvmkNxuRc1602lnBRWdigImxEllKXFxHrhoQiXrQKCd/BXduMh8/1U9qiH78QVSB 7c5S7ezbG9b0IyFMyjyKJfqMfOlKLLxGvvNgBihm5eD0rKX+5aM+gJgMv3xSocW1VwRz xQbD5rjx1CLlT4NsdsPAa3HbrerxpX0guwTvUUMvGc5mKkTrZl/9M5Z7gJSzfDl8V0kt kk0eF8RLHeZTNZI9a4WZHPUxKled+tr5ahbc9aSonS6WiPaRelTr3D5AfGXC4Vf8SYmp re+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NLM9Ml01; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id bw26-20020a056a02049a00b0059cc8d682dfsi4973679pgb.814.2023.11.18.07.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:53:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NLM9Ml01; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 3B6A0809AFCE; Sat, 18 Nov 2023 07:53:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231213AbjKRPwd (ORCPT + 99 others); Sat, 18 Nov 2023 10:52:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbjKRPwR (ORCPT ); Sat, 18 Nov 2023 10:52:17 -0500 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CEA610F5; Sat, 18 Nov 2023 07:51:25 -0800 (PST) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5c6705515d8so20371277b3.2; Sat, 18 Nov 2023 07:51:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700322684; x=1700927484; 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=1vgDBzQP5sgQpLZgXf8Y/I5f9ETKynbv5QtuyG4UrSA=; b=NLM9Ml01qJ4IkgQbv+Ri2+76QFWWzLh3mkWpi2OMleBF9fCxNnKV5WDc06aryh1ZCn vgOHDqjT7TWl8ljXxWzhEk3nj/Rd37oKoCseY8zyOTDceyspJJZJLUMxHczflHr6WWiw Deqd55futvd833FMrWwCkW7ijwTE1YzqyTTnYiqV7sUY2VObBW7IK/Yb/L3r+4qtbuSD lGs/RspReC5DpMizaE+J0JUaIJ99LGvfX/+urpzt4h3ltI6Sop1MaPpEmGu+q/dLMQGh ig5sveUuNKNUpxCnyXMTgAGx32LMQxZLI/Rsz88fRT36Sfd/3YlkIzw6AX/ru5Vxgku/ SJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700322684; x=1700927484; 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=1vgDBzQP5sgQpLZgXf8Y/I5f9ETKynbv5QtuyG4UrSA=; b=oMZ2QVn4WxpBJ5vMypY2awJI3IUtglNe8gR6mNOxIkxy263dtx1wKXYhE5j5/VhuP8 7A6Gz7dHzS6QZbbrYzvJfwgdoLSXBIfrUwcbx9O7QWSuA8Y/nA0veHz/CLXpx2D39ipW 81j1mXz/B1WVkhHlTeHIet3MHRENMF3hFJQg+EiHNYVQcj6VtnHTuHZQfGWYz4lOKLhB Dxw1eg1ZT5t9LT0zt/XODIYHvdUv1ZonCVmx1lDXywfTIvZso7SNIk6Myr3XvhJOUqcF nv/UqMRagQVx2CqWcbqlV3PVSApHF/OPVxThZfQvcYnzkAzfGhYJ41X1dbn8FFfVqHxP mdcA== X-Gm-Message-State: AOJu0YzCOvVbW5kpSYk52bruo/clHnp9aJNaVqjyXPUBPzocVqsNUJ5A UnJmYkW4h01GOgI2UHB8hsXumyjjWavZEoWM X-Received: by 2002:a0d:ccd4:0:b0:5a8:7cb2:15d0 with SMTP id o203-20020a0dccd4000000b005a87cb215d0mr2911801ywd.11.1700322683795; Sat, 18 Nov 2023 07:51:23 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:48a9:bd4c:868d:dc97]) by smtp.gmail.com with ESMTPSA id j63-20020a0dc742000000b005a7d9fca87dsm1157680ywd.107.2023.11.18.07.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:51:22 -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 Subject: [PATCH 09/34] dmaengine: idxd: optimize perfmon_assign_event() Date: Sat, 18 Nov 2023 07:50:40 -0800 Message-Id: <20231118155105.25678-10-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 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 fry.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 (fry.vger.email [0.0.0.0]); Sat, 18 Nov 2023 07:53:37 -0800 (PST) The function searches used_mask for a set bit in a for-loop bit by bit. We can do it faster by using atomic find_and_set_bit(). Signed-off-by: Yury Norov --- 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.39.2