MT#55283 move ssrc_stats into kernel header

Change-Id: I14cb7fd76633374331a1ba4d556a053c53d0fcda
pull/1826/head
Richard Fuchs 1 year ago
parent 2698e53948
commit a1a1e42b02

@ -1776,11 +1776,11 @@ static void __stream_consume_stats(struct packet_stream *ps, const struct rtpeng
continue; continue;
struct ssrc_entry_call *parent = ssrc_ctx->parent; struct ssrc_entry_call *parent = ssrc_ctx->parent;
if (!stats_info->ssrc_stats[u].packets) // no change if (!atomic64_get_na(&stats_info->ssrc_stats[u].packets)) // no change
continue; continue;
atomic64_add(&ssrc_ctx->packets, stats_info->ssrc_stats[u].packets); atomic64_add(&ssrc_ctx->packets, atomic64_get_na(&stats_info->ssrc_stats[u].packets));
atomic64_add(&ssrc_ctx->octets, stats_info->ssrc_stats[u].bytes); atomic64_add(&ssrc_ctx->octets, atomic64_get_na(&stats_info->ssrc_stats[u].bytes));
parent->packets_lost += stats_info->ssrc_stats[u].total_lost; // XXX should be atomic? parent->packets_lost += stats_info->ssrc_stats[u].total_lost; // XXX should be atomic?
atomic64_set(&ssrc_ctx->last_seq, stats_info->ssrc_stats[u].ext_seq); atomic64_set(&ssrc_ctx->last_seq, stats_info->ssrc_stats[u].ext_seq);
parent->jitter = stats_info->ssrc_stats[u].jitter; parent->jitter = stats_info->ssrc_stats[u].jitter;
@ -1811,8 +1811,8 @@ static void __stream_consume_stats(struct packet_stream *ps, const struct rtpeng
if (ssrc_ctx) { if (ssrc_ctx) {
parent = ssrc_ctx->parent; parent = ssrc_ctx->parent;
atomic64_add(&ssrc_ctx->packets, stats_info->ssrc_stats[u].packets); atomic64_add(&ssrc_ctx->packets, atomic64_get_na(&stats_info->ssrc_stats[u].packets));
atomic64_add(&ssrc_ctx->octets, stats_info->ssrc_stats[u].bytes); atomic64_add(&ssrc_ctx->octets, atomic64_get_na(&stats_info->ssrc_stats[u].bytes));
} }
mutex_unlock(&sink->out_lock); mutex_unlock(&sink->out_lock);

@ -59,5 +59,15 @@ struct rtp_stats {
atomic64 kernel_packets; atomic64 kernel_packets;
atomic64 kernel_bytes; atomic64 kernel_bytes;
}; };
struct ssrc_stats {
atomic64 packets;
atomic64 bytes;
atomic_t timestamp;
atomic_t ext_seq;
uint32_t lost_bits; // sliding bitfield, [0] = ext_seq
atomic_t total_lost;
atomic_t transit;
atomic_t jitter;
};
#endif #endif

@ -321,7 +321,7 @@ struct rtpengine_target {
unsigned int last_pt; // index into pt_input[] and pt_output[] unsigned int last_pt; // index into pt_input[] and pt_output[]
spinlock_t ssrc_stats_lock; spinlock_t ssrc_stats_lock;
struct rtpengine_ssrc_stats ssrc_stats[RTPE_NUM_SSRC_TRACKING]; struct ssrc_stats ssrc_stats[RTPE_NUM_SSRC_TRACKING];
struct re_crypto_context decrypt_rtp; struct re_crypto_context decrypt_rtp;
struct re_crypto_context decrypt_rtcp; struct re_crypto_context decrypt_rtcp;
@ -1864,9 +1864,9 @@ static void target_retrieve_stats(struct rtpengine_target *g, struct rtpengine_s
i->ssrc[u] = g->target.ssrc[u]; i->ssrc[u] = g->target.ssrc[u];
i->ssrc_stats[u] = g->ssrc_stats[u]; i->ssrc_stats[u] = g->ssrc_stats[u];
g->ssrc_stats[u].packets = 0; atomic64_set(&g->ssrc_stats[u].packets, 0);
g->ssrc_stats[u].bytes = 0; atomic64_set(&g->ssrc_stats[u].bytes, 0);
g->ssrc_stats[u].total_lost = 0; atomic_set(&g->ssrc_stats[u].total_lost, 0);
} }
for (u = 0; u < g->target.num_destinations; u++) { for (u = 0; u < g->target.num_destinations; u++) {
@ -5212,7 +5212,7 @@ static void rtp_stats(struct rtpengine_target *g, struct rtp_parsed *rtp, s64 ar
int ssrc_idx) int ssrc_idx)
{ {
unsigned long flags; unsigned long flags;
struct rtpengine_ssrc_stats *s = &g->ssrc_stats[ssrc_idx]; struct ssrc_stats *s = &g->ssrc_stats[ssrc_idx];
uint16_t old_seq_trunc; uint16_t old_seq_trunc;
uint32_t last_seq; uint32_t last_seq;
uint16_t seq_diff; uint16_t seq_diff;
@ -5224,15 +5224,15 @@ static void rtp_stats(struct rtpengine_target *g, struct rtp_parsed *rtp, s64 ar
uint16_t seq = ntohs(rtp->rtp_header->seq_num); uint16_t seq = ntohs(rtp->rtp_header->seq_num);
uint32_t ts = ntohl(rtp->rtp_header->timestamp); uint32_t ts = ntohl(rtp->rtp_header->timestamp);
spin_lock_irqsave(&g->ssrc_stats_lock, flags); atomic64_inc(&s->packets);
atomic64_add(rtp->payload_len, &s->bytes);
atomic_set(&s->timestamp, ts);
s->packets++; spin_lock_irqsave(&g->ssrc_stats_lock, flags);
s->bytes += rtp->payload_len;
s->timestamp = ts;
// track sequence numbers and lost frames // track sequence numbers and lost frames
last_seq = s->ext_seq; last_seq = atomic_read(&s->ext_seq);
new_seq = last_seq; new_seq = last_seq;
// old seq or seq reset? // old seq or seq reset?
@ -5243,7 +5243,7 @@ static void rtp_stats(struct rtpengine_target *g, struct rtp_parsed *rtp, s64 ar
else if (seq_diff > 0x100) { else if (seq_diff > 0x100) {
// reset seq and loss tracker // reset seq and loss tracker
new_seq = seq; new_seq = seq;
s->ext_seq = seq; atomic_set(&s->ext_seq, seq);
s->lost_bits = -1; s->lost_bits = -1;
} }
else { else {
@ -5255,19 +5255,19 @@ static void rtp_stats(struct rtpengine_target *g, struct rtp_parsed *rtp, s64 ar
break; break;
} }
seq_diff = new_seq - last_seq; seq_diff = new_seq - last_seq;
s->ext_seq = new_seq; atomic_set(&s->ext_seq, new_seq);
// shift loss tracker bit field and count losses // shift loss tracker bit field and count losses
if (seq_diff >= (sizeof(s->lost_bits) * 8)) { if (seq_diff >= (sizeof(s->lost_bits) * 8)) {
// complete loss // complete loss
s->total_lost += sizeof(s->lost_bits) * 8; atomic_add(sizeof(s->lost_bits) * 8, &s->total_lost);
s->lost_bits = -1; s->lost_bits = -1;
} }
else { else {
while (seq_diff) { while (seq_diff) {
// shift out one bit and see if we lost it // shift out one bit and see if we lost it
if ((s->lost_bits & 0x80000000) == 0) if ((s->lost_bits & 0x80000000) == 0)
s->total_lost++; atomic_inc(&s->total_lost);
s->lost_bits <<= 1; s->lost_bits <<= 1;
seq_diff--; seq_diff--;
} }
@ -5283,15 +5283,15 @@ static void rtp_stats(struct rtpengine_target *g, struct rtp_parsed *rtp, s64 ar
// RFC 3550 A.8 // RFC 3550 A.8
clockrate = g->target.pt_stats[pt_idx]->clock_rate; clockrate = g->target.pt_stats[pt_idx]->clock_rate;
transit = ((uint32_t) (div64_s64(arrival_time, 1000) * clockrate) / 1000) - ts; transit = ((uint32_t) (div64_s64(arrival_time, 1000) * clockrate) / 1000) - ts;
d = 0; d = atomic_read(&s->transit);
if (s->transit) if (d)
d = transit - s->transit; d = transit - d;
s->transit = transit; atomic_set(&s->transit, transit);
if (d < 0) if (d < 0)
d = -d; d = -d;
// ignore implausibly large values // ignore implausibly large values
if (d < 100000) if (d < 100000)
s->jitter += d - ((s->jitter + 8) >> 4); atomic_add(d - ((atomic_read(&s->jitter) + 8) >> 4), &s->jitter);
spin_unlock_irqrestore(&g->ssrc_stats_lock, flags); spin_unlock_irqrestore(&g->ssrc_stats_lock, flags);
} }

@ -17,17 +17,6 @@ struct xt_rtpengine_info {
unsigned int id; unsigned int id;
}; };
struct rtpengine_ssrc_stats {
uint64_t packets;
uint64_t bytes;
uint32_t timestamp;
uint32_t ext_seq;
uint32_t lost_bits; // sliding bitfield, [0] = ext_seq
uint32_t total_lost;
uint32_t transit;
uint32_t jitter;
};
struct re_address { struct re_address {
int family; int family;
union { union {
@ -172,7 +161,7 @@ struct rtpengine_packet_info {
struct rtpengine_stats_info { struct rtpengine_stats_info {
uint32_t ssrc[RTPE_NUM_SSRC_TRACKING]; uint32_t ssrc[RTPE_NUM_SSRC_TRACKING];
struct rtpengine_ssrc_stats ssrc_stats[RTPE_NUM_SSRC_TRACKING]; struct ssrc_stats ssrc_stats[RTPE_NUM_SSRC_TRACKING];
uint64_t last_rtcp_index[RTPE_MAX_FORWARD_DESTINATIONS][RTPE_NUM_SSRC_TRACKING]; uint64_t last_rtcp_index[RTPE_MAX_FORWARD_DESTINATIONS][RTPE_NUM_SSRC_TRACKING];
}; };

Loading…
Cancel
Save