From patchwork Wed May 24 05:28:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 98298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2615972vqo; Tue, 23 May 2023 22:45:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ypos3ATxvgf5tmAOpkuseR9zkTH04qU9R/GtE/etcbohM449QGqS5Dr2t8chOjOuvIBve X-Received: by 2002:a05:6a20:918a:b0:101:282c:2b with SMTP id v10-20020a056a20918a00b00101282c002bmr18398651pzd.32.1684907107058; Tue, 23 May 2023 22:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684907107; cv=none; d=google.com; s=arc-20160816; b=PHDgkIwjb1cdoZ+Eod7DxrgTrdkY/h8jjckHXknR/16qy/e9t38d/9guVFxePGzWcE kYIyWfPE3ADlbUHX7Lypb66mZVMNdpUAs/mGTYaYPtnmUgf6HE/e/zy6YSPSOQr6ZQgM 6OOn69QnIrNxK6KvNct5ppZcgCYJHehEMty9kEOtryIjWILso9dZvMtHdvUnpZEIMO75 YeSm7Y4s8QcySTMdjRy5v6vH8ORZcbXeanBZrI0iE1dW8rS1Iq3qy6EbOJbbDGATTfEl wAAyur5o/zfLKWxvo7+W1mRJKSLzU8C9YonFsdkFKXwaB0wuDtFFLTxYX0MqaX/HjMVM TBww== 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 :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=W6kUveazmI/2mChCTnueKXfUry75ocgV/yH5bVTAw9A=; b=MFnyIkOkTSMxo0Kg97AjJ7tSZUK6SveO1QYbtyiBuBCi8JCadX1esjJ6hk1xTJwKl3 rOmLDPmUVJppHNTfkeiMjPYuK+LxDfctRJsEKmBq10FJQuuFiq2faBcIXSlE/RXIC157 nYxZsR/Pt6QgtbxXv9RQXU5rkPHn1DEoFLgoJPGVaCtGm8g3yDiSInLXoO2LcrNWZ4lG HXvax+p1OZ8Vhuuu/lt+vhVsh8GIvwU6+T9Y/VufaMKw5c8nECpgxT5qdDAJn6M8q2JM KM6zISaXqufWDYG7ZQnOEvAVdt29WuLEZemyNu3JfQJc5zSNYtkelaq0XQ7UoSha3zxx fyQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XjDPkqRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d13-20020a170902aa8d00b001afaae8a0a8si541727plr.8.2023.05.23.22.44.53; Tue, 23 May 2023 22:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XjDPkqRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239359AbjEXF2m (ORCPT + 99 others); Wed, 24 May 2023 01:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239347AbjEXF2j (ORCPT ); Wed, 24 May 2023 01:28:39 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89E0213E; Tue, 23 May 2023 22:28:37 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1ae4d1d35e6so4208605ad.0; Tue, 23 May 2023 22:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684906117; x=1687498117; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=W6kUveazmI/2mChCTnueKXfUry75ocgV/yH5bVTAw9A=; b=XjDPkqRK9rr1M8kESs++g8i2DeggEfB1cY59xqV+hFKaoZDNJcbIOuA8avK4mRKeUv 3CGu+OQZSAUsLX/Mfo5keCG84W6IN4yVYpW3iWlr0t+wLZh8w/Xj6wc42uqfNDMPfo4G qB7+s+Jk4qan3k2GfhT4SFv4+Hzw1Ov6VWotsWjcqfTyoAm8rbT9sc9E8nuiHJAxKv+8 MdN2+8ZaTC7+f2FOq0oZj5etQEgq+p5pGB1K0rBkgrDPK0WEbhb7F4xsQRhheiQ0oAYR nb4mtR0jxEUxJHrf4CyfGTBihfKxOb9JnssxSnzNYLdQ/KGdRbEVfO/3ueiWwm+g/bvx 5bow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684906117; x=1687498117; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=W6kUveazmI/2mChCTnueKXfUry75ocgV/yH5bVTAw9A=; b=Unzt9fxR4+uIRDeUAqXQjdn/EpEmjByjSLeNWRkMs/5WOHEmxlpeS6UWNho/9SnLy0 xBrCsL36czs6rMzl0YJcs1r1PeKD7aZExuc7Uul1OnrPBYPqmcR46kzr10MyiDNoXe3V vX81KSorD02qKOroLcjN5zVUgVuKOHY2zepI4J8KZqqPXb3zlEGoPXfXue5RKC4xv6Kf AZyBmgKufkP39oLbemcHzSgtsMB8qaxQ2HerBZPBQbWXQmSrVUB0QKOQVCxMKmOalDKH Xq8zsUf+3d5vFefsk9n1JCRn6N9lTKMMEzkqkPTfYSDIplb8D6zE5kBLbQw+K34x0He6 k18Q== X-Gm-Message-State: AC+VfDx/Ahefr5gai71s6nhbOEkaJDQwibQvjhzzcnx0he2lbafouuqK y04aoMjqFmRKYCN48Pnm6Yt9Ad7AYCs= X-Received: by 2002:a17:903:2341:b0:1a6:7ed0:147e with SMTP id c1-20020a170903234100b001a67ed0147emr20337766plh.33.1684906116826; Tue, 23 May 2023 22:28:36 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6700:7f00:806f:2bdc:cf65:f76b]) by smtp.gmail.com with ESMTPSA id f10-20020a170902ce8a00b001a64011899asm7706626plg.25.2023.05.23.22.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 22:28:36 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Andi Kleen , Masami Hiramatsu , Kan Liang Subject: [PATCH 1/2] perf annotate: Handle x86 instruction suffix generally Date: Tue, 23 May 2023 22:28:33 -0700 Message-ID: <20230524052834.1041418-1-namhyung@kernel.org> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog 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,T_SCC_BODY_TEXT_LINE 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766753154631292924?= X-GMAIL-MSGID: =?utf-8?q?1766753154631292924?= Most of x86 instructions can have size suffix like b, w, l or q. Instead of adding all these instructions in the table, we can handle them in a general way. For example, it can try to find an instruction as is. If not found, it'd try again without the suffix if it's one of the allowed suffixes. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index b708bbc49c9e..7f05f2a2aa83 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -70,6 +70,7 @@ struct arch { struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const char *name); bool sorted_instructions; bool initialized; + const char *insn_suffix; void *priv; unsigned int model; unsigned int family; @@ -179,6 +180,7 @@ static struct arch architectures[] = { .init = x86__annotate_init, .instructions = x86__instructions, .nr_instructions = ARRAY_SIZE(x86__instructions), + .insn_suffix = "bwlq", .objdump = { .comment_char = '#', }, @@ -720,6 +722,26 @@ static struct ins_ops *__ins__find(struct arch *arch, const char *name) } ins = bsearch(name, arch->instructions, nmemb, sizeof(struct ins), ins__key_cmp); + if (ins) + return ins->ops; + + if (arch->insn_suffix) { + char tmp[32]; + char suffix; + size_t len = strlen(name); + + if (len == 0 || len >= sizeof(tmp)) + return NULL; + + suffix = name[len - 1]; + if (strchr(arch->insn_suffix, suffix) == NULL) + return NULL; + + strcpy(tmp, name); + tmp[len - 1] = '\0'; /* remove the suffix and check again */ + + ins = bsearch(tmp, arch->instructions, nmemb, sizeof(struct ins), ins__key_cmp); + } return ins ? ins->ops : NULL; }