diff --git a/daemon/media_socket.c b/daemon/media_socket.c index e7577c4ee..4a932fd62 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -45,20 +45,6 @@ #define MAX_RECV_LOOP_STRIKES 5 #endif -#define DS_io(x, ps, io) do { \ - uint64_t ks_val, cur_val; \ - ks_val = atomic64_get_na(&ps->kernel_stats_ ## io.x); \ - cur_val = atomic64_get_na(&ps->stats_ ## io->x); \ - if (cur_val < ks_val) \ - diff_ ## x ## _ ## io = 0; \ - else \ - diff_ ## x ## _ ## io = cur_val - ks_val; \ - RTPE_STATS_ADD(x ## _kernel, diff_ ## x ## _ ## io); \ - } while (0) - -#define DS(x) DS_io(x, ps, in) -#define DSo(x) DS_io(x, sink, out) - struct intf_rr { struct logical_intf hash_key; @@ -1506,8 +1492,6 @@ static const char *kernelize_one(struct rtpengine_target_info *reti, GQueue *out reti->ssrc[u] = htonl(stream->ssrc_in[u]->parent->h.ssrc); } - ZERO(stream->kernel_stats_in); - if (proto_is_rtp(media->protocol)) { reti->rtp = 1; if (!MEDIA_ISSET(media, TRANSCODING)) { @@ -3520,13 +3504,6 @@ enum thread_looper_action kernel_stats_updater(void) { goto next; } - uint64_t diff_packets_in, diff_bytes_in, diff_errors_in; - uint64_t diff_packets_out, diff_bytes_out, diff_errors_out; - - DS(packets); - DS(bytes); - DS(errors); - // stats_in->last_packet is updated by the kernel only, so we can use it // to count kernel streams if (rtpe_now.tv_sec - atomic64_get_na(&ps->stats_in->last_packet) < 2) { @@ -3535,10 +3512,6 @@ enum thread_looper_action kernel_stats_updater(void) { ps->in_tos_tclass = ke->tos; - atomic64_set_na(&ps->kernel_stats_in.bytes, atomic64_get_na(&ps->stats_in->bytes)); - atomic64_set_na(&ps->kernel_stats_in.packets, atomic64_get_na(&ps->stats_in->packets)); - atomic64_set_na(&ps->kernel_stats_in.errors, atomic64_get_na(&ps->stats_in->errors)); - uint64_t max_diff = 0; int max_pt = -1; for (j = 0; j < ke->target.num_payload_types; j++) { @@ -3563,10 +3536,11 @@ enum thread_looper_action kernel_stats_updater(void) { bool update = false; - if (diff_packets_in) + bool active_media = (rtpe_now.tv_sec - packet_stream_last_packet(ps) < 1); + if (active_media) CALL_CLEAR(sfd->call, FOREIGN_MEDIA); - if (!ke->target.non_forwarding && diff_packets_in) { + if (!ke->target.non_forwarding && active_media) { for (__auto_type l = ps->rtp_sinks.head; l; l = l->next) { struct sink_handler *sh = l->data; struct packet_stream *sink = sh->sink; @@ -3577,14 +3551,6 @@ enum thread_looper_action kernel_stats_updater(void) { struct rtpengine_output_info *o = &ke->outputs[sh->kernel_output_idx]; - DSo(bytes); - DSo(packets); - DSo(errors); - - atomic64_set_na(&sink->kernel_stats_out.bytes, atomic64_get_na(&sink->stats_out->bytes)); - atomic64_set_na(&sink->kernel_stats_out.packets, atomic64_get_na(&sink->stats_out->packets)); - atomic64_set_na(&sink->kernel_stats_out.errors, atomic64_get_na(&sink->stats_out->errors)); - mutex_lock(&sink->out_lock); for (unsigned int u = 0; u < G_N_ELEMENTS(ke->target.ssrc); u++) { if (!ke->target.ssrc[u]) // end of list diff --git a/include/call.h b/include/call.h index bbf082681..0a72f1906 100644 --- a/include/call.h +++ b/include/call.h @@ -467,8 +467,6 @@ struct packet_stream { struct stream_stats *stats_in; struct stream_stats *stats_out; - struct stream_stats kernel_stats_in; - struct stream_stats kernel_stats_out; unsigned char in_tos_tclass; atomic64 last_packet; // userspace only GHashTable *rtp_stats; /* LOCK: call->master_lock */ diff --git a/kernel-module/xt_RTPENGINE.c b/kernel-module/xt_RTPENGINE.c index f97d23b8e..6f2b12cca 100644 --- a/kernel-module/xt_RTPENGINE.c +++ b/kernel-module/xt_RTPENGINE.c @@ -5512,6 +5512,7 @@ static unsigned int rtpengine46(struct sk_buff *skb, struct sk_buff *oskb, log_err("out of memory while creating skb copy"); atomic64_inc(&g->target.stats->errors); atomic64_inc(&g->target.iface_stats->in.errors); + atomic64_inc(&t->rtpe_stats->errors_kernel); continue; } skb_gso_reset(skb2); @@ -5531,6 +5532,7 @@ static unsigned int rtpengine46(struct sk_buff *skb, struct sk_buff *oskb, atomic64_inc(&g->target.iface_stats->in.errors); atomic64_inc(&o->output.stats->errors); atomic64_inc(&o->output.iface_stats->out.errors); + atomic64_inc(&t->rtpe_stats->errors_kernel); } else { atomic64_inc(&o->output.stats->packets); @@ -5548,6 +5550,8 @@ do_stats: atomic64_add(datalen, &g->target.stats->bytes); atomic64_inc(&g->target.iface_stats->in.packets); atomic64_add(datalen, &g->target.iface_stats->in.bytes); + atomic64_inc(&t->rtpe_stats->packets_kernel); + atomic64_add(datalen, &t->rtpe_stats->bytes_kernel); if (rtp_pt_idx >= 0) { atomic64_inc(&g->rtp_stats[rtp_pt_idx].packets); @@ -5571,6 +5575,7 @@ out_error: log_err("x_tables action failed: %s", errstr); atomic64_inc(&g->target.stats->errors); atomic64_inc(&g->target.iface_stats->in.errors); + atomic64_inc(&t->rtpe_stats->errors_kernel); out: target_put(g); out_no_target: