~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/bp_signal_overflow.c

Version: ~ [ linux-6.0 ] ~ [ linux-5.19.12 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.71 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.146 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.215 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.260 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.295 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.330 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Originally done by Vince Weaver <vincent.weaver@maine.edu> for
  4  * perf_event_tests (git://github.com/deater/perf_event_tests)
  5  */
  6 
  7 /*
  8  * Powerpc needs __SANE_USERSPACE_TYPES__ before <linux/types.h> to select
  9  * 'int-ll64.h' and avoid compile warnings when printing __u64 with %llu.
 10  */
 11 #define __SANE_USERSPACE_TYPES__
 12 
 13 #include <stdlib.h>
 14 #include <stdio.h>
 15 #include <unistd.h>
 16 #include <string.h>
 17 #include <sys/ioctl.h>
 18 #include <time.h>
 19 #include <fcntl.h>
 20 #include <signal.h>
 21 #include <sys/mman.h>
 22 #include <linux/compiler.h>
 23 #include <linux/hw_breakpoint.h>
 24 
 25 #include "tests.h"
 26 #include "debug.h"
 27 #include "perf.h"
 28 #include "cloexec.h"
 29 
 30 static int overflows;
 31 
 32 static noinline int test_function(void)
 33 {
 34         return time(NULL);
 35 }
 36 
 37 static void sig_handler(int signum __maybe_unused,
 38                         siginfo_t *oh __maybe_unused,
 39                         void *uc __maybe_unused)
 40 {
 41         overflows++;
 42 }
 43 
 44 static long long bp_count(int fd)
 45 {
 46         long long count;
 47         int ret;
 48 
 49         ret = read(fd, &count, sizeof(long long));
 50         if (ret != sizeof(long long)) {
 51                 pr_debug("failed to read: %d\n", ret);
 52                 return TEST_FAIL;
 53         }
 54 
 55         return count;
 56 }
 57 
 58 #define EXECUTIONS 10000
 59 #define THRESHOLD  100
 60 
 61 int test__bp_signal_overflow(struct test *test __maybe_unused, int subtest __maybe_unused)
 62 {
 63         struct perf_event_attr pe;
 64         struct sigaction sa;
 65         long long count;
 66         int fd, i, fails = 0;
 67 
 68         /* setup SIGIO signal handler */
 69         memset(&sa, 0, sizeof(struct sigaction));
 70         sa.sa_sigaction = (void *) sig_handler;
 71         sa.sa_flags = SA_SIGINFO;
 72 
 73         if (sigaction(SIGIO, &sa, NULL) < 0) {
 74                 pr_debug("failed setting up signal handler\n");
 75                 return TEST_FAIL;
 76         }
 77 
 78         memset(&pe, 0, sizeof(struct perf_event_attr));
 79         pe.type = PERF_TYPE_BREAKPOINT;
 80         pe.size = sizeof(struct perf_event_attr);
 81 
 82         pe.config = 0;
 83         pe.bp_type = HW_BREAKPOINT_X;
 84         pe.bp_addr = (unsigned long) test_function;
 85         pe.bp_len = sizeof(long);
 86 
 87         pe.sample_period = THRESHOLD;
 88         pe.sample_type = PERF_SAMPLE_IP;
 89         pe.wakeup_events = 1;
 90 
 91         pe.disabled = 1;
 92         pe.exclude_kernel = 1;
 93         pe.exclude_hv = 1;
 94 
 95         fd = sys_perf_event_open(&pe, 0, -1, -1,
 96                                  perf_event_open_cloexec_flag());
 97         if (fd < 0) {
 98                 pr_debug("failed opening event %llx\n", pe.config);
 99                 return TEST_FAIL;
100         }
101 
102         fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC);
103         fcntl(fd, F_SETSIG, SIGIO);
104         fcntl(fd, F_SETOWN, getpid());
105 
106         ioctl(fd, PERF_EVENT_IOC_RESET, 0);
107         ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
108 
109         for (i = 0; i < EXECUTIONS; i++)
110                 test_function();
111 
112         ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
113 
114         count = bp_count(fd);
115 
116         close(fd);
117 
118         pr_debug("count %lld, overflow %d\n",
119                  count, overflows);
120 
121         if (count != EXECUTIONS) {
122                 pr_debug("\tWrong number of executions %lld != %d\n",
123                 count, EXECUTIONS);
124                 fails++;
125         }
126 
127         if (overflows != EXECUTIONS / THRESHOLD) {
128                 pr_debug("\tWrong number of overflows %d != %d\n",
129                 overflows, EXECUTIONS / THRESHOLD);
130                 fails++;
131         }
132 
133         return fails ? TEST_FAIL : TEST_OK;
134 }
135 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp