public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com
Subject: Re: [PATCH 01/13] perf: Simplify perf_event_alloc() error path
Date: Wed, 15 Nov 2023 10:31:08 +0100	[thread overview]
Message-ID: <20231115093108.GA3818@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <ZUTprUojg7eHoxQI@krava>

On Fri, Nov 03, 2023 at 01:38:05PM +0100, Jiri Olsa wrote:

> > -err_callchain_buffer:
> > -	if (!event->parent) {
> > -		if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN)
> > -			put_callchain_buffers();
> > -	}
> 
> hum, so this is now called all the time via __free_event, but it should
> be called only if we passed get_callchain_buffers call.. this could screw
> up nr_callchain_events number eventually no?

Yes, good catch, thanks!

Something like the below should handle that, no?

---
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -628,14 +628,15 @@ struct swevent_hlist {
 	struct rcu_head			rcu_head;
 };
 
-#define PERF_ATTACH_CONTEXT	0x01
-#define PERF_ATTACH_GROUP	0x02
-#define PERF_ATTACH_TASK	0x04
-#define PERF_ATTACH_TASK_DATA	0x08
-#define PERF_ATTACH_ITRACE	0x10
-#define PERF_ATTACH_SCHED_CB	0x20
-#define PERF_ATTACH_CHILD	0x40
-#define PERF_ATTACH_EXCLUSIVE	0x80
+#define PERF_ATTACH_CONTEXT	0x0001
+#define PERF_ATTACH_GROUP	0x0002
+#define PERF_ATTACH_TASK	0x0004
+#define PERF_ATTACH_TASK_DATA	0x0008
+#define PERF_ATTACH_ITRACE	0x0010
+#define PERF_ATTACH_SCHED_CB	0x0020
+#define PERF_ATTACH_CHILD	0x0040
+#define PERF_ATTACH_EXCLUSIVE	0x0080
+#define PERF_ATTACH_CALLCHAIN	0x0100
 
 struct bpf_prog;
 struct perf_cgroup;
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5166,10 +5166,8 @@ static void perf_addr_filters_splice(str
 /* vs perf_event_alloc() error */
 static void __free_event(struct perf_event *event)
 {
-	if (!event->parent) {
-		if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN)
-			put_callchain_buffers();
-	}
+	if (event->attach_state & PERF_ATTACH_CALLCHAIN)
+		put_callchain_buffers();
 
 	kfree(event->addr_filter_ranges);
 
@@ -12065,6 +12063,7 @@ perf_event_alloc(struct perf_event_attr
 			err = get_callchain_buffers(attr->sample_max_stack);
 			if (err)
 				goto err;
+			event->attach_state |= PERF_ATTACH_CALLCHAIN;
 		}
 	}
 

  parent reply	other threads:[~2023-11-15  9:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02 15:09 [PATCH 00/13] perf: Employ SBRM to simplify error handling -- batch 1/3 Peter Zijlstra
2023-11-02 15:09 ` [PATCH 01/13] perf: Simplify perf_event_alloc() error path Peter Zijlstra
2023-11-03 12:38   ` Jiri Olsa
2023-11-03 19:50     ` Namhyung Kim
2023-11-15  9:58       ` Peter Zijlstra
2023-11-15 15:12         ` Namhyung Kim
2023-11-15  9:31     ` Peter Zijlstra [this message]
2023-11-02 15:09 ` [PATCH 02/13] perf: Simplify perf_pmu_register() " Peter Zijlstra
2023-11-02 15:09 ` [PATCH 03/13] perf: Simplify perf_fget_light() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 04/13] perf: Simplify event_function*() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 05/13] perf: Simplify perf_cgroup_connect() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 06/13] perf; Simplify event_sched_in() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 07/13] perf: Simplify: __perf_install_in_context() Peter Zijlstra
2023-11-04  1:08   ` Namhyung Kim
2023-11-15  9:24     ` Peter Zijlstra
2023-11-02 15:09 ` [PATCH 08/13] perf: Simplify: *perf_event_{dis,en}able*() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 09/13] perf: Simplify perf_event_modify_attr() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 10/13] perf: Simplify perf_event_context_sched_in() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 11/13] perf: Simplify perf_adjust_freq_unthr_context() Peter Zijlstra
2023-11-04  1:14   ` Namhyung Kim
2023-11-15 10:31     ` Peter Zijlstra
2023-11-02 15:09 ` [PATCH 12/13] perf: Simplify perf_event_*_on_exec() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 13/13] perf: Simplify *perf_event_read*() Peter Zijlstra

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=20231115093108.GA3818@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=olsajiri@gmail.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