From: John Garry Date: Mon, 7 Aug 2023 11:16:31 +0000 (+0000) Subject: perf jevents: Raise exception for no definition of a arch std event X-Git-Tag: v6.6.17~3940^2~70 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7298e876075eea8d2e782bf846ab0b4721afac92;p=platform%2Fkernel%2Flinux-rpi.git perf jevents: Raise exception for no definition of a arch std event Recently Ilkka reported that the JSONs for the AmpereOne arm64-based platform included a dud event which referenced a non-existent arch std event [0]. Previously in the times of jevents.c, we would raise an exception for this. This is still invalid, even though the current code just ignores such an event. Re-introduce code to raise an exception for when no definition exists to help catch as many invalid JSONs as possible. [0] https://lore.kernel.org/linux-perf-users/9e851e2a-26c7-ba78-cb20-be4337b2916a@oracle.com/ Reviewed-by: Ian Rogers Signed-off-by: John Garry Tested-by: Ilkka Koskinen Link: https://lore.kernel.org/r/20230807111631.3033102-1-john.g.garry@oracle.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 8cd561a..98cccc3 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -347,12 +347,15 @@ class JsonEvent: if self.desc and not self.desc.endswith('. '): self.desc += '. ' self.desc = (self.desc if self.desc else '') + ('Unit: ' + self.pmu + ' ') - if arch_std and arch_std.lower() in _arch_std_events: - event = _arch_std_events[arch_std.lower()].event - # Copy from the architecture standard event to self for undefined fields. - for attr, value in _arch_std_events[arch_std.lower()].__dict__.items(): - if hasattr(self, attr) and not getattr(self, attr): - setattr(self, attr, value) + if arch_std: + if arch_std.lower() in _arch_std_events: + event = _arch_std_events[arch_std.lower()].event + # Copy from the architecture standard event to self for undefined fields. + for attr, value in _arch_std_events[arch_std.lower()].__dict__.items(): + if hasattr(self, attr) and not getattr(self, attr): + setattr(self, attr, value) + else: + raise argparse.ArgumentTypeError('Cannot find arch std event:', arch_std) self.event = real_event(self.name, event)