Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Shuai Xue <xueshuai@linux.alibaba.com>
To: Tengda Wu <wutengda@huaweicloud.com>,
	Namhyung Kim <namhyung@kernel.org>,
	james.clark@linaro.org, Li Huafei <lihuafei1@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	leo.yan@linux.dev, Ian Rogers <irogers@google.com>,
	Kim Phillips <kim.phillips@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@redhat.com>, Bill Wendling <morbo@google.com>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Zecheng Li <zli94@ncsu.edu>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH v4 17/23] perf annotate-data: Track imm_value for stack variables
Date: Tue, 11 Aug 2026 16:16:01 +0800	[thread overview]
Message-ID: <8bdc13c7-5277-4489-a5d1-9cae14f88beb@linux.alibaba.com> (raw)
In-Reply-To: <20260808122400.2961238-18-wutengda@huaweicloud.com>



On 8/8/26 8:23 PM, Tengda Wu wrote:
> Currently, imm_value are tracked in registers but dropped when values

Nit: s/imm_value are tracked/imm_value is tracked/ in the changelog.

> are saved to or loaded from stack variables during type profiling.
> If a register of type TSR_KIND_CONST is stored to the stack, its value
> will be lost.
> 
> Add an imm_value field to struct type_state_stack and update
> set_stack_state() and findnew_stack_state() to accept and preserve the
> immediate value when updating stack state.
> 
> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
> ---
>   tools/perf/util/annotate-arch/annotate-x86.c |  8 ++++++--
>   tools/perf/util/annotate-data.c              | 13 +++++++------
>   tools/perf/util/annotate-data.h              |  5 +++--
>   3 files changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util/annotate-arch/annotate-x86.c
> index eec3d8ce00b8..995117525e7d 100644
> --- a/tools/perf/util/annotate-arch/annotate-x86.c
> +++ b/tools/perf/util/annotate-arch/annotate-x86.c
> @@ -591,6 +591,7 @@ static void update_insn_state_x86(struct type_state *state,
>   				tsr->type = stack->type;
>   				tsr->kind = stack->kind;
>   				tsr->offset = stack->ptr_offset;
> +				tsr->imm_value = stack->imm_value;
>   				tsr->ok = true;
>   			} else if (die_get_member_type(&stack->type,
>   						       offset - stack->offset,
> @@ -598,6 +599,7 @@ static void update_insn_state_x86(struct type_state *state,
>   				tsr->type = type_die;
>   				tsr->kind = TSR_KIND_TYPE;
>   				tsr->offset = 0;
> +				tsr->imm_value = 0;
>   				tsr->ok = true;
>   			} else {
>   				invalidate_reg_state(tsr);
> @@ -773,10 +775,12 @@ static void update_insn_state_x86(struct type_state *state,
>   				 */
>   				if (!stack->compound)
>   					set_stack_state(stack, offset, tsr->kind,
> -							&tsr->type, tsr->offset);
> +							&tsr->type, tsr->offset,
> +							tsr->imm_value);
>   			} else {
>   				findnew_stack_state(state, offset, tsr->kind,
> -						    &tsr->type, tsr->offset);
> +						    &tsr->type, tsr->offset,
> +						    tsr->imm_value);
>   			}
>   
>   			if (dst->reg1 == fbreg) {
> diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
> index c51b20a7af9b..9dcdc3c7e688 100644
> --- a/tools/perf/util/annotate-data.c
> +++ b/tools/perf/util/annotate-data.c
> @@ -590,7 +590,7 @@ struct type_state_stack *find_stack_state(struct type_state *state,
>   }
>   
>   void set_stack_state(struct type_state_stack *stack, int offset, u8 kind,
> -			    Dwarf_Die *type_die, int ptr_offset)
> +			    Dwarf_Die *type_die, int ptr_offset, u64 imm_value)
>   {
>   	int tag;
>   	Dwarf_Word size;
> @@ -607,8 +607,9 @@ void set_stack_state(struct type_state_stack *stack, int offset, u8 kind,
>   	stack->offset = offset;
>   	stack->ptr_offset = ptr_offset;
>   	stack->kind = kind;
> +	stack->imm_value = imm_value;
>   
> -	if (kind == TSR_KIND_POINTER) {
> +	if (kind == TSR_KIND_POINTER || kind == TSR_KIND_CONST) {
>   		stack->compound = false;
>   		return;
>   	}
> @@ -629,18 +630,18 @@ void set_stack_state(struct type_state_stack *stack, int offset, u8 kind,
>   struct type_state_stack *findnew_stack_state(struct type_state *state,
>   						    int offset, u8 kind,
>   						    Dwarf_Die *type_die,
> -						    int ptr_offset)
> +						    int ptr_offset, u64 imm_value)
>   {
>   	struct type_state_stack *stack = find_stack_state(state, offset);
>   
>   	if (stack) {
> -		set_stack_state(stack, offset, kind, type_die, ptr_offset);
> +		set_stack_state(stack, offset, kind, type_die, ptr_offset, imm_value);
>   		return stack;
>   	}
>   
>   	stack = malloc(sizeof(*stack));
>   	if (stack) {
> -		set_stack_state(stack, offset, kind, type_die, ptr_offset);
> +		set_stack_state(stack, offset, kind, type_die, ptr_offset, imm_value);
>   		list_add(&stack->list, &state->stack_vars);
>   	}
>   	return stack;
> @@ -935,7 +936,7 @@ static void update_var_state(struct type_state *state, struct data_loc_info *dlo
>   				continue;
>   
>   			findnew_stack_state(state, offset, TSR_KIND_TYPE,
> -					    &mem_die, /*ptr_offset=*/0);
> +					    &mem_die, /*ptr_offset=*/0, /*imm_value=*/0);
>   
>   			if (var->reg == state->stack_reg) {
>   				pr_debug_dtp("var [%"PRIx64"] %#x(reg%d)",
> diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-data.h
> index 91b83e94c51b..06fc4dbfb35c 100644
> --- a/tools/perf/util/annotate-data.h
> +++ b/tools/perf/util/annotate-data.h
> @@ -199,6 +199,7 @@ struct type_state_stack {
>   	int size;
>   	bool compound;
>   	u8 kind;
> +	u64 imm_value;
>   };
>   
>   /*
> @@ -253,9 +254,9 @@ bool has_reg_type(struct type_state *state, int reg);
>   struct type_state_stack *findnew_stack_state(struct type_state *state,
>   						int offset, u8 kind,
>   						Dwarf_Die *type_die,
> -						int ptr_offset);
> +						int ptr_offset, u64 imm_value);
>   void set_stack_state(struct type_state_stack *stack, int offset, u8 kind,
> -				Dwarf_Die *type_die, int ptr_offset);
> +				Dwarf_Die *type_die, int ptr_offset, u64 imm_value);
>   struct type_state_stack *find_stack_state(struct type_state *state,
>   						int offset);
>   void invalidate_reg_state(struct type_state_reg *reg);


Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com>

Thanks.
Shuai


  reply	other threads:[~2026-08-11  8:16 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-08 12:23 [PATCH v4 00/23] perf arm64: Support data type profiling Tengda Wu
2026-08-08 12:23 ` [PATCH v4 01/23] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump Tengda Wu
2026-08-10 13:08   ` Shuai Xue
2026-08-11  2:27     ` Tengda Wu
2026-08-11  3:25       ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 02/23] perf llvm: Fix arm64 adrp instruction " Tengda Wu
2026-08-08 12:23 ` [PATCH v4 03/23] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-08-08 12:23 ` [PATCH v4 04/23] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-08-08 12:23 ` [PATCH v4 05/23] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-08-08 12:23 ` [PATCH v4 06/23] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-08-11  6:33   ` Shuai Xue
2026-08-11  8:16     ` Tengda Wu
2026-08-08 12:23 ` [PATCH v4 07/23] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-08-08 12:23 ` [PATCH v4 08/23] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-08-11  6:50   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 09/23] perf annotate: Deduplicate overlapping ARM SPE events for data type profiling Tengda Wu
2026-08-10  6:57   ` Adrian Hunter
2026-08-08 12:23 ` [PATCH v4 10/23] perf arm-spe: Set default synthesized event period to 1 Tengda Wu
2026-08-08 12:23 ` [PATCH v4 11/23] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-08-11  7:09   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 12/23] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-08-08 12:23 ` [PATCH v4 13/23] perf annotate-arm64: Track return type after call instructions Tengda Wu
2026-08-08 12:23 ` [PATCH v4 14/23] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-08-11  7:36   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 15/23] perf annotate-arm64: Support store " Tengda Wu
2026-08-11  8:00   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 16/23] perf annotate-data: Expand type_state_reg imm_value to u64 Tengda Wu
2026-08-11  8:10   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 17/23] perf annotate-data: Track imm_value for stack variables Tengda Wu
2026-08-11  8:16   ` Shuai Xue [this message]
2026-08-08 12:23 ` [PATCH v4 18/23] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-08-11  8:24   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 19/23] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-08-11  8:37   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 20/23] perf annotate-arm64: Support 'add' " Tengda Wu
2026-08-11  8:45   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 21/23] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-08-11  8:50   ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 22/23] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-08-08 12:24 ` [PATCH v4 23/23] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bdc13c7-5277-4489-a5d1-9cae14f88beb@linux.alibaba.com \
    --to=xueshuai@linux.alibaba.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=kim.phillips@arm.com \
    --cc=leo.yan@linux.dev \
    --cc=lihuafei1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=namhyung@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=peterz@infradead.org \
    --cc=wutengda@huaweicloud.com \
    --cc=zli94@ncsu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox