From nobody Sun Oct 5 09:05:14 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 0087328BAAF; Wed, 6 Aug 2025 11:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754480571; cv=none; b=uHHolk94Ek6mrd7nsrv7cpHkA3OF1FFTWA8skyb/T/67uuNEloCjAaWFp8Sm503FTbxaJfW/8ea0kDkFIFh/ywlScMmXfmY+3TiQGPH/uVOuBgr8EkZnwCbIRpXpyutK8U0Tf4puKoYzSdCwvVKs2Eg0DxfzW67mJRWiD8y4ugk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754480571; c=relaxed/simple; bh=MIa7VhkI/yh4gVKc0wQvVbeoKvozHlCYgPTBtwGcE5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QsYLlPbZNdiyrx7qUlvdJhf7OR60PMBIpuS810NMZ+tFPbyB+kwUfZh5T8d/lx55gx41QCIvm4HTEaxv6jhHviwNlceGvqLUxtx532ze39gCtY0yc5RomvXK8X79/wNxjfmY9zU5rlUnQtI9L0mYF/CT0X6KXXZDNwtxULvbTb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=V3eFX0KI; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="V3eFX0KI" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 576690sA028213; Wed, 6 Aug 2025 11:42:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ZupdQg1vICiEqWP2f GJRDGqMQGt9XrZTyX7kfwpFfL8=; b=V3eFX0KI/RLszMjKsYnV54QfTTASiWUp5 9FMRB9Z5J54hLzhPhqAQn4IvNI88pEybIywmo0k65EW/ZxpRgcBoDsVwcJHox2CF 5/mF1svNmnmoRyx/FBxZk0h+EsByMUZzjxnrjkJnG2cjdJtmmI1wCJjLb4Pm1xNT YZyq4FSoLcW++dzoLVzLfaiqNUFa2OcBOVBnxsgXLG34mrbzf2L25eyl+QwiiVCj KBfTMBXncerLuQMl3teOy8AgNQW3DxeldqNLJMKJbGXrutZDpHOvlK+aAD231BtD oLsPe/EMhkAfCUdyjl2Rzaiepk2ssgM7qOHoAeA/Tgb2srftqjwaA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48bq60uwpt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Aug 2025 11:42:36 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 576Bgack014013; Wed, 6 Aug 2025 11:42:36 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48bq60uwpp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Aug 2025 11:42:36 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5767mMGH025946; Wed, 6 Aug 2025 11:42:35 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 48bpwn3d7c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Aug 2025 11:42:35 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 576BgVC061211018 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Aug 2025 11:42:31 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2DF420043; Wed, 6 Aug 2025 11:42:31 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17CBC20040; Wed, 6 Aug 2025 11:42:31 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.111.29.38]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 6 Aug 2025 11:42:31 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Ian Rogers , Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Thomas Richter , Jiri Olsa , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Ilya Leoshkevich , Eduard Zingerman Subject: [PATCH v4 1/2] libbpf: Add the ability to suppress perf event enablement Date: Wed, 6 Aug 2025 13:40:34 +0200 Message-ID: <20250806114227.14617-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250806114227.14617-1-iii@linux.ibm.com> References: <20250806114227.14617-1-iii@linux.ibm.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-TM-AS-GCONF: 00 X-Proofpoint-GUID: RjeSZbbjwwvN4eaYsdbq3rCoyu36mHDg X-Proofpoint-ORIG-GUID: 4Q29_vahi6Xz3ZMX2B2MrAa5Xq1-mKvT X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODA2MDA3MSBTYWx0ZWRfX15si+6XF8fVZ 9fRWgbfiFD+3QAmQgF1o1tcMONzhIVqMxgQOAFqudKLcccII3heufS8KIR4AyY3F8hlbUXjly/j Lb/PzBt1pOmBCpUU4TdzhtwZVW16tae2uedXOsqPX4EWez/9k7a870VXLR6RxuPVcRiMGAsuYpJ SH0N6eWnEXyVe50a88Py+qnY7KOaIL0o99xg+6mlwODWd6azI2TkO9Fv66ca7USLZEutnHQ66rg iPNF6NMq8qikUX8Gr1fanPC64Ww+nNjwetptQWZryGii1WwfOxgBMnZAzFFVKNcOjUZtFQ/0QCC fWM1ncztNJJ6AoVCaMQSLtUb2Glcik6dkBmmol5WmU2+s6/PzSgewitEm3hn3rBpMOdqADKo40N r2LZU+mvo1Zo4i7G1xl/eI0jzx4Uu/zzkHmcP3ZMQSzdHikGhDlqnLbQfThoTC7SNQ3wB2US X-Authority-Analysis: v=2.4 cv=TayWtQQh c=1 sm=1 tr=0 ts=68933fac cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=2OwXVqhp2XgA:10 a=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=TeCzLofx3L-FRdGKzo8A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-08-06_03,2025-08-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=996 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2508060071 Content-Type: text/plain; charset="utf-8" Automatically enabling a perf event after attaching a BPF prog to it is not always desirable. Add a new no_ioctl_enable field to struct bpf_perf_event_opts. While introducing ioctl_enable instead would be nicer in that it would avoid a double negation in the implementation, it would make DECLARE_LIBBPF_OPTS() less efficient. Acked-by: Eduard Zingerman Suggested-by: Jiri Olsa Tested-by: Thomas Richter Co-developed-by: Thomas Richter Signed-off-by: Thomas Richter Signed-off-by: Ilya Leoshkevich --- tools/lib/bpf/libbpf.c | 13 ++++++++----- tools/lib/bpf/libbpf.h | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index fb4d92c5c339..8f5a81b672e1 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -10965,11 +10965,14 @@ struct bpf_link *bpf_program__attach_perf_event_o= pts(const struct bpf_program *p } link->link.fd =3D pfd; } - if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { - err =3D -errno; - pr_warn("prog '%s': failed to enable perf_event FD %d: %s\n", - prog->name, pfd, errstr(err)); - goto err_out; + + if (!OPTS_GET(opts, dont_enable, false)) { + if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) { + err =3D -errno; + pr_warn("prog '%s': failed to enable perf_event FD %d: %s\n", + prog->name, pfd, errstr(err)); + goto err_out; + } } =20 return &link->link; diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index d1cf813a057b..455a957cb702 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -499,9 +499,11 @@ struct bpf_perf_event_opts { __u64 bpf_cookie; /* don't use BPF link when attach BPF program */ bool force_ioctl_attach; + /* don't automatically enable the event */ + bool dont_enable; size_t :0; }; -#define bpf_perf_event_opts__last_field force_ioctl_attach +#define bpf_perf_event_opts__last_field dont_enable =20 LIBBPF_API struct bpf_link * bpf_program__attach_perf_event(const struct bpf_program *prog, int pfd); --=20 2.50.1 From nobody Sun Oct 5 09:05:14 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 E478D28C030; Wed, 6 Aug 2025 11:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754480573; cv=none; b=BUhA2LGUnD2Sqye9+MZD4ZFxh37c4HUcUqvcK+dZ8znuT8GKbw5BBIySY70oCwcToSc9GQyJ4BwUJU4rcDns7Dx8CIOyG2s2KM8Y49fTyQHC5pd5JOAm7vh8uWcKtJtS6ysFyROkXsTlhpJQ7Vr+Ao+5X1iHO8T02t1ZCuO73ME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754480573; c=relaxed/simple; bh=AIGTeJYxg5f5rTF9J6Yr1pP2uX496go7egdBTNpDEjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sPMRuQ8OwUDZNmCfdjUF0fNTsUBi5+7EworwF32hSId9ETT3N/QT7j3cuJbEvdAODeWpmJg6ZVAybcETX1sXAShIkah5lhyUYXipQ6Od7WRS2jTw8ZgLx3aY6fyKSW3zXom5O9C1zzARAibmi/sEDlXnFAw+Iu2HFqTJLJOTeFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=aSAq6H+T; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="aSAq6H+T" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 57692NVB018065; Wed, 6 Aug 2025 11:42:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=kCizlyGIBjEVHLJ2i 2UgIfg7sJkeCUGZArvHbQj6wec=; b=aSAq6H+TVYDtBlIgytuIv7xyS1MJ/AIuJ 2Tm5zmjTP99oIw8o0iTj8gZGnKJ7+IkVb7me6Sh760ULzZlINNQ1wtKfIyzPVrQL xIkRRte/ZF/2ozBzLm6jiRbeGrsZThNfraSRrkgW7DWR/dy75XfF68GndAXdBzuM I542mDKYlKk7RMsYGwqCy2DF44j6D9Srl0mbqbrLcedGZVQF/Vo9J8XVp6QpmEMm HrOwxO5wk471iDm6rbOr/2QT3JpFdICkQ/b9ElLWAkJFjjQvJIfoIuXag3sgiXEf eLn052FK9KAix8QiWeRxNHHjrhU2zTjIZ4DWYqtCpNIfKaT6yDhlw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48bq633ukb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Aug 2025 11:42:37 +0000 (GMT) Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 576BbGqG026883; Wed, 6 Aug 2025 11:42:37 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48bq633uk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Aug 2025 11:42:37 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 57681YJN022687; Wed, 6 Aug 2025 11:42:36 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 48bpwqbcsc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Aug 2025 11:42:36 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 576BgWk250659818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Aug 2025 11:42:32 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 836B420043; Wed, 6 Aug 2025 11:42:32 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D680F20040; Wed, 6 Aug 2025 11:42:31 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.111.29.38]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 6 Aug 2025 11:42:31 +0000 (GMT) From: Ilya Leoshkevich To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Ian Rogers , Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Thomas Richter , Jiri Olsa , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Ilya Leoshkevich Subject: [PATCH v4 2/2] perf bpf-filter: Enable events manually Date: Wed, 6 Aug 2025 13:40:35 +0200 Message-ID: <20250806114227.14617-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250806114227.14617-1-iii@linux.ibm.com> References: <20250806114227.14617-1-iii@linux.ibm.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-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODA2MDA2OCBTYWx0ZWRfX1EZA0dnykXKF kxr+0U5eNc1nrJcoVH3WWb/Xfh6cPPnE/0KgSsscLVMJhnWAnYsMwOLtXZluIWm1udgfY6qbCQU qbT5T8zR7F9U1YtxJ8wDsHxOo0rW6Vh/CoaK/OPytFZ2shO3IZ8ANDeUnLzQ75yaqgHhEgpZN/0 9GkzA4jZMk9JsviizY1zLBLmkac+eWp4l9dZphr1r4eVmIYPylXfLDzDHEjbJu/0ANdKn183Eeq A6JQsb2jOr3IzEeumWpdzPgauqiyjuEunEj587M9Ny+UOYizxGt4FReHLsrEDgU4g6pQYa4DHs2 YV7toJSA/Yn8LM8ExokS+DjZ6sovj9la+tk3XXobmsJWl0Xuahexhy2shMG7t6FO64OUVzrBxho 7/NX+aL5QBUlLbGuknBj1z+g7pjmawIN0ZNUEVUQIssTNhX3cIaDkQHHQhCz2JNfMnR5+pDg X-Proofpoint-GUID: FgBIBnTGOEFzoYAjWcROHYtQV1Q3R7vG X-Authority-Analysis: v=2.4 cv=PoCTbxM3 c=1 sm=1 tr=0 ts=68933fae cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=2OwXVqhp2XgA:10 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=w8wHeiwaHs5MaTQqMIoA:9 X-Proofpoint-ORIG-GUID: J2WZsTn9MnauYsWfMsbgbFbpSmkH3uA2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-08-06_02,2025-08-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 adultscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2508060068 Content-Type: text/plain; charset="utf-8" On s390, and, in general, on all platforms where the respective event supports auxiliary data gathering, the command: # ./perf record -u 0 -aB --synth=3Dno -- ./perf test -w thloop [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.011 MB perf.data ] # ./perf report --stats | grep SAMPLE # does not generate samples in the perf.data file. On x86 the command: # sudo perf record -e intel_pt// -u 0 ls is broken too. Looking at the sequence of calls in 'perf record' reveals this behavior: 1. The event 'cycles' is created and enabled: record__open() +-> evlist__apply_filters() +-> perf_bpf_filter__prepare() +-> bpf_program.attach_perf_event() +-> bpf_program.attach_perf_event_opts() +-> __GI___ioctl(..., PERF_EVENT_IOC_ENABLE, ...) The event 'cycles' is enabled and active now. However the event's ring-buffer to store the samples generated by hardware is not allocated yet. 2. The event's fd is mmap()ed to create the ring buffer: record__open() +-> record__mmap() +-> record__mmap_evlist() +-> evlist__mmap_ex() +-> perf_evlist__mmap_ops() +-> mmap_per_cpu() +-> mmap_per_evsel() +-> mmap__mmap() +-> perf_mmap__mmap() +-> mmap() This allocates the ring buffer for the event 'cycles'. With mmap() the kernel creates the ring buffer: perf_mmap(): kernel function to create the event's ring | buffer to save the sampled data. | +-> ring_buffer_attach(): Allocates memory for ring buffer. | The PMU has auxiliary data setup function. The | has_aux(event) condition is true and the PMU's | stop() is called to stop sampling. It is not | restarted: | | if (has_aux(event)) | perf_event_stop(event, 0); | +-> cpumsf_pmu_stop(): Hardware sampling is stopped. No samples are generated and saved anymore. 3. After the event 'cycles' has been mapped, the event is enabled a second time in: __cmd_record() +-> evlist__enable() +-> __evlist__enable() +-> evsel__enable_cpu() +-> perf_evsel__enable_cpu() +-> perf_evsel__run_ioctl() +-> perf_evsel__ioctl() +-> __GI___ioctl(., PERF_EVENT_IOC_ENABLE, .) The second ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); is just a NOP in this case. The first invocation in (1.) sets the event::state to PERF_EVENT_STATE_ACTIVE. The kernel functions perf_ioctl() +-> _perf_ioctl() +-> _perf_event_enable() +-> __perf_event_enable() return immediately because event::state is already set to PERF_EVENT_STATE_ACTIVE. This happens on s390, because the event 'cycles' offers the possibility to save auxilary data. The PMU callbacks setup_aux() and free_aux() are defined. Without both callback functions, cpumsf_pmu_stop() is not invoked and sampling continues. To remedy this, remove the first invocation of ioctl(..., PERF_EVENT_IOC_ENABLE, ...). in step (1.) Create the event in step (1.) and enable it in step (3.) after the ring buffer has been mapped. Output after: # ./perf record -aB --synth=3Dno -u 0 -- ./perf test -w thloop 2 [ perf record: Woken up 3 times to write data ] [ perf record: Captured and wrote 0.876 MB perf.data ] # ./perf report --stats | grep SAMPLE SAMPLE events: 16200 (99.5%) SAMPLE events: 16200 # The software event succeeded both before and after the patch: # ./perf record -e cpu-clock -aB --synth=3Dno -u 0 -- \ ./perf test -w thloop 2 [ perf record: Woken up 7 times to write data ] [ perf record: Captured and wrote 2.870 MB perf.data ] # ./perf report --stats | grep SAMPLE SAMPLE events: 53506 (99.8%) SAMPLE events: 53506 # Fixes: b4c658d4d63d61 ("perf target: Remove uid from target") Suggested-by: Jiri Olsa Tested-by: Thomas Richter Co-developed-by: Thomas Richter Signed-off-by: Thomas Richter Signed-off-by: Ilya Leoshkevich Acked-by: Namhyung Kim --- tools/perf/util/bpf-filter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c index d0e013eeb0f7..a0b11f35395f 100644 --- a/tools/perf/util/bpf-filter.c +++ b/tools/perf/util/bpf-filter.c @@ -451,6 +451,8 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struc= t target *target) struct bpf_link *link; struct perf_bpf_filter_entry *entry; bool needs_idx_hash =3D !target__has_cpu(target); + DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts, + .dont_enable =3D true); =20 entry =3D calloc(MAX_FILTERS, sizeof(*entry)); if (entry =3D=3D NULL) @@ -522,7 +524,8 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struc= t target *target) prog =3D skel->progs.perf_sample_filter; for (x =3D 0; x < xyarray__max_x(evsel->core.fd); x++) { for (y =3D 0; y < xyarray__max_y(evsel->core.fd); y++) { - link =3D bpf_program__attach_perf_event(prog, FD(evsel, x, y)); + link =3D bpf_program__attach_perf_event_opts(prog, FD(evsel, x, y), + &pe_opts); if (IS_ERR(link)) { pr_err("Failed to attach perf sample-filter program\n"); ret =3D PTR_ERR(link); --=20 2.50.1