Patch "perf cs-etm: Don't flush when packet_queue fills up" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    perf cs-etm: Don't flush when packet_queue fills up

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     perf-cs-etm-don-t-flush-when-packet_queue-fills-up.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 181647a7becf91597037cb105e8fbe3d29d961e0
Author: James Clark <james.clark@xxxxxxxxxx>
Date:   Mon Sep 16 14:57:32 2024 +0100

    perf cs-etm: Don't flush when packet_queue fills up
    
    [ Upstream commit 5afd032961e8465808c4bc385c06e7676fbe1951 ]
    
    cs_etm__flush(), like cs_etm__sample() is an operation that generates a
    sample and then swaps the current with the previous packet. Calling
    flush after processing the queues results in two swaps which corrupts
    the next sample. Therefore it wasn't appropriate to call flush here so
    remove it.
    
    Flushing is still done on a discontinuity to explicitly clear the last
    branch buffer, but when the packet_queue fills up before reaching a
    timestamp, that's not a discontinuity and the call to
    cs_etm__process_traceid_queue() already generated samples and drained
    the buffers correctly.
    
    This is visible by looking for a branch that has the same target as the
    previous branch and the following source is before the address of the
    last target, which is impossible as execution would have had to have
    gone backwards:
    
      ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94
       (packet_queue fills here before a timestamp, resulting in a flush and
        branch target ffff80008011cadc is duplicated.)
      ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff80008011cadc update_sg_lb_stats+0x94
      ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34
    
    After removing the flush the correct branch target is used for the
    second sample, and ffff8000801117c4 is no longer before the previous
    address:
    
      ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94
      ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff8000801117a0 cpu_util+0x0
      ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34
    
    Make sure that a final branch stack is output at the end of the trace
    by calling cs_etm__end_block(). This is already done for both the
    timeless decode paths.
    
    Fixes: 21fe8dc1191a ("perf cs-etm: Add support for CPU-wide trace scenarios")
    Reported-by: Ganapatrao Kulkarni <gankulkarni@xxxxxxxxxxxxxxxxxxxxxx>
    Closes: https://lore.kernel.org/all/20240719092619.274730-1-gankulkarni@xxxxxxxxxxxxxxxxxxxxxx/
    Reviewed-by: Leo Yan <leo.yan@xxxxxxx>
    Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
    Tested-by: Ganapatrao Kulkarni <gankulkarni@xxxxxxxxxxxxxxxxxxxxxx>
    Cc: Ben Gainey <ben.gainey@xxxxxxx>
    Cc: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
    Cc: Will Deacon <will@xxxxxxxxxx>
    Cc: Mathieu Poirier <mathieu.poirier@xxxxxxxxxx>
    Cc: Mike Leach <mike.leach@xxxxxxxxxx>
    Cc: Ruidong Tian <tianruidong@xxxxxxxxxxxxxxxxx>
    Cc: Benjamin Gray <bgray@xxxxxxxxxxxxx>
    Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
    Cc: coresight@xxxxxxxxxxxxxxxx
    Cc: John Garry <john.g.garry@xxxxxxxxxx>
    Cc: scclevenger@xxxxxxxxxxxxxxxxxxxxxx
    Link: https://lore.kernel.org/r/20240916135743.1490403-2-james.clark@xxxxxxxxxx
    Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index f323adb1af855..6fa698186f0b6 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2126,12 +2126,6 @@ static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq)
 
 		/* Ignore return value */
 		cs_etm__process_traceid_queue(etmq, tidq);
-
-		/*
-		 * Generate an instruction sample with the remaining
-		 * branchstack entries.
-		 */
-		cs_etm__flush(etmq, tidq);
 	}
 }
 
@@ -2228,7 +2222,7 @@ static int cs_etm__process_queues(struct cs_etm_auxtrace *etm)
 
 	while (1) {
 		if (!etm->heap.heap_cnt)
-			goto out;
+			break;
 
 		/* Take the entry at the top of the min heap */
 		cs_queue_nr = etm->heap.heap_array[0].queue_nr;
@@ -2311,6 +2305,23 @@ static int cs_etm__process_queues(struct cs_etm_auxtrace *etm)
 		ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp);
 	}
 
+	for (i = 0; i < etm->queues.nr_queues; i++) {
+		struct int_node *inode;
+
+		etmq = etm->queues.queue_array[i].priv;
+		if (!etmq)
+			continue;
+
+		intlist__for_each_entry(inode, etmq->traceid_queues_list) {
+			int idx = (int)(intptr_t)inode->priv;
+
+			/* Flush any remaining branch stack entries */
+			tidq = etmq->traceid_queues[idx];
+			ret = cs_etm__end_block(etmq, tidq);
+			if (ret)
+				return ret;
+		}
+	}
 out:
 	return ret;
 }




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux