lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [PATCH 3/3] Add a simple FIFO queueing discipline.


From: Russ Dill
Subject: [lwip-devel] [PATCH 3/3] Add a simple FIFO queueing discipline.
Date: Fri, 23 Oct 2015 04:58:09 -0700

This adds a very simple FIFO based queueing discipline. New packets are
dropped when the queue becomes full.

Signed-off-by: Russ Dill <address@hidden>
---
 src/include/lwip/opt.h   |   9 ++++
 src/include/sched/fifo.h |  61 ++++++++++++++++++++++++
 src/sched/fifo.c         | 121 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 191 insertions(+)
 create mode 100644 src/include/sched/fifo.h
 create mode 100644 src/sched/fifo.c

diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
index f87defa..d7776b1 100644
--- a/src/include/lwip/opt.h
+++ b/src/include/lwip/opt.h
@@ -1491,6 +1491,15 @@
 #define LWIP_SCHED                      0
 #endif
 
+/**
+ * LWIP_SCHED_FIFO==1: support the FIFO (first-in-first-out) scheduling
+ * discipline.
+ */
+#ifndef LWIP_SCHED_FIFO
+#define LWIP_SCHED_FIFO                 0
+#endif
+
+/*
    ------------------------------------
    ---------- Thread options ----------
    ------------------------------------
diff --git a/src/include/sched/fifo.h b/src/include/sched/fifo.h
new file mode 100644
index 0000000..f4aea16
--- /dev/null
+++ b/src/include/sched/fifo.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 Russ Dill <address@hidden>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without 
modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ *
+ * Author: Russ Dill <address@hidden>
+ *
+ */
+#ifndef LWIP_HDR_SCHED_FIFO_H
+#define LWIP_HDR_SCHED_FIFO_H
+
+#include "lwip/opt.h"
+
+#if LWIP_SCHED && LWIP_SCHED_FIFO
+
+#include "lwip/err.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct sched_queue;
+struct sched_packet;
+
+struct sched_queue_fifo {
+  struct sched_packet *head;
+  struct sched_packet *tail;
+};
+
+err_t sched_fifo_init(struct sched_queue *sq);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LWIP_SCHED && LWIP_SCHED_FIFO */
+
+#endif /* LWIP_HDR_SCHED_H */
diff --git a/src/sched/fifo.c b/src/sched/fifo.c
new file mode 100644
index 0000000..ece8c80
--- /dev/null
+++ b/src/sched/fifo.c
@@ -0,0 +1,121 @@
+/**
+ * @file
+ * lwIP network interface abstraction
+ *
+ */
+
+/*
+ * Copyright (c) 2015 Russ Dill <address@hidden>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without 
modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ *
+ * Author: Russ Dill <address@hidden>
+ *
+ */
+
+#include "lwip/opt.h"
+
+#if LWIP_SCHED_FIFO
+
+#include "lwip/sched.h"
+#include "sched/fifo.h"
+
+static int
+sched_fifo_empty(struct sched_queue *sq)
+{
+  struct sched_queue_fifo *fifo = sq->state;
+
+  return fifo->head == NULL;
+}
+
+static struct sched_packet *
+sched_fifo_peek(struct sched_queue *sq)
+{
+  struct sched_queue_fifo *fifo = sq->state;
+
+  return fifo->head;
+}
+
+static err_t
+sched_fifo_queue(struct sched_queue *sq, struct sched_packet *packet)
+{
+  struct sched_queue_fifo *fifo = sq->state;
+
+  /* Add to tail */
+  if (fifo->tail)
+    fifo->tail->next = packet;
+  else
+    fifo->head = packet;
+  fifo->tail = packet;
+
+  return ERR_OK;
+}
+
+static void
+sched_fifo_dequeue(struct sched_queue *sq, struct sched_packet *packet)
+{
+  struct sched_queue_fifo *fifo = sq->state;
+
+  LWIP_ASSERT("Peeked packet does not match queue\n", packet == fifo->head);
+
+  /* Pop item off head */
+  fifo->head = fifo->head->next;
+
+  /* Check if queue is now empty */
+  if (!fifo->head)
+    fifo->tail = NULL;
+}
+
+static void
+sched_fifo_drop_all(struct sched_queue *sq)
+{
+  struct sched_queue_fifo *fifo = sq->state;
+  struct sched_packet *curr;
+
+  for (curr = fifo->head; curr; curr = curr->next)
+    sched_drop(sq, curr);
+
+  fifo->head = fifo->tail = NULL;
+}
+
+err_t
+sched_fifo_init(struct sched_queue *sq)
+{
+  struct sched_queue_fifo *fifo;
+
+  sq->queue = sched_fifo_queue;
+  sq->empty = sched_fifo_empty;
+  sq->dequeue = sched_fifo_dequeue;
+  sq->peek = sched_fifo_peek;
+  sq->drop_all = sched_fifo_drop_all;
+
+  fifo = sq->state;
+  fifo->head = fifo->tail = NULL;
+
+  return ERR_OK;
+}
+
+#endif /* LWIP_SCHED_FIFO */
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]