From patchwork Sat Nov 18 15:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13460153 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 11340C5ACB3 for ; Sat, 18 Nov 2023 15:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6hSYMkJZmV8zo/Z78tgyD54lT8IEd8sPbSZW/KgMdRw=; b=PjcECcVEcz7RQb 67a5OG/Vhpdvu1jUdxQAkm6stF3m+dW3h6w3XB6BOSUasFohG4WQuB8QtZbKD3qqff6yIFEsn+1X2 n0LXX3tGs2jAL14g/VJef8aLXfdXjUSp6zg5rR7pPr1i5viFGwLnNDzB3q2QQxvueN+VtbMp02PJp /FZGEz4asAwcew00q+o3sX4yoSY2pH4uhPldGUMjNNhQ78JtBUR0Pw8xFfweQyzcQgELWThpobOVd MSxsuv9t95Y2jWg3Kqwt6CfaulbiPQRRckgxzuzDOrClaOvSwUrXXqJWK5MdmsHntpCEqEWTjSnRZ nFwPyef10bCE+klZuNQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r4NbV-008lB0-1a; Sat, 18 Nov 2023 15:51:29 +0000 Received: from mail-yw1-x1133.google.com ([2607:f8b0:4864:20::1133]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r4NbO-008l5k-34 for linux-arm-kernel@lists.infradead.org; Sat, 18 Nov 2023 15:51:24 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5c08c47c055so32759717b3.1 for ; Sat, 18 Nov 2023 07:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700322682; x=1700927482; 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=9UsBR6w3W758FRiCdHZSwpEWSnagR0QzKE5nlW0aMIc=; b=KLdNI7iqwXy38QVVO5aZMPaQSSsZQ3w+IHLWUpasoXoKyC4Y9rESradGAOtCf/ajig M89fV66d52AYUuuYSX+bAyETVTpkLtZyo3/0VslUPv48Y8b5Q7+2BAhCudu1ucs5V/Ab dwNMx0QhKJ9JNMHt/0qhsQPIoNDbUF+pzduWTLwz8LSdFMMu+2xbYrx572xRx92xNmTe 1wAY4TPDNicoSPgvwM4yfIvwdczBIQPpw3S/ENTCN7s2PHau5TO01BgGXU7e/nkaIQt6 sIhcJosiRHrW5xxPxJ3m63lZlzKFuSFGq4S3h2AR/QP+d8yF8NBTxJ6wfEqJOvj9atK1 3hAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700322682; x=1700927482; 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=9UsBR6w3W758FRiCdHZSwpEWSnagR0QzKE5nlW0aMIc=; b=WEc+VCdUFUMOhbwIMaREqaf7vWrKGVsTEGUxUr5hMN3OEKFG8EoWGPjXp6aKjEo5od SxhVyt8NESrVUinbyIq8ywN4HTsExfJlN8WUMVsj6vcNjXmugn5VEeFc+9aWm46kg6GK StRYl2QGrSItRkipl6sK9UGX4tKBJOfagKa3nkhl+1a+jaQx7KA3e5H4bTNhfAHITUv7 tVvj5Y1ILtwj5xWv5CGjx5gJhROzoJiTlImjus9MqQvzAvZQR2IygxO6V3KKx+V+/sUK zz8YqodEIiv+CJaOaQTtZhn3Z+0I0z3gX/HXcoawBfxXAx1jZmbnrH9ZS+osqxXhfCaM HKvg== X-Gm-Message-State: AOJu0YxN6uBUggUGYBiJxhHdhprRv6S9SMEcrPwn8/Cr6JUEq1bzVPEB ChaGqyXFCKMI5PSaP+zcPCg= X-Google-Smtp-Source: AGHT+IFMi3zL8WSF03nEf+gU11A9ztIok6tcrLg24vsR46a+e0EFl+1hnebBli0fdxvl68Hs4Jerug== X-Received: by 2002:a0d:dc43:0:b0:59b:ec85:54ee with SMTP id f64-20020a0ddc43000000b0059bec8554eemr3160808ywe.39.1700322682161; Sat, 18 Nov 2023 07:51:22 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:48a9:bd4c:868d:dc97]) by smtp.gmail.com with ESMTPSA id d19-20020a814f13000000b0058ddb62f99bsm1187785ywb.38.2023.11.18.07.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:51:21 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Shuai Xue , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov Subject: [PATCH 08/34] drivers/perf: optimize ali_drw_get_counter_idx() by using find_bit() Date: Sat, 18 Nov 2023 07:50:39 -0800 Message-Id: <20231118155105.25678-9-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231118_075122_991564_ADD63B71 X-CRM114-Status: GOOD ( 12.70 ) 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. We can do it faster by using atomic find_and_set_bit(). Signed-off-by: Yury Norov Acked-by: Will Deacon --- drivers/perf/alibaba_uncore_drw_pmu.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_uncore_drw_pmu.c index 19d459a36be5..2a3b7701d568 100644 --- a/drivers/perf/alibaba_uncore_drw_pmu.c +++ b/drivers/perf/alibaba_uncore_drw_pmu.c @@ -274,15 +274,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)