• Alexey Brodkin's avatar
    ARCv2: perf: implement "event_set_period" · 1fe8bfa5
    Alexey Brodkin authored
    This generalization prepares for support of overflow interrupts.
    
    Hardware event counters on ARC work that way:
    Each counter counts from programmed start value (set in
    ARC_REG_PCT_COUNT) to a limit value (set in ARC_REG_PCT_INT_CNT) and
    once limit value is reached this timer generates an interrupt.
    
    Even though this hardware implementation allows for more flexibility,
    in Linux kernel we decided to mimic behavior of other architectures
    this way:
    
     [1] Set limit value as half of counter's max value (to allow counter to
         run after reaching it limit, see below for more explanation):
     ---------->8-----------
     arc_pmu->max_period = (1ULL << counter_size) / 2 - 1ULL;
     ---------->8-----------
    
     [2] Set start value as "arc_pmu->max_period - sample_period" and then
    count up to the limit
    
    Our event counters don't stop on reaching max value (the one we set in
    ARC_REG_PCT_INT_CNT) but continue to count until kernel explicitly
    stops each of them.
    
    And setting a limit as half of counter capacity is done to allow
    capturing of additional events in between moment when interrupt was
    triggered until we're actually processing PMU interrupts. That way
    we're trying to be more precise.
    
    For example if we count CPU cycles we keep track of cycles while
    running through generic IRQ handling code:
    
     [1] We set counter period as say 100_000 events of type "crun"
     [2] Counter reaches that limit and raises its interrupt
     [3] Once we get in PMU IRQ handler we read current counter value from
    ARC_REG_PCT_SNAP ans see there something like 105_000.
    
    If counters stop on reaching a limit value then we would miss
    additional 5000 cycles.
    Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
    Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
    Signed-off-by: default avatarAlexey Brodkin <abrodkin@synopsys.com>
    Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
    1fe8bfa5
perf_event.c 10.3 KB