blob: 5de275194f2b199b797a0647c543472338347aa2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Olsad8095602015-08-07 12:51:03 +02002#ifndef __PERF_COUNTS_H
3#define __PERF_COUNTS_H
4
Arnaldo Carvalho de Melo2d64ae92019-08-21 11:56:13 -03005#include <linux/types.h>
Jiri Olsa4b247fa2019-07-21 13:24:44 +02006#include <internal/xyarray.h>
Jiri Olsa5c30af92019-07-21 13:24:51 +02007#include <perf/evsel.h>
Arnaldo Carvalho de Melo2d64ae92019-08-21 11:56:13 -03008#include <stdbool.h>
9
10struct evsel;
Jiri Olsad8095602015-08-07 12:51:03 +020011
12struct perf_counts {
13 s8 scaled;
14 struct perf_counts_values aggr;
15 struct xyarray *values;
Jiri Olsadf1d6852019-07-21 13:23:48 +020016 struct xyarray *loaded;
Jiri Olsad8095602015-08-07 12:51:03 +020017};
18
19
20static inline struct perf_counts_values*
Ian Rogers73162682022-01-04 22:13:32 -080021perf_counts(struct perf_counts *counts, int cpu_map_idx, int thread)
Jiri Olsad8095602015-08-07 12:51:03 +020022{
Ian Rogers73162682022-01-04 22:13:32 -080023 return xyarray__entry(counts->values, cpu_map_idx, thread);
Jiri Olsad8095602015-08-07 12:51:03 +020024}
25
Jiri Olsadf1d6852019-07-21 13:23:48 +020026static inline bool
Ian Rogers73162682022-01-04 22:13:32 -080027perf_counts__is_loaded(struct perf_counts *counts, int cpu_map_idx, int thread)
Jiri Olsadf1d6852019-07-21 13:23:48 +020028{
Ian Rogers73162682022-01-04 22:13:32 -080029 return *((bool *) xyarray__entry(counts->loaded, cpu_map_idx, thread));
Jiri Olsadf1d6852019-07-21 13:23:48 +020030}
31
32static inline void
Ian Rogers73162682022-01-04 22:13:32 -080033perf_counts__set_loaded(struct perf_counts *counts, int cpu_map_idx, int thread, bool loaded)
Jiri Olsadf1d6852019-07-21 13:23:48 +020034{
Ian Rogers73162682022-01-04 22:13:32 -080035 *((bool *) xyarray__entry(counts->loaded, cpu_map_idx, thread)) = loaded;
Jiri Olsadf1d6852019-07-21 13:23:48 +020036}
37
Jiri Olsad8095602015-08-07 12:51:03 +020038struct perf_counts *perf_counts__new(int ncpus, int nthreads);
39void perf_counts__delete(struct perf_counts *counts);
Jin Yaocf4d9bd2020-05-20 12:27:34 +080040void perf_counts__reset(struct perf_counts *counts);
Jiri Olsad8095602015-08-07 12:51:03 +020041
Arnaldo Carvalho de Melo7d1e2392020-05-06 13:38:26 -030042void evsel__reset_counts(struct evsel *evsel);
Ian Rogers2ca0a372022-01-04 22:13:29 -080043int evsel__alloc_counts(struct evsel *evsel);
Arnaldo Carvalho de Melo7d1e2392020-05-06 13:38:26 -030044void evsel__free_counts(struct evsel *evsel);
Jiri Olsad8095602015-08-07 12:51:03 +020045
46#endif /* __PERF_COUNTS_H */