From patchwork Thu Nov 9 23:59:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 163652 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp786693vqs; Thu, 9 Nov 2023 16:03:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmKNNj3EhU60m7PKThRM4AOJQz2wtVS6PVujCerYOkWJxgzh6nTVGj3X6YH7c3McSZFFN8 X-Received: by 2002:a92:c249:0:b0:34f:c7f7:18b with SMTP id k9-20020a92c249000000b0034fc7f7018bmr8057962ilo.2.1699574591541; Thu, 09 Nov 2023 16:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699574591; cv=none; d=google.com; s=arc-20160816; b=KZS0TDZgQiMdFHUbjRieX2dA9LQaYqqZdYEI+h0j069eHZaB7OpDRLB5EqE4PWtHwc MNehEdfqI0ohQiyC1EkHfG3d85RMT7o+JP9n9G1XoSsfArtAV4MV4Bp1yQrbBp28hM5A VpobIggJjoBqIf1tMBz5kwUbO4SzfFyof4YOuXRPOgGNu1J/0evcMSxSEWCDJO2k9C0i H3mGosRo0Vw42qIOO3SmQTzZKpPj1AyF1PrH/d53VTtJVXrNSFZxD2pGM73xDw9fds1V lTXN04/GGsF5O1+AEz50eYelN27kcZKgiY8WA5HekVEq2MV5MIe4ff4Onn+t68oA9n0e zOLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=kl6qkwzmCb2Fb09U1AXlxKbKREoLSgao7N8IelzAMBg=; fh=K//si1Hi/RYC7s39rVvmvh0YbZGmBrdWWHQg3cPF7Xc=; b=vxSM9KZDtDYgqMe9HXQF4ZMkDk2ccFsd6YGB9aa5N7uY9R8J1Hx96aJleW21LX1xSm iQ9J9KGFXvxHnypPFFsXOjAzM1skj6JODNAjP57sDk/MK0oN+IqMs2LNb3ns8qgIGLrQ 2NItnsbSPPqbbWUvn9av925js+jDdl/paiI0VDPBD7uJnRdjVR1tqFCOjEFure3RJO9O Wvs2vFHVJCklIwLhrCjHds4/jBLbFIFrUWG4suG3EEngPi9/MR3Iir6IL45feR4U5+WC c+/9fY6CkKbbOeevGjpaC3qpCwm64IEeWdY0fBr19RPOSD5HIis1RXwsFgHVnkDfrCEQ eJPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=huE+tmGr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id g9-20020a656cc9000000b005859b1b34f7si9726909pgw.862.2023.11.09.16.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 16:03:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=huE+tmGr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 33C2683A58E0; Thu, 9 Nov 2023 16:01:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345581AbjKJAB1 (ORCPT + 30 others); Thu, 9 Nov 2023 19:01:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345580AbjKJAAx (ORCPT ); Thu, 9 Nov 2023 19:00:53 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813CC49CF; Thu, 9 Nov 2023 16:00:38 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5bd85b1939aso1097043a12.2; Thu, 09 Nov 2023 16:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699574438; x=1700179238; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=kl6qkwzmCb2Fb09U1AXlxKbKREoLSgao7N8IelzAMBg=; b=huE+tmGrENZq27PQZHbDXKv6PKMPRIOtN7Xqxmp0hx2BqD3mneWnaoPNo3K2fTc+BE QmIrJKTqku7Sg43Do4ltYgF+JZPgsqGNMBUTYAYsqXEj83zx0zRejw0M54eA/cB278da ZMKdTcOkwyd0yt87axOzKIVTWxBSM1u9tY7BwoCzS/P1YMZJbafHIz47kQODVhXWa2bu a9WLOLn+4Z7/wH7lA1TfVziWgnQy3oK6/Dkt9Espw9xEkr3SrohWX8YH/peTRiOzWytN vwmDMHM8JS2S+5FDUcC8i1QAaB8UBCvhSo0eCujORsX/iDttStGN5RUEY0anxeFDRMem XU1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699574438; x=1700179238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kl6qkwzmCb2Fb09U1AXlxKbKREoLSgao7N8IelzAMBg=; b=lVmljx6hu8aS8p0W/xqj3/hzSB5Cd8XH3z32JYG58kJ/tsWtPPrqQA7te7UPyKqhX8 0W4LB8hYquNHvR/a5sSLcAMD0lPsdzpNka4PMFIwX5XrMQ+B3ZzGGOiU72xi9C98R1iU td9e7gcxTuO0pd/DyxcubFolyD7DV+r28JyyTvBl+/u4yKVHooh/oGEf0Hy6/C4NyySJ B0zbaXXoBnfTskLE6U50jKCuMO5ekP6eO4uJiR5g2yC9S5FCeW6NvBfZBQJZzbsBJRKV 54y2+iT0xTQHNw57VR8bydYH2866aepxF2Ex8wO5AGWhwK502Bq0lRMEZ/cPPLn77L0Y Al5A== X-Gm-Message-State: AOJu0YyRiV5c68eBD7SHdFoiyebVUrnm96k13rBUA7wVkI3sQ0uwCWaF DUXpdL5f08mxpncfCZMazXw= X-Received: by 2002:a17:90a:4888:b0:280:1df1:cbc7 with SMTP id b8-20020a17090a488800b002801df1cbc7mr3334799pjh.19.1699574437858; Thu, 09 Nov 2023 16:00:37 -0800 (PST) Received: from bangji.corp.google.com ([2620:15c:2c0:5:d45c:ae16:d959:a5f1]) by smtp.gmail.com with ESMTPSA id k32-20020a17090a4ca300b002635db431a0sm371312pjh.45.2023.11.09.16.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 16:00:37 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra Cc: Ian Rogers , Adrian Hunter , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , Andi Kleen , linux-trace-devel@vger.kernel.org, linux-toolchains@vger.kernel.org Subject: [PATCH 15/52] perf annotate: Check if operand has multiple regs Date: Thu, 9 Nov 2023 15:59:34 -0800 Message-ID: <20231110000012.3538610-16-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231110000012.3538610-1-namhyung@kernel.org> References: <20231110000012.3538610-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 09 Nov 2023 16:01:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782133126972330890 X-GMAIL-MSGID: 1782133126972330890 It needs to check all possible information in an instruction. Let's add a field indicating if the operand has multiple registers. I'll be used to search type information like in an array access on x86 like: mov 0x10(%rax,%rbx,8), %rcx ------------- here Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.c | 36 ++++++++++++++++++++++++++++++++++++ tools/perf/util/annotate.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 83e0996992af..9e297adc8c59 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -85,6 +85,8 @@ struct arch { struct { char comment_char; char skip_functions_char; + char register_char; + char memory_ref_char; } objdump; }; @@ -188,6 +190,8 @@ static struct arch architectures[] = { .insn_suffix = "bwlq", .objdump = { .comment_char = '#', + .register_char = '%', + .memory_ref_char = '(', }, }, { @@ -566,6 +570,34 @@ static struct ins_ops lock_ops = { .scnprintf = lock__scnprintf, }; +/* + * Check if the operand has more than one registers like x86 SIB addressing: + * 0x1234(%rax, %rbx, 8) + * + * But it doesn't care segment selectors like %gs:0x5678(%rcx), so just check + * the input string after 'memory_ref_char' if exists. + */ +static bool check_multi_regs(struct arch *arch, const char *op) +{ + int count = 0; + + if (arch->objdump.register_char == 0) + return false; + + if (arch->objdump.memory_ref_char) { + op = strchr(op, arch->objdump.memory_ref_char); + if (op == NULL) + return false; + } + + while ((op = strchr(op, arch->objdump.register_char)) != NULL) { + count++; + op++; + } + + return count > 1; +} + static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms __maybe_unused) { char *s = strchr(ops->raw, ','), *target, *comment, prev; @@ -593,6 +625,8 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy if (ops->source.raw == NULL) return -1; + ops->source.multi_regs = check_multi_regs(arch, ops->source.raw); + target = skip_spaces(++s); comment = strchr(s, arch->objdump.comment_char); @@ -613,6 +647,8 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy if (ops->target.raw == NULL) goto out_free_source; + ops->target.multi_regs = check_multi_regs(arch, ops->target.raw); + if (comment == NULL) return 0; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index e8b0173f5f00..4ebc6407c68a 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -39,12 +39,14 @@ struct ins_operands { s64 offset; bool offset_avail; bool outside; + bool multi_regs; } target; union { struct { char *raw; char *name; u64 addr; + bool multi_regs; } source; struct { struct ins ins;