]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf annotate: Move the data structures related to register type to header file
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Thu, 18 Jul 2024 08:43:44 +0000 (14:13 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 31 Jul 2024 19:12:59 +0000 (16:12 -0300)
Data type profiling uses instruction tracking by checking each
instruction and updating the register type state in some data
structures.

This is useful to find the data type in cases when the register state
gets transferred from one reg to another.

Example, in x86, "mov" instruction and in powerpc, "mr" instruction.

Currently these structures are defined in annotate-data.c and
instruction tracking is implemented only for x86.

Move these data structures to "annotate-data.h" header file so that
other arch implementations can use it in arch specific files as well.

Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Tested-by: Kajol Jain <kjain@linux.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Akanksha J N <akanksha@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Link: https://lore.kernel.org/lkml/20240718084358.72242-2-atrajeev@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/annotate-data.c
tools/perf/util/annotate-data.h

index 965da6c0b5427eaa0cea98e92e51e7c67e687f81..a4c7f98a75e3bd64384595dd47eb92bb77f681e5 100644 (file)
 
 static void delete_var_types(struct die_var_type *var_types);
 
-enum type_state_kind {
-       TSR_KIND_INVALID = 0,
-       TSR_KIND_TYPE,
-       TSR_KIND_PERCPU_BASE,
-       TSR_KIND_CONST,
-       TSR_KIND_POINTER,
-       TSR_KIND_CANARY,
-};
-
 #define pr_debug_dtp(fmt, ...)                                 \
 do {                                                           \
        if (debug_type_profile)                                 \
@@ -140,49 +131,7 @@ static void pr_debug_location(Dwarf_Die *die, u64 pc, int reg)
        }
 }
 
-/*
- * Type information in a register, valid when @ok is true.
- * The @caller_saved registers are invalidated after a function call.
- */
-struct type_state_reg {
-       Dwarf_Die type;
-       u32 imm_value;
-       bool ok;
-       bool caller_saved;
-       u8 kind;
-};
-
-/* Type information in a stack location, dynamically allocated */
-struct type_state_stack {
-       struct list_head list;
-       Dwarf_Die type;
-       int offset;
-       int size;
-       bool compound;
-       u8 kind;
-};
-
-/* FIXME: This should be arch-dependent */
-#define TYPE_STATE_MAX_REGS  16
-
-/*
- * State table to maintain type info in each register and stack location.
- * It'll be updated when new variable is allocated or type info is moved
- * to a new location (register or stack).  As it'd be used with the
- * shortest path of basic blocks, it only maintains a single table.
- */
-struct type_state {
-       /* state of general purpose registers */
-       struct type_state_reg regs[TYPE_STATE_MAX_REGS];
-       /* state of stack location */
-       struct list_head stack_vars;
-       /* return value register */
-       int ret_reg;
-       /* stack pointer register */
-       int stack_reg;
-};
-
-static bool has_reg_type(struct type_state *state, int reg)
+bool has_reg_type(struct type_state *state, int reg)
 {
        return (unsigned)reg < ARRAY_SIZE(state->regs);
 }
index 0a57d9f5ee78120d0d1614715aefe990fd086a94..cdb5cd8960bb87e849d81fe91b710935a2834bec 100644 (file)
@@ -6,6 +6,11 @@
 #include <linux/compiler.h>
 #include <linux/rbtree.h>
 #include <linux/types.h>
+#include "annotate.h"
+
+#ifdef HAVE_DWARF_SUPPORT
+#include "debuginfo.h"
+#endif
 
 struct annotated_op_loc;
 struct debuginfo;
@@ -15,6 +20,15 @@ struct hist_entry;
 struct map_symbol;
 struct thread;
 
+enum type_state_kind {
+       TSR_KIND_INVALID = 0,
+       TSR_KIND_TYPE,
+       TSR_KIND_PERCPU_BASE,
+       TSR_KIND_CONST,
+       TSR_KIND_POINTER,
+       TSR_KIND_CANARY,
+};
+
 /**
  * struct annotated_member - Type of member field
  * @node: List entry in the parent list
@@ -143,6 +157,47 @@ struct annotated_data_stat {
 extern struct annotated_data_stat ann_data_stat;
 
 #ifdef HAVE_DWARF_SUPPORT
+/*
+ * Type information in a register, valid when @ok is true.
+ * The @caller_saved registers are invalidated after a function call.
+ */
+struct type_state_reg {
+       Dwarf_Die type;
+       u32 imm_value;
+       bool ok;
+       bool caller_saved;
+       u8 kind;
+};
+
+/* Type information in a stack location, dynamically allocated */
+struct type_state_stack {
+       struct list_head list;
+       Dwarf_Die type;
+       int offset;
+       int size;
+       bool compound;
+       u8 kind;
+};
+
+/* FIXME: This should be arch-dependent */
+#define TYPE_STATE_MAX_REGS  16
+
+/*
+ * State table to maintain type info in each register and stack location.
+ * It'll be updated when new variable is allocated or type info is moved
+ * to a new location (register or stack).  As it'd be used with the
+ * shortest path of basic blocks, it only maintains a single table.
+ */
+struct type_state {
+       /* state of general purpose registers */
+       struct type_state_reg regs[TYPE_STATE_MAX_REGS];
+       /* state of stack location */
+       struct list_head stack_vars;
+       /* return value register */
+       int ret_reg;
+       /* stack pointer register */
+       int stack_reg;
+};
 
 /* Returns data type at the location (ip, reg, offset) */
 struct annotated_data_type *find_data_type(struct data_loc_info *dloc);
@@ -160,6 +215,7 @@ void global_var_type__tree_delete(struct rb_root *root);
 
 int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evsel);
 
+bool has_reg_type(struct type_state *state, int reg);
 #else /* HAVE_DWARF_SUPPORT */
 
 static inline struct annotated_data_type *