Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently prefer sysfs/json events #878

Closed
wants to merge 16 commits into from

Commits on Apr 16, 2024

  1. perf parse-events: Factor out '<event_or_pmu>/.../' parsing

    Factor out the case of an event or PMU name followed by a slash based
    term list. This is with a view to sharing the code with new legacy
    hardware parsing. Use early return to reduce indentation in the code.
    Make parse_events_add_pmu static now it doesn't need sharing with
    parse-events.y.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    8554ddb View commit details
    Browse the repository at this point in the history
  2. perf parse-events: Directly pass PMU to parse_events_add_pmu

    Avoid passing the name of a PMU then finding it again, just directly
    pass the PMU. parse_events_multi_pmu_add_or_add_pmu is the only
    version that needs to find a PMU, so move the find there. Remove the
    error message as parse_events_multi_pmu_add_or_add_pmu will given an
    error at the end when a name isn't either a PMU name or event
    name. Without the error message being created the location in the
    input parameter (loc) can be removed.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    cf782ea View commit details
    Browse the repository at this point in the history
  3. perf parse-events: Avoid copying an empty list

    In parse_events_add_pmu, delay copying the list of terms until it is
    known the list contains terms.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    d83931e View commit details
    Browse the repository at this point in the history
  4. perf pmu: Refactor perf_pmu__match

    Move all implementation to pmu code. Don't allocate a fnmatch wildcard
    pattern, matching ignoring the suffix already handles this, and only
    use fnmatch if the given PMU name has a '*' in it.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    1f8829e View commit details
    Browse the repository at this point in the history
  5. perf tests parse-events: Use branches rather than cache-references

    Switch from cache-references to branches in test as Intel has a sysfs
    event for cache-references and changing the priority for sysfs over
    legacy causes the test to fail.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    f85bce3 View commit details
    Browse the repository at this point in the history
  6. perf parse-events: Legacy cache names on all PMUs and lower priority

    Prior behavior is to not look for legacy cache names in sysfs/json and
    to create events on all core PMUs. New behavior is to look for
    sysfs/json events first on all PMUs, for core PMUs add a legacy event
    if the sysfs/json event isn't present.
    
    This is done so that there is consistency with how event names in
    terms are handled and their prioritization of sysfs/json over
    legacy. It may make sense to use a legacy cache event name as an event
    name on a non-core PMU so we should allow it.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    1df3dcb View commit details
    Browse the repository at this point in the history
  7. perf parse-events: Handle PE_TERM_HW in name_or_raw

    Avoid duplicate logic for name_or_raw and PE_TERM_HW by having a rule
    to turn PE_TERM_HW into a name_or_raw.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    1029687 View commit details
    Browse the repository at this point in the history
  8. perf parse-events: Constify parse_events_add_numeric

    Allow the term list to be const so that other functions can pass const
    term lists. Add const as necessary to called functions.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    b0992fd View commit details
    Browse the repository at this point in the history
  9. perf parse-events: Prefer sysfs/json hardware events over legacy

    It was requested that RISC-V be able to add events to the perf tool so
    the PMU driver didn't need to map legacy events to config encodings:
    https://lore.kernel.org/lkml/20240217005738.3744121-1-atishp@rivosinc.com/
    
    This change makes the priority of events specified without a PMU the
    same as those specified with a PMU, namely sysfs and json events are
    checked first before using the legacy encoding.
    
    The hw_term is made more generic as a hardware_event that encodes a
    pair of string and int value, allowing parse_events_multi_pmu_add to
    fall back on a known encoding when the sysfs/json adding fails for
    core events. As this covers PE_VALUE_SYM_HW, that token is removed and
    related code simplified.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    f74a903 View commit details
    Browse the repository at this point in the history
  10. perf parse-events: Inline parse_events_update_lists

    The helper function just wraps a splice and free. Making the free
    inline removes a comment, so then it just wraps a splice which we can
    make inline too.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    873deeb View commit details
    Browse the repository at this point in the history
  11. perf parse-events: Improve error message for bad numbers

    Use the error handler from the parse_state to give a more informative
    error message.
    
    Before:
    ```
    $ perf stat -e 'cycles/period=99999999999999999999/' true
    event syntax error: 'cycles/period=99999999999999999999/'
                                      \___ parser error
    Run 'perf list' for a list of valid events
    
     Usage: perf stat [<options>] [<command>]
    
        -e, --event <event>   event selector. use 'perf list' to list available events
    ```
    
    After:
    ```
    $ perf stat -e 'cycles/period=99999999999999999999/' true
    event syntax error: 'cycles/period=99999999999999999999/'
                                      \___ parser error
    
    event syntax error: '..les/period=99999999999999999999/'
                                      \___ Bad base 10 number "99999999999999999999"
    Run 'perf list' for a list of valid events
    
     Usage: perf stat [<options>] [<command>]
    
        -e, --event <event>   event selector. use 'perf list' to list available events
    ```
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    362e67e View commit details
    Browse the repository at this point in the history
  12. perf parse-events: Inline parse_events_evlist_error

    Inline parse_events_evlist_error that is only used in
    parse_events_error. Modify parse_events_error to not report a parser
    error unless errors haven't already been reported. Make it clearer
    that the latter case only happens for unrecognized input.
    
    Before:
    ```
    $ perf stat -e 'cycles/period=99999999999999999999/' true
    event syntax error: 'cycles/period=99999999999999999999/'
                                      \___ parser error
    
    event syntax error: '..les/period=99999999999999999999/'
                                      \___ Bad base 10 number "99999999999999999999"
    Run 'perf list' for a list of valid events
    
     Usage: perf stat [<options>] [<command>]
    
        -e, --event <event>   event selector. use 'perf list' to list available events
    $ perf stat -e 'cycles:xyz' true
    event syntax error: 'cycles:xyz'
                               \___ parser error
    Run 'perf list' for a list of valid events
    
     Usage: perf stat [<options>] [<command>]
    
        -e, --event <event>   event selector. use 'perf list' to list available events
    ```
    
    After:
    ```
    $ perf stat -e 'cycles/period=99999999999999999999/xyz' true
    event syntax error: '..les/period=99999999999999999999/xyz'
                                      \___ Bad base 10 number "99999999999999999999"
    Run 'perf list' for a list of valid events
    
     Usage: perf stat [<options>] [<command>]
    
        -e, --event <event>   event selector. use 'perf list' to list available events
    $ perf stat -e 'cycles:xyz' true
    event syntax error: 'cycles:xyz'
                               \___ Unrecognized input
    Run 'perf list' for a list of valid events
    
     Usage: perf stat [<options>] [<command>]
    
        -e, --event <event>   event selector. use 'perf list' to list available events
    ```
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    cd0fbdf View commit details
    Browse the repository at this point in the history
  13. perf parse-events: Improvements to modifier parsing

    Use a struct/bitmap rather than a copied string from lexer.
    
    In lexer give improved error message when too many precise flags are
    given or repeated modifiers.
    
    Before:
    ```
    $ perf stat -e 'cycles:kuk' true
    event syntax error: 'cycles:kuk'
                                \___ Bad modifier
    ...
    $ perf stat -e 'cycles:pppp' true
    event syntax error: 'cycles:pppp'
                                \___ Bad modifier
    ...
    $ perf stat -e '{instructions:p,cycles:pp}:pp' -a true
    event syntax error: '..cycles:pp}:pp'
                                      \___ Bad modifier
    ...
    ```
    After:
    ```
    $ perf stat -e 'cycles:kuk' true
    event syntax error: 'cycles:kuk'
                                  \___ Duplicate modifier 'k' (kernel)
    ...
    $ perf stat -e 'cycles:pppp' true
    event syntax error: 'cycles:pppp'
                                   \___ Maximum precise value is 3
    ...
    $ perf stat -e '{instructions:p,cycles:pp}:pp' true
    event syntax error: '..cycles:pp}:pp'
                                      \___ Maximum combined precise value is 3, adding precision to "cycles:pp"
    ...
    ```
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    1984ded View commit details
    Browse the repository at this point in the history
  14. perf parse-event: Constify event_symbol arrays

    Moves 352 bytes from .data to .data.rel.ro.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    11ce57a View commit details
    Browse the repository at this point in the history
  15. perf parse-events: Minor grouping tidy up

    Add comments. Ensure leader->group_name is freed before overwriting
    it.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    1f3611a View commit details
    Browse the repository at this point in the history
  16. perf parse-events: Tidy the setting of the default event name

    Add comments. Pass ownership of the event name to save on a strdup.
    
    Signed-off-by: Ian Rogers <irogers@google.com>
    Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
    captain5050 authored and Björn Töpel committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    15a8cde View commit details
    Browse the repository at this point in the history