From c3c0b7197fb2459233e7e115177d808dd7c2233b Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Fri, 27 Mar 2020 02:12:04 -0400 Subject: [PATCH] test: perf: prevent overflow counter from stopping counter Fixes: 1a204b6 "perf: overflow test" Change-Id: I4d8e93b97f7a8d58ef7811f55b5c995b16c5af69 --- test/perf_overflow/combination_test.c | 26 ++++++++++++++++++++++++++ test/perf_overflow/perf_common.c | 7 +++++-- test/perf_overflow/perf_common.h | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/perf_overflow/combination_test.c b/test/perf_overflow/combination_test.c index 33e293d6..91b97f45 100644 --- a/test/perf_overflow/combination_test.c +++ b/test/perf_overflow/combination_test.c @@ -1,5 +1,6 @@ /* combination_test.c COPYRIGHT FUJITSU LIMITED 2019 */ #include "combination_test.h" +#include "perf_common.h" // // main @@ -32,6 +33,31 @@ static int combination_test(struct command_set *cmd_set) goto out; } + /* Set reasonable value to overflow counter so as not to stop + * counter on Linux. Reset must precede to prevent + * uninitialized value is accumulated on McKernel for the case + * REFRESH includes ENABLE + */ + ret = perf_event_ioc_refresh(fd, NULL); + if (ret < 0) { + perror("perf_event_ioc_refresh"); + goto out; + } + + /* Stop counter for the case REFRESH includes ENABLE */ + ret = asm_ioctl3(fd, PERF_EVENT_IOC_DISABLE, 0); + if (ret < 0) { + errno = -ret; + perror("asm_ioctl(PERF_EVENT_IOC_DISABLE)"); + goto out; + } + + ret = ioctl(fd, PERF_EVENT_IOC_RESET, 0); + if (ret < 0) { + perror("ioctl(PERF_EVENT_IOC_RESET)"); + goto out; + } + ret = asm_ioctl3(fd, PERF_EVENT_IOC_ENABLE, 0); if (ret < 0) { errno = -ret; diff --git a/test/perf_overflow/perf_common.c b/test/perf_overflow/perf_common.c index e53f076b..7c2e5f76 100644 --- a/test/perf_overflow/perf_common.c +++ b/test/perf_overflow/perf_common.c @@ -164,9 +164,12 @@ static void build_perf_event_ioc_reset(struct command *cmd) } // perf_event_ioc_refresh command -static int perf_event_ioc_refresh(int fd, void *_args) +int perf_event_ioc_refresh(int fd, void *_args) { - int ret = asm_ioctl3(fd, PERF_EVENT_IOC_REFRESH, 0); + /* Prevent overflow counter from stopping counter + * Note that it starts counter as well + */ + int ret = asm_ioctl3(fd, PERF_EVENT_IOC_REFRESH, 256); if (ret < 0) { errno = -ret; diff --git a/test/perf_overflow/perf_common.h b/test/perf_overflow/perf_common.h index f72f2551..d0ebbcee 100644 --- a/test/perf_overflow/perf_common.h +++ b/test/perf_overflow/perf_common.h @@ -25,6 +25,7 @@ void print_usage(void); //system call long perf_event_open(struct perf_event_attr *event_attr, pid_t pid, int cpu, int group_fd, unsigned long flags); +int perf_event_ioc_refresh(int fd, void *_args); int init_perf_event_attr(struct perf_event_attr *event_attr); int asm_ioctl3(int fd, unsigned long arg1, unsigned long arg2); int asm_read(int fd, void *buf, size_t size);