Skip to contentSkip to conversation

perf ordered_events: Optimise event object reuse

PATCH Superseded Matt Fleming 2 participants 5 messages May 15, 2020 – May 21, 2020 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf ordered_events: Optimise event object reuse

ordered_event objects can be placed on the free object cache list in any order which means future allocations may not return objects at sequential locations in memory. Getting non-contiguous objects from the free cache has bad consequences when later iterating over those objects in ordered_events__queue().

For example, large perf.data files can contain trillions of events and since objects that are next to each other in the free cache linked list can point to pretty much anywhere in the object address space, lots of cycles in ordered_events__queue() are spent servicing DTLB misses.

Implement the free object cache using the in-kernel implementation of interval trees so that objects can always be allocated from the free object cache in sequential order, improving spatial locality and reducing DTLB misses.

Here are some numbers showing the speed up (reducing in execution time) when running perf sched latency on sched events data and perf report on HW_CPU_CYCLES.

 $ perf stat --null -r 10 -- bash -c \
	"export PAGER=cat ; perf sched latency -i $file --stdio &>/dev/null"

Nr events File Size Before After Speed up
-------------- --------- -------- ------- ----------

  123318457470     29MB     0.2149    0.2440    -13.5%
 1651500885357    260MB     3.1205    1.9855    +36.4%
 3470519751785    506MB     6.1821    3.8941    +37.0%
 8213765551679   1100MB    13.4875    8.5079    +36.9%
15900515973759   1946MB    23.4069   15.0960    +35.5%

and HW_CPU_CYCLES events:

 $ perf stat --null -r 10 -- bash -c \
	"export PAGER=cat ; perf report -i $file --stdio &>/dev/null"

Nr events File Size Before After Speed up
-------------- --------- -------- ------- ----------

  328805166262     29MB      1.637     1.587    +3.0%
 3280413919096    253MB     13.381    12.349    +7.7%
 6475305954370    500MB     25.648    23.753    +7.4%
14218430569416   1000MB     52.800    49.036    +7.1%
26760562279427   2000MB     97.169    90.129    +7.2%
---
 tools/include/linux/interval_tree.h         |  30 +++
 tools/include/linux/interval_tree_generic.h | 187 ++++++++++++++++++
 tools/lib/interval_tree.c                   |  12 ++
 tools/perf/MANIFEST                         |   1 +
 tools/perf/tests/Build                      |   1 +
 tools/perf/tests/builtin-test.c             |   4 +
 tools/perf/tests/free-object-cache.c        | 200 ++++++++++++++++++++
 tools/perf/tests/tests.h                    |   2 +
 tools/perf/util/Build                       |   6 +
 tools/perf/util/ordered-events.c            | 130 ++++++++++++-
 tools/perf/util/ordered-events.h            |   8 +-
 11 files changed, 573 insertions(+), 8 deletions(-)
 create mode 100644 tools/include/linux/interval_tree.h
 create mode 100644 tools/include/linux/interval_tree_generic.h
 create mode 100644 tools/lib/interval_tree.c
 create mode 100644 tools/perf/tests/free-object-cache.c
tools/include/linux/interval_tree.h new file +30 -0
new file mode 100644
index 000000000000..288c26f50732
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_INTERVAL_TREE_H
+#define _LINUX_INTERVAL_TREE_H
+
+#include <linux/rbtree.h>
+
+struct interval_tree_node {
+	struct rb_node rb;
+	unsigned long start;	/* Start of interval */
+	unsigned long last;	/* Last location _in_ interval */
+	unsigned long __subtree_last;
+};
+
+extern void
+interval_tree_insert(struct interval_tree_node *node,
+		     struct rb_root_cached *root);
+
+extern void
+interval_tree_remove(struct interval_tree_node *node,
+		     struct rb_root_cached *root);
+
+extern struct interval_tree_node *
+interval_tree_iter_first(struct rb_root_cached *root,
+			 unsigned long start, unsigned long last);
+
+extern struct interval_tree_node *
+interval_tree_iter_next(struct interval_tree_node *node,
+			unsigned long start, unsigned long last);
+
+#endif	/* _LINUX_INTERVAL_TREE_H */
tools/include/linux/interval_tree_generic.h new file +187 -0

187 lines not on this page · raw message

tools/lib/interval_tree.c new file +12 -0
new file mode 100644
index 000000000000..4775c291edd6
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/interval_tree.h>
+#include <linux/interval_tree_generic.h>
+#include <linux/compiler.h>
+#include <linux/export.h>
+
+#define START(node) ((node)->start)
+#define LAST(node)  ((node)->last)
+
+INTERVAL_TREE_DEFINE(struct interval_tree_node, rb,
+		     unsigned long, __subtree_last,
+		     START, LAST,, interval_tree)
tools/perf/MANIFEST +1 -0
index 5d7b947320fb..01fe06660a77 100644
@@ -20,4 +20,5 @@ tools/lib/bitmap.c
 tools/lib/str_error_r.c
 tools/lib/vsprintf.c
 tools/lib/zalloc.c
+tools/lib/interval_tree.c
 scripts/bpf_helpers_doc.py
tools/perf/tests/Build +1 -0
index b3d1bf13ca07..c4e65ce96e2e 100644
@@ -56,6 +56,7 @@ perf-y += mem2node.o
 perf-y += maps.o
 perf-y += time-utils-test.o
 perf-y += genelf.o
+perf-y += free-object-cache.o
 
 $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
 	$(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
index b6322eb0f423..efb9bf7b9056 100644
@@ -313,6 +313,10 @@ static struct test generic_tests[] = {
 		.desc = "maps__merge_in",
 		.func = test__maps__merge_in,
 	},
+	{
+		.desc = "Free object cache",
+		.func = test__free_object_cache,
+	},
 	{
 		.func = NULL,
 	},
tools/perf/tests/free-object-cache.c new file +200 -0

200 lines not on this page · raw message

tools/perf/tests/tests.h +2 -0
index 61a1ab032080..f790da4357c9 100644
@@ -117,6 +117,8 @@ bool test__bp_signal_is_supported(void);
 bool test__bp_account_is_supported(void);
 bool test__wp_is_supported(void);
 
+int test__free_object_cache(struct test *test, int subtest);
+
 #if defined(__arm__) || defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
 struct thread;
tools/perf/util/Build +6 -0
index c0cf8dff694e..3bfb4ab1bd7f 100644
@@ -28,6 +28,7 @@ perf-y += print_binary.o
 perf-y += rlimit.o
 perf-y += argv_split.o
 perf-y += rbtree.o
+perf-y += interval_tree.o
 perf-y += libstring.o
 perf-y += bitmap.o
 perf-y += hweight.o
@@ -223,6 +224,7 @@ CFLAGS_find_bit.o      += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ET
 CFLAGS_rbtree.o        += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_libstring.o     += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_hweight.o       += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
+CFLAGS_interval_tree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_parse-events.o  += -Wno-redundant-decls
 CFLAGS_expr.o          += -Wno-redundant-decls
 CFLAGS_header.o        += -include $(OUTPUT)PERF-VERSION-FILE
@@ -251,6 +253,10 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
 
+$(OUTPUT)util/interval_tree.o: ../lib/interval_tree.c FORCE
+	$(call rule_mkdir)
+	$(call if_changed_dep,cc_o_c)
+
 $(OUTPUT)util/libstring.o: ../lib/string.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
tools/perf/util/ordered-events.c +123 -7

174 lines not on this page · raw message

tools/perf/util/ordered-events.h +7 -1
index 0920fb0ec6cc..20d108baa572 100644
@@ -3,9 +3,15 @@
 #define __ORDERED_EVENTS_H
 
 #include <linux/types.h>
+#include <linux/interval_tree.h>
 
 struct perf_sample;
 
+struct cache_region {
+	struct interval_tree_node node;
+	size_t len;
+};
+
 struct ordered_event {
 	u64			timestamp;
 	u64			file_offset;
@@ -39,7 +45,7 @@ struct ordered_events {
 	u64				 max_alloc_size;
 	u64				 cur_alloc_size;
 	struct list_head		 events;
-	struct list_head		 cache;
+	struct rb_root_cached		 cache;
 	struct list_head		 to_free;
 	struct ordered_events_buffer	*buffer;
 	struct ordered_event		*last;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 11 lines · Matt Fleming

ordered_event objects can be placed on the free object cache list in any order which means future allocations may not return objects at sequential locations in memory. Getting non-contiguous objects from the free cache has bad consequences when later iterating over those objects in ordered_events__queue().

For example, large perf.data files can contain trillions of events and since objects that are next to each other in the free cache linked list can point to pretty much anywhere in the object address space, lots of cycles in ordered_events__queue() are spent servicing DTLB misses.

Quoted 8 lines

Implement the free object cache using the in-kernel implementation of interval trees so that objects can always be allocated from the free object cache in sequential order, improving spatial locality and reducing DTLB misses.

Here are some numbers showing the speed up (reducing in execution time) when running perf sched latency on sched events data and perf report on HW_CPU_CYCLES.

really nice, few questions below

Quoted 7 lines
 $ perf stat --null -r 10 -- bash -c \
	"export PAGER=cat ; perf sched latency -i $file --stdio &>/dev/null"

Nr events File Size Before After Speed up
-------------- --------- -------- ------- ----------
123318457470 29MB 0.2149 0.2440 -13.5%

should we be concerned about small data and the extra processing?

maybe we could add some option that disables this, at leat to be able to compare times in the future

Quoted 4 lines
 1651500885357    260MB     3.1205    1.9855    +36.4%
 3470519751785    506MB     6.1821    3.8941    +37.0%
 8213765551679   1100MB    13.4875    8.5079    +36.9%
15900515973759   1946MB    23.4069   15.0960    +35.5%

SNIP

Quoted 21 lines
tools/include/linux/interval_tree_generic.h new file +15 -0
new file mode 100644
index 000000000000..aaa8a0767aa3
@@ -0,0 +1,187 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+  Interval Trees
+  (C) 2012  Michel Lespinasse <[email protected]>
+
+
+  include/linux/interval_tree_generic.h
+*/
+
+#include <linux/rbtree_augmented.h>
+
+/*
+ * Template for implementing interval trees
+ *
+ * ITSTRUCT:   struct type of the interval tree nodes

tools/include/linux/interval_tree_generic.h line 25

Quoted 10 lines
tools/include/linux/interval_tree_generic.h new file +10 -0
+ * ITRB:       name of struct rb_node field within ITSTRUCT
+ * ITTYPE:     type of the interval endpoints
+ * ITSUBTREE:  name of ITTYPE field within ITSTRUCT holding last-in-subtree
+ * ITSTART(n): start endpoint of ITSTRUCT node n
+ * ITLAST(n):  last endpoint of ITSTRUCT node n
+ * ITSTATIC:   'static' or empty
+ * ITPREFIX:   prefix to use for the inline tree definitions
+ *
+ * Note - before using this, please consider if generic version
+ * (interval_tree.h) would work for you...

the interval_tree.h looks like what you have added with the generic header.. is there some reason to use the _generic header?

please add the header file also to check-headers.sh

Quoted 13 lines
tools/include/linux/interval_tree_generic.h new file +13 -0
+ */
+
+#define INTERVAL_TREE_DEFINE(ITSTRUCT, ITRB, ITTYPE, ITSUBTREE,		      \
+			     ITSTART, ITLAST, ITSTATIC, ITPREFIX)	      \
+									      \
+/* Callbacks for augmented rbtree insert and remove */			      \
+									      \
+RB_DECLARE_CALLBACKS_MAX(static, ITPREFIX ## _augment,			      \
+			 ITSTRUCT, ITRB, ITTYPE, ITSUBTREE, ITLAST)	      \
+									      \
+/* Insert / remove interval nodes from the tree */			      \
+									      \
+ITSTATIC void ITPREFIX ## _insert(ITSTRUCT *node,			      \

SNIP

Quoted 8 lines
tools/perf/tests/free-object-cache.c new file +2 -0
new file mode 100644
index 000000000000..e4395ece7d2b
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "tests.h"

tools/perf/tests/free-object-cache.c line 12

Quoted 10 lines
tools/perf/tests/free-object-cache.c new file +10 -0
+#include <linux/kernel.h>
+
+#define ordered_events__flush_time __test_ordered_events__flush_time
+#define ordered_events__first_time __test_ordered_events__first_time
+#define ordered_events__delete __test_ordered_events__delete
+#define ordered_events__init __test_ordered_events__init
+#define ordered_events__free __test_ordered_events__free
+#define ordered_events__queue __test_ordered_events__queue
+#define ordered_events__reinit __test_ordered_events__reinit
+#define ordered_events__flush __test_ordered_events__flush

I'm excited to see these tests, but why is above needed?

can't you use ordered-events interface as it is? you used only exported functions right?

Quoted 12 lines
tools/perf/tests/free-object-cache.c new file +12 -0
+
+#include "../util/ordered-events.c"
+
+static void *alloc_cache(unsigned int num_objs)
+{
+	void *ptr = calloc(sizeof(struct ordered_event), num_objs);
+	return ptr;
+}
+
+static inline struct ordered_event *
+cache_obj_entry(void *ptr, unsigned int index)
+{

SNIP

Quoted 9 lines
tools/perf/tests/free-object-cache.c new file +9 -0
+static struct ordered_event *free_cache_get(struct ordered_events *oe)
+{
+	struct interval_tree_node *it;
+	struct ordered_event *new;
+	size_t bytes = sizeof(*new);
+
+	it = interval_tree_iter_first(&oe->cache, 0, ULONG_MAX);
+	if (!it)
+		return NULL;

tools/perf/tests/free-object-cache.c

Quoted 10 lines
tools/perf/tests/free-object-cache.c new file +10 -0
+
+	/* Has the cache memory been exhausted? */
+	assert(cache_region_size(it) >= bytes);
+
+	new = (void *)it->start;
+	interval_tree_remove(it, &oe->cache);
+
+	it->start += bytes;
+	if (cache_region_size(it))
+		interval_tree_insert(it, &oe->cache);

in case we did not use the whole node, do we need to remove and insert back the node? it should be still the lowest node in the tree no? we could just fix 'start'

Quoted 6 lines
tools/perf/tests/free-object-cache.c new file +6 -0
+	else
+		free(it);
+
+	return new;
+}
+

SNIP

Quoted 6 lines
tools/perf/util/ordered-events.h +0 -0
index 0920fb0ec6cc..20d108baa572 100644
@@ -3,9 +3,15 @@
 #define __ORDERED_EVENTS_H

tools/perf/util/ordered-events.h line 13

Quoted 10 lines
tools/perf/util/ordered-events.h +5 -0
 
 #include <linux/types.h>
+#include <linux/interval_tree.h>
 
 struct perf_sample;
 
+struct cache_region {
+	struct interval_tree_node node;
+	size_t len;
+};

^^^ this looks like some leftover

thanks,
jirka

Quoted 16 lines
tools/perf/util/ordered-events.h +2 -1
+
 struct ordered_event {
 	u64			timestamp;
 	u64			file_offset;
@@ -39,7 +45,7 @@ struct ordered_events {
 	u64				 max_alloc_size;
 	u64				 cur_alloc_size;
 	struct list_head		 events;
-	struct list_head		 cache;
+	struct rb_root_cached		 cache;
 	struct list_head		 to_free;
 	struct ordered_events_buffer	*buffer;
 	struct ordered_event		*last;
Signature · 1 line
2.17.1
#2 lore raw
Quoted 24 lines · Jiri Olsa
Quoted 11 lines · Matt Fleming

ordered_event objects can be placed on the free object cache list in any order which means future allocations may not return objects at sequential locations in memory. Getting non-contiguous objects from the free cache has bad consequences when later iterating over those objects in ordered_events__queue().

For example, large perf.data files can contain trillions of events and since objects that are next to each other in the free cache linked list can point to pretty much anywhere in the object address space, lots of cycles in ordered_events__queue() are spent servicing DTLB misses.

Quoted 8 lines

Implement the free object cache using the in-kernel implementation of interval trees so that objects can always be allocated from the free object cache in sequential order, improving spatial locality and reducing DTLB misses.

Here are some numbers showing the speed up (reducing in execution time) when running perf sched latency on sched events data and perf report on HW_CPU_CYCLES.

really nice, few questions below

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
 $ perf stat --null -r 10 -- bash -c \
	"export PAGER=cat ; perf sched latency -i $file --stdio &>/dev/null"

Nr events File Size Before After Speed up
-------------- --------- -------- ------- ----------
123318457470 29MB 0.2149 0.2440 -13.5%

should we be concerned about small data and the extra processing?

I didn't look into this slowdown originally because it's ~2.9 ms, but FYI it looks like this is caused by:

- Longer code paths (more instructions)
- More branches
- More branch mispredicts

Quoted 2 lines

maybe we could add some option that disables this, at leat to be able to compare times in the future

Sure. Do you mean a command-line option or build-time config?

Quoted 26 lines
Quoted 26 lines
tools/include/linux/interval_tree_generic.h new file +20 -0
new file mode 100644
index 000000000000..aaa8a0767aa3
@@ -0,0 +1,187 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+  Interval Trees
+  (C) 2012  Michel Lespinasse <[email protected]>
+
+
+  include/linux/interval_tree_generic.h
+*/
+
+#include <linux/rbtree_augmented.h>
+
+/*
+ * Template for implementing interval trees
+ *
+ * ITSTRUCT:   struct type of the interval tree nodes
+ * ITRB:       name of struct rb_node field within ITSTRUCT
+ * ITTYPE:     type of the interval endpoints
+ * ITSUBTREE:  name of ITTYPE field within ITSTRUCT holding last-in-subtree
+ * ITSTART(n): start endpoint of ITSTRUCT node n
+ * ITLAST(n):  last endpoint of ITSTRUCT node n
Quoted 8 lines

tools/include/linux/interval_tree_generic.h line 25

Quoted 5 lines
tools/include/linux/interval_tree_generic.h new file +5 -0
+ * ITSTATIC:   'static' or empty
+ * ITPREFIX:   prefix to use for the inline tree definitions
+ *
+ * Note - before using this, please consider if generic version
+ * (interval_tree.h) would work for you...

the interval_tree.h looks like what you have added with the generic header.. is there some reason to use the _generic header?

Yes, the _generic version contains the actual implementation of interval trees, so you need both.

Quoted 1 line

please add the header file also to check-headers.sh

Done!

Quoted 21 lines
Quoted 8 lines
tools/perf/tests/free-object-cache.c new file +2 -0
new file mode 100644
index 000000000000..e4395ece7d2b
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "tests.h"

tools/perf/tests/free-object-cache.c line 12

Quoted 10 lines
tools/perf/tests/free-object-cache.c new file +10 -0
+#include <linux/kernel.h>
+
+#define ordered_events__flush_time __test_ordered_events__flush_time
+#define ordered_events__first_time __test_ordered_events__first_time
+#define ordered_events__delete __test_ordered_events__delete
+#define ordered_events__init __test_ordered_events__init
+#define ordered_events__free __test_ordered_events__free
+#define ordered_events__queue __test_ordered_events__queue
+#define ordered_events__reinit __test_ordered_events__reinit
+#define ordered_events__flush __test_ordered_events__flush

I'm excited to see these tests, but why is above needed?

Quoted 2 lines

can't you use ordered-events interface as it is? you used only exported functions right?

Nope, the tests in this file are unit tests so I'm testing free_cache_{get,put} which are file-local functions by #include'ing ordered-events.c.

The above define are required to avoid duplicate symbol errors at link-time, e.g.

util/perf-in.o: In function `ordered_events__flush_time':
/home/matt/src/kernels/linux/tools/perf/util/ordered-events.c:461: multiple definition of `ordered_events__flush_time' tests/perf-in.o:/home/matt/src/kernels/linux/tools/perf/tests/../util/ordered-events.c:461: first defined here

There are other ways to resolve this (linker flags to change the symbols) but I couldn't find any precedent with that, so this seemed like the easiest and most obvious solution. I'm happy to fix this up any other way if you have suggestions though.

Quoted 15 lines
Quoted 15 lines
tools/perf/tests/free-object-cache.c new file +15 -0
+static struct ordered_event *free_cache_get(struct ordered_events *oe)
+{
+	struct interval_tree_node *it;
+	struct ordered_event *new;
+	size_t bytes = sizeof(*new);
+
+	it = interval_tree_iter_first(&oe->cache, 0, ULONG_MAX);
+	if (!it)
+		return NULL;
+
+	/* Has the cache memory been exhausted? */
+	assert(cache_region_size(it) >= bytes);
+
+	new = (void *)it->start;
+	interval_tree_remove(it, &oe->cache);
Quoted 8 lines

tools/perf/tests/free-object-cache.c line 31

Quoted 4 lines
tools/perf/tests/free-object-cache.c new file +4 -0
+
+	it->start += bytes;
+	if (cache_region_size(it))
+		interval_tree_insert(it, &oe->cache);

in case we did not use the whole node, do we need to remove and insert back the node? it should be still the lowest node in the tree no? we could just fix 'start'

Hmm.. I originally did this remove/insert dance to be sure that the rbtree semantics are maintained. But I think you're right that adjusting ->start cannot cause this rbtree node to move places in the tree and the ->start value isn't stored anywhere other than this interval_tree node (a copy of ->last, on the other hand, can be stored in the parent node).

Quoted 10 lines
Quoted 10 lines
tools/perf/util/ordered-events.h +1 -0
index 0920fb0ec6cc..20d108baa572 100644
@@ -3,9 +3,15 @@
 #define __ORDERED_EVENTS_H
 
 #include <linux/types.h>
+#include <linux/interval_tree.h>
 
Quoted 8 lines

tools/perf/util/ordered-events.h line 13

Quoted 6 lines
tools/perf/util/ordered-events.h +4 -0
 struct perf_sample;
 
+struct cache_region {
+	struct interval_tree_node node;
+	size_t len;
+};

^^^ this looks like some leftover

Oops :) Yes, you're right. This should not be here.

#3 lore raw
Quoted 37 lines · Matt Fleming
Quoted 24 lines · Jiri Olsa
Quoted 11 lines · Matt Fleming

ordered_event objects can be placed on the free object cache list in any order which means future allocations may not return objects at sequential locations in memory. Getting non-contiguous objects from the free cache has bad consequences when later iterating over those objects in ordered_events__queue().

For example, large perf.data files can contain trillions of events and since objects that are next to each other in the free cache linked list can point to pretty much anywhere in the object address space, lots of cycles in ordered_events__queue() are spent servicing DTLB misses.

Quoted 8 lines

Implement the free object cache using the in-kernel implementation of interval trees so that objects can always be allocated from the free object cache in sequential order, improving spatial locality and reducing DTLB misses.

Here are some numbers showing the speed up (reducing in execution time) when running perf sched latency on sched events data and perf report on HW_CPU_CYCLES.

really nice, few questions below

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
 $ perf stat --null -r 10 -- bash -c \
	"export PAGER=cat ; perf sched latency -i $file --stdio &>/dev/null"

Nr events File Size Before After Speed up
-------------- --------- -------- ------- ----------
123318457470 29MB 0.2149 0.2440 -13.5%

should we be concerned about small data and the extra processing?

I didn't look into this slowdown originally because it's ~2.9 ms, but FYI it looks like this is caused by:

Quoted 8 lines

- Longer code paths (more instructions)
- More branches
- More branch mispredicts

Quoted 2 lines

maybe we could add some option that disables this, at leat to be able to compare times in the future

Sure. Do you mean a command-line option or build-time config?

command line option would be great

SNIP

Quoted 31 lines
Quoted 21 lines
Quoted 8 lines
tools/perf/tests/free-object-cache.c new file +2 -0
new file mode 100644
index 000000000000..e4395ece7d2b
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "tests.h"

tools/perf/tests/free-object-cache.c line 12

Quoted 10 lines
tools/perf/tests/free-object-cache.c new file +10 -0
+#include <linux/kernel.h>
+
+#define ordered_events__flush_time __test_ordered_events__flush_time
+#define ordered_events__first_time __test_ordered_events__first_time
+#define ordered_events__delete __test_ordered_events__delete
+#define ordered_events__init __test_ordered_events__init
+#define ordered_events__free __test_ordered_events__free
+#define ordered_events__queue __test_ordered_events__queue
+#define ordered_events__reinit __test_ordered_events__reinit
+#define ordered_events__flush __test_ordered_events__flush

I'm excited to see these tests, but why is above needed?

Quoted 2 lines

can't you use ordered-events interface as it is? you used only exported functions right?

Nope, the tests in this file are unit tests so I'm testing free_cache_{get,put} which are file-local functions by #include'ing ordered-events.c.

The above define are required to avoid duplicate symbol errors at link-time, e.g.

Quoted 8 lines

util/perf-in.o: In function `ordered_events__flush_time':
/home/matt/src/kernels/linux/tools/perf/util/ordered-events.c:461: multiple definition of `ordered_events__flush_time' tests/perf-in.o:/home/matt/src/kernels/linux/tools/perf/tests/../util/ordered-events.c:461: first defined here

There are other ways to resolve this (linker flags to change the symbols) but I couldn't find any precedent with that, so this seemed like the easiest and most obvious solution. I'm happy to fix this up any other way if you have suggestions though.

hum, could we just make free_cache_{get,put} public?

thanks,
jirka

#4 lore raw
Quoted 13 lines · Jiri Olsa
Quoted 12 lines · Matt Fleming

Nope, the tests in this file are unit tests so I'm testing free_cache_{get,put} which are file-local functions by #include'ing ordered-events.c.

The above define are required to avoid duplicate symbol errors at link-time, e.g.

util/perf-in.o: In function `ordered_events__flush_time':
/home/matt/src/kernels/linux/tools/perf/util/ordered-events.c:461: multiple definition of `ordered_events__flush_time' tests/perf-in.o:/home/matt/src/kernels/linux/tools/perf/tests/../util/ordered-events.c:461: first defined here

Quoted 6 lines
Quoted 4 lines

There are other ways to resolve this (linker flags to change the symbols) but I couldn't find any precedent with that, so this seemed like the easiest and most obvious solution. I'm happy to fix this up any other way if you have suggestions though.

hum, could we just make free_cache_{get,put} public?

Yeah that's totally doable. I'll send a v2 with all these changes.