Change in libosmo-netif[master]: jibuf: Fix out-of-order seq queue around syncpoints

2018-05-17 Thread Pau Espin Pedrol
Pau Espin Pedrol has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/9172 )

Change subject: jibuf: Fix out-of-order seq queue around syncpoints
..

jibuf: Fix out-of-order seq queue around syncpoints

Fixes: OS#3262

Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
---
M src/jibuf.c
M tests/jibuf/jibuf_test.c
M tests/jibuf/jibuf_test.ok
3 files changed, 36 insertions(+), 7 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/jibuf.c b/src/jibuf.c
index 45019ae..2632a57 100644
--- a/src/jibuf.c
+++ b/src/jibuf.c
@@ -119,6 +119,35 @@

 }

+static void enqueue_pkt(struct osmo_jibuf *jb, struct msgb  *msg, bool 
is_syncpoint)
+{
+   struct msgb *cur;
+   struct timeval *msg_ts;
+
+   if (!is_syncpoint) {
+   llist_add_sorted(msg, >msg_list);
+   return;
+   }
+
+   /* syncpoints change the reference timings, and as such they can provoke
+  out of order enqueuing of this packet and its followups with regards
+  to the already stored packets which may be scheduled for later times.
+  We thus need to adapt dequeue time for the already stored pkts to be
+  dequeued before the syncpoint pkt. See OS#3262 for related scenarios.
+   */
+
+   msg_ts = msgb_scheduled_ts(msg);
+
+   llist_for_each_entry(cur, >msg_list, list) {
+   struct timeval *cur_ts = msgb_scheduled_ts(cur);
+   if (timercmp(msg_ts, cur_ts, <))
+   *cur_ts = *msg_ts;
+   }
+   /* syncpoint goes always to the end since we moved all older packets
+  before it */
+   llist_add_tail(>list, >msg_list);
+}
+
 static bool msg_get_marker(struct msgb *msg)
 {
/* TODO: make it more generic as a callback so that different types of
@@ -314,11 +343,13 @@
 {
int rel_delay, delay;
struct timeval delay_ts, sched_ts;
+   bool is_syncpoint;

clock_gettime_timeval(CLOCK_MONOTONIC, >last_enqueue_time);

/* Check if it's time to sync, ie. start of talkspurt */
-   if (!jb->started || msg_is_syncpoint(jb, msg)) {
+   is_syncpoint = !jb->started || msg_is_syncpoint(jb, msg);
+   if (is_syncpoint) {
jb->started = true;
msg_set_as_reference(jb, msg);
rel_delay = 0;
@@ -365,8 +396,7 @@
jbcb->ts = sched_ts;
jbcb->old_cb = old_cb;

-   llist_add_sorted(msg, >msg_list);
-
+   enqueue_pkt(jb, msg, is_syncpoint);

/* See if updating the timer is needed: */
if (!osmo_timer_pending(>timer) ||
diff --git a/tests/jibuf/jibuf_test.c b/tests/jibuf/jibuf_test.c
index 7993a65..ba1bb01 100644
--- a/tests/jibuf/jibuf_test.c
+++ b/tests/jibuf/jibuf_test.c
@@ -673,8 +673,7 @@
clock_override_add(0, min_delay*1000);
osmo_select_main(0);

-   /* This assert shows that packets are queued out of order in this 
case:*/
-   OSMO_ASSERT(!osmo_jibuf_empty(jb));
+   OSMO_ASSERT(osmo_jibuf_empty(jb));

osmo_jibuf_delete(jb);
 }
diff --git a/tests/jibuf/jibuf_test.ok b/tests/jibuf/jibuf_test.ok
index 6bf52fb..b92f73c 100644
--- a/tests/jibuf/jibuf_test.ok
+++ b/tests/jibuf/jibuf_test.ok
@@ -383,10 +383,10 @@
 sys={0.14}, mono={0.14}: dequeue: seq=34 ts=720 INTERMEDIATE
 sys={0.14}, mono={0.14}: dequeue: seq=35 ts=880 INTERMEDIATE
 sys={0.14}, mono={0.14}: dequeue: seq=36 ts=1040 INTERMEDIATE
-sys={0.14}, mono={0.14}: dequeue: seq=39 ts=1520 INTERMEDIATE
 sys={0.14}, mono={0.14}: dequeue: seq=37 ts=1200 INTERMEDIATE
-sys={0.14}, mono={0.14}: dequeue: seq=40 ts=1680 LATEST
 sys={0.14}, mono={0.14}: dequeue: seq=38 ts=1360 INTERMEDIATE
+sys={0.14}, mono={0.14}: dequeue: seq=39 ts=1520 INTERMEDIATE
+sys={0.14}, mono={0.14}: dequeue: seq=40 ts=1680 LATEST
 ===test_rtp_out_of_sync(1600, 5, 800, 1)===
 sys={0.00}, mono={0.00}: clock_override_set
 sys={0.00}, mono={0.00}: enqueue 1st packet (seq=33, ts=560)

--
To view, visit https://gerrit.osmocom.org/9172
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
Gerrit-Change-Number: 9172
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 


Change in libosmo-netif[master]: jibuf: Fix out-of-order seq queue around syncpoints

2018-05-17 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/9172 )

Change subject: jibuf: Fix out-of-order seq queue around syncpoints
..


Patch Set 1: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/9172
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
Gerrit-Change-Number: 9172
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Comment-Date: Thu, 17 May 2018 09:37:34 +
Gerrit-HasComments: No
Gerrit-HasLabels: Yes


Change in libosmo-netif[master]: jibuf: Fix out-of-order seq queue around syncpoints

2018-05-17 Thread Pau Espin Pedrol
Pau Espin Pedrol has posted comments on this change. ( 
https://gerrit.osmocom.org/9172 )

Change subject: jibuf: Fix out-of-order seq queue around syncpoints
..


Patch Set 1:

I'll +2 this in a few hours if nobody finds an issue.


--
To view, visit https://gerrit.osmocom.org/9172
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
Gerrit-Change-Number: 9172
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Comment-Date: Thu, 17 May 2018 09:14:43 +
Gerrit-HasComments: No
Gerrit-HasLabels: No


Change in libosmo-netif[master]: jibuf: Fix out-of-order seq queue around syncpoints

2018-05-15 Thread Pau Espin Pedrol
Pau Espin Pedrol has uploaded this change for review. ( 
https://gerrit.osmocom.org/9172


Change subject: jibuf: Fix out-of-order seq queue around syncpoints
..

jibuf: Fix out-of-order seq queue around syncpoints

Fixes: OS#3262

Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
---
M src/jibuf.c
M tests/jibuf/jibuf_test.c
M tests/jibuf/jibuf_test.ok
3 files changed, 36 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/72/9172/1

diff --git a/src/jibuf.c b/src/jibuf.c
index 45019ae..2632a57 100644
--- a/src/jibuf.c
+++ b/src/jibuf.c
@@ -119,6 +119,35 @@

 }

+static void enqueue_pkt(struct osmo_jibuf *jb, struct msgb  *msg, bool 
is_syncpoint)
+{
+   struct msgb *cur;
+   struct timeval *msg_ts;
+
+   if (!is_syncpoint) {
+   llist_add_sorted(msg, >msg_list);
+   return;
+   }
+
+   /* syncpoints change the reference timings, and as such they can provoke
+  out of order enqueuing of this packet and its followups with regards
+  to the already stored packets which may be scheduled for later times.
+  We thus need to adapt dequeue time for the already stored pkts to be
+  dequeued before the syncpoint pkt. See OS#3262 for related scenarios.
+   */
+
+   msg_ts = msgb_scheduled_ts(msg);
+
+   llist_for_each_entry(cur, >msg_list, list) {
+   struct timeval *cur_ts = msgb_scheduled_ts(cur);
+   if (timercmp(msg_ts, cur_ts, <))
+   *cur_ts = *msg_ts;
+   }
+   /* syncpoint goes always to the end since we moved all older packets
+  before it */
+   llist_add_tail(>list, >msg_list);
+}
+
 static bool msg_get_marker(struct msgb *msg)
 {
/* TODO: make it more generic as a callback so that different types of
@@ -314,11 +343,13 @@
 {
int rel_delay, delay;
struct timeval delay_ts, sched_ts;
+   bool is_syncpoint;

clock_gettime_timeval(CLOCK_MONOTONIC, >last_enqueue_time);

/* Check if it's time to sync, ie. start of talkspurt */
-   if (!jb->started || msg_is_syncpoint(jb, msg)) {
+   is_syncpoint = !jb->started || msg_is_syncpoint(jb, msg);
+   if (is_syncpoint) {
jb->started = true;
msg_set_as_reference(jb, msg);
rel_delay = 0;
@@ -365,8 +396,7 @@
jbcb->ts = sched_ts;
jbcb->old_cb = old_cb;

-   llist_add_sorted(msg, >msg_list);
-
+   enqueue_pkt(jb, msg, is_syncpoint);

/* See if updating the timer is needed: */
if (!osmo_timer_pending(>timer) ||
diff --git a/tests/jibuf/jibuf_test.c b/tests/jibuf/jibuf_test.c
index 7993a65..ba1bb01 100644
--- a/tests/jibuf/jibuf_test.c
+++ b/tests/jibuf/jibuf_test.c
@@ -673,8 +673,7 @@
clock_override_add(0, min_delay*1000);
osmo_select_main(0);

-   /* This assert shows that packets are queued out of order in this 
case:*/
-   OSMO_ASSERT(!osmo_jibuf_empty(jb));
+   OSMO_ASSERT(osmo_jibuf_empty(jb));

osmo_jibuf_delete(jb);
 }
diff --git a/tests/jibuf/jibuf_test.ok b/tests/jibuf/jibuf_test.ok
index 6bf52fb..b92f73c 100644
--- a/tests/jibuf/jibuf_test.ok
+++ b/tests/jibuf/jibuf_test.ok
@@ -383,10 +383,10 @@
 sys={0.14}, mono={0.14}: dequeue: seq=34 ts=720 INTERMEDIATE
 sys={0.14}, mono={0.14}: dequeue: seq=35 ts=880 INTERMEDIATE
 sys={0.14}, mono={0.14}: dequeue: seq=36 ts=1040 INTERMEDIATE
-sys={0.14}, mono={0.14}: dequeue: seq=39 ts=1520 INTERMEDIATE
 sys={0.14}, mono={0.14}: dequeue: seq=37 ts=1200 INTERMEDIATE
-sys={0.14}, mono={0.14}: dequeue: seq=40 ts=1680 LATEST
 sys={0.14}, mono={0.14}: dequeue: seq=38 ts=1360 INTERMEDIATE
+sys={0.14}, mono={0.14}: dequeue: seq=39 ts=1520 INTERMEDIATE
+sys={0.14}, mono={0.14}: dequeue: seq=40 ts=1680 LATEST
 ===test_rtp_out_of_sync(1600, 5, 800, 1)===
 sys={0.00}, mono={0.00}: clock_override_set
 sys={0.00}, mono={0.00}: enqueue 1st packet (seq=33, ts=560)

--
To view, visit https://gerrit.osmocom.org/9172
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
Gerrit-Change-Number: 9172
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol