1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 #include <errno.h> 2 #include <errno.h> 3 #include <stdlib.h> 3 #include <stdlib.h> 4 #include <string.h> 4 #include <string.h> 5 #include "evsel.h" 5 #include "evsel.h" 6 #include "counts.h" 6 #include "counts.h" 7 #include <perf/threadmap.h> << 8 #include <linux/zalloc.h> 7 #include <linux/zalloc.h> 9 8 10 struct perf_counts *perf_counts__new(int ncpus 9 struct perf_counts *perf_counts__new(int ncpus, int nthreads) 11 { 10 { 12 struct perf_counts *counts = zalloc(si 11 struct perf_counts *counts = zalloc(sizeof(*counts)); 13 12 14 if (counts) { 13 if (counts) { 15 struct xyarray *values; 14 struct xyarray *values; 16 15 17 values = xyarray__new(ncpus, n 16 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values)); 18 if (!values) { 17 if (!values) { 19 free(counts); 18 free(counts); 20 return NULL; 19 return NULL; 21 } 20 } 22 21 23 counts->values = values; 22 counts->values = values; 24 23 25 values = xyarray__new(ncpus, n 24 values = xyarray__new(ncpus, nthreads, sizeof(bool)); 26 if (!values) { 25 if (!values) { 27 xyarray__delete(counts 26 xyarray__delete(counts->values); 28 free(counts); 27 free(counts); 29 return NULL; 28 return NULL; 30 } 29 } 31 30 32 counts->loaded = values; 31 counts->loaded = values; 33 } 32 } 34 33 35 return counts; 34 return counts; 36 } 35 } 37 36 38 void perf_counts__delete(struct perf_counts *c 37 void perf_counts__delete(struct perf_counts *counts) 39 { 38 { 40 if (counts) { 39 if (counts) { 41 xyarray__delete(counts->loaded 40 xyarray__delete(counts->loaded); 42 xyarray__delete(counts->values 41 xyarray__delete(counts->values); 43 free(counts); 42 free(counts); 44 } 43 } 45 } 44 } 46 45 47 void perf_counts__reset(struct perf_counts *co 46 void perf_counts__reset(struct perf_counts *counts) 48 { 47 { 49 xyarray__reset(counts->loaded); 48 xyarray__reset(counts->loaded); 50 xyarray__reset(counts->values); 49 xyarray__reset(counts->values); >> 50 memset(&counts->aggr, 0, sizeof(struct perf_counts_values)); 51 } 51 } 52 52 53 void evsel__reset_counts(struct evsel *evsel) 53 void evsel__reset_counts(struct evsel *evsel) 54 { 54 { 55 perf_counts__reset(evsel->counts); 55 perf_counts__reset(evsel->counts); 56 } 56 } 57 57 58 int evsel__alloc_counts(struct evsel *evsel) !! 58 int evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads) 59 { 59 { 60 struct perf_cpu_map *cpus = evsel__cpu !! 60 evsel->counts = perf_counts__new(ncpus, nthreads); 61 int nthreads = perf_thread_map__nr(evs << 62 << 63 evsel->counts = perf_counts__new(perf_ << 64 return evsel->counts != NULL ? 0 : -EN 61 return evsel->counts != NULL ? 0 : -ENOMEM; 65 } 62 } 66 63 67 void evsel__free_counts(struct evsel *evsel) 64 void evsel__free_counts(struct evsel *evsel) 68 { 65 { 69 perf_counts__delete(evsel->counts); 66 perf_counts__delete(evsel->counts); 70 evsel->counts = NULL; 67 evsel->counts = NULL; 71 } 68 } 72 69
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.