Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp32122lqj; Wed, 10 Apr 2024 03:04:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8OWAviyXA1rlesXsCo9KDjIradEr3kZVeBKPdgCmUqvsoKrhJT2OaiO3IqtyEtJbPgQqUBxmeXtHJ4LtF7WQVIkb21wBfEEINn7EnSw== X-Google-Smtp-Source: AGHT+IEDzGQP5jTMUIlbVEQxnn8GPmL63l+gSUjiuyHl1+B5UI9olRkH/7FtZ+yjaQggN8WrgptO X-Received: by 2002:a17:90a:6d61:b0:2a2:6735:c426 with SMTP id z88-20020a17090a6d6100b002a26735c426mr2388118pjj.34.1712743444985; Wed, 10 Apr 2024 03:04:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712743444; cv=pass; d=google.com; s=arc-20160816; b=NcuyP9eNSZ5CuWU68hdPlrXy1bupfvWecLgicApo5e1PIeYbgqN+1pyPDfCUSPHi2g JqFTd/udg8zHAWRjaTpAEhXilX9zLl5TvZoXQlitMNRSC98rMARonMDTAqvwmAawiAQ0 NIw4c2/v/bprsxfmMcRlebAEBoOpW8pAui1jubyzqjLQbkAUtUtu29bc4qmEbyBd3FGN //lMEhX0nG/P43G1bKZLOvjr7uJdx/K6fPc7H/fOAHNg0c6mIVBQiw4PHkP5MCfiBF/x WMHtIO2XE12pdTi/x7uTasezXle3/cDX634yzlfh+aFtu9GF8TzTQw5iV6SGy7kOy7nx AmxA== 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:message-id:date:subject:cc:to :from; bh=677jkwcyLoIw3bwtmZNjeTjEeogLyFbws7oS3q3d5QQ=; fh=wlk2/BtQnnn+vbfuTmWGWAwyATjkSxrhQPkKaMzb9rU=; b=H4warAZ9ZORyfYGn90/VNgLdm8uPVlzgMl05ImzIQxxjnSFcT7nRTgg1icEIdoJPqV ZNbIqzKFbJeBX6OJdiHK217EtiRXs19b506eD9ESro9ywgjz+6cyLEWR/XH5XcIgiNDH SvHDjHJV1xYsGkaaA0rW//jIBN1k0d4dThD5UVBveIw29gfYbrsu7MiWF4P74m8sjAU7 IZcKw3w12Ycx/v6gJ0inXSrIsE5q80zCka3YHbqnbFc3nAitPx07w66VSpFfKjQ/wR6C zADZFnWx/ngzt40jXnkSH1hBdpgoKufB8C/hyedTuR4MFPBG1CKgnfRbNVYXHS/T5Mge hIpQ==; 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-138294-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x13-20020a17090a8a8d00b002a2243ed622si1215635pjn.123.2024.04.10.03.04.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 03:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138294-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-138294-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138294-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 830C6B21AB2 for ; Wed, 10 Apr 2024 10:03:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 247AE1581E9; Wed, 10 Apr 2024 10:03:34 +0000 (UTC) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (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 8DA2E8F4E for ; Wed, 10 Apr 2024 10:03:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712743413; cv=none; b=BRNqBrVYNg5u3ldcrhSk08PGU2a+BjRcX744wzHFZKoLEHpd0vEolWmj0hWv601BzPUlyPxvO+b5VWqqO+m6ctHc96lgstvcn6gDY+BBlyCl8vfcF64kxr21toz04f1aoVrKm7huyOS+qLmU0vhQj6rkcR8kWgG4PRDWueGimog= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712743413; c=relaxed/simple; bh=ElFxRXFnLreP2B/j6C2YdLwoMXQn2kE494QqHuqzJBY=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=s+b4bG/NQjef5MItJJBT8Az1FVYiCMElbO+jRsyeRs6Wr9nBisc+KKGtP3OFuP+97yIwKUePXZrEGil+DnujF+2debvcweToJLFNRXRoulcqGhRfXbRTNOyb6r8mcYZZ2Gs+51Hv6e38cmZaoB/8L9yJyAkweVg0XKbse0fMXaw= 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.189 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.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4VDyyX29TxzNnM7; Wed, 10 Apr 2024 18:01:08 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 5EF4B1402CE; Wed, 10 Apr 2024 18:03:24 +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.28; Wed, 10 Apr 2024 18:03:23 +0800 From: Yicong Yang To: , , , CC: , , , Subject: [PATCH 1/2] perf: arm_pmu: Only show online CPUs in device's "cpus" attribute Date: Wed, 10 Apr 2024 17:58:32 +0800 Message-ID: <20240410095833.63934-1-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 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 kwepemd200014.china.huawei.com (7.221.188.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 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, }; -- 2.24.0