From patchwork Thu Oct 12 03:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 151687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp964319vqb; Wed, 11 Oct 2023 20:51:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHt6uPczVUCWj+633CZQYBFJSecRftNsN10i43SLPF7LiJBUlt9O8Bck5aLV6jThhpRoaVe X-Received: by 2002:a05:6a20:429f:b0:15c:b7ba:e9ba with SMTP id o31-20020a056a20429f00b0015cb7bae9bamr27121401pzj.0.1697082696781; Wed, 11 Oct 2023 20:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697082696; cv=none; d=google.com; s=arc-20160816; b=MW/hQranu2GUPPLqEEw0H0lWUOA+WOlc4TZoqzWwKq40T5gaHq5pf3GOzeM9i3DOgo QCN9TdTMBqASmslQI9CtsvZqtRBCj6IJWOFitVBnmCr4VlMOWdwpwczFlMg60dh6raEe +cwDaAatGBskQ6oxs45uK+RrjgdmCd85F3vw/mXex5C9YI2XWUN70e2RojkOwam1qK3N C5XFPkLXHvMvi5F8bl65eta1flcIEtgPunsCCneLG7l4rliUVysriYUJx9UTUozPa+RH 7LWhVzy1pMkrtVJlR55xylt6oSCH83U7QzrtOB1hthi/km7OceQLOXsUxotPW2q8fMGI yyFw== 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=Ed07eY8Yy1Ov3wLjexONW1pCgxoZtQGuV9y71hqZcBM=; fh=7Id7wL2M+oCJXD4imOzx4OKioxBXSOZqypDprm7aO4E=; b=MDLRtcMqErltVM059Av0wjP+usToGvYjBoXRG6Xdjm4w5SmotgemnxeILuaxJhzd5g qlWMyWq3sn4GdlTJLIi6lIV/oXM22HsSDAlYNEbGUsjCifHxoUHsXt2Hbui1kt1pzcXk UzZlNrXm/N/wtbzrIzxGc4fQ/qio/+w0LDGYpR/mwesmtx2U6oXt8FqUFGJlRI4KLSut UlqFq5il0kqP40rlwjpTErIIorI9KoGU1/4wNJlUs5rGKEoiD4k0AIoFwVuF4ZZv8K67 SRD1pKI9OiLQLyf0YI3FRO/vUK0/zF2289dmctygWSnlQqCSO/9jylmbCXqj7ojHaf0C GihA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eaZQg1tL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u9-20020a170902a60900b001c446f12975si1171679plq.447.2023.10.11.20.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 20:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eaZQg1tL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 9948F801909F; Wed, 11 Oct 2023 20:51:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376921AbjJLDv3 (ORCPT + 18 others); Wed, 11 Oct 2023 23:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344734AbjJLDvS (ORCPT ); Wed, 11 Oct 2023 23:51:18 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0D6CB7; Wed, 11 Oct 2023 20:51:17 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c735473d1aso4395815ad.1; Wed, 11 Oct 2023 20:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697082677; x=1697687477; 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=Ed07eY8Yy1Ov3wLjexONW1pCgxoZtQGuV9y71hqZcBM=; b=eaZQg1tL7TBIGDgwpNe8+dcw2HCPBAaznYJA1hsKS+cXUDd/Cdu8pe0k35EHS+z/GW OnYFYqNTcQl7lWg9UAAsQ1GDEmLM1vNXN5obwYli2LQ24mtF2ADZW3s5zfuDKNKHsLAw G1lwmAEYZbXkIC6ZSTpBLUxExgvt/ZQ9OaB6kvh5wiRBbp85SfT9nISq8BrI7YIpkvTX Pf2iJb3/dr3MicHRo6d0au9K1mlCQDmKZaPyXBDzxILIRUwXbCO3q6juVxWdWhbpL/i8 isy6USE5TLx+ipQvdBUbZsxYi2yRVBUXtG2Z9RPjV/Unvi2w+qtG3IlHt4xVfPv8FJOD 9GYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697082677; x=1697687477; 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=Ed07eY8Yy1Ov3wLjexONW1pCgxoZtQGuV9y71hqZcBM=; b=KGYO4m2wJQi85fbgDyhiIX+yTKjzXstzQlgGLb+mV/LGSW6fBOWuZga4/4w7Z25dWf 6mIe812yQT230nLHBW+BbtHEWVkV1PK0kudaqisP3pYtXBqgNxDOmZ9tTbkQVK/lhxPa K0BXtdoe+olJVOF88I24s5Ocd9lXawtSdyDhtMLV/ct46mMhOSKI8fKgEOdrkDdnAtU2 0YGi7XaOGbyF3d1Rm61giC6OOc3qx8XG+d+EmS/kqh63ncpox6kutHsQNPmfFxyiFd0J kpnrOsxZWve+YVaerXBjMr7mqgkLfo7aWh8txEwdDNb67LKNYl9xo9LGkwI/9913xYSz mEjA== X-Gm-Message-State: AOJu0YwocfeyHMAMXN/Cm4z6zsLvsFSDZtnmJauprvgcgzUjxgp9/URc F2+QBo5RMG0vSoR+Slg7XsE= X-Received: by 2002:a17:902:e9c5:b0:1c9:bcbe:f581 with SMTP id 5-20020a170902e9c500b001c9bcbef581mr6002537plk.50.1697082677020; Wed, 11 Oct 2023 20:51:17 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:b1b9:d490:2f5e:be06]) by smtp.gmail.com with ESMTPSA id w8-20020a170902d70800b001bc18e579aesm711374ply.101.2023.10.11.20.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 20:51:16 -0700 (PDT) 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 , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 02/48] perf annotate: Check if operand has multiple regs Date: Wed, 11 Oct 2023 20:50:25 -0700 Message-ID: <20231012035111.676789-3-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012035111.676789-1-namhyung@kernel.org> References: <20231012035111.676789-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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]); Wed, 11 Oct 2023 20:51:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779520185927657275 X-GMAIL-MSGID: 1779520185927657275 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 211636e65b03..605298410ed4 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 9d8b4199e3bd..e33a55431bad 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;