power: supply: bq24190_charger: Add disable-reset device-property
[linux/fpc-iii.git] / tools / perf / tests / event-times.c
blob19ef77bd6eb4152b539dc46638d4ef3a8db972e3
1 #include <linux/compiler.h>
2 #include <string.h>
3 #include "tests.h"
4 #include "evlist.h"
5 #include "evsel.h"
6 #include "util.h"
7 #include "debug.h"
8 #include "thread_map.h"
9 #include "target.h"
11 static int attach__enable_on_exec(struct perf_evlist *evlist)
13 struct perf_evsel *evsel = perf_evlist__last(evlist);
14 struct target target = {
15 .uid = UINT_MAX,
17 const char *argv[] = { "true", NULL, };
18 char sbuf[STRERR_BUFSIZE];
19 int err;
21 pr_debug("attaching to spawned child, enable on exec\n");
23 err = perf_evlist__create_maps(evlist, &target);
24 if (err < 0) {
25 pr_debug("Not enough memory to create thread/cpu maps\n");
26 return err;
29 err = perf_evlist__prepare_workload(evlist, &target, argv, false, NULL);
30 if (err < 0) {
31 pr_debug("Couldn't run the workload!\n");
32 return err;
35 evsel->attr.enable_on_exec = 1;
37 err = perf_evlist__open(evlist);
38 if (err < 0) {
39 pr_debug("perf_evlist__open: %s\n",
40 str_error_r(errno, sbuf, sizeof(sbuf)));
41 return err;
44 return perf_evlist__start_workload(evlist) == 1 ? TEST_OK : TEST_FAIL;
47 static int detach__enable_on_exec(struct perf_evlist *evlist)
49 waitpid(evlist->workload.pid, NULL, 0);
50 return 0;
53 static int attach__current_disabled(struct perf_evlist *evlist)
55 struct perf_evsel *evsel = perf_evlist__last(evlist);
56 struct thread_map *threads;
57 int err;
59 pr_debug("attaching to current thread as disabled\n");
61 threads = thread_map__new(-1, getpid(), UINT_MAX);
62 if (threads == NULL) {
63 pr_debug("thread_map__new\n");
64 return -1;
67 evsel->attr.disabled = 1;
69 err = perf_evsel__open_per_thread(evsel, threads);
70 if (err) {
71 pr_debug("Failed to open event cpu-clock:u\n");
72 return err;
75 thread_map__put(threads);
76 return perf_evsel__enable(evsel) == 0 ? TEST_OK : TEST_FAIL;
79 static int attach__current_enabled(struct perf_evlist *evlist)
81 struct perf_evsel *evsel = perf_evlist__last(evlist);
82 struct thread_map *threads;
83 int err;
85 pr_debug("attaching to current thread as enabled\n");
87 threads = thread_map__new(-1, getpid(), UINT_MAX);
88 if (threads == NULL) {
89 pr_debug("failed to call thread_map__new\n");
90 return -1;
93 err = perf_evsel__open_per_thread(evsel, threads);
95 thread_map__put(threads);
96 return err == 0 ? TEST_OK : TEST_FAIL;
99 static int detach__disable(struct perf_evlist *evlist)
101 struct perf_evsel *evsel = perf_evlist__last(evlist);
103 return perf_evsel__enable(evsel);
106 static int attach__cpu_disabled(struct perf_evlist *evlist)
108 struct perf_evsel *evsel = perf_evlist__last(evlist);
109 struct cpu_map *cpus;
110 int err;
112 pr_debug("attaching to CPU 0 as enabled\n");
114 cpus = cpu_map__new("0");
115 if (cpus == NULL) {
116 pr_debug("failed to call cpu_map__new\n");
117 return -1;
120 evsel->attr.disabled = 1;
122 err = perf_evsel__open_per_cpu(evsel, cpus);
123 if (err) {
124 if (err == -EACCES)
125 return TEST_SKIP;
127 pr_debug("Failed to open event cpu-clock:u\n");
128 return err;
131 cpu_map__put(cpus);
132 return perf_evsel__enable(evsel);
135 static int attach__cpu_enabled(struct perf_evlist *evlist)
137 struct perf_evsel *evsel = perf_evlist__last(evlist);
138 struct cpu_map *cpus;
139 int err;
141 pr_debug("attaching to CPU 0 as enabled\n");
143 cpus = cpu_map__new("0");
144 if (cpus == NULL) {
145 pr_debug("failed to call cpu_map__new\n");
146 return -1;
149 err = perf_evsel__open_per_cpu(evsel, cpus);
150 if (err == -EACCES)
151 return TEST_SKIP;
153 cpu_map__put(cpus);
154 return err ? TEST_FAIL : TEST_OK;
157 static int test_times(int (attach)(struct perf_evlist *),
158 int (detach)(struct perf_evlist *))
160 struct perf_counts_values count;
161 struct perf_evlist *evlist = NULL;
162 struct perf_evsel *evsel;
163 int err = -1, i;
165 evlist = perf_evlist__new();
166 if (!evlist) {
167 pr_debug("failed to create event list\n");
168 goto out_err;
171 err = parse_events(evlist, "cpu-clock:u", NULL);
172 if (err) {
173 pr_debug("failed to parse event cpu-clock:u\n");
174 goto out_err;
177 evsel = perf_evlist__last(evlist);
178 evsel->attr.read_format |=
179 PERF_FORMAT_TOTAL_TIME_ENABLED |
180 PERF_FORMAT_TOTAL_TIME_RUNNING;
182 err = attach(evlist);
183 if (err == TEST_SKIP) {
184 pr_debug(" SKIP : not enough rights\n");
185 return err;
188 TEST_ASSERT_VAL("failed to attach", !err);
190 for (i = 0; i < 100000000; i++) { }
192 TEST_ASSERT_VAL("failed to detach", !detach(evlist));
194 perf_evsel__read(evsel, 0, 0, &count);
196 err = !(count.ena == count.run);
198 pr_debug(" %s: ena %" PRIu64", run %" PRIu64"\n",
199 !err ? "OK " : "FAILED",
200 count.ena, count.run);
202 out_err:
203 perf_evlist__delete(evlist);
204 return !err ? TEST_OK : TEST_FAIL;
208 * This test creates software event 'cpu-clock'
209 * attaches it in several ways (explained below)
210 * and checks that enabled and running times
211 * match.
213 int test__event_times(int subtest __maybe_unused)
215 int err, ret = 0;
217 #define _T(attach, detach) \
218 err = test_times(attach, detach); \
219 if (err && (ret == TEST_OK || ret == TEST_SKIP)) \
220 ret = err;
222 /* attach on newly spawned process after exec */
223 _T(attach__enable_on_exec, detach__enable_on_exec)
224 /* attach on current process as enabled */
225 _T(attach__current_enabled, detach__disable)
226 /* attach on current process as disabled */
227 _T(attach__current_disabled, detach__disable)
228 /* attach on cpu as disabled */
229 _T(attach__cpu_disabled, detach__disable)
230 /* attach on cpu as enabled */
231 _T(attach__cpu_enabled, detach__disable)
233 #undef _T
234 return ret;