public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Sapkal, Swapnil" <swapnil.sapkal@amd.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<irogers@google.com>, <james.clark@arm.com>,
	<ravi.bangoria@amd.com>, <yu.c.chen@intel.com>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@kernel.org>, <rostedt@goodmis.org>,
	<vincent.guittot@linaro.org>, <adrian.hunter@intel.com>,
	<kan.liang@linux.intel.com>, <gautham.shenoy@amd.com>,
	<kprateek.nayak@amd.com>, <juri.lelli@redhat.com>,
	<yangjihong@bytedance.com>, <void@manifault.com>, <tj@kernel.org>,
	<sshegde@linux.ibm.com>, <linux-kernel@vger.kernel.org>,
	<linux-perf-users@vger.kernel.org>, <santosh.shukla@amd.com>,
	<ananth.narayan@amd.com>, <sandipan.das@amd.com>,
	James Clark <james.clark@linaro.org>
Subject: Re: [PATCH v3 5/8] perf sched stats: Add support for live mode
Date: Mon, 24 Mar 2025 14:45:51 +0530	[thread overview]
Message-ID: <01671eda-c8f3-4093-a782-2c73b4a73b12@amd.com> (raw)
In-Reply-To: <Z9UGEaypiEbOuhHv@google.com>

Hi Namhyung,

Sorry for the delay in response.

On 3/15/2025 10:16 AM, Namhyung Kim wrote:
> On Tue, Mar 11, 2025 at 12:02:27PM +0000, Swapnil Sapkal wrote:
>> The live mode works similar to simple `perf stat` command, by profiling
>> the target and printing results on the terminal as soon as the target
>> finishes.
>>
>> Example usage:
>>
>>    # perf sched stats -- sleep 10
>>
>> Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
>> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
>> Tested-by: James Clark <james.clark@linaro.org>
>> Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
>> ---
>>   tools/perf/builtin-sched.c | 87 +++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 86 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
>> index e2e7dbc4f0aa..9813e25b54b8 100644
>> --- a/tools/perf/builtin-sched.c
>> +++ b/tools/perf/builtin-sched.c
>> @@ -4364,6 +4364,91 @@ static int perf_sched__schedstat_report(struct perf_sched *sched)
>>   	return err;
>>   }
>>   
>> +static int process_synthesized_event_live(const struct perf_tool *tool __maybe_unused,
>> +					  union perf_event *event,
>> +					  struct perf_sample *sample __maybe_unused,
>> +					  struct machine *machine __maybe_unused)
>> +{
>> +	return perf_sched__process_schedstat(NULL, event);
>> +}
>> +
>> +static int perf_sched__schedstat_live(struct perf_sched *sched,
>> +				      int argc, const char **argv)
>> +{
>> +	struct evlist *evlist;
>> +	struct target *target;
>> +	int reset = 0;
>> +	int err = 0;
>> +
>> +	signal(SIGINT, sighandler);
>> +	signal(SIGCHLD, sighandler);
>> +	signal(SIGTERM, sighandler);
>> +
>> +	evlist = evlist__new();
>> +	if (!evlist)
>> +		return -ENOMEM;
>> +
>> +	/*
>> +	 * `perf sched schedstat` does not support workload profiling (-p pid)
>> +	 * since /proc/schedstat file contains cpu specific data only. Hence, a
>> +	 * profile target is either set of cpus or systemwide, never a process.
>> +	 * Note that, although `-- <workload>` is supported, profile data are
>> +	 * still cpu/systemwide.
>> +	 */
>> +	target = zalloc(sizeof(struct target));
> 
> As I said, you can put it on stack.
> 

Sure.

> 
>> +	if (cpu_list)
>> +		target->cpu_list = cpu_list;
>> +	else
>> +		target->system_wide = true;
>> +
>> +	if (argc) {
>> +		err = evlist__prepare_workload(evlist, target, argv, false, NULL);
>> +		if (err)
>> +			goto out_target;
>> +	}
>> +
>> +	if (cpu_list) {
>> +		user_requested_cpus = perf_cpu_map__new(cpu_list);
>> +		if (!user_requested_cpus)
>> +			goto out_target;
>> +	}
> 
> How about this instead?
> 
> 	evlist__create_maps(evlist, target);
> 

Sure, will use evlist__create_maps(evlist, target).

>> +
>> +	err = perf_event__synthesize_schedstat(&(sched->tool),
>> +					       process_synthesized_event_live,
>> +					       user_requested_cpus);
>> +	if (err < 0)
>> +		goto out_target;
>> +
>> +	err = enable_sched_schedstats(&reset);
>> +	if (err < 0)
>> +		goto out_target;
>> +
>> +	if (argc)
>> +		evlist__start_workload(evlist);
>> +
>> +	/* wait for signal */
>> +	pause();
>> +
>> +	if (reset) {
>> +		err = disable_sched_schedstat();
>> +		if (err < 0)
>> +			goto out_target;
>> +	}
>> +
>> +	err = perf_event__synthesize_schedstat(&(sched->tool),
>> +					       process_synthesized_event_live,
>> +					       user_requested_cpus);
>> +	if (err)
>> +		goto out_target;
>> +
>> +	setup_pager();
>> +	show_schedstat_data(cpu_head);
>> +	free_schedstat(cpu_head);
>> +out_target:
>> +	free(target);
> 
> 	evlist__delete(evlist);
> 
> and unless you use evlist__create_maps().
> 

Ack.

> 	perf_cpu_map__put(user_requested_cpus);
> 
> Thanks,
> Namhyung
> 
> 
>> +	return err;
>> +}
>> +
>>   static bool schedstat_events_exposed(void)
>>   {
>>   	/*
>> @@ -4686,7 +4771,7 @@ int cmd_sched(int argc, const char **argv)
>>   						     stats_usage, 0);
>>   			return perf_sched__schedstat_report(&sched);
>>   		}
>> -		usage_with_options(stats_usage, stats_options);
>> +		return perf_sched__schedstat_live(&sched, argc, argv);
>>   	} else {
>>   		usage_with_options(sched_usage, sched_options);
>>   	}
>> -- 
>> 2.43.0
>>
--
Thanks and Regards,
Swapnil

  reply	other threads:[~2025-03-24  9:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 12:02 [PATCH v3 0/8] perf sched: Introduce stats tool Swapnil Sapkal
2025-03-11 12:02 ` [PATCH v3 1/8] perf sched stats: Add record and rawdump support Swapnil Sapkal
2025-03-11 13:10   ` Markus Elfring
2025-03-11 16:19   ` Markus Elfring
2025-03-15  2:24   ` Namhyung Kim
2025-03-17 13:29     ` Sapkal, Swapnil
2025-03-11 12:02 ` [PATCH v3 2/8] perf sched stats: Add schedstat v16 support Swapnil Sapkal
2025-03-11 12:02 ` [PATCH v3 3/8] perf sched stats: Add schedstat v17 support Swapnil Sapkal
2025-03-15  2:27   ` Namhyung Kim
2025-03-17 13:32     ` Sapkal, Swapnil
2025-03-11 12:02 ` [PATCH v3 4/8] perf sched stats: Add support for report subcommand Swapnil Sapkal
2025-03-15  4:39   ` Namhyung Kim
2025-03-18 11:08     ` Sapkal, Swapnil
2025-05-20 10:36   ` Peter Zijlstra
2025-05-21  5:32     ` Sapkal, Swapnil
2025-03-11 12:02 ` [PATCH v3 5/8] perf sched stats: Add support for live mode Swapnil Sapkal
2025-03-15  4:46   ` Namhyung Kim
2025-03-24  9:15     ` Sapkal, Swapnil [this message]
2025-03-11 12:02 ` [PATCH v3 6/8] perf sched stats: Add support for diff subcommand Swapnil Sapkal
2025-03-11 12:02 ` [PATCH v3 7/8] perf sched stats: Add basic perf sched stats test Swapnil Sapkal
2025-03-11 12:02 ` [PATCH v3 8/8] perf sched stats: Add details in man page Swapnil Sapkal
2025-04-10  9:41 ` [PATCH v3 0/8] perf sched: Introduce stats tool Chen, Yu C
2025-04-10 10:29   ` Sapkal, Swapnil

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=01671eda-c8f3-4093-a782-2c73b4a73b12@amd.com \
    --to=swapnil.sapkal@amd.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ananth.narayan@amd.com \
    --cc=gautham.shenoy@amd.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=kprateek.nayak@amd.com \
    --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=ravi.bangoria@amd.com \
    --cc=rostedt@goodmis.org \
    --cc=sandipan.das@amd.com \
    --cc=santosh.shukla@amd.com \
    --cc=sshegde@linux.ibm.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=yangjihong@bytedance.com \
    --cc=yu.c.chen@intel.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