aboutsummaryrefslogtreecommitdiffstats
path: root/src/llc.cpp
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2013-12-04 18:11:47 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-12-25 14:55:04 +0100
commit9c623892f5bb2bcc058a43c4d18aa2ce3bff2383 (patch)
tree7ae3832b24d8cb6181d72d65b7f3fd444057078c /src/llc.cpp
parenta42b2ad5ed6b71457c87651e24b01ba6dfb92d22 (diff)
llc: Calculate the average queuing delay of the LLC queues
Use a formula like it is used with TCP. This can help to make decisions about if frames should be dropped or not at the time we enqueue them. This code will store two timeval structs in fron the of the actual data and compute the average at the time of the dequeue.
Diffstat (limited to 'src/llc.cpp')
-rw-r--r--src/llc.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/llc.cpp b/src/llc.cpp
index c557584c..2d295f86 100644
--- a/src/llc.cpp
+++ b/src/llc.cpp
@@ -78,14 +78,34 @@ void gprs_llc::init()
{
INIT_LLIST_HEAD(&queue);
m_queue_size = 0;
+ m_avg_queue_delay = 0;
reset();
}
+#define ALPHA 0.5f
+
struct msgb *gprs_llc::dequeue()
{
- if (m_queue_size > 0)
- m_queue_size -= 1;
- return msgb_dequeue(&queue);
+ struct msgb *msg;
+ struct timeval *tv, tv_now, tv_result;
+ uint32_t lifetime;
+
+
+ msg = msgb_dequeue(&queue);
+ if (!msg)
+ return NULL;
+
+ m_queue_size -= 1;
+
+ /* take the second time */
+ gettimeofday(&tv_now, NULL);
+ tv = (struct timeval *)&msg->data[sizeof(*tv)];
+ timersub(&tv_now, tv, &tv_result);
+
+ lifetime = tv_result.tv_sec*1000 + tv_result.tv_usec/1000;
+ m_avg_queue_delay = m_avg_queue_delay * ALPHA + lifetime * (1-ALPHA);
+
+ return msg;
}