From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hendrik Brueckner Subject: [PATCH 3/5] perf util: Introduce architecture specific errno/name mapping Date: Tue, 16 Jan 2018 10:46:29 +0100 Message-ID: <1516095991-16337-4-git-send-email-brueckner@linux.vnet.ibm.com> References: <1516095991-16337-1-git-send-email-brueckner@linux.vnet.ibm.com> Return-path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44200 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751062AbeAPJqr (ORCPT ); Tue, 16 Jan 2018 04:46:47 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0G9iunh109214 for ; Tue, 16 Jan 2018 04:46:47 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fhb4shn9t-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 16 Jan 2018 04:46:47 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Jan 2018 09:46:44 -0000 In-Reply-To: <1516095991-16337-1-git-send-email-brueckner@linux.vnet.ibm.com> Sender: linux-perf-users-owner@vger.kernel.org List-ID: To: Arnaldo Carvalho de Melo Cc: Thomas-Mich Richter , Michael Petlan , Jiri Olsa , linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org, Arnaldo Carvalho de Melo Introduce a script that generates a mapping of errno numbers to their names for each architecture that is supported by perf (i.e. has a subdirectory in tools/perf/arch/). The file is generated as util/errno-names.c. A corresponding header file util/errno-names.h is provided that defines the arch_errno_to_name() function. Use arch_errno_to_name() to lookup an errno value to obtain the errno name (e.g. ENOENT) for a particular architecture. This is to be used by perf trace. Signed-off-by: Hendrik Brueckner Reviewed-by: Thomas Richter Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa --- tools/perf/.gitignore | 1 + tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 9 ++- tools/perf/util/Build | 1 + tools/perf/util/errno-names.h | 7 +++ tools/perf/util/generate-errno-names.sh | 101 ++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 tools/perf/util/errno-names.h create mode 100755 tools/perf/util/generate-errno-names.sh diff --git a/tools/perf/.gitignore b/tools/perf/.gitignore index 643cc4ba..1d4d43c 100644 --- a/tools/perf/.gitignore +++ b/tools/perf/.gitignore @@ -14,6 +14,7 @@ perf*.1 perf*.xml perf*.html common-cmds.h +errno-names.c perf.data perf.data.old output.svg diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 12dec6e..90ce14f 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -249,7 +249,7 @@ INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/ INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/ -# $(obj-perf) for generated common-cmds.h +# $(obj-perf) for generated common-cmds.h and errno-names.c # $(obj-perf)/util for generated bison/flex headers ifneq ($(OUTPUT),) INC_FLAGS += -I$(obj-perf)/util diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 9fdefd7..332b4b4 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -518,6 +518,9 @@ $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt $(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt) $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@ +$(OUTPUT)util/errno-names.c: util/generate-errno-names.sh + $(QUIET_GEN). util/generate-errno-names.sh "$(CC)" "$(srctree)/tools" > $@+ && mv $@+ $@ + $(SCRIPTS) : % : %.sh $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@' @@ -565,7 +568,8 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc $(vhost_virtio_ioctl_array) \ $(madvise_behavior_array) \ $(perf_ioctl_array) \ - $(prctl_option_array) + $(prctl_option_array) \ + $(OUTPUT)util/errno-names.c $(OUTPUT)%.o: %.c prepare FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@ @@ -847,7 +851,8 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea $(OUTPUT)$(kcmp_type_array) \ $(OUTPUT)$(vhost_virtio_ioctl_array) \ $(OUTPUT)$(perf_ioctl_array) \ - $(OUTPUT)$(prctl_option_array) + $(OUTPUT)$(prctl_option_array) \ + $(OUTPUT)util/errno-names.c $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean # diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 7c6a8b4..6d4f8f0 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -5,6 +5,7 @@ libperf-y += config.o libperf-y += ctype.o libperf-y += db-export.o libperf-y += env.o +libperf-y += errno-names.o libperf-y += event.o libperf-y += evlist.o libperf-y += evsel.o diff --git a/tools/perf/util/errno-names.h b/tools/perf/util/errno-names.h new file mode 100644 index 0000000..1cdcbd3 --- /dev/null +++ b/tools/perf/util/errno-names.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_ERRNO_NAMES_H +#define __PERF_ERRNO_NAMES_H + +const char *arch_errno_to_name(const char *arch, int err); + +#endif /* __PERF_ERRNO_NAMES_H */ diff --git a/tools/perf/util/generate-errno-names.sh b/tools/perf/util/generate-errno-names.sh new file mode 100755 index 0000000..1738800 --- /dev/null +++ b/tools/perf/util/generate-errno-names.sh @@ -0,0 +1,101 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Generate C file mapping errno codes to errno names. +# +# Copyright IBM Corp. 2018 +# Author(s): Hendrik Brueckner + +gcc="$1" +toolsdir="$2" +include_path="-I$toolsdir/include/uapi" + +arch_string() +{ + echo "$1" |sed -e 'y/- /__/' |tr '[[:upper:]]' '[[:lower:]]' +} + +asm_errno_file() +{ + local arch="$1" + local header + + header="$toolsdir/arch/$arch/include/uapi/asm/errno.h" + if test -r "$header"; then + echo "$header" + else + echo "$toolsdir/include/uapi/asm-generic/errno.h" + fi +} + +create_errno_lookup_func() +{ + local arch=$(arch_string "$1") + local nr name + + cat < +#include "errno-names.h" + +EoHEADER + +# Create list of architectures and ignore those that do not appear +# in tools/perf/arch +archlist="" +for arch in $(find $toolsdir/arch -maxdepth 1 -mindepth 1 -type d -printf "%f\n" |sort); do + test -d arch/$arch && archlist="$archlist $arch" +done + +for arch in $archlist generic; do + process_arch "$arch" +done +create_arch_errno_table_func "$archlist" "generic" -- 1.8.3.1