Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6005019rwd; Wed, 24 May 2023 09:31:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Pw+ifj1It1jrDFb+KyyIOxeONQ/vEbkoQXhevdFyLDdxhNHxx0bx9LmRoSRVQdYFEQsDF X-Received: by 2002:a17:90a:cf01:b0:24e:3e07:9e27 with SMTP id h1-20020a17090acf0100b0024e3e079e27mr20738574pju.10.1684945894885; Wed, 24 May 2023 09:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684945894; cv=none; d=google.com; s=arc-20160816; b=Be1VxX2U1um6MuBaHh+IdDI5oGQmM7dAFaxyFn1L4UyqiK5qrc8PQp5z1Hx/kWbCkw R2IhcfIKafxp7D+RAZl6hr2WPxywDUXwiN1F5I8yIHINA0A/sXb5wrg2mCefi/zYV73t /b5w0f0vouvlPhe+1JXOe/qI4P9XVHhx7JE4Hhu5flCnd0jjjg+gVxYn+5nBynN6sWKP Y8l2wN3SyQIssNkPX6KvWwW4vduepUWF12WNt9Dquz2FJB7lVpJrCKVqgQcVVX3vaz9R gIQVWYUayVrW75npyS5TG7s+SFxxkgT4yUL//Qr2snPvjxiPbyeNvru2fXAhkm5UPx29 pe3g== 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=JiEjoGVIg+89fN2lf0naUZpKihn8jn7FKyp1smiZhBY=; b=R1tUAwy91nvc8wsW6DaGU6H57152iZxbhFI10zpxX13lwByaFdTLqeQZw1gu6GzXj6 pROeyuDiA7qMKPUT8SIOc+uCG7eQ81Y/chw3FduYOzy2X2OF70435QHKPtPEJqjBhw/a JgwM107y9YAyrsyB4tp1azLFHkhjGjqhznT6Ci/B/I7TOwVfQkpd4JCP7StHhuSDsHK4 +V/Hz6CIVYyIpOKF0j8RF3ZLeMiDAK59YS4NO9sqD6Wg5+nNml9Vz578MDgYO1hfxZMC pWTwUzofQzeVBdwNse9rRlRR/5gcn8vmAxutzARrUjrPWVKaOTmaXUoGCSATFp4W59Pq Kq6g== 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 o29-20020a637e5d000000b00528c170e4f3si8866667pgn.544.2023.05.24.09.31.21; Wed, 24 May 2023 09:31:34 -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 S232644AbjEXQLP convert rfc822-to-8bit (ORCPT + 99 others); Wed, 24 May 2023 12:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjEXQLM (ORCPT ); Wed, 24 May 2023 12:11:12 -0400 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 329C510B; Wed, 24 May 2023 09:10:59 -0700 (PDT) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-55db055b412so21117b3.0; Wed, 24 May 2023 09:10:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684944658; x=1687536658; 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=hliVnTwHwWho3tFIzV1PGbhYXsG4KcvdaSdTP6Kzvoc=; b=NpSiIhbRB35clt5PBN3+ovlcOV0PyISYv+TCeAEFzaYh7h2jl/Zl4zjhoGOd1Ru+id sRPBJZOHo8GpRC6ZMMvfEMRF2BH6Ls/wrMxtBH3klFnHYxQjUDc2Z82OTdntmqiVtA+Y MD71CA86GtRFKy3tjxMR5j2CiHjbNDEPVV5eIfaQ/Ubnf5p427UvduQZJ70lj8eS4N2N dO6N30cBJc0syNhM+djXQXctA39Y0epaqz1mH+587xs+iw3HFprC8c26JHEJiq6l1L3/ sMHJ0F++ixVGMX2eYro/P35ot+9526d0df5p6BV7INuI44v5mNVI8mAd9bKZYx3nrtZ1 MdCw== X-Gm-Message-State: AC+VfDxfSfxbhITBV6lNYU/TrYqV/EqwK7tpbLCrBrN1qxauIbFRvcDw rFK0zbkIGc81byy6yf4FIyUzkre0IcQis6Wro5I= X-Received: by 2002:a25:208:0:b0:bab:b12c:b665 with SMTP id 8-20020a250208000000b00babb12cb665mr402930ybc.7.1684944658133; Wed, 24 May 2023 09:10:58 -0700 (PDT) MIME-Version: 1.0 References: <20230524052834.1041418-1-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Wed, 24 May 2023 09:10:47 -0700 Message-ID: Subject: Re: [PATCH 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 Adrian, On Tue, May 23, 2023 at 11:11 PM Adrian Hunter wrote: > > On 24/05/23 08:28, Namhyung Kim wrote: > > Most of x86 instructions can have size suffix like b, w, l or q. > > (AT&T mnemonics) Right, will update. > > > 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. > > I guess it might be possible that xyz is in the table but xyz > is a completely different instruction? Then xyz should be in the table too. The match without suffix is a fallback so it should find the correct instruction first. Thanks, Namhyung > > > > > 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; > > } > > >