Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6376953rwd; Mon, 5 Jun 2023 17:46:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6J86Iy4mzG1xgTY8M5Qja1kiBhPN+K92qtRCfNKn+eDYqveyArD+dgciljlM4M7Pg28JI0 X-Received: by 2002:a05:6a20:9388:b0:10b:f590:5a26 with SMTP id x8-20020a056a20938800b0010bf5905a26mr588823pzh.26.1686012414538; Mon, 05 Jun 2023 17:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686012414; cv=none; d=google.com; s=arc-20160816; b=xK7vkSgogB+b08epb4nHTyUicNZd0pJPgPEocC///8Wi9NqDsl/ofnudsKNr6ZwqEl fUVkOfn5FWCjqtiommC5aEPxfrtMhLSanntZy5DV6G6217kk4F2qj5y6+dK0fsutj4Pd FWHaxUT5kUN1z3LqTcTk5MYa/xWDuu69spNQzCsATKqhHdvVJCuqP2Wckzq66bbvNN6x eFjz6TCKBf2+f1sGL/+qUoDopEADZqdy9crDJAq3Kew3cuz8gpyrjvF2kVuqm3+MHr4y l0cr7BhcT1sDaodYQURA9BWgdar/aSDn10+/2GeQoCD+pM1nBqVfJ18OynjEIQKhlo8u G5nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=RW0a9+o8lEfXcOVLEo0P2aG8R0V5SeWDjVCxgti+bUo=; b=mGg9xL79HkJU9r3aa1IibbA9QuApKfwo1JI7q3oqhQ1aJNqzmUf2MH/kfAcUuQ507U oh7XKAFfhBY4FOsi5T/z3g1I/W5JVzUlh7yCbpcY8X17K4zL56Fo+uFWq68APlpx3QWq c1hj1l33I0Se7Eq4MK4Hz9yvSAXWRH6qTzFu+wN2I90hwkq6Z8hnwAYRmYz6i3SBvKNe 9p5Ngo78A6U7q0ZwghYLWI/RvPfA2TTaouEg1jIrbTlM8L+XGSb4hc4oV/LZmDttnO83 Zc8WM02fxFx5mpF4V/cPejHbHq0PAbrGLHcwjuzsZ9TEhWvbWZ8I7ppLgcCrtTBuwkXH 5bJw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iy19-20020a170903131300b001a6fe422894si6098702plb.200.2023.06.05.17.46.42; Mon, 05 Jun 2023 17:46:54 -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; 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 S232502AbjFEX5M convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Jun 2023 19:57:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230328AbjFEX5L (ORCPT ); Mon, 5 Jun 2023 19:57:11 -0400 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2B4BF2; Mon, 5 Jun 2023 16:57:10 -0700 (PDT) Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-ba8374001abso6042088276.2; Mon, 05 Jun 2023 16:57:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686009430; x=1688601430; 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=dT1VLgcbU914AmCWBxVB8Uqq7gnS8nT0HPPcjgOhVqA=; b=AkXEPTzs2Ow/lRmO7T0kA4dNxsGqbM5gEQo6vZDx7pTP2Kzfbk4LztZ7bhzYYC0uZY VZZalosfTHwPsMiVkb/lNJ9xmWX20Lf56u+439wCWtEAWVqUr24QAQjsY3xMaMmUb+Am 8qAHN0oHXGyBpyLZo6XR9EciJ4vHIq4JNYvD7rTnyIK/W3i9c/yVBD8ilwTDTOK7u6Ij 5/iyKPj4ldFjBgaE0SiG0TFJccsHgLN4+/uVnirTmobK2orpxXzme/sre0Ii9ZyytH/v J0DD3ukCJnGC8w7S+SAD3HzZDeP2KhS7FXzGGp4QQ4b4Zzvc7GG6rkVc0edXQHDvyBjf cCcA== X-Gm-Message-State: AC+VfDzVNs0URl2kVh5w5oF+BXXpg9+iqq6bFuEXA2tF9e0n2iuB7QCS 5+uiipxXKp0ye0YQQBgfK09SVDFEm9ewPjzq0TgbdFXERhXAbQ== X-Received: by 2002:a25:8b87:0:b0:ba7:9c6f:e2de with SMTP id j7-20020a258b87000000b00ba79c6fe2demr99896ybl.27.1686009429930; Mon, 05 Jun 2023 16:57:09 -0700 (PDT) MIME-Version: 1.0 References: <20230524205054.3087004-1-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Mon, 5 Jun 2023 16:56:58 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] perf annotate: Handle x86 instruction suffix generally To: Adrian Hunter Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Ian Rogers , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Andi Kleen , Masami Hiramatsu , Kan Liang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 Hi Arnaldo, On Wed, May 24, 2023 at 10:21 PM Adrian Hunter wrote: > > On 24/05/23 23:50, Namhyung Kim wrote: > > In AT&T asm syntax, 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, > > assuming it has a suffix and it'd try again without the suffix if it's > > one of the allowed suffixes. This way, we can reduce the instruction > > table size for duplicated entries of the same instructions with a > > different suffix. > > > > If an instruction xyz and others like xyz are completely > > different ones, then they both need to be listed in the table so that > > they can be found before the second attempt (without the suffix). > > > > Signed-off-by: Namhyung Kim > > Reviewed-by: Adrian Hunter Can you please pick this up? Thanks, Namhyung > > > --- > > 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; > > } > > >