Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1764261rdb; Sat, 3 Feb 2024 23:50:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9uFD4G2sLpW3rSFyKE+AQWONUNKQIDbzQXcGfEyjUwCZalbeElHJ0K/E7GxSZm8Dkh9hu X-Received: by 2002:a05:6808:2207:b0:3bf:d065:fa0e with SMTP id bd7-20020a056808220700b003bfd065fa0emr3652762oib.38.1707033049054; Sat, 03 Feb 2024 23:50:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707033049; cv=pass; d=google.com; s=arc-20160816; b=pdV3VZVz6ouER2M9o0Ot6oRLVJA8F/MZhI88mMSLCFAfwP/gKoM+IAQLPqchwiSrBH Tg7SOQOFTgItqYewLSBZbE/3tVqJFALjHEVRypQt4vtlFCJnptHiyAaPmwrOZpAR4ANx uwItiBsKcdEyJloniEstWKx9GYKZf52rbmQf4tDCbPZsaymcVTVyVv147BTbbKHwJuf8 SQcWYc+GEzSJ80aRH2HfltQ1cOh6Vl1THUrzE5f7w+udNTLck0UtpCLFbzYzEuJGMAPQ JhkG1a4yhT7VA5Li3FugXK8hQ2e5R9vjifHkzK8xmsQFOvbY8G8ScZ1aRMNPu/X1zvf8 9W/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=25onVGtVafuKcCwJg5IjbQI+Bs2Pk7zHB6Vj1NaEtJs=; fh=EgARfm95OXOulDvuBKrS4tlS8FKDwEkjQtwakfxHSvk=; b=UYSGrmkZWKI/CyIRyLcRFKZ9X8l6jX9cE4CkNASs+5YTYA56sO+SMjGqYpFFAsJWxE wynMlEqDFQ6oaB3skh9d4MIbwn8BjrXEmf0WCmPFxgy6WZaj0R00o8E9T96FuX+Fan38 y1z8T4VOuMp45nlbF+kkDsIKj8K9Xb5KTqMANlmgKc6QjkeytsM25QTYwuHJSDq8tjLQ UFmTuGEpsyq0bP3teFZ9LuaATTV0atTPuIO2cf/PrqnItUmM+ct9iPdTke7wMTj96lJ9 HkyMsWrbrlAtBEdDu9oqIRoZud8qo0CG2CA3wUTyPhaMZOXWwFvQFE14sHj67kEr/4vZ 2D/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-51504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCVgqiLVkeAEp7Pt/XeQtDJM3LzXB2MVkdnVed5fAwTAaaVVHpzssQC2yiCFCSZM5Mn9WfN+kcGjd3LKm81em83pmWmuXSEOgaZyHzN0UA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lw16-20020a17090b181000b0029517218203si2643078pjb.189.2024.02.03.23.50.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 23:50:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-51504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A18F2284ADE for ; Sun, 4 Feb 2024 07:50:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9E69134C8; Sun, 4 Feb 2024 07:49:42 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5470FBE4 for ; Sun, 4 Feb 2024 07:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707032982; cv=none; b=DPiuSHdpQbMPn7yC7ZOoNthlRop0pOxDC537rCXkVbiOFZ09eoYJYxT10NUTnKxddEtSx13me+Gno3y4JBuSjDS4cPFCHFd0v0mDWS4R1kfu9QwkM1r3aJxxRD20WN/mPxPCixyFyskIfuhQkn6peY8kdySnapGkLi/zc/57LWo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707032982; c=relaxed/simple; bh=1UkIr5V/52bHREXY34P/myH6Vo5bhtQZ1nGTyQc/848=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LGXN//llTF4VzGbxjs19WnfQPTDRD5pku1HFqv8NrhUFikZdOGmuKR9mZaIsN3OpWnoXFY2iffapvpzeSdEclFomDx95rAXSe7xkMvR0JkB7Kr1yRxCVeMIXPaBIE4hE2sqfzHg34Bhoe9Uqw/CHxkNzsOE6/aSkKqzTwFLB0Zw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TSM722wJdz1gyTn; Sun, 4 Feb 2024 15:47:42 +0800 (CST) Received: from canpemm500009.china.huawei.com (unknown [7.192.105.203]) by mail.maildlp.com (Postfix) with ESMTPS id 1507818002F; Sun, 4 Feb 2024 15:49:36 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 4 Feb 2024 15:49:35 +0800 From: Yicong Yang To: , , , , , CC: , , , Subject: [PATCH 6/7] drivers/perf: hisi_pcie: Merge find_related_event() and get_event_idx() Date: Sun, 4 Feb 2024 15:45:26 +0800 Message-ID: <20240204074527.47110-7-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240204074527.47110-1-yangyicong@huawei.com> References: <20240204074527.47110-1-yangyicong@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500009.china.huawei.com (7.192.105.203) From: Junhao He The function xxx_find_related_event() scan all working events to find related events. During this process, we also can find the idle counters. If not found related events, return the first idle counter to simplify the code. Signed-off-by: Junhao He Signed-off-by: Yicong Yang --- drivers/perf/hisilicon/hisi_pcie_pmu.c | 55 ++++++++++---------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index 1b45aeb82859..2edde66675e7 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -397,16 +397,24 @@ static u64 hisi_pcie_pmu_read_counter(struct perf_event *event) return hisi_pcie_pmu_readq(pcie_pmu, event->hw.event_base, idx); } -static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, - struct perf_event *event) +/* + * Check all work events, if a relevant event is found then we return it + * first, otherwise return the first idle counter (need to reset). + */ +static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu, + struct perf_event *event) { + int first_idle = HISI_PCIE_MAX_COUNTERS; struct perf_event *sibling; int idx; for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) { sibling = pcie_pmu->hw_events[idx]; - if (!sibling) + if (!sibling) { + if (first_idle == HISI_PCIE_MAX_COUNTERS) + first_idle = idx; continue; + } /* Related events must be used in group */ if (hisi_pcie_pmu_cmp_event(sibling, event) && @@ -414,19 +422,7 @@ static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, return idx; } - return idx; -} - -static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu) -{ - int idx; - - for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) { - if (!pcie_pmu->hw_events[idx]) - return idx; - } - - return -EINVAL; + return first_idle; } static void hisi_pcie_pmu_event_update(struct perf_event *event) @@ -552,27 +548,18 @@ static int hisi_pcie_pmu_add(struct perf_event *event, int flags) hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE; - /* Check all working events to find a related event. */ - idx = hisi_pcie_pmu_find_related_event(pcie_pmu, event); - if (idx < 0) - return idx; - - /* Current event shares an enabled counter with the related event */ - if (idx < HISI_PCIE_MAX_COUNTERS) { - hwc->idx = idx; - goto start_count; - } - - idx = hisi_pcie_pmu_get_event_idx(pcie_pmu); - if (idx < 0) - return idx; + idx = hisi_pcie_pmu_get_event_idx(pcie_pmu, event); + if (idx == HISI_PCIE_MAX_COUNTERS) + return -EAGAIN; hwc->idx = idx; - pcie_pmu->hw_events[idx] = event; - /* Reset Counter to avoid previous statistic interference. */ - hisi_pcie_pmu_reset_counter(pcie_pmu, idx); -start_count: + /* No enabled counter found with related event, reset it */ + if (!pcie_pmu->hw_events[idx]) { + hisi_pcie_pmu_reset_counter(pcie_pmu, idx); + pcie_pmu->hw_events[idx] = event; + } + if (flags & PERF_EF_START) hisi_pcie_pmu_start(event, PERF_EF_RELOAD); -- 2.24.0