From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F3FDC7EE24 for ; Mon, 5 Jun 2023 23:57:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232168AbjFEX5M convert rfc822-to-8bit (ORCPT ); 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-Google-Smtp-Source: ACHHUZ6wxJN99gbp1wFCNM7foFqrCsQe1qe/8D+p4YucDPIiXBInk1KI8dw4snDZjTizyZbZiKZJAs78w3MQKcfhKLc= 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 Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@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; > > } > > >