linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yang Jihong <yangjihong1@huawei.com>
To: James Clark <james.clark@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-perf-users <linux-perf-users@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [RFC] Adding support for setting the affinity of the recording process
Date: Tue, 13 Jun 2023 10:28:14 +0800	[thread overview]
Message-ID: <c291692c-7db8-b4cc-e17a-422c75ad8daa@huawei.com> (raw)
In-Reply-To: <a24634f7-be80-6ca2-9df7-1624fe11c281@arm.com>

Hello,

On 2023/6/12 23:27, James Clark wrote:
> 
> 
> On 12/06/2023 11:26, Yang Jihong wrote:
>> Hello everyone,
>>
>> Currently, perf-record supports profiling an existing process, thread,
>> or a specified command.
>>
>> Sometimes we may need to set CPU affinity of the target process before
>> recording:
>>
>>    # taskset -pc <cpus> <pid>
>>    # perf record -p <pid> -- sleep 10
>>
>> or:
>>
>>    # perf record -- `taskset -c <cpus> COMMAND`
>>
>> I'm thinking about getting perf to support setting the affinity of the
>> recording process, for example:
>>
>> 1. set the CPU affinity of the <pid1> process to <cpus1>, <pid2> process
>> to <cpus2>,  and record:
>>
>>    # perf record -p <pid1>/<cpus1>:<pid2>/<cpus2> -- sleep 10
>>
> 
> I'm not sure if this is necessary. You can already do this with taskset
> when you launch the processes or for existing ones.

Yes, that's what we're doing now, and I'm thinking about whether perf 
can support this "taskset" feature.

> 
>> and
>>
>> 2. set CPU affinity of the COMMAND and record:
>>
>>    # perf record --taskset-command <cpus> COMMAND
>>
>> In doing so, perf, as an observer, actually changes some of the
>> properties of the target process, which may be contrary to the purpose
>> of perf tool.
>>
>>
>> Will we consider accepting this approach?
>>
> 
> For #2 I do this sometimes, but I prefix the perf command with taskset
> because otherwise there is a small time between when taskset does its
> thing and launching the child process that it runs in the wrong place.
> 
> Then one issue with the above method is that perf itself gets pinned to
> those CPUs as well. I suppose that could influence your application but
> I've never had an issue with it.
> 
> If you really can't live with perf also being pinned to those CPUs I
> would say it makes sense to add options for #2. Otherwise I would just
> run everything under taskset and no changes are needed.

If "perf" process and the target process are pinned to the same CPU, 
and the CPU usage of the target process is high, the perf data 
collection may be affected. Therefore, in this case, we may need to pin 
the target process and "perf" to different CPUs.

> 
> I think you would still need to have perf itself pinned to the CPUs just
> before it does the fork and exec, and then after that it can undo its
> pinning. Otherwise you'd still get that small time running on the wrong
> cores.
>

Thanks for your advice, or we can support setting different affinities 
for the "perf" process and the target process.


Thanks,
Yang.

  reply	other threads:[~2023-06-13  2:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 10:26 [RFC] Adding support for setting the affinity of the recording process Yang Jihong
2023-06-12 14:24 ` Arnaldo Carvalho de Melo
2023-06-12 15:05   ` Peter Zijlstra
2023-06-13  2:11     ` Yang Jihong
2023-06-13  2:03   ` Yang Jihong
2023-06-12 15:27 ` James Clark
2023-06-13  2:28   ` Yang Jihong [this message]
2023-06-13  5:50     ` Namhyung Kim
2023-06-13  7:03       ` 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=c291692c-7db8-b4cc-e17a-422c75ad8daa@huawei.com \
    --to=yangjihong1@huawei.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.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 \
    /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;
as well as URLs for NNTP newsgroup(s).