summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYogesh Tillu <yogesh.tillu@linaro.org>2015-07-28 14:54:15 +0530
committerYogesh Tillu <yogesh.tillu@linaro.org>2015-07-30 17:25:00 +0530
commitc40a41e0ea3d6bd3fbad8eecc89aece011e71f09 (patch)
tree64476bfb294a18d0e9b6d8343d1d1c52f7fac579
parenta8b75a4ec9ebfd1b2bb141aca08ff2adaef5b578 (diff)
perf_ev_open: Added support for passing sample_period as argument
NOTE: To reduce number of overflow occurance while testing with perf hw counter, we can tune sample_period value as parameter. Signed-off-by: Yogesh Tillu <yogesh.tillu@linaro.org> Reviewed-by: Anders Roxell <anders.roxell@linaro.org>
-rw-r--r--perf_ev_open.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/perf_ev_open.c b/perf_ev_open.c
index b8cf681..9b59a37 100644
--- a/perf_ev_open.c
+++ b/perf_ev_open.c
@@ -31,7 +31,7 @@ static void sigio_handler(int signo, siginfo_t *info, void *uc)
overflow = overflow + 1;
}
-static int counter_init(unsigned int counter)
+static int counter_init(unsigned int counter,long unsigned int sample)
{
static struct perf_event_attr attr;
attr.type = PERF_TYPE_HARDWARE;
@@ -49,7 +49,7 @@ static int counter_init(unsigned int counter)
printf("Error: SIGIO signal handler %s\n",strerror(errno));
}
- attr.sample_period = 1000000;
+ attr.sample_period = sample;
attr.sample_type = PERF_SAMPLE_IP;
attr.wakeup_events = 1;
attr.config = counter;
@@ -97,8 +97,9 @@ void print_usage(char *argv)
"Refer to 'enum perf_hw_id'[file <linux/perf_event.h>] for hw\n"
"counter enum value in range of 0 to PERF_COUNT_HW_MAX\n"
"-n\t Length size array will implement busyloop\n"
+ "-s\t Sample period [> 1000000 samples]\n"
"e.g.\n"
- "\t%s -c 0 -n 64\n", argv, argv, argv);
+ "\t%s -c 0 -n 64 -s 1000000\n", argv, argv, argv);
}
int main(int ac, char *argv[])
@@ -110,8 +111,9 @@ int main(int ac, char *argv[])
int *a = NULL;
int *b = NULL;
int i, pre_loop_res, post_loop_res, sum = 0;
+ unsigned long s_period = 1000000;
- while ((option = getopt(ac, argv, "c:n:")) != -1) {
+ while ((option = getopt(ac, argv, "c:n:s:")) != -1) {
switch (option) {
case 'c':
cnt = atoi(optarg);
@@ -119,6 +121,9 @@ int main(int ac, char *argv[])
case 'n':
len = atoi(optarg);
break;
+ case 's':
+ s_period = atoi(optarg);
+ break;
default:
print_usage(argv[0]);
exit(EXIT_FAILURE);
@@ -130,7 +135,7 @@ int main(int ac, char *argv[])
exit(EXIT_FAILURE);
}
- if (counter_init(cnt) < 0) {
+ if (counter_init(cnt, s_period) < 0) {
printf("Error: Counter Invalid\n");
print_usage(argv[0]);
exit(EXIT_FAILURE);