All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
@ 2016-08-18  8:57 Masami Hiramatsu
  2016-08-18  8:57 ` [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types Masami Hiramatsu
                   ` (7 more replies)
  0 siblings, 8 replies; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Hi Arnaldo and Steven,

Here is an RFC series of hexadecimal type casting and
changing default type casting of perf and ftrace.

I've introduced x8,x16,x32,x64 according to previous
discussion on LKML.
  https://lkml.org/lkml/2016/8/10/339

This series includes not only adding hexadecimal types
(x8,x16,x32,x64), but also checking it is supported by
running kernel and keeping the backward compativility.

[1/6] Add hexadecimal type casting, but does not touch
   existing types like 'u8'.
[2/6] Show the supported types on README of ftrace so
   that user application (e.g. perf) can check that.
[3/6] Add a type availability check to perf-probe.
[4/6] Add hexadecimal prefix support to perf-probe if
   it is supported by the kernel. 
[5/6] Change the perf-probe default type casting for
   unsigned type to hexadecimal (for backward compatibility)
[6/6] Change ftrace's 'uNN' to show value in decimal
   and use 'xNN' by default (for backward compatibility)

This way, we can also add "octal" type, pointer type,
and "character" type etc. and perf can check whether
the kernel supports it or not. :)

Thanks,
---

Masami Hiramatsu (6):
      ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types
      ftrace: probe: Add README entries for k/uprobe-events
      perf probe: Add supported type casting of running kernel
      perf probe: Support hexadecimal casting
      perf-probe: Use hexadecimal type by default if possible
      ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal


 tools/perf/Documentation/perf-probe.txt |    5 +--
 tools/perf/util/probe-file.c            |   57 +++++++++++++++++++++++++++++++
 tools/perf/util/probe-file.h            |   10 +++++
 tools/perf/util/probe-finder.c          |   19 +++++++---
 4 files changed, 81 insertions(+), 10 deletions(-)

--
Masami Hiramatsu (Linaro Ltd.) <mhiramat@kernel.org>

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

* [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
@ 2016-08-18  8:57 ` Masami Hiramatsu
  2016-08-18 15:38   ` Steven Rostedt
  2016-08-24  9:25   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  2016-08-18  8:58 ` [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events Masami Hiramatsu
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Add x8/x16/x32/x64 for hexadecimal type casting to kprobe/uprobe
event tracer.

These type casts can be used for integer arguments for explicitly
showing them in hexadecimal digits in formatted text.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/Documentation/perf-probe.txt |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt
index ea52ec1..9109c8e 100644
--- a/Documentation/trace/kprobetrace.txt
+++ b/Documentation/trace/kprobetrace.txt
@@ -44,8 +44,8 @@ Synopsis of kprobe_events
   +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
   NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
   FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
-		  (u8/u16/u32/u64/s8/s16/s32/s64), "string" and bitfield
-		  are supported.
+		  (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
+		  (x8/x16/x32/x64), "string" and bitfield are supported.
 
   (*) only for return probe.
   (**) this is useful for fetching a field of data structures.
diff --git a/Documentation/trace/uprobetracer.txt b/Documentation/trace/uprobetracer.txt
index 72d1cd4..7e6d28c 100644
--- a/Documentation/trace/uprobetracer.txt
+++ b/Documentation/trace/uprobetracer.txt
@@ -40,8 +40,8 @@ Synopsis of uprobe_tracer
    +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
    NAME=FETCHARG     : Set NAME as the argument name of FETCHARG.
    FETCHARG:TYPE     : Set TYPE as the type of FETCHARG. Currently, basic types
-		       (u8/u16/u32/u64/s8/s16/s32/s64), "string" and bitfield
-		       are supported.
+		       (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
+		       (x8/x16/x32/x64), "string" and bitfield are supported.
 
   (*) only for return probe.
   (**) this is useful for fetching a field of data structures.
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 9aedb0b..eb6c9f1 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -253,6 +253,10 @@ static const struct fetch_type kprobes_fetch_type_table[] = {
 	ASSIGN_FETCH_TYPE(s16, u16, 1),
 	ASSIGN_FETCH_TYPE(s32, u32, 1),
 	ASSIGN_FETCH_TYPE(s64, u64, 1),
+	ASSIGN_FETCH_TYPE_ALIAS(x8,  u8,  u8,  0),
+	ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
 
 	ASSIGN_FETCH_TYPE_END
 };
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 74e80a5..725af9d 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -36,24 +36,28 @@ const char *reserved_field_names[] = {
 };
 
 /* Printing  in basic type function template */
-#define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt)				\
-int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, const char *name,	\
+#define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt)			\
+int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name,	\
 				void *data, void *ent)			\
 {									\
 	trace_seq_printf(s, " %s=" fmt, name, *(type *)data);		\
 	return !trace_seq_has_overflowed(s);				\
 }									\
-const char PRINT_TYPE_FMT_NAME(type)[] = fmt;				\
-NOKPROBE_SYMBOL(PRINT_TYPE_FUNC_NAME(type));
-
-DEFINE_BASIC_PRINT_TYPE_FUNC(u8 , "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u32, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u64, "0x%Lx")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  "%d")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%d")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%Ld")
+const char PRINT_TYPE_FMT_NAME(tname)[] = fmt;				\
+NOKPROBE_SYMBOL(PRINT_TYPE_FUNC_NAME(tname));
+
+DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "0x%Lx")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  s8,  "%d")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x8,  u8,  "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
 
 /* Print type function for string type */
 int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, const char *name,
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index 45400ca..f0c470a 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -149,6 +149,11 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(s8);
 DECLARE_BASIC_PRINT_TYPE_FUNC(s16);
 DECLARE_BASIC_PRINT_TYPE_FUNC(s32);
 DECLARE_BASIC_PRINT_TYPE_FUNC(s64);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x8);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x16);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x32);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x64);
+
 DECLARE_BASIC_PRINT_TYPE_FUNC(string);
 
 #define FETCH_FUNC_NAME(method, type)	fetch_##method##_##type
@@ -234,6 +239,10 @@ ASSIGN_FETCH_FUNC(file_offset, ftype),			\
 #define ASSIGN_FETCH_TYPE(ptype, ftype, sign)			\
 	__ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype)
 
+/* If ptype is an alias of atype, use this macro (show atype in format) */
+#define ASSIGN_FETCH_TYPE_ALIAS(ptype, atype, ftype, sign)		\
+	__ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #atype)
+
 #define ASSIGN_FETCH_TYPE_END {}
 
 #define FETCH_TYPE_STRING	0
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index c534854..7a68732 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -211,6 +211,10 @@ static const struct fetch_type uprobes_fetch_type_table[] = {
 	ASSIGN_FETCH_TYPE(s16, u16, 1),
 	ASSIGN_FETCH_TYPE(s32, u32, 1),
 	ASSIGN_FETCH_TYPE(s64, u64, 1),
+	ASSIGN_FETCH_TYPE_ALIAS(x8,  u8,  u8,  0),
+	ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
 
 	ASSIGN_FETCH_TYPE_END
 };
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index b303bcd..aa33325 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,13 +176,13 @@ Each probe argument follows below syntax.
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
-'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
 
 On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
 
 TYPES
 -----
-Basic types (u8/u16/u32/u64/s8/s16/s32/s64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
+Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
 String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
 

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

* [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
  2016-08-18  8:57 ` [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types Masami Hiramatsu
@ 2016-08-18  8:58 ` Masami Hiramatsu
  2016-08-18 15:40   ` Steven Rostedt
  2016-08-24  9:25   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  2016-08-18  8:58 ` [PATCH 3/6] perf probe: Add supported type casting of running kernel Masami Hiramatsu
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Add README entries for kprobe-events and uprobe-events.
This allows user to check what options can be acceptable
for running kernel.
E.g. perf tools can choose correct types for the kernel.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 0 files changed

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index dade4c9..1e2ce3b 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4123,6 +4123,30 @@ static const char readme_msg[] =
 	"\t\t\t  traces\n"
 #endif
 #endif /* CONFIG_STACK_TRACER */
+#ifdef CONFIG_KPROBE_EVENT
+	"  kprobe_events\t\t- Add/remove/show the kernel dynamic events\n"
+	"\t\t\t  Write into this file to define/undefine new trace events.\n"
+#endif
+#ifdef CONFIG_UPROBE_EVENT
+	"  uprobe_events\t\t- Add/remove/show the userspace dynamic events\n"
+	"\t\t\t  Write into this file to define/undefine new trace events.\n"
+#endif
+#if defined(CONFIG_KPROBE_EVENT) || defined(CONFIG_UPROBE_EVENT)
+	"\t  accepts: event-definitions (one definition per line)\n"
+	"\t   Format: p|r[:[<group>/]<event>] <place> [<args>]\n"
+	"\t           -:[<group>/]<event>\n"
+#ifdef CONFIG_KPROBE_EVENT
+	"\t    place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
+#endif
+#ifdef CONFIG_UPROBE_EVENT
+	"\t    place: <path>:<offset>\n"
+#endif
+	"\t     args: <name>=fetcharg[:type]\n"
+	"\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n"
+	"\t           $stack<index>, $stack, $retval, $comm\n"
+	"\t     type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string,\n"
+	"\t           b<bit-width>@<bit-offset>/<container-size>\n"
+#endif
 	"  events/\t\t- Directory containing all trace event subsystems:\n"
 	"      enable\t\t- Write 0/1 to enable/disable tracing of all events\n"
 	"  events/<system>/\t- Directory containing all trace events for <system>:\n"

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

* [PATCH 3/6] perf probe: Add supported type casting of running kernel
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
  2016-08-18  8:57 ` [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types Masami Hiramatsu
  2016-08-18  8:58 ` [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events Masami Hiramatsu
@ 2016-08-18  8:58 ` Masami Hiramatsu
  2016-08-23 19:45   ` Arnaldo Carvalho de Melo
  2016-08-24  9:26   ` [tip:perf/core] perf probe: Add supported for type casting by the " tip-bot for Masami Hiramatsu
  2016-08-18  8:58 ` [PATCH 4/6] perf probe: Support hexadecimal casting Masami Hiramatsu
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Add a checking routine what types are supported by the
running kernel by finding the pattern in
<debugfs>/tracing/README.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/probe-file.c   |   57 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/probe-file.h   |   10 +++++++
 tools/perf/util/probe-finder.c |    1 +
 3 files changed, 68 insertions(+)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 9aed9c3..552e56b 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -855,3 +855,60 @@ int probe_cache__show_all_caches(struct strfilter *filter)
 
 	return 0;
 }
+
+static struct {
+	const char *pattern;
+	bool	avail;
+	bool	checked;
+} probe_type_table[] = {
+#define DEFINE_TYPE(idx, pat, def_avail)	\
+	[idx] = {.pattern = pat, .avail = (def_avail)}
+	DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true),
+	DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
+	DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
+	DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
+	DEFINE_TYPE(PROBE_TYPE_BITFIELD,
+		    "* b<bit-width>@<bit-offset>/<container-size>", true),
+};
+
+bool probe_type_is_available(enum probe_type type)
+{
+	FILE *fp;
+	char *buf = NULL;
+	size_t len = 0;
+	bool target_line = false;
+	bool ret = probe_type_table[type].avail;
+
+	if (type < 0 || type >= PROBE_TYPE_END)
+		return false;
+	/* We don't have to check the type which supported by default */
+	if (ret || probe_type_table[type].checked)
+		return ret;
+
+	if (asprintf(&buf, "%s/README", tracing_path) < 0)
+		return ret;
+
+	fp = fopen(buf, "r");
+	if (!fp)
+		goto end;
+
+	zfree(&buf);
+	while (getline(&buf, &len, fp) > 0 && !ret) {
+		if (!target_line) {
+			target_line = !!strstr(buf, " type: ");
+			if (!target_line)
+				continue;
+		} else if (strstr(buf, "\t          ") != buf)
+			break;
+		ret = strglobmatch(buf, probe_type_table[type].pattern);
+	}
+	/* Cache the result */
+	probe_type_table[type].checked = true;
+	probe_type_table[type].avail = ret;
+
+	fclose(fp);
+end:
+	free(buf);
+
+	return ret;
+}
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 9577b5c..eba44c3 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -19,6 +19,15 @@ struct probe_cache {
 	struct list_head entries;
 };
 
+enum probe_type {
+	PROBE_TYPE_U = 0,
+	PROBE_TYPE_S,
+	PROBE_TYPE_X,
+	PROBE_TYPE_STRING,
+	PROBE_TYPE_BITFIELD,
+	PROBE_TYPE_END,
+};
+
 #define PF_FL_UPROBE	1
 #define PF_FL_RW	2
 #define for_each_probe_cache_entry(entry, pcache) \
@@ -54,6 +63,7 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
 struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
 					const char *group, const char *event);
 int probe_cache__show_all_caches(struct strfilter *filter);
+bool probe_type_is_available(enum probe_type type);
 #else	/* ! HAVE_LIBELF_SUPPORT */
 static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
 {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 5c290c6..24dbe23 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -39,6 +39,7 @@
 #include "util.h"
 #include "symbol.h"
 #include "probe-finder.h"
+#include "probe-file.h"
 
 /* Kprobe tracer basic type is up to u64 */
 #define MAX_BASIC_TYPE_BITS	64

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

* [PATCH 4/6] perf probe: Support hexadecimal casting
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
                   ` (2 preceding siblings ...)
  2016-08-18  8:58 ` [PATCH 3/6] perf probe: Add supported type casting of running kernel Masami Hiramatsu
@ 2016-08-18  8:58 ` Masami Hiramatsu
  2016-08-24  9:26   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  2016-08-18  8:59 ` [PATCH 5/6] perf-probe: Use hexadecimal type by default if possible Masami Hiramatsu
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Support hexadecimal unsigned integer casting by 'x'.
This allows user to explicitly specify the output
format of the probe arguments as hexadecimal.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/Documentation/perf-probe.txt |    4 ++--
 tools/perf/util/probe-finder.c          |   17 ++++++++++-------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index aa33325..d217617 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,13 +176,13 @@ Each probe argument follows below syntax.
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
-'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
 
 On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
 
 TYPES
 -----
-Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
+Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
 String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
 
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 24dbe23..f18cd6b 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -298,13 +298,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 	char sbuf[STRERR_BUFSIZE];
 	int bsize, boffs, total;
 	int ret;
-	char sign;
+	char prefix;
 
 	/* TODO: check all types */
-	if (cast && strcmp(cast, "string") != 0 &&
+	if (cast && strcmp(cast, "string") != 0 && strcmp(cast, "x") != 0 &&
 	    strcmp(cast, "s") != 0 && strcmp(cast, "u") != 0) {
 		/* Non string type is OK */
-		/* and respect signedness cast */
+		/* and respect signedness/hexadecimal cast */
 		tvar->type = strdup(cast);
 		return (tvar->type == NULL) ? -ENOMEM : 0;
 	}
@@ -366,11 +366,14 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 	}
 
 	if (cast && (strcmp(cast, "u") == 0))
-		sign = 'u';
+		prefix = 'u';
 	else if (cast && (strcmp(cast, "s") == 0))
-		sign = 's';
+		prefix = 's';
+	else if (cast && (strcmp(cast, "x") == 0) &&
+		 probe_type_is_available(PROBE_TYPE_X))
+		prefix = 'x';
 	else
-		sign = die_is_signed_type(&type) ? 's' : 'u';
+		prefix = die_is_signed_type(&type) ? 's' : 'u';
 
 	ret = dwarf_bytesize(&type);
 	if (ret <= 0)
@@ -384,7 +387,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 			dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
 		ret = MAX_BASIC_TYPE_BITS;
 	}
-	ret = snprintf(buf, 16, "%c%d", sign, ret);
+	ret = snprintf(buf, 16, "%c%d", prefix, ret);
 
 formatted:
 	if (ret < 0 || ret >= 16) {

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

* [PATCH 5/6] perf-probe: Use hexadecimal type by default if possible
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
                   ` (3 preceding siblings ...)
  2016-08-18  8:58 ` [PATCH 4/6] perf probe: Support hexadecimal casting Masami Hiramatsu
@ 2016-08-18  8:59 ` Masami Hiramatsu
  2016-08-24  9:27   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
  2016-08-18  8:59 ` [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal Masami Hiramatsu
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:59 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Use hexadecimal type by default if it is available on
current running kernel.
This keeps the default behavior of perf probe after
changing the output format of 'u8/16/32/64' to
unsigned decimal number.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/probe-finder.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index f18cd6b..ac4740f 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -373,7 +373,8 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 		 probe_type_is_available(PROBE_TYPE_X))
 		prefix = 'x';
 	else
-		prefix = die_is_signed_type(&type) ? 's' : 'u';
+		prefix = die_is_signed_type(&type) ? 's' :
+			 probe_type_is_available(PROBE_TYPE_X) ? 'x' : 'u';
 
 	ret = dwarf_bytesize(&type);
 	if (ret <= 0)

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

* [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
                   ` (4 preceding siblings ...)
  2016-08-18  8:59 ` [PATCH 5/6] perf-probe: Use hexadecimal type by default if possible Masami Hiramatsu
@ 2016-08-18  8:59 ` Masami Hiramatsu
  2016-08-18 15:41   ` Steven Rostedt
  2016-08-24  9:27   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  2016-08-18 14:14 ` [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Arnaldo Carvalho de Melo
  2016-08-18 16:03 ` Steven Rostedt
  7 siblings, 2 replies; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18  8:59 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Change kprobe/uprobe-tracer to show the arguments type-casted
with u8/u16/u32/u64 in decimal digits instead of hexadecimal.

To minimize compatibility issue, the arguments without type
casting are typed by x64 (or x32 for 32bit arch) by default.

Note: all arguments set by old perf probe without types are
shown in decimal by default.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/Documentation/perf-probe.txt |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt
index 9109c8e..e4991fb 100644
--- a/Documentation/trace/kprobetrace.txt
+++ b/Documentation/trace/kprobetrace.txt
@@ -54,7 +54,10 @@ Types
 -----
 Several types are supported for fetch-args. Kprobe tracer will access memory
 by given type. Prefix 's' and 'u' means those types are signed and unsigned
-respectively. Traced arguments are shown in decimal (signed) or hex (unsigned).
+respectively. 'x' prefix implies it is unsigned. Traced arguments are shown
+in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32'
+or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and
+x86-64 uses x64).
 String type is a special type, which fetches a "null-terminated" string from
 kernel space. This means it will fail and store NULL if the string container
 has been paged out.
diff --git a/Documentation/trace/uprobetracer.txt b/Documentation/trace/uprobetracer.txt
index 7e6d28c..94b6b45 100644
--- a/Documentation/trace/uprobetracer.txt
+++ b/Documentation/trace/uprobetracer.txt
@@ -50,7 +50,10 @@ Types
 -----
 Several types are supported for fetch-args. Uprobe tracer will access memory
 by given type. Prefix 's' and 'u' means those types are signed and unsigned
-respectively. Traced arguments are shown in decimal (signed) or hex (unsigned).
+respectively. 'x' prefix implies it is unsigned. Traced arguments are shown
+in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32'
+or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and
+x86-64 uses x64).
 String type is a special type, which fetches a "null-terminated" string from
 user space.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 725af9d..8c0553d 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -46,10 +46,10 @@ int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name,	\
 const char PRINT_TYPE_FMT_NAME(tname)[] = fmt;				\
 NOKPROBE_SYMBOL(PRINT_TYPE_FUNC_NAME(tname));
 
-DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "0x%Lx")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "%u")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu")
 DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  s8,  "%d")
 DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
 DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index f0c470a..0c0ae54 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -208,7 +208,7 @@ DEFINE_FETCH_##method(u32)		\
 DEFINE_FETCH_##method(u64)
 
 /* Default (unsigned long) fetch type */
-#define __DEFAULT_FETCH_TYPE(t) u##t
+#define __DEFAULT_FETCH_TYPE(t) x##t
 #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
 #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG)
 #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index d217617..f37d123 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,13 +176,12 @@ Each probe argument follows below syntax.
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
-'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
-
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo (*). Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
 On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
 
 TYPES
 -----
-Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
+Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (sNN/uNN) or hex (xNN). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
 String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
 

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

* Re: [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
                   ` (5 preceding siblings ...)
  2016-08-18  8:59 ` [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal Masami Hiramatsu
@ 2016-08-18 14:14 ` Arnaldo Carvalho de Melo
  2016-08-18 16:01   ` Masami Hiramatsu
  2016-08-18 16:03 ` Steven Rostedt
  7 siblings, 1 reply; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-08-18 14:14 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Steven Rostedt, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Em Thu, Aug 18, 2016 at 05:57:32PM +0900, Masami Hiramatsu escreveu:
> Hi Arnaldo and Steven,
> 
> Here is an RFC series of hexadecimal type casting and
> changing default type casting of perf and ftrace.
> 
> I've introduced x8,x16,x32,x64 according to previous
> discussion on LKML.
>   https://lkml.org/lkml/2016/8/10/339
> 
> This series includes not only adding hexadecimal types
> (x8,x16,x32,x64), but also checking it is supported by
> running kernel and keeping the backward compativility.
> 
> [1/6] Add hexadecimal type casting, but does not touch
>    existing types like 'u8'.
> [2/6] Show the supported types on README of ftrace so
>    that user application (e.g. perf) can check that.
> [3/6] Add a type availability check to perf-probe.
> [4/6] Add hexadecimal prefix support to perf-probe if
>    it is supported by the kernel. 
> [5/6] Change the perf-probe default type casting for
>    unsigned type to hexadecimal (for backward compatibility)
> [6/6] Change ftrace's 'uNN' to show value in decimal
>    and use 'xNN' by default (for backward compatibility)
> 
> This way, we can also add "octal" type, pointer type,
> and "character" type etc. and perf can check whether
> the kernel supports it or not. :)

But this requires a kernel update... If we do it all in the tooling
side, no kernel changes are required _and_ newer tools will work with
older kernels, as this is just a formatting issue, the value is there
and from its format one can infer its value, it is not even necessary to
look at its "type".

I understand this is necessary for ftrace, because the pretty printer is
in the kernel, but I don't see why we would prevent tooling from doing
this pretty printing work and make it support any kernel.

I.e. no need at all for checking if the kernel supports anything, just
pretty print it.

- Arnaldo

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

* Re: [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types
  2016-08-18  8:57 ` [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types Masami Hiramatsu
@ 2016-08-18 15:38   ` Steven Rostedt
  2016-08-24  9:25   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: Steven Rostedt @ 2016-08-18 15:38 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Peter Zijlstra,
	Ingo Molnar, Naohiro Aota, Alexander Shishkin, Wang Nan,
	Hemant Kumar

On Thu, 18 Aug 2016 17:57:50 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Add x8/x16/x32/x64 for hexadecimal type casting to kprobe/uprobe
> event tracer.
> 
> These type casts can be used for integer arguments for explicitly
> showing them in hexadecimal digits in formatted text.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>

Acked-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve

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

* Re: [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events
  2016-08-18  8:58 ` [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events Masami Hiramatsu
@ 2016-08-18 15:40   ` Steven Rostedt
  2016-08-24  9:25   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: Steven Rostedt @ 2016-08-18 15:40 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Peter Zijlstra,
	Ingo Molnar, Naohiro Aota, Alexander Shishkin, Wang Nan,
	Hemant Kumar

On Thu, 18 Aug 2016 17:58:15 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Add README entries for kprobe-events and uprobe-events.
> This allows user to check what options can be acceptable
> for running kernel.
> E.g. perf tools can choose correct types for the kernel.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---

Acked-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve

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

* Re: [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal
  2016-08-18  8:59 ` [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal Masami Hiramatsu
@ 2016-08-18 15:41   ` Steven Rostedt
  2016-08-24  9:27   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: Steven Rostedt @ 2016-08-18 15:41 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Peter Zijlstra,
	Ingo Molnar, Naohiro Aota, Alexander Shishkin, Wang Nan,
	Hemant Kumar

On Thu, 18 Aug 2016 17:59:21 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Change kprobe/uprobe-tracer to show the arguments type-casted
> with u8/u16/u32/u64 in decimal digits instead of hexadecimal.
> 
> To minimize compatibility issue, the arguments without type
> casting are typed by x64 (or x32 for 32bit arch) by default.
> 
> Note: all arguments set by old perf probe without types are
> shown in decimal by default.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---

Acked-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve

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

* Re: [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
  2016-08-18 14:14 ` [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Arnaldo Carvalho de Melo
@ 2016-08-18 16:01   ` Masami Hiramatsu
  2016-08-18 16:13     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-18 16:01 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Steven Rostedt, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

On Thu, 18 Aug 2016 11:14:42 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Em Thu, Aug 18, 2016 at 05:57:32PM +0900, Masami Hiramatsu escreveu:
> > Hi Arnaldo and Steven,
> > 
> > Here is an RFC series of hexadecimal type casting and
> > changing default type casting of perf and ftrace.
> > 
> > I've introduced x8,x16,x32,x64 according to previous
> > discussion on LKML.
> >   https://lkml.org/lkml/2016/8/10/339
> > 
> > This series includes not only adding hexadecimal types
> > (x8,x16,x32,x64), but also checking it is supported by
> > running kernel and keeping the backward compativility.
> > 
> > [1/6] Add hexadecimal type casting, but does not touch
> >    existing types like 'u8'.
> > [2/6] Show the supported types on README of ftrace so
> >    that user application (e.g. perf) can check that.
> > [3/6] Add a type availability check to perf-probe.
> > [4/6] Add hexadecimal prefix support to perf-probe if
> >    it is supported by the kernel. 
> > [5/6] Change the perf-probe default type casting for
> >    unsigned type to hexadecimal (for backward compatibility)
> > [6/6] Change ftrace's 'uNN' to show value in decimal
> >    and use 'xNN' by default (for backward compatibility)
> > 
> > This way, we can also add "octal" type, pointer type,
> > and "character" type etc. and perf can check whether
> > the kernel supports it or not. :)
> 
> But this requires a kernel update... If we do it all in the tooling
> side, no kernel changes are required _and_ newer tools will work with
> older kernels, as this is just a formatting issue, the value is there
> and from its format one can infer its value, it is not even necessary to
> look at its "type".
> 
> I understand this is necessary for ftrace, because the pretty printer is
> in the kernel, but I don't see why we would prevent tooling from doing
> this pretty printing work and make it support any kernel.
> 
> I.e. no need at all for checking if the kernel supports anything, just
> pretty print it.

That's should be handled by libtraceevent. And if you need just
a pretty printing, you can do it in python/perl script via perf-script.
Anyway, to see the event parameters via perf tools, we have to use
perf-script with/without scripts. As you know, perf-script without
scripts, the output format depends on libtraceevent. And it seems that
the libtraceevent output depends on ftrace event "format" file.

And also as you can see in Naohiro's report ( https://lkml.org/lkml/2016/8/5/191 )
he was using perf-probe with ftrace trace_pipe interface, which was my
expected usecase. In that case we have to change ftrace side to
support various pretty printing.

IOW, perf only has very strong pretty printing interface - script
based output - for trace event arguments. For lighter use cases,
ftrace provide the print format.

So, I think this is a better meeting point, wouldn't you?

Thank you,


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
  2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
                   ` (6 preceding siblings ...)
  2016-08-18 14:14 ` [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Arnaldo Carvalho de Melo
@ 2016-08-18 16:03 ` Steven Rostedt
  2016-08-18 16:08   ` Arnaldo Carvalho de Melo
  7 siblings, 1 reply; 23+ messages in thread
From: Steven Rostedt @ 2016-08-18 16:03 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Arnaldo Carvalho de Melo, linux-kernel, Peter Zijlstra,
	Ingo Molnar, Naohiro Aota, Alexander Shishkin, Wang Nan,
	Hemant Kumar

On Thu, 18 Aug 2016 17:57:32 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Hi Arnaldo and Steven,
> 

Arnaldo,

I acked all the patches with ftrace in the subject. You can take the
series through your tree.

Thanks,

-- Steve

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

* Re: [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
  2016-08-18 16:03 ` Steven Rostedt
@ 2016-08-18 16:08   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-08-18 16:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Em Thu, Aug 18, 2016 at 12:03:26PM -0400, Steven Rostedt escreveu:
> On Thu, 18 Aug 2016 17:57:32 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > Hi Arnaldo and Steven,
> > 
> 
> Arnaldo,
> 
> I acked all the patches with ftrace in the subject. You can take the
> series through your tree.

Ok!

- Arnaldo

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

* Re: [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
  2016-08-18 16:01   ` Masami Hiramatsu
@ 2016-08-18 16:13     ` Arnaldo Carvalho de Melo
  2016-08-20  3:40       ` Masami Hiramatsu
  0 siblings, 1 reply; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-08-18 16:13 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Steven Rostedt, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Em Fri, Aug 19, 2016 at 01:01:43AM +0900, Masami Hiramatsu escreveu:
> On Thu, 18 Aug 2016 11:14:42 -0300
> Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> 
> > Em Thu, Aug 18, 2016 at 05:57:32PM +0900, Masami Hiramatsu escreveu:
> > > Hi Arnaldo and Steven,
> > > 
> > > Here is an RFC series of hexadecimal type casting and
> > > changing default type casting of perf and ftrace.
> > > 
> > > I've introduced x8,x16,x32,x64 according to previous
> > > discussion on LKML.
> > >   https://lkml.org/lkml/2016/8/10/339
> > > 
> > > This series includes not only adding hexadecimal types
> > > (x8,x16,x32,x64), but also checking it is supported by
> > > running kernel and keeping the backward compativility.
> > > 
> > > [1/6] Add hexadecimal type casting, but does not touch
> > >    existing types like 'u8'.
> > > [2/6] Show the supported types on README of ftrace so
> > >    that user application (e.g. perf) can check that.
> > > [3/6] Add a type availability check to perf-probe.
> > > [4/6] Add hexadecimal prefix support to perf-probe if
> > >    it is supported by the kernel. 
> > > [5/6] Change the perf-probe default type casting for
> > >    unsigned type to hexadecimal (for backward compatibility)
> > > [6/6] Change ftrace's 'uNN' to show value in decimal
> > >    and use 'xNN' by default (for backward compatibility)
> > > 
> > > This way, we can also add "octal" type, pointer type,
> > > and "character" type etc. and perf can check whether
> > > the kernel supports it or not. :)
> > 
> > But this requires a kernel update... If we do it all in the tooling
> > side, no kernel changes are required _and_ newer tools will work with
> > older kernels, as this is just a formatting issue, the value is there
> > and from its format one can infer its value, it is not even necessary to
> > look at its "type".
> > 
> > I understand this is necessary for ftrace, because the pretty printer is
> > in the kernel, but I don't see why we would prevent tooling from doing
> > this pretty printing work and make it support any kernel.
> > 
> > I.e. no need at all for checking if the kernel supports anything, just
> > pretty print it.
> 
> That's should be handled by libtraceevent. And if you need just
> a pretty printing, you can do it in python/perl script via perf-script.
> Anyway, to see the event parameters via perf tools, we have to use
> perf-script with/without scripts. As you know, perf-script without
> scripts, the output format depends on libtraceevent. And it seems that
> the libtraceevent output depends on ftrace event "format" file.
 
> And also as you can see in Naohiro's report ( https://lkml.org/lkml/2016/8/5/191 )
> he was using perf-probe with ftrace trace_pipe interface, which was my
> expected usecase. In that case we have to change ftrace side to
> support various pretty printing.

Sure, if one wants to have pretty printing via trace_pipe, then a kernel
reboot is needed, I'm talking about those who don't want to or can't
reboot their machines :-)

But anyway, your patches allow seeing those events in decimal for people
that can reboot their machine when that wasn't possible without extra
scripting via perl/python, a clear advance!

It remains to be coded a way to achieve the same result without
requiring a kernel reboot, i.e. a tooling only change.
 
> IOW, perf only has very strong pretty printing interface - script
> based output - for trace event arguments. For lighter use cases,
> ftrace provide the print format.
 
> So, I think this is a better meeting point, wouldn't you?

If upgrading the kernel is possible, yes.

- Arnaldo

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

* Re: [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting
  2016-08-18 16:13     ` Arnaldo Carvalho de Melo
@ 2016-08-20  3:40       ` Masami Hiramatsu
  0 siblings, 0 replies; 23+ messages in thread
From: Masami Hiramatsu @ 2016-08-20  3:40 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Steven Rostedt, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

On Thu, 18 Aug 2016 13:13:21 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Em Fri, Aug 19, 2016 at 01:01:43AM +0900, Masami Hiramatsu escreveu:
> > On Thu, 18 Aug 2016 11:14:42 -0300
> > Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > 
> > > Em Thu, Aug 18, 2016 at 05:57:32PM +0900, Masami Hiramatsu escreveu:
> > > > Hi Arnaldo and Steven,
> > > > 
> > > > Here is an RFC series of hexadecimal type casting and
> > > > changing default type casting of perf and ftrace.
> > > > 
> > > > I've introduced x8,x16,x32,x64 according to previous
> > > > discussion on LKML.
> > > >   https://lkml.org/lkml/2016/8/10/339
> > > > 
> > > > This series includes not only adding hexadecimal types
> > > > (x8,x16,x32,x64), but also checking it is supported by
> > > > running kernel and keeping the backward compativility.
> > > > 
> > > > [1/6] Add hexadecimal type casting, but does not touch
> > > >    existing types like 'u8'.
> > > > [2/6] Show the supported types on README of ftrace so
> > > >    that user application (e.g. perf) can check that.
> > > > [3/6] Add a type availability check to perf-probe.
> > > > [4/6] Add hexadecimal prefix support to perf-probe if
> > > >    it is supported by the kernel. 
> > > > [5/6] Change the perf-probe default type casting for
> > > >    unsigned type to hexadecimal (for backward compatibility)
> > > > [6/6] Change ftrace's 'uNN' to show value in decimal
> > > >    and use 'xNN' by default (for backward compatibility)
> > > > 
> > > > This way, we can also add "octal" type, pointer type,
> > > > and "character" type etc. and perf can check whether
> > > > the kernel supports it or not. :)
> > > 
> > > But this requires a kernel update... If we do it all in the tooling
> > > side, no kernel changes are required _and_ newer tools will work with
> > > older kernels, as this is just a formatting issue, the value is there
> > > and from its format one can infer its value, it is not even necessary to
> > > look at its "type".
> > > 
> > > I understand this is necessary for ftrace, because the pretty printer is
> > > in the kernel, but I don't see why we would prevent tooling from doing
> > > this pretty printing work and make it support any kernel.
> > > 
> > > I.e. no need at all for checking if the kernel supports anything, just
> > > pretty print it.
> > 
> > That's should be handled by libtraceevent. And if you need just
> > a pretty printing, you can do it in python/perl script via perf-script.
> > Anyway, to see the event parameters via perf tools, we have to use
> > perf-script with/without scripts. As you know, perf-script without
> > scripts, the output format depends on libtraceevent. And it seems that
> > the libtraceevent output depends on ftrace event "format" file.
>  
> > And also as you can see in Naohiro's report ( https://lkml.org/lkml/2016/8/5/191 )
> > he was using perf-probe with ftrace trace_pipe interface, which was my
> > expected usecase. In that case we have to change ftrace side to
> > support various pretty printing.
> 
> Sure, if one wants to have pretty printing via trace_pipe, then a kernel
> reboot is needed, I'm talking about those who don't want to or can't
> reboot their machines :-)
> 
> But anyway, your patches allow seeing those events in decimal for people
> that can reboot their machine when that wasn't possible without extra
> scripting via perl/python, a clear advance!
> 
> It remains to be coded a way to achieve the same result without
> requiring a kernel reboot, i.e. a tooling only change.

Hmm, one solution for user space tool is to identify the probed event
from event name, and decide output format based on the format locally
stored, like cached entries. Actually, current perf-probe to perf-script
execution chain lacks such kind of information, that is a problem.

 DWARF -> perf-probe -> ftrace -> perf-record -> perf-script

perf-probe can read DWARF(debuginfo) so it can handle a variety of types,
but between perf-probe to ftrace, it lacks type information and all
types falls into s8/16/32/64, u8/16/32/64, string and bitfield.
So after that process, perf-record treats data as a raw binary,
and perf-script tries to parse that binary based on ftrace's event
format. 

But if we can pass the data format in perf-cache entries like below

 DWARF -> perf-probe -> ftrace -> perf-record -+-> perf-script
                 +-------> probe-cache entry --+

then perf-probe can pass correct format to perf-script.

But anyway, I will update ftrace to add other types since that will
help ftrace users.
 
Thanks,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH 3/6] perf probe: Add supported type casting of running kernel
  2016-08-18  8:58 ` [PATCH 3/6] perf probe: Add supported type casting of running kernel Masami Hiramatsu
@ 2016-08-23 19:45   ` Arnaldo Carvalho de Melo
  2016-08-24  9:26   ` [tip:perf/core] perf probe: Add supported for type casting by the " tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-08-23 19:45 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Steven Rostedt, linux-kernel, Peter Zijlstra, Ingo Molnar,
	Naohiro Aota, Alexander Shishkin, Wang Nan, Hemant Kumar

Em Thu, Aug 18, 2016 at 05:58:31PM +0900, Masami Hiramatsu escreveu:
> Add a checking routine what types are supported by the
> running kernel by finding the pattern in
> <debugfs>/tracing/README.

Fails in several distros, I'm fixing it:

# time dm
 1 67.863552726 alpine:3.4: Ok
 2 26.710853767 android-ndk:r12b-arm: Ok
 3 72.985361634 archlinux:latest: Ok
 4 19.637909096 centos:5: FAIL
  CC       /tmp/build/perf/util/probe-event.o
cc1: warnings being treated as errors
util/probe-file.c: In function 'probe_type_is_available':
util/probe-file.c:904: warning: comparison of unsigned expression < 0 is always false
mv: cannot stat `/tmp/build/perf/util/.probe-file.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/util/probe-file.o] Error 1
make[3]: *** Waiting for unfinished jobs....
 5 28.720326873 centos:6: FAIL
cc1: warnings being treated as errors
util/probe-file.c: In function 'probe_type_is_available':
util/probe-file.c:904: error: comparison of unsigned expression < 0 is always false
mv: cannot stat `/tmp/build/perf/util/.probe-file.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/util/probe-file.o] Error 1
make[3]: *** Waiting for unfinished jobs....
 6 70.156507794 centos:7: Ok
 7 32.013330592 debian:7: FAIL
  CC       /tmp/build/perf/util/probe-file.o
util/probe-file.c: In function 'probe_type_is_available':
util/probe-file.c:904:2: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
cc1: all warnings being treated as errors
mv: cannot stat `/tmp/build/perf/util/.probe-file.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/util/probe-file.o] Error 1
make[3]: *** Waiting for unfinished jobs....
 8 69.603178590 debian:8: Ok
 9 73.783068558 debian:experimental: Ok
10 69.957097133 fedora:20: Ok
11 76.603382387 fedora:21: Ok
12 73.468157842 fedora:22: Ok
13 71.936508182 fedora:23: Ok
14 77.361195679 fedora:24: Ok
15 38.279025856 fedora:24-x-ARC-uClibc: Ok
16 97.249261355 fedora:rawhide: Ok
17 98.245080998 mageia:5: Ok
18 94.932568645 opensuse:13.2: Ok
19 75.037585460 opensuse:42.1: Ok
20 78.874088196 opensuse:tumbleweed: Ok
21 29.516286324 ubuntu:12.04.5: FAIL
  CC       /tmp/build/perf/util/probe-event.o
util/probe-file.c: In function 'probe_type_is_available':
util/probe-file.c:904:2: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
cc1: all warnings being treated as errors
mv: cannot stat `/tmp/build/perf/util/.probe-file.o.tmp': No such file or directory
make[3]: *** [/tmp/build/perf/util/probe-file.o] Error 1
make[3]: *** Waiting for unfinished jobs....
22 67.473466290 ubuntu:14.04.4: Ok
23 70.052930002 ubuntu:15.10: Ok
24 73.910662998 ubuntu:16.04: Ok
25 58.592432948 ubuntu:16.04-x-arm: Ok
26 53.732729132 ubuntu:16.04-x-arm64: Ok
27 53.279460667 ubuntu:16.04-x-powerpc64: Ok
28 53.933970903 ubuntu:16.04-x-powerpc64el: Ok
29 73.724853906 ubuntu:16.10: Ok
30 55.651095622 ubuntu:16.10-x-s390: Ok

 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  tools/perf/util/probe-file.c   |   57 ++++++++++++++++++++++++++++++++++++++++
>  tools/perf/util/probe-file.h   |   10 +++++++
>  tools/perf/util/probe-finder.c |    1 +
>  3 files changed, 68 insertions(+)
> 
> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> index 9aed9c3..552e56b 100644
> --- a/tools/perf/util/probe-file.c
> +++ b/tools/perf/util/probe-file.c
> @@ -855,3 +855,60 @@ int probe_cache__show_all_caches(struct strfilter *filter)
>  
>  	return 0;
>  }
> +
> +static struct {
> +	const char *pattern;
> +	bool	avail;
> +	bool	checked;
> +} probe_type_table[] = {
> +#define DEFINE_TYPE(idx, pat, def_avail)	\
> +	[idx] = {.pattern = pat, .avail = (def_avail)}
> +	DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true),
> +	DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
> +	DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
> +	DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
> +	DEFINE_TYPE(PROBE_TYPE_BITFIELD,
> +		    "* b<bit-width>@<bit-offset>/<container-size>", true),
> +};
> +
> +bool probe_type_is_available(enum probe_type type)
> +{
> +	FILE *fp;
> +	char *buf = NULL;
> +	size_t len = 0;
> +	bool target_line = false;
> +	bool ret = probe_type_table[type].avail;
> +
> +	if (type < 0 || type >= PROBE_TYPE_END)
> +		return false;
> +	/* We don't have to check the type which supported by default */
> +	if (ret || probe_type_table[type].checked)
> +		return ret;
> +
> +	if (asprintf(&buf, "%s/README", tracing_path) < 0)
> +		return ret;
> +
> +	fp = fopen(buf, "r");
> +	if (!fp)
> +		goto end;
> +
> +	zfree(&buf);
> +	while (getline(&buf, &len, fp) > 0 && !ret) {
> +		if (!target_line) {
> +			target_line = !!strstr(buf, " type: ");
> +			if (!target_line)
> +				continue;
> +		} else if (strstr(buf, "\t          ") != buf)
> +			break;
> +		ret = strglobmatch(buf, probe_type_table[type].pattern);
> +	}
> +	/* Cache the result */
> +	probe_type_table[type].checked = true;
> +	probe_type_table[type].avail = ret;
> +
> +	fclose(fp);
> +end:
> +	free(buf);
> +
> +	return ret;
> +}
> diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
> index 9577b5c..eba44c3 100644
> --- a/tools/perf/util/probe-file.h
> +++ b/tools/perf/util/probe-file.h
> @@ -19,6 +19,15 @@ struct probe_cache {
>  	struct list_head entries;
>  };
>  
> +enum probe_type {
> +	PROBE_TYPE_U = 0,
> +	PROBE_TYPE_S,
> +	PROBE_TYPE_X,
> +	PROBE_TYPE_STRING,
> +	PROBE_TYPE_BITFIELD,
> +	PROBE_TYPE_END,
> +};
> +
>  #define PF_FL_UPROBE	1
>  #define PF_FL_RW	2
>  #define for_each_probe_cache_entry(entry, pcache) \
> @@ -54,6 +63,7 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
>  struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
>  					const char *group, const char *event);
>  int probe_cache__show_all_caches(struct strfilter *filter);
> +bool probe_type_is_available(enum probe_type type);
>  #else	/* ! HAVE_LIBELF_SUPPORT */
>  static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
>  {
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 5c290c6..24dbe23 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -39,6 +39,7 @@
>  #include "util.h"
>  #include "symbol.h"
>  #include "probe-finder.h"
> +#include "probe-file.h"
>  
>  /* Kprobe tracer basic type is up to u64 */
>  #define MAX_BASIC_TYPE_BITS	64

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

* [tip:perf/core] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types
  2016-08-18  8:57 ` [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types Masami Hiramatsu
  2016-08-18 15:38   ` Steven Rostedt
@ 2016-08-24  9:25   ` tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-08-24  9:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: wangnan0, peterz, acme, naohiro.aota, tglx, linux-kernel,
	rostedt, alexander.shishkin, hpa, mingo, mhiramat, hemant

Commit-ID:  17ce3dc7e5a0e4796cc7838d1f7b2531d0bca130
Gitweb:     http://git.kernel.org/tip/17ce3dc7e5a0e4796cc7838d1f7b2531d0bca130
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 18 Aug 2016 17:57:50 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Aug 2016 15:38:09 -0300

ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types

Add x8/x16/x32/x64 for hexadecimal type casting to kprobe/uprobe event
tracer.

These type casts can be used for integer arguments for explicitly
showing them in hexadecimal digits in formatted text.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Naohiro Aota <naohiro.aota@hgst.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/147151067029.12957.11591314629326414783.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 Documentation/trace/kprobetrace.txt     |  4 ++--
 Documentation/trace/uprobetracer.txt    |  4 ++--
 kernel/trace/trace_kprobe.c             |  4 ++++
 kernel/trace/trace_probe.c              | 30 +++++++++++++++++-------------
 kernel/trace/trace_probe.h              |  9 +++++++++
 kernel/trace/trace_uprobe.c             |  4 ++++
 tools/perf/Documentation/perf-probe.txt |  4 ++--
 7 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt
index ea52ec1..9109c8e 100644
--- a/Documentation/trace/kprobetrace.txt
+++ b/Documentation/trace/kprobetrace.txt
@@ -44,8 +44,8 @@ Synopsis of kprobe_events
   +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
   NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
   FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
-		  (u8/u16/u32/u64/s8/s16/s32/s64), "string" and bitfield
-		  are supported.
+		  (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
+		  (x8/x16/x32/x64), "string" and bitfield are supported.
 
   (*) only for return probe.
   (**) this is useful for fetching a field of data structures.
diff --git a/Documentation/trace/uprobetracer.txt b/Documentation/trace/uprobetracer.txt
index 72d1cd4..7e6d28c 100644
--- a/Documentation/trace/uprobetracer.txt
+++ b/Documentation/trace/uprobetracer.txt
@@ -40,8 +40,8 @@ Synopsis of uprobe_tracer
    +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
    NAME=FETCHARG     : Set NAME as the argument name of FETCHARG.
    FETCHARG:TYPE     : Set TYPE as the type of FETCHARG. Currently, basic types
-		       (u8/u16/u32/u64/s8/s16/s32/s64), "string" and bitfield
-		       are supported.
+		       (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
+		       (x8/x16/x32/x64), "string" and bitfield are supported.
 
   (*) only for return probe.
   (**) this is useful for fetching a field of data structures.
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 9aedb0b..eb6c9f1 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -253,6 +253,10 @@ static const struct fetch_type kprobes_fetch_type_table[] = {
 	ASSIGN_FETCH_TYPE(s16, u16, 1),
 	ASSIGN_FETCH_TYPE(s32, u32, 1),
 	ASSIGN_FETCH_TYPE(s64, u64, 1),
+	ASSIGN_FETCH_TYPE_ALIAS(x8,  u8,  u8,  0),
+	ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
 
 	ASSIGN_FETCH_TYPE_END
 };
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 74e80a5..725af9d 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -36,24 +36,28 @@ const char *reserved_field_names[] = {
 };
 
 /* Printing  in basic type function template */
-#define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt)				\
-int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, const char *name,	\
+#define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt)			\
+int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name,	\
 				void *data, void *ent)			\
 {									\
 	trace_seq_printf(s, " %s=" fmt, name, *(type *)data);		\
 	return !trace_seq_has_overflowed(s);				\
 }									\
-const char PRINT_TYPE_FMT_NAME(type)[] = fmt;				\
-NOKPROBE_SYMBOL(PRINT_TYPE_FUNC_NAME(type));
-
-DEFINE_BASIC_PRINT_TYPE_FUNC(u8 , "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u32, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u64, "0x%Lx")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  "%d")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%d")
-DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%Ld")
+const char PRINT_TYPE_FMT_NAME(tname)[] = fmt;				\
+NOKPROBE_SYMBOL(PRINT_TYPE_FUNC_NAME(tname));
+
+DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "0x%Lx")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  s8,  "%d")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
+DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x8,  u8,  "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
+DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
 
 /* Print type function for string type */
 int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, const char *name,
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index 45400ca..f0c470a 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -149,6 +149,11 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(s8);
 DECLARE_BASIC_PRINT_TYPE_FUNC(s16);
 DECLARE_BASIC_PRINT_TYPE_FUNC(s32);
 DECLARE_BASIC_PRINT_TYPE_FUNC(s64);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x8);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x16);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x32);
+DECLARE_BASIC_PRINT_TYPE_FUNC(x64);
+
 DECLARE_BASIC_PRINT_TYPE_FUNC(string);
 
 #define FETCH_FUNC_NAME(method, type)	fetch_##method##_##type
@@ -234,6 +239,10 @@ ASSIGN_FETCH_FUNC(file_offset, ftype),			\
 #define ASSIGN_FETCH_TYPE(ptype, ftype, sign)			\
 	__ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype)
 
+/* If ptype is an alias of atype, use this macro (show atype in format) */
+#define ASSIGN_FETCH_TYPE_ALIAS(ptype, atype, ftype, sign)		\
+	__ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #atype)
+
 #define ASSIGN_FETCH_TYPE_END {}
 
 #define FETCH_TYPE_STRING	0
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index c534854..7a68732 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -211,6 +211,10 @@ static const struct fetch_type uprobes_fetch_type_table[] = {
 	ASSIGN_FETCH_TYPE(s16, u16, 1),
 	ASSIGN_FETCH_TYPE(s32, u32, 1),
 	ASSIGN_FETCH_TYPE(s64, u64, 1),
+	ASSIGN_FETCH_TYPE_ALIAS(x8,  u8,  u8,  0),
+	ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
 
 	ASSIGN_FETCH_TYPE_END
 };
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index b303bcd..aa33325 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,13 +176,13 @@ Each probe argument follows below syntax.
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
-'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
 
 On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
 
 TYPES
 -----
-Basic types (u8/u16/u32/u64/s8/s16/s32/s64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
+Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
 String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
 

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

* [tip:perf/core] ftrace: probe: Add README entries for k/uprobe-events
  2016-08-18  8:58 ` [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events Masami Hiramatsu
  2016-08-18 15:40   ` Steven Rostedt
@ 2016-08-24  9:25   ` tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-08-24  9:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: rostedt, wangnan0, linux-kernel, peterz, acme, hemant,
	alexander.shishkin, tglx, hpa, mhiramat, naohiro.aota, mingo

Commit-ID:  864256255597aad86abcecbe6c53da8852ded15b
Gitweb:     http://git.kernel.org/tip/864256255597aad86abcecbe6c53da8852ded15b
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 18 Aug 2016 17:58:15 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Aug 2016 15:39:57 -0300

ftrace: probe: Add README entries for k/uprobe-events

Add README entries for kprobe-events and uprobe-events.
This allows user to check what options can be acceptable
for running kernel.
E.g. perf tools can choose correct types for the kernel.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Naohiro Aota <naohiro.aota@hgst.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/147151069524.12957.12957179170304055028.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 kernel/trace/trace.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index dade4c9..1e2ce3b 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4123,6 +4123,30 @@ static const char readme_msg[] =
 	"\t\t\t  traces\n"
 #endif
 #endif /* CONFIG_STACK_TRACER */
+#ifdef CONFIG_KPROBE_EVENT
+	"  kprobe_events\t\t- Add/remove/show the kernel dynamic events\n"
+	"\t\t\t  Write into this file to define/undefine new trace events.\n"
+#endif
+#ifdef CONFIG_UPROBE_EVENT
+	"  uprobe_events\t\t- Add/remove/show the userspace dynamic events\n"
+	"\t\t\t  Write into this file to define/undefine new trace events.\n"
+#endif
+#if defined(CONFIG_KPROBE_EVENT) || defined(CONFIG_UPROBE_EVENT)
+	"\t  accepts: event-definitions (one definition per line)\n"
+	"\t   Format: p|r[:[<group>/]<event>] <place> [<args>]\n"
+	"\t           -:[<group>/]<event>\n"
+#ifdef CONFIG_KPROBE_EVENT
+	"\t    place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
+#endif
+#ifdef CONFIG_UPROBE_EVENT
+	"\t    place: <path>:<offset>\n"
+#endif
+	"\t     args: <name>=fetcharg[:type]\n"
+	"\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n"
+	"\t           $stack<index>, $stack, $retval, $comm\n"
+	"\t     type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string,\n"
+	"\t           b<bit-width>@<bit-offset>/<container-size>\n"
+#endif
 	"  events/\t\t- Directory containing all trace event subsystems:\n"
 	"      enable\t\t- Write 0/1 to enable/disable tracing of all events\n"
 	"  events/<system>/\t- Directory containing all trace events for <system>:\n"

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

* [tip:perf/core] perf probe: Add supported for type casting by the running kernel
  2016-08-18  8:58 ` [PATCH 3/6] perf probe: Add supported type casting of running kernel Masami Hiramatsu
  2016-08-23 19:45   ` Arnaldo Carvalho de Melo
@ 2016-08-24  9:26   ` tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-08-24  9:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, peterz, wangnan0, mingo, hpa, mhiramat, alexander.shishkin,
	hemant, rostedt, naohiro.aota, linux-kernel, tglx

Commit-ID:  180b20616ce57e93eb692170c793be94c456b1e2
Gitweb:     http://git.kernel.org/tip/180b20616ce57e93eb692170c793be94c456b1e2
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 18 Aug 2016 17:58:31 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Aug 2016 17:03:31 -0300

perf probe: Add supported for type casting by the running kernel

Add a checking routine what types are supported by the running kernel by
finding the pattern in <debugfs>/tracing/README.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Naohiro Aota <naohiro.aota@hgst.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/147151071172.12957.3340095690753291085.stgit@devbox
[ 'enum probe_type' has no negative entries, so ends up as 'unsigned', remove '< 0'
   test to fix the build on at least centos:5, debian:7 & ubuntu:12.04.5 ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-file.c   | 57 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/probe-file.h   | 10 ++++++++
 tools/perf/util/probe-finder.c |  1 +
 3 files changed, 68 insertions(+)

diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 9c3b9ed..697ef66 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -877,3 +877,60 @@ int probe_cache__show_all_caches(struct strfilter *filter)
 
 	return 0;
 }
+
+static struct {
+	const char *pattern;
+	bool	avail;
+	bool	checked;
+} probe_type_table[] = {
+#define DEFINE_TYPE(idx, pat, def_avail)	\
+	[idx] = {.pattern = pat, .avail = (def_avail)}
+	DEFINE_TYPE(PROBE_TYPE_U, "* u8/16/32/64,*", true),
+	DEFINE_TYPE(PROBE_TYPE_S, "* s8/16/32/64,*", true),
+	DEFINE_TYPE(PROBE_TYPE_X, "* x8/16/32/64,*", false),
+	DEFINE_TYPE(PROBE_TYPE_STRING, "* string,*", true),
+	DEFINE_TYPE(PROBE_TYPE_BITFIELD,
+		    "* b<bit-width>@<bit-offset>/<container-size>", true),
+};
+
+bool probe_type_is_available(enum probe_type type)
+{
+	FILE *fp;
+	char *buf = NULL;
+	size_t len = 0;
+	bool target_line = false;
+	bool ret = probe_type_table[type].avail;
+
+	if (type >= PROBE_TYPE_END)
+		return false;
+	/* We don't have to check the type which supported by default */
+	if (ret || probe_type_table[type].checked)
+		return ret;
+
+	if (asprintf(&buf, "%s/README", tracing_path) < 0)
+		return ret;
+
+	fp = fopen(buf, "r");
+	if (!fp)
+		goto end;
+
+	zfree(&buf);
+	while (getline(&buf, &len, fp) > 0 && !ret) {
+		if (!target_line) {
+			target_line = !!strstr(buf, " type: ");
+			if (!target_line)
+				continue;
+		} else if (strstr(buf, "\t          ") != buf)
+			break;
+		ret = strglobmatch(buf, probe_type_table[type].pattern);
+	}
+	/* Cache the result */
+	probe_type_table[type].checked = true;
+	probe_type_table[type].avail = ret;
+
+	fclose(fp);
+end:
+	free(buf);
+
+	return ret;
+}
diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
index 9577b5c..eba44c3 100644
--- a/tools/perf/util/probe-file.h
+++ b/tools/perf/util/probe-file.h
@@ -19,6 +19,15 @@ struct probe_cache {
 	struct list_head entries;
 };
 
+enum probe_type {
+	PROBE_TYPE_U = 0,
+	PROBE_TYPE_S,
+	PROBE_TYPE_X,
+	PROBE_TYPE_STRING,
+	PROBE_TYPE_BITFIELD,
+	PROBE_TYPE_END,
+};
+
 #define PF_FL_UPROBE	1
 #define PF_FL_RW	2
 #define for_each_probe_cache_entry(entry, pcache) \
@@ -54,6 +63,7 @@ struct probe_cache_entry *probe_cache__find(struct probe_cache *pcache,
 struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
 					const char *group, const char *event);
 int probe_cache__show_all_caches(struct strfilter *filter);
+bool probe_type_is_available(enum probe_type type);
 #else	/* ! HAVE_LIBELF_SUPPORT */
 static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
 {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 5c290c6..24dbe23 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -39,6 +39,7 @@
 #include "util.h"
 #include "symbol.h"
 #include "probe-finder.h"
+#include "probe-file.h"
 
 /* Kprobe tracer basic type is up to u64 */
 #define MAX_BASIC_TYPE_BITS	64

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

* [tip:perf/core] perf probe: Support hexadecimal casting
  2016-08-18  8:58 ` [PATCH 4/6] perf probe: Support hexadecimal casting Masami Hiramatsu
@ 2016-08-24  9:26   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-08-24  9:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hemant, tglx, mhiramat, rostedt, peterz, hpa, alexander.shishkin,
	mingo, acme, linux-kernel, naohiro.aota, wangnan0

Commit-ID:  925437872525ee229736a9a8bdf804fc98f75b44
Gitweb:     http://git.kernel.org/tip/925437872525ee229736a9a8bdf804fc98f75b44
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 18 Aug 2016 17:58:47 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Aug 2016 17:06:37 -0300

perf probe: Support hexadecimal casting

Support hexadecimal unsigned integer casting by 'x'.  This allows user
to explicitly specify the output format of the probe arguments as
hexadecimal.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Naohiro Aota <naohiro.aota@hgst.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/147151072679.12957.4458656416765710753.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-probe.txt |  4 ++--
 tools/perf/util/probe-finder.c          | 17 ++++++++++-------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index aa33325..d217617 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,13 +176,13 @@ Each probe argument follows below syntax.
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
-'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
 
 On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
 
 TYPES
 -----
-Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe.
+Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
 String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
 
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 24dbe23..f18cd6b 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -298,13 +298,13 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 	char sbuf[STRERR_BUFSIZE];
 	int bsize, boffs, total;
 	int ret;
-	char sign;
+	char prefix;
 
 	/* TODO: check all types */
-	if (cast && strcmp(cast, "string") != 0 &&
+	if (cast && strcmp(cast, "string") != 0 && strcmp(cast, "x") != 0 &&
 	    strcmp(cast, "s") != 0 && strcmp(cast, "u") != 0) {
 		/* Non string type is OK */
-		/* and respect signedness cast */
+		/* and respect signedness/hexadecimal cast */
 		tvar->type = strdup(cast);
 		return (tvar->type == NULL) ? -ENOMEM : 0;
 	}
@@ -366,11 +366,14 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 	}
 
 	if (cast && (strcmp(cast, "u") == 0))
-		sign = 'u';
+		prefix = 'u';
 	else if (cast && (strcmp(cast, "s") == 0))
-		sign = 's';
+		prefix = 's';
+	else if (cast && (strcmp(cast, "x") == 0) &&
+		 probe_type_is_available(PROBE_TYPE_X))
+		prefix = 'x';
 	else
-		sign = die_is_signed_type(&type) ? 's' : 'u';
+		prefix = die_is_signed_type(&type) ? 's' : 'u';
 
 	ret = dwarf_bytesize(&type);
 	if (ret <= 0)
@@ -384,7 +387,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 			dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
 		ret = MAX_BASIC_TYPE_BITS;
 	}
-	ret = snprintf(buf, 16, "%c%d", sign, ret);
+	ret = snprintf(buf, 16, "%c%d", prefix, ret);
 
 formatted:
 	if (ret < 0 || ret >= 16) {

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

* [tip:perf/core] perf probe: Use hexadecimal type by default if possible
  2016-08-18  8:59 ` [PATCH 5/6] perf-probe: Use hexadecimal type by default if possible Masami Hiramatsu
@ 2016-08-24  9:27   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-08-24  9:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mhiramat, linux-kernel, wangnan0, peterz, hpa, hemant,
	tglx, naohiro.aota, mingo, rostedt, alexander.shishkin

Commit-ID:  9880ce4a69ba5c66a5ffdd711fe446bd0226bd8c
Gitweb:     http://git.kernel.org/tip/9880ce4a69ba5c66a5ffdd711fe446bd0226bd8c
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 18 Aug 2016 17:59:07 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Aug 2016 17:06:37 -0300

perf probe: Use hexadecimal type by default if possible

Use hexadecimal type by default if it is available on current running
kernel.

This keeps the default behavior of perf probe after changing the output
format of 'u8/16/32/64' to unsigned decimal number.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Naohiro Aota <naohiro.aota@hgst.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/147151074685.12957.16415861010796255514.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/probe-finder.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index f18cd6b..ac4740f 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -373,7 +373,8 @@ static int convert_variable_type(Dwarf_Die *vr_die,
 		 probe_type_is_available(PROBE_TYPE_X))
 		prefix = 'x';
 	else
-		prefix = die_is_signed_type(&type) ? 's' : 'u';
+		prefix = die_is_signed_type(&type) ? 's' :
+			 probe_type_is_available(PROBE_TYPE_X) ? 'x' : 'u';
 
 	ret = dwarf_bytesize(&type);
 	if (ret <= 0)

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

* [tip:perf/core] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal
  2016-08-18  8:59 ` [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal Masami Hiramatsu
  2016-08-18 15:41   ` Steven Rostedt
@ 2016-08-24  9:27   ` tip-bot for Masami Hiramatsu
  1 sibling, 0 replies; 23+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2016-08-24  9:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, acme, naohiro.aota, wangnan0, rostedt, hemant,
	linux-kernel, peterz, hpa, mingo, alexander.shishkin, mhiramat

Commit-ID:  bdca79c2bf40556b664c9b1c32aec103e9bdb4a9
Gitweb:     http://git.kernel.org/tip/bdca79c2bf40556b664c9b1c32aec103e9bdb4a9
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 18 Aug 2016 17:59:21 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 23 Aug 2016 17:06:38 -0300

ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal

Change kprobe/uprobe-tracer to show the arguments type-casted
with u8/u16/u32/u64 in decimal digits instead of hexadecimal.

To minimize compatibility issue, the arguments without type
casting are typed by x64 (or x32 for 32bit arch) by default.

Note: all arguments set by old perf probe without types are
shown in decimal by default.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Naohiro Aota <naohiro.aota@hgst.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/147151076135.12957.14684546093034343894.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 Documentation/trace/kprobetrace.txt     | 5 ++++-
 Documentation/trace/uprobetracer.txt    | 5 ++++-
 kernel/trace/trace_probe.c              | 8 ++++----
 kernel/trace/trace_probe.h              | 2 +-
 tools/perf/Documentation/perf-probe.txt | 5 ++---
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt
index 9109c8e..e4991fb 100644
--- a/Documentation/trace/kprobetrace.txt
+++ b/Documentation/trace/kprobetrace.txt
@@ -54,7 +54,10 @@ Types
 -----
 Several types are supported for fetch-args. Kprobe tracer will access memory
 by given type. Prefix 's' and 'u' means those types are signed and unsigned
-respectively. Traced arguments are shown in decimal (signed) or hex (unsigned).
+respectively. 'x' prefix implies it is unsigned. Traced arguments are shown
+in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32'
+or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and
+x86-64 uses x64).
 String type is a special type, which fetches a "null-terminated" string from
 kernel space. This means it will fail and store NULL if the string container
 has been paged out.
diff --git a/Documentation/trace/uprobetracer.txt b/Documentation/trace/uprobetracer.txt
index 7e6d28c..94b6b45 100644
--- a/Documentation/trace/uprobetracer.txt
+++ b/Documentation/trace/uprobetracer.txt
@@ -50,7 +50,10 @@ Types
 -----
 Several types are supported for fetch-args. Uprobe tracer will access memory
 by given type. Prefix 's' and 'u' means those types are signed and unsigned
-respectively. Traced arguments are shown in decimal (signed) or hex (unsigned).
+respectively. 'x' prefix implies it is unsigned. Traced arguments are shown
+in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32'
+or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and
+x86-64 uses x64).
 String type is a special type, which fetches a "null-terminated" string from
 user space.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 725af9d..8c0553d 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -46,10 +46,10 @@ int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name,	\
 const char PRINT_TYPE_FMT_NAME(tname)[] = fmt;				\
 NOKPROBE_SYMBOL(PRINT_TYPE_FUNC_NAME(tname));
 
-DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "0x%x")
-DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "0x%Lx")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "%u")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u")
+DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu")
 DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  s8,  "%d")
 DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
 DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index f0c470a..0c0ae54 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -208,7 +208,7 @@ DEFINE_FETCH_##method(u32)		\
 DEFINE_FETCH_##method(u64)
 
 /* Default (unsigned long) fetch type */
-#define __DEFAULT_FETCH_TYPE(t) u##t
+#define __DEFAULT_FETCH_TYPE(t) x##t
 #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
 #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG)
 #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE)
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index d217617..f37d123 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -176,13 +176,12 @@ Each probe argument follows below syntax.
 
 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
 '$vars' and '$params' special arguments are also available for NAME, '$vars' is expanded to the local variables (including function parameters) which can access at given probe point. '$params' is expanded to only the function parameters.
-'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
-
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo (*). Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal integers (x/x8/x16/x32/x64), signedness casting (u/s), "string" and bitfield are supported. (see TYPES for detail)
 On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
 
 TYPES
 -----
-Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (signed) or hex (unsigned). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
+Basic types (u8/u16/u32/u64/s8/s16/s32/s64) and hexadecimal integers (x8/x16/x32/x64) are integer types. Prefix 's' and 'u' means those types are signed and unsigned respectively, and 'x' means that is shown in hexadecimal format. Traced arguments are shown in decimal (sNN/uNN) or hex (xNN). You can also use 's' or 'u' to specify only signedness and leave its size auto-detected by perf probe. Moreover, you can use 'x' to explicitly specify to be shown in hexadecimal (the size is also auto-detected).
 String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
 Bitfield is another special type, which takes 3 parameters, bit-width, bit-offset, and container-size (usually 32). The syntax is;
 

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

end of thread, other threads:[~2016-08-24  9:47 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-18  8:57 [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Masami Hiramatsu
2016-08-18  8:57 ` [PATCH 1/6] ftrace: kprobe: uprobe: Add x8/x16/x32/x64 for hexadecimal types Masami Hiramatsu
2016-08-18 15:38   ` Steven Rostedt
2016-08-24  9:25   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2016-08-18  8:58 ` [PATCH 2/6] ftrace: probe: Add README entries for k/uprobe-events Masami Hiramatsu
2016-08-18 15:40   ` Steven Rostedt
2016-08-24  9:25   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2016-08-18  8:58 ` [PATCH 3/6] perf probe: Add supported type casting of running kernel Masami Hiramatsu
2016-08-23 19:45   ` Arnaldo Carvalho de Melo
2016-08-24  9:26   ` [tip:perf/core] perf probe: Add supported for type casting by the " tip-bot for Masami Hiramatsu
2016-08-18  8:58 ` [PATCH 4/6] perf probe: Support hexadecimal casting Masami Hiramatsu
2016-08-24  9:26   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2016-08-18  8:59 ` [PATCH 5/6] perf-probe: Use hexadecimal type by default if possible Masami Hiramatsu
2016-08-24  9:27   ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2016-08-18  8:59 ` [PATCH 6/6] ftrace: kprobe: uprobe: Show u8/u16/u32/u64 types in decimal Masami Hiramatsu
2016-08-18 15:41   ` Steven Rostedt
2016-08-24  9:27   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2016-08-18 14:14 ` [PATCH 0/6] perf/ftrace: Introduce hexadecimal type casting Arnaldo Carvalho de Melo
2016-08-18 16:01   ` Masami Hiramatsu
2016-08-18 16:13     ` Arnaldo Carvalho de Melo
2016-08-20  3:40       ` Masami Hiramatsu
2016-08-18 16:03 ` Steven Rostedt
2016-08-18 16:08   ` Arnaldo Carvalho de Melo

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.