Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp848962lqj; Mon, 3 Jun 2024 02:41:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1uWs/+ecX/W5Z4Mgp13NS9a3Hf4bfGmL66wcFpzswvl6DE1Eij3U5Aph39kzxXmleMTJ0begJa48DEANc13PcLX3o5otUxjVc+z2OCQ== X-Google-Smtp-Source: AGHT+IHtYQvONydnsO4YqkN3xHs6tJjuDUcRswDYEkZgg+jzH76Yxs3WUoMtLOvF67vJ+IujW742 X-Received: by 2002:a05:6830:1646:b0:6f1:a68:aa7a with SMTP id 46e09a7af769-6f911fa4811mr9264974a34.30.1717407706973; Mon, 03 Jun 2024 02:41:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717407706; cv=pass; d=google.com; s=arc-20160816; b=NBc0e1HnldOFBwtr4qOehouWvK1EAyr/JKqm5OZG0dhlN0FJZ6Gq9tsw8p8dsuGJ0e SeVth9WWF6pQ2oHNKFHtgYjGJGzZqjH6UayXd0jAHLq9ESgrAvConvQL49UoJ2/hGaZD /UqKgIWoBZ3Ctw9aLkWZgV0TXLEZKoqIWyxVd+FTxpPKTvqy9mGUAkedgITgXbnamlmm 6MnSdMK9ObvqHcxV9RaND7fW569FJYJ4NQRocd8YCIu6e1ps4aIAw9/cJWF4ece2J319 XAOiRFgaohokQ7lTYbGT+kla+pvpaLVwhTBh2fu991ps46rq6OESiaplrVwqOId8NokJ o7QA== 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=bYtUH2sACtbt4/o9pxq08YeS83/l28fZ9AReIkaZhQk=; fh=VhBxH1C4pU1DnwJbzdVbrnpE43L8HbJjIwxS5moYSuM=; b=GYX3NUzPKtxyfNMCcjk3JoOZyijN6vQNcQ7ea8n6WFjySCuPAANg6ph49+M6PzQTzT QtUkv9NwpMwxc2bIMw3XSuODIgEQWZOX5gfrDjMGgGQQRGNJLCsJPRLVVqhEfNkpzER5 co0La0Kydg7AD3KUMBk7OqymzwXVdi6ahbsp96z2ztimdF+3S6gyIsyflYNpy1mcyCUT GX/8r5H1m8BDfO3DzYOBCrHzd0JrkdEzyBdXH75LcNJQT75ceQTAGQIo2sbdvr10nLFn 6AXO82e+uySBukw4ddWyAgDmkE9NdbmivC20958pBA5eMOuQRiVBhzT7c9LgVrVT2ci8 wEpg==; 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-198910-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198910-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c355157b95si6155647a12.190.2024.06.03.02.41.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 02:41:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198910-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-198910-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198910-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F89D280AA2 for ; Mon, 3 Jun 2024 09:41:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 860EA763E4; Mon, 3 Jun 2024 09:33:46 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 5632282D86; Mon, 3 Jun 2024 09:33:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407226; cv=none; b=Kl22NDWBopGYRobKNYO3A5VlgQlUZfH/95JWgpkSilluJ7vkWouwLBHK1+oSuoDX3vtqIZl1kFDh3i0MjP8CoEyC5yywL3IPpWhn36MGtIeaIPjIoKJ0+l0PhYXX+BsgqNBs7iRjgAcQ1zfyvBFS9Tq3N8dUFXKHLed0IPbJAbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407226; c=relaxed/simple; bh=irUYFkAM4ysrKF+H1+xbc54MGs1P7MFJrAkGBeKcA2s=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cZKNNN+zXCEJUKJWyTeITjb01SEoza8H5a5V6lf/A/Ud3pyVMUL5MHIZ6zYSeBeF1MkpGdkfVzSJvUPzUhZolBIbTR8SigMO0Kw+RtW2UQuG5ymUnjVJZHgsv4W7g4ew+y/qKC83yz4Zyw9azJnV9QQ4sHOs4d/Bl6Ui2c7xfwc= 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.187 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.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 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: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd200014.china.huawei.com (7.221.188.8) 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(-) -- 2.24.0