Skip to content

Commit ee9a32c

Browse files
Yang Jihonggregkh
Yang Jihong
authored andcommitted
perf sched: Move start_work_mutex and work_done_wait_mutex initialization to perf_sched__replay()
[ Upstream commit c690786 ] The start_work_mutex and work_done_wait_mutex are used only for the 'perf sched replay'. Put their initialization in perf_sched__replay () to reduce unnecessary actions in other commands. Simple functional testing: # perf sched record perf bench sched messaging # Running 'sched/messaging' benchmark: # 20 sender and receiver processes per group # 10 groups == 400 processes run Total time: 0.197 [sec] [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 14.952 MB perf.data (134165 samples) ] # perf sched replay run measurement overhead: 108 nsecs sleep measurement overhead: 65658 nsecs the run test took 999991 nsecs the sleep test took 1079324 nsecs nr_run_events: 42378 nr_sleep_events: 43102 nr_wakeup_events: 31852 target-less wakeups: 17 multi-target wakeups: 712 task 0 ( swapper: 0), nr_events: 10451 task 1 ( swapper: 1), nr_events: 3 task 2 ( swapper: 2), nr_events: 1 <SNIP> task 717 ( sched-messaging: 74483), nr_events: 152 task 718 ( sched-messaging: 74484), nr_events: 1944 task 719 ( sched-messaging: 74485), nr_events: 73 task 720 ( sched-messaging: 74486), nr_events: 163 task 721 ( sched-messaging: 74487), nr_events: 942 task 722 ( sched-messaging: 74488), nr_events: 78 task 723 ( sched-messaging: 74489), nr_events: 1090 ------------------------------------------------------------ #1 : 1366.507, ravg: 1366.51, cpu: 7682.70 / 7682.70 #2 : 1410.072, ravg: 1370.86, cpu: 7723.88 / 7686.82 #3 : 1396.296, ravg: 1373.41, cpu: 7568.20 / 7674.96 #4 : 1381.019, ravg: 1374.17, cpu: 7531.81 / 7660.64 #5 : 1393.826, ravg: 1376.13, cpu: 7725.25 / 7667.11 #6 : 1401.581, ravg: 1378.68, cpu: 7594.82 / 7659.88 #7 : 1381.337, ravg: 1378.94, cpu: 7371.22 / 7631.01 #8 : 1373.842, ravg: 1378.43, cpu: 7894.92 / 7657.40 #9 : 1364.697, ravg: 1377.06, cpu: 7324.91 / 7624.15 #10 : 1363.613, ravg: 1375.72, cpu: 7209.55 / 7582.69 # echo $? 0 Signed-off-by: Yang Jihong <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Stable-dep-of: 1a5efc9 ("libsubcmd: Don't free the usage string") Signed-off-by: Sasha Levin <[email protected]>
1 parent 6ec7796 commit ee9a32c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tools/perf/builtin-sched.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -3317,15 +3317,20 @@ static int perf_sched__map(struct perf_sched *sched)
33173317

33183318
static int perf_sched__replay(struct perf_sched *sched)
33193319
{
3320+
int ret;
33203321
unsigned long i;
33213322

3323+
mutex_init(&sched->start_work_mutex);
3324+
mutex_init(&sched->work_done_wait_mutex);
3325+
33223326
calibrate_run_measurement_overhead(sched);
33233327
calibrate_sleep_measurement_overhead(sched);
33243328

33253329
test_calibrations(sched);
33263330

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;
33293334

33303335
printf("nr_run_events: %ld\n", sched->nr_run_events);
33313336
printf("nr_sleep_events: %ld\n", sched->nr_sleep_events);
@@ -3350,7 +3355,11 @@ static int perf_sched__replay(struct perf_sched *sched)
33503355

33513356
sched->thread_funcs_exit = true;
33523357
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;
33543363
}
33553364

33563365
static void setup_sorting(struct perf_sched *sched, const struct option *options,
@@ -3588,8 +3597,6 @@ int cmd_sched(int argc, const char **argv)
35883597
unsigned int i;
35893598
int ret = 0;
35903599

3591-
mutex_init(&sched.start_work_mutex);
3592-
mutex_init(&sched.work_done_wait_mutex);
35933600
sched.curr_thread = calloc(MAX_CPUS, sizeof(*sched.curr_thread));
35943601
if (!sched.curr_thread) {
35953602
ret = -ENOMEM;
@@ -3677,8 +3684,6 @@ int cmd_sched(int argc, const char **argv)
36773684
free(sched.curr_pid);
36783685
free(sched.cpu_last_switched);
36793686
free(sched.curr_thread);
3680-
mutex_destroy(&sched.start_work_mutex);
3681-
mutex_destroy(&sched.work_done_wait_mutex);
36823687

36833688
return ret;
36843689
}

0 commit comments

Comments
 (0)