From 2cc60d6167d05426de39feb003f9c93d6c18b670 Mon Sep 17 00:00:00 2001 From: hackerman-kl Date: Sat, 25 Apr 2026 08:03:41 +0200 Subject: [PATCH] milan-avb: adp: add log_state diagnostic --- src/modules/module-avb/adp.c | 40 +++++++++++++++++++++++++++++++++++- src/modules/module-avb/adp.h | 2 ++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/modules/module-avb/adp.c b/src/modules/module-avb/adp.c index c9cf57d30..12ece4ef2 100644 --- a/src/modules/module-avb/adp.c +++ b/src/modules/module-avb/adp.c @@ -115,6 +115,14 @@ static int adp_message(void *data, uint64_t now, const void *message, int len) e = find_entity_by_id(adp, entity_id); + { + const char *mt = (message_type == AVB_ADP_MESSAGE_TYPE_ENTITY_AVAILABLE) ? "ADP rx ENTITY_AVAILABLE" : + (message_type == AVB_ADP_MESSAGE_TYPE_ENTITY_DEPARTING) ? "ADP rx ENTITY_DEPARTING" : + (message_type == AVB_ADP_MESSAGE_TYPE_ENTITY_DISCOVER) ? "ADP rx ENTITY_DISCOVER" : + "ADP rx ?"; + avb_log_state(server, mt); + } + switch (message_type) { case AVB_ADP_MESSAGE_TYPE_ENTITY_AVAILABLE: if (e == NULL) { @@ -145,7 +153,7 @@ static int adp_message(void *data, uint64_t now, const void *message, int len) struct avb_packet_adp *p_saved = SPA_PTROFF(h_saved, sizeof(*h_saved), void); - if (p_saved->available_index != p->available_index) { + if (ntohl(p->available_index) <= ntohl(p_saved->available_index)) { if (handle_evt_tk_departed(server->acmp, entity_id, now)) { pw_log_info("handling departing event"); return -1; @@ -431,6 +439,36 @@ void adp_stop_discovery_entity(struct server *server, uint64_t entity_id) pw_log_warn("Could not find entity 0x%"PRIx64, entity_id); } +void adp_log_state(struct server *server, const char *label) +{ + struct adp *adp = (struct adp *)server->adp; + struct entity *e; + struct timespec ts; + uint64_t now; + char buf[64]; + int n = 0; + + if (adp == NULL) + return; + + clock_gettime(CLOCK_MONOTONIC, &ts); + now = SPA_TIMESPEC_TO_NSEC(&ts); + + spa_list_for_each(e, &adp->entities, link) + n++; + pw_log_debug("[%s] ADP: %d entit%s", label, n, n == 1 ? "y" : "ies"); + + spa_list_for_each(e, &adp->entities, link) { + struct avb_ethernet_header *h = (void *)e->buf; + struct avb_packet_adp *p = SPA_PTROFF(h, sizeof(*h), void); + uint64_t age_ms = (now - e->last_time) / 1000000ULL; + pw_log_debug("[%s] %s last_seen=%" PRIu64 "ms valid=%ds available_index=%u", + label, + avb_utils_format_id(buf, sizeof(buf), e->entity_id), + age_ms, e->valid_time, ntohl(p->available_index)); + } +} + struct avb_adp *avb_adp_register(struct server *server) { struct adp *adp; diff --git a/src/modules/module-avb/adp.h b/src/modules/module-avb/adp.h index 37c303103..7b65a9f19 100644 --- a/src/modules/module-avb/adp.h +++ b/src/modules/module-avb/adp.h @@ -88,4 +88,6 @@ void adp_stop_discovery_entity(struct server *server, uint64_t entity_id); struct avb_adp *avb_adp_register(struct server *server); void avb_adp_unregister(struct avb_adp *adp); +void adp_log_state(struct server *server, const char *label); + #endif /* AVB_ADP_H */