From: Jiri Olsa <jolsa@kernel.org>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>, Ingo Molnar <mingo@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
David Ahern <dsahern@gmail.com>, Andi Kleen <ak@linux.intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andy Lutomirski <luto@amacapital.net>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: [PATCH 07/21] perf: Add PERF_SAMPLE_USER_DATA_ID sample type
Date: Wed, 24 Jan 2018 12:51:29 +0100 [thread overview]
Message-ID: <20180124115143.14322-8-jolsa@kernel.org> (raw)
In-Reply-To: <20180124115143.14322-1-jolsa@kernel.org>
We need to add id to connect sample and user data
event in case one of them get lost. Adding new
PERF_SAMPLE_USER_DATA_ID for that purpose.
Samples mark with PERF_RECORD_MISC_USER_DATA carry
current user data ID, otherwise that field is 0.
This will be used in user space to connect samples
with USER DATA event and force proper link in cases
of lost events.
Link: http://lkml.kernel.org/n/tip-j8azyyhfgipc6mn8amfpy8hm@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/perf_event.h | 2 ++
include/linux/sched.h | 1 +
include/uapi/linux/perf_event.h | 14 +++++++++++++-
kernel/events/core.c | 21 +++++++++++++++++++++
tools/include/uapi/linux/perf_event.h | 3 ++-
5 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index b716bbca6f87..225f0787d886 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -918,6 +918,8 @@ struct perf_sample_data {
u64 stack_user_size;
u64 phys_addr;
+
+ u64 user_data_id;
} ____cacheline_aligned;
/* default value for data source */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 101c49cdde09..a2e041acfc4e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -518,6 +518,7 @@ struct perf_user_data {
u64 type;
int enabled_count;
struct mutex enabled_mutex;
+ u64 id;
};
enum perf_event_task_context {
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index f7b152a2f004..3df8024f54f1 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -141,8 +141,9 @@ enum perf_event_sample_format {
PERF_SAMPLE_TRANSACTION = 1U << 17,
PERF_SAMPLE_REGS_INTR = 1U << 18,
PERF_SAMPLE_PHYS_ADDR = 1U << 19,
+ PERF_SAMPLE_USER_DATA_ID = 1U << 20,
- PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */
+ PERF_SAMPLE_MAX = 1U << 21, /* non-ABI */
};
/*
@@ -823,6 +824,7 @@ enum perf_event_type {
* { u64 abi; # enum perf_sample_regs_abi
* u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
* { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR
+ * { u64 user_data_id;} && PERF_SAMPLE_USER_DATA_ID
* };
*/
PERF_RECORD_SAMPLE = 9,
@@ -932,6 +934,16 @@ enum perf_event_type {
* struct {
* struct perf_event_header header;
* u64 sample_type;
+ *
+ * # The sample_type value could contain following
+ * # PERF_SAMPLE_* bits:
+ * #
+ * # PERF_SAMPLE_USER_DATA_ID
+ * #
+ * # and governs the data portion:
+ *
+ * { u64 user_data_id;} && PERF_SAMPLE_USER_DATA_ID
+ *
* struct sample_id sample_id;
* };
*/
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8162cadb6736..1edf02dcd6e8 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1566,6 +1566,9 @@ static void __perf_event_header_size(struct perf_event *event, u64 sample_type)
if (sample_type & PERF_SAMPLE_PHYS_ADDR)
size += sizeof(data->phys_addr);
+ if (sample_type & PERF_SAMPLE_USER_DATA_ID)
+ size += sizeof(data->user_data_id);
+
event->header_size = size;
}
@@ -5931,6 +5934,9 @@ void perf_output_sample(struct perf_output_handle *handle,
if (sample_type & PERF_SAMPLE_PHYS_ADDR)
perf_output_put(handle, data->phys_addr);
+ if (sample_type & PERF_SAMPLE_USER_DATA_ID)
+ perf_output_put(handle, data->user_data_id);
+
if (!event->attr.watermark) {
int wakeup_events = event->attr.wakeup_events;
@@ -6152,6 +6158,9 @@ void perf_prepare_sample(struct perf_event_header *header,
if (sample_type & PERF_SAMPLE_PHYS_ADDR)
data->phys_addr = perf_virt_to_phys(data->addr);
+ if (sample_type & PERF_SAMPLE_USER_DATA_ID)
+ data->user_data_id = 0;
+
if (ud.allow && ud.type) {
struct perf_user_data *user_data = ¤t->perf_user_data;
@@ -6160,6 +6169,8 @@ void perf_prepare_sample(struct perf_event_header *header,
if (!user_data->state)
user_data->state = PERF_USER_DATA_STATE_ENABLE;
+
+ data->user_data_id = user_data->id;
}
}
@@ -6367,13 +6378,21 @@ static void perf_user_data_output(struct perf_event *event, void *data)
return;
user->event_id.type = event->attr.sample_type & user_data->type;
+ user->event_id.type |= event->attr.sample_type & PERF_SAMPLE_USER_DATA_ID;
perf_event_header__init_id(&user->event_id.header, &sample, event);
+ if (user->event_id.type & PERF_SAMPLE_USER_DATA_ID)
+ user->event_id.header.size += sizeof(u64);
+
if (perf_output_begin(&handle, event, user->event_id.header.size))
goto out;
perf_output_put(&handle, user->event_id);
+
+ if (user->event_id.type & PERF_SAMPLE_USER_DATA_ID)
+ perf_output_put(&handle, user_data->id);
+
perf_event__output_id_sample(event, &handle, &sample);
perf_output_end(&handle);
out:
@@ -6402,6 +6421,7 @@ static void perf_user_data_event(struct perf_user_data *user_data)
*/
user_data->type = 0;
user_data->state = PERF_USER_DATA_STATE_OFF;
+ user_data->id++;
}
static void perf_user_data_work(struct callback_head *work)
@@ -11124,6 +11144,7 @@ int perf_event_init_task(struct task_struct *child)
INIT_LIST_HEAD(&child->perf_event_list);
init_task_work(&child->perf_user_data.work, perf_user_data_work);
mutex_init(&child->perf_user_data.enabled_mutex);
+ child->perf_user_data.id = 0;
for_each_task_context_nr(ctxn) {
ret = perf_event_init_context(child, ctxn);
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index c77c9a2ebbbb..dea5e9c32e8a 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -141,8 +141,9 @@ enum perf_event_sample_format {
PERF_SAMPLE_TRANSACTION = 1U << 17,
PERF_SAMPLE_REGS_INTR = 1U << 18,
PERF_SAMPLE_PHYS_ADDR = 1U << 19,
+ PERF_SAMPLE_USER_DATA_ID = 1U << 20,
- PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */
+ PERF_SAMPLE_MAX = 1U << 21, /* non-ABI */
};
/*
--
2.13.6
next prev parent reply other threads:[~2018-01-24 11:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-24 11:51 [RFC 00/21] perf tools: Add perf_evsel__is_sample_bit function Jiri Olsa
2018-01-24 11:51 ` [PATCH 01/21] " Jiri Olsa
2018-01-24 11:51 ` [PATCH 02/21] perf tools: Add perf_sample__process function Jiri Olsa
2018-01-24 11:51 ` [PATCH 03/21] perf tools: Add callchain__printf for pure callchain dump Jiri Olsa
2018-01-24 11:51 ` [PATCH 04/21] perf tools: Add perf_sample__copy|free functions Jiri Olsa
2018-01-24 11:51 ` [PATCH 05/21] perf: Add TIF_PERF_USER_DATA bit Jiri Olsa
2018-01-24 11:51 ` [PATCH 06/21] perf: Add PERF_RECORD_USER_DATA event processing Jiri Olsa
2018-01-24 11:51 ` Jiri Olsa [this message]
2018-01-24 11:51 ` [PATCH 08/21] perf: Add PERF_SAMPLE_CALLCHAIN to user data event Jiri Olsa
2018-01-24 11:51 ` [PATCH 09/21] perf: Export running sample length values through debugfs Jiri Olsa
2018-01-24 11:51 ` [PATCH 10/21] perf tools: Sync perf_event.h uapi header Jiri Olsa
2018-01-24 11:51 ` [PATCH 11/21] perf tools: Add perf_sample__parse function Jiri Olsa
2018-01-24 11:51 ` [PATCH 12/21] perf tools: Add struct parse_args arg to perf_sample__parse Jiri Olsa
2018-01-24 11:51 ` [PATCH 13/21] perf tools: Add support to parse user data event Jiri Olsa
2018-01-24 11:51 ` [PATCH 14/21] perf tools: Add support to dump user data event info Jiri Olsa
2018-01-24 11:51 ` [PATCH 15/21] perf report: Add delayed user data event processing Jiri Olsa
2018-01-24 11:51 ` [PATCH 16/21] perf record: Enable delayed user data events Jiri Olsa
2018-01-24 11:51 ` [PATCH 17/21] perf script: Add support to display " Jiri Olsa
2018-01-24 11:51 ` [PATCH 18/21] perf script: Add support to display user data ID Jiri Olsa
2018-01-24 11:51 ` [PATCH 19/21] perf script: Display USER_DATA misc char for sample Jiri Olsa
2018-01-24 11:51 ` [PATCH 20/21] perf report: Add user data processing stats Jiri Olsa
2018-01-24 11:51 ` [PATCH 21/21] perf report: Add --stats=ud option to display user data debug info Jiri Olsa
2018-01-24 12:11 ` [RFC 00/21] perf tools: Add user data delayed processing Jiri Olsa
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=20180124115143.14322-8-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=dsahern@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=namhyung@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox