• L
    perf cs-etm: Avoid stale branch samples when flush packet · 24fff5eb
    Leo Yan 提交于
    At the end of trace buffer handling, function cs_etm__flush() is invoked
    to flush any remaining branch stack entries.  As a side effect, it also
    generates branch sample, because the 'etmq->packet' doesn't contains any
    new coming packet but point to one stale packet after packets swapping,
    so it wrongly makes synthesize branch samples with stale packet info.
    
    We could review below detailed flow which causes issue:
    
      Packet1: start_addr=0xffff000008b1fbf0 end_addr=0xffff000008b1fbfc
      Packet2: start_addr=0xffff000008b1fb5c end_addr=0xffff000008b1fb6c
    
      step 1: cs_etm__sample():
    	sample: ip=(0xffff000008b1fbfc-4) addr=0xffff000008b1fb5c
    
      step 2: flush packet in cs_etm__run_decoder():
    	cs_etm__run_decoder()
    	  `-> err = cs_etm__flush(etmq, false);
    	sample: ip=(0xffff000008b1fb6c-4) addr=0xffff000008b1fbf0
    
    Packet1 and packet2 are two continuous packets, when packet2 is the new
    coming packet, cs_etm__sample() generates branch sample for these two
    packets and use [packet1::end_addr - 4 => packet2::start_addr] as branch
    jump flow, thus we can see the first generated branch sample in step 1.
    At the end of cs_etm__sample() it swaps packets so 'etm->prev_packet'=
    packet2 and 'etm->packet'=packet1, so far it's okay for branch sample.
    
    If packet2 is the last one packet in trace buffer, even there have no
    any new coming packet, cs_etm__run_decoder() invokes cs_etm__flush() to
    flush branch stack entries as expected, but it also generates branch
    samples by taking 'etm->packet' as a new coming packet, thus the branch
    jump flow is as [packet2::end_addr - 4 =>  packet1::start_addr]; this
    is the second sample which is generated in step 2.  So actually the
    second sample is a stale sample and we should not generate it.
    
    This patch introduces a new function cs_etm__end_block(), at the end of
    trace block this function is invoked to only flush branch stack entries
    and thus can avoid to generate branch sample for stale packet.
    Signed-off-by: NLeo Yan <leo.yan@linaro.org>
    Reviewed-by: NMathieu Poirier <mathieu.poirier@linaro.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Robert Walker <robert.walker@arm.com>
    Cc: coresight@lists.linaro.org
    Cc: linux-arm-kernel@lists.infradead.org
    Link: http://lkml.kernel.org/r/1544513908-16805-3-git-send-email-leo.yan@linaro.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
    24fff5eb
cs-etm.c 38.8 KB