Message ID | 20230524205054.3087004-1-namhyung@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp174900vqr; Wed, 24 May 2023 13:55:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48j5iieEXGNmlrviTryc8o6XENGsLRQKcVNDZq3aBAfFTF4G6e3XrOcQ4q/S3GBnTSo/X3 X-Received: by 2002:a17:902:c20c:b0:1aa:ef83:34be with SMTP id 12-20020a170902c20c00b001aaef8334bemr18084667pll.47.1684961712626; Wed, 24 May 2023 13:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684961712; cv=none; d=google.com; s=arc-20160816; b=Mai90SKRPIACUTzNoRNEu3HeL6ABV77h+PFK7pLnTVUBCObViMZ7SvNKvsYFZOvxyX AmMah+nyDd2lQpqfSdgmVQewGL4EB1XTMcgYrwaf6O86qIm20fsw2fTtSPPVIx3qP6kI WRWPJXcF6307LaudocVh0EA7pq0X59P3nLLbw66k/CJYpi/5Bu7qH3+oCnXW3VR8YnsY 1DgS7avdWGrZ/qbl5Yim+JXYku0KSol9ul/MhdiS1hBnrtmgWMm5sCOgl56b/kBRjeIN /QUjiG5ezcHUoTHrj5ahaPN/FBvllTBLc6cAtdhwseUkL0ROQ10jwAU2aEhMbh+D3TA8 xoeA== 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=+kCS8NmWh8J3rptO4tJyXuUGglRPpK4fkLORybVjSro=; b=DvGdiVl0QF/7Us2Sju5nTbYtyA2WznMmxUuk4pJsWjNk4wF2azI64AXsTUC5WZVwFE dfvM0ydLJV2tY4yxNhqQLOBJ6Q8xdYhUTJxGAgxxiV/krShtP+ZSDXotEZA3oZszhHGk FdPv9FGa0X3ON1p8P2xa6UQ8vQ/s9s0uxlm3eG7+ONinRsg1yy5RZse1qaEwO5JjAbUk bvRdRyHg/Alt0F8+rzWdjAzCn93u4WtJCEC5htgWRGmIgOCAEEie+ofOpMC6qOOK4o4F hPm100PmK06dJJc7InbVu7NIZOA6zpbU6G295pkGZo550l6ID2BaCRkauHglR8R+58NI 3mvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TH8yxjEG; 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 n7-20020a170902e54700b001a94f85b0besi9252328plf.406.2023.05.24.13.54.57; Wed, 24 May 2023 13:55:12 -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=TH8yxjEG; 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 S231658AbjEXUvA (ORCPT <rfc822;jian.xie.xdx@gmail.com> + 99 others); Wed, 24 May 2023 16:51:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjEXUu7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 24 May 2023 16:50:59 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF67E12B; Wed, 24 May 2023 13:50:58 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ae454844edso5430625ad.1; Wed, 24 May 2023 13:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684961458; x=1687553458; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=+kCS8NmWh8J3rptO4tJyXuUGglRPpK4fkLORybVjSro=; b=TH8yxjEGgCPqsHlvuDYZXFS1SUUnpo3HgCA7hD10gV3eVWv+XCC4O8Gjl3Th9GGBIz FBEPj/rKHB9yXKMSpf+JiXA1lbbhT2SpxSouY9dVFzS3te99iNEeEx1pPczgdCOdoxbF o28mDQkkS53f88pnp956dWOrVAlzBfZMavlaEsmDHAn4pcqih1soB63MrDzIt7QCY33E WFp4aTdT9T7cV3Vd71rrBbboX+YkGwgskQXyRkI6gWfHf5Z4s5jbUW6rIPyHlGRN3JzS h5HOkJzAqF1P5imbKnyTKS55BWu0Yl510RmsVCTFzsVipY8BTnC1W3elNDYd3Ay7GZ7n Lcqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684961458; x=1687553458; 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=+kCS8NmWh8J3rptO4tJyXuUGglRPpK4fkLORybVjSro=; b=OIKuHdT9igXM2wdzkKZGI+f8ByHUPv6c9iO0mUYsslt4ImUCFNxjJRsOrhdumwF8Dr gmUC14WrqhbfFyBdbQzE18hPnp0EQ9PqA3G5qCzhItAp7ofScpsKCOwww8yze4zgC1y6 UP7eE8U5qtu5X0hI0oSy98/IIWCUk+w5y5mAKUUT83m1evpsEFmRncZNeSjqHJ2ALCft I4NG4XdiD9czEr5ZIfEUNPqeyw3lTEpDw+GyIx8/zd4tICfJqOfKMPxdbD4OvHkAIZPE Iu32kpaYaIWi0Ejkw5Lt3GgF+YROVDxuaG2v6S7ag+ew2tLqlftMKacIM1bKaKbpEiaI 8qUQ== X-Gm-Message-State: AC+VfDw9MCqsMKOYAazqwULvmcslyxPcJigN1mBkOSkgjw/h9XHTPfEV AIC4ldn2lMZEB9ZcInt+bOU= X-Received: by 2002:a17:902:c20c:b0:1aa:ef83:34be with SMTP id 12-20020a170902c20c00b001aaef8334bemr18075841pll.47.1684961457892; Wed, 24 May 2023 13:50:57 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2d4:203:121:f908:b42d:c399]) by smtp.gmail.com with ESMTPSA id 31-20020a63185f000000b00513973a7014sm5215340pgy.12.2023.05.24.13.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 13:50:57 -0700 (PDT) Sender: Namhyung Kim <namhyung@gmail.com> From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org> Cc: Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>, LKML <linux-kernel@vger.kernel.org>, linux-perf-users@vger.kernel.org, Andi Kleen <ak@linux.intel.com>, Masami Hiramatsu <mhiramat@kernel.org>, Kan Liang <kan.liang@linux.intel.com> Subject: [PATCH v2 1/2] perf annotate: Handle x86 instruction suffix generally Date: Wed, 24 May 2023 13:50:53 -0700 Message-ID: <20230524205054.3087004-1-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766810412489785980?= X-GMAIL-MSGID: =?utf-8?q?1766810412489785980?= |
Series |
[v2,1/2] perf annotate: Handle x86 instruction suffix generally
|
|
Commit Message
Namhyung Kim
May 24, 2023, 8:50 p.m. UTC
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<suffix> 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 <namhyung@kernel.org>
---
tools/perf/util/annotate.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
Comments
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<suffix> 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 <namhyung@kernel.org> Reviewed-by: Adrian Hunter <adrian.hunter@intel.com> > --- > 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; > } >
Hi Arnaldo, On Wed, May 24, 2023 at 10:21 PM Adrian Hunter <adrian.hunter@intel.com> 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<suffix> 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 <namhyung@kernel.org> > > Reviewed-by: Adrian Hunter <adrian.hunter@intel.com> 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; > > } > > >
On Wed, 24 May 2023 13:50:53 -0700 Namhyung Kim <namhyung@kernel.org> 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<suffix> 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). Looks good to me. Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > --- > 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; > } > > -- > 2.41.0.rc0.172.g3f132b7071-goog >
Em Tue, Jun 06, 2023 at 11:06:58PM +0900, Masami Hiramatsu escreveu: > On Wed, 24 May 2023 13:50:53 -0700 > Namhyung Kim <namhyung@kernel.org> 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<suffix> 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). > > Looks good to me. > > Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Thanks, applied both patches. - Arnaldo > > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > --- > > 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; > > } > > > > -- > > 2.41.0.rc0.172.g3f132b7071-goog > > > > > -- > Masami Hiramatsu (Google) <mhiramat@kernel.org>
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; }