From nobody Sun Oct 5 10:44:51 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 402692749E5; Tue, 5 Aug 2025 13:04:07 +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=1754399049; cv=none; b=iBjpv4Acw8yVpNmc7ir/2KIEQl6eAvgOcJmIoi1XmFMUZNj4wu0S1kCQKl3NTj+tv1AC8UaDpQqzFgl/juOFIm6zw+t04IAznjljxwEGBkDDnyJfC8dUxmLrwphuY03fNca9V+Z19hsLaWw5pZHoXbyIc21JOObB1oAOtYKQjrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754399049; c=relaxed/simple; bh=qowIQFnkyUS+qUvfWHjIy9RCYD1yFAM+odJM6VCYDhc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fuCsviECmmb6VkLBhPkKjBhfyFYwLNml9YJb+V040HmJ3zEc+mJaOzu9nbvIiuqnscqdns9Y8FLWiA8fuAXPzDmT6MAJTzMp+Aw7vBIhoeiQz/8g1mzvik+kKCUwuzVt2CsixLn/4q8YFKqUJWvegxisHhEUKP0OUGtHZ5HLeuI= 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=pW4GvNIQ; 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="pW4GvNIQ" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5751TCO6026512; Tue, 5 Aug 2025 13:03:55 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=nU7M5SlBmkDNtuaV9 CsYc1B9MsKzHyuyhrX31Jev03s=; b=pW4GvNIQ4GSuEXekE4Sj55eibSWDwflDq 3z0pQhAjJN1NDw8ZGlPpuB/kcPSH0TEOaomQifNqFSRtUbn9RL+RRSmnIFkr5gNq M5lmPh6En39eB2IUxLa8ej1pGY7IBvMGhQBITtgkoOwTRenf+bWG1LcLn4y9Su+a PlyoiUMB6D0wfUqOTVeQcvpia5jc84vzt3x/wAO3Sat9BlAqQYIOWqXPZkJi0cKg hFG2cso8chE/NJjyZzFI/3WmyBWXGgSapU96Wk6lMnY6XzocHbD5T2F4MW/WT4DK 0dD8Vwxa8tsAmfeBnc/pjq9w2rjNLE/XwmuMpEbYtCQcLO8FcJPAw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48a4aa2k85-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Aug 2025 13:03:55 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 575D3ske006493; Tue, 5 Aug 2025 13:03:54 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48a4aa2k82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Aug 2025 13:03:54 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 575A6bFv004495; Tue, 5 Aug 2025 13:03:53 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 489yq2j7fc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Aug 2025 13:03:53 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 575D3osS50069940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Aug 2025 13:03:50 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 301902004D; Tue, 5 Aug 2025 13:03:50 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 23A9520040; Tue, 5 Aug 2025 13:03:49 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.87.141.116]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 Aug 2025 13:03:49 +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 v3 1/2] libbpf: Add the ability to suppress perf event enablement Date: Tue, 5 Aug 2025 14:54:04 +0200 Message-ID: <20250805130346.1225535-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805130346.1225535-1-iii@linux.ibm.com> References: <20250805130346.1225535-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: MhSFNhiVsLSK11Rjn3lbrUYxrrJs5w7d X-Authority-Analysis: v=2.4 cv=dNummPZb c=1 sm=1 tr=0 ts=6892013b cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=2OwXVqhp2XgA:10 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=5Tfx8qovrACkoZmbRlMA:9 X-Proofpoint-ORIG-GUID: TW7xbIt1y1u0HOPmQdlcuS-tZzJlO244 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwODA1MDA5MCBTYWx0ZWRfX1W7T1XxXpGvU XDolJo/df3zFzod2G0pUB+iZCySjXFm+njIKXw/RaFBSukDBXHkFmJt/i3mjmBIU52/Yehn8cvd 7YcNsTJhAgcf4DuYVH+faP9stl462+22xFizdQZNaqmgpd+hyr6aRnrwQ+cMoqS0JanRWg9EVnG 9GVa7p6louUJd8n88Q6qWRr4Qsghql9g6q2pAy/j+SrGt4zyHlaR5InziGCvGypy5zhShD5/+ao lpIXGNVBcEfxGsoZVQCH/+GCZkz7UsuvjQlfasE4WW+EPrGdtLhJYtztXQQe3zf4564N0ai+qsF o22PSx1LUdCvLVS8i3f2eHxvnfSb/DyvsvB2DmtmSWG98y3SfjN5S30WDuh+emB6REAvlFGjzLI BfpNmuPdIomNfKhe7/xIXEVyXaPWOEK5mIn+syy0UUB15fIZdVrDVOOmfVC/kNgwGjF3I4/h 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-05_03,2025-08-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 mlxscore=0 clxscore=1015 mlxlogscore=902 malwarescore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 impostorscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2508050090 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. Suggested-by: Jiri Olsa Co-developed-by: Thomas Richter Signed-off-by: Thomas Richter Signed-off-by: Ilya Leoshkevich Tested-by: Thomas Richter --- 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..414c566c4650 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, no_ioctl_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..2d3cc436cdbf 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 no_ioctl_enable; size_t :0; }; -#define bpf_perf_event_opts__last_field force_ioctl_attach +#define bpf_perf_event_opts__last_field no_ioctl_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 10:44:51 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 60B6E274FE8; Tue, 5 Aug 2025 13:04:10 +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=1754399053; cv=none; b=bD4J9z76XSVwnxR+Zw1dbt9kQ2CxT2rEwdN6+E7+h3XxcQH3Wi0GkOknLfAOrgXx9d1BQRoSuCZ6oJEHNZ4wWoWTU09pXwai0diP1/2U3VP+Ta1OdxeavLaq8MGzFsVqoIkoXM+ZTWbh4A98qi8w4SD5gwd5HEFdv4VPlb0YnmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754399053; c=relaxed/simple; bh=4TCs8T6rPdDw+WjORxD4LfXmreO/1Hdv3tZS6BINC8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jhNqc6j56BpOid3D3nWDhflCTVCICkQO2Rkm793UQtGHmyuNWaJq7uU71MWVdvv8aRpNhJi4T5hP3bPvy2sAL4gucv1adjl9P8468Ohon4SsShukP3+hrAlljWEh8KlQ3Ouk+S/Mfv1iYTL2aVmv4Wky+sTwV/UX6HPZCa+jDfk= 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=Oo9jZTOL; 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="Oo9jZTOL" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5758wBSJ025323; Tue, 5 Aug 2025 13:03:56 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=oznJXzdTR8cxpW1z6 yoy8Ld2n5Rz+kPjepuZzrbEiKQ=; b=Oo9jZTOLyeTMA+EnWWmish8KWe3hXBkKa o88YzSO6crvxs2IOTBsHQmn0DoZCf1CVYibJVIihYeUbaIOchFqKflGz73U4YkNI 1u5ZzA7+u8/OLHv86clZ74r2BNuyikOo9JhfHepc1Ys4W45XMOQ7bvqt9xO/iHiR vnUA/C80hSTbCPgnUY8ftLPxIEk0pVDy4B33hfxjIO851dikKtn0c2KY11GlX5/n +d/2xs33D8ZFnRNYXmk29hnskxpBpMCDFJ18lPanjvsGXxK4k2OiTn9t+xMxc4/Y g62zFP6+6F4sO3tTMHUkNB2eA5x+s0OmQa4RBi1ZpMdYph6FxXwWA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48983t6wss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Aug 2025 13:03:56 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 575D3tTc010205; Tue, 5 Aug 2025 13:03:55 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 48983t6wsq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Aug 2025 13:03:55 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 575A6bFw004495; Tue, 5 Aug 2025 13:03:55 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 489yq2j7fg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 Aug 2025 13:03:54 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 575D3pSI19202414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Aug 2025 13:03:51 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 41A9520043; Tue, 5 Aug 2025 13:03:51 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CEE420040; Tue, 5 Aug 2025 13:03:50 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.87.141.116]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 Aug 2025 13:03:50 +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 v3 2/2] perf bpf-filter: Enable events manually Date: Tue, 5 Aug 2025 14:54:05 +0200 Message-ID: <20250805130346.1225535-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805130346.1225535-1-iii@linux.ibm.com> References: <20250805130346.1225535-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: AW1haW4tMjUwODA1MDA5NCBTYWx0ZWRfX324SwytEouD1 Fs1ajQyWChONgqYW8d4gmuGL+21nOHk2q+E7pptl07nXTzMuigLC2NHjcG10022p6h+/l0mIrwE oeITPgBWlVoSy9HSzyyvXZRlqS/X1oQopg84Z31LRC/obz7OIJfhEdwZH+CQkMZ3S2bXC7odCl2 dYw6ddY5kZjutBQ1PUMw/ISfhUnbTfcbAtHYl5K9tqcJXEnctjCrqhUZcATSkUjDC8/5j0eSW4X il39bibvaAROVjYkYgCrTojHIp+L7FS0Zn/PZaK8nkFBovGekb3m4e6zKHl0TFBhiTmwdBkHI4x nNpQVLLs+dYALZKc80C/BzRA40hq63IIZ3Fg5bLn0bZVWkTxAqjjIxeZsBTNcfOBUHvC/1C+GLT jEZWdCU/lo6pjrACYnXpReg2ZdeO3+caCVcdtCaYCbw/L5BTuKVGrpE6VUVW2yA0g6LXM7Lc X-Proofpoint-GUID: KL32_dLLaN2XvdAwN5Y8IBib0CB_nCmp X-Proofpoint-ORIG-GUID: oTmD_Lxw1PKjGtEeRBBjLOGmESNl0GYT X-Authority-Analysis: v=2.4 cv=AZSxH2XG c=1 sm=1 tr=0 ts=6892013c cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=2OwXVqhp2XgA:10 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=vr62MNj9oYPwvujLfVgA: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-05_03,2025-08-04_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 impostorscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2508050094 Content-Type: text/plain; charset="utf-8" On linux-next commit b4c658d4d63d61 ("perf target: Remove uid from target") introduces a regression on s390. In fact the regression exists on all platforms when the event supports auxiliary data gathering. 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 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: 63f2f5ee856ba ("libbpf: add ability to attach/detach BPF program to = perf event") Suggested-by: Jiri Olsa Co-developed-by: Thomas Richter Signed-off-by: Thomas Richter Signed-off-by: Ilya Leoshkevich Tested-by: Thomas Richter --- 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..d480ccaf3662 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, + .no_ioctl_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