Skip to content

Commit e2ab285

Browse files
mathieupoirieracmel
authored andcommitted
perf cs-etm: Fix indexing for decoder packet queue
The tail of a queue is supposed to be pointing to the next available slot in a queue. In this implementation the tail is incremented before it is used and as such points to the last used element, something that has the immense advantage of centralizing tail management at a single location and eliminating a lot of redundant code. But this needs to be taken into consideration on the dequeueing side where the head also needs to be incremented before it is used, or the first available element of the queue will be skipped. Signed-off-by: Mathieu Poirier <[email protected]> Tested-by: Leo Yan <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Robert Walker <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ab4e32f commit e2ab285

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/perf/util/cs-etm-decoder/cs-etm-decoder.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,19 @@ int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder,
9696
/* Nothing to do, might as well just return */
9797
if (decoder->packet_count == 0)
9898
return 0;
99+
/*
100+
* The queueing process in function cs_etm_decoder__buffer_packet()
101+
* increments the tail *before* using it. This is somewhat counter
102+
* intuitive but it has the advantage of centralizing tail management
103+
* at a single location. Because of that we need to follow the same
104+
* heuristic with the head, i.e we increment it before using its
105+
* value. Otherwise the first element of the packet queue is not
106+
* used.
107+
*/
108+
decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1);
99109

100110
*packet = decoder->packet_buffer[decoder->head];
101111

102-
decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1);
103-
104112
decoder->packet_count--;
105113

106114
return 1;

0 commit comments

Comments
 (0)