From: Adrian Hunter <adrian.hunter@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
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>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC 3/5] perf: Add namespaces to the sideband ioctl
Date: Fri, 14 Apr 2023 11:22:58 +0300 [thread overview]
Message-ID: <20230414082300.34798-4-adrian.hunter@intel.com> (raw)
In-Reply-To: <20230414082300.34798-1-adrian.hunter@intel.com>
Support the case of output to an active event, and return an error if
output is not possible in that case. Set PERF_RECORD_MISC_STATUS_ONLY to
differentiate the ioctl status-only sideband event from a "real" sideband
event.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
kernel/events/core.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4e76596d3bfb..ed4af231853a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8364,8 +8364,7 @@ static int perf_event_namespaces_match(struct perf_event *event)
return event->attr.namespaces;
}
-static void perf_event_namespaces_output(struct perf_event *event,
- void *data)
+static int perf_event_namespaces_output(struct perf_event *event, void *data)
{
struct perf_namespaces_event *namespaces_event = data;
struct perf_output_handle handle;
@@ -8374,7 +8373,7 @@ static void perf_event_namespaces_output(struct perf_event *event,
int ret;
if (!perf_event_namespaces_match(event))
- return;
+ return -ENOENT;
perf_event_header__init_id(&namespaces_event->event_id.header,
&sample, event);
@@ -8395,6 +8394,7 @@ static void perf_event_namespaces_output(struct perf_event *event,
perf_output_end(&handle);
out:
namespaces_event->event_id.header.size = header_size;
+ return ret;
}
static void perf_fill_ns_link_info(struct perf_ns_link_info *ns_link_info,
@@ -8414,20 +8414,20 @@ static void perf_fill_ns_link_info(struct perf_ns_link_info *ns_link_info,
}
}
-void perf_event_namespaces(struct task_struct *task)
+static int __perf_event_namespaces(struct task_struct *task, struct perf_event *event)
{
struct perf_namespaces_event namespaces_event;
struct perf_ns_link_info *ns_link_info;
if (!atomic_read(&nr_namespaces_events))
- return;
+ return -ENOENT;
namespaces_event = (struct perf_namespaces_event){
.task = task,
.event_id = {
.header = {
.type = PERF_RECORD_NAMESPACES,
- .misc = 0,
+ .misc = event ? PERF_RECORD_MISC_STATUS_ONLY : 0,
.size = sizeof(namespaces_event.event_id),
},
/* .pid */
@@ -8467,9 +8467,12 @@ void perf_event_namespaces(struct task_struct *task)
task, &cgroupns_operations);
#endif
- perf_iterate_sb(perf_event_namespaces_output,
- &namespaces_event,
- NULL);
+ return perf_output_sb(perf_event_namespaces_output, &namespaces_event, NULL, event);
+}
+
+void perf_event_namespaces(struct task_struct *task)
+{
+ __perf_event_namespaces(task, NULL);
}
/*
@@ -12880,7 +12883,10 @@ static int perf_event_emit_fork(struct perf_event *event, struct task_struct *ta
static int perf_event_emit_namespaces(struct perf_event *event, struct task_struct *task)
{
- return -EINVAL;
+ if (!event->attr.namespaces)
+ return -EINVAL;
+
+ return __perf_event_namespaces(task, event);
}
static int perf_event_emit_comm(struct perf_event *event, struct task_struct *task)
--
2.34.1
next prev parent reply other threads:[~2023-04-14 8:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-14 8:22 [PATCH RFC 0/5] perf: Add ioctl to emit sideband events Adrian Hunter
2023-04-14 8:22 ` [PATCH RFC 1/5] " Adrian Hunter
2023-04-17 10:57 ` Peter Zijlstra
2023-04-18 6:29 ` Adrian Hunter
2023-04-14 8:22 ` [PATCH RFC 2/5] perf: Add fork to the sideband ioctl Adrian Hunter
2023-04-14 8:22 ` Adrian Hunter [this message]
2023-04-14 8:22 ` [PATCH RFC 4/5] perf: Add comm " Adrian Hunter
2023-04-14 8:23 ` [PATCH RFC 5/5] perf: Add mmap " Adrian Hunter
2023-04-17 11:02 ` [PATCH RFC 0/5] perf: Add ioctl to emit sideband events Peter Zijlstra
2023-04-17 16:37 ` Ian Rogers
2023-04-18 7:03 ` Adrian Hunter
2023-04-18 6:18 ` Adrian Hunter
2023-04-18 13:36 ` Adrian Hunter
2023-04-18 15:51 ` Ian Rogers
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=20230414082300.34798-4-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.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).