Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp191355lqt; Thu, 6 Jun 2024 00:04:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW4vvMMZCCDEU2Cw/gOKDSqx9PTxnIjwOmaPBXW1fjWZi3y6uEq9LVOvjI8WgBecm1LLa/H+9Y+K9RF5VdUBSPaHmiDQkj4NOXEilMJCA== X-Google-Smtp-Source: AGHT+IHO3ap6xkVWo+2jQ/eLgAJDqq0SLU6MGKvru6Yr7FO7zksLMZPnfMir7o1DkAoI43f5M6fr X-Received: by 2002:a17:90b:896:b0:2a2:c16:d673 with SMTP id 98e67ed59e1d1-2c27db5b7acmr5555874a91.36.1717657470899; Thu, 06 Jun 2024 00:04:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717657470; cv=pass; d=google.com; s=arc-20160816; b=ZXIJ86gFG8xJkObrJoTT5Fn2poiQZXrGzUez3+WtXhsErS0P7QHkTYgSGrBES10rBL ojO6AS7DQJ+KCBKf5l+ln2WMPEb/1nFk0TwQvb4dzBlwSg+ZkOTKxr/j/IXoTl3CNN2u dRkch/vvwueMc9nELfWo8e1aFzbIubv++35Z6oLfIQuNMS4tZ3qAH8PZFg2oCNw4MW5O n7xE565j8ZdBwjincFO7kD5BDsuUduYdssbV+mkv+pa4yL6NnMcdUv7Ho6jALRgpKtW/ BcRphKwTebqdYyGWbB3ZydA0FUrGWGz+AsbxKMsqBkjOIAUOzfEIRYW98PsgPTzX35w+ QnWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=O5+LS1B28AJkl+m+tJmJXKBMZUeHg4r6JiYXfXuZB7c=; fh=0GnPHI8cG7EnaPHvHltVzQ62T9OekctpN2tGbv+E008=; b=0QjWQLIw8F1VcyogF5cTGMTNYycfGELXPc6NXdyZmyr0kI63o/5+alS0HoIxUm9s+A JNOzuDxkwtCIRseSmE9JDX3aSLX6mr4dEZe+eilFK7g6JmdHsDgDS4fCV/jLSq7INCdU I5Z86FKvnpPctLijHeBNjKCSXM2MJjvXX1qhUUE6aORYm+2D8DSOOBpY+mdrnZ6GMIy6 03JJPBa5CH81cOxhO6oLiDnxualIrN+r/bWhiAUAglsT4VYwGNJDxWwNjpTvHkI6cSXL GutafIjpCgQb/f4nP8e9O9UYHKX4sqGZCqP/OBdMrWsUh+tFT5k4zoRgmXImrmbXA00g /ThQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ilU3ez+S; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-203695-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203695-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2559fa5a3si1268654a91.1.2024.06.06.00.04.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 00:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203695-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ilU3ez+S; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-203695-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203695-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 10816B23172 for ; Thu, 6 Jun 2024 06:53:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61E2313AA59; Thu, 6 Jun 2024 06:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ilU3ez+S" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71FF96F068; Thu, 6 Jun 2024 06:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717656812; cv=none; b=fEJ6kuFKvjIXh70O6GmE/M8hJODpH9yJ4293+xVbbqdZE2mESQbpzwI1K073ZwOx9yaZoFDsxlWXafdFogPkdYIHXBLpsfzLzrK46mLbfe5olD6acawexSVyWSKxw47JHmtSQr6n6YpX+yv6EpKJwNKMCrajqjJUUKuNgvOr2o8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717656812; c=relaxed/simple; bh=YWrK4iYDDKbeb1azVQHle6znUk1b3N3hYO1w8gGk7I4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qQTERqg1wu4+fR1AxOiqywzc4vMnKKgt4duZE4Q7WO9zb5sMTkFS8XaBjpxTMYpqqKh7NA0cg7S/de0mAesbJAWqwa4XagFuWf3ZSsQaUOZlGo9nisEX/nQYAuycJE+eHvkqIuUIaj78u/1H0QPv40zFFBiB57d8rghLnoe3e6s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ilU3ez+S; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86633C4AF08; Thu, 6 Jun 2024 06:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717656812; bh=YWrK4iYDDKbeb1azVQHle6znUk1b3N3hYO1w8gGk7I4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ilU3ez+Sh2XfeQBILe8JRGQCLnC0ghKF6UuH7S5xS7LUc3l6SC5WHPqAFhVpuM48c UECg8zkcemdw1eBNAIjRZ/NZWujmFxOgSPn2UL9xZi5NQLBZQ/ef+8I39VSs7UN04U wkFp1ypqPfeFRFh1I5BlyWBysjO7DS9d2V4CePghEko5dFcaph6FPk4VLiMqkIzEM8 76XRTmS6pzm8GnxikRS52HlQrOtfSg7hmx1gtGM+TwkIXaIImPaFkacPCT7T5uNSOQ Ngjr8RT737ynyCqqwVmGcV7Hptn6Oh7BKdWg3BvsMl3daitgXE+1H5Q0O75jivs6WI ETUIi3yq6f9ig== Date: Wed, 5 Jun 2024 23:53:30 -0700 From: Namhyung Kim To: Athira Rajeev Cc: acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com, irogers@google.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, akanksha@linux.ibm.com, maddy@linux.ibm.com, kjain@linux.ibm.com, disgoel@linux.vnet.ibm.com Subject: Re: [PATCH V3 10/14] tools/perf: Update instruction tracking for powerpc Message-ID: References: <20240601060941.13692-1-atrajeev@linux.vnet.ibm.com> <20240601060941.13692-11-atrajeev@linux.vnet.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240601060941.13692-11-atrajeev@linux.vnet.ibm.com> On Sat, Jun 01, 2024 at 11:39:37AM +0530, Athira Rajeev wrote: > Add instruction tracking function "update_insn_state_powerpc" for > powerpc. Example sequence in powerpc: > > ld r10,264(r3) > mr r31,r3 > < > ld r9,312(r31) > > Consider ithe sample is pointing to: "ld r9,312(r31)". > Here the memory reference is hit at "312(r31)" where 312 is the offset > and r31 is the source register. Previous instruction sequence shows that > register state of r3 is moved to r31. So to identify the data type for r31 > access, the previous instruction ("mr") needs to be tracked and the > state type entry has to be updated. Current instruction tracking support > in perf tools infrastructure is specific to x86. Patch adds this support > for powerpc as well. > > Signed-off-by: Athira Rajeev > --- > .../perf/arch/powerpc/annotate/instructions.c | 65 +++++++++++++++++++ > tools/perf/util/annotate-data.c | 9 ++- > tools/perf/util/disasm.c | 1 + > 3 files changed, 74 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/arch/powerpc/annotate/instructions.c > index db72148eb857..3ecf5a986037 100644 > --- a/tools/perf/arch/powerpc/annotate/instructions.c > +++ b/tools/perf/arch/powerpc/annotate/instructions.c > @@ -231,6 +231,71 @@ static struct ins_ops *check_ppc_insn(int raw_insn) > return NULL; > } > > +/* > + * Instruction tracking function to track register state moves. > + * Example sequence: > + * ld r10,264(r3) > + * mr r31,r3 > + * < > + * ld r9,312(r31) > + * > + * Previous instruction sequence shows that register state of r3 > + * is moved to r31. update_insn_state_powerpc tracks these state > + * changes > + */ > +#ifdef HAVE_DWARF_SUPPORT > +static void update_insn_state_powerpc(struct type_state *state, > + struct data_loc_info *dloc, Dwarf_Die * cu_die __maybe_unused, > + struct disasm_line *dl) > +{ > + struct annotated_insn_loc loc; > + struct annotated_op_loc *src = &loc.ops[INSN_OP_SOURCE]; > + struct annotated_op_loc *dst = &loc.ops[INSN_OP_TARGET]; > + struct type_state_reg *tsr; > + u32 insn_offset = dl->al.offset; > + > + if (annotate_get_insn_location(dloc->arch, dl, &loc) < 0) > + return; > + > + /* > + * Value 444 for bits 21:30 is for "mr" > + * instruction. "mr" is extended OR. So set the > + * source and destination reg correctly > + */ > + if (PPC_21_30(dl->ops.raw_insn) == 444) { > + int src_reg = src->reg1; > + > + src->reg1 = dst->reg1; > + dst->reg1 = src_reg; > + } > + > + if (!has_reg_type(state, dst->reg1)) > + return; > + > + tsr = &state->regs[dst->reg1]; > + > + if (!has_reg_type(state, src->reg1) || > + !state->regs[src->reg1].ok) { > + tsr->ok = false; > + return; > + } > + > + tsr->type = state->regs[src->reg1].type; > + tsr->kind = state->regs[src->reg1].kind; > + tsr->ok = true; > + > + pr_debug("mov [%x] reg%d -> reg%d", pr_debug_dtp() ? Thanks, Namhyung > + insn_offset, src->reg1, dst->reg1); > + pr_debug_type_name(&tsr->type, tsr->kind); > +} > +#else /* HAVE_DWARF_SUPPORT */ > +static void update_insn_state_powerpc(struct type_state *state __maybe_unused, struct data_loc_info *dloc __maybe_unused, > + Dwarf_Die * cu_die __maybe_unused, struct disasm_line *dl __maybe_unused) > +{ > + return; > +} > +#endif /* HAVE_DWARF_SUPPORT */ > + > static int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) > { > if (!arch->initialized) { > diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c > index 7a48c3d72b89..734acdd8c4b7 100644 > --- a/tools/perf/util/annotate-data.c > +++ b/tools/perf/util/annotate-data.c > @@ -1080,6 +1080,13 @@ static int find_data_type_insn(struct data_loc_info *dloc, > return ret; > } > > +static int arch_supports_insn_tracking(struct data_loc_info *dloc) > +{ > + if ((arch__is(dloc->arch, "x86")) || (arch__is(dloc->arch, "powerpc"))) > + return 1; > + return 0; > +} > + > /* > * Construct a list of basic blocks for each scope with variables and try to find > * the data type by updating a type state table through instructions. > @@ -1094,7 +1101,7 @@ static int find_data_type_block(struct data_loc_info *dloc, > int ret = -1; > > /* TODO: other architecture support */ > - if (!arch__is(dloc->arch, "x86")) > + if (!arch_supports_insn_tracking(dloc)) > return -1; > > prev_dst_ip = dst_ip = dloc->ip; > diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c > index 57af4dc42a58..d8b357055302 100644 > --- a/tools/perf/util/disasm.c > +++ b/tools/perf/util/disasm.c > @@ -155,6 +155,7 @@ static struct arch architectures[] = { > { > .name = "powerpc", > .init = powerpc__annotate_init, > + .update_insn_state = update_insn_state_powerpc, > }, > { > .name = "riscv64", > -- > 2.43.0 >