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