@@ -3329,15 +3329,20 @@ static int perf_sched__map(struct perf_sched *sched)
3329
3329
3330
3330
static int perf_sched__replay (struct perf_sched * sched )
3331
3331
{
3332
+ int ret ;
3332
3333
unsigned long i ;
3333
3334
3335
+ mutex_init (& sched -> start_work_mutex );
3336
+ mutex_init (& sched -> work_done_wait_mutex );
3337
+
3334
3338
calibrate_run_measurement_overhead (sched );
3335
3339
calibrate_sleep_measurement_overhead (sched );
3336
3340
3337
3341
test_calibrations (sched );
3338
3342
3339
- if (perf_sched__read_events (sched ))
3340
- return -1 ;
3343
+ ret = perf_sched__read_events (sched );
3344
+ if (ret )
3345
+ goto out_mutex_destroy ;
3341
3346
3342
3347
printf ("nr_run_events: %ld\n" , sched -> nr_run_events );
3343
3348
printf ("nr_sleep_events: %ld\n" , sched -> nr_sleep_events );
@@ -3362,7 +3367,11 @@ static int perf_sched__replay(struct perf_sched *sched)
3362
3367
3363
3368
sched -> thread_funcs_exit = true;
3364
3369
destroy_tasks (sched );
3365
- return 0 ;
3370
+
3371
+ out_mutex_destroy :
3372
+ mutex_destroy (& sched -> start_work_mutex );
3373
+ mutex_destroy (& sched -> work_done_wait_mutex );
3374
+ return ret ;
3366
3375
}
3367
3376
3368
3377
static void setup_sorting (struct perf_sched * sched , const struct option * options ,
@@ -3600,8 +3609,6 @@ int cmd_sched(int argc, const char **argv)
3600
3609
unsigned int i ;
3601
3610
int ret = 0 ;
3602
3611
3603
- mutex_init (& sched .start_work_mutex );
3604
- mutex_init (& sched .work_done_wait_mutex );
3605
3612
sched .curr_thread = calloc (MAX_CPUS , sizeof (* sched .curr_thread ));
3606
3613
if (!sched .curr_thread ) {
3607
3614
ret = - ENOMEM ;
@@ -3689,8 +3696,6 @@ int cmd_sched(int argc, const char **argv)
3689
3696
free (sched .curr_pid );
3690
3697
free (sched .cpu_last_switched );
3691
3698
free (sched .curr_thread );
3692
- mutex_destroy (& sched .start_work_mutex );
3693
- mutex_destroy (& sched .work_done_wait_mutex );
3694
3699
3695
3700
return ret ;
3696
3701
}
0 commit comments