From patchwork Fri Dec 1 20:30:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 172658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1399238vqy; Fri, 1 Dec 2023 12:31:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRQxyo+D7TemuWs/kYYpAk73N+GY0Qp81qVrLH93zavxovCE4p/gkiUrnPQbAv2zaNSFH4 X-Received: by 2002:a05:6a00:189d:b0:6cd:9033:b3d0 with SMTP id x29-20020a056a00189d00b006cd9033b3d0mr89333pfh.28.1701462673260; Fri, 01 Dec 2023 12:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701462673; cv=none; d=google.com; s=arc-20160816; b=G1xmoGRdTlMlGBE+xdlPwkxtty4bMpdqDpDcrNabDFrpzteosYlK27ScSeOdXrBDYx zfGeuJUQgVtJYr0Epu9V7/clXhJI50svE7aDDyatuHMOhH0p+YGYZuM/BeHTvqRek4Gc CW2shClYlSPHStiSdo1eRoITgRZR9jTxhgugAeXHi83J0lum35sRga67RcdVAKKOh54y h0uToxtRXAQp5WBqBu5taWugba10nmXhQAw1E59JeLorhEcZ/L1YFhCHZ/AF9behywEN qIUYs+cqAcXTi3cLAY+1iDmQHRHFkInlOgUFSqoDs6rSVPKbwKOtvzfzGEl0faT1r7zq jstA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bmg+ttNSCzKmqi+mdIdWQIMaIa3NMN3rIZwgTL9pmis=; fh=uZsD07co8Icydw+TJ5RhxP40OBPNx7zXkeQ59T5yII8=; b=Gn1qh22xGb1OBMdIFtS30v9wC594itmMgPRzah3oORA5CXtSkH2BY6Ci6/zpyQnyoV vkeA0a/TjSxGJu/Y4tSC9TUelQJKTqCkiTplXZxPBjN/wm3q71LF2z9T7MVNwIzgdbNy NP0lAZlCwmpk31PzvXrIt0fbyoNwxr2wZBOIhocbLnp+0qDcBgZq1OfNcC81GFUXcrlK wNMk+SHiXlnlDROJ0B/oR2nOXiGAC9ABUxX+f8+S6LJfN3W7Tbd556zJrDV9bokcLF8q CqqF0YP4tc/HiHk4fJs8C91sBSEqi4bUwlExakqV+3xbEG+cRSY8KJ0qaa8lX2EKZvlu Jqhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ly7tgk2a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id dr2-20020a056a004a8200b006cbee3a0c06si3606239pfb.6.2023.12.01.12.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 12:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ly7tgk2a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6F019807D999; Fri, 1 Dec 2023 12:31:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379625AbjLAUa4 (ORCPT + 99 others); Fri, 1 Dec 2023 15:30:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379603AbjLAUay (ORCPT ); Fri, 1 Dec 2023 15:30:54 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0594E10F4 for ; Fri, 1 Dec 2023 12:31:01 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC08EC433CC; Fri, 1 Dec 2023 20:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701462660; bh=+mj0dcN7GlPP3mSnBDcO9llFhhVlvh7EarboXmVwsd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ly7tgk2aHQCuPkEy3d0psO0fSlUxGiuY/19+2l3JKYAzw2+dgsX70kVlPH6a30e/1 vy04Wvgg19peOLQMUhsmQYSVibsgt7pntzMX+FnYiRJRBzpIITky3qe44wzcyvQTJN CZwTwfluwXcs/fi1E/YTcXO2EfxTrQfGrOFwwsIBFXt8HAr+2a1rpRZR8Y7SSUwtcv IwyzFJFKlxQ3s2mtbDD1oOP6YcLW+dyscEqSIDOVpw/I7cLBQXm5r6VYtWOp+/uy6H 9XmU2EtZZBpphq9sIVY4TxkWrUmLYirCv8UTSj4gJfkpLmjFFvifqBNqseggX/ZI9X tELCENgp9/mrQ== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , David Laight Subject: [PATCH 2/2] perf env: Cache the arch specific strerrno function in perf_env__arch_strerrno() Date: Fri, 1 Dec 2023 17:30:46 -0300 Message-ID: <20231201203046.486596-3-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231201203046.486596-1-acme@kernel.org> References: <20231201203046.486596-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 01 Dec 2023 12:31:09 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784112923746442654 X-GMAIL-MSGID: 1784112923746442654 From: Arnaldo Carvalho de Melo So that we don't have to go thru the series of strcmp(arch) calls for each id -> string translation. Cc: Adrian Hunter Cc: David Laight Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Link: https://lore.kernel.org/lkml/ Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/trace/beauty/arch_errno_names.sh | 6 +++--- tools/perf/trace/beauty/beauty.h | 2 -- tools/perf/util/env.c | 6 ++++-- tools/perf/util/env.h | 5 +++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/trace/beauty/arch_errno_names.sh b/tools/perf/trace/beauty/arch_errno_names.sh index b6e0767b4b34e46a..7df4bf5b55a3cc2a 100755 --- a/tools/perf/trace/beauty/arch_errno_names.sh +++ b/tools/perf/trace/beauty/arch_errno_names.sh @@ -57,13 +57,13 @@ create_arch_errno_table_func() archlist="$1" default="$2" - printf 'const char *arch_syscalls__strerrno(const char *arch, int err)\n' + printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do printf '\tif (!strcmp(arch, "%s"))\n' $(arch_string "$arch") - printf '\t\treturn errno_to_name__%s(err);\n' $(arch_string "$arch") + printf '\t\treturn errno_to_name__%s;\n' $(arch_string "$arch") done - printf '\treturn errno_to_name__%s(err);\n' $(arch_string "$default") + printf '\treturn errno_to_name__%s;\n' $(arch_string "$default") printf '}\n' } diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h index 788e8f6bd90eb753..9feb794f5c6e15f4 100644 --- a/tools/perf/trace/beauty/beauty.h +++ b/tools/perf/trace/beauty/beauty.h @@ -251,6 +251,4 @@ size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool sh void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg, size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg)); -const char *arch_syscalls__strerrno(const char *arch, int err); - #endif /* _PERF_TRACE_BEAUTY_H */ diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index fdd62ea00173ccf5..2845b9f4694591be 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -456,8 +456,10 @@ const char *perf_env__arch(struct perf_env *env) const char *perf_env__arch_strerrno(struct perf_env *env, int err) { - const char *arch_name = perf_env__arch(env); - return arch_syscalls__strerrno(arch_name, err); + if (env->arch_strerrno == NULL) + env->arch_strerrno = arch_syscalls__strerrno_function(perf_env__arch(env)); + + return env->arch_strerrno ? env->arch_strerrno(err) : "no arch specific strerrno function"; } const char *perf_env__cpuid(struct perf_env *env) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 79f371879f45bafc..bf7e3c4c211f971e 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -53,6 +53,10 @@ struct pmu_caps { char *pmu_name; }; +typedef const char *(arch_syscalls__strerrno_t)(int err); + +arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch); + struct perf_env { char *hostname; char *os_release; @@ -135,6 +139,7 @@ struct perf_env { */ bool enabled; } clock; + arch_syscalls__strerrno_t *arch_strerrno; }; enum perf_compress_type {