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

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


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 29 Mar 2018 19:03:38 +0300
  • Cc: Costin Lupu <costin.lup@xxxxxxxxx>, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Thu, 29 Mar 2018 16:03:50 +0000
  • Ironport-phdr: 9a23:JsYTrxJc2JPXRwxsBdmcpTZWNBhigK39O0sv0rFitYgeLPTxwZ3uMQTl6Ol3ixeRBMOHs6kC07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffwtFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhjoHOTAn/mHZicJ+g6xUrx2juxNxzJXZYJ2XOfdkYq/RYd0XSGhHU81MVyJBGIS8b44XAucfOuZYtJX9p1oIrRCjAwesGfvvyiJVjXLxwaI61P8hER3H3AwmBd4OtGnUrM3oNKoJTe+117PEzS3eb/xNwzv98o/IfwknrPqRXrxwadLcxVQgGg/YlFmdqozoMymL2ugTsWWX9eRtWfqyh2Motg19uDuiy8c2hoXXiI8YxErI+Th2zYorI9CzVVR1bsS+EJRKsiGXL452QsQ/TG52oCs60bgGuYKjfCgN1ZQn2wbTa/yZfIiM5RLuTPiRITJii3JkfLKznQq98VO6xu3kS8m7y0xGrjBCktXUt3AN0QLc6tSfR/dg8UqtxCyD2gPT5+1eP0w4i6jWJ4Qvz7Iok5ocq0XDHiv4mEXsi6+Wc10p9fSv6+T8frXmp5mcO5VwigHjKqQuh9eyDvgjMgQUR2ib5P+z2Kf5/U3+WLlKlOE5krHFsJDGIsQWvrK2AwhO0oY/6ha/CS2q0NAFnXkfN19FdxeHgJLoO1HKOvz3EfC/g1G0mjdx2//GJqHhAonKLnXblbfhfLB9609byAoo1NxQ+oxbCq8fL/L3QULxsN3YDgQlMwyv2ermB8ty1oUEVWKIGK+ZP7vYsUWU6eI3P+mMeIgVtS7mK/gk4v7uink5lUUefam0w5QXbnG5Eep8I0iCZ3rjnMsOEWMQsQUlVuDllkCCAnZvYCO3XqQ94Sp+BI+4AIPrQoG2nKfHzCq9WJpMaTNoEFeJRFzvbJmFXb8odTqPaptqlScYVL7nT5I5yDmlr0ni1rAhNO2CqX5Qjo7qyNUgv76brho17zEhV8k=
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Please ignore this patch and consider the next one.

Thanks,
Costin

On 03/29/2018 05:40 PM, Costin Lupu wrote:
> From: Costin Lupu <costin.lup@xxxxxxxxx>
> 
> Waiting queues are used for managing threads that wait for some
> condition to become true. The implementation was ported from Mini-OS.
> 
> Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
> ---
>  lib/uksched/include/uk/wait.h       | 138 
> ++++++++++++++++++++++++++++++++++++
>  lib/uksched/include/uk/wait_types.h |  51 +++++++++++++
>  2 files changed, 189 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..7ec5a20
> --- /dev/null
> +++ b/lib/uksched/include/uk/wait.h
> @@ -0,0 +1,138 @@
> +/* 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__ */
> 

_______________________________________________
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®.