2018-01-19 01:56:15 -07:00
|
|
|
#!/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()
|
|
|
|
{
|
2023-07-09 11:27:48 -07:00
|
|
|
arch="$1"
|
2018-01-19 01:56:15 -07:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-07-09 11:27:48 -07:00
|
|
|
arch=$(arch_string "$1")
|
2018-01-19 01:56:15 -07:00
|
|
|
|
2022-06-21 08:34:37 -07:00
|
|
|
printf "static const char *errno_to_name__%s(int err)\n{\n\tswitch (err) {\n" $arch
|
2018-01-19 01:56:15 -07:00
|
|
|
|
|
|
|
while read name nr; do
|
|
|
|
printf '\tcase %d: return "%s";\n' $nr $name
|
|
|
|
done
|
|
|
|
|
2022-06-21 08:34:37 -07:00
|
|
|
printf '\tdefault: return "(unknown)";\n\t}\n}\n'
|
2018-01-19 01:56:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
process_arch()
|
|
|
|
{
|
2023-07-09 11:27:48 -07:00
|
|
|
arch="$1"
|
|
|
|
asm_errno=$(asm_errno_file "$arch")
|
2018-01-19 01:56:15 -07:00
|
|
|
|
2020-03-06 00:11:10 -07:00
|
|
|
$gcc $CFLAGS $include_path -E -dM -x c $asm_errno \
|
2018-01-19 01:56:15 -07:00
|
|
|
|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()
|
|
|
|
{
|
2023-07-09 11:27:48 -07:00
|
|
|
archlist="$1"
|
|
|
|
default="$2"
|
2018-01-19 01:56:15 -07:00
|
|
|
|
2023-12-01 13:07:34 -07:00
|
|
|
printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch)\n'
|
2018-01-19 01:56:15 -07:00
|
|
|
printf '{\n'
|
|
|
|
for arch in $archlist; do
|
2024-04-08 19:32:16 -07:00
|
|
|
arch_str=$(arch_string "$arch")
|
|
|
|
printf '\tif (!strcmp(arch, "%s"))\n' "$arch_str"
|
|
|
|
printf '\t\treturn errno_to_name__%s;\n' "$arch_str"
|
2018-01-19 01:56:15 -07:00
|
|
|
done
|
2024-04-08 19:32:16 -07:00
|
|
|
arch_str=$(arch_string "$default")
|
|
|
|
printf '\treturn errno_to_name__%s;\n' "$arch_str"
|
2018-01-19 01:56:15 -07:00
|
|
|
printf '}\n'
|
|
|
|
}
|
|
|
|
|
|
|
|
cat <<EoHEADER
|
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
EoHEADER
|
|
|
|
|
perf beauty: Reuse the generic arch errno switch
Previously the code would see if, for example,
tools/perf/arch/arm/include/uapi/asm/errno.h exists and if not generate
a "generic" switch statement using the asm-generic/errno.h.
This creates multiple identical "generic" switch statements before the
default generic switch statement for an unknown architecture.
By simplifying the archlist to be only for architectures that are not
"generic" the amount of generated code can be reduced from 14 down to 6
functions.
Remove the special case of x86, instead reverse the architecture names
so that it comes first.
Committer testing:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > before
Apply this patch and:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > after
14 arches down to 6, that are the ones with an explicit errno.h file:
$ ls -1 tools/arch/*/include/uapi/asm/errno.h
tools/arch/alpha/include/uapi/asm/errno.h
tools/arch/mips/include/uapi/asm/errno.h
tools/arch/parisc/include/uapi/asm/errno.h
tools/arch/powerpc/include/uapi/asm/errno.h
tools/arch/sparc/include/uapi/asm/errno.h
tools/arch/x86/include/uapi/asm/errno.h
$
$ diff -u4 before after
@@ -2099,32 +987,16 @@
const char *arch_syscalls__strerrno(const char *arch, int err)
{
if (!strcmp(arch, "x86"))
return errno_to_name__x86(err);
- if (!strcmp(arch, "alpha"))
- return errno_to_name__alpha(err);
- if (!strcmp(arch, "arc"))
- return errno_to_name__arc(err);
- if (!strcmp(arch, "arm"))
- return errno_to_name__arm(err);
- if (!strcmp(arch, "arm64"))
- return errno_to_name__arm64(err);
- if (!strcmp(arch, "csky"))
- return errno_to_name__csky(err);
- if (!strcmp(arch, "mips"))
- return errno_to_name__mips(err);
- if (!strcmp(arch, "parisc"))
- return errno_to_name__parisc(err);
- if (!strcmp(arch, "powerpc"))
- return errno_to_name__powerpc(err);
- if (!strcmp(arch, "riscv"))
- return errno_to_name__riscv(err);
- if (!strcmp(arch, "s390"))
- return errno_to_name__s390(err);
- if (!strcmp(arch, "sh"))
- return errno_to_name__sh(err);
if (!strcmp(arch, "sparc"))
return errno_to_name__sparc(err);
- if (!strcmp(arch, "xtensa"))
- return errno_to_name__xtensa(err);
+ if (!strcmp(arch, "powerpc"))
+ return errno_to_name__powerpc(err);
+ if (!strcmp(arch, "parisc"))
+ return errno_to_name__parisc(err);
+ if (!strcmp(arch, "mips"))
+ return errno_to_name__mips(err);
+ if (!strcmp(arch, "alpha"))
+ return errno_to_name__alpha(err);
return errno_to_name__generic(err);
}
The rest of the patch is the removal of the errno_to_name__generic()
unneeded clones.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210513060441.408507-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-12 23:04:41 -07:00
|
|
|
# Create list of architectures that have a specific errno.h.
|
2018-01-19 01:56:15 -07:00
|
|
|
archlist=""
|
2023-11-30 14:46:36 -07:00
|
|
|
for f in $toolsdir/arch/*/include/uapi/asm/errno.h; do
|
|
|
|
d=${f%/include/uapi/asm/errno.h}
|
|
|
|
arch="${d##*/}"
|
perf beauty: Reuse the generic arch errno switch
Previously the code would see if, for example,
tools/perf/arch/arm/include/uapi/asm/errno.h exists and if not generate
a "generic" switch statement using the asm-generic/errno.h.
This creates multiple identical "generic" switch statements before the
default generic switch statement for an unknown architecture.
By simplifying the archlist to be only for architectures that are not
"generic" the amount of generated code can be reduced from 14 down to 6
functions.
Remove the special case of x86, instead reverse the architecture names
so that it comes first.
Committer testing:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > before
Apply this patch and:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > after
14 arches down to 6, that are the ones with an explicit errno.h file:
$ ls -1 tools/arch/*/include/uapi/asm/errno.h
tools/arch/alpha/include/uapi/asm/errno.h
tools/arch/mips/include/uapi/asm/errno.h
tools/arch/parisc/include/uapi/asm/errno.h
tools/arch/powerpc/include/uapi/asm/errno.h
tools/arch/sparc/include/uapi/asm/errno.h
tools/arch/x86/include/uapi/asm/errno.h
$
$ diff -u4 before after
@@ -2099,32 +987,16 @@
const char *arch_syscalls__strerrno(const char *arch, int err)
{
if (!strcmp(arch, "x86"))
return errno_to_name__x86(err);
- if (!strcmp(arch, "alpha"))
- return errno_to_name__alpha(err);
- if (!strcmp(arch, "arc"))
- return errno_to_name__arc(err);
- if (!strcmp(arch, "arm"))
- return errno_to_name__arm(err);
- if (!strcmp(arch, "arm64"))
- return errno_to_name__arm64(err);
- if (!strcmp(arch, "csky"))
- return errno_to_name__csky(err);
- if (!strcmp(arch, "mips"))
- return errno_to_name__mips(err);
- if (!strcmp(arch, "parisc"))
- return errno_to_name__parisc(err);
- if (!strcmp(arch, "powerpc"))
- return errno_to_name__powerpc(err);
- if (!strcmp(arch, "riscv"))
- return errno_to_name__riscv(err);
- if (!strcmp(arch, "s390"))
- return errno_to_name__s390(err);
- if (!strcmp(arch, "sh"))
- return errno_to_name__sh(err);
if (!strcmp(arch, "sparc"))
return errno_to_name__sparc(err);
- if (!strcmp(arch, "xtensa"))
- return errno_to_name__xtensa(err);
+ if (!strcmp(arch, "powerpc"))
+ return errno_to_name__powerpc(err);
+ if (!strcmp(arch, "parisc"))
+ return errno_to_name__parisc(err);
+ if (!strcmp(arch, "mips"))
+ return errno_to_name__mips(err);
+ if (!strcmp(arch, "alpha"))
+ return errno_to_name__alpha(err);
return errno_to_name__generic(err);
}
The rest of the patch is the removal of the errno_to_name__generic()
unneeded clones.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210513060441.408507-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-12 23:04:41 -07:00
|
|
|
test -f $toolsdir/arch/$arch/include/uapi/asm/errno.h && archlist="$archlist $arch"
|
2018-01-19 01:56:15 -07:00
|
|
|
done
|
|
|
|
|
perf beauty: Reuse the generic arch errno switch
Previously the code would see if, for example,
tools/perf/arch/arm/include/uapi/asm/errno.h exists and if not generate
a "generic" switch statement using the asm-generic/errno.h.
This creates multiple identical "generic" switch statements before the
default generic switch statement for an unknown architecture.
By simplifying the archlist to be only for architectures that are not
"generic" the amount of generated code can be reduced from 14 down to 6
functions.
Remove the special case of x86, instead reverse the architecture names
so that it comes first.
Committer testing:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > before
Apply this patch and:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > after
14 arches down to 6, that are the ones with an explicit errno.h file:
$ ls -1 tools/arch/*/include/uapi/asm/errno.h
tools/arch/alpha/include/uapi/asm/errno.h
tools/arch/mips/include/uapi/asm/errno.h
tools/arch/parisc/include/uapi/asm/errno.h
tools/arch/powerpc/include/uapi/asm/errno.h
tools/arch/sparc/include/uapi/asm/errno.h
tools/arch/x86/include/uapi/asm/errno.h
$
$ diff -u4 before after
@@ -2099,32 +987,16 @@
const char *arch_syscalls__strerrno(const char *arch, int err)
{
if (!strcmp(arch, "x86"))
return errno_to_name__x86(err);
- if (!strcmp(arch, "alpha"))
- return errno_to_name__alpha(err);
- if (!strcmp(arch, "arc"))
- return errno_to_name__arc(err);
- if (!strcmp(arch, "arm"))
- return errno_to_name__arm(err);
- if (!strcmp(arch, "arm64"))
- return errno_to_name__arm64(err);
- if (!strcmp(arch, "csky"))
- return errno_to_name__csky(err);
- if (!strcmp(arch, "mips"))
- return errno_to_name__mips(err);
- if (!strcmp(arch, "parisc"))
- return errno_to_name__parisc(err);
- if (!strcmp(arch, "powerpc"))
- return errno_to_name__powerpc(err);
- if (!strcmp(arch, "riscv"))
- return errno_to_name__riscv(err);
- if (!strcmp(arch, "s390"))
- return errno_to_name__s390(err);
- if (!strcmp(arch, "sh"))
- return errno_to_name__sh(err);
if (!strcmp(arch, "sparc"))
return errno_to_name__sparc(err);
- if (!strcmp(arch, "xtensa"))
- return errno_to_name__xtensa(err);
+ if (!strcmp(arch, "powerpc"))
+ return errno_to_name__powerpc(err);
+ if (!strcmp(arch, "parisc"))
+ return errno_to_name__parisc(err);
+ if (!strcmp(arch, "mips"))
+ return errno_to_name__mips(err);
+ if (!strcmp(arch, "alpha"))
+ return errno_to_name__alpha(err);
return errno_to_name__generic(err);
}
The rest of the patch is the removal of the errno_to_name__generic()
unneeded clones.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210513060441.408507-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-12 23:04:41 -07:00
|
|
|
for arch in generic $archlist; do
|
2018-01-19 01:56:15 -07:00
|
|
|
process_arch "$arch"
|
|
|
|
done
|
perf beauty: Reuse the generic arch errno switch
Previously the code would see if, for example,
tools/perf/arch/arm/include/uapi/asm/errno.h exists and if not generate
a "generic" switch statement using the asm-generic/errno.h.
This creates multiple identical "generic" switch statements before the
default generic switch statement for an unknown architecture.
By simplifying the archlist to be only for architectures that are not
"generic" the amount of generated code can be reduced from 14 down to 6
functions.
Remove the special case of x86, instead reverse the architecture names
so that it comes first.
Committer testing:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > before
Apply this patch and:
$ tools/perf/trace/beauty/arch_errno_names.sh gcc tools > after
14 arches down to 6, that are the ones with an explicit errno.h file:
$ ls -1 tools/arch/*/include/uapi/asm/errno.h
tools/arch/alpha/include/uapi/asm/errno.h
tools/arch/mips/include/uapi/asm/errno.h
tools/arch/parisc/include/uapi/asm/errno.h
tools/arch/powerpc/include/uapi/asm/errno.h
tools/arch/sparc/include/uapi/asm/errno.h
tools/arch/x86/include/uapi/asm/errno.h
$
$ diff -u4 before after
@@ -2099,32 +987,16 @@
const char *arch_syscalls__strerrno(const char *arch, int err)
{
if (!strcmp(arch, "x86"))
return errno_to_name__x86(err);
- if (!strcmp(arch, "alpha"))
- return errno_to_name__alpha(err);
- if (!strcmp(arch, "arc"))
- return errno_to_name__arc(err);
- if (!strcmp(arch, "arm"))
- return errno_to_name__arm(err);
- if (!strcmp(arch, "arm64"))
- return errno_to_name__arm64(err);
- if (!strcmp(arch, "csky"))
- return errno_to_name__csky(err);
- if (!strcmp(arch, "mips"))
- return errno_to_name__mips(err);
- if (!strcmp(arch, "parisc"))
- return errno_to_name__parisc(err);
- if (!strcmp(arch, "powerpc"))
- return errno_to_name__powerpc(err);
- if (!strcmp(arch, "riscv"))
- return errno_to_name__riscv(err);
- if (!strcmp(arch, "s390"))
- return errno_to_name__s390(err);
- if (!strcmp(arch, "sh"))
- return errno_to_name__sh(err);
if (!strcmp(arch, "sparc"))
return errno_to_name__sparc(err);
- if (!strcmp(arch, "xtensa"))
- return errno_to_name__xtensa(err);
+ if (!strcmp(arch, "powerpc"))
+ return errno_to_name__powerpc(err);
+ if (!strcmp(arch, "parisc"))
+ return errno_to_name__parisc(err);
+ if (!strcmp(arch, "mips"))
+ return errno_to_name__mips(err);
+ if (!strcmp(arch, "alpha"))
+ return errno_to_name__alpha(err);
return errno_to_name__generic(err);
}
The rest of the patch is the removal of the errno_to_name__generic()
unneeded clones.
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210513060441.408507-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-12 23:04:41 -07:00
|
|
|
create_arch_errno_table_func "$archlist" "generic"
|