ALSA: firewire-lib: extend tracepoints event including CYCLE_TIME of 1394 OHCI
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 9 Jan 2023 21:32:31 +0000 (06:32 +0900)
committerTakashi Iwai <tiwai@suse.de>
Tue, 10 Jan 2023 08:34:47 +0000 (09:34 +0100)
A commit baa914cd81f5 ("firewire: add kernel API to access CYCLE_TIME
register") allow unit drivers to read CYCLE_TIME of 1394 OHCI controller.
The value expresses monotonic time with 42.195 Mhz resolution and wrapping
around every 128 seconds. The controller uses the time to govern
isochronous cycle.

This commit extends tracepoints event including the value so that event
parser can compute gap between current isochronous cycle and the latest
isochronous cycle in which packet is processed (in IR context) or scheduled
(in IT context). It loses backward compatibility to former format of the
tracepoints event.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20230109213231.138223-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/amdtp-stream-trace.h
sound/firewire/amdtp-stream.c

index 5fd2aeccdfc2ff385f40820ac4629754e6a3db81..208f97cf8de60ae18bb7203785a20056a596aae1 100644 (file)
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(amdtp_packet,
-       TP_PROTO(const struct amdtp_stream *s, u32 cycles, const __be32 *cip_header, unsigned int payload_length, unsigned int data_blocks, unsigned int data_block_counter, unsigned int packet_index, unsigned int index),
-       TP_ARGS(s, cycles, cip_header, payload_length, data_blocks, data_block_counter, packet_index, index),
+       TP_PROTO(const struct amdtp_stream *s, u32 cycles, const __be32 *cip_header, unsigned int payload_length, unsigned int data_blocks, unsigned int data_block_counter, unsigned int packet_index, unsigned int index, u32 curr_cycle_time),
+       TP_ARGS(s, cycles, cip_header, payload_length, data_blocks, data_block_counter, packet_index, index, curr_cycle_time),
        TP_STRUCT__entry(
+               __field(unsigned int, cycle_time)
                __field(unsigned int, second)
                __field(unsigned int, cycle)
                __field(int, channel)
@@ -31,6 +32,7 @@ TRACE_EVENT(amdtp_packet,
                __field(unsigned int, index)
        ),
        TP_fast_assign(
+               __entry->cycle_time = curr_cycle_time;
                __entry->second = cycles / CYCLES_PER_SECOND;
                __entry->cycle = cycles % CYCLES_PER_SECOND;
                __entry->channel = s->context->channel;
@@ -53,7 +55,8 @@ TRACE_EVENT(amdtp_packet,
                __entry->index = index;
        ),
        TP_printk(
-               "%02u %04u %04x %04x %02d %03u %02u %03u %02u %01u %02u %s",
+               "%08x %02u %04u %04x %04x %02d %03u %02u %03u %02u %01u %02u %s",
+               __entry->cycle_time,
                __entry->second,
                __entry->cycle,
                __entry->src,
index 430b33dc60b337353a5cc9fa827b125750bf834e..65720ae866cbb41707f4635c85e8a5d654506552 100644 (file)
@@ -674,7 +674,7 @@ static void build_it_pkt_header(struct amdtp_stream *s, unsigned int cycle,
                                struct fw_iso_packet *params, unsigned int header_length,
                                unsigned int data_blocks,
                                unsigned int data_block_counter,
-                               unsigned int syt, unsigned int index)
+                               unsigned int syt, unsigned int index, u32 curr_cycle_time)
 {
        unsigned int payload_length;
        __be32 *cip_header;
@@ -691,7 +691,7 @@ static void build_it_pkt_header(struct amdtp_stream *s, unsigned int cycle,
        }
 
        trace_amdtp_packet(s, cycle, cip_header, payload_length + header_length, data_blocks,
-                          data_block_counter, s->packet_index, index);
+                          data_block_counter, s->packet_index, index, curr_cycle_time);
 }
 
 static int check_cip_header(struct amdtp_stream *s, const __be32 *buf,
@@ -793,7 +793,8 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,
                               const __be32 *ctx_header,
                               unsigned int *data_blocks,
                               unsigned int *data_block_counter,
-                              unsigned int *syt, unsigned int packet_index, unsigned int index)
+                              unsigned int *syt, unsigned int packet_index, unsigned int index,
+                              u32 curr_cycle_time)
 {
        unsigned int payload_length;
        const __be32 *cip_header;
@@ -838,7 +839,7 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle,
        }
 
        trace_amdtp_packet(s, cycle, cip_header, payload_length, *data_blocks,
-                          *data_block_counter, packet_index, index);
+                          *data_block_counter, packet_index, index, curr_cycle_time);
 
        return 0;
 }
@@ -889,9 +890,13 @@ static int generate_tx_packet_descs(struct amdtp_stream *s, struct pkt_desc *des
        unsigned int dbc = s->data_block_counter;
        unsigned int packet_index = s->packet_index;
        unsigned int queue_size = s->queue_size;
+       u32 curr_cycle_time;
        int i;
        int err;
 
+       if (trace_amdtp_packet_enabled())
+               (void)fw_card_read_cycle_time(fw_parent_device(s->unit)->card, &curr_cycle_time);
+
        *desc_count = 0;
        for (i = 0; i < packet_count; ++i) {
                unsigned int cycle;
@@ -936,7 +941,7 @@ static int generate_tx_packet_descs(struct amdtp_stream *s, struct pkt_desc *des
                }
 
                err = parse_ir_ctx_header(s, cycle, ctx_header, &data_blocks, &dbc, &syt,
-                                         packet_index, i);
+                                         packet_index, i, curr_cycle_time);
                if (err < 0)
                        return err;
 
@@ -1050,6 +1055,7 @@ static void process_rx_packets(struct fw_iso_context *context, u32 tstamp, size_
        struct pkt_desc *desc = s->packet_descs_cursor;
        unsigned int pkt_header_length;
        unsigned int packets;
+       u32 curr_cycle_time;
        bool need_hw_irq;
        int i;
 
@@ -1078,6 +1084,9 @@ static void process_rx_packets(struct fw_iso_context *context, u32 tstamp, size_
                need_hw_irq = false;
        }
 
+       if (trace_amdtp_packet_enabled())
+               (void)fw_card_read_cycle_time(fw_parent_device(s->unit)->card, &curr_cycle_time);
+
        for (i = 0; i < packets; ++i) {
                struct {
                        struct fw_iso_packet params;
@@ -1087,7 +1096,7 @@ static void process_rx_packets(struct fw_iso_context *context, u32 tstamp, size_
 
                build_it_pkt_header(s, desc->cycle, &template.params, pkt_header_length,
                                    desc->data_blocks, desc->data_block_counter,
-                                   desc->syt, i);
+                                   desc->syt, i, curr_cycle_time);
 
                if (s == s->domain->irq_target) {
                        event_count += desc->data_blocks;