1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __PERF_COUNTS_H
3*4882a593Smuzhiyun #define __PERF_COUNTS_H
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun #include <linux/types.h>
6*4882a593Smuzhiyun #include <internal/xyarray.h>
7*4882a593Smuzhiyun #include <perf/evsel.h>
8*4882a593Smuzhiyun #include <stdbool.h>
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun struct evsel;
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun struct perf_counts {
13*4882a593Smuzhiyun s8 scaled;
14*4882a593Smuzhiyun struct perf_counts_values aggr;
15*4882a593Smuzhiyun struct xyarray *values;
16*4882a593Smuzhiyun struct xyarray *loaded;
17*4882a593Smuzhiyun };
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun static inline struct perf_counts_values*
perf_counts(struct perf_counts * counts,int cpu,int thread)21*4882a593Smuzhiyun perf_counts(struct perf_counts *counts, int cpu, int thread)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun return xyarray__entry(counts->values, cpu, thread);
24*4882a593Smuzhiyun }
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun static inline bool
perf_counts__is_loaded(struct perf_counts * counts,int cpu,int thread)27*4882a593Smuzhiyun perf_counts__is_loaded(struct perf_counts *counts, int cpu, int thread)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun return *((bool *) xyarray__entry(counts->loaded, cpu, thread));
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun static inline void
perf_counts__set_loaded(struct perf_counts * counts,int cpu,int thread,bool loaded)33*4882a593Smuzhiyun perf_counts__set_loaded(struct perf_counts *counts, int cpu, int thread, bool loaded)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun *((bool *) xyarray__entry(counts->loaded, cpu, thread)) = loaded;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun struct perf_counts *perf_counts__new(int ncpus, int nthreads);
39*4882a593Smuzhiyun void perf_counts__delete(struct perf_counts *counts);
40*4882a593Smuzhiyun void perf_counts__reset(struct perf_counts *counts);
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun void evsel__reset_counts(struct evsel *evsel);
43*4882a593Smuzhiyun int evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads);
44*4882a593Smuzhiyun void evsel__free_counts(struct evsel *evsel);
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #endif /* __PERF_COUNTS_H */
47