Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp869061rdb; Fri, 23 Feb 2024 02:38:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUiTPfMN2kZHs3NUnAsVGoStDn/TeihsfS1/8V5VnFA5DoVIfk8hzEPr0FNQ9xuMGUQ49u2WrkWv09OXO7+289SwlbMkwpXoDDa2Ad2XQ== X-Google-Smtp-Source: AGHT+IG6HsW+adIT7Qz/QP2jnQJlnRp4EKsAeHRSMUIbkfUjtKYW+uIDOr1oVJHkXk6/AZX1syC1 X-Received: by 2002:a05:620a:1b9c:b0:787:2226:c4bd with SMTP id dv28-20020a05620a1b9c00b007872226c4bdmr1783786qkb.31.1708684733118; Fri, 23 Feb 2024 02:38:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708684733; cv=pass; d=google.com; s=arc-20160816; b=qArv4X19B6Am3l86ZWTLp8hwniY7q9R2+wJGZakwT/5FTeIOz5Ce2y8YAGmGdCD0Rj NfekDIPYVZb0c2+Q8W5N7cUXJZvURAPywsX2r9nh2eYEFuxSZacv/KBaggceNfAd7zUm mbfEiayX0W/V6LBzgppw5omj/qTk1BlZZfOqit4blSbRc7CxP2AdIp2YiPs2lZiTOWPS hVngXWdch5x5WyzLh1qR7f85F/d43PZcTKRmw2mPY5GiYiyAQK8LdpGk74FAk7WzgPHm fQ1DhPWhWktwX1+ZdhytKXG9mOqKu4sEGzYGc7SjgsIUyGPgwUcBW+VfKQ0soNVoKaT2 A2Bg== 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=4sRjNuZpfZ4LcvgjIu8kxLpsCFhgblGkP5ZcG/UgLyc=; fh=jersQh8TE0KFZCA3V8poDAKHKQ+owT+1iuzuvpXietI=; b=ja12ZBTtSnnASfI6sU1ZgUSj/nC5AjXsc+FTwsVzM99lBANvVyS6JB2imYk6hVFtq2 ZGRLJiu9eAJvk3z0JgKVbBTX1OD0v8UdnQoHJWyHm5R7gineYsC08L1OBhn9iOR3BgqK HzRd8ZJjOYuc7aLCCdUEIfG3bMUq0XaUtMsaijKDyOoTux4qV38tLE5MefcEDJYBdym2 66EJkyXpHG1tg1UKhatphaZnADeFe5UYbMCvWPRrtD0W4YxO9QtDFvJHAcHhOmiw7ETx WfCEXMs48Umqsoun0DA1PGL0nymfVn62o1KZA8tsD8vaC4SfAq8jfOuTHnGxsJLy24CP J7fg==; 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-78144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78144-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v20-20020ae9e314000000b007879b1a3f98si3245907qkf.484.2024.02.23.02.38.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:38:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-78144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78144-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CE3C61C215DD for ; Fri, 23 Feb 2024 10:38:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D68A77A05; Fri, 23 Feb 2024 10:38:25 +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 6B3F86306D for ; Fri, 23 Feb 2024 10:38:22 +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=1708684704; cv=none; b=PvicNor+8Q6BbPCFM/BuD5ODB42HWAXO3HyLaMjZDdyN8nHR4ONReR1MnemVCRYOyRwrgzAXQlFBwlGq+BW+ld0S7nG6t/c67nhS9/HkS62PQiHQ92mOHOOxj4ibI/E3NasoOzTLVhfaKO4cjmZSMZKi+OGFIwLn376sLa164zk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708684704; c=relaxed/simple; bh=XfzDTM55JnKi9GmEEmEXI8Y/oikyBoFxPQs6RKvi91U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DzPyOfKfD5J/2zSG7mmacS4lN2hWwekyhjFDfMREYTZx+mhDVuxST/Tv1PZHFdvLANBuQ4c/QJTeNr5Dl8PO78AnfNlx/kF2J2sjZdKuaZ03DNGHm0DmaSPbfKKKum8c/C/0WiNpJlbQ4WNmdEZFXySm00lIpE3za+4okGHFG0s= 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.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Th5yd4SQ1z1h0KH; Fri, 23 Feb 2024 18:36:09 +0800 (CST) Received: from canpemm500009.china.huawei.com (unknown [7.192.105.203]) by mail.maildlp.com (Postfix) with ESMTPS id 1155214011F; Fri, 23 Feb 2024 18:38:20 +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_256_GCM_SHA384) id 15.1.2507.35; Fri, 23 Feb 2024 18:38:19 +0800 From: Yicong Yang To: , , , , , CC: , , , Subject: [PATCH v2 7/8] drivers/perf: hisi_pcie: Merge find_related_event() and get_event_idx() Date: Fri, 23 Feb 2024 18:33:58 +0800 Message-ID: <20240223103359.18669-8-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240223103359.18669-1-yangyicong@huawei.com> References: <20240223103359.18669-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: dggems705-chm.china.huawei.com (10.3.19.182) 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 | 51 ++++++++++---------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index 5b15f3698188..5d1f0e9fdb08 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -398,16 +398,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 = -EAGAIN; 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 == -EAGAIN) + first_idle = idx; continue; + } /* Related events must be used in group */ if (hisi_pcie_pmu_cmp_event(sibling, event) && @@ -415,19 +423,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) @@ -553,27 +549,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); + idx = hisi_pcie_pmu_get_event_idx(pcie_pmu, event); if (idx < 0) return idx; 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