From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Yang Jihong <yangjihong1@huawei.com>
Cc: peterz@infradead.org, mingo@redhat.com, namhyung@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] perf sched: Move curr_thread initialization to perf_sched__map()
Date: Mon, 5 Feb 2024 15:59:53 -0300 [thread overview]
Message-ID: <ZcEwKf8Jmd6yciWa@x1> (raw)
In-Reply-To: <20240205104616.132417-4-yangjihong1@huawei.com>
On Mon, Feb 05, 2024 at 10:46:14AM +0000, Yang Jihong wrote:
> 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 <yangjihong1@huawei.com>
> ---
> tools/perf/builtin-sched.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index 26dbfa4aab61..54d79e560617 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -3266,9 +3266,13 @@ static int perf_sched__map(struct perf_sched *sched)
> {
> int rc = -1;
>
> - if (setup_map_cpus(sched))
> + sched->curr_thread = calloc(MAX_CPUS, sizeof(*(sched->curr_thread)));
> + if (!sched->curr_thread)
> return rc;
>
> + if (setup_map_cpus(sched))
> + goto out_free_curr_thread;
> +
> if (setup_color_pids(sched))
> goto out_free_map_cpus;
>
> @@ -3291,6 +3295,9 @@ static int perf_sched__map(struct perf_sched *sched)
> out_free_map_cpus:
> free(sched->map.comp_cpus);
> perf_cpu_map__put(sched->map.cpus);
> +
> +out_free_curr_thread:
> + free(sched->curr_thread);
zfree(&sched->curr_thread);
> return rc;
> }
>
> @@ -3576,11 +3583,6 @@ int cmd_sched(int argc, const char **argv)
> unsigned int i;
> int ret = 0;
>
> - sched.curr_thread = calloc(MAX_CPUS, sizeof(*sched.curr_thread));
> - if (!sched.curr_thread) {
> - ret = -ENOMEM;
> - goto out;
> - }
> sched.cpu_last_switched = calloc(MAX_CPUS, sizeof(*sched.cpu_last_switched));
> if (!sched.cpu_last_switched) {
> ret = -ENOMEM;
> @@ -3662,7 +3664,6 @@ int cmd_sched(int argc, const char **argv)
> out:
> free(sched.curr_pid);
> free(sched.cpu_last_switched);
> - free(sched.curr_thread);
>
> return ret;
> }
> --
> 2.34.1
next prev parent reply other threads:[~2024-02-05 18:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 10:46 [PATCH 0/5] perf sched: Minor optimizations for resource initialization Yang Jihong
2024-02-05 10:46 ` [PATCH 1/5] perf sched: Move start_work_mutex and work_done_wait_mutex initialization to perf_sched__replay() Yang Jihong
2024-02-05 10:46 ` [PATCH 2/5] perf sched: Fix memory leak in perf_sched__map() Yang Jihong
2024-02-05 18:58 ` Arnaldo Carvalho de Melo
2024-02-06 7:08 ` Yang Jihong
2024-02-05 10:46 ` [PATCH 3/5] perf sched: Move curr_thread initialization to perf_sched__map() Yang Jihong
2024-02-05 18:59 ` Arnaldo Carvalho de Melo [this message]
2024-02-05 10:46 ` [PATCH 4/5] perf sched: Move curr_pid and cpu_last_switched initialization to perf_sched__{lat|map|replay}() Yang Jihong
2024-02-05 19:01 ` Arnaldo Carvalho de Melo
2024-02-05 10:46 ` [PATCH 5/5] perf thread_map: Free strlist on normal path in thread_map__new_by_tid_str() Yang Jihong
2024-02-05 19:09 ` Arnaldo Carvalho de Melo
2024-02-06 7:10 ` Yang Jihong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZcEwKf8Jmd6yciWa@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=yangjihong1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox