These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / tools / perf / util / counts.c
1 #include <stdlib.h>
2 #include "evsel.h"
3 #include "counts.h"
4
5 struct perf_counts *perf_counts__new(int ncpus, int nthreads)
6 {
7         struct perf_counts *counts = zalloc(sizeof(*counts));
8
9         if (counts) {
10                 struct xyarray *values;
11
12                 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
13                 if (!values) {
14                         free(counts);
15                         return NULL;
16                 }
17
18                 counts->values = values;
19         }
20
21         return counts;
22 }
23
24 void perf_counts__delete(struct perf_counts *counts)
25 {
26         if (counts) {
27                 xyarray__delete(counts->values);
28                 free(counts);
29         }
30 }
31
32 static void perf_counts__reset(struct perf_counts *counts)
33 {
34         xyarray__reset(counts->values);
35 }
36
37 void perf_evsel__reset_counts(struct perf_evsel *evsel)
38 {
39         perf_counts__reset(evsel->counts);
40 }
41
42 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
43 {
44         evsel->counts = perf_counts__new(ncpus, nthreads);
45         return evsel->counts != NULL ? 0 : -ENOMEM;
46 }
47
48 void perf_evsel__free_counts(struct perf_evsel *evsel)
49 {
50         perf_counts__delete(evsel->counts);
51         evsel->counts = NULL;
52 }