Update gcc-auto-profile / gen_autofdo_event.py

Message ID 20241031233639.3672032-1-ak@linux.intel.com
State Committed
Commit 9c8f3d5e7d5ee64ffe5c50a72b087227f2e8f957
Headers
Series Update gcc-auto-profile / gen_autofdo_event.py |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Andi Kleen Oct. 31, 2024, 11:36 p.m. UTC
  From: Andi Kleen <ak@gcc.gnu.org>

- Fix warnings with newer python versions about bad escapes by
making all the python string raw.
- Add a fallback for using the builtin perf event list if the
CPU model number is unknown.
- Regenerate the shipped gcc-auto-profile with the changes.

contrib/ChangeLog:

	* gen_autofdo_event.py: Convert strings to raw.
	Add fallback to using builtin perf event list.

gcc/ChangeLog:

	* config/i386/gcc-auto-profile: Regenerate.
---
 contrib/gen_autofdo_event.py     | 36 ++++++++++++++++++--------------
 gcc/config/i386/gcc-auto-profile | 21 ++++++++++++-------
 2 files changed, 34 insertions(+), 23 deletions(-)
  

Comments

Eugene Rozenfeld Nov. 9, 2024, 3:39 a.m. UTC | #1
The patch looks good to me. Thank you for fixing this, Andi.

-----Original Message-----
From: Andi Kleen <ak@linux.intel.com> 
Sent: Thursday, October 31, 2024 4:37 PM
To: gcc-patches@gcc.gnu.org
Cc: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com>; Andi Kleen <ak@gcc.gnu.org>
Subject: [EXTERNAL] [PATCH] Update gcc-auto-profile / gen_autofdo_event.py

From: Andi Kleen <ak@gcc.gnu.org>

- Fix warnings with newer python versions about bad escapes by making all the python string raw.
- Add a fallback for using the builtin perf event list if the CPU model number is unknown.
- Regenerate the shipped gcc-auto-profile with the changes.

contrib/ChangeLog:

	* gen_autofdo_event.py: Convert strings to raw.
	Add fallback to using builtin perf event list.

gcc/ChangeLog:

	* config/i386/gcc-auto-profile: Regenerate.
---
 contrib/gen_autofdo_event.py     | 36 ++++++++++++++++++--------------
 gcc/config/i386/gcc-auto-profile | 21 ++++++++++++-------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/contrib/gen_autofdo_event.py b/contrib/gen_autofdo_event.py index 4c201943b5c7..4e58a5320fff 100755
--- a/contrib/gen_autofdo_event.py
+++ b/contrib/gen_autofdo_event.py
@@ -112,7 +112,7 @@ for j in u:
 u.close()
 
 if args.script:
-    print('''#!/bin/sh
+    print(r'''#!/bin/sh
 # Profile workload for gcc profile feedback (autofdo) using Linux perf.
 # Auto generated. To regenerate for new CPUs run  # contrib/gen_autofdo_event.py --script --all in gcc source @@ -152,22 +152,26 @@ case `grep -E -q "^cpu family\s*: 6" /proc/cpuinfo &&
     for event, mod in eventmap.items():
         for m in mod[:-1]:
             print("model*:\ %s|\\" % m)
-        print('model*:\ %s) E="%s$FLAGS" ;;' % (mod[-1], event))
-    print('''*)
+        print(r'model*:\ %s) E="%s$FLAGS" ;;' % (mod[-1], event))
+    print(r'''*)
+        if perf list br_inst_retired | grep -q br_inst_retired.near_taken ; then
+            E=br_inst_retired.near_taken:p
+        else
 echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script."
-	exit 1 ;;''')
-    print("esac")
-    print("set -x")
-    print('if ! perf record -e $E -b "$@" ; then')
-    print('  # PEBS may not actually be working even if the processor supports it')
-    print('  # (e.g., in a virtual machine). Trying to run without /p.')
-    print('  set +x')
-    print('  echo >&2 "Retrying without /p."')
-    print('  E="$(echo "${E}" | sed -e \'s/\/p/\//\')"')
-    print('  set -x')
-    print('  exec perf record -e $E -b "$@"')
-    print(' set +x')
-    print('fi')
+	  exit 1
+        fi ;;''')
+    print(r"esac")
+    print(r"set -x")
+    print(r'if ! perf record -e $E -b "$@" ; then')
+    print(r'  # PEBS may not actually be working even if the processor supports it')
+    print(r'  # (e.g., in a virtual machine). Trying to run without /p.')
+    print(r'  set +x')
+    print(r'  echo >&2 "Retrying without /p."')
+    print(r'  E="$(echo "${E}" | sed -e \'s/\/p/\//\ -e s/:p//)"')
+    print(r'  set -x')
+    print(r'  exec perf record -e $E -b "$@"')
+    print(r' set +x')
+    print(r'fi')
 
 if cpufound == 0 and not args.all:
     sys.exit('CPU %s not found' % cpu)
diff --git a/gcc/config/i386/gcc-auto-profile b/gcc/config/i386/gcc-auto-profile
index 04f7d35dcc51..528b34e42400 100755
--- a/gcc/config/i386/gcc-auto-profile
+++ b/gcc/config/i386/gcc-auto-profile
@@ -82,17 +82,24 @@ model*:\ 126|\
 model*:\ 167|\
 model*:\ 140|\
 model*:\ 141|\
-model*:\ 143|\
-model*:\ 207|\
 model*:\ 106|\
-model*:\ 108) E="cpu/event=0xc4,umask=0x20/p$FLAGS" ;;
+model*:\ 108|\
+model*:\ 173|\
+model*:\ 174) E="cpu/event=0xc4,umask=0x20/$FLAGS" ;;
 model*:\ 134|\
 model*:\ 150|\
-model*:\ 156|\
-model*:\ 190) E="cpu/event=0xc4,umask=0xfe/p$FLAGS" ;;
+model*:\ 156) E="cpu/event=0xc4,umask=0xfe/p$FLAGS" ;; model*:\ 143|\ 
+model*:\ 207) E="cpu/event=0xc4,umask=0x20/p$FLAGS" ;; model*:\ 190) 
+E="cpu/event=0xc4,umask=0xc0/$FLAGS" ;; model*:\ 190) 
+E="cpu/event=0xc4,umask=0xfe/$FLAGS" ;;
 *)
+        if perf list br_inst_retired | grep -q br_inst_retired.near_taken ; then
+            E=br_inst_retired.near_taken:p
+        else
 echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script."
-	exit 1 ;;
+	  exit 1
+        fi ;;
 esac
 set -x
 if ! perf record -e $E -b "$@" ; then
@@ -100,7 +107,7 @@ if ! perf record -e $E -b "$@" ; then
   # (e.g., in a virtual machine). Trying to run without /p.
   set +x
   echo >&2 "Retrying without /p."
-  E="$(echo "${E}" | sed -e 's/\/p/\//')"
+  E="$(echo "${E}" | sed -e \'s/\/p/\//\ -e s/:p//)"
   set -x
   exec perf record -e $E -b "$@"
  set +x
--
2.46.2
  

Patch

diff --git a/contrib/gen_autofdo_event.py b/contrib/gen_autofdo_event.py
index 4c201943b5c7..4e58a5320fff 100755
--- a/contrib/gen_autofdo_event.py
+++ b/contrib/gen_autofdo_event.py
@@ -112,7 +112,7 @@  for j in u:
 u.close()
 
 if args.script:
-    print('''#!/bin/sh
+    print(r'''#!/bin/sh
 # Profile workload for gcc profile feedback (autofdo) using Linux perf.
 # Auto generated. To regenerate for new CPUs run
 # contrib/gen_autofdo_event.py --script --all in gcc source
@@ -152,22 +152,26 @@  case `grep -E -q "^cpu family\s*: 6" /proc/cpuinfo &&
     for event, mod in eventmap.items():
         for m in mod[:-1]:
             print("model*:\ %s|\\" % m)
-        print('model*:\ %s) E="%s$FLAGS" ;;' % (mod[-1], event))
-    print('''*)
+        print(r'model*:\ %s) E="%s$FLAGS" ;;' % (mod[-1], event))
+    print(r'''*)
+        if perf list br_inst_retired | grep -q br_inst_retired.near_taken ; then
+            E=br_inst_retired.near_taken:p
+        else
 echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script."
-	exit 1 ;;''')
-    print("esac")
-    print("set -x")
-    print('if ! perf record -e $E -b "$@" ; then')
-    print('  # PEBS may not actually be working even if the processor supports it')
-    print('  # (e.g., in a virtual machine). Trying to run without /p.')
-    print('  set +x')
-    print('  echo >&2 "Retrying without /p."')
-    print('  E="$(echo "${E}" | sed -e \'s/\/p/\//\')"')
-    print('  set -x')
-    print('  exec perf record -e $E -b "$@"')
-    print(' set +x')
-    print('fi')
+	  exit 1
+        fi ;;''')
+    print(r"esac")
+    print(r"set -x")
+    print(r'if ! perf record -e $E -b "$@" ; then')
+    print(r'  # PEBS may not actually be working even if the processor supports it')
+    print(r'  # (e.g., in a virtual machine). Trying to run without /p.')
+    print(r'  set +x')
+    print(r'  echo >&2 "Retrying without /p."')
+    print(r'  E="$(echo "${E}" | sed -e \'s/\/p/\//\ -e s/:p//)"')
+    print(r'  set -x')
+    print(r'  exec perf record -e $E -b "$@"')
+    print(r' set +x')
+    print(r'fi')
 
 if cpufound == 0 and not args.all:
     sys.exit('CPU %s not found' % cpu)
diff --git a/gcc/config/i386/gcc-auto-profile b/gcc/config/i386/gcc-auto-profile
index 04f7d35dcc51..528b34e42400 100755
--- a/gcc/config/i386/gcc-auto-profile
+++ b/gcc/config/i386/gcc-auto-profile
@@ -82,17 +82,24 @@  model*:\ 126|\
 model*:\ 167|\
 model*:\ 140|\
 model*:\ 141|\
-model*:\ 143|\
-model*:\ 207|\
 model*:\ 106|\
-model*:\ 108) E="cpu/event=0xc4,umask=0x20/p$FLAGS" ;;
+model*:\ 108|\
+model*:\ 173|\
+model*:\ 174) E="cpu/event=0xc4,umask=0x20/$FLAGS" ;;
 model*:\ 134|\
 model*:\ 150|\
-model*:\ 156|\
-model*:\ 190) E="cpu/event=0xc4,umask=0xfe/p$FLAGS" ;;
+model*:\ 156) E="cpu/event=0xc4,umask=0xfe/p$FLAGS" ;;
+model*:\ 143|\
+model*:\ 207) E="cpu/event=0xc4,umask=0x20/p$FLAGS" ;;
+model*:\ 190) E="cpu/event=0xc4,umask=0xc0/$FLAGS" ;;
+model*:\ 190) E="cpu/event=0xc4,umask=0xfe/$FLAGS" ;;
 *)
+        if perf list br_inst_retired | grep -q br_inst_retired.near_taken ; then
+            E=br_inst_retired.near_taken:p
+        else
 echo >&2 "Unknown CPU. Run contrib/gen_autofdo_event.py --all --script to update script."
-	exit 1 ;;
+	  exit 1
+        fi ;;
 esac
 set -x
 if ! perf record -e $E -b "$@" ; then
@@ -100,7 +107,7 @@  if ! perf record -e $E -b "$@" ; then
   # (e.g., in a virtual machine). Trying to run without /p.
   set +x
   echo >&2 "Retrying without /p."
-  E="$(echo "${E}" | sed -e 's/\/p/\//')"
+  E="$(echo "${E}" | sed -e \'s/\/p/\//\ -e s/:p//)"
   set -x
   exec perf record -e $E -b "$@"
  set +x