Add trace events for CXL event log activity.  Event insertion, overflow,
and clearing are exercised on every error injection or dynamic capacity
event, but the interaction with the per-log overflow counter was
previously opaque.

Three trace points are added:

  cxl_event_insert   - successful enqueue, with log type and resulting
                       occupancy (queue depth after insert)
  cxl_event_overflow - overflow threshold hit, event dropped, with
                       cumulative overflow count
  cxl_event_clear    - bulk clear with log type and number of records
                       removed

As a minor optimisation, cache the result of cxl_event_count() in a
local variable so the O(n) queue walk is performed once per insert
rather than twice.

Signed-off-by: Junjie Cao <[email protected]>
---
 hw/cxl/cxl-events.c | 13 +++++++++++--
 hw/cxl/trace-events |  5 +++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/hw/cxl/cxl-events.c b/hw/cxl/cxl-events.c
index 5356dfb5b3..685ef5dc44 100644
--- a/hw/cxl/cxl-events.c
+++ b/hw/cxl/cxl-events.c
@@ -13,6 +13,7 @@
 #include "hw/pci/msix.h"
 #include "hw/cxl/cxl.h"
 #include "hw/cxl/cxl_events.h"
+#include "trace.h"
 
 /* Artificial limit on the number of events a log can hold */
 #define CXL_TEST_EVENT_OVERFLOW 8
@@ -98,6 +99,7 @@ bool cxl_event_insert(CXLDeviceState *cxlds, CXLEventLogType 
log_type,
     uint64_t time;
     CXLEventLog *log;
     CXLEvent *entry;
+    int occupancy;
 
     if (log_type >= CXL_EVENT_TYPE_MAX) {
         return false;
@@ -109,12 +111,15 @@ bool cxl_event_insert(CXLDeviceState *cxlds, 
CXLEventLogType log_type,
 
     QEMU_LOCK_GUARD(&log->lock);
 
-    if (cxl_event_count(log) >= CXL_TEST_EVENT_OVERFLOW) {
+    occupancy = cxl_event_count(log);
+
+    if (occupancy >= CXL_TEST_EVENT_OVERFLOW) {
         if (log->overflow_err_count == 0) {
             log->first_overflow_timestamp = time;
         }
         log->overflow_err_count++;
         log->last_overflow_timestamp = time;
+        trace_cxl_event_overflow(log_type, log->overflow_err_count);
         return false;
     }
 
@@ -133,8 +138,10 @@ bool cxl_event_insert(CXLDeviceState *cxlds, 
CXLEventLogType log_type,
     QSIMPLEQ_INSERT_TAIL(&log->events, entry, node);
     cxl_event_set_status(cxlds, log_type, true);
 
+    trace_cxl_event_insert(log_type, occupancy + 1);
+
     /* Count went from 0 to 1 */
-    return cxl_event_count(log) == 1;
+    return occupancy == 0;
 }
 
 void cxl_discard_all_event_records(CXLDeviceState *cxlds)
@@ -234,6 +241,8 @@ CXLRetCode cxl_event_clear_records(CXLDeviceState *cxlds,
         entry = cxl_event_get_head(log);
     }
 
+    trace_cxl_event_clear(log_type, nr);
+
     return CXL_MBOX_SUCCESS;
 }
 
diff --git a/hw/cxl/trace-events b/hw/cxl/trace-events
index 609def2dec..17f9e7059c 100644
--- a/hw/cxl/trace-events
+++ b/hw/cxl/trace-events
@@ -4,3 +4,8 @@
 cxl_mailbox_cmd(uint8_t set, uint8_t cmd, const char *name, size_t len_in) 
"set=0x%02x cmd=0x%02x [%s] len_in=%zu"
 cxl_mailbox_cmd_done(uint8_t set, uint8_t cmd, int ret, size_t len_out) 
"set=0x%02x cmd=0x%02x ret=%d len_out=%zu"
 cxl_mailbox_payload_error(uint8_t set, uint8_t cmd, const char *name, size_t 
len_in) "set=0x%02x cmd=0x%02x [%s] len_in=%zu"
+
+# cxl-events.c
+cxl_event_insert(int log_type, int occupancy) "log_type=%d occupancy=%d"
+cxl_event_overflow(int log_type, uint16_t overflow_count) "log_type=%d 
overflow_count=%u"
+cxl_event_clear(int log_type, int nr_recs) "log_type=%d nr_recs=%d"
-- 
2.43.0


Reply via email to