• Ian Rogers's avatar
    perf parse-events: Avoid scanning PMUs before parsing · 70c90e4a
    Ian Rogers authored
    The event parser needs to handle two special cases:
    1) legacy events like L1-dcache-load-miss. These event names don't
       appear in JSON or sysfs, and lookup tables are used for the config
       value.
    2) raw events where 'r0xead' is the same as 'read' unless the PMU has
       an event called 'read' in which case the event has priority.
    
    The previous parser to handle these cases would scan all PMUs for
    components of event names. These components would then be used to
    classify in the lexer whether the token should be part of a legacy
    event, a raw event or an event. The grammar would handle legacy event
    tokens or recombining the tokens back into a regular event name.  The
    code wasn't PMU specific and had issues around events like AMD's
    branch-brs that would fail to parse as it expects brs to be a suffix
    on a legacy event style name:
    
    $ perf stat -e branch-brs true
    event syntax error: 'branch-brs'
                               \___ parser error
    
    This change removes processing all PMUs by using the lexer in the form
    of a regular expression matcher. The lexer will return the token for
    the longest matched sequence of characters, and in the event of a tie
    the first. The legacy events are a fixed number of regular
    expressions, and by matching these before a name token its possible to
    generate an accurate legacy event token with everything else matching
    as a name. Because of the lexer change the handling of hyphens in the
    grammar can be removed as hyphens just become a part of the name.
    
    To handle raw events and terms the parser is changed to defer trying
    to evaluate whether something is a raw event until the PMU is known in
    the grammar. Once the PMU is known, the events of the PMU can be
    scanned for the 'read' style problem. A new term type is added for
    these raw terms, used to enable deferring the evaluation.
    
    While this change is large, it has stats of:
    170 insertions(+), 436 deletions(-)
    the bulk of the change is deleting the old approach. It isn't possible
    to break apart the code added due to the dependencies on how the parts
    of the parsing work.
    Signed-off-by: default avatarIan Rogers <irogers@google.com>
    Tested-by: default avatarKan Liang <kan.liang@linux.intel.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ahmad Yasin <ahmad.yasin@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Caleb Biggers <caleb.biggers@intel.com>
    Cc: Edward Baker <edward.baker@intel.com>
    Cc: Florian Fischer <florian.fischer@muhq.space>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Kajol Jain <kjain@linux.ibm.com>
    Cc: Kang Minchul <tegongkang@gmail.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Perry Taylor <perry.taylor@intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Samantha Alt <samantha.alt@intel.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Weilin Wang <weilin.wang@intel.com>
    Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Link: https://lore.kernel.org/r/20230502223851.2234828-19-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    70c90e4a
parse-events.h 7.57 KB