Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1214324rdb; Fri, 2 Feb 2024 19:09:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXGry1T4jcKgogW8yz57htgLMNYG+vao7u6yeA9sh/sNOoR6hXcu2PRfMLqugcQkIZGr1u X-Received: by 2002:a17:902:d389:b0:1d8:e7a4:3474 with SMTP id e9-20020a170902d38900b001d8e7a43474mr3900947pld.68.1706929766380; Fri, 02 Feb 2024 19:09:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706929766; cv=pass; d=google.com; s=arc-20160816; b=Ej0smJco3cx+KkPKtwawPGQc2xup2EB2paGjmAGucPA7R3KiRyQifmn+ldaF1oi8Eq QPauDQt9DDd6CAwle+fSfDJDO6ng1Ii2zPeeXPYtFn+rlEp91LyLnQAoitXZmSi0VHQd JxLT+AL57y9sRdyD7afHt59rZOU0On9H7E5rEPuoGEDFJ2vFeN63HtOOClGp9P4iYc8D N6dgBuMHQ6BsRyjyHPmHaawNexFKo7j+a1xNZj1Kk7eQhD5dgPYyojMUCWM7JcWViLj6 1XXj2PDd6Pk3q9e/ogUOEJIZzhdNEPDqLMQ3nKQOZqUQ7s7cJTDdFulNiqaFbZvuXtOQ 8WLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=b1DU4tok1X0r9bYtqZ6dNhjxfX0/7CKeHdYGkX55OSE=; fh=rvF/KkKT2HoOoDSMQOCNiuZj9aOXLLmzR8WpfG7RZvc=; b=EIXBR6fEGDwE5M85IjDFRliJ3wBCWkWxG06VwVqmi+IbRG7PWUq61gt5pgPOU2Ht++ 6U+a2P8DN2cfSKPmwO4IvZauEyKZf/AqFntrRCfJJt0L9X52xhEoO5jdoAkhkAmhvn5l nqT+fW0RUgrK2qO/MWQSyPb+u5AuWzfAOi2YU0r3PUiL9mTm0Nj8TbApljxwdcYuQ0Ij InncmfYKf4Ykjx+SRWj4UCVmmzbLH28SQMzhUV79Wt/V6z2jmxVv9WkBX1HpXd4ma3Lb HJbj2ew9RtbK1c5UQYaKF+e5nlhpuQXDlNvtIPB3/5XyLV7Wx3W99477zd7ECNWMVjUq jK1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hJ+thUtV; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-50885-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCVe8K5TM3fY/0BreoCPSRXR3AwV0v6YwG4eKzQ6nrVgqHXzHBMuAYD8Z8F7lWRtjioVOxJ7fcGmkm4YWoQTASN0FXNEp/f4dX+78fjblA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f11-20020a170902ce8b00b001d4bcc54417si2758925plg.605.2024.02.02.19.09.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 19:09:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50885-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hJ+thUtV; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-50885-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50885-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 089A0287A64 for ; Sat, 3 Feb 2024 03:09:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AF888C11; Sat, 3 Feb 2024 03:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hJ+thUtV" Received: from mail-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88BA9101CE for ; Sat, 3 Feb 2024 03:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706929759; cv=none; b=be5RuwqK7tZcFe4qT89lS6z/u4GLXeJeIImj9jXbP1/YhOJS4Ad/DqF0P6AFFgaoBDpYWWYP/k63wB84pFZNtWz8EMa5dQyff9apM4AwsQeCUnaaHcaWsy709w6sLMpyG5kPnyRcZXZfJ05cyPNqMrl1cLN5e0wx2tS/jxx4yRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706929759; c=relaxed/simple; bh=KLM26Yfrtc8SeQCiqpSzGGfhWq7k+6JxiLtHj7A+bGk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=hafhT1yrAFmnGIfaYHkCYZJF9BknUnkIPVqc++MWFdR2KxyUW67hefJmuduph/m6BZ1pKJ1Nt88tlnGdiu9gGo4r+sF1Ubsaz9HoOMKPBKPtAYzxJUjdNbaWzP//XF164X0IMkUUZiaf0uURj/bj2lmzr1Y3LLSG9qLW8okKSac= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hJ+thUtV; arc=none smtp.client-ip=209.85.166.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-il1-f182.google.com with SMTP id e9e14a558f8ab-3638bd37107so52895ab.0 for ; Fri, 02 Feb 2024 19:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706929756; x=1707534556; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b1DU4tok1X0r9bYtqZ6dNhjxfX0/7CKeHdYGkX55OSE=; b=hJ+thUtVNbyUF1HPW0HiEbQmPcQUT9xO7AzHVMbe35f0DQD0WH8OXXfZrN+sfE+9Zy hHucswnk+Z9laWpb9MD4LQ/8NSDHlJ5bU9ZKnM8mzJugG+WCdedOiVP7oz2JrJ9k4IlL gbG6KAw5F/UrdBLFWqYnlILDcwRC+2Jv412iVdphCGUIbamOqVe7cPjkFssN4YWsT59L Qsi3bwDtfrj33v3Z+s+9tyWM6JF4mL7ZgS3y/zM6N12tYSSfqgUBVfb9i3sQpGhQzIMU vFMc+az0tOWt3W/LdKF9XOFN2bwcoZQohL9BVXOB33S5dRWqEIx8khaz4T6/gY4xnC6L Jk0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706929756; x=1707534556; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b1DU4tok1X0r9bYtqZ6dNhjxfX0/7CKeHdYGkX55OSE=; b=PqdsydjQ8+AxurLHXPTAcCLi5AiyrU7lXrVYNxkXogMtS45TKkdpYl7PbIs67zdd6K VRzyKBZQDYFhNEW5JFGOz3PQebK6+m+DkiyTEIOnGNd5bQKJxJRSVQx9MWjsjYvcBVkg 3xk1YdPNmOmIZXGeJwLDwbop+lPm4YsgAY9yhsW50m3BYq26ykh6OWMatdzPBQhmhdIs HwjsK85lgsETAZIUUWDOV/FrkNcdA07l59d95BhtfvFnEmv6xdTTtPOfBiJqfC49+d0w XW/VRilZ17rm4ekuR3OS5To5EJOESl2pKvZVWUhmopmRlLkcjwV8VkdcNFmxkeWTZcvZ zVkg== X-Gm-Message-State: AOJu0Yz7jxNZYQmdEvDNxGy6ZGWS5WgK7WJThnE17b6N2UnhOoANuoil Fi/sVyJJCp+3JzaMy9jEwm0NeZwG0qbdwtKe0Tu8LWNn/baxiKskgCaR0hElyZzpXBJl5gsQZkA tVIVH1ZIqSopT77Yw5VNB0ieWm91EHrM1ZAu/ X-Received: by 2002:a05:6e02:23c3:b0:363:8007:d7dd with SMTP id br3-20020a056e0223c300b003638007d7ddmr71455ilb.3.1706929756513; Fri, 02 Feb 2024 19:09:16 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240202220459.527138-1-namhyung@kernel.org> <20240202220459.527138-10-namhyung@kernel.org> In-Reply-To: <20240202220459.527138-10-namhyung@kernel.org> From: Ian Rogers Date: Fri, 2 Feb 2024 19:09:05 -0800 Message-ID: Subject: Re: [PATCH 09/14] perf annotate-data: Handle call instructions To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 2, 2024 at 2:05=E2=80=AFPM Namhyung Kim w= rote: > > When updating instruction states, the call instruction should play a > role since it can change the register states. For simplicity, mark some > registers as scratch registers (should be arch-dependent), and > invalidate them all after a function call. nit: Volatile or caller-save would be a more conventional name than scratch= . Thanks, Ian > 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-d= ata.c > index e46e162c783f..185cb896b9d6 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 @scratch registers are invalidated after a function call. > + */ > struct type_state_reg { > Dwarf_Die type; > bool ok; > + bool scratch; > }; > > /* 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, in= t 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].scratch =3D true; > + state->regs[1].scratch =3D true; > + state->regs[2].scratch =3D true; > + state->regs[4].scratch =3D true; > + state->regs[5].scratch =3D true; > + state->regs[8].scratch =3D true; > + state->regs[9].scratch =3D true; > + state->regs[10].scratch =3D true; > + state->regs[11].scratch =3D true; > + state->ret_reg =3D 0; > + } > } > > void exit_type_state(struct type_state *state) > @@ -417,6 +435,29 @@ void update_insn_state(struct type_state *state, str= uct data_loc_info *dloc, > int fbreg =3D dloc->fbreg; > int fboff =3D 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 scratch registers after call */ > + for (unsigned i =3D 0; i < ARRAY_SIZE(state->regs); i++) = { > + if (state->regs[i].scratch) > + state->regs[i].ok =3D 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 =3D type_die; > + state->regs[state->ret_reg].ok =3D true; > + } > + return; > + } > + > /* FIXME: remove x86 specific code and handle more instructions l= ike LEA */ > if (!strstr(dl->ins.name, "mov")) > return; > -- > 2.43.0.594.gd9cf4e227d-goog >