@@ -3285,15 +3285,20 @@ static int perf_sched__map(struct perf_sched *sched)
3285
3285
3286
3286
static int perf_sched__replay (struct perf_sched * sched )
3287
3287
{
3288
+ int ret ;
3288
3289
unsigned long i ;
3289
3290
3291
+ mutex_init (& sched -> start_work_mutex );
3292
+ mutex_init (& sched -> work_done_wait_mutex );
3293
+
3290
3294
calibrate_run_measurement_overhead (sched );
3291
3295
calibrate_sleep_measurement_overhead (sched );
3292
3296
3293
3297
test_calibrations (sched );
3294
3298
3295
- if (perf_sched__read_events (sched ))
3296
- return -1 ;
3299
+ ret = perf_sched__read_events (sched );
3300
+ if (ret )
3301
+ goto out_mutex_destroy ;
3297
3302
3298
3303
printf ("nr_run_events: %ld\n" , sched -> nr_run_events );
3299
3304
printf ("nr_sleep_events: %ld\n" , sched -> nr_sleep_events );
@@ -3318,7 +3323,11 @@ static int perf_sched__replay(struct perf_sched *sched)
3318
3323
3319
3324
sched -> thread_funcs_exit = true;
3320
3325
destroy_tasks (sched );
3321
- return 0 ;
3326
+
3327
+ out_mutex_destroy :
3328
+ mutex_destroy (& sched -> start_work_mutex );
3329
+ mutex_destroy (& sched -> work_done_wait_mutex );
3330
+ return ret ;
3322
3331
}
3323
3332
3324
3333
static void setup_sorting (struct perf_sched * sched , const struct option * options ,
@@ -3556,8 +3565,6 @@ int cmd_sched(int argc, const char **argv)
3556
3565
unsigned int i ;
3557
3566
int ret = 0 ;
3558
3567
3559
- mutex_init (& sched .start_work_mutex );
3560
- mutex_init (& sched .work_done_wait_mutex );
3561
3568
sched .curr_thread = calloc (MAX_CPUS , sizeof (* sched .curr_thread ));
3562
3569
if (!sched .curr_thread ) {
3563
3570
ret = - ENOMEM ;
@@ -3645,8 +3652,6 @@ int cmd_sched(int argc, const char **argv)
3645
3652
free (sched .curr_pid );
3646
3653
free (sched .cpu_last_switched );
3647
3654
free (sched .curr_thread );
3648
- mutex_destroy (& sched .start_work_mutex );
3649
- mutex_destroy (& sched .work_done_wait_mutex );
3650
3655
3651
3656
return ret ;
3652
3657
}
0 commit comments