Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf jevents: Sort strings in the big C string to reduce faults

Sort the strings within the big C string based on whether they were
for a metric and then by when they were added. This helps group
related strings and reduce minor faults by approximately 10 in 1740,
about 0.57%.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20230824041330.266337-18-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
f85d120c 8d4b6d37

+23 -8
+23 -8
tools/perf/pmu-events/jevents.py
··· 113 113 strings: Set[str] 114 114 big_string: Sequence[str] 115 115 offsets: Dict[str, int] 116 + insert_number: int 117 + insert_point: Dict[str, int] 118 + metrics: Set[str] 116 119 117 120 def __init__(self): 118 121 self.strings = set() 122 + self.insert_number = 0; 123 + self.insert_point = {} 124 + self.metrics = set() 119 125 120 - def add(self, s: str) -> None: 126 + def add(self, s: str, metric: bool) -> None: 121 127 """Called to add to the big string.""" 122 - self.strings.add(s) 128 + if s not in self.strings: 129 + self.strings.add(s) 130 + self.insert_point[s] = self.insert_number 131 + self.insert_number += 1 132 + if metric: 133 + self.metrics.add(s) 123 134 124 135 def compute(self) -> None: 125 136 """Called once all strings are added to compute the string and offsets.""" ··· 171 160 self.big_string = [] 172 161 self.offsets = {} 173 162 163 + def string_cmp_key(s: str) -> Tuple[bool, int, str]: 164 + return (s in self.metrics, self.insert_point[s], s) 165 + 174 166 # Emit all strings that aren't folded in a sorted manner. 175 - for s in sorted(self.strings): 167 + for s in sorted(self.strings, key=string_cmp_key): 176 168 if s not in folded_strings: 177 169 self.offsets[s] = big_string_offset 178 170 self.big_string.append(f'/* offset={big_string_offset} */ "') ··· 588 574 assert len(mgroup) > 1, parents 589 575 description = f"{metricgroup_descriptions[mgroup]}\\000" 590 576 mgroup = f"{mgroup}\\000" 591 - _bcs.add(mgroup) 592 - _bcs.add(description) 577 + _bcs.add(mgroup, metric=True) 578 + _bcs.add(description, metric=True) 593 579 _metricgroups[mgroup] = description 594 580 return 595 581 596 582 topic = get_topic(item.name) 597 583 for event in read_json_events(item.path, topic): 598 584 pmu_name = f"{event.pmu}\\000" 599 - _bcs.add(pmu_name) 600 585 if event.name: 601 - _bcs.add(event.build_c_string(metric=False)) 586 + _bcs.add(pmu_name, metric=False) 587 + _bcs.add(event.build_c_string(metric=False), metric=False) 602 588 if event.metric_name: 603 - _bcs.add(event.build_c_string(metric=True)) 589 + _bcs.add(pmu_name, metric=True) 590 + _bcs.add(event.build_c_string(metric=True), metric=True) 604 591 605 592 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: 606 593 """Process a JSON file during the main walk."""