@@ -3317,15 +3317,20 @@ static int perf_sched__map(struct perf_sched *sched)
3317
3317
3318
3318
static int perf_sched__replay (struct perf_sched * sched )
3319
3319
{
3320
+ int ret ;
3320
3321
unsigned long i ;
3321
3322
3323
+ mutex_init (& sched -> start_work_mutex );
3324
+ mutex_init (& sched -> work_done_wait_mutex );
3325
+
3322
3326
calibrate_run_measurement_overhead (sched );
3323
3327
calibrate_sleep_measurement_overhead (sched );
3324
3328
3325
3329
test_calibrations (sched );
3326
3330
3327
- if (perf_sched__read_events (sched ))
3328
- return -1 ;
3331
+ ret = perf_sched__read_events (sched );
3332
+ if (ret )
3333
+ goto out_mutex_destroy ;
3329
3334
3330
3335
printf ("nr_run_events: %ld\n" , sched -> nr_run_events );
3331
3336
printf ("nr_sleep_events: %ld\n" , sched -> nr_sleep_events );
@@ -3350,7 +3355,11 @@ static int perf_sched__replay(struct perf_sched *sched)
3350
3355
3351
3356
sched -> thread_funcs_exit = true;
3352
3357
destroy_tasks (sched );
3353
- return 0 ;
3358
+
3359
+ out_mutex_destroy :
3360
+ mutex_destroy (& sched -> start_work_mutex );
3361
+ mutex_destroy (& sched -> work_done_wait_mutex );
3362
+ return ret ;
3354
3363
}
3355
3364
3356
3365
static void setup_sorting (struct perf_sched * sched , const struct option * options ,
@@ -3588,8 +3597,6 @@ int cmd_sched(int argc, const char **argv)
3588
3597
unsigned int i ;
3589
3598
int ret = 0 ;
3590
3599
3591
- mutex_init (& sched .start_work_mutex );
3592
- mutex_init (& sched .work_done_wait_mutex );
3593
3600
sched .curr_thread = calloc (MAX_CPUS , sizeof (* sched .curr_thread ));
3594
3601
if (!sched .curr_thread ) {
3595
3602
ret = - ENOMEM ;
@@ -3677,8 +3684,6 @@ int cmd_sched(int argc, const char **argv)
3677
3684
free (sched .curr_pid );
3678
3685
free (sched .cpu_last_switched );
3679
3686
free (sched .curr_thread );
3680
- mutex_destroy (& sched .start_work_mutex );
3681
- mutex_destroy (& sched .work_done_wait_mutex );
3682
3687
3683
3688
return ret ;
3684
3689
}
0 commit comments