From patchwork Mon Jun 3 09:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 13683468 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 78C4EC25B76 for ; Mon, 3 Jun 2024 09:34:20 +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=Fpx4dPIHwnWMGGH1da44Hzst+E+8ZOPyfz8Qym5jutI=; b=xCacxb5bh6xJuY 347s+6HfPRUIO8KLYtA+WiKdCTTbPP3fkovQPFLp3IEPrbhXOgDgSxwKr2dF4Zqh4hl3c+TmXAQpq LVXqgEvzT9yGegb2sj/J2vLkuMT+AwS13fQ5ip5lfYQyMOiXi5xF4ItZMKVCRW9jZCxI5PnZY8z4h SMT65uafR0/OiWnIWP0hOfli2dEJ3Og2jqfiZrF0ArxWueOuF4XQt1NU3F/jivgfW+4Mr8cHzYuxU A5GV1PbZkFv+bMxYXaisy49GmFqM+SNBsUtFVsjTf8F0pwz5fuxj6IHuOcttg7q/a28YSP6nbC1Ub ijLX/4px1L2f72ie+83g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44u-0000000GF0l-3dbd; Mon, 03 Jun 2024 09:34:08 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44a-0000000GEmI-3glr for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 09:33:57 +0000 Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Vt7hk5M0NzmXXQ; Mon, 3 Jun 2024 17:29:10 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id D03E5180060; Mon, 3 Jun 2024 17:33:40 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 3 Jun 2024 17:33:40 +0800 From: Yicong Yang To: , , , , , , CC: , , , , , , , , , , Subject: [PATCH 1/3] perf pmu: Limit PMU cpumask to online CPUs Date: Mon, 3 Jun 2024 17:28:10 +0800 Message-ID: <20240603092812.46616-2-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240603092812.46616-1-yangyicong@huawei.com> References: <20240603092812.46616-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_023349_537963_98367C4B X-CRM114-Status: GOOD ( 14.11 ) 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 From: Yicong Yang We'll initialize the PMU's cpumask from "cpumask" or "cpus" sysfs attributes if provided by the driver without checking the CPUs are online or not. In such case that CPUs provided by the driver contains the offline CPUs, we'll try to open event on the offline CPUs and then rejected by the kernel: [root@localhost yang]# echo 0 > /sys/devices/system/cpu/cpu0/online [root@localhost yang]# ./perf_static stat -e armv8_pmuv3_0/cycles/ --timeout 100 Error: The sys_perf_event_open() syscall returned with 19 (No such device) for event (cpu-clock). /bin/dmesg | grep -i perf may provide additional information. So it's better to do a double check in the userspace and only include the online CPUs from "cpumask" or "cpus" to avoid opening events on offline CPUs. Signed-off-by: Yicong Yang --- tools/perf/util/pmu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 888ce9912275..51e8d10ee28b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -771,8 +771,17 @@ static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool is_cor continue; cpus = perf_cpu_map__read(file); fclose(file); - if (cpus) - return cpus; + if (cpus) { + struct perf_cpu_map *intersect __maybe_unused; + + if (perf_cpu_map__is_subset(cpu_map__online(), cpus)) + return cpus; + + intersect = perf_cpu_map__intersect(cpus, cpu_map__online()); + perf_cpu_map__put(cpus); + if (intersect) + return intersect; + } } /* Nothing found, for core PMUs assume this means all CPUs. */ From patchwork Mon Jun 3 09:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 13683466 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 530BDC25B75 for ; Mon, 3 Jun 2024 09:34:19 +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=K6MuJnN6l+n/4Pig1ykjhR7X87mcIZChxUXIgw1RvTE=; b=Piz4sz7X84rYKX LhxEJx27zkCBqNg29brmuhY/SnqTwu24wYUYERKRqy3o1hWQl6HXdoyfhelmEFHABC5K9CZu0y/HV 8FTMOkhtslkXwCROlVtWXJ/rrfQ61eTead/fTDTaFDVKRv/1YXH0WGcq7bAj7DzGZclQFIkHGeljV XqQ2CxFnLxKJDkYaHB/RlLkPHhLlDM4IoDyXEWFfb4frTu7hcEitIa6KbcQ8vty14GsDvSNECjSMA izFV7e52vL0Ach+KsJ78XI2nZOXOOCO3hMaNl/9/OYMgae/jqQNCfQ25FyOw9JQDAhyLa8kKIRE39 486QOcQsb7KRp+p0mh7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44n-0000000GEwe-3cTH; Mon, 03 Jun 2024 09:34:02 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44a-0000000GEmM-49dr for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 09:33:56 +0000 Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Vt7kB55pNz1yspx; Mon, 3 Jun 2024 17:30:26 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 6AA4F180063; Mon, 3 Jun 2024 17:33:41 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 3 Jun 2024 17:33:40 +0800 From: Yicong Yang To: , , , , , , CC: , , , , , , , , , , Subject: [PATCH 2/3] perf: arm_pmu: Only show online CPUs in device's "cpus" attribute Date: Mon, 3 Jun 2024 17:28:11 +0800 Message-ID: <20240603092812.46616-3-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240603092812.46616-1-yangyicong@huawei.com> References: <20240603092812.46616-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_023349_536159_316ECC2B X-CRM114-Status: GOOD ( 13.91 ) 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 From: Yicong Yang When there're CPUs offline after system booting, perf will failed: [root@localhost ~]# /home/yang/perf stat -a -e armv8_pmuv3_0/cycles/ Error: The sys_perf_event_open() syscall returned with 19 (No such device) for event (cpu-clock). /bin/dmesg | grep -i perf may provide additional information. This is due to PMU's "cpus" is not updated and still contains offline CPUs and perf will try to open perf event on the offlined CPUs. Make "cpus" attribute only shows online CPUs and introduced a new "supported_cpus" where users can get the range of the CPUs this PMU supported monitoring. Signed-off-by: Yicong Yang --- drivers/perf/arm_pmu.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 8458fe2cebb4..acbb0e1d0414 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -558,13 +558,35 @@ static ssize_t cpus_show(struct device *dev, struct device_attribute *attr, char *buf) { struct arm_pmu *armpmu = to_arm_pmu(dev_get_drvdata(dev)); - return cpumap_print_to_pagebuf(true, buf, &armpmu->supported_cpus); + cpumask_var_t mask; + ssize_t n; + + /* If allocation failed then show the supported_cpus */ + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + return cpumap_print_to_pagebuf(true, buf, &armpmu->supported_cpus); + + cpumask_and(mask, &armpmu->supported_cpus, cpu_online_mask); + n = cpumap_print_to_pagebuf(true, buf, mask); + free_cpumask_var(mask); + + return n; } static DEVICE_ATTR_RO(cpus); +static ssize_t supported_cpus_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct arm_pmu *armpmu = to_arm_pmu(dev_get_drvdata(dev)); + + return cpumap_print_to_pagebuf(true, buf, &armpmu->supported_cpus); +} + +static DEVICE_ATTR_RO(supported_cpus); + static struct attribute *armpmu_common_attrs[] = { &dev_attr_cpus.attr, + &dev_attr_supported_cpus.attr, NULL, }; From patchwork Mon Jun 3 09:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 13683467 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 0B707C27C44 for ; Mon, 3 Jun 2024 09:34:20 +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=EyomjVfnhG1sM5LPdtKXb0FkYiO3lXLxgxMLQJN9lGA=; b=Alep7oVkx6ec8F EG9sz+ZnWFUUHUXVbfGZ+AQneK+Td2gECrW/28oOSkFs1sQq90Q1Q/zzQBsi+T/riydI0Kra/QQ+q kzL9ewdiBcbny25M5c6DJmJa1x0qj1W+KIzTwG8BmQGL1/T8rYsSTeHtns/D4kRZjppZxIxScr4pi GmagN4Xp+kWn8+YoBKPHpcRkz1mhwekKjDB+ylwoOVLO/hFmaZEuaHVCD7cB8RFFqpwS5ZYVwxQ/o OnC/LlAkaqTE84xJ8nXHaU3Y0sS7By5/rOF7D+UMwkEe9/OZgfd4aPg7+ZfLx7m7C5/ph48lKQ+jd 6Yg5/lKPAl03dGJrwO1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44t-0000000GEzz-2yhM; Mon, 03 Jun 2024 09:34:07 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44b-0000000GEmf-0KvV for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 09:33:57 +0000 Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Vt7lw6C5Dz1HCv1; Mon, 3 Jun 2024 17:31:56 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 0306A1A0188; Mon, 3 Jun 2024 17:33:42 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemd200014.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 3 Jun 2024 17:33:41 +0800 From: Yicong Yang To: , , , , , , CC: , , , , , , , , , , Subject: [PATCH 3/3] perf: arm_spe: Only show online CPUs in device's "cpumask" attribute Date: Mon, 3 Jun 2024 17:28:12 +0800 Message-ID: <20240603092812.46616-4-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20240603092812.46616-1-yangyicong@huawei.com> References: <20240603092812.46616-1-yangyicong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_023350_271731_E4A06487 X-CRM114-Status: GOOD ( 13.91 ) 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 From: Yicong Yang When there're CPUs offline after system booting, perf will failed: [root@localhost ~]# /home/yang/perf record -e arm_spe_0// Error: The sys_perf_event_open() syscall returned with 19 (No such device) for event (arm_spe_0//). /bin/dmesg | grep -i perf may provide additional information. This is due to PMU's "cpumask" is not updated and still contains offline CPUs and perf will try to open perf event on the offlined CPUs. Make "cpumask" attribute only shows online CPUs and introduced a new "supported_cpus" where users can get the range of the CPUs this PMU supported monitoring. Signed-off-by: Yicong Yang --- drivers/perf/arm_spe_pmu.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index 9100d82bfabc..2182f214c587 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -254,13 +254,33 @@ static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr, char *buf) { struct arm_spe_pmu *spe_pmu = dev_get_drvdata(dev); + cpumask_var_t mask; + ssize_t n; - return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus); + /* If allocation failed then show the supported_cpus */ + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus); + + cpumask_and(mask, &spe_pmu->supported_cpus, cpu_online_mask); + n = cpumap_print_to_pagebuf(true, buf, mask); + free_cpumask_var(mask); + + return n; } static DEVICE_ATTR_RO(cpumask); +static ssize_t supported_cpus_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct arm_spe_pmu *spe_pmu = dev_get_drvdata(dev); + + return cpumap_print_to_pagebuf(true, buf, &spe_pmu->supported_cpus); +} +static DEVICE_ATTR_RO(supported_cpus); + static struct attribute *arm_spe_pmu_attrs[] = { &dev_attr_cpumask.attr, + &dev_attr_supported_cpus.attr, NULL, };