From 124654232c8e9fb436394b8ca6a69ce205d70d8b Mon Sep 17 00:00:00 2001 From: dingguangya Date: Mon, 4 Sep 2023 20:06:54 +0800 Subject: [PATCH] [Sync] Sync patch from openeuler/gcc Sync patch from openeuler/gcc (cherry picked from commit 95427adf7d16bbb61ae3ced9c64aacbaf53dce72) --- 0025-AArch64-Rewrite-the-tsv110-option.patch | 114 ++++++++++++++++++ ...utline-atomics-improves-libgomp-perf.patch | 37 ++++++ gcc.spec | 10 +- 3 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 0025-AArch64-Rewrite-the-tsv110-option.patch create mode 100644 0026-GOMP-Enabling-moutline-atomics-improves-libgomp-perf.patch diff --git a/0025-AArch64-Rewrite-the-tsv110-option.patch b/0025-AArch64-Rewrite-the-tsv110-option.patch new file mode 100644 index 0000000..d2e0dcd --- /dev/null +++ b/0025-AArch64-Rewrite-the-tsv110-option.patch @@ -0,0 +1,114 @@ +From 2f0d0b1298fb9c3266bb102796b027a5570ad833 Mon Sep 17 00:00:00 2001 +From: dingguangya +Date: Mon, 4 Sep 2023 16:27:38 +0800 +Subject: [PATCH 1/2] [AArch64] Rewrite the tsv110 option + +Reset the more appropriate options for tsv110. +--- + gcc/common/config/aarch64/aarch64-common.cc | 76 +++++++++++++++++++++ + 1 file changed, 76 insertions(+) + +diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc +index dfda5b837..85ce8133b 100644 +--- a/gcc/common/config/aarch64/aarch64-common.cc ++++ b/gcc/common/config/aarch64/aarch64-common.cc +@@ -44,6 +44,8 @@ + #undef TARGET_OPTION_INIT_STRUCT + #define TARGET_OPTION_INIT_STRUCT aarch64_option_init_struct + ++#define INVALID_IMP ((unsigned) -1) ++ + /* Set default optimization options. */ + static const struct default_options aarch_option_optimization_table[] = + { +@@ -65,6 +67,77 @@ static const struct default_options aarch_option_optimization_table[] = + { OPT_LEVELS_NONE, 0, NULL, 0 } + }; + ++/* CPU vendor id. */ ++static unsigned vendor_id = INVALID_IMP; ++ ++/* The part number of the CPU. */ ++static unsigned part_id = INVALID_IMP; ++ ++/* Return the hex integer that is after ':' for the FIELD. ++ Return -1 if there was problem parsing the integer. */ ++static unsigned ++parse_cpuinfo (char *field) ++{ ++ if (field == NULL) ++ return INVALID_IMP; ++ const char *rest = strchr (field, ':'); ++ ++ if (rest == NULL) ++ return INVALID_IMP; ++ ++ char *after; ++ unsigned fint = strtol (rest + 1, &after, 16); ++ if (after == rest + 1) ++ return INVALID_IMP; ++ return fint; ++} ++ ++/* Read CPU vendor_id and part_id. */ ++ ++static void ++read_cpuinfo () ++{ ++ FILE *fp = fopen ("/proc/cpuinfo", "r"); ++ if (fp == NULL) ++ return; ++ ++ /* Read 1024-byte data from /proc/cpuinfo. */ ++ char cpuinfo[1024]; ++ fread(cpuinfo, sizeof(char), sizeof(cpuinfo) - 1, fp); ++ ++ char *vendor = strstr(cpuinfo, "CPU implementer"); ++ vendor_id = parse_cpuinfo(vendor); ++ ++ char *part = strstr(cpuinfo, "CPU part"); ++ part_id = parse_cpuinfo(part); ++ ++ fclose(fp); ++} ++ ++/* Reset the tsv110 option. After checking the platform information, ++ this function can reset the more appropriate options. ++ TODO: Currently, this function is not applicable to the cross ++ compilation scenario. */ ++ ++static void ++reset_tsv110_option () ++{ ++ /* Read CPU Information. */ ++ if (vendor_id == INVALID_IMP) ++ read_cpuinfo (); ++ ++ if (vendor_id == 0x48 && part_id == 0xd01) ++ { ++ /* Outline-atomics is enabled by default and ++ aarch64_flag_outline_atomics defaults to 2. Therefore, the current ++ modification affects only the default scenario. When the option ++ moutline-atomics is added, the value of aarch64_flag_outline_atomics is 1, ++ that is, aarch64_flag_outline_atomics is not reset to 0. */ ++ if (aarch64_flag_outline_atomics == 2) ++ aarch64_flag_outline_atomics = 0; ++ } ++} ++ + /* Implement TARGET_HANDLE_OPTION. + This function handles the target specific options for CPU/target selection. + +@@ -83,6 +156,9 @@ aarch64_handle_option (struct gcc_options *opts, + const char *arg = decoded->arg; + int val = decoded->value; + ++ /* Reset the tsv110 options. */ ++ reset_tsv110_option (); ++ + switch (code) + { + case OPT_march_: +-- +2.33.0 + diff --git a/0026-GOMP-Enabling-moutline-atomics-improves-libgomp-perf.patch b/0026-GOMP-Enabling-moutline-atomics-improves-libgomp-perf.patch new file mode 100644 index 0000000..b57a5a6 --- /dev/null +++ b/0026-GOMP-Enabling-moutline-atomics-improves-libgomp-perf.patch @@ -0,0 +1,37 @@ +From 7efae59159577657f22511aa3b2cebe85ca60d9d Mon Sep 17 00:00:00 2001 +From: dingguangya +Date: Mon, 4 Sep 2023 16:30:58 +0800 +Subject: [PATCH 2/2] [GOMP] Enabling moutline-atomics improves libgomp + performance in multi-thread scenarios + +Libgomp is used in multi-thread scenarios, +Enabling moutline-atomics improves performance. +--- + libgomp/configure.tgt | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/libgomp/configure.tgt b/libgomp/configure.tgt +index 2cd7272fc..f924e9f98 100644 +--- a/libgomp/configure.tgt ++++ b/libgomp/configure.tgt +@@ -32,6 +32,17 @@ if test $gcc_cv_have_tls = yes ; then + esac + fi + ++# Enabling moutline-atomics improves libgomp performance in multi-thread scenarios. ++case "${target_cpu}" in ++ aarch64*) ++ case "${target}" in ++ aarch64*-*-linux*) ++ XCFLAGS="${XCFLAGS} -moutline-atomics" ++ ;; ++ esac ++ ;; ++esac ++ + tmake_file= + # Since we require POSIX threads, assume a POSIX system by default. + config_path="posix" +-- +2.33.0 + diff --git a/gcc.spec b/gcc.spec index fa47798..50445a9 100644 --- a/gcc.spec +++ b/gcc.spec @@ -2,7 +2,7 @@ %global gcc_major 12 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 9 +%global gcc_release 10 %global _unpackaged_files_terminate_build 0 %global _performance_build 1 @@ -159,6 +159,8 @@ Patch21: 0021-StructReorderFields-Structure-reorder-fields.patch Patch22: 0022-DFE-Add-Dead-Field-Elimination-in-Struct-Reorg.patch Patch23: 0023-PGO-kernel-Add-fkernel-pgo-option-to-support-PGO-ker.patch Patch24: 0024-Struct-Reorg-Refactoring-and-merge-reorder-fields-in.patch +Patch25: 0025-AArch64-Rewrite-the-tsv110-option.patch +Patch26: 0026-GOMP-Enabling-moutline-atomics-improves-libgomp-perf.patch # On ARM EABI systems, we do want -gnueabi to be part of the # target triple. @@ -649,6 +651,8 @@ not stable, so plugins must be rebuilt any time GCC is updated. %patch22 -p1 %patch23 -p1 %patch24 -p1 +%patch25 -p1 +%patch26 -p1 echo '%{_vendor} %{version}-%{release}' > gcc/DEV-PHASE @@ -2752,6 +2756,10 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Mon Sep 04 2023 dingguangya 12.3.1-10 +- Type: Sync +- DESC: Sync patch from openeuler/gcc + * Tue Aug 29 2023 huangxiaoquan 12.3.1-9 - Type: Sync - DESC: Sync patch from openeuler/gcc part 2 -- Gitee