blob: 15e458e150bd8c9d17302c4cbb1dd0c875ef1f9b [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _PERF_SYS_H
3#define _PERF_SYS_H
4
5#include <unistd.h>
6#include <sys/types.h>
7#include <sys/syscall.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008#include <linux/compiler.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009
David Brazdil0f672f62019-12-10 10:32:29 +000010struct perf_event_attr;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000011
David Brazdil0f672f62019-12-10 10:32:29 +000012extern bool test_attr__enabled;
13void test_attr__ready(void);
14void test_attr__init(void);
15void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
16 int fd, int group_fd, unsigned long flags);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017
David Brazdil0f672f62019-12-10 10:32:29 +000018#ifndef HAVE_ATTR_TEST
19#define HAVE_ATTR_TEST 1
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020#endif
21
22static inline int
23sys_perf_event_open(struct perf_event_attr *attr,
24 pid_t pid, int cpu, int group_fd,
25 unsigned long flags)
26{
27 int fd;
28
29 fd = syscall(__NR_perf_event_open, attr, pid, cpu,
30 group_fd, flags);
31
David Brazdil0f672f62019-12-10 10:32:29 +000032#if HAVE_ATTR_TEST
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000033 if (unlikely(test_attr__enabled))
34 test_attr__open(attr, pid, cpu, fd, group_fd, flags);
35#endif
36 return fd;
37}
38
39#endif /* _PERF_SYS_H */