From: Andi Kleen <[email protected]>
- Add --inherit to the generation script too (even though it's probably
only needed on ARM)
- Support hybrid CPUs correctly
- Always use a sample after value to make profiling more stable
- Fix the error messages to suggest updating perf in fallback mode
- Use PEBS more consistently
- Regenerate the script
contrib/ChangeLog:
* gen_autofdo_event.py: Support hybrid. Improve error messages.
Add periods by default. Add --inherit. Use PEBS more.
gcc/ChangeLog:
* config/i386/gcc-auto-profile: Regenerate.
---
contrib/gen_autofdo_event.py | 43 ++++++++++++++++++++++++--------
gcc/config/i386/gcc-auto-profile | 38 ++++++++++++++++++++--------
2 files changed, 61 insertions(+), 20 deletions(-)
diff --git a/contrib/gen_autofdo_event.py b/contrib/gen_autofdo_event.py
index 1fcea0a6d63..a742132c604 100755
--- a/contrib/gen_autofdo_event.py
+++ b/contrib/gen_autofdo_event.py
@@ -47,6 +47,7 @@ ap.add_argument('--script', help='Generate shell script',
action='store_true')
args = ap.parse_args()
eventmap = collections.defaultdict(list)
+eventmod = dict()
def get_cpustr():
cpuinfo = os.getenv("CPUINFO")
@@ -72,23 +73,35 @@ def get_cpustr():
return "%s-%d-%X-%X" % tuple(cpu)
return "%s-%d-%X" % tuple(cpu)[:3]
-def find_event(eventurl, model):
+def find_event(eventurl, model, hybrid, htype):
print("Downloading", eventurl, file = sys.stderr)
u = urllib.request.urlopen(eventurl)
events = json.loads(u.read())["Events"]
u.close()
+ def gen_event(pmu, j):
+ return "%s/event=%s,umask=%s,period=%s/%s" % (htype, j['EventCode'],
j['UMask'],
+ j["SampleAfterValue"],
+ "p" if "Precise" in j and j["Precise"] ==
"1" else "")
+
found = 0
for j in events:
if j['EventName'] in target_events:
- event = "cpu/event=%s,umask=%s/" % (j['EventCode'], j['UMask'])
- if 'PEBS' in j and int(j['PEBS']) > 0:
- event += "p"
+ if hybrid and htype != "cpu":
+ event = gen_event(htype, j)
+ if model in eventmod:
+ event = eventmod[model] + "$FLAGS," + event
+ else:
+ eventmod[model] = event
+ return 1 # will be added later for the other core type
+ else:
+ event = gen_event("cpu", j)
if args.script:
eventmap[event].append(model)
else:
print(j['EventName'], "event for model", model, "is", event)
found += 1
+ break
return found
if not args.all:
@@ -103,12 +116,17 @@ found = 0
cpufound = 0
for j in u:
n = j.rstrip().decode().split(',')
- if len(n) >= 4 and (args.all or fnmatch.fnmatch(cpu, n[0])) and n[3] ==
"core":
+ if len(n) >= 4 and (args.all or fnmatch.fnmatch(cpu, n[0])) and n[3] in
("core", "hybridcore"):
components = n[0].split("-")
model = components[2]
model = int(model, 16)
cpufound += 1
- found += find_event(baseurl + n[2], model)
+ htype = "cpu"
+ if len(n) >= 7 and n[6]:
+ if n[6] not in ("Core", "Atom"):
+ continue
+ htype = "cpu_" + n[6].lower()
+ found += find_event(baseurl + n[2], model, n[3] == "hybridcore", htype)
u.close()
if args.script:
@@ -163,11 +181,16 @@ case `test $vendor = Intel && grep -E -q "^cpu family\s*:
6" /proc/cpuinfo &&
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
+ if [ -r /sys/devices/cpu_core -a -r /sys/devices/cpu_atom ] ; then
+
E=cpu_core/br_inst_retired.near_taken/p$FLAGS,cpu_atom/br_inst_retired.near_taken/p$FLAGS
+ else
+ E=br_inst_retired.near_taken:p
+ fi
elif perf list ex_ret_brn_tkn | grep -q ex_ret_brn_tkn ; then
E=ex_ret_brn_tkn:P$FLAGS
elif $vendor = Intel ; then
-echo >&2 "Unknown Intel CPU. Run contrib/gen_autofdo_event.py --all --script
to update script."
+echo >&2 "Unknown Intel CPU. Run gccsource/contrib/gen_autofdo_event.py --all
--script to update script"
+echo >&2 "or update Linux perf version to version supporting this CPU."
exit 1
else
echo >&2 "AMD CPU without support for ex_ret_brn_tkn event"
@@ -175,14 +198,14 @@ echo >&2 "AMD CPU without support for ex_ret_brn_tkn
event"
fi ;;''')
print(r"esac")
print(r"set -x")
- print(r'if ! perf record -e $E -b "$@" ; then')
+ print(r'if ! perf record --inherit -o perf.data -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' exec perf record --inherit -o perf.data -e $E -b "$@"')
print(r' set +x')
print(r'fi')
diff --git a/gcc/config/i386/gcc-auto-profile b/gcc/config/i386/gcc-auto-profile
index c7772a2800f..bd78ad1962e 100755
--- a/gcc/config/i386/gcc-auto-profile
+++ b/gcc/config/i386/gcc-auto-profile
@@ -49,7 +49,7 @@ model*:\ 31|\
model*:\ 26|\
model*:\ 47|\
model*:\ 37|\
-model*:\ 44) E="cpu/event=0x88,umask=0x40/$FLAGS" ;;
+model*:\ 44) E="cpu/event=0x88,umask=0x40,period=200000/$FLAGS" ;;
model*:\ 55|\
model*:\ 74|\
model*:\ 77|\
@@ -59,12 +59,12 @@ model*:\ 92|\
model*:\ 95|\
model*:\ 87|\
model*:\ 133|\
-model*:\ 122) E="cpu/event=0xC4,umask=0xFE/p$FLAGS" ;;
+model*:\ 122) E="cpu/event=0xC4,umask=0xFE,period=200003/$FLAGS" ;;
model*:\ 28|\
model*:\ 38|\
model*:\ 39|\
model*:\ 54|\
-model*:\ 53) E="cpu/event=0x88,umask=0x41/$FLAGS" ;;
+model*:\ 53) E="cpu/event=0x88,umask=0x41,period=2000000/$FLAGS" ;;
model*:\ 42|\
model*:\ 45|\
model*:\ 58|\
@@ -84,7 +84,7 @@ model*:\ 158|\
model*:\ 165|\
model*:\ 166|\
model*:\ 85|\
-model*:\ 85) E="cpu/event=0xC4,umask=0x20/p$FLAGS" ;;
+model*:\ 85) E="cpu/event=0xC4,umask=0x20,period=400009/$FLAGS" ;;
model*:\ 125|\
model*:\ 126|\
model*:\ 167|\
@@ -95,21 +95,39 @@ model*:\ 207|\
model*:\ 106|\
model*:\ 108|\
model*:\ 173|\
-model*:\ 174) E="cpu/event=0xc4,umask=0x20/$FLAGS" ;;
+model*:\ 174) E="cpu/event=0xc4,umask=0x20,period=400009/p$FLAGS" ;;
model*:\ 134|\
model*:\ 150|\
-model*:\ 156) E="cpu/event=0xc4,umask=0xfe/p$FLAGS" ;;
+model*:\ 156) E="cpu/event=0xc4,umask=0xfe,period=200003/$FLAGS" ;;
+model*:\ 151|\
+model*:\ 154|\
+model*:\ 183|\
+model*:\ 186|\
+model*:\ 191|\
+model*:\ 170|\
+model*:\ 172|\
+model*:\ 181|\
+model*:\ 189|\
+model*:\ 197|\
+model*:\ 198)
E="cpu_atom/event=0xc4,umask=0xc0,period=200003/p$FLAGS,cpu_core/event=0xc4,umask=0x20,period=400009/p$FLAGS"
;;
model*:\ 190|\
model*:\ 175|\
-model*:\ 182) E="cpu/event=0xc4,umask=0xc0/$FLAGS" ;;
-model*:\ 190) E="cpu/event=0xc4,umask=0xfe/$FLAGS" ;;
+model*:\ 182) E="cpu/event=0xc4,umask=0xc0,period=200003/p$FLAGS" ;;
+model*:\ 204|\
+model*:\ 213)
E="cpu_atom/event=0xc4,umask=0xfb,period=1000003/p$FLAGS,cpu_core/event=0xc4,umask=0xfb,period=400009/p$FLAGS"
;;
+model*:\ 221) E="cpu/event=0xc4,umask=0xfb,period=1000003/p$FLAGS" ;;
*)
if perf list br_inst_retired | grep -q br_inst_retired.near_taken ;
then
- E=br_inst_retired.near_taken:p
+ if [ -r /sys/devices/cpu_core -a -r /sys/devices/cpu_atom ] ; then
+
E=cpu_core/br_inst_retired.near_taken/p$FLAGS,cpu_atom/br_inst_retired.near_taken/p$FLAGS
+ else
+ E=br_inst_retired.near_taken:p
+ fi
elif perf list ex_ret_brn_tkn | grep -q ex_ret_brn_tkn ; then
E=ex_ret_brn_tkn:P$FLAGS
elif $vendor = Intel ; then
-echo >&2 "Unknown Intel CPU. Run contrib/gen_autofdo_event.py --all --script
to update script."
+echo >&2 "Unknown Intel CPU. Run gccsource/contrib/gen_autofdo_event.py --all
--script to update script"
+echo >&2 "or update Linux perf version to version supporting this CPU."
exit 1
else
echo >&2 "AMD CPU without support for ex_ret_brn_tkn event"
--
2.54.0