All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org, Song Liu <song@kernel.org>,
	bpf@vger.kernel.org
Subject: Re: [PATCH 1/3] perf lock contention: Handle error in a single place
Date: Fri, 30 Aug 2024 10:17:32 -0300	[thread overview]
Message-ID: <ZtHGbFyJYLzzVRou@x1> (raw)
In-Reply-To: <20240830065150.1758962-1-namhyung@kernel.org>

On Thu, Aug 29, 2024 at 11:51:48PM -0700, Namhyung Kim wrote:
> It has some duplicate codes to do the same job.  Let's add a label and
> goto there to handle errors in a single place.

Thanks, applied to perf-tools-next,

- Arnaldo
 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/bpf_skel/lock_contention.bpf.c | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/perf/util/bpf_skel/lock_contention.bpf.c b/tools/perf/util/bpf_skel/lock_contention.bpf.c
> index d931a898c434..e8a6f6463019 100644
> --- a/tools/perf/util/bpf_skel/lock_contention.bpf.c
> +++ b/tools/perf/util/bpf_skel/lock_contention.bpf.c
> @@ -439,11 +439,8 @@ int contention_end(u64 *ctx)
>  
>  	duration = bpf_ktime_get_ns() - pelem->timestamp;
>  	if ((__s64)duration < 0) {
> -		pelem->lock = 0;
> -		if (need_delete)
> -			bpf_map_delete_elem(&tstamp, &pid);
>  		__sync_fetch_and_add(&time_fail, 1);
> -		return 0;
> +		goto out;
>  	}
>  
>  	switch (aggr_mode) {
> @@ -477,11 +474,8 @@ int contention_end(u64 *ctx)
>  	data = bpf_map_lookup_elem(&lock_stat, &key);
>  	if (!data) {
>  		if (data_map_full) {
> -			pelem->lock = 0;
> -			if (need_delete)
> -				bpf_map_delete_elem(&tstamp, &pid);
>  			__sync_fetch_and_add(&data_fail, 1);
> -			return 0;
> +			goto out;
>  		}
>  
>  		struct contention_data first = {
> @@ -502,10 +496,7 @@ int contention_end(u64 *ctx)
>  				data_map_full = 1;
>  			__sync_fetch_and_add(&data_fail, 1);
>  		}
> -		pelem->lock = 0;
> -		if (need_delete)
> -			bpf_map_delete_elem(&tstamp, &pid);
> -		return 0;
> +		goto out;
>  	}
>  
>  	__sync_fetch_and_add(&data->total_time, duration);
> @@ -517,6 +508,7 @@ int contention_end(u64 *ctx)
>  	if (data->min_time > duration)
>  		data->min_time = duration;
>  
> +out:
>  	pelem->lock = 0;
>  	if (need_delete)
>  		bpf_map_delete_elem(&tstamp, &pid);
> -- 
> 2.46.0.469.g59c65b2a67-goog

      parent reply	other threads:[~2024-08-30 13:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-30  6:51 [PATCH 1/3] perf lock contention: Handle error in a single place Namhyung Kim
2024-08-30  6:51 ` [PATCH 2/3] perf lock contention: Simplify spinlock check Namhyung Kim
2024-08-30  6:51 ` [PATCH 3/3] perf lock contention: Do not fail EEXIST for update Namhyung Kim
2024-08-30 13:17 ` Arnaldo Carvalho de Melo [this message]

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=ZtHGbFyJYLzzVRou@x1 \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=bpf@vger.kernel.org \
    --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 \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=song@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.