summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@kernel.org>2019-11-26 12:34:17 -0800
committerAndy Lutomirski <luto@kernel.org>2019-11-26 12:34:17 -0800
commit47c81ffebffd1d03f3ed2e990e6d3e553dfcf3d4 (patch)
treee06a99a06888ec6c5673337a1025ca8d7ea7a2b0
parentaf15264fae43a67441a8c711d6b171ebf63a8eb8 (diff)
downloadmisc-tests-47c81ffebffd1d03f3ed2e990e6d3e553dfcf3d4.tar.gz
Add perf_lots_of_nmi
Signed-off-by: Andy Lutomirski <luto@kernel.org>
-rw-r--r--Makefile2
-rw-r--r--perf_lots_of_nmi.c52
2 files changed, 53 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index c31760f..d8a5f04 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.PHONY: all clean
-SIMPLE_C_TARGETS := dump-vsyscall context_switch_latency kernel_pf user_visible_state null_seccomp highsys gsbase
+SIMPLE_C_TARGETS := dump-vsyscall context_switch_latency kernel_pf user_visible_state null_seccomp highsys gsbase perf_lots_of_nmi
SIMPLE_CC_TARGETS := evil-clock-test
diff --git a/perf_lots_of_nmi.c b/perf_lots_of_nmi.c
new file mode 100644
index 0000000..c1a8119
--- /dev/null
+++ b/perf_lots_of_nmi.c
@@ -0,0 +1,52 @@
+#include <linux/perf_event.h>
+#include <sys/syscall.h>
+#include <sys/mman.h>
+#include <sys/user.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s CPU\n", argv[0]);
+ return 1;
+ }
+
+ int cpu = atoi(argv[1]);
+
+ struct perf_event_attr attr;
+ memset(&attr, 0, sizeof(attr));
+
+ attr.type = PERF_TYPE_HARDWARE;
+ attr.size = sizeof(struct perf_event_attr);
+ attr.freq = 1;
+ attr.sample_freq = 10000;
+ attr.config = PERF_COUNT_HW_CPU_CYCLES;
+
+ int fd = syscall(
+ SYS_perf_event_open,
+ &attr, /* attributes */
+ -1, /* monitor all tasks */
+ cpu, /* selected CPU */
+ -1, /* group leader */
+ PERF_FLAG_FD_CLOEXEC /* flags */
+ );
+
+ if (fd == -1)
+ err(1, "perf_event_open");
+
+ pause();
+
+ /*
+ void *addr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
+ if (addr == MAP_FAILED) {
+ err(1, "mmap");
+ }
+ */
+
+ return 0;
+}