From nobody Fri Feb 13 03:09:00 2026 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 A53F484039; Mon, 3 Jun 2024 09:33:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407231; cv=none; b=nJ38hfbRyYJ9F3XKyRYn11QzGIdgrawL+N5o8tl4WeQ2XY4LHzCvWqJJH412H5tApLpi8cy0ZeMWX4f1zdreWPew1+qwZLXqquB6TTIRpH9AOtVw8XRksDl7K911OkwaWyGRLQ7biOxAjfOxXeaNI16Ocf/ktTX+KVbf8HFy7xU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407231; c=relaxed/simple; bh=vLeKRnEegxE0K436urLC3fMIxW8y761LOsyI4592Faw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pPGNttOTrw/RAXT0Bb6Xaw3TIdaas0+dAsAJM4MzMv4OWU0l6YRDPS1Cb1YFCCdUUu4ElbzXbPj19Zr8ETwauL57iN0YWupxTBBM21PQ3mjozmGNyo9joGUMMZeT4disbQlDNBQJfw9XgRR1261uvlKMNr4XQWC/pDX+wZdGY0o= 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.188 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.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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" 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/ --timeou= t 100 Error: The sys_perf_event_open() syscall returned with 19 (No such device) for eve= nt (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, con= st char *name, bool is_cor continue; cpus =3D 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 =3D perf_cpu_map__intersect(cpus, cpu_map__online()); + perf_cpu_map__put(cpus); + if (intersect) + return intersect; + } } =20 /* Nothing found, for core PMUs assume this means all CPUs. */ --=20 2.24.0 From nobody Fri Feb 13 03:09:00 2026 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 7A0D784039; Mon, 3 Jun 2024 09:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407226; cv=none; b=S8q9jfCWr8F7028UCgCT3/AbWXgN+PMFaJSDVlAnfbXLAAiYQh/Xrzsa2UcDtmj+ATtZK8qURa4i4NPBN/tc/rhQJ5T1mqNVIM4nIN3KWI2Kry+Y3HfAsacTNhe1DSAtYXCMdGKE79i73XjQHQq6QofaxRDx2Zo2nbfDWaSyYgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407226; c=relaxed/simple; bh=ElFxRXFnLreP2B/j6C2YdLwoMXQn2kE494QqHuqzJBY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hgU0JQgdh77ZJTV8/JYLQhLKH/OPcUbiIkj0PxdtrTUFAnl+G3ISJJQFwzjx1d2yKBeL+WHjn45d2cWkS5F78uoVfhkdIcueXZc/DdIgfegLJ+R1tNLJmuIanniY9rzfSJuyiCM2ucYwV0XrC6W2e8ptqdyS8+dqFTdyWR7XxDA= 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.190 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" 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 eve= nt (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 =3D 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 =3D cpumap_print_to_pagebuf(true, buf, mask); + free_cpumask_var(mask); + + return n; } =20 static DEVICE_ATTR_RO(cpus); =20 +static ssize_t supported_cpus_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct arm_pmu *armpmu =3D 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[] =3D { &dev_attr_cpus.attr, + &dev_attr_supported_cpus.attr, NULL, }; =20 --=20 2.24.0 From nobody Fri Feb 13 03:09:00 2026 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 C70D585C77; Mon, 3 Jun 2024 09:33:49 +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=1717407231; cv=none; b=C+AcLVRNThe9B5egPUcbdIgx+evbkKl7WYEG6YwTf3PMFRvUKc76bThSVkHc9jeT+ffouPdR+8O2PAKAbNLxqpkyFhDbFHfl+LM8llQWhkuaHQ0zxxnJD83ugMMhw0xdR5o9R74/JX/EQ2gMEh4zNBSY957baiRbLniG5NT6zGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407231; c=relaxed/simple; bh=XhEbvu4Og1P2n64dCfUrrOpcJR4T9pHKZ6Ww9X4yrKg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZVTtSFuyBfqwz5O+O1J7jBNZ2fGW7izR3FrF5U+Csg/rG9f0HhXsVA+rudDE9Jc7hwPyWQ3hOhSHKqx4MSc7DD+/ItCOFFkMCQ6YR48QSOh5OK2oZsLnlaaCGSspGKp5y12YJCSm/bon+4czqIX6g0ZoZ8kpZ8gg4U57bIUNpuA= 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.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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) Content-Type: text/plain; charset="utf-8" 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 eve= nt (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 =3D dev_get_drvdata(dev); + cpumask_var_t mask; + ssize_t n; =20 - 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 =3D cpumap_print_to_pagebuf(true, buf, mask); + free_cpumask_var(mask); + + return n; } static DEVICE_ATTR_RO(cpumask); =20 +static ssize_t supported_cpus_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct arm_spe_pmu *spe_pmu =3D 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[] =3D { &dev_attr_cpumask.attr, + &dev_attr_supported_cpus.attr, NULL, }; =20 --=20 2.24.0