From patchwork Fri Feb 16 23:54:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 202441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60004dyc; Fri, 16 Feb 2024 15:57:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAS14blHhJxpyC+Yd3rSPSvaVlXr7z7L0JKQSCyA2pebTj2VtQ71HwnkPspqRxYquxEjFEpYv3FeuEfk0nSvbP/abDow== X-Google-Smtp-Source: AGHT+IFaWbvjuVUl4P00xbEaufzBbEh4io5e7kpnOwz1rY2WwFju+l575gQ9DR1IsZmiD35tq0j8 X-Received: by 2002:a0c:e389:0:b0:68c:9d36:db88 with SMTP id a9-20020a0ce389000000b0068c9d36db88mr5530780qvl.6.1708127848286; Fri, 16 Feb 2024 15:57:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127848; cv=pass; d=google.com; s=arc-20160816; b=FeA5KPucvidfMQxp/pAThxLvAusygriit/BbIe1nwoT2pENEhUSF+D27Ot4EVypDw9 C+wFKOj9dgTkP+neXrWr7lGfsq4wPscBZ5fO/2WV8plOI+n51as88MMYVuUkG6KScuth xz9kaGHEgFPTrsMrxjQVyRmRoyq0/6yRYIDg7iHAENk4zXvVK4ZsTfcQygqD6ucikz+A tbjRZhy5b8ka2aIgHF+gRFZFtMaFR7Z7fDVwtqIbC8ygkYOS8rlQair6saI69wgm15ap amW5//S0C4Tt7VC/ZBg9AFkYvuNpxoW3x96cLH5CLmowa8MES0DZoyRqvsQQjSMaHpSu jitA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LKjJc/di3rsXXDt/3Tw8I4jt2NSg7jeQAXy8AdYRrZM=; fh=44lErbL5kvNUjSV6UDWgBEjJyOJpjjMpxi6K+HFi+Bc=; b=pYYG9jy1Gl3KQQTdYaEvjcuCOQRTkxtQ/7cHTa70Zos6sv5yZh4S362/yuR7l3suGe 5okeucA9WdO754NWlFEB3qZcCJEGvh8HrXR+bzp95IOVkfDH4zJay8p9Kx35ZClNXA4r jPcbBhRU1hg7N9UUhg+Sfl0Sh/ybX3oBTMkxOvtFLtAUBzqTkW2HfSjU4RO43s4BFIdk fxhoQ8BZurIkn09REaFwOnl/8TucPHpoubwUS9dumTu6J70MmfL0oj/6oD4Any2lQ0n7 iOY/MSAVgPiZSjw3FWgpOg1KxEqssFrW59AMe2+JF+7qUFMutRxwNx8jQraAOzb75sZw 4tYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tZVxGjD9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69503-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69503-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fo5-20020ad45f05000000b0068cfb592036si942460qvb.449.2024.02.16.15.57.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:57:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69503-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tZVxGjD9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69503-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69503-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0C8161C21F65 for ; Fri, 16 Feb 2024 23:57:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CA89151CD2; Fri, 16 Feb 2024 23:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tZVxGjD9" 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 902ED14E2C4; Fri, 16 Feb 2024 23:54:30 +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=1708127671; cv=none; b=SwvFCNsX1TjIIR/gAJYIhd50mvtT+YbPwSIk9dKWMYtdPfSXq+9TaxZauzV6tPbKXvEGZcYWgkTOY5GZgZddZfw+P1WwhG/FyhUquBRF7emJyrGnEiUURRd7Fg9jmeLZBU6u1+cZCgxTO1Mxs3aLfixUz3gDayhtZ7xYZegKdPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127671; c=relaxed/simple; bh=zZHOIpCOQRvZUMTIDQX7NJi7rHNLMrUEbf5ATQRYfWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JAxZDGh9xLbIVk7RbY55S+6brTpgQtaPFD7RwaKF6KXj3mbqYVdWEI2Eej2xU+zNc/nVihQrlyVLDhccdLkstwI4aYAGSqXlQOw+LNhAYJPWgUM1dVz18wRdn1Zh+21RkZeJlmO7vknLzwRhvVr1aaUhu20O3mQ4a4y5NjN6cEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tZVxGjD9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 215B6C433B1; Fri, 16 Feb 2024 23:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708127670; bh=zZHOIpCOQRvZUMTIDQX7NJi7rHNLMrUEbf5ATQRYfWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tZVxGjD9fx55g/829dqU23cR9Np786MufZf4Yc5V7mqADC3/a+IuTCz2gRxEWzfhO M9QSXZnPQKiyslE/mGzNLg/0UoyBZsox0KCkEQnV54tIKBjukFdb29EnXfXahcqaSN kCzb5KBTY+SuyYADZPxf2V2oOiCtEEVithd3oP25ZfewJYx6UdtdpRrLiEr2kqayIa WqGWQ3+gca7KSH9b2bspj15L9eSz0/0sb686xOPqciCrlTbYUGEh3B7EW8MpFPMsDw An6T8jbnrK+LWBfKAwN32K6wccKsYCsA1WKgPPlxZCqmNXhin/HShdaG2Eyy+ZItYE mz7FSZcKt6MsA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 09/14] perf annotate-data: Handle call instructions Date: Fri, 16 Feb 2024 15:54:18 -0800 Message-ID: <20240216235423.2343167-10-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240216235423.2343167-1-namhyung@kernel.org> References: <20240216235423.2343167-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791101866801410002 X-GMAIL-MSGID: 1791101866801410002 When updating instruction states, the call instruction should play a role since it changes the register states. For simplicity, mark some registers as caller-saved registers (should be arch-dependent), and invalidate them all after a function call. If the function returns something, the designated register (ret_reg) will have the type info. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 45 +++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index e46e162c783f..e8e363fed8c2 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -23,10 +23,14 @@ #include "symbol.h" #include "symbol_conf.h" -/* Type information in a register, valid when ok is true */ +/* + * 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; bool ok; + bool caller_saved; }; /* Type information in a stack location, dynamically allocated */ @@ -50,6 +54,7 @@ struct type_state_stack { struct type_state { struct type_state_reg regs[TYPE_STATE_MAX_REGS]; struct list_head stack_vars; + int ret_reg; }; static bool has_reg_type(struct type_state *state, int reg) @@ -57,10 +62,23 @@ static bool has_reg_type(struct type_state *state, int reg) return (unsigned)reg < ARRAY_SIZE(state->regs); } -void init_type_state(struct type_state *state, struct arch *arch __maybe_unused) +void init_type_state(struct type_state *state, struct arch *arch) { memset(state, 0, sizeof(*state)); INIT_LIST_HEAD(&state->stack_vars); + + if (arch__is(arch, "x86")) { + state->regs[0].caller_saved = true; + state->regs[1].caller_saved = true; + state->regs[2].caller_saved = true; + state->regs[4].caller_saved = true; + state->regs[5].caller_saved = true; + state->regs[8].caller_saved = true; + state->regs[9].caller_saved = true; + state->regs[10].caller_saved = true; + state->regs[11].caller_saved = true; + state->ret_reg = 0; + } } void exit_type_state(struct type_state *state) @@ -417,6 +435,29 @@ void update_insn_state(struct type_state *state, struct data_loc_info *dloc, int fbreg = dloc->fbreg; int fboff = 0; + if (ins__is_call(&dl->ins)) { + Dwarf_Die func_die; + + /* __fentry__ will preserve all registers */ + if (dl->ops.target.sym && + !strcmp(dl->ops.target.sym->name, "__fentry__")) + return; + + /* Otherwise invalidate caller-saved registers after call */ + for (unsigned i = 0; i < ARRAY_SIZE(state->regs); i++) { + if (state->regs[i].caller_saved) + state->regs[i].ok = false; + } + + /* Update register with the return type (if any) */ + if (die_find_realfunc(cu_die, dl->ops.target.addr, &func_die) && + die_get_real_type(&func_die, &type_die)) { + state->regs[state->ret_reg].type = type_die; + state->regs[state->ret_reg].ok = true; + } + return; + } + /* FIXME: remove x86 specific code and handle more instructions like LEA */ if (!strstr(dl->ins.name, "mov")) return;