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

[Minios-devel] [UNIKRAFT PATCH] lib/uksched: Add waiting queue


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Tue, 27 Mar 2018 12:41:57 +0300
  • Cc: simon.kuenzer@xxxxxxxxx
  • Delivery-date: Tue, 27 Mar 2018 10:19:37 +0000
  • Ironport-phdr: 9a23:Nu/uGhT95Zyxus35bSOmdFTjDNpsv+yvbD5Q0YIujvd0So/mwa6yZBaN2/xhgRfzUJnB7Loc0qyK6/umATRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfb1/IA+qoQnNq8IbnZZsJqEtxxXTv3BGYf5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbDVwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4qF2QxHqlSgHLSY0/mHJhMJtgqxVoxWvqgdjz4LIeoyZKOBzcr/Bcd4cWGFPXtxRVytEAo6kcYYPCPEBPfpZr4n7ulAAqwa+BRGxBOjyzTJHmnj23bYm0+QgFwHKxgggH88WsHTJt9j6KLwSXfqtzKnV1jrPdelW2TDk5YXObxsvoumMUKptfcfe1EUjDQDIg1WKpYD7IT+Y1P4BvmaD4+Z9Wu+jlnQrpgJxrzS12MshhIfEipgIxl3L6yl0xps+K8eiR05he9GkFYNdtySdN4RrXMwvW3pouCMmyr0evp67YTQKxIwnxxHBb/yHdJCF4gzmVOmLIDd4gGhpd66khxqo6Uig1/bzWtOu0FZNtiZFk9/MuW4R1xHL98SKReZx8l2i1DuPzQzf9P9ILEIumafVM5Ihx6Q/lpsXsUTNBC/2n0D2gbeKeUUj4eio9+XnYrP8qp+YKo90khz+P78ylcykG+g4KhUOUHOB9eSm073v5Vf5T6lSjv0qjqnZt4jXJcEapq6/Ag9V1Z0j5w+iADi4ztQXg30HIUlBeBKGlIjpJ0rOLOr3DPihhVSgijBrx+rJPrf5GJXCMmDDkKv9fbZ680Nc0wszzdVY55JSEL0BI+/zVVH3tN3ZEBA5KRe5w+D5B9ph0oMRQ3mADrWHP6PP4he04bcqIu+NY5RQtDvjJvwN4//1kWR/iVIbO66z0sg5cne9S99hOFmYZzLIn88cWTMBuREiTeqsjECaTBZYfDCqQqh6/DZtW9HuNpvKWo342O/J5yy8BJADPm0=
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/uksched/include/uk/wait.h       | 137 ++++++++++++++++++++++++++++++++++++
 lib/uksched/include/uk/wait_types.h |  51 ++++++++++++++
 2 files changed, 188 insertions(+)
 create mode 100644 lib/uksched/include/uk/wait.h
 create mode 100644 lib/uksched/include/uk/wait_types.h

diff --git a/lib/uksched/include/uk/wait.h b/lib/uksched/include/uk/wait.h
new file mode 100644
index 0000000..6032e46
--- /dev/null
+++ b/lib/uksched/include/uk/wait.h
@@ -0,0 +1,137 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``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 AUTHOR OR CONTRIBUTORS 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.
+ */
+/* Ported from Mini-OS */
+
+#ifndef __UK_SCHED_WAIT_H__
+#define __UK_SCHED_WAIT_H__
+
+#include <uk/plat/lcpu.h>
+#include <uk/plat/time.h>
+#include <uk/sched.h>
+#include <uk/wait_types.h>
+
+
+static inline
+void uk_waitq_init(struct uk_waitq *wq)
+{
+       UK_STAILQ_INIT(wq);
+}
+
+static inline
+void uk_waitq_entry_init(struct uk_waitq_entry *entry,
+               struct uk_thread *thread)
+{
+       entry->thread = thread;
+       entry->waiting = 0;
+}
+
+static inline
+int uk_waitq_empty(struct uk_waitq *wq)
+{
+       return UK_STAILQ_EMPTY(wq);
+}
+
+static inline
+void uk_waitq_add(struct uk_waitq *wq,
+               struct uk_waitq_entry *entry)
+{
+       if (!entry->waiting) {
+               UK_STAILQ_INSERT_HEAD(wq, entry, thread_list);
+               entry->waiting = 1;
+       }
+}
+
+static inline
+void uk_waitq_remove(struct uk_waitq *wq,
+               struct uk_waitq_entry *entry)
+{
+       if (entry->waiting) {
+               UK_STAILQ_REMOVE(wq, entry, struct uk_waitq_entry, thread_list);
+               entry->waiting = 0;
+       }
+}
+
+#define uk_waitq_add_waiter(wq, w) \
+do { \
+       unsigned long flags; \
+       flags = ukplat_lcpu_save_irqf(); \
+       uk_waitq_add(wq, w); \
+       uk_thread_block(uk_thread_current()); \
+       ukplat_lcpu_restore_irqf(flags); \
+} while (0)
+
+#define uk_waitq_remove_waiter(wq, w) \
+do { \
+       unsigned long flags; \
+       flags = ukplat_lcpu_save_irqf(); \
+       uk_waitq_remove(wq, w); \
+       ukplat_lcpu_restore_irqf(flags); \
+} while (0)
+
+#define __wq_wait_event_deadline(wq, condition, deadline, deadline_condition) \
+do { \
+       struct uk_thread *__current; \
+       unsigned long flags; \
+       DEFINE_WAIT(__wait); \
+       if (condition) \
+               break; \
+       for (;;) { \
+               __current = uk_thread_current(); \
+               /* protect the list */ \
+               flags = ukplat_lcpu_save_irqf(); \
+               uk_waitq_add(wq, &__wait); \
+               __current->wakeup_time = deadline; \
+               clear_runnable(__current); \
+               ukplat_lcpu_restore_irqf(flags); \
+               if ((condition) || (deadline_condition)) \
+                       break; \
+               uk_sched_yield(); \
+       } \
+       flags = ukplat_lcpu_save_irqf(); \
+       /* need to wake up */ \
+       uk_thread_wake(__current); \
+       uk_waitq_remove(wq, &__wait); \
+       ukplat_lcpu_restore_irqf(flags); \
+} while(0)
+
+#define uk_waitq_wait_event(wq, condition) \
+       __wq_wait_event_deadline(wq, (condition), 0, 0)
+
+#define uk_waitq_wait_event_deadline(wq, condition, deadline) \
+       __wq_wait_event_deadline(wq, (condition), \
+               (deadline), (deadline) && ukplat_monotonic_clock() >= 
(deadline))
+
+static inline
+void uk_waitq_wake_up(struct uk_waitq *wq)
+{
+       unsigned long flags;
+       struct uk_waitq_entry *curr, *tmp;
+
+       flags = ukplat_lcpu_save_irqf();
+       UK_STAILQ_FOREACH_SAFE(curr, wq, thread_list, tmp)
+               uk_thread_wake(curr->thread);
+       ukplat_lcpu_restore_irqf(flags);
+}
+
+#endif /* __UK_SCHED_WAIT_H__ */
diff --git a/lib/uksched/include/uk/wait_types.h 
b/lib/uksched/include/uk/wait_types.h
new file mode 100644
index 0000000..1ef5959
--- /dev/null
+++ b/lib/uksched/include/uk/wait_types.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``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 AUTHOR OR CONTRIBUTORS 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.
+ */
+/* Ported from Mini-OS */
+
+#ifndef __UK_SCHED_WAIT_TYPES_H__
+#define __UK_SCHED_WAIT_TYPES_H__
+
+#include <uk/list.h>
+
+struct uk_waitq_entry {
+       int waiting;
+       struct uk_thread *thread;
+       UK_STAILQ_ENTRY(struct uk_waitq_entry) thread_list;
+};
+
+/* TODO - lock required? */
+UK_STAILQ_HEAD(uk_waitq, struct uk_waitq_entry);
+
+#define __WAIT_QUEUE_INITIALIZER(name) UK_STAILQ_HEAD_INITIALIZER(name)
+
+#define DEFINE_WAIT_QUEUE(name) \
+       struct uk_waitq name = __WAIT_QUEUE_INITIALIZER(name)
+
+#define DEFINE_WAIT(name) \
+struct uk_waitq_entry name = { \
+       .thread       = uk_thread_current(), \
+       .waiting      = 0, \
+}
+
+#endif /* __UK_SCHED_WAIT_TYPES_H__ */
-- 
2.1.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.