From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Cc: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>,
Michael Petlan <mpetlan@redhat.com>, Jiri Olsa <jolsa@redhat.com>,
linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH 3/5] perf util: Introduce architecture specific errno/name mapping
Date: Tue, 16 Jan 2018 10:58:48 -0300 [thread overview]
Message-ID: <20180116135848.GC25687@kernel.org> (raw)
In-Reply-To: <1516095991-16337-4-git-send-email-brueckner@linux.vnet.ibm.com>
Em Tue, Jan 16, 2018 at 10:46:29AM +0100, Hendrik Brueckner escreveu:
> 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.
Ok, this is almost there, one nit I think needs to be fixed, instead of
generating it on $(OUTPUT)util/errno-names.c we can generate it here:
[acme@jouet perf]$ ls -la /tmp/build/perf/trace/beauty/generated
total 16
drwxrwxr-x. 3 acme acme 140 Jan 16 10:23 .
drwxrwxr-x. 3 acme acme 380 Jan 16 10:23 ..
drwxrwxr-x. 2 acme acme 160 Jan 16 10:23 ioctl
-rw-rw-r--. 1 acme acme 235 Jan 16 10:23 kcmp_type_array.c
-rw-rw-r--. 1 acme acme 421 Jan 16 10:23 madvise_behavior_array.c
-rw-rw-r--. 1 acme acme 152 Jan 16 10:23 pkey_alloc_access_rights_array.c
-rw-rw-r--. 1 acme acme 1222 Jan 16 10:23 prctl_option_array.c
[acme@jouet perf]$
[acme@jouet perf]$ ls -la /tmp/build/perf/trace/beauty/generated/ioctl/
total 28
drwxrwxr-x. 2 acme acme 160 Jan 16 10:23 .
drwxrwxr-x. 3 acme acme 140 Jan 16 10:23 ..
-rw-rw-r--. 1 acme acme 5440 Jan 16 10:23 drm_ioctl_array.c
-rw-rw-r--. 1 acme acme 2269 Jan 16 10:23 kvm_ioctl_array.c
-rw-rw-r--. 1 acme acme 226 Jan 16 10:23 perf_ioctl_array.c
-rw-rw-r--. 1 acme acme 689 Jan 16 10:23 sndrv_ctl_ioctl_array.c
-rw-rw-r--. 1 acme acme 716 Jan 16 10:23 sndrv_pcm_ioctl_array.c
-rw-rw-r--. 1 acme acme 883 Jan 16 10:23 vhost_virtio_ioctl_array.c
[acme@jouet perf]$
I.e. all these are beautifier routines generated by shell scripts from
kernel header copies, so I think this new one, for errno, belongs there,
ok?
tools/perf/Makefile.perf is where this is being done, arguably with a
lot of cut'n'paste boilerplate that has to get cleaned up at some point
:-\
What do you think?
- Arnaldo
> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
> Reviewed-by: Thomas Richter <tmricht@linux.vnet.ibm.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> ---
> 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 <brueckner@linux.vnet.ibm.com>
> +
> +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 <<EoFuncBegin
> +static const char *errno_to_name__$arch(int err)
> +{
> + switch (err) {
> +EoFuncBegin
> +
> + while read name nr; do
> + printf '\tcase %d: return "%s";\n' $nr $name
> + done
> +
> + cat <<EoFuncEnd
> + default:
> + return "(unknown)";
> + }
> +}
> +
> +EoFuncEnd
> +}
> +
> +process_arch()
> +{
> + local arch="$1"
> + local asm_errno=$(asm_errno_file "$arch")
> +
> + $gcc $include_path -E -dM -x c $asm_errno \
> + |grep -hE '^#define[[:blank:]]+(E[^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' \
> + |awk '{ print $2","$3; }' \
> + |sort -t, -k2 -nu \
> + |IFS=, create_errno_lookup_func "$arch"
> +}
> +
> +create_arch_errno_table_func()
> +{
> + local archlist="$1"
> + local default="$2"
> + local arch
> +
> + printf 'const char *arch_errno_to_name(const char *arch, int err)\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")
> + done
> + printf '\treturn errno_to_name__%s(err);\n' $(arch_string "$default")
> + printf '}'
> +}
> +
> +cat <<EoHEADER
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#include <string.h>
> +#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
next prev parent reply other threads:[~2018-01-16 13:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-16 9:46 [PATCH 0/5] perf trace: Introduce arch-specific errno code/name mappings Hendrik Brueckner
2018-01-16 9:46 ` [PATCH 1/5] tools include arch: Grab a copy of errno.h for arch's supported by perf Hendrik Brueckner
2018-01-16 9:46 ` [PATCH 2/5] tools include asm-generic: Grab errno.h and errno-base.h Hendrik Brueckner
2018-01-16 9:46 ` [PATCH 3/5] perf util: Introduce architecture specific errno/name mapping Hendrik Brueckner
2018-01-16 13:58 ` Arnaldo Carvalho de Melo [this message]
2018-01-17 8:49 ` Hendrik Brueckner
2018-01-18 10:07 ` Jiri Olsa
2018-01-18 10:49 ` Arnaldo Carvalho de Melo
2018-01-18 11:33 ` Hendrik Brueckner
2018-01-18 14:11 ` Arnaldo Carvalho de Melo
2018-01-18 12:19 ` Jiri Olsa
2018-01-16 9:46 ` [PATCH 4/5] perf trace: Obtain errno values by using arch_errno_to_name() Hendrik Brueckner
2018-01-16 9:46 ` [PATCH 5/5] perf trace: Remove audit-libs dependency if syscall tables are present Hendrik Brueckner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180116135848.GC25687@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=brueckner@linux.vnet.ibm.com \
--cc=jolsa@redhat.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mpetlan@redhat.com \
--cc=tmricht@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox