From patchwork Mon Jun 3 09:28:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yicong Yang X-Patchwork-Id: 13683465 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 5F3D7C25B75 for ; Mon, 3 Jun 2024 09:34:12 +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: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:In-Reply-To:References: List-Owner; bh=nSIKooOp1LH3bzLM47pgpGNN2LjjdVesfkuJmy2J21Y=; b=lCVMEF4VJOGwuZ oR5S12SMvApphe1Da5wskhs6Oc8WaMFm/wL1LFdAK06thTqiMIk3HgzwMlgiJ+Q8zhyOJCthQQP/c ZeDekB+rfWw9l+K1KQ8wHfUzTbilrAFh8bJwg50zKMMPT2Kx75t4tNQ3TtQ/4nrge/uUDWSktjQbb kzwYk+PE3JpKTcDiH06BtPH2z7sfNfwI4useGkJMTD1gj8ZvTNFRfV3tEz3lFmiDiL+r04u4JBtUD GpBhoEtbV4EyJtPZTzYAjjQPN7NsezXWBd4NwWMXLmEgh0kUbo+BbZpEvQfm29yxfys2LNwHEOXyb YL7J/WLLZQGvJfpUCfdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44j-0000000GEur-26JI; Mon, 03 Jun 2024 09:33:57 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sE44Z-0000000GEmH-1y02 for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 09:33:55 +0000 Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Vt7jQ2TGNzwRJy; Mon, 3 Jun 2024 17:29:46 +0800 (CST) Received: from kwepemd200014.china.huawei.com (unknown [7.221.188.8]) by mail.maildlp.com (Postfix) with ESMTPS id 4866118006E; 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:39 +0800 From: Yicong Yang To: , , , , , , CC: , , , , , , , , , , Subject: [PATCH 0/3] Perf avoid opening events on offline CPUs Date: Mon, 3 Jun 2024 17:28:09 +0800 Message-ID: <20240603092812.46616-1-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 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_279918_014E9287 X-CRM114-Status: GOOD ( 11.75 ) 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 If user doesn't specify the CPUs, perf will try to open events on CPUs of the PMU which is initialized from the PMU's "cpumask" or "cpus" sysfs attributes if provided. But we doesn't check whether the CPUs provided by the PMU are all online. So we may open events on offline CPUs if PMU driver provide offline CPUs and then we'll be 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. This patchset tries to avoid this case by: - Double check the PMU's cpumask in the perf tool and only include online CPUs - Trying to make the PMU drivers only export online CPUs in its "cpus" or "cpumask" attributes Previously discussion can be found at [1]. Will suggested to do it in userspace. I think it makes sense to do a double check in the perf tool in case the driver doesn't do this. So PATCH 1/3 is added in this version. [1] https://lore.kernel.org/linux-arm-kernel/20240410095833.63934-1-yangyicong@huawei.com/ Yicong Yang (3): perf pmu: Limit PMU cpumask to online CPUs perf: arm_pmu: Only show online CPUs in device's "cpus" attribute perf: arm_spe: Only show online CPUs in device's "cpumask" attribute drivers/perf/arm_pmu.c | 24 +++++++++++++++++++++++- drivers/perf/arm_spe_pmu.c | 22 +++++++++++++++++++++- tools/perf/util/pmu.c | 13 +++++++++++-- 3 files changed, 55 insertions(+), 4 deletions(-)