2022-03-25 19:07:47

by [email protected]

[permalink] [raw]
Subject: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events

This patch series adds interface for overflow check of sampling events
to libperf.

First patch fixes a typo in the error message that I noticed.

Second patch move 'open_flags' from tools/perf to evsel::open_flags.

Third patch adds a interface to perform IOC_REFRESH and IOC_PERIOD.

Fourth patch introduce perf_{evsel, evlist}__open_opt() with extensible
structure opts.

Fifth patch adds a interface to check overflowed events.

Sixth and seventh patch adds tests.

---
Previous version at:
https://lore.kernel.org/linux-perf-users/[email protected]/

Changes in v2:
- Delete perf_evsel__set_close_on_exec() function
- Introduce perf_{evsel, evlist}__open_opt() with extensible structure
opts
- Fix perf_evsel__set_signal() to a internal function
- Add bool type argument to perf_evsel__check_{fd, fd_cpu}() to indicate
overflow results


Shunsuke Nakamura (7):
libperf tests: Fix typo in the error message
libperf: Move 'open_flags' from tools/perf to evsel::open_flags
libperf: Add perf_evsel__{refresh, period}() functions
libperf: Introduce perf_{evsel, evlist}__open_opt with extensible
struct opts
libperf: Add perf_evsel__check_overflow() functions
libperf test: Add test_stat_overflow()
libperf test: Add test_stat_overflow_event()

tools/lib/perf/Documentation/libperf.txt | 22 +++
tools/lib/perf/evlist.c | 20 +++
tools/lib/perf/evsel.c | 210 ++++++++++++++++++++++-
tools/lib/perf/include/internal/evsel.h | 2 +
tools/lib/perf/include/perf/evlist.h | 3 +
tools/lib/perf/include/perf/evsel.h | 35 ++++
tools/lib/perf/internal.h | 44 +++++
tools/lib/perf/libperf.map | 8 +
tools/lib/perf/tests/test-evlist.c | 135 ++++++++++++++-
tools/lib/perf/tests/test-evsel.c | 111 ++++++++++++
tools/perf/util/evsel.c | 16 +-
tools/perf/util/evsel.h | 1 -
12 files changed, 588 insertions(+), 19 deletions(-)

--
2.25.1


2022-03-25 19:57:46

by [email protected]

[permalink] [raw]
Subject: [RFC PATCH v2 3/7] libperf: Add perf_evsel__{refresh, period}() functions

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 <[email protected]>
---
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/Documentation/libperf.txt
index 32c5051c24eb..ae55e62fc4ce 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 6640a333e6d9..b17842581dea 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,
}

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 *evsel,

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);
}

int perf_evsel__enable(struct perf_evsel *evsel)
@@ -362,13 +362,13 @@ int perf_evsel__enable(struct perf_evsel *evsel)
int err = 0;

for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
- err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, i);
+ err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, i);
return err;
}

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_idx);
}

int perf_evsel__disable(struct perf_evsel *evsel)
@@ -377,7 +377,63 @@ int perf_evsel__disable(struct perf_evsel *evsel)
int err = 0;

for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
- err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i);
+ err = 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 = 0;
+
+ for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
+ err = 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)
+{
+ struct perf_event_attr *attr;
+ int err = 0;
+
+ attr = perf_evsel__attr(evsel);
+ if (!attr)
+ return -EINVAL;
+
+ err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
+ (unsigned long)&period, cpu_map_idx);
+ if (err)
+ return err;
+
+ attr->sample_period = period;
+
+ return err;
+}
+
+int perf_evsel__period(struct perf_evsel *evsel, __u64 period)
+{
+ struct perf_event_attr *attr;
+ int i;
+ int err = 0;
+
+ attr = perf_evsel__attr(evsel);
+ if (!attr)
+ return -EINVAL;
+
+ for (i = 0; i < xyarray__max_x(evsel->fd); i++) {
+ err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
+ (unsigned long)&period, i);
+ if (err)
+ return err;
+ }
+
+ attr->sample_period = period;
+
return err;
}

@@ -388,7 +444,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
for (i = 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++)
err = perf_evsel__run_ioctl(evsel,
PERF_EVENT_IOC_SET_FILTER,
- (void *)filter, i);
+ (unsigned long)filter, i);
return err;
}

diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h
index 2a9516b42d15..360ced734add 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 *evsel);
LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_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 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 period, 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 *evsel);
diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map
index 6fa0d651576b..ab0f44e9bb57 100644
--- a/tools/lib/perf/libperf.map
+++ b/tools/lib/perf/libperf.map
@@ -29,6 +29,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;
--
2.25.1

2022-03-25 19:59:27

by [email protected]

[permalink] [raw]
Subject: [RFC PATCH v2 6/7] libperf test: Add test_stat_overflow()

Added overflow test 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=1
make: Entering directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf'
make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=libperf
make -C /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/api/ O= libapi.a
make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fd obj=libapi
make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fs obj=libapi
make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=tests
make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./tests obj=tests
running static:
- running tests/test-cpumap.c...OK
- running tests/test-threadmap.c...OK
- running tests/test-evlist.c...

<SNIP>

OK
- running tests/test-evsel.c...

<SNIP>

period = 1000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
period = 2000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
period = 1000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
period = 2000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
OK
running dynamic:
- running tests/test-cpumap.c...OK
- running tests/test-threadmap.c...OK
- running tests/test-evlist.c...

<SNIP>

OK
- running tests/test-evsel.c...

<SNIP>

period = 1000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
period = 2000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
period = 1000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
period = 2000000
overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_UP = 1, other signal event = 0
OK
make: Leaving directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf'

Signed-off-by: Shunsuke Nakamura <[email protected]>
---
tools/lib/perf/tests/test-evsel.c | 111 ++++++++++++++++++++++++++++++
1 file changed, 111 insertions(+)

diff --git a/tools/lib/perf/tests/test-evsel.c b/tools/lib/perf/tests/test-evsel.c
index 89be89afb24d..8e7cf336fcd7 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 <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <fcntl.h>
#include <linux/perf_event.h>
#include <perf/cpumap.h>
#include <perf/threadmap.h>
@@ -8,6 +16,15 @@
#include <internal/tests.h>
#include "tests.h"

+#define WAIT_COUNT 10000000UL
+static struct signal_counts {
+ int in;
+ int hup;
+ int others;
+ int overflow;
+} sig_count = {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,98 @@ static int test_stat_user_read(int event)
return 0;
}

+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_overflow(int owner)
+{
+ static struct sigaction sig;
+ u64 period = 1000000;
+ int overflow_limit = 3;
+
+ struct perf_thread_map *threads;
+ struct perf_event_attr attr = {
+ .type = PERF_TYPE_SOFTWARE,
+ .config = PERF_COUNT_SW_TASK_CLOCK,
+ .sample_type = PERF_SAMPLE_PERIOD,
+ .sample_period = period,
+ .disabled = 1,
+ };
+ struct perf_event_attr *tmp_attr;
+ int err = 0, i;
+
+ LIBPERF_OPTS(perf_evsel_open_opts, opts,
+ .open_flags = PERF_FLAG_FD_CLOEXEC,
+ .flags = (O_RDWR | O_NONBLOCK | O_ASYNC),
+ .signal = SIGIO,
+ .owner_type = owner,
+ .sig = &sig);
+
+ /* setup signal handler */
+ memset(&sig, 0, sizeof(struct sigaction));
+ sig.sa_sigaction = (void *)sig_handler;
+ sig.sa_flags = SA_SIGINFO;
+
+ threads = perf_thread_map__new_dummy();
+ __T("failed to create threads", threads);
+
+ perf_thread_map__set_pid(threads, 0, 0);
+
+ s_evsel = perf_evsel__new(&attr);
+ __T("failed to create evsel", s_evsel);
+
+ err = perf_evsel__open_opts(s_evsel, NULL, threads, &opts);
+ __T("failed to open evsel", err == 0);
+
+ for (i = 0; i < 2; i++) {
+ volatile unsigned int wait_count = WAIT_COUNT;
+
+ period = period << i;
+ err = perf_evsel__period(s_evsel, period);
+ __T("failed to period evsel", err == 0);
+
+ tmp_attr = perf_evsel__attr(s_evsel);
+ __T_VERBOSE("\tperiod = %llu\n", tmp_attr->sample_period);
+
+ err = perf_evsel__refresh(s_evsel, overflow_limit);
+ __T("failed to refresh evsel", err == 0);
+
+ while (wait_count--)
+ ;
+
+ __T_VERBOSE("\toverflow limit = %d, overflow count = %d, ",
+ overflow_limit, sig_count.overflow);
+ __T_VERBOSE("POLL_IN = %d, POLL_UP = %d, other signal event = %d\n",
+ sig_count.in, sig_count.hup, sig_count.others);
+
+ __T("failed to overflow count", overflow_limit == sig_count.overflow);
+
+ sig_count.in = 0;
+ sig_count.hup = 0;
+ sig_count.others = 0;
+ sig_count.overflow = 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 +309,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_overflow(F_OWNER_PID);
+ test_stat_overflow(F_OWNER_TID);

__T_END;
return tests_failed == 0 ? 0 : -1;
--
2.25.1

2022-03-31 03:45:38

by Jiri Olsa

[permalink] [raw]
Subject: Re: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events

On Fri, Mar 25, 2022 at 01:38:22PM +0900, Shunsuke Nakamura wrote:
> This patch series adds interface for overflow check of sampling events
> to libperf.
>
> First patch fixes a typo in the error message that I noticed.
>
> Second patch move 'open_flags' from tools/perf to evsel::open_flags.
>
> Third patch adds a interface to perform IOC_REFRESH and IOC_PERIOD.
>
> Fourth patch introduce perf_{evsel, evlist}__open_opt() with extensible
> structure opts.
>
> Fifth patch adds a interface to check overflowed events.
>
> Sixth and seventh patch adds tests.
>
> ---
> Previous version at:
> https://lore.kernel.org/linux-perf-users/[email protected]/
>
> Changes in v2:
> - Delete perf_evsel__set_close_on_exec() function
> - Introduce perf_{evsel, evlist}__open_opt() with extensible structure
> opts
> - Fix perf_evsel__set_signal() to a internal function
> - Add bool type argument to perf_evsel__check_{fd, fd_cpu}() to indicate
> overflow results

looks good.. it got more clear to me, sending some comments


>
>
> Shunsuke Nakamura (7):
> libperf tests: Fix typo in the error message
> libperf: Move 'open_flags' from tools/perf to evsel::open_flags
> libperf: Add perf_evsel__{refresh, period}() functions
> libperf: Introduce perf_{evsel, evlist}__open_opt with extensible
> struct opts
> libperf: Add perf_evsel__check_overflow() functions
> libperf test: Add test_stat_overflow()
> libperf test: Add test_stat_overflow_event()

I'm getting:

[root@krava perf]# make tests
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...FAILED tests/test-evsel.c:286 failed to overflow count
FAILED tests/test-evsel.c:286 failed to overflow count
FAILED (2)
FAILED tests/main.c:13 test evsel
make: *** [Makefile:162: tests] Error 255

thanks,
jirka

>
> tools/lib/perf/Documentation/libperf.txt | 22 +++
> tools/lib/perf/evlist.c | 20 +++
> tools/lib/perf/evsel.c | 210 ++++++++++++++++++++++-
> tools/lib/perf/include/internal/evsel.h | 2 +
> tools/lib/perf/include/perf/evlist.h | 3 +
> tools/lib/perf/include/perf/evsel.h | 35 ++++
> tools/lib/perf/internal.h | 44 +++++
> tools/lib/perf/libperf.map | 8 +
> tools/lib/perf/tests/test-evlist.c | 135 ++++++++++++++-
> tools/lib/perf/tests/test-evsel.c | 111 ++++++++++++
> tools/perf/util/evsel.c | 16 +-
> tools/perf/util/evsel.h | 1 -
> 12 files changed, 588 insertions(+), 19 deletions(-)
>
> --
> 2.25.1
>

2022-03-31 04:45:55

by Jiri Olsa

[permalink] [raw]
Subject: Re: [RFC PATCH v2 3/7] libperf: Add perf_evsel__{refresh, period}() functions

On Fri, Mar 25, 2022 at 01:38:25PM +0900, Shunsuke Nakamura wrote:

SNIP

> +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 = 0;
> +
> + for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
> + err = 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)
> +{
> + struct perf_event_attr *attr;
> + int err = 0;
> +
> + attr = perf_evsel__attr(evsel);
> + if (!attr)
> + return -EINVAL;
> +
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
> + (unsigned long)&period, cpu_map_idx);
> + if (err)
> + return err;
> +
> + attr->sample_period = period;

what's the point in updating attr? this will be used after
event is created right?

> +
> + return err;
> +}
> +
> +int perf_evsel__period(struct perf_evsel *evsel, __u64 period)
> +{
> + struct perf_event_attr *attr;
> + int i;
> + int err = 0;
> +
> + attr = perf_evsel__attr(evsel);
> + if (!attr)
> + return -EINVAL;
> +
> + for (i = 0; i < xyarray__max_x(evsel->fd); i++) {
> + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
> + (unsigned long)&period, i);
> + if (err)
> + return err;
> + }
> +
> + attr->sample_period = period;

same as above

thanks,
jirka

> +
> return err;
> }
>

SNIP

2022-04-12 03:20:04

by [email protected]

[permalink] [raw]
Subject: RE: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events

Hi jirka

Sorry for the late reply.

> >
> > Shunsuke Nakamura (7):
> > libperf tests: Fix typo in the error message
> > libperf: Move 'open_flags' from tools/perf to evsel::open_flags
> > libperf: Add perf_evsel__{refresh, period}() functions
> > libperf: Introduce perf_{evsel, evlist}__open_opt with extensible
> > struct opts
> > libperf: Add perf_evsel__check_overflow() functions
> > libperf test: Add test_stat_overflow()
> > libperf test: Add test_stat_overflow_event()
>
> I'm getting:
>
> [root@krava perf]# make tests
> 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...FAILED tests/test-evsel.c:286 failed to overflow
> count FAILED tests/test-evsel.c:286 failed to overflow count
> FAILED (2)
> FAILED tests/main.c:13 test evsel
> make: *** [Makefile:162: tests] Error 255
>
Thanks for telling me.
However, we could not reproduce the test failure in our environment.
Could you please tell me the results of your test with the addition of V=1?


Best Regards
Shunsuke

2022-04-12 21:07:49

by [email protected]

[permalink] [raw]
Subject: RE: [RFC PATCH v2 3/7] libperf: Add perf_evsel__{refresh, period}() functions

Hi jirka

> On Fri, Mar 25, 2022 at 01:38:25PM +0900, Shunsuke Nakamura wrote:
>
> SNIP
>
> > +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 = 0;
> > +
> > + for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++)
> > + err = 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) {
> > + struct perf_event_attr *attr;
> > + int err = 0;
> > +
> > + attr = perf_evsel__attr(evsel);
> > + if (!attr)
> > + return -EINVAL;
> > +
> > + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD,
> > + (unsigned long)&period, cpu_map_idx);
> > + if (err)
> > + return err;
> > +
> > + attr->sample_period = period;
>
> what's the point in updating attr? this will be used after event is created right?
>
This is to maintain consistency between evsel->attr->sample_period and the sample_period of the created event.
Users can reference evsel->attr->sample_period using perf_evsel__attr().
So I thought it was necessary to update the sample_period of the event and the sample_period of evsel to avoid discrepancies.


Best Regards
Shunsuke

2022-04-21 21:23:34

by [email protected]

[permalink] [raw]
Subject: RE: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events

Hi jirka

> On Mon, Apr 11, 2022 at 08:23:54AM +0000, [email protected] wrote:
> > Hi jirka
> >
> > Sorry for the late reply.
> >
> > > >
> > > > Shunsuke Nakamura (7):
> > > > libperf tests: Fix typo in the error message
> > > > libperf: Move 'open_flags' from tools/perf to evsel::open_flags
> > > > libperf: Add perf_evsel__{refresh, period}() functions
> > > > libperf: Introduce perf_{evsel, evlist}__open_opt with extensible
> > > > struct opts
> > > > libperf: Add perf_evsel__check_overflow() functions
> > > > libperf test: Add test_stat_overflow()
> > > > libperf test: Add test_stat_overflow_event()
> > >
> > > I'm getting:
> > >
> > > [root@krava perf]# make tests
> > > 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...FAILED tests/test-evsel.c:286 failed
> > > to overflow count FAILED tests/test-evsel.c:286 failed to overflow count
> > > FAILED (2)
> > > FAILED tests/main.c:13 test evsel
> > > make: *** [Makefile:162: tests] Error 255
> > >
> > Thanks for telling me.
> > However, we could not reproduce the test failure in our environment.
> > Could you please tell me the results of your test with the addition of V=1?
>
> sorry, forgot to answer this one..
>
Thanks for the information.


> [root@krava perf]# LD_LIBRARY_PATH=. ./tests-shared -v
> - running tests/test-cpumap.c...OK
> - running tests/test-threadmap.c...OK
> - running tests/test-evlist.c...
> Event 0 -- Raw count = 231217013, run = 10196083, enable = 22183091
> Scaled count = 503046909 (45.96%, 10196083/22183091) Event 1 --
> Raw count = 247219790, run = 10946246, enable = 22182044
> Scaled count = 500979080 (49.35%, 10946246/22182044) Event 2 --
> Raw count = 268999685, run = 11943490, enable = 22180868
> Scaled count = 499573115 (53.85%, 11943490/22180868) Event 3 --
> Raw count = 291383974, run = 12941069, enable = 22179798
> Scaled count = 499405241 (58.35%, 12941069/22179798) Event 4 --
> Raw count = 314293846, run = 13938576, enable = 22178649
> Scaled count = 500095052 (62.85%, 13938576/22178649) Event 5 --
> Raw count = 337393782, run = 14935798, enable = 22177192
> Scaled count = 500974014 (67.35%, 14935798/22177192) Event 6 --
> Raw count = 360218294, run = 15933314, enable = 22175507
> Scaled count = 501340982 (71.85%, 15933314/22175507) Event 7 --
> Raw count = 365516630, run = 16179860, enable = 22173686
> Scaled count = 500922194 (72.97%, 16179860/22173686) Event 8 --
> Raw count = 365180177, run = 16178058, enable = 22171705
> Scaled count = 500472130 (72.97%, 16178058/22171705) Event 9 --
> Raw count = 341205844, run = 15233252, enable = 22169603
> Scaled count = 496571454 (68.71%, 15233252/22169603) Event 10 --
> Raw count = 318204949, run = 14234754, enable = 22167081
> Scaled count = 495524887 (64.22%, 14234754/22167081) Event 11 --
> Raw count = 296671131, run = 13236210, enable = 22164791
> Scaled count = 496792783 (59.72%, 13236210/22164791) Event 12 --
> Raw count = 276639189, run = 12237128, enable = 22162629
> Scaled count = 501020477 (55.22%, 12237128/22162629) Event 13 --
> Raw count = 255437518, run = 11238588, enable = 22160497
> Scaled count = 503677361 (50.71%, 11238588/22160497) Event 14 --
> Raw count = 232427791, run = 10239844, enable = 22158353
> Scaled count = 502958545 (46.21%, 10239844/22158353)
> Expected: 500221918
> High: 503677361 Low: 231217013 Average: 500223614
> Average Error = 0.00%
> Event 0 -- overflow flag = 0x1, POLL_UP = 1, other signal event = 0 Event 1 --
> overflow flag = 0x2, POLL_UP = 1, other signal event = 0 Event 2 -- overflow
> flag = 0x4, POLL_UP = 1, other signal event = 0 Event 3 -- overflow flag = 0x8,
> POLL_UP = 1, other signal event = 0 OK
> - running tests/test-evsel.c...
> loop = 65536, count = 328183
> loop = 131072, count = 655863
> loop = 262144, count = 1320613
> loop = 524288, count = 2621943
> loop = 1048576, count = 5243383
> loop = 65536, count = 66349
> loop = 131072, count = 131789
> loop = 262144, count = 264697
> loop = 524288, count = 528484
> loop = 1048576, count = 1056485
> period = 1000000
> overflow limit = 3, overflow count = 2, POLL_IN = 2, POLL_UP = 0, other
> signal event = 0 FAILED tests/test-evsel.c:286 failed to overflow count

This test was using standard signals (SIGIO), but after changing to real-time signals,
I confirmed that the test succeeded.
When using standard signals, it seems that if there is an overlapping timing of standard signals,
the signals generated later will be dropped.


> period = 1000000
> overflow limit = 3, overflow count = 5, POLL_IN = 4, POLL_UP = 1, other
> signal event = 0 FAILED tests/test-evsel.c:286 failed to overflow count

Fixed implementation of overflow counter not clearing on test failure.


> FAILED (2)
> FAILED tests/main.c:13 test evsel
>
I will post a v3 patch with the above fixes.

Best Regards
Shunsuke

2022-04-22 17:20:37

by Jiri Olsa

[permalink] [raw]
Subject: Re: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events

On Mon, Apr 11, 2022 at 08:23:54AM +0000, [email protected] wrote:
> Hi jirka
>
> Sorry for the late reply.
>
> > >
> > > Shunsuke Nakamura (7):
> > > libperf tests: Fix typo in the error message
> > > libperf: Move 'open_flags' from tools/perf to evsel::open_flags
> > > libperf: Add perf_evsel__{refresh, period}() functions
> > > libperf: Introduce perf_{evsel, evlist}__open_opt with extensible
> > > struct opts
> > > libperf: Add perf_evsel__check_overflow() functions
> > > libperf test: Add test_stat_overflow()
> > > libperf test: Add test_stat_overflow_event()
> >
> > I'm getting:
> >
> > [root@krava perf]# make tests
> > 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...FAILED tests/test-evsel.c:286 failed to overflow
> > count FAILED tests/test-evsel.c:286 failed to overflow count
> > FAILED (2)
> > FAILED tests/main.c:13 test evsel
> > make: *** [Makefile:162: tests] Error 255
> >
> Thanks for telling me.
> However, we could not reproduce the test failure in our environment.
> Could you please tell me the results of your test with the addition of V=1?

sorry, forgot to answer this one..

[root@krava perf]# LD_LIBRARY_PATH=. ./tests-shared -v
- running tests/test-cpumap.c...OK
- running tests/test-threadmap.c...OK
- running tests/test-evlist.c...
Event 0 -- Raw count = 231217013, run = 10196083, enable = 22183091
Scaled count = 503046909 (45.96%, 10196083/22183091)
Event 1 -- Raw count = 247219790, run = 10946246, enable = 22182044
Scaled count = 500979080 (49.35%, 10946246/22182044)
Event 2 -- Raw count = 268999685, run = 11943490, enable = 22180868
Scaled count = 499573115 (53.85%, 11943490/22180868)
Event 3 -- Raw count = 291383974, run = 12941069, enable = 22179798
Scaled count = 499405241 (58.35%, 12941069/22179798)
Event 4 -- Raw count = 314293846, run = 13938576, enable = 22178649
Scaled count = 500095052 (62.85%, 13938576/22178649)
Event 5 -- Raw count = 337393782, run = 14935798, enable = 22177192
Scaled count = 500974014 (67.35%, 14935798/22177192)
Event 6 -- Raw count = 360218294, run = 15933314, enable = 22175507
Scaled count = 501340982 (71.85%, 15933314/22175507)
Event 7 -- Raw count = 365516630, run = 16179860, enable = 22173686
Scaled count = 500922194 (72.97%, 16179860/22173686)
Event 8 -- Raw count = 365180177, run = 16178058, enable = 22171705
Scaled count = 500472130 (72.97%, 16178058/22171705)
Event 9 -- Raw count = 341205844, run = 15233252, enable = 22169603
Scaled count = 496571454 (68.71%, 15233252/22169603)
Event 10 -- Raw count = 318204949, run = 14234754, enable = 22167081
Scaled count = 495524887 (64.22%, 14234754/22167081)
Event 11 -- Raw count = 296671131, run = 13236210, enable = 22164791
Scaled count = 496792783 (59.72%, 13236210/22164791)
Event 12 -- Raw count = 276639189, run = 12237128, enable = 22162629
Scaled count = 501020477 (55.22%, 12237128/22162629)
Event 13 -- Raw count = 255437518, run = 11238588, enable = 22160497
Scaled count = 503677361 (50.71%, 11238588/22160497)
Event 14 -- Raw count = 232427791, run = 10239844, enable = 22158353
Scaled count = 502958545 (46.21%, 10239844/22158353)
Expected: 500221918
High: 503677361 Low: 231217013 Average: 500223614
Average Error = 0.00%
Event 0 -- overflow flag = 0x1, POLL_UP = 1, other signal event = 0
Event 1 -- overflow flag = 0x2, POLL_UP = 1, other signal event = 0
Event 2 -- overflow flag = 0x4, POLL_UP = 1, other signal event = 0
Event 3 -- overflow flag = 0x8, POLL_UP = 1, other signal event = 0
OK
- running tests/test-evsel.c...
loop = 65536, count = 328183
loop = 131072, count = 655863
loop = 262144, count = 1320613
loop = 524288, count = 2621943
loop = 1048576, count = 5243383
loop = 65536, count = 66349
loop = 131072, count = 131789
loop = 262144, count = 264697
loop = 524288, count = 528484
loop = 1048576, count = 1056485
period = 1000000
overflow limit = 3, overflow count = 2, POLL_IN = 2, POLL_UP = 0, other signal event = 0
FAILED tests/test-evsel.c:286 failed to overflow count
period = 1000000
overflow limit = 3, overflow count = 5, POLL_IN = 4, POLL_UP = 1, other signal event = 0
FAILED tests/test-evsel.c:286 failed to overflow count
FAILED (2)
FAILED tests/main.c:13 test evsel


jirka