Skip to content

Commit 5a49279

Browse files
authored
refactor uncore event collection and handling (#462)
* don't adjust core c6 residency event if in cpu granularity Signed-off-by: Harper, Jason M <jason.m.harper@intel.com> * don't expand uncore events Signed-off-by: Harper, Jason M <jason.m.harper@intel.com> * refactor: optimize uncore event aggregation in bucketed events Signed-off-by: Harper, Jason M <jason.m.harper@intel.com> * manual merge Signed-off-by: Harper, Jason M <jason.m.harper@intel.com> --------- Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
1 parent a8c830a commit 5a49279

File tree

4 files changed

+123
-275
lines changed

4 files changed

+123
-275
lines changed

cmd/metrics/event_defs.go

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"log/slog"
1313
"os"
1414
"path/filepath"
15-
"regexp"
16-
"slices"
1715
"strings"
1816

1917
mapset "github.com/deckarep/golang-set/v2"
@@ -73,9 +71,7 @@ func LoadEventGroups(eventDefinitionOverridePath string, metadata Metadata) (gro
7371
if event, err = parseEventDefinition(line[:len(line)-1]); err != nil {
7472
return
7573
}
76-
// abbreviate the event name to shorten the eventual perf stat command line
77-
event.Name = abbreviateEventName(event.Name)
78-
event.Raw = abbreviateEventName(event.Raw)
74+
// check if the event is collectable
7975
if isCollectableEvent(event, metadata) {
8076
group = append(group, event)
8177
} else {
@@ -95,47 +91,13 @@ func LoadEventGroups(eventDefinitionOverridePath string, metadata Metadata) (gro
9591
return
9692
}
9793
uncollectableEvents = uncollectable.ToSlice()
98-
// expand uncore groups for all uncore devices
99-
groups, err = expandUncoreGroups(groups, metadata)
10094

10195
if uncollectable.Cardinality() != 0 {
10296
slog.Debug("Events not collectable on target", slog.String("events", uncollectable.String()))
10397
}
10498
return
10599
}
106100

107-
// abbreviateEventName replaces long event names with abbreviations to reduce the length of the perf command.
108-
// focus is on uncore events because they are repeated for each uncore device
109-
func abbreviateEventName(event string) string {
110-
// Abbreviations must be unique and in order. And, if replacing UNC_*, the abbreviation must begin with "UNC" because this is how we identify uncore events when collapsing them.
111-
var abbreviations = [][]string{
112-
{"UNC_CHA_TOR_INSERTS", "UNCCTI"},
113-
{"UNC_CHA_TOR_OCCUPANCY", "UNCCTO"},
114-
{"UNC_CHA_CLOCKTICKS", "UNCCCT"},
115-
{"UNC_M_CAS_COUNT_SCH", "UNCMCC"},
116-
{"IA_MISS_DRD_REMOTE", "IMDR"},
117-
{"IA_MISS_DRD_LOCAL", "IMDL"},
118-
{"IA_MISS_LLCPREFDATA", "IMLP"},
119-
{"IA_MISS_LLCPREFRFO", "IMLR"},
120-
{"IA_MISS_DRD_PREF_LOCAL", "IMDPL"},
121-
{"IA_MISS_DRD_PREF_REMOTE", "IMDRP"},
122-
{"IA_MISS_CRD_PREF", "IMCP"},
123-
{"IA_MISS_RFO_PREF", "IMRP"},
124-
{"IA_MISS_RFO", "IMRF"},
125-
{"IA_MISS_CRD", "IMC"},
126-
{"IA_MISS_DRD", "IMD"},
127-
{"IO_PCIRDCUR", "IPCI"},
128-
{"IO_ITOMCACHENEAR", "IITN"},
129-
{"IO_ITOM", "IITO"},
130-
{"IMD_OPT", "IMDO"},
131-
}
132-
// if an abbreviation key is found in the event, replace the matching portion of the event with the abbreviation
133-
for _, abbr := range abbreviations {
134-
event = strings.Replace(event, abbr[0], abbr[1], -1)
135-
}
136-
return event
137-
}
138-
139101
// isCollectableEvent confirms if given event can be collected on the platform
140102
func isCollectableEvent(event EventDefinition, metadata Metadata) bool {
141103
// fixed-counter TMA
@@ -250,61 +212,3 @@ func parseEventDefinition(line string) (eventDef EventDefinition, err error) {
250212
}
251213
return
252214
}
253-
254-
// expandUncoreGroup expands a perf event group into a list of groups where each group is
255-
// associated with an uncore device
256-
func expandUncoreGroup(group GroupDefinition, ids []int, re *regexp.Regexp, vendor string) (groups []GroupDefinition, err error) {
257-
for _, deviceID := range ids {
258-
var newGroup GroupDefinition
259-
for _, event := range group {
260-
match := re.FindStringSubmatch(event.Raw)
261-
if len(match) == 0 {
262-
err = fmt.Errorf("unexpected raw event format: %s", event.Raw)
263-
return
264-
}
265-
var newEvent EventDefinition
266-
if vendor == "AuthenticAMD" {
267-
newEvent.Name = match[4]
268-
newEvent.Raw = fmt.Sprintf("amd_%s/event=%s,umask=%s,name='%s'/", match[1], match[2], match[3], newEvent.Name)
269-
} else {
270-
newEvent.Name = fmt.Sprintf("%s.%d", match[4], deviceID)
271-
newEvent.Raw = fmt.Sprintf("uncore_%s_%d/event=%s,umask=%s,name='%s'/", match[1], deviceID, match[2], match[3], newEvent.Name)
272-
}
273-
newEvent.Device = event.Device
274-
newGroup = append(newGroup, newEvent)
275-
}
276-
groups = append(groups, newGroup)
277-
}
278-
return
279-
}
280-
281-
// expandUncoreGroups expands groups with uncore events to include events for all uncore devices
282-
// assumes that uncore device events are in their own groups, not mixed with other device types
283-
func expandUncoreGroups(groups []GroupDefinition, metadata Metadata) (expandedGroups []GroupDefinition, err error) {
284-
// example 1: cha/event=0x35,umask=0xc80ffe01,name='UNC_CHA_TOR_INSERTS.IA_MISS_CRD'/,
285-
// expand to: uncore_cha_0/event=0x35,umask=0xc80ffe01,name='UNC_CHA_TOR_INSERTS.IA_MISS_CRD.0'/,
286-
// example 2: cha/event=0x36,umask=0x21,config1=0x4043300000000,name='UNC_CHA_TOR_OCCUPANCY.IA_MISS.0x40433'/
287-
// expand to: uncore_cha_0/event=0x36,umask=0x21,config1=0x4043300000000,name='UNC_CHA_TOR_OCCUPANCY.IA_MISS.0x40433'/
288-
re := regexp.MustCompile(`(\w+)/event=(0x[0-9,a-f,A-F]+),umask=(0x[0-9,a-f,A-F]+.*),name='(.*)'`)
289-
var deviceTypes []string
290-
for deviceType := range metadata.UncoreDeviceIDs {
291-
deviceTypes = append(deviceTypes, deviceType)
292-
}
293-
for _, group := range groups {
294-
device := group[0].Device
295-
if slices.Contains(deviceTypes, device) {
296-
var newGroups []GroupDefinition
297-
if len(metadata.UncoreDeviceIDs[device]) == 0 {
298-
slog.Warn("No uncore devices found", slog.String("type", device))
299-
continue
300-
}
301-
if newGroups, err = expandUncoreGroup(group, metadata.UncoreDeviceIDs[device], re, metadata.Vendor); err != nil {
302-
return
303-
}
304-
expandedGroups = append(expandedGroups, newGroups...)
305-
} else {
306-
expandedGroups = append(expandedGroups, group)
307-
}
308-
}
309-
return
310-
}

0 commit comments

Comments
 (0)