All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/x86: public: add TSC defines for cpuid leaf 4
@ 2023-01-24 22:35 Krister Johansen
  2023-01-25  6:57 ` Jan Beulich
  2023-01-25 18:45 ` [PATCH v2] " Krister Johansen
  0 siblings, 2 replies; 16+ messages in thread
From: Krister Johansen @ 2023-01-24 22:35 UTC (permalink / raw)
  To: Jan Beulich, Andrew Cooper, Roger Pau Monné, Wei Liu
  Cc: xen-devel, Juergen Gross, Boris Ostrovsky, David Reaver

Cpuid leaf 4 contains information about how the state of the tsc, its
mode, and some additional information.  A commit that is queued for
linux would like to use this to determine whether the tsc mode has been
set to 'no emulation' in order to make some decisions about which
clocksource is more reliable.

Expose this information in the public API headers so that they can
subsequently be imported into linux and used there.

Link: https://lore.kernel.org/xen-devel/eda8d9f2-3013-1b68-0df8-64d7f13ee35e@suse.com/
Link: https://lore.kernel.org/xen-devel/0835453d-9617-48d5-b2dc-77a2ac298bad@oracle.com/
Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
---
 xen/include/public/arch-x86/cpuid.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/include/public/arch-x86/cpuid.h b/xen/include/public/arch-x86/cpuid.h
index 7ecd16ae05..97dc970417 100644
--- a/xen/include/public/arch-x86/cpuid.h
+++ b/xen/include/public/arch-x86/cpuid.h
@@ -71,6 +71,12 @@
  *             EDX: shift amount for tsc->ns conversion
  * Sub-leaf 2: EAX: host tsc frequency in kHz
  */
+#define XEN_CPUID_TSC_EMULATED       (1u << 0)
+#define XEN_CPUID_HOST_TSC_RELIABLE  (1u << 1)
+#define XEN_CPUID_RDTSCP_INSTR_AVAIL (1u << 2)
+#define XEN_CPUID_TSC_MODE_DEFAULT   (0)
+#define XEN_CPUID_TSC_MODE_EMULATE   (1u)
+#define XEN_CPUID_TSC_MODE_NOEMULATE (2u)
 
 /*
  * Leaf 5 (0x40000x04)
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH] perf/util: Symbol lookup can fail if multiple segmets match stext
@ 2023-01-24 22:35 Krister Johansen
  2023-01-25 18:33 ` [PATCH v2] xen/x86: public: add TSC defines for cpuid leaf 4 Krister Johansen
  0 siblings, 1 reply; 16+ messages in thread
From: Krister Johansen @ 2023-01-24 22:35 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Michael Petlan, David Reaver,
	linux-perf-users, linux-kernel

This problem was encountered on an arm64 system with a lot of memory.
Without kernel debug symbols installed, and with both kcore and kallsyms
available, perf managed to get confused and returned "unknown" for all
of the kernel symbols that it tried to look up.

On this system, stext fell within the vmalloc segment.  The kcore symbol
matching code tries to find the first segment that contains stext and
uses that to replace the segment generated from just the kallsyms
information.  In this case, however, there were two: a very large
vmalloc segment, and the text segment.  This caused perf to get confused
because multiple overlapping segments were inserted into the RB tree
that holds the discovered segments.  However, that alone wasn't
sufficient to cause the problem. Even when we could find the segment,
the offsets were adjusted in such a way that the newly generated symbols
didn't line up with the instruction addresses in the trace.  The most
obvious solution would be to consult which segment type is text from
kcore, but this information is not exposed to users.

Instead, select the smallest matching segment that contains stext
instead of the first matching segment.  This allows us to match the text
segment instead of vmalloc, if one is contained within the other.

Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
---
 tools/perf/util/symbol.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index a3a165ae933a..14ac4189eaff 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1368,10 +1368,16 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 
 	/* Find the kernel map using the '_stext' symbol */
 	if (!kallsyms__get_function_start(kallsyms_filename, "_stext", &stext)) {
+		u64 replacement_size = 0;
 		list_for_each_entry(new_map, &md.maps, node) {
-			if (stext >= new_map->start && stext < new_map->end) {
+			u64 new_size = new_map->end - new_map->start;
+
+			if (!(stext >= new_map->start && stext < new_map->end))
+				continue;
+
+			if (!replacement_map || new_size < replacement_size) {
 				replacement_map = new_map;
-				break;
+				replacement_size = new_size;
 			}
 		}
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-01-31  8:43 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 22:35 [PATCH] xen/x86: public: add TSC defines for cpuid leaf 4 Krister Johansen
2023-01-25  6:57 ` Jan Beulich
2023-01-25 18:31   ` Krister Johansen
2023-01-25 18:45 ` [PATCH v2] " Krister Johansen
2023-01-26  8:57   ` Jan Beulich
2023-01-26 17:54     ` Krister Johansen
2023-01-26  9:57   ` Jan Beulich
2023-01-26 18:02     ` Krister Johansen
2023-01-27  7:16       ` Jan Beulich
2023-01-27 18:37         ` Krister Johansen
2023-01-27 18:51         ` [PATCH v3] " Krister Johansen
2023-01-30  8:22           ` Jan Beulich
2023-01-30 17:43             ` Krister Johansen
2023-01-30 17:44             ` [PATCH v4] " Krister Johansen
2023-01-31  8:42               ` Jan Beulich
2023-01-24 22:35 [PATCH] perf/util: Symbol lookup can fail if multiple segmets match stext Krister Johansen
2023-01-25 18:33 ` [PATCH v2] xen/x86: public: add TSC defines for cpuid leaf 4 Krister Johansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.