@@ -3167,14 +3167,44 @@ static void perf_sched__merge_lat(struct perf_sched *sched)
3167
3167
}
3168
3168
}
3169
3169
3170
+ static int setup_cpus_switch_event (struct perf_sched * sched )
3171
+ {
3172
+ unsigned int i ;
3173
+
3174
+ sched -> cpu_last_switched = calloc (MAX_CPUS , sizeof (* (sched -> cpu_last_switched )));
3175
+ if (!sched -> cpu_last_switched )
3176
+ return -1 ;
3177
+
3178
+ sched -> curr_pid = malloc (MAX_CPUS * sizeof (* (sched -> curr_pid )));
3179
+ if (!sched -> curr_pid ) {
3180
+ zfree (& sched -> cpu_last_switched );
3181
+ return -1 ;
3182
+ }
3183
+
3184
+ for (i = 0 ; i < MAX_CPUS ; i ++ )
3185
+ sched -> curr_pid [i ] = -1 ;
3186
+
3187
+ return 0 ;
3188
+ }
3189
+
3190
+ static void free_cpus_switch_event (struct perf_sched * sched )
3191
+ {
3192
+ zfree (& sched -> curr_pid );
3193
+ zfree (& sched -> cpu_last_switched );
3194
+ }
3195
+
3170
3196
static int perf_sched__lat (struct perf_sched * sched )
3171
3197
{
3198
+ int rc = -1 ;
3172
3199
struct rb_node * next ;
3173
3200
3174
3201
setup_pager ();
3175
3202
3203
+ if (setup_cpus_switch_event (sched ))
3204
+ return rc ;
3205
+
3176
3206
if (perf_sched__read_events (sched ))
3177
- return -1 ;
3207
+ goto out_free_cpus_switch_event ;
3178
3208
3179
3209
perf_sched__merge_lat (sched );
3180
3210
perf_sched__sort_lat (sched );
@@ -3203,7 +3233,11 @@ static int perf_sched__lat(struct perf_sched *sched)
3203
3233
print_bad_events (sched );
3204
3234
printf ("\n" );
3205
3235
3206
- return 0 ;
3236
+ rc = 0 ;
3237
+
3238
+ out_free_cpus_switch_event :
3239
+ free_cpus_switch_event (sched );
3240
+ return rc ;
3207
3241
}
3208
3242
3209
3243
static int setup_map_cpus (struct perf_sched * sched )
@@ -3270,9 +3304,12 @@ static int perf_sched__map(struct perf_sched *sched)
3270
3304
if (!sched -> curr_thread )
3271
3305
return rc ;
3272
3306
3273
- if (setup_map_cpus (sched ))
3307
+ if (setup_cpus_switch_event (sched ))
3274
3308
goto out_free_curr_thread ;
3275
3309
3310
+ if (setup_map_cpus (sched ))
3311
+ goto out_free_cpus_switch_event ;
3312
+
3276
3313
if (setup_color_pids (sched ))
3277
3314
goto out_put_map_cpus ;
3278
3315
@@ -3296,6 +3333,9 @@ static int perf_sched__map(struct perf_sched *sched)
3296
3333
zfree (& sched -> map .comp_cpus );
3297
3334
perf_cpu_map__put (sched -> map .cpus );
3298
3335
3336
+ out_free_cpus_switch_event :
3337
+ free_cpus_switch_event (sched );
3338
+
3299
3339
out_free_curr_thread :
3300
3340
zfree (& sched -> curr_thread );
3301
3341
return rc ;
@@ -3309,14 +3349,18 @@ static int perf_sched__replay(struct perf_sched *sched)
3309
3349
mutex_init (& sched -> start_work_mutex );
3310
3350
mutex_init (& sched -> work_done_wait_mutex );
3311
3351
3352
+ ret = setup_cpus_switch_event (sched );
3353
+ if (ret )
3354
+ goto out_mutex_destroy ;
3355
+
3312
3356
calibrate_run_measurement_overhead (sched );
3313
3357
calibrate_sleep_measurement_overhead (sched );
3314
3358
3315
3359
test_calibrations (sched );
3316
3360
3317
3361
ret = perf_sched__read_events (sched );
3318
3362
if (ret )
3319
- goto out_mutex_destroy ;
3363
+ goto out_free_cpus_switch_event ;
3320
3364
3321
3365
printf ("nr_run_events: %ld\n" , sched -> nr_run_events );
3322
3366
printf ("nr_sleep_events: %ld\n" , sched -> nr_sleep_events );
@@ -3342,6 +3386,9 @@ static int perf_sched__replay(struct perf_sched *sched)
3342
3386
sched -> thread_funcs_exit = true;
3343
3387
destroy_tasks (sched );
3344
3388
3389
+ out_free_cpus_switch_event :
3390
+ free_cpus_switch_event (sched );
3391
+
3345
3392
out_mutex_destroy :
3346
3393
mutex_destroy (& sched -> start_work_mutex );
3347
3394
mutex_destroy (& sched -> work_done_wait_mutex );
@@ -3580,21 +3627,7 @@ int cmd_sched(int argc, const char **argv)
3580
3627
.switch_event = replay_switch_event ,
3581
3628
.fork_event = replay_fork_event ,
3582
3629
};
3583
- unsigned int i ;
3584
- int ret = 0 ;
3585
-
3586
- sched .cpu_last_switched = calloc (MAX_CPUS , sizeof (* sched .cpu_last_switched ));
3587
- if (!sched .cpu_last_switched ) {
3588
- ret = - ENOMEM ;
3589
- goto out ;
3590
- }
3591
- sched .curr_pid = malloc (MAX_CPUS * sizeof (* sched .curr_pid ));
3592
- if (!sched .curr_pid ) {
3593
- ret = - ENOMEM ;
3594
- goto out ;
3595
- }
3596
- for (i = 0 ; i < MAX_CPUS ; i ++ )
3597
- sched .curr_pid [i ] = -1 ;
3630
+ int ret ;
3598
3631
3599
3632
argc = parse_options_subcommand (argc , argv , sched_options , sched_subcommands ,
3600
3633
sched_usage , PARSE_OPT_STOP_AT_NON_OPTION );
@@ -3605,9 +3638,9 @@ int cmd_sched(int argc, const char **argv)
3605
3638
* Aliased to 'perf script' for now:
3606
3639
*/
3607
3640
if (!strcmp (argv [0 ], "script" )) {
3608
- ret = cmd_script (argc , argv );
3641
+ return cmd_script (argc , argv );
3609
3642
} else if (strlen (argv [0 ]) > 2 && strstarts ("record" , argv [0 ])) {
3610
- ret = __cmd_record (argc , argv );
3643
+ return __cmd_record (argc , argv );
3611
3644
} else if (strlen (argv [0 ]) > 2 && strstarts ("latency" , argv [0 ])) {
3612
3645
sched .tp_handler = & lat_ops ;
3613
3646
if (argc > 1 ) {
@@ -3616,7 +3649,7 @@ int cmd_sched(int argc, const char **argv)
3616
3649
usage_with_options (latency_usage , latency_options );
3617
3650
}
3618
3651
setup_sorting (& sched , latency_options , latency_usage );
3619
- ret = perf_sched__lat (& sched );
3652
+ return perf_sched__lat (& sched );
3620
3653
} else if (!strcmp (argv [0 ], "map" )) {
3621
3654
if (argc ) {
3622
3655
argc = parse_options (argc , argv , map_options , map_usage , 0 );
@@ -3625,15 +3658,15 @@ int cmd_sched(int argc, const char **argv)
3625
3658
}
3626
3659
sched .tp_handler = & map_ops ;
3627
3660
setup_sorting (& sched , latency_options , latency_usage );
3628
- ret = perf_sched__map (& sched );
3661
+ return perf_sched__map (& sched );
3629
3662
} else if (strlen (argv [0 ]) > 2 && strstarts ("replay" , argv [0 ])) {
3630
3663
sched .tp_handler = & replay_ops ;
3631
3664
if (argc ) {
3632
3665
argc = parse_options (argc , argv , replay_options , replay_usage , 0 );
3633
3666
if (argc )
3634
3667
usage_with_options (replay_usage , replay_options );
3635
3668
}
3636
- ret = perf_sched__replay (& sched );
3669
+ return perf_sched__replay (& sched );
3637
3670
} else if (!strcmp (argv [0 ], "timehist" )) {
3638
3671
if (argc ) {
3639
3672
argc = parse_options (argc , argv , timehist_options ,
@@ -3649,21 +3682,16 @@ int cmd_sched(int argc, const char **argv)
3649
3682
parse_options_usage (NULL , timehist_options , "w" , true);
3650
3683
if (sched .show_next )
3651
3684
parse_options_usage (NULL , timehist_options , "n" , true);
3652
- ret = - EINVAL ;
3653
- goto out ;
3685
+ return - EINVAL ;
3654
3686
}
3655
3687
ret = symbol__validate_sym_arguments ();
3656
3688
if (ret )
3657
- goto out ;
3689
+ return ret ;
3658
3690
3659
- ret = perf_sched__timehist (& sched );
3691
+ return perf_sched__timehist (& sched );
3660
3692
} else {
3661
3693
usage_with_options (sched_usage , sched_options );
3662
3694
}
3663
3695
3664
- out :
3665
- free (sched .curr_pid );
3666
- free (sched .cpu_last_switched );
3667
-
3668
- return ret ;
3696
+ return 0 ;
3669
3697
}
0 commit comments