Skip to content

Commit 4d2df69

Browse files
Yang Jihonggregkh
Yang Jihong
authored andcommitted
perf sched: Move curr_thread initialization to perf_sched__map()
[ Upstream commit 5e89527 ] The curr_thread is used only for the 'perf sched map'. Put initialization in perf_sched__map() 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 15.526 MB perf.data (140095 samples) ] # perf sched map *A0 451264.532445 secs A0 => migration/0:15 *. 451264.532468 secs . => swapper:0 . *B0 451264.532537 secs B0 => migration/1:21 . *. 451264.532560 secs . . *C0 451264.532644 secs C0 => migration/2:27 . . *. 451264.532668 secs . . . *D0 451264.532753 secs D0 => migration/3:33 . . . *. 451264.532778 secs . . . . *E0 451264.532861 secs E0 => migration/4:39 . . . . *. 451264.532886 secs . . . . . *F0 451264.532973 secs F0 => migration/5:45 <SNIP> A7 A7 A7 A7 A7 *A7 . . . . . . . . . . 451264.790785 secs A7 A7 A7 A7 A7 A7 *A7 . . . . . . . . . 451264.790858 secs A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . . . 451264.790934 secs A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . . 451264.791004 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . . 451264.791075 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . . 451264.791143 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . . 451264.791232 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . . 451264.791336 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . . 451264.791407 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 . 451264.791484 secs A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 A7 *A7 451264.791553 secs # 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 f231623 commit 4d2df69

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tools/perf/builtin-sched.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -3298,9 +3298,13 @@ static int perf_sched__map(struct perf_sched *sched)
32983298
{
32993299
int rc = -1;
33003300

3301-
if (setup_map_cpus(sched))
3301+
sched->curr_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_thread)));
3302+
if (!sched->curr_thread)
33023303
return rc;
33033304

3305+
if (setup_map_cpus(sched))
3306+
goto out_free_curr_thread;
3307+
33043308
if (setup_color_pids(sched))
33053309
goto out_put_map_cpus;
33063310

@@ -3323,6 +3327,9 @@ static int perf_sched__map(struct perf_sched *sched)
33233327
out_put_map_cpus:
33243328
zfree(&sched->map.comp_cpus);
33253329
perf_cpu_map__put(sched->map.cpus);
3330+
3331+
out_free_curr_thread:
3332+
zfree(&sched->curr_thread);
33263333
return rc;
33273334
}
33283335

@@ -3608,11 +3615,6 @@ int cmd_sched(int argc, const char **argv)
36083615
unsigned int i;
36093616
int ret = 0;
36103617

3611-
sched.curr_thread = calloc(MAX_CPUS, sizeof(*sched.curr_thread));
3612-
if (!sched.curr_thread) {
3613-
ret = -ENOMEM;
3614-
goto out;
3615-
}
36163618
sched.cpu_last_switched = calloc(MAX_CPUS, sizeof(*sched.cpu_last_switched));
36173619
if (!sched.cpu_last_switched) {
36183620
ret = -ENOMEM;
@@ -3694,7 +3696,6 @@ int cmd_sched(int argc, const char **argv)
36943696
out:
36953697
free(sched.curr_pid);
36963698
free(sched.cpu_last_switched);
3697-
free(sched.curr_thread);
36983699

36993700
return ret;
37003701
}

0 commit comments

Comments
 (0)