blob: 15e458e150bd8c9d17302c4cbb1dd0c875ef1f9b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Olsa43599d12014-05-05 12:53:20 +02002#ifndef _PERF_SYS_H
3#define _PERF_SYS_H
4
Jiri Olsa82baa0e2014-05-05 12:58:31 +02005#include <unistd.h>
6#include <sys/types.h>
7#include <sys/syscall.h>
Arnaldo Carvalho de Melo14f06522016-07-18 17:40:49 -03008#include <linux/compiler.h>
Arnaldo Carvalho de Melo91854f92019-08-29 14:59:50 -03009
10struct perf_event_attr;
11
12extern 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);
17
Björn Töpel6bd7cf62019-10-01 13:33:06 +020018#ifndef HAVE_ATTR_TEST
19#define HAVE_ATTR_TEST 1
20#endif
Jiri Olsa43599d12014-05-05 12:53:20 +020021
Jiri Olsa82baa0e2014-05-05 12:58:31 +020022static 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
Björn Töpel6bd7cf62019-10-01 13:33:06 +020032#if HAVE_ATTR_TEST
Jiri Olsa82baa0e2014-05-05 12:58:31 +020033 if (unlikely(test_attr__enabled))
34 test_attr__open(attr, pid, cpu, fd, group_fd, flags);
35#endif
36 return fd;
37}
38
Jiri Olsa43599d12014-05-05 12:53:20 +020039#endif /* _PERF_SYS_H */