Re: [PATCH 3/5] perf util: Introduce architecture specific errno/name mapping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx>
> Reviewed-by: Thomas Richter <tmricht@xxxxxxxxxxxxxxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxxxxxxxxxx>
> +
> +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
--
To unsubscribe from this list: send the line "unsubscribe linux-s390" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux