Skip to content
Snippets Groups Projects
  • Adrian Hunter's avatar
    bc9b40fa
    perf/x86/intel/pt: Fix buffer full but size is 0 case · bc9b40fa
    Adrian Hunter authored
    
    commit 5b590160d2cf776b304eb054afafea2bd55e3620 upstream.
    
    If the trace data buffer becomes full, a truncated flag [T] is reported
    in PERF_RECORD_AUX.  In some cases, the size reported is 0, even though
    data must have been added to make the buffer full.
    
    That happens when the buffer fills up from empty to full before the
    Intel PT driver has updated the buffer position.  Then the driver
    calculates the new buffer position before calculating the data size.
    If the old and new positions are the same, the data size is reported
    as 0, even though it is really the whole buffer size.
    
    Fix by detecting when the buffer position is wrapped, and adjust the
    data size calculation accordingly.
    
    Example
    
      Use a very small buffer size (8K) and observe the size of truncated [T]
      data. Before the fix, it is possible to see records of 0 size.
    
      Before:
    
        $ perf record -m,8K -e intel_pt// uname
        Linux
        [ perf record: Woken up 2 times to write data ]
        [ perf record: Captured and wrote 0.105 MB perf.data ]
        $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
        Warning:
        AUX data lost 2 times out of 3!
    
        5 19462712368111 0x19710 [0x40]: PERF_RECORD_AUX offset: 0 size: 0 flags: 0x1 [T]
        5 19462712700046 0x19ba8 [0x40]: PERF_RECORD_AUX offset: 0x170 size: 0xe90 flags: 0x1 [T]
    
     After:
    
        $ perf record -m,8K -e intel_pt// uname
        Linux
        [ perf record: Woken up 3 times to write data ]
        [ perf record: Captured and wrote 0.040 MB perf.data ]
        $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
        Warning:
        AUX data lost 2 times out of 3!
    
        1 113720802995 0x4948 [0x40]: PERF_RECORD_AUX offset: 0 size: 0x2000 flags: 0x1 [T]
        1 113720979812 0x6b10 [0x40]: PERF_RECORD_AUX offset: 0x2000 size: 0x2000 flags: 0x1 [T]
    
    Fixes: 52ca9ced ("perf/x86/intel/pt: Add Intel PT PMU driver")
    Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20241022155920.17511-2-adrian.hunter@intel.com
    
    
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    bc9b40fa
    History
    perf/x86/intel/pt: Fix buffer full but size is 0 case
    Adrian Hunter authored
    
    commit 5b590160d2cf776b304eb054afafea2bd55e3620 upstream.
    
    If the trace data buffer becomes full, a truncated flag [T] is reported
    in PERF_RECORD_AUX.  In some cases, the size reported is 0, even though
    data must have been added to make the buffer full.
    
    That happens when the buffer fills up from empty to full before the
    Intel PT driver has updated the buffer position.  Then the driver
    calculates the new buffer position before calculating the data size.
    If the old and new positions are the same, the data size is reported
    as 0, even though it is really the whole buffer size.
    
    Fix by detecting when the buffer position is wrapped, and adjust the
    data size calculation accordingly.
    
    Example
    
      Use a very small buffer size (8K) and observe the size of truncated [T]
      data. Before the fix, it is possible to see records of 0 size.
    
      Before:
    
        $ perf record -m,8K -e intel_pt// uname
        Linux
        [ perf record: Woken up 2 times to write data ]
        [ perf record: Captured and wrote 0.105 MB perf.data ]
        $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
        Warning:
        AUX data lost 2 times out of 3!
    
        5 19462712368111 0x19710 [0x40]: PERF_RECORD_AUX offset: 0 size: 0 flags: 0x1 [T]
        5 19462712700046 0x19ba8 [0x40]: PERF_RECORD_AUX offset: 0x170 size: 0xe90 flags: 0x1 [T]
    
     After:
    
        $ perf record -m,8K -e intel_pt// uname
        Linux
        [ perf record: Woken up 3 times to write data ]
        [ perf record: Captured and wrote 0.040 MB perf.data ]
        $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
        Warning:
        AUX data lost 2 times out of 3!
    
        1 113720802995 0x4948 [0x40]: PERF_RECORD_AUX offset: 0 size: 0x2000 flags: 0x1 [T]
        1 113720979812 0x6b10 [0x40]: PERF_RECORD_AUX offset: 0x2000 size: 0x2000 flags: 0x1 [T]
    
    Fixes: 52ca9ced ("perf/x86/intel/pt: Add Intel PT PMU driver")
    Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: stable@vger.kernel.org
    Link: https://lkml.kernel.org/r/20241022155920.17511-2-adrian.hunter@intel.com
    
    
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>