From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CB67C433F5 for ; Fri, 25 Feb 2022 10:36:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239622AbiBYKgq (ORCPT ); Fri, 25 Feb 2022 05:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239591AbiBYKgm (ORCPT ); Fri, 25 Feb 2022 05:36:42 -0500 Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB192399F4; Fri, 25 Feb 2022 02:36:10 -0800 (PST) IronPort-SDR: 3Ize7zT55FsZi+9UEP3oL5OFjOldX0bdD8oqpHofkx6N9REqySHynuB3vFr3NGK3UkvpPvyPn3 SzD+RXjnw7OBhpYOdH7ZxRpPRLjzK68V8r4dXfEbi4Ka5pYexU9M/dyWp8VEy4kHPzR0xQgvQl tmP+9x7Yy/0jesRwHC/jwBLVJq8zmaM7D40bJaxOu7kjBVxjQcL+++RmAhPQKrzO7BPTltgHXa URgHiAo2TtUbZ5BkrEgrUVDXw6JR61hEMKxkCji7piNbdl5kGzxyaLR/v16kaFOnLAC7gOOaqY p4ABAb6LrOyNs7wAmkUVIMlX X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="64248432" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="64248432" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:08 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 8CAD1C68A8; Fri, 25 Feb 2022 19:35:06 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 7899FCFBC2; Fri, 25 Feb 2022 19:35:05 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 6D1AA40124EF7; Fri, 25 Feb 2022 19:35:05 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 1/7] libperf tests: Fix typo in the error message "evsel" -> "evlist" Date: Fri, 25 Feb 2022 19:31:08 +0900 Message-Id: <20220225103114.144239-2-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura This patch corrects a typo in the error message. Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/tests/test-evlist.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test= -evlist.c index b3479dfa9a1c..fafc6b0f8687 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -68,7 +68,7 @@ static int test_stat_cpu(void) perf_evlist__set_maps(evlist, cpus, NULL); =20 err =3D perf_evlist__open(evlist); - __T("failed to open evsel", err =3D=3D 0); + __T("failed to open evlist", err =3D=3D 0); =20 perf_evlist__for_each_evsel(evlist, evsel) { cpus =3D perf_evsel__cpus(evsel); @@ -129,7 +129,7 @@ static int test_stat_thread(void) perf_evlist__set_maps(evlist, NULL, threads); =20 err =3D perf_evlist__open(evlist); - __T("failed to open evsel", err =3D=3D 0); + __T("failed to open evlist", err =3D=3D 0); =20 perf_evlist__for_each_evsel(evlist, evsel) { perf_evsel__read(evsel, 0, 0, &counts); @@ -186,7 +186,7 @@ static int test_stat_thread_enable(void) perf_evlist__set_maps(evlist, NULL, threads); =20 err =3D perf_evlist__open(evlist); - __T("failed to open evsel", err =3D=3D 0); + __T("failed to open evlist", err =3D=3D 0); =20 perf_evlist__for_each_evsel(evlist, evsel) { perf_evsel__read(evsel, 0, 0, &counts); @@ -506,7 +506,7 @@ static int test_stat_multiplexing(void) perf_evlist__set_maps(evlist, NULL, threads); =20 err =3D perf_evlist__open(evlist); - __T("failed to open evsel", err =3D=3D 0); + __T("failed to open evlist", err =3D=3D 0); =20 perf_evlist__enable(evlist); =20 --=20 2.31.1 From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FEACC4332F for ; Fri, 25 Feb 2022 10:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239645AbiBYKhE (ORCPT ); Fri, 25 Feb 2022 05:37:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239634AbiBYKg5 (ORCPT ); Fri, 25 Feb 2022 05:36:57 -0500 Received: from esa4.hc1455-7.c3s2.iphmx.com (esa4.hc1455-7.c3s2.iphmx.com [68.232.139.117]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A58424FA02; Fri, 25 Feb 2022 02:36:24 -0800 (PST) IronPort-SDR: D6FgPXK2j950xBnExInaXsP24Vu1JkBjTBH2CJ++8R0BUXnD4nCMf1E3RmHVoNef1TVpfJG18I aKiHTtoScN2T+QcSypTdk+C6wigS9YUW+9LNYjPuHYgBH1nBWtsQSjVpyR7APaI1ps10tM2AUM R9N5v0tfVj6H+EsWbBuNBoATElZXx3hewbPlaP7a80axjZaXTw2QuHZ8NO1YIm2S9cQtn1Wp7A CI/Ij5K1CK92qzUuzgNxPiPBO3sR1YyfsAcevQTawTyYg3iesbAf9HZf163+o7r3xkB/JYR52d vsH5Hvt6VVQwgVX+FWazQwbI X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="64087260" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="64087260" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa4.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:17 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id DABBCCA245; Fri, 25 Feb 2022 19:35:15 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 9A105D9945; Fri, 25 Feb 2022 19:35:14 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 7F5BC40124EF7; Fri, 25 Feb 2022 19:35:09 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 2/7] libperf: Add perf_evsel__set_close_on_exec() function Date: Fri, 25 Feb 2022 19:31:09 +0900 Message-Id: <20220225103114.144239-3-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura Move evsel::open_flags to perf_evsel::open_flags and add a function to set PERF_FLAG_FD_CLOEXEC. Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/Documentation/libperf.txt | 1 + tools/lib/perf/evsel.c | 15 ++++++++++++++- tools/lib/perf/include/internal/evsel.h | 2 ++ tools/lib/perf/include/perf/evsel.h | 1 + tools/lib/perf/libperf.map | 1 + tools/perf/util/evsel.c | 16 +++++++++------- tools/perf/util/evsel.h | 1 - 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index 32c5051c24eb..96a451cd34eb 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -149,6 +149,7 @@ SYNOPSIS struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); + int perf_evsel__set_close_on_exec(struct perf_evsel *evsel); -- =20 *API to handle maps (perf ring buffers):* diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 210ea7c06ce8..d22b1468a1ad 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -26,6 +26,7 @@ void perf_evsel__init(struct perf_evsel *evsel, struct pe= rf_event_attr *attr, evsel->attr =3D *attr; evsel->idx =3D idx; evsel->leader =3D evsel; + evsel->open_flags =3D 0; } =20 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr) @@ -158,7 +159,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct p= erf_cpu_map *cpus, =20 fd =3D sys_perf_event_open(&evsel->attr, threads->map[thread].pid, - cpu, group_fd, 0); + cpu, group_fd, evsel->open_flags); =20 if (fd < 0) return -errno; @@ -454,3 +455,15 @@ void perf_counts_values__scale(struct perf_counts_valu= es *count, if (pscaled) *pscaled =3D scaled; } + +int perf_evsel__set_close_on_exec(struct perf_evsel *evsel) +{ + int err =3D 0; + + if (evsel) + evsel->open_flags |=3D PERF_FLAG_FD_CLOEXEC; + else + err =3D -1; + + return err; +} diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/inclu= de/internal/evsel.h index cfc9ebd7968e..37a99cf261b3 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -51,6 +51,8 @@ struct perf_evsel { int nr_members; bool system_wide; int idx; + + unsigned long open_flags; }; =20 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *at= tr, diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index 2a9516b42d15..23b0334a4c57 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -43,5 +43,6 @@ LIBPERF_API struct perf_thread_map *perf_evsel__threads(s= truct perf_evsel *evsel LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *ev= sel); LIBPERF_API void perf_counts_values__scale(struct perf_counts_values *coun= t, bool scale, __s8 *pscaled); +LIBPERF_API int perf_evsel__set_close_on_exec(struct perf_evsel *evsel); =20 #endif /* __LIBPERF_EVSEL_H */ diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 93696affda2e..0f8d13f9009b 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -52,6 +52,7 @@ LIBPERF_0.0.1 { perf_mmap__read_done; perf_mmap__read_event; perf_counts_values__scale; + perf_evsel__set_close_on_exec; local: *; }; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 22d3267ce294..52c34552ee76 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1794,9 +1794,9 @@ static int __evsel__prepare_open(struct evsel *evsel,= struct perf_cpu_map *cpus, perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) = < 0) return -ENOMEM; =20 - evsel->open_flags =3D PERF_FLAG_FD_CLOEXEC; + evsel->core.open_flags =3D PERF_FLAG_FD_CLOEXEC; if (evsel->cgrp) - evsel->open_flags |=3D PERF_FLAG_PID_CGROUP; + evsel->core.open_flags |=3D PERF_FLAG_PID_CGROUP; =20 return 0; } @@ -1814,7 +1814,7 @@ static void evsel__disable_missing_features(struct ev= sel *evsel) evsel->core.attr.clockid =3D 0; } if (perf_missing_features.cloexec) - evsel->open_flags &=3D ~(unsigned long)PERF_FLAG_FD_CLOEXEC; + evsel->core.open_flags &=3D ~(unsigned long)PERF_FLAG_FD_CLOEXEC; if (perf_missing_features.mmap2) evsel->core.attr.mmap2 =3D 0; if (evsel->pmu && evsel->pmu->missing_features.exclude_guest) @@ -1902,7 +1902,8 @@ bool evsel__detect_missing_features(struct evsel *evs= el) perf_missing_features.clockid =3D true; pr_debug2_peo("switching off use_clockid\n"); return true; - } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FL= AG_FD_CLOEXEC)) { + } else if (!perf_missing_features.cloexec && + (evsel->core.open_flags & PERF_FLAG_FD_CLOEXEC)) { perf_missing_features.cloexec =3D true; pr_debug2_peo("switching off cloexec flag\n"); return true; @@ -2029,11 +2030,12 @@ static int evsel__open_cpu(struct evsel *evsel, str= uct perf_cpu_map *cpus, test_attr__ready(); =20 pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags = %#lx", - pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, evsel->open_flags); + pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, + evsel->core.open_flags); =20 fd =3D sys_perf_event_open(&evsel->core.attr, pid, perf_cpu_map__cpu(cpus, idx).cpu, - group_fd, evsel->open_flags); + group_fd, evsel->core.open_flags); =20 FD(evsel, idx, thread) =3D fd; =20 @@ -2050,7 +2052,7 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, if (unlikely(test_attr__enabled)) { test_attr__open(&evsel->core.attr, pid, perf_cpu_map__cpu(cpus, idx), - fd, group_fd, evsel->open_flags); + fd, group_fd, evsel->core.open_flags); } =20 pr_debug2_peo(" =3D %d\n", fd); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 041b42d33bf5..8a545954eec7 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -152,7 +152,6 @@ struct evsel { struct bperf_leader_bpf *leader_skel; struct bperf_follower_bpf *follower_skel; }; - unsigned long open_flags; int precise_ip_original; =20 /* for missing_features */ --=20 2.31.1 From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E5C7C433EF for ; Fri, 25 Feb 2022 10:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239642AbiBYKg7 (ORCPT ); Fri, 25 Feb 2022 05:36:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239626AbiBYKgz (ORCPT ); Fri, 25 Feb 2022 05:36:55 -0500 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 25 Feb 2022 02:36:22 PST Received: from esa4.hc1455-7.c3s2.iphmx.com (esa4.hc1455-7.c3s2.iphmx.com [68.232.139.117]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C033A261496; Fri, 25 Feb 2022 02:36:22 -0800 (PST) IronPort-SDR: 8MKI5A8gydDt3U7+qbJAxgzYoqZuH1kTO8DhZGLVIp39wwnkW3Nl9K9g7XlQcTrnJUAyo0xqOT 3+cODv7kBIVCpLaEclJv5w38zw93VfSkPHnv7CAFKcGv2akX8g9gl8pfwhsbaEFsxK03CzsW1b KHcw5sHBKbucqMND3SCBEPO2XbJnG22kz+8D/fvq67oFSs6RKv93a4743GICEnyJbruesZDr/2 pv2WbUSxT8ckuR7ZV83cc9+k1X0yFiF3OLLwAiuL7D+uVLA20oZNLAixgXQuCdScS6FFBbTgXI WV5HJ2YudD3YtnxxrYIoP00J X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="64087259" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="64087259" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa4.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:16 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id E865AF625F; Fri, 25 Feb 2022 19:35:14 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 2AF7BDCD18; Fri, 25 Feb 2022 19:35:13 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 1198840124EEE; Fri, 25 Feb 2022 19:35:13 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 3/7] libperf: Add perf_evsel__refresh()/period() functions Date: Fri, 25 Feb 2022 19:31:10 +0900 Message-Id: <20220225103114.144239-4-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura Add the following functions: perf_evsel__refresh() perf_evsel__refresh_cpu() perf_evsel__period() perf_evsel__period_cpu() to set the over flow limit and period. Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/Documentation/libperf.txt | 5 ++ tools/lib/perf/evsel.c | 68 +++++++++++++++++++++--- tools/lib/perf/include/perf/evsel.h | 5 ++ tools/lib/perf/libperf.map | 4 ++ 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index 96a451cd34eb..8f523293fb9d 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -146,6 +146,11 @@ SYNOPSIS int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx); int perf_evsel__disable(struct perf_evsel *evsel); int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx); + int perf_evsel__refresh(struct perf_evsel *evsel, int refresh); + int perf_evsel__refresh_cpu(struct perf_evsel *evsel, int refresh, + int cpu_map_idx); + int perf_evsel__period(struct perf_evsel *evsel, int period); + int perf_evsel__period_cpu(struct perf_evsel *evsel, int period, int cpu= _map_idx); struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index d22b1468a1ad..8348545874e4 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -330,7 +330,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu_= map_idx, int thread, } =20 static int perf_evsel__run_ioctl(struct perf_evsel *evsel, - int ioc, void *arg, + int ioc, unsigned long arg, int cpu_map_idx) { int thread; @@ -353,7 +353,7 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evs= el, =20 int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, cpu_map_= idx); + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, cpu_map_idx= ); } =20 int perf_evsel__enable(struct perf_evsel *evsel) @@ -362,13 +362,13 @@ int perf_evsel__enable(struct perf_evsel *evsel) int err =3D 0; =20 for (i =3D 0; i < xyarray__max_x(evsel->fd) && !err; i++) - err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, i); + err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, i); return err; } =20 int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, cpu_map= _idx); + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, cpu_map_id= x); } =20 int perf_evsel__disable(struct perf_evsel *evsel) @@ -377,7 +377,63 @@ int perf_evsel__disable(struct perf_evsel *evsel) int err =3D 0; =20 for (i =3D 0; i < xyarray__max_x(evsel->fd) && !err; i++) - err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i); + err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, i); + return err; +} + +int perf_evsel__refresh_cpu(struct perf_evsel *evsel, int refresh, int cpu= _map_idx) +{ + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_REFRESH, refresh, cpu_= map_idx); +} + +int perf_evsel__refresh(struct perf_evsel *evsel, int refresh) +{ + int i; + int err =3D 0; + + for (i =3D 0; i < xyarray__max_x(evsel->fd) && !err; i++) + err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_REFRESH, refresh, i); + return err; +} + +int perf_evsel__period_cpu(struct perf_evsel *evsel, __u64 period, int cpu= _map_idx) +{ + int err =3D 0; + struct perf_event_attr *attr; + + err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD, + (unsigned long)&period, cpu_map_idx); + if (err) + return err; + + attr =3D perf_evsel__attr(evsel); + if (!attr) + return -1; + + attr->sample_period =3D period; + + return err; +} + +int perf_evsel__period(struct perf_evsel *evsel, __u64 period) +{ + int i; + int err =3D 0; + struct perf_event_attr *attr; + + for (i =3D 0; i < xyarray__max_x(evsel->fd) && !err; i++) { + err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD, + (unsigned long)&period, i); + if (err) + return err; + } + + attr =3D perf_evsel__attr(evsel); + if (!attr) + return -1; + + attr->sample_period =3D period; + return err; } =20 @@ -388,7 +444,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, = const char *filter) for (i =3D 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++) err =3D perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_SET_FILTER, - (void *)filter, i); + (unsigned long)filter, i); return err; } =20 diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index 23b0334a4c57..9ec24a5f5f9f 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -38,6 +38,11 @@ LIBPERF_API int perf_evsel__enable(struct perf_evsel *ev= sel); LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_m= ap_idx); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_= map_idx); +LIBPERF_API int perf_evsel__refresh(struct perf_evsel *evsel, int refresh); +LIBPERF_API int perf_evsel__refresh_cpu(struct perf_evsel *evsel, int refr= esh, + int cpu_map_idx); +LIBPERF_API int perf_evsel__period(struct perf_evsel *evsel, __u64 period); +LIBPERF_API int perf_evsel__period_cpu(struct perf_evsel *evsel, __u64 per= iod, int cpu_map_idx); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel= ); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel = *evsel); LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *ev= sel); diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 0f8d13f9009b..83ecbce9cfbb 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -28,6 +28,10 @@ LIBPERF_0.0.1 { perf_evsel__munmap; perf_evsel__mmap_base; perf_evsel__read; + perf_evsel__refresh; + perf_evsel__refresh_cpu; + perf_evsel__period; + perf_evsel__period_cpu; perf_evsel__cpus; perf_evsel__threads; perf_evsel__attr; --=20 2.31.1 From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9CA3C433F5 for ; Fri, 25 Feb 2022 10:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239649AbiBYKhJ (ORCPT ); Fri, 25 Feb 2022 05:37:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239643AbiBYKg7 (ORCPT ); Fri, 25 Feb 2022 05:36:59 -0500 X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 25 Feb 2022 02:36:25 PST Received: from esa12.hc1455-7.c3s2.iphmx.com (esa12.hc1455-7.c3s2.iphmx.com [139.138.37.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 118C929DD52; Fri, 25 Feb 2022 02:36:25 -0800 (PST) IronPort-SDR: DibmdeHjlOFNowuKLV0Dp7lXHcEDpQyJ4NvUNmqDBj1hIi7+CnKKzyNXNOQ+gv/KIdCclwwpjm 53I8KDKzrCvxp2BjCwiuRuIdYTnS6ueTLAy0VB/8rPMvlh6OnypTmbAvssj6umYJqQZnNZYBtE f22pCyFsIWDdMbHBwfPYX/tlZos1Vw0aM5LjMOAgDNtL+g7AffPRH1TMiL9Z6kVyJ64idsEDie opq24uZ7h5D54yPrzxCRPWxHGLtwBfQiJp7BOQ/uAo/0Q2WAoV9eOKwQcxpYuCBevhiVYhUhbW v1Gl6fvHgoogVkBsHuy0pXdA X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="43953260" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="43953260" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:18 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id D31A1F617A; Fri, 25 Feb 2022 19:35:17 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id DF49CD95E7; Fri, 25 Feb 2022 19:35:16 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id C8B9B40124EEE; Fri, 25 Feb 2022 19:35:16 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 4/7] libperf: Add perf_evsel__set_signal() functions Date: Fri, 25 Feb 2022 19:31:11 +0900 Message-Id: <20220225103114.144239-5-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura Add the following functions: perf_evsel__set_signal() perf_evsel__set_signal_cpu() to set the parameters to get the overflow signal. Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/Documentation/libperf.txt | 4 + tools/lib/perf/evsel.c | 105 +++++++++++++++++++++++ tools/lib/perf/include/perf/evsel.h | 6 ++ tools/lib/perf/libperf.map | 2 + 4 files changed, 117 insertions(+) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index 8f523293fb9d..d0aa57c6ca97 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -151,6 +151,10 @@ SYNOPSIS int cpu_map_idx); int perf_evsel__period(struct perf_evsel *evsel, int period); int perf_evsel__period_cpu(struct perf_evsel *evsel, int period, int cpu= _map_idx); + int perf_evsel__set_signal(struct perf_evsel *evsel, int owner_type, uns= igned int signal, + struct sigaction *sig); + int perf_evsel__set_signal_cpu(struct perf_evsel *evsel, int owner_type,= unsigned int signal, + struct sigaction *sig, int cpu_map_idx); struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 8348545874e4..991ab04112b1 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include #include #include @@ -16,6 +19,9 @@ #include #include #include +#include +#include +#include #include #include =20 @@ -351,6 +357,28 @@ static int perf_evsel__run_ioctl(struct perf_evsel *ev= sel, return 0; } =20 +static int perf_evsel__run_fcntl(struct perf_evsel *evsel, + unsigned int cmd, unsigned long arg, + int cpu_map_idx) +{ + int thread; + + for (thread =3D 0; thread < xyarray__max_y(evsel->fd); thread++) { + int err; + int *fd =3D FD(evsel, cpu_map_idx, thread); + + if (!fd || *fd < 0) + return -1; + + err =3D fcntl(*fd, cmd, arg); + + if (err) + return err; + } + + return 0; +} + int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, cpu_map_idx= ); @@ -437,6 +465,83 @@ int perf_evsel__period(struct perf_evsel *evsel, __u64= period) return err; } =20 +int perf_evsel__set_signal_cpu(struct perf_evsel *evsel, int owner_type, u= nsigned int signal, + struct sigaction *sig, int cpu_map_idx) +{ + int err =3D 0; + struct f_owner_ex owner; + + switch (owner_type) { + case F_OWNER_PID: + owner.pid =3D getpid(); + break; + case F_OWNER_TID: + owner.pid =3D syscall(SYS_gettid); + break; + default: + return -1; + } + + err =3D perf_evsel__run_fcntl(evsel, F_SETFL, (O_RDWR | O_NONBLOCK | O_AS= YNC), cpu_map_idx); + if (err) + return err; + + err =3D perf_evsel__run_fcntl(evsel, F_SETSIG, signal, cpu_map_idx); + if (err) + return err; + + err =3D perf_evsel__run_fcntl(evsel, F_SETOWN_EX, (unsigned long)&owner, = cpu_map_idx); + if (err) + return err; + + err =3D sigaction(signal, sig, NULL); + if (err) + return err; + + return err; +} + +int perf_evsel__set_signal(struct perf_evsel *evsel, int owner_type, unsig= ned int signal, + struct sigaction *sig) +{ + int i; + int err =3D 0; + struct f_owner_ex owner; + + switch (owner_type) { + case F_OWNER_PID: + owner.pid =3D getpid(); + break; + case F_OWNER_TID: + owner.pid =3D syscall(SYS_gettid); + break; + default: + return -1; + } + + owner.type =3D owner_type; + + for (i =3D 0; i < xyarray__max_x(evsel->fd) && !err; i++) { + err =3D perf_evsel__run_fcntl(evsel, F_SETFL, (O_RDWR | O_NONBLOCK | O_A= SYNC), i); + if (err) + return err; + + err =3D perf_evsel__run_fcntl(evsel, F_SETSIG, signal, i); + if (err) + return err; + + err =3D perf_evsel__run_fcntl(evsel, F_SETOWN_EX, (unsigned long)&owner,= i); + if (err) + return err; + } + + err =3D sigaction(signal, sig, NULL); + if (err) + return err; + + return err; +} + int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter) { int err =3D 0, i; diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index 9ec24a5f5f9f..15768fc91910 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -5,6 +5,7 @@ #include #include #include +#include #include =20 struct perf_evsel; @@ -43,6 +44,11 @@ LIBPERF_API int perf_evsel__refresh_cpu(struct perf_evse= l *evsel, int refresh, int cpu_map_idx); LIBPERF_API int perf_evsel__period(struct perf_evsel *evsel, __u64 period); LIBPERF_API int perf_evsel__period_cpu(struct perf_evsel *evsel, __u64 per= iod, int cpu_map_idx); +LIBPERF_API int perf_evsel__set_signal(struct perf_evsel *evsel, int owner= _type, + unsigned int signal, struct sigaction *sig); +LIBPERF_API int perf_evsel__set_signal_cpu(struct perf_evsel *evsel, int o= wner_type, + unsigned int signal, struct sigaction *sig, + int cpu_map_idx); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel= ); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel = *evsel); LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *ev= sel); diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 83ecbce9cfbb..5e04fe2b611c 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -32,6 +32,8 @@ LIBPERF_0.0.1 { perf_evsel__refresh_cpu; perf_evsel__period; perf_evsel__period_cpu; + perf_evsel__set_signal; + perf_evsel__set_signal_cpu; perf_evsel__cpus; perf_evsel__threads; perf_evsel__attr; --=20 2.31.1 From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84A0DC4332F for ; Fri, 25 Feb 2022 10:36:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239666AbiBYKhL (ORCPT ); Fri, 25 Feb 2022 05:37:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239647AbiBYKg7 (ORCPT ); Fri, 25 Feb 2022 05:36:59 -0500 Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D70F21CABC7; Fri, 25 Feb 2022 02:36:26 -0800 (PST) IronPort-SDR: gdPc5Vx/vHcn1NeOBHgSKjq6bJ+T3Oj9XzQjHlXElnaqVSpcAhBt/1lcxma32FsZyhAU0V8m0S I+ZgzJx4oZrhsvMU6F/2GtF1T4mU5mBI2MRPSOOlseIwDtjMnQ7OZJnO4BbPbQAtO0RtcPSqxm Wq+gh9ozTcts+GZGjn4Stntii4VIZV7lRHZ4avf2ZqHImu6mvvmFSs8bJanH6UX3V0W6/U8Pcd 0/Y3TRFKP+HPkAEs6o1BWc9t9BhyzThcNKDTuBMRPlZpgQ6c8ZhZGEygnEtBLw5e5DePe/1qNO 1uGYKB+ORVbnSuYnImfRIVV7 X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="64248459" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="64248459" Received: from unknown (HELO oym-r4.gw.nic.fujitsu.com) ([210.162.30.92]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:22 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 6E6DCE07E0; Fri, 25 Feb 2022 19:35:20 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 7E3C7D95E9; Fri, 25 Feb 2022 19:35:19 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 6833640124EEE; Fri, 25 Feb 2022 19:35:19 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 5/7] libperf: Add perf_evsel__check_fd() functions Date: Fri, 25 Feb 2022 19:31:12 +0900 Message-Id: <20220225103114.144239-6-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura Add the following functions: perf_evsel__check_fd() perf_evsel__check_fd_cpu() to check for perf events with the file descriptor specified in the argument. These functions can be used in signal handlers to detect overflow. Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/Documentation/libperf.txt | 2 ++ tools/lib/perf/evsel.c | 27 ++++++++++++++++++++++++ tools/lib/perf/include/perf/evsel.h | 2 ++ tools/lib/perf/libperf.map | 2 ++ 4 files changed, 33 insertions(+) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index d0aa57c6ca97..d3a1a9e77262 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -155,6 +155,8 @@ SYNOPSIS struct sigaction *sig); int perf_evsel__set_signal_cpu(struct perf_evsel *evsel, int owner_type,= unsigned int signal, struct sigaction *sig, int cpu_map_idx); + int perf_evsel__check_fd(struct perf_evsel *evsel, int sig_fd); + int perf_evsel__check_fd_cpu(struct perf_evsel *evsel, int cpu_map_idx, = int sig_fd); struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 991ab04112b1..0c626f846980 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -542,6 +542,33 @@ int perf_evsel__set_signal(struct perf_evsel *evsel, i= nt owner_type, unsigned in return err; } =20 +int perf_evsel__check_fd_cpu(struct perf_evsel *evsel, int cpu_map_idx, in= t sig_fd) +{ + int thread; + int *fd; + + for (thread =3D 0; thread < xyarray__max_y(evsel->fd); ++thread) { + fd =3D FD(evsel, cpu_map_idx, thread); + if (sig_fd <=3D 0 || !fd || *fd < 0) + return -1; + + if (sig_fd =3D=3D *fd) + return 0; + } + + return -1; +} + +int perf_evsel__check_fd(struct perf_evsel *evsel, int sig_fd) +{ + int i; + int err =3D 0; + + for (i =3D 0; i < xyarray__max_x(evsel->fd); i++) + err =3D perf_evsel__check_fd_cpu(evsel, i, sig_fd); + return err; +} + int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter) { int err =3D 0, i; diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index 15768fc91910..5d4b4912fec9 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -49,6 +49,8 @@ LIBPERF_API int perf_evsel__set_signal(struct perf_evsel = *evsel, int owner_type, LIBPERF_API int perf_evsel__set_signal_cpu(struct perf_evsel *evsel, int o= wner_type, unsigned int signal, struct sigaction *sig, int cpu_map_idx); +LIBPERF_API int perf_evsel__check_fd(struct perf_evsel *evsel, int sig_fd); +LIBPERF_API int perf_evsel__check_fd_cpu(struct perf_evsel *evsel, int cpu= _map_idx, int sig_fd); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel= ); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel = *evsel); LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *ev= sel); diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 5e04fe2b611c..edd60bc69822 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -34,6 +34,8 @@ LIBPERF_0.0.1 { perf_evsel__period_cpu; perf_evsel__set_signal; perf_evsel__set_signal_cpu; + perf_evsel__check_fd; + perf_evsel__check_fd_cpu; perf_evsel__cpus; perf_evsel__threads; perf_evsel__attr; --=20 2.31.1 From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ECBDC433F5 for ; Fri, 25 Feb 2022 10:36:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239672AbiBYKhO (ORCPT ); Fri, 25 Feb 2022 05:37:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239654AbiBYKhJ (ORCPT ); Fri, 25 Feb 2022 05:37:09 -0500 Received: from esa12.hc1455-7.c3s2.iphmx.com (esa12.hc1455-7.c3s2.iphmx.com [139.138.37.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EF161CABD2; Fri, 25 Feb 2022 02:36:27 -0800 (PST) IronPort-SDR: ++KFWPclbV2kMtWtx6h5gXaoRNZ5CNWAsx9OQN6dnscnI07H2JC2xbwghZuVI6jhgPhzOJqtSw oB24CwXUnzk8oeQf0qhDz9gqq2AeTpDlXQy9lZyEFyO8wCTEgiw2L6jaWiy8n6FUUrQu5MO8sp Kh67xFDrxCSvJ+IdAJppBSvr5xzQ0idwqcpB4TqGbS/lJHgRUGWPTNYRP1hzg+38yFD/pA7NAz POYgStWCzk9xMfJyY5o5MG/SSXpygwcBzv23PUdJzRvS5/Vg2G+iDe7695bLjdajTmn0z7f47b bRe47eq0WDruQzzMDn5kxSTP X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="43953277" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="43953277" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:23 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id F356CC9165; Fri, 25 Feb 2022 19:35:22 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 47D15141E9; Fri, 25 Feb 2022 19:35:21 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id 4106F40124EF0; Fri, 25 Feb 2022 19:35:21 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 6/7] libperf test: Add test_stat_overflow() Date: Fri, 25 Feb 2022 19:31:13 +0900 Message-Id: <20220225103114.144239-7-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura Added tests using refresh and period. Confirmation - That the overflow occurs the number of times specified by perf_evse__refresh() - That the period can be updated by perf_evsel__period() Committer testing: $ sudo make tests -C tools/lib/perf/ V=3D1 make: Entering directory '/home/nakamura/build_work/build_kernel/linux-ke= rnel/linux/tools/lib/perf' make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D. obj=3Dlibperf make -C /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/l= ib/api/ O=3D libapi.a make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D./fd obj=3Dlibapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D./fs obj=3Dlibapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D. obj=3Dtests make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D./tests obj=3Dtests running static: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... OK - running tests/test-evsel.c... loop =3D 65536, count =3D 330818 loop =3D 131072, count =3D 662958 loop =3D 262144, count =3D 1316088 loop =3D 524288, count =3D 2632699 loop =3D 1048576, count =3D 5254501 loop =3D 65536, count =3D 348709 loop =3D 131072, count =3D 694239 loop =3D 262144, count =3D 1370888 loop =3D 524288, count =3D 2744824 loop =3D 1048576, count =3D 5465047 period =3D 1000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 period =3D 2000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 period =3D 1000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 period =3D 2000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 OK running dynamic: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... OK - running tests/test-evsel.c... loop =3D 65536, count =3D 330819 loop =3D 131072, count =3D 662959 loop =3D 262144, count =3D 1323589 loop =3D 524288, count =3D 2626809 loop =3D 1048576, count =3D 5260090 loop =3D 65536, count =3D 351641 loop =3D 131072, count =3D 697661 loop =3D 262144, count =3D 1373234 loop =3D 524288, count =3D 2743662 loop =3D 1048576, count =3D 5473195 period =3D 1000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 period =3D 2000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 period =3D 1000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 period =3D 2000000 overflow limit =3D 3, overflow count =3D 3POLL_IN =3D 2, POLL_UP = =3D 1, other signal event =3D 0 OK make: Leaving directory '/home/nakamura/build_work/build_kernel/linux-ker= nel/linux/tools/lib/perf' Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/tests/test-evsel.c | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/tools/lib/perf/tests/test-evsel.c b/tools/lib/perf/tests/test-= evsel.c index 89be89afb24d..9232b2f25082 100644 --- a/tools/lib/perf/tests/test-evsel.c +++ b/tools/lib/perf/tests/test-evsel.c @@ -1,6 +1,14 @@ // SPDX-License-Identifier: GPL-2.0 +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include #include #include +#include +#include +#include +#include #include #include #include @@ -8,6 +16,15 @@ #include #include "tests.h" =20 +#define WAIT_COUNT 10000000UL +static struct signal_counts { + int in; + int hup; + int others; + int overflow; +} sig_count =3D {0, 0, 0}; +static struct perf_evsel *s_evsel; + static int libperf_print(enum libperf_print_level level, const char *fmt, va_list ap) { @@ -189,6 +206,97 @@ static int test_stat_user_read(int event) return 0; } =20 +static void sig_handler(int signo, siginfo_t *info, void *uc) +{ + switch (info->si_code) { + case POLL_IN: + sig_count.in++; + break; + case POLL_HUP: + sig_count.hup++; + break; + default: + sig_count.others++; + } + + sig_count.overflow++; +} + +static int test_stat_refresh(int owner) +{ + static struct sigaction sig; + u64 period =3D 1000000; + int overflow_limit =3D 3; + + struct perf_thread_map *threads; + struct perf_event_attr attr =3D { + .type =3D PERF_TYPE_SOFTWARE, + .config =3D PERF_COUNT_SW_TASK_CLOCK, + .sample_type =3D PERF_SAMPLE_PERIOD, + .sample_period =3D period, + .disabled =3D 1, + }; + struct perf_event_attr *tmp_attr; + int err, i; + unsigned int wait_count; + + /* setup signal handler */ + memset(&sig, 0, sizeof(struct sigaction)); + sig.sa_sigaction =3D (void *)sig_handler; + sig.sa_flags =3D SA_SIGINFO; + + threads =3D perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + s_evsel =3D perf_evsel__new(&attr); + __T("failed to create evsel", s_evsel); + + err =3D perf_evsel__set_close_on_exec(s_evsel); + __T("failed to set PERF_FLAG_FD_CLOEXEC flag to evsel", err =3D=3D 0); + + err =3D perf_evsel__open(s_evsel, NULL, threads); + __T("failed to open evsel", err =3D=3D 0); + + err =3D perf_evsel__set_signal(s_evsel, owner, SIGIO, &sig); + __T("failed to set signal", err =3D=3D 0); + + for (i =3D 0; i < 2; i++) { + period =3D period << i; + err =3D perf_evsel__period(s_evsel, period); + __T("failed to period evsel", err =3D=3D 0); + + tmp_attr =3D perf_evsel__attr(s_evsel); + __T_VERBOSE("\tperiod =3D %llu\n", tmp_attr->sample_period); + + err =3D perf_evsel__refresh(s_evsel, overflow_limit); + __T("failed to refresh evsel", err =3D=3D 0); + + wait_count =3D WAIT_COUNT; + while (wait_count--) + ; + + __T_VERBOSE("\toverflow limit =3D %d, overflow count =3D %d", + overflow_limit, sig_count.overflow); + __T_VERBOSE("POLL_IN =3D %d, POLL_UP =3D %d, other signal event =3D %d\n= ", + sig_count.in, sig_count.hup, sig_count.others); + + __T("failed to overflow count", overflow_limit =3D=3D sig_count.overflow= ); + + sig_count.in =3D 0; + sig_count.hup =3D 0; + sig_count.others =3D 0; + sig_count.overflow =3D 0; + } + + perf_evsel__close(s_evsel); + perf_evsel__delete(s_evsel); + perf_thread_map__put(threads); + + return 0; +} + int test_evsel(int argc, char **argv) { __T_START; @@ -200,6 +308,8 @@ int test_evsel(int argc, char **argv) test_stat_thread_enable(); test_stat_user_read(PERF_COUNT_HW_INSTRUCTIONS); test_stat_user_read(PERF_COUNT_HW_CPU_CYCLES); + test_stat_refresh(F_OWNER_PID); + test_stat_refresh(F_OWNER_TID); =20 __T_END; return tests_failed =3D=3D 0 ? 0 : -1; --=20 2.31.1 From nobody Tue Jun 23 22:32:38 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BCFDC433F5 for ; Fri, 25 Feb 2022 10:36:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239657AbiBYKhY (ORCPT ); Fri, 25 Feb 2022 05:37:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239654AbiBYKhT (ORCPT ); Fri, 25 Feb 2022 05:37:19 -0500 X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 25 Feb 2022 02:36:31 PST Received: from esa10.hc1455-7.c3s2.iphmx.com (esa10.hc1455-7.c3s2.iphmx.com [139.138.36.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE0D1706B; Fri, 25 Feb 2022 02:36:31 -0800 (PST) IronPort-SDR: ZG0eaNRQY9wW3i5IvIav1d/iCpl9u9sfW+DHk3LK7dvewajofUNyfmsrQXzobHmKXBemvQ2/zs c3IDjSZsQv35SI9SPnzAZrNOlQVTwJVw1vJJvunmMaQWQ8iY5jKtMWQTYNIfQlw1d0Io6ig3WY yydeWBdJcRirQvXPg3jUGt4X4q4xoec6oZ0ud6f3Ubjzs2RABXSP6S8DKpCmGMXNuaxLQGLkM2 fTx4uLGCIQWgA9kvaxp5fmmewOP05BsqSOWWaAlFBv0WlDCQbIygJqtbpXAJdrX2orLI6LQRiM DYSgC7JuMiYy0opmTaP0sWwo X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="52058638" X-IronPort-AV: E=Sophos;i="5.90,136,1643641200"; d="scan'208";a="52058638" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa10.hc1455-7.c3s2.iphmx.com with ESMTP; 25 Feb 2022 19:35:24 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id DF8FBCA240; Fri, 25 Feb 2022 19:35:23 +0900 (JST) Received: from yto-om3.fujitsu.com (yto-om3.o.css.fujitsu.com [10.128.89.164]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id ED662D99E7; Fri, 25 Feb 2022 19:35:22 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by yto-om3.fujitsu.com (Postfix) with ESMTP id D5E0D40124EF0; Fri, 25 Feb 2022 19:35:22 +0900 (JST) From: Shunsuke To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Shunsuke Nakamura Subject: [RFC PATCH 7/7] libperf test: Add test_detect_overflow_event() Date: Fri, 25 Feb 2022 19:31:14 +0900 Message-Id: <20220225103114.144239-8-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225103114.144239-1-nakamura.shun@fujitsu.com> References: <20220225103114.144239-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shunsuke Nakamura Add a test to detect overflowed events. Committer testing: $ sudo make tests -C tools/lib/perf/ V=3D1 make: Entering directory '/home/nakamura/build_work/build_kernel/linux-ke= rnel/linux/tools/lib/perf' make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D. obj=3Dlibperf make -C /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/l= ib/api/ O=3D libapi.a make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D./fd obj=3Dlibapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D./fs obj=3Dlibapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D. obj=3Dtests make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/b= uild/Makefile.build dir=3D./tests obj=3Dtests running static: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... Event 0 -- overflow flag =3D 0x1, POLL_UP =3D 1, other signal event =3D 0 Event 1 -- overflow flag =3D 0x2, POLL_UP =3D 1, other signal event =3D 0 Event 2 -- overflow flag =3D 0x4, POLL_UP =3D 1, other signal event =3D 0 Event 3 -- overflow flag =3D 0x8, POLL_UP =3D 1, other signal event =3D 0 OK - running tests/test-evsel.c... OK running dynamic: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... Event 0 -- overflow flag =3D 0x1, POLL_UP =3D 1, other signal event =3D 0 Event 1 -- overflow flag =3D 0x2, POLL_UP =3D 1, other signal event =3D 0 Event 2 -- overflow flag =3D 0x4, POLL_UP =3D 1, other signal event =3D 0 Event 3 -- overflow flag =3D 0x8, POLL_UP =3D 1, other signal event =3D 0 OK - running tests/test-evsel.c... OK make: Leaving directory '/home/nakamura/build_work/build_kernel/linux-ker= nel/linux/tools/lib/perf' Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/tests/test-evlist.c | 119 +++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test= -evlist.c index fafc6b0f8687..c0f0109c8b51 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -24,6 +26,13 @@ #define EVENT_NUM 15 #define WAIT_COUNT 100000000UL =20 +static unsigned int overflow_flag; +static struct signal_counts { + int hup; + int others; +} sig_count =3D { 0, 0 }; +static struct perf_evlist *s_evlist; + static int libperf_print(enum libperf_print_level level, const char *fmt, va_list ap) { @@ -570,6 +579,115 @@ static int test_stat_multiplexing(void) return 0; } =20 +static void sig_handler(int signo, siginfo_t *info, void *uc) +{ + int err; + int idx =3D 0; + struct perf_evsel *evsel; + + switch (info->si_code) { + case POLL_HUP: + perf_evlist__for_each_evsel(s_evlist, evsel) { + err =3D perf_evsel__check_fd(evsel, info->si_fd); + if (!err) { + overflow_flag =3D (1U << idx); + sig_count.hup++; + break; + } + idx++; + } + break; + default: + perf_evlist__for_each_evsel(s_evlist, evsel) { + err =3D perf_evsel__check_fd(evsel, info->si_fd); + if (!err) { + overflow_flag =3D (1U << idx); + sig_count.others++; + break; + } + idx++; + } + } +} + +static int test_stat_overflow_event(void) +{ + static struct sigaction sig; + + struct perf_thread_map *threads; + struct perf_evsel *evsel; + struct perf_event_attr attr =3D { + .type =3D PERF_TYPE_SOFTWARE, + .config =3D PERF_COUNT_SW_CPU_CLOCK, + .sample_type =3D PERF_SAMPLE_PERIOD, + .sample_period =3D 100000, + .disabled =3D 1, + }; + int err, i, event_num =3D 4; + unsigned int wait_count; + + /* setup signal handler */ + memset(&sig, 0, sizeof(struct sigaction)); + sig.sa_sigaction =3D (void *)sig_handler; + sig.sa_flags =3D SA_SIGINFO; + + threads =3D perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + s_evlist =3D perf_evlist__new(); + __T("failed to create evlist", s_evlist); + + for (i =3D 0; i < event_num; i++) { + evsel =3D perf_evsel__new(&attr); + __T("failed to create evsel", evsel); + + err =3D perf_evsel__set_close_on_exec(evsel); + __T("failed to set PERF_FLAG_FD_CLOEXEC flag to evsel", err =3D=3D 0); + + perf_evlist__add(s_evlist, evsel); + } + + perf_evlist__set_maps(s_evlist, NULL, threads); + + err =3D perf_evlist__open(s_evlist); + __T("failed to open evlist", err =3D=3D 0); + + i =3D 0; + perf_evlist__for_each_evsel(s_evlist, evsel) { + err =3D perf_evsel__set_signal(evsel, F_OWNER_PID, SIGIO, &sig); + __T("failed to set signal", err =3D=3D 0); + + err =3D perf_evsel__refresh(evsel, 1); + __T("failed to refresh evsel", err =3D=3D 0); + + wait_count =3D WAIT_COUNT; + while (wait_count--) + ; + + __T_VERBOSE("Event %2d -- overflow flag =3D %#x, ", + i, overflow_flag); + __T_VERBOSE("POLL_UP =3D %d, other signal event =3D %d\n", + sig_count.hup, sig_count.others); + + __T("unexpected event overflow detected", overflow_flag && (1U << i)); + __T("unexpected signal event detected", + sig_count.hup =3D=3D 1 && sig_count.others =3D=3D 0); + + overflow_flag =3D 0; + sig_count.hup =3D 0; + sig_count.others =3D 0; + i++; + } + + perf_evlist__close(s_evlist); + perf_evlist__delete(s_evlist); + perf_thread_map__put(threads); + + return 0; +} + int test_evlist(int argc, char **argv) { __T_START; @@ -582,6 +700,7 @@ int test_evlist(int argc, char **argv) test_mmap_thread(); test_mmap_cpus(); test_stat_multiplexing(); + test_stat_overflow_event(); =20 __T_END; return tests_failed =3D=3D 0 ? 0 : -1; --=20 2.31.1