All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Howard Chu <howardchu95@gmail.com>
Cc: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com,
	jolsa@kernel.org, kan.liang@linux.intel.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/9] perf record --off-cpu: Add --off-cpu-thresh
Date: Wed, 7 Aug 2024 16:22:26 -0700	[thread overview]
Message-ID: <ZrQBsmfS-RcXmncw@google.com> (raw)
In-Reply-To: <20240807153843.3231451-3-howardchu95@gmail.com>

On Wed, Aug 07, 2024 at 11:38:36PM +0800, Howard Chu wrote:
> Add the --off-cpu-thresh argument to specify the off-cpu time threshold.
> If the off-cpu time exceeds this threshold, dump the off-cpu data
> directly.
> 
> Suggested-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Howard Chu <howardchu95@gmail.com>
> ---
>  tools/perf/builtin-record.c            | 26 ++++++++++++++++++++++++++
>  tools/perf/util/bpf_off_cpu.c          |  2 ++
>  tools/perf/util/bpf_skel/off_cpu.bpf.c |  2 ++
>  tools/perf/util/record.h               |  1 +
>  4 files changed, 31 insertions(+)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 72345d1e54b0..60c6fe7b4804 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -3133,6 +3133,28 @@ static int record__parse_mmap_pages(const struct option *opt,
>  	return ret;
>  }
>  
> +static int record__parse_off_cpu_thresh(const struct option *opt,
> +					const char *str,
> +					int unset __maybe_unused)
> +{
> +	struct record_opts *opts = opt->value;
> +	char *endptr;
> +	u64 off_cpu_thresh;
> +
> +	if (!str)
> +		return -EINVAL;
> +
> +	off_cpu_thresh = strtoul(str, &endptr, 10);
> +
> +	/* threshold isn't string "0", yet strtoull() returns 0, parsing failed. */
> +	if (*endptr || (off_cpu_thresh == 0 && strcmp(str, "0")))
> +		return -EINVAL;
> +	else
> +		opts->off_cpu_thresh = off_cpu_thresh;
> +
> +	return 0;
> +}
> +
>  void __weak arch__add_leaf_frame_record_opts(struct record_opts *opts __maybe_unused)
>  {
>  }
> @@ -3326,6 +3348,7 @@ static struct record record = {
>  		.ctl_fd              = -1,
>  		.ctl_fd_ack          = -1,
>  		.synth               = PERF_SYNTH_ALL,
> +		.off_cpu_thresh      = OFF_CPU_THRESH_DEFAULT,

Where is it defined?

Thanks,
Namhyung


>  	},
>  	.tool = {
>  		.sample		= process_sample_event,
> @@ -3560,6 +3583,9 @@ static struct option __record_options[] = {
>  	OPT_BOOLEAN(0, "off-cpu", &record.off_cpu, "Enable off-cpu analysis"),
>  	OPT_STRING(0, "setup-filter", &record.filter_action, "pin|unpin",
>  		   "BPF filter action"),
> +	OPT_CALLBACK(0, "off-cpu-thresh", &record.opts, "us",
> +		     "Dump off-cpu samples if off-cpu time reaches this threshold. The unit is microseconds. (default: 500000)",
> +		     record__parse_off_cpu_thresh),
>  	OPT_END()
>  };
>  
> diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
> index 6af36142dc5a..1e0e454bfb5e 100644
> --- a/tools/perf/util/bpf_off_cpu.c
> +++ b/tools/perf/util/bpf_off_cpu.c
> @@ -272,6 +272,8 @@ int off_cpu_prepare(struct evlist *evlist, struct target *target,
>  		}
>  	}
>  
> +	skel->bss->offcpu_thresh = opts->off_cpu_thresh * 1000ull;
> +
>  	err = off_cpu_bpf__attach(skel);
>  	if (err) {
>  		pr_err("Failed to attach off-cpu BPF skeleton\n");
> diff --git a/tools/perf/util/bpf_skel/off_cpu.bpf.c b/tools/perf/util/bpf_skel/off_cpu.bpf.c
> index d877a0a9731f..cca1b6990a57 100644
> --- a/tools/perf/util/bpf_skel/off_cpu.bpf.c
> +++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c
> @@ -96,6 +96,8 @@ const volatile bool uses_cgroup_v1 = false;
>  
>  int perf_subsys_id = -1;
>  
> +__u64 sample_id, sample_type, offcpu_thresh;
> +
>  /*
>   * Old kernel used to call it task_struct->state and now it's '__state'.
>   * Use BPF CO-RE "ignored suffix rule" to deal with it like below:
> diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h
> index a6566134e09e..3c11416e6627 100644
> --- a/tools/perf/util/record.h
> +++ b/tools/perf/util/record.h
> @@ -79,6 +79,7 @@ struct record_opts {
>  	int	      synth;
>  	int	      threads_spec;
>  	const char    *threads_user_spec;
> +	u64	      off_cpu_thresh;
>  };
>  
>  extern const char * const *record_usage;
> -- 
> 2.45.2
> 

  reply	other threads:[~2024-08-07 23:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 15:38 [PATCH v4 0/9] perf record --off-cpu: Dump off-cpu samples directly Howard Chu
2024-08-07 15:38 ` [PATCH v4 1/9] perf evsel: Set BPF output to system-wide Howard Chu
2024-08-07 23:21   ` Namhyung Kim
2024-08-08  3:58     ` Howard Chu
2024-09-25  2:53       ` Ian Rogers
2024-09-25  7:07         ` Howard Chu
2024-08-07 15:38 ` [PATCH v4 2/9] perf record --off-cpu: Add --off-cpu-thresh Howard Chu
2024-08-07 23:22   ` Namhyung Kim [this message]
2024-08-08  4:01     ` Howard Chu
2024-08-07 15:38 ` [PATCH v4 3/9] perf record --off-cpu: Parse offcpu-time event Howard Chu
2024-08-07 23:25   ` Namhyung Kim
2024-08-08  8:52     ` Howard Chu
2024-08-07 15:38 ` [PATCH v4 4/9] perf record off-cpu: Dump direct off-cpu samples in BPF Howard Chu
2024-08-07 23:49   ` Namhyung Kim
2024-08-08 11:57     ` Howard Chu
2024-08-07 15:38 ` [PATCH v4 5/9] perf record --off-cpu: Dump total off-cpu time at the end Howard Chu
2024-08-07 15:38 ` [PATCH v4 6/9] perf evsel: Delete unnecessary = 0 Howard Chu
2024-08-07 15:38 ` [PATCH v4 7/9] perf record --off-cpu: Parse BPF output embedded data Howard Chu
2024-08-07 15:38 ` [PATCH v4 8/9] perf header: Add field 'embed' Howard Chu
2024-08-07 23:52   ` Namhyung Kim
2024-08-08 13:57     ` Howard Chu
2024-08-07 15:38 ` [PATCH v4 9/9] perf test: Add direct off-cpu dumping test Howard Chu
2024-09-25  3:04 ` [PATCH v4 0/9] perf record --off-cpu: Dump off-cpu samples directly Ian Rogers
2024-09-25  6:59   ` Howard Chu

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=ZrQBsmfS-RcXmncw@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=howardchu95@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.