@@ -179,145 +179,6 @@ static inline int nsec_counter(struct perf_evsel *evsel)
179179 return 0 ;
180180}
181181
182- static void zero_per_pkg (struct perf_evsel * counter )
183- {
184- if (counter -> per_pkg_mask )
185- memset (counter -> per_pkg_mask , 0 , MAX_NR_CPUS );
186- }
187-
188- static int check_per_pkg (struct perf_evsel * counter , int cpu , bool * skip )
189- {
190- unsigned long * mask = counter -> per_pkg_mask ;
191- struct cpu_map * cpus = perf_evsel__cpus (counter );
192- int s ;
193-
194- * skip = false;
195-
196- if (!counter -> per_pkg )
197- return 0 ;
198-
199- if (cpu_map__empty (cpus ))
200- return 0 ;
201-
202- if (!mask ) {
203- mask = zalloc (MAX_NR_CPUS );
204- if (!mask )
205- return - ENOMEM ;
206-
207- counter -> per_pkg_mask = mask ;
208- }
209-
210- s = cpu_map__get_socket (cpus , cpu );
211- if (s < 0 )
212- return -1 ;
213-
214- * skip = test_and_set_bit (s , mask ) == 1 ;
215- return 0 ;
216- }
217-
218- static int
219- process_counter_values (struct perf_stat_config * config , struct perf_evsel * evsel ,
220- int cpu , int thread ,
221- struct perf_counts_values * count )
222- {
223- struct perf_counts_values * aggr = & evsel -> counts -> aggr ;
224- static struct perf_counts_values zero ;
225- bool skip = false;
226-
227- if (check_per_pkg (evsel , cpu , & skip )) {
228- pr_err ("failed to read per-pkg counter\n" );
229- return -1 ;
230- }
231-
232- if (skip )
233- count = & zero ;
234-
235- switch (config -> aggr_mode ) {
236- case AGGR_THREAD :
237- case AGGR_CORE :
238- case AGGR_SOCKET :
239- case AGGR_NONE :
240- if (!evsel -> snapshot )
241- perf_evsel__compute_deltas (evsel , cpu , thread , count );
242- perf_counts_values__scale (count , config -> scale , NULL );
243- if (config -> aggr_mode == AGGR_NONE )
244- perf_stat__update_shadow_stats (evsel , count -> values , cpu );
245- break ;
246- case AGGR_GLOBAL :
247- aggr -> val += count -> val ;
248- if (config -> scale ) {
249- aggr -> ena += count -> ena ;
250- aggr -> run += count -> run ;
251- }
252- default :
253- break ;
254- }
255-
256- return 0 ;
257- }
258-
259- static int process_counter_maps (struct perf_stat_config * config ,
260- struct perf_evsel * counter )
261- {
262- int nthreads = thread_map__nr (counter -> threads );
263- int ncpus = perf_evsel__nr_cpus (counter );
264- int cpu , thread ;
265-
266- if (counter -> system_wide )
267- nthreads = 1 ;
268-
269- for (thread = 0 ; thread < nthreads ; thread ++ ) {
270- for (cpu = 0 ; cpu < ncpus ; cpu ++ ) {
271- if (process_counter_values (config , counter , cpu , thread ,
272- perf_counts (counter -> counts , cpu , thread )))
273- return -1 ;
274- }
275- }
276-
277- return 0 ;
278- }
279-
280- static int process_counter (struct perf_stat_config * config ,
281- struct perf_evsel * counter )
282- {
283- struct perf_counts_values * aggr = & counter -> counts -> aggr ;
284- struct perf_stat * ps = counter -> priv ;
285- u64 * count = counter -> counts -> aggr .values ;
286- int i , ret ;
287-
288- aggr -> val = aggr -> ena = aggr -> run = 0 ;
289- init_stats (ps -> res_stats );
290-
291- if (counter -> per_pkg )
292- zero_per_pkg (counter );
293-
294- ret = process_counter_maps (& stat_config , counter );
295- if (ret )
296- return ret ;
297-
298- if (config -> aggr_mode != AGGR_GLOBAL )
299- return 0 ;
300-
301- if (!counter -> snapshot )
302- perf_evsel__compute_deltas (counter , -1 , -1 , aggr );
303- perf_counts_values__scale (aggr , config -> scale , & counter -> counts -> scaled );
304-
305- for (i = 0 ; i < 3 ; i ++ )
306- update_stats (& ps -> res_stats [i ], count [i ]);
307-
308- if (verbose ) {
309- fprintf (config -> output , "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n" ,
310- perf_evsel__name (counter ), count [0 ], count [1 ], count [2 ]);
311- }
312-
313- /*
314- * Save the full runtime - to allow normalization during printout:
315- */
316- perf_stat__update_shadow_stats (counter , count , 0 );
317-
318- return 0 ;
319- }
320-
321182/*
322183 * Read out the results of a single counter:
323184 * do not aggregate counts across CPUs in system-wide mode
@@ -355,7 +216,7 @@ static void read_counters(bool close_counters)
355216 if (read_counter (counter ))
356217 pr_warning ("failed to read counter %s\n" , counter -> name );
357218
358- if (process_counter (& stat_config , counter ))
219+ if (perf_stat_process_counter (& stat_config , counter ))
359220 pr_warning ("failed to process counter %s\n" , counter -> name );
360221
361222 if (close_counters ) {
0 commit comments