Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp869240rdb; Fri, 23 Feb 2024 02:39:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVbkdqKOXNX8qDX9xUVLpkEcQ7xpVlew0HCby0woQ0s5sGvQLt9EXlfFxK1NHew2TLdRFWJiV89ULX99KY1Y9lIqsQJ+Za3AGFfIjf0qA== X-Google-Smtp-Source: AGHT+IF7XDXleg+nwtF+btjdvKItsV4AfdO8gGre7e3ISrbr767cQ3gpw1PFaXvv+hXnoh2Vhj5f X-Received: by 2002:a1f:c645:0:b0:4ca:15b2:a09b with SMTP id w66-20020a1fc645000000b004ca15b2a09bmr1619456vkf.13.1708684768907; Fri, 23 Feb 2024 02:39:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708684768; cv=pass; d=google.com; s=arc-20160816; b=X4EB1oag6/GAG4jWc+IlkGTxmOaZtg/aZE4patlX+n344paLmsstAbBTgDZXL3Vk29 +pOLDwcJloiWq1hNTeXRMcgTZ8SMms2m/5eL79S4LnBGZOPe4/Hh/qLeCwBM0/MLV5Zl +58htiw1GIFlcxd5FUWuHtXuCigCBkNuElxmz8++jW0NpbeHu9I3n1ZSTl4NrqE2Hgia kDzQmIf3fXbtZ04wJogQJGJAgx78GjVaZRSvv8ZFNSxQ7RFeuYuH+NyhOeemOe4gMpuA u9DXnJgJ//f6Bjra14HnHsocI3yaO2IP/z6lnh4zlWz13totGswPNeGM7I/aaW4wCi2g BRZw== 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=fzsQJgYgyVJYEOZ+y1fhg+jFUheUp1nWTtAJ6LSzjhM=; fh=jersQh8TE0KFZCA3V8poDAKHKQ+owT+1iuzuvpXietI=; b=CnINXq39ocGxvODl8jcdvbDva0ABsFhY7PwNTgr8Q4823digtgTzRxB9Q8DXutfG3+ EqA4GyqmmYQONvIZRZ5DhelFEiuWjl2DT2eT8k1wG7UYeIBp8QTGNB6ujz4asFd9hHjr 7bWtfgYEig6CUeB3fT28dsWhFOaLGhXQdWBMEASH62wXBLNcDl96klyHt4qcJm/KLSz1 wX6eRUL0xSmhLgopN/rcXwKFuKPb6v+Jo/JCUGaWCn4VH03/Y1jtIsW2EfMDSQeXAPQk aDvLxtvdYvRq46Keg8iru0rZgSdhNK/kJepMj/8h0A4zF4ps0ZxVuAURjPKx1w0wXIv2 Dplw==; 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-78148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78148-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 t10-20020a0562140c6a00b0068fc0b417b8si2701777qvj.56.2024.02.23.02.39.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:39:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78148-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-78148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78148-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 97A4E1C221CE for ; Fri, 23 Feb 2024 10:39:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08A757B3F6; Fri, 23 Feb 2024 10:38:26 +0000 (UTC) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 53C9A6310A for ; Fri, 23 Feb 2024 10:38:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708684705; cv=none; b=k2i/uz8mf0W9eD2hA+vz965GO4Oh1lbdEGvmtk+5JIZUVxENV/yHtk9KjDJpIw/p+J1YeeVYJ/dQ/VojPcv/Mx+rqys4pDFIKGy+08brS5KES40RkLaoUmdJ7vppfgc6ClXs6HlMFOoLsQAOoELztCV83upw7pJftNkUNHlZ77c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708684705; c=relaxed/simple; bh=azBPhXIyTF3fSClMZpebCbapCugiPBnyh9ir8UHejD4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kEJjYC9vDc7XuN8uB2HvgaPMzzhwdBEXoMu4C61sTbBoeKvFxPNaDwGjh1enuB1lmnM1d1faVJhU5EQBfF6qyOzoEkuTnVTz51NbAx/rLD2NQILBSppEyx5M1bGfUJul6fgsev2F8/hyY1CsdxQ6+73yxLeUr/LH3HmAYucp1tQ= 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.32 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.163.17]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Th60S5mTTz1vv9l; Fri, 23 Feb 2024 18:37:44 +0800 (CST) Received: from canpemm500009.china.huawei.com (unknown [7.192.105.203]) by mail.maildlp.com (Postfix) with ESMTPS id D27221A0172; Fri, 23 Feb 2024 18:38:19 +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 6/8] drivers/perf: hisi_pcie: Relax the check on related events Date: Fri, 23 Feb 2024 18:33:57 +0800 Message-ID: <20240223103359.18669-7-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 If we use two events with the same filter and related event type (see the following example), the driver check whether they are related events and are in the same group, otherwise the function hisi_pcie_pmu_find_related_event() return -EINVAL, then the 2nd event cannot count but the 1st event is running, although the PCIe PMU has other idle counters. In this case, The perf event scheduler will make the two events to multiplex a counter, if the user use the formula (1st event_value / 2nd event_value) to calculate the bandwidth, he/she won't get the correct value, because they are not counting at the same period. This patch tries to fix this by making the related events to use different idle counters if they are not in the same event group. And finally, I'm going to say. The related events are best used in the same group [1]. There are two ways to know if they are related events. a) By event name, such as the latency events "xxx_latency, xxx_cnt" or bandwidth events "xxx_flux, xxx_time". b) By event type, such as "event=0xXXXX, event=0x1XXXX". Use group to count the related events: [1] -e "{pmu_name/xxx_latency,port=1/,pmu_name/xxx_cnt,port=1/}" example: 1st event: hisi_pcie0_core1/event=0x804,port=1 2nd event: hisi_pcie0_core1/event=0x10804,port=1 test cmd: perf stat -e hisi_pcie0_core1/event=0x804,port=1/ \ -e hisi_pcie0_core1/event=0x10804,port=1/ before patch: 25,281 hisi_pcie0_core1/event=0x804,port=1/ (49.91%) 470,598 hisi_pcie0_core1/event=0x10804,port=1/ (50.09%) after patch: 24,147 hisi_pcie0_core1/event=0x804,port=1/ 474,558 hisi_pcie0_core1/event=0x10804,port=1/ Signed-off-by: Junhao He Signed-off-by: Yicong Yang --- drivers/perf/hisilicon/hisi_pcie_pmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c index b2dde7559639..5b15f3698188 100644 --- a/drivers/perf/hisilicon/hisi_pcie_pmu.c +++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c @@ -409,14 +409,10 @@ static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, if (!sibling) continue; - if (!hisi_pcie_pmu_cmp_event(sibling, event)) - continue; - /* Related events must be used in group */ - if (sibling->group_leader == event->group_leader) + if (hisi_pcie_pmu_cmp_event(sibling, event) && + sibling->group_leader == event->group_leader) return idx; - else - return -EINVAL; } return idx; -- 2.24.0