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

Shunsuke Nakamura posted 7 patches 4 years, 2 months ago
There is a newer version of this series
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(-)
[RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events
Posted by Shunsuke Nakamura 4 years, 2 months ago
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/20220225103114.144239-1-nakamura.shun@fujitsu.com/

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
Re: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events
Posted by Jiri Olsa 4 years, 2 months ago
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/20220225103114.144239-1-nakamura.shun@fujitsu.com/
> 
> 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
>
RE: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events
Posted by nakamura.shun@fujitsu.com 4 years, 2 months ago
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
Re: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events
Posted by Jiri Olsa 4 years, 2 months ago
On Mon, Apr 11, 2022 at 08:23:54AM +0000, nakamura.shun@fujitsu.com 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
RE: [RFC PATCH v2 0/7] libperf: Add interface for overflow check of sampling events
Posted by nakamura.shun@fujitsu.com 4 years, 2 months ago
Hi jirka

> On Mon, Apr 11, 2022 at 08:23:54AM +0000, nakamura.shun@fujitsu.com 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