lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210622153918.688500-5-jolsa@kernel.org>
Date:   Tue, 22 Jun 2021 17:39:12 +0200
From:   Jiri Olsa <jolsa@...hat.com>
To:     Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:     lkml <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Ingo Molnar <mingo@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Namhyung Kim <namhyung@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Michael Petlan <mpetlan@...hat.com>,
        Ian Rogers <irogers@...gle.com>
Subject: [PATCH 04/10] perf: Add new read_format bit to read lost events

It's now possible to retrieve lost stats by read
syscall on events.

Adding PERF_FORMAT_LOST read_format bit to get the
value of lost events through the read syscall.

Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
 include/linux/perf_event.h      |  1 +
 include/uapi/linux/perf_event.h |  5 ++++-
 kernel/events/core.c            | 21 ++++++++++++++++++---
 kernel/events/ring_buffer.c     |  3 +++
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 5110a998f59b..209c66a01797 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -670,6 +670,7 @@ struct perf_event {
 	local64_t			count;
 	atomic64_t			child_count;
 	local64_t			build_id_faults;
+	local64_t			lost;
 
 	/*
 	 * These are the total time in nanoseconds that the event
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 2424ba7f95fb..e742c8f43a18 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -300,6 +300,7 @@ enum {
  *	  { u64		time_running;    } && PERF_FORMAT_TOTAL_TIME_RUNNING
  *	  { u64		id;              } && PERF_FORMAT_ID
  *	  { u64		build_id_faults; } && PERF_FORMAT_BUILD_ID_FAULTS
+ *	  { u64		lost;            } && PERF_FORMAT_LOST
  *	} && !PERF_FORMAT_GROUP
  *
  *	{ u64		nr;
@@ -308,6 +309,7 @@ enum {
  *	  { u64		value;
  *	    { u64	id;              } && PERF_FORMAT_ID
  *	    { u64	build_id_faults; } && PERF_FORMAT_BUILD_ID_FAULTS
+ *	    { u64	lost;            } && PERF_FORMAT_LOST
  *	  }		cntr[nr];
  *	} && PERF_FORMAT_GROUP
  * };
@@ -318,8 +320,9 @@ enum perf_event_read_format {
 	PERF_FORMAT_ID				= 1U << 2,
 	PERF_FORMAT_GROUP			= 1U << 3,
 	PERF_FORMAT_BUILD_ID_FAULTS		= 1U << 4,
+	PERF_FORMAT_LOST			= 1U << 5,
 
-	PERF_FORMAT_MAX = 1U << 5,		/* non-ABI */
+	PERF_FORMAT_MAX = 1U << 6,		/* non-ABI */
 };
 
 #define PERF_ATTR_SIZE_VER0	64	/* sizeof first published struct */
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f3cd06012115..ba02ce9e9134 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1843,6 +1843,9 @@ static void __perf_event_read_size(struct perf_event *event, int nr_siblings)
 	if (event->attr.read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 		entry += sizeof(u64);
 
+	if (event->attr.read_format & PERF_FORMAT_LOST)
+		entry += sizeof(u64);
+
 	if (event->attr.read_format & PERF_FORMAT_GROUP) {
 		nr += nr_siblings;
 		size += sizeof(u64);
@@ -5252,6 +5255,8 @@ static int __perf_read_group_add(struct perf_event *leader,
 		values[n++] = primary_event_id(leader);
 	if (read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 		values[n++] = local64_read(&leader->build_id_faults);
+	if (read_format & PERF_FORMAT_LOST)
+		values[n++] = local64_read(&leader->lost);
 
 	for_each_sibling_event(sub, leader) {
 		values[n++] += perf_event_count(sub);
@@ -5259,6 +5264,8 @@ static int __perf_read_group_add(struct perf_event *leader,
 			values[n++] = primary_event_id(sub);
 		if (read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 			values[n++] = local64_read(&sub->build_id_faults);
+		if (read_format & PERF_FORMAT_LOST)
+			values[n++] = local64_read(&sub->lost);
 	}
 
 	raw_spin_unlock_irqrestore(&ctx->lock, flags);
@@ -5315,7 +5322,7 @@ static int perf_read_one(struct perf_event *event,
 				 u64 read_format, char __user *buf)
 {
 	u64 enabled, running;
-	u64 values[5];
+	u64 values[6];
 	int n = 0;
 
 	values[n++] = __perf_event_read_value(event, &enabled, &running);
@@ -5327,6 +5334,8 @@ static int perf_read_one(struct perf_event *event,
 		values[n++] = primary_event_id(event);
 	if (read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 		values[n++] = local64_read(&event->build_id_faults);
+	if (read_format & PERF_FORMAT_LOST)
+		values[n++] = local64_read(&event->lost);
 
 	if (copy_to_user(buf, values, n * sizeof(u64)))
 		return -EFAULT;
@@ -6829,7 +6838,7 @@ static void perf_output_read_one(struct perf_output_handle *handle,
 				 u64 enabled, u64 running)
 {
 	u64 read_format = event->attr.read_format;
-	u64 values[5];
+	u64 values[6];
 	int n = 0;
 
 	values[n++] = perf_event_count(event);
@@ -6845,6 +6854,8 @@ static void perf_output_read_one(struct perf_output_handle *handle,
 		values[n++] = primary_event_id(event);
 	if (read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 		values[n++] = local64_read(&event->build_id_faults);
+	if (read_format & PERF_FORMAT_LOST)
+		values[n++] = local64_read(&event->lost);
 
 	__output_copy(handle, values, n * sizeof(u64));
 }
@@ -6855,7 +6866,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
 {
 	struct perf_event *leader = event->group_leader, *sub;
 	u64 read_format = event->attr.read_format;
-	u64 values[6];
+	u64 values[7];
 	int n = 0;
 
 	values[n++] = 1 + leader->nr_siblings;
@@ -6875,6 +6886,8 @@ static void perf_output_read_group(struct perf_output_handle *handle,
 		values[n++] = primary_event_id(leader);
 	if (read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 		values[n++] = local64_read(&leader->build_id_faults);
+	if (read_format & PERF_FORMAT_LOST)
+		values[n++] = local64_read(&leader->lost);
 
 	__output_copy(handle, values, n * sizeof(u64));
 
@@ -6890,6 +6903,8 @@ static void perf_output_read_group(struct perf_output_handle *handle,
 			values[n++] = primary_event_id(sub);
 		if (read_format & PERF_FORMAT_BUILD_ID_FAULTS)
 			values[n++] = local64_read(&sub->build_id_faults);
+		if (read_format & PERF_FORMAT_LOST)
+			values[n++] = local64_read(&sub->lost);
 
 		__output_copy(handle, values, n * sizeof(u64));
 	}
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 52868716ec35..51738bc7cf44 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -248,6 +248,9 @@ __perf_output_begin(struct perf_output_handle *handle,
 		perf_event_header__init_id(&lost_event.header, data, event);
 		perf_output_put(handle, lost_event);
 		perf_event__output_id_sample(event, handle, data);
+
+		/* Keep track of lost events in event for PERF_FORMAT_LOST */
+		local64_add(lost_event.lost, &event->lost);
 	}
 
 	return 0;
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ