summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYogesh Tillu <yogesh.tillu@linaro.org>2015-07-15 16:13:58 +0530
committerYogesh Tillu <yogesh.tillu@linaro.org>2015-07-21 13:11:45 +0530
commit4bc63b967f055f52b9dbeed61ab0e65ac1cb27d6 (patch)
tree82614a10ecb0854e4c5ff16a2d2c1353163a77d4
parentb71f2bcc165a0aebcfb92742277238bf609c4b30 (diff)
Added support for passing sample_period as command line
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_rc_mmap.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/perf_rc_mmap.c b/perf_rc_mmap.c
index 34dab28..57767be 100644
--- a/perf_rc_mmap.c
+++ b/perf_rc_mmap.c
@@ -37,7 +37,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;
static struct sigaction sigio;
@@ -53,8 +53,7 @@ static int counter_init(unsigned int counter)
if (sigaction(SIGIO, &sigio, NULL) == -1) {
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;
@@ -127,8 +126,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[])
@@ -139,9 +139,9 @@ int main(int ac, char *argv[])
int len = -1, cnt = -1;
int i, pre_loop_res, post_loop_res, sum = 0;
void *addr; /* mmaped address */
- unsigned long start_count, stop_count;
+ unsigned long start_count, stop_count, 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);
@@ -149,6 +149,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);
@@ -160,7 +163,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);