Files
mckernel/test/perf_overflow/simple_test.c
TOIDA,Suguru 1a204b6674 perf: overflow test
Change-Id: Ic7aa0d99ae9a5b7d3ce4436129a360275e6937ca
refs: #1358
2020-03-03 15:55:13 +09:00

65 lines
1.0 KiB
C

/* simple_test.c COPYRIGHT FUJITSU LIMITED 2019 */
#include "simple_test.h"
int simple_test(void)
{
struct perf_event_attr pe;
long long count = 0;
int fd = -1;
int ret = -1;
ret = init_perf_event_attr(&pe);
if (ret < 0) {
fprintf(stderr,
"%s : Failed to init_perf_event_attr.\n",
__func__);
goto out;
}
fd = perf_event_open(&pe, 0, -1, -1, 0);
if (fd == -1) {
ret = errno;
perror("perf_event_open");
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) {
perror("asm_ioctl(PERF_EVENT_IOC_ENABLE)");
goto out;
}
nop10;
nop10;
nop10;
nop10;
nop10;
nop10;
nop10;
nop10;
ret = asm_ioctl3(fd, PERF_EVENT_IOC_DISABLE, 0);
if (ret < 0) {
perror("asm_ioctl(PERF_EVENT_IOC_DISABLE)");
}
ret = read(fd, &count, sizeof(long long));
if (ret < 0) {
perror("read");
}
printf("Used %lld instructions\n", count);
ret = 0;
out:
if (fd != -1) {
close(fd);
}
return ret;
}