[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 10/17] plat/common: Common x86 threading code
We define a new primitive - the software context - used in context switching for cooperative scheduling and scheduling on PV guests. The code for Xen platform is reused to enable cooperative scheduling on KVM as well. Since Unikraft may run different schedulers on dedicated CPUs, a new abstraction is introduced, ukplat_ctx_callbacks, for enabling support of other types of contexts as well (e.g. hardware contexts for preemptive scheduling). Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- include/uk/arch/thread.h | 53 ----------------- include/uk/plat/thread.h | 70 +++++++++++++++++++--- plat/common/include/sw_ctx.h | 56 ++++++++++++++++++ plat/common/sw_ctx.c | 97 +++++++++++++++++++++++++++++++ plat/common/thread.c | 66 +++++++++++++++++++++ plat/common/x86/thread_start.S | 65 +++++++++++++++++++++ plat/kvm/Makefile.uk | 5 ++ plat/xen/Makefile.uk | 8 ++- plat/xen/include/common/sched.h | 52 ----------------- plat/xen/include/xen-x86/arch_sched.h | 55 ------------------ plat/xen/sched.c | 106 ---------------------------------- plat/xen/thread.c | 66 --------------------- plat/xen/x86/arch_thread.c | 93 ----------------------------- plat/xen/x86/entry64.S | 31 ---------- plat/xen/x86/setup.c | 3 - 15 files changed, 357 insertions(+), 469 deletions(-) delete mode 100644 include/uk/arch/thread.h create mode 100644 plat/common/include/sw_ctx.h create mode 100644 plat/common/sw_ctx.c create mode 100644 plat/common/thread.c create mode 100644 plat/common/x86/thread_start.S delete mode 100644 plat/xen/include/common/sched.h delete mode 100644 plat/xen/include/xen-x86/arch_sched.h delete mode 100644 plat/xen/sched.c delete mode 100644 plat/xen/thread.c delete mode 100644 plat/xen/x86/arch_thread.c diff --git a/include/uk/arch/thread.h b/include/uk/arch/thread.h deleted file mode 100644 index 7a10d2a..0000000 --- a/include/uk/arch/thread.h +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Authors: Costin Lupu <costin.lupu@xxxxxxxxx> - * - * - * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. 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. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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. - * - * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. - */ - -#ifndef __UKARCH_THREAD_H__ -#define __UKARCH_THREAD_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -struct ukplat_thread_ctx { - /* keep in that order */ - unsigned long sp; /* Stack pointer */ - unsigned long ip; /* Instruction pointer */ -}; - -#ifdef __cplusplus -} -#endif - -#endif /* __UKARCH_THREAD_H__ */ diff --git a/include/uk/plat/thread.h b/include/uk/plat/thread.h index 905d942..69fc5e2 100644 --- a/include/uk/plat/thread.h +++ b/include/uk/plat/thread.h @@ -38,17 +38,73 @@ #ifndef __UKPLAT_THREAD_H__ #define __UKPLAT_THREAD_H__ -#include <uk/arch/thread.h> +#include <stdlib.h> #include <uk/essentials.h> +#include <uk/assert.h> -int ukplat_thread_ctx_init(struct ukplat_thread_ctx *ctx, void *stack, - void (*function)(void *), void *data); +enum ukplat_ctx_type { + ukplat_ctx_none, + ukplat_ctx_hw, + ukplat_ctx_sw, +}; -void ukplat_thread_ctx_switch(struct ukplat_thread_ctx *prev, - struct ukplat_thread_ctx *next); +struct uk_alloc; -struct ukplat_thread_ctx *ukplat_thread_ctx_current(void); +typedef void *(*ukplat_ctx_create_func_t) + (struct uk_alloc *allocator, unsigned long sp); +typedef void (*ukplat_ctx_start_func_t) + (void *ctx); +typedef void (*ukplat_ctx_switch_func_t) + (void *prevctx, void *nextctx); -void ukplat_thread_ctx_run_idle(struct ukplat_thread_ctx *ctx) __noreturn; +struct ukplat_ctx_callbacks { + /* callback for creating thread context */ + ukplat_ctx_create_func_t create_cb; + /* callback for starting thread context */ + ukplat_ctx_start_func_t start_cb __noreturn; + /* callback for switching contexts */ + ukplat_ctx_switch_func_t switch_cb; +}; + +int ukplat_ctx_callbacks_init(struct ukplat_ctx_callbacks *ctx_cbs, + enum ukplat_ctx_type ctx_type); + + +static inline +void *ukplat_thread_ctx_create(struct ukplat_ctx_callbacks *cbs, + struct uk_alloc *allocator, unsigned long sp) +{ + UK_ASSERT(cbs != NULL); + UK_ASSERT(allocator != NULL); + + return cbs->create_cb(allocator, sp); +} + +void ukplat_thread_ctx_destroy(struct uk_alloc *allocator, void *ctx); + +static inline +void ukplat_thread_ctx_start(struct ukplat_ctx_callbacks *cbs, + void *ctx) __noreturn; + +static inline +void ukplat_thread_ctx_start(struct ukplat_ctx_callbacks *cbs, + void *ctx) +{ + UK_ASSERT(cbs != NULL); + UK_ASSERT(ctx != NULL); + + cbs->start_cb(ctx); +} + +static inline +void ukplat_thread_ctx_switch(struct ukplat_ctx_callbacks *cbs, + void *prevctx, void *nextctx) +{ + UK_ASSERT(cbs != NULL); + UK_ASSERT(prevctx != NULL); + UK_ASSERT(nextctx != NULL); + + cbs->switch_cb(prevctx, nextctx); +} #endif /* __UKPLAT_THREAD_H__ */ diff --git a/plat/common/include/sw_ctx.h b/plat/common/include/sw_ctx.h new file mode 100644 index 0000000..fae96be --- /dev/null +++ b/plat/common/include/sw_ctx.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Costin Lupu <costin.lupu@xxxxxxxxx> + * + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ +#ifndef __PLAT_CMN_SW_CTX_H__ +#define __PLAT_CMN_SW_CTX_H__ + +#ifndef __ASSEMBLY__ +#include <uk/plat/thread.h> + +struct sw_ctx { + unsigned long sp; /* Stack pointer */ + unsigned long ip; /* Instruction pointer */ +}; + +void sw_ctx_callbacks_init(struct ukplat_ctx_callbacks *ctx_cbs); +#endif + +#define OFFSETOF_SW_CTX_SP 0 +#define OFFSETOF_SW_CTX_IP 8 + +#define SIZEOF_SW_CTX 8 + +/* TODO This should be better defined in the thread header */ +#define OFFSETOF_UKTHREAD_SW_CTX 16 + +#endif /* __PLAT_CMN_SW_CTX_H__ */ diff --git a/plat/common/sw_ctx.c b/plat/common/sw_ctx.c new file mode 100644 index 0000000..5913769 --- /dev/null +++ b/plat/common/sw_ctx.c @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Costin Lupu <costin.lupu@xxxxxxxxx> + * + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#include <stdlib.h> +#include <uk/plat/thread.h> +#include <uk/alloc.h> +#include <sw_ctx.h> +#include <uk/assert.h> + + +static void *sw_ctx_create(struct uk_alloc *allocator, unsigned long sp); +static void sw_ctx_start(void *ctx) __noreturn; +static void sw_ctx_switch(void *prevctx, void *nextctx); + + +/* Gets run when a new thread is scheduled the first time ever, + * defined in x86_[32/64].S + */ +extern void asm_thread_starter(void); + +static void *sw_ctx_create(struct uk_alloc *allocator, unsigned long sp) +{ + struct sw_ctx *ctx; + + UK_ASSERT(allocator != NULL); + + ctx = uk_malloc(allocator, sizeof(struct sw_ctx)); + if (ctx == NULL) { + uk_printd(DLVL_WARN, "Error allocating software context."); + return NULL; + } + + ctx->sp = sp; + ctx->ip = (unsigned long) asm_thread_starter; + + return ctx; +} + +extern void asm_ctx_start(unsigned long sp, unsigned long ip) __noreturn; + +static void sw_ctx_start(void *ctx) +{ + struct sw_ctx *sw_ctx = ctx; + + UK_ASSERT(sw_ctx != NULL); + + /* Switch stacks and run the thread */ + asm_ctx_start(sw_ctx->sp, sw_ctx->ip); + + UK_CRASH("Thread did not start."); +} + +extern void asm_sw_ctx_switch(void *prevctx, void *nextctx); + +static void sw_ctx_switch(void *prevctx, void *nextctx) +{ + asm_sw_ctx_switch(prevctx, nextctx); +} + +void sw_ctx_callbacks_init(struct ukplat_ctx_callbacks *ctx_cbs) +{ + UK_ASSERT(ctx_cbs != NULL); + ctx_cbs->create_cb = sw_ctx_create; + ctx_cbs->start_cb = sw_ctx_start; + ctx_cbs->switch_cb = sw_ctx_switch; +} diff --git a/plat/common/thread.c b/plat/common/thread.c new file mode 100644 index 0000000..702338e --- /dev/null +++ b/plat/common/thread.c @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Costin Lupu <costin.lupu@xxxxxxxxx> + * + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. 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. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#include <stdlib.h> +#include <uk/plat/thread.h> +#include <uk/alloc.h> +#include <sw_ctx.h> +#include <uk/assert.h> + +void ukplat_thread_ctx_destroy(struct uk_alloc *allocator, void *ctx) +{ + UK_ASSERT(allocator != NULL); + UK_ASSERT(ctx != NULL); + + uk_free(allocator, ctx); +} + +int ukplat_ctx_callbacks_init(struct ukplat_ctx_callbacks *ctx_cbs, + enum ukplat_ctx_type ctx_type) +{ + int err = 0; + + UK_ASSERT(ctx_cbs != NULL); + + switch (ctx_type) { + case ukplat_ctx_sw: + sw_ctx_callbacks_init(ctx_cbs); + break; + default: + err = EINVAL; + break; + } + + return err; +} diff --git a/plat/common/x86/thread_start.S b/plat/common/x86/thread_start.S new file mode 100644 index 0000000..a6ab297 --- /dev/null +++ b/plat/common/x86/thread_start.S @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (c) 2009, Citrix Systems, Inc. + * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. + * + * 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. + */ +/* Taken from Mini-OS arch/x86/x86_64.S */ + +#include <sw_ctx.h> + +#define ENTRY(X) .globl X ; X : + +ENTRY(asm_thread_starter) + popq %rdi + popq %rbx + pushq $0 + xorq %rbp,%rbp + call *%rbx + call uk_sched_thread_exit + +ENTRY(asm_ctx_start) + mov %rdi, %rsp /* set SP */ + push %rsi /* push IP and return */ + ret + +ENTRY(asm_sw_ctx_switch) + pushq %rbp + pushq %rbx + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + movq %rsp, OFFSETOF_SW_CTX_SP(%rdi) /* save ESP */ + movq OFFSETOF_SW_CTX_SP(%rsi), %rsp /* restore ESP */ + movq $1f, OFFSETOF_SW_CTX_IP(%rdi) /* save EIP */ + pushq OFFSETOF_SW_CTX_IP(%rsi) /* restore EIP */ + ret +1: + popq %r15 + popq %r14 + popq %r13 + popq %r12 + popq %rbx + popq %rbp + ret diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk index 433d298..823e785 100644 --- a/plat/kvm/Makefile.uk +++ b/plat/kvm/Makefile.uk @@ -16,6 +16,11 @@ LIBKVMPLAT_ASINCLUDES-y += -I$(UK_PLAT_COMMON_BASE)/include LIBKVMPLAT_CINCLUDES-y += -I$(LIBKVMPLAT_BASE)/include LIBKVMPLAT_CINCLUDES-y += -I$(UK_PLAT_COMMON_BASE)/include +ifeq ($(HAVE_SCHED),y) +LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/thread_start.S|common +LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/thread.c|common +LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/sw_ctx.c|common +endif LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/entry64.S LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/cpu_x86_64.c LIBKVMPLAT_SRCS-$(ARCH_X86_64) += $(LIBKVMPLAT_BASE)/x86/setup.c diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk index 7cb55dc..4a2f9bf 100644 --- a/plat/xen/Makefile.uk +++ b/plat/xen/Makefile.uk @@ -32,6 +32,11 @@ LIBXENPLAT_SRCS-y += $(UK_PLAT_COMMON_BASE)/lcpu.c|common ifneq (,$(filter x86_32 x86_64,$(UK_ARCH))) LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/trace.c|common LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/traps.c|common +ifeq ($(HAVE_SCHED),y) +LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/x86/thread_start.S|common +LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/thread.c|common +LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(UK_PLAT_COMMON_BASE)/sw_ctx.c|common +endif LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/x86/setup.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/x86/traps.c LIBXENPLAT_SRCS-$(ARCH_X86_32) += $(LIBXENPLAT_BASE)/x86/entry32.S @@ -39,7 +44,6 @@ LIBXENPLAT_SRCS-$(ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/entry64.S LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/x86/mm.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/x86/arch_events.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/x86/arch_time.c -LIBXENPLAT_SRCS-$(LIBUKSCHED) += $(LIBXENPLAT_BASE)/x86/arch_thread.c ifneq ($(XEN_HVMLITE),y) LIBXENPLAT_ASFLAGS-y += -DCONFIG_PARAVIRT @@ -65,5 +69,3 @@ LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/lcpu.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/console.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/shutdown.c LIBXENPLAT_SRCS-y += $(LIBXENPLAT_BASE)/events.c -LIBXENPLAT_SRCS-$(LIBUKSCHED) += $(LIBXENPLAT_BASE)/thread.c -LIBXENPLAT_SRCS-$(LIBUKSCHED) += $(LIBXENPLAT_BASE)/sched.c diff --git a/plat/xen/include/common/sched.h b/plat/xen/include/common/sched.h deleted file mode 100644 index 12df1bb..0000000 --- a/plat/xen/include/common/sched.h +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (c) 2009 Citrix Systems, Inc. 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. - * - * 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. - */ -/* - * Port from Mini-OS: include/sched.h - */ - -#ifndef __SCHED_H__ -#define __SCHED_H__ - -#include <stdint.h> -#ifdef HAVE_LIBC -#include <sys/reent.h> -#endif -#include <xen-x86/arch_sched.h> -#include <uk/essentials.h> -#include <uk/list.h> -#include <uk/thread.h> - -#define switch_threads(prev, next) arch_switch_threads(prev, next) - -/* Architecture specific setup of thread creation. */ -void arch_thread_init(struct ukplat_thread_ctx *thread, void *stack, - void (*function)(void *), void *data); -void arch_run_idle_thread(struct ukplat_thread_ctx *idle_thread) __noreturn; - -/* TODO revisit for other schedulers */ -void exit_thread(void) __noreturn; - -#endif /* __SCHED_H__ */ diff --git a/plat/xen/include/xen-x86/arch_sched.h b/plat/xen/include/xen-x86/arch_sched.h deleted file mode 100644 index 6f714e8..0000000 --- a/plat/xen/include/xen-x86/arch_sched.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (c) 2009 Citrix Systems, Inc. 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. - * - * 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. - */ -/* - * Port from Mini-OS: include/x86/arch_sched.h - */ - -#ifndef __ARCH_SCHED_H__ -#define __ARCH_SCHED_H__ - -#include "uk/arch/limits.h" - -static inline struct ukplat_thread_ctx *get_current_ctx(void) -{ - struct ukplat_thread_ctx **current; -#ifdef __i386__ - register unsigned long sp asm("esp"); -#else - register unsigned long sp asm("rsp"); -#endif - current = (struct ukplat_thread_ctx **) - (unsigned long)(sp & ~(__STACK_SIZE-1)); - - return *current; -} - -extern void __arch_switch_threads(unsigned long *prevctx, - unsigned long *nextctx); - -#define arch_switch_threads(prev, next) \ - __arch_switch_threads(&(prev)->sp, &(next)->sp) - -#endif /* __ARCH_SCHED_H__ */ diff --git a/plat/xen/sched.c b/plat/xen/sched.c deleted file mode 100644 index 2a4015e..0000000 --- a/plat/xen/sched.c +++ /dev/null @@ -1,106 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - **************************************************************************** - * (C) 2005 - Grzegorz Milos - Intel Research Cambridge - **************************************************************************** - * - * File: sched.c - * Author: Grzegorz Milos - * Changes: Robert Kaiser - * - * Date: Aug 2005 - * - * Environment: Xen Minimal OS - * Description: simple scheduler for Mini-Os - * Ported from Mini-OS - * - * The scheduler is non-preemptive (cooperative), and schedules according - * to Round Robin algorithm. - * - **************************************************************************** - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include <stdlib.h> -#include <stdint.h> -#include <common/hypervisor.h> -#include <common/sched.h> -#include <xen-x86/irq.h> -#include <uk/sched.h> -#include <uk/list.h> -#include <uk/assert.h> - - -#ifdef SCHED_DEBUG -#define DEBUG(_f, _a...) \ - uk_printk("MINI_OS(file=sched.c, line=%d) " _f "\n", __LINE__, ## _a) -#else -#define DEBUG(_f, _a...) ((void)0) -#endif - -#if 0//TODO revisit -#ifdef HAVE_LIBC -static struct _reent callback_reent; -struct _reent *__getreent(void) -{ - struct _reent *_reent; - - if (!threads_started) - _reent = _impure_ptr; - else if (in_callback) - _reent = &callback_reent; - else - _reent = &get_current_ctx()->reent; - -#ifndef NDEBUG -#if defined(__x86_64__) || defined(__x86__) - { -#ifdef __x86_64__ - register unsigned long sp asm ("rsp"); -#else - register unsigned long sp asm ("esp"); -#endif - if ((sp & (STACK_SIZE-1)) < STACK_SIZE / 16) { - static int overflowing; - - if (!overflowing) { - overflowing = 1; - uk_printk("stack overflow\n"); - UC_BUG(); - } - } - } -#endif -#else -#error Not implemented yet -#endif - return _reent; -} -#endif -#endif - -void exit_thread(void) -{ - struct uk_thread *thread = uk_thread_current(); - - uk_printk("Thread \"%s\" exited.\n", thread->name); - - uk_thread_stop(thread); - UK_CRASH("Error stopping thread."); -} diff --git a/plat/xen/thread.c b/plat/xen/thread.c deleted file mode 100644 index 51f33d4..0000000 --- a/plat/xen/thread.c +++ /dev/null @@ -1,66 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Authors: Costin Lupu <costin.lupu@xxxxxxxxx> - * - * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. 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. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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. - * - * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. - */ -/* - * Platform specific thread functions - * Ported from Mini-OS - */ - -#include <uk/sched.h> -#include <uk/plat/thread.h> -#include <common/sched.h> - -int ukplat_thread_ctx_init(struct ukplat_thread_ctx *ctx, void *stack, - void (*function)(void *), void *data) -{ - /* Call architecture specific setup. */ - arch_thread_init(ctx, stack, function, data); - - return 0; -} - -void ukplat_thread_ctx_switch(struct ukplat_thread_ctx *prev, - struct ukplat_thread_ctx *next) -{ - switch_threads(prev, next); -} - -struct ukplat_thread_ctx *ukplat_thread_ctx_current(void) -{ - return get_current_ctx(); -} - -void ukplat_thread_ctx_run_idle(struct ukplat_thread_ctx *ctx) -{ - arch_run_idle_thread(ctx); -} diff --git a/plat/xen/x86/arch_thread.c b/plat/xen/x86/arch_thread.c deleted file mode 100644 index 6522bd5..0000000 --- a/plat/xen/x86/arch_thread.c +++ /dev/null @@ -1,93 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - **************************************************************************** - * (C) 2005 - Grzegorz Milos - Intel Research Cambridge - **************************************************************************** - * - * File: sched.c - * Author: Grzegorz Milos - * Changes: Robert Kaiser - * - * Date: Aug 2005 - * - * Environment: Xen Minimal OS - * Description: simple scheduler for Mini-Os - * Ported from Mini-OS - * - * The scheduler is non-preemptive (cooperative), and schedules according - * to Round Robin algorithm. - * - **************************************************************************** - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include <stdlib.h> -#include <uk/arch/thread.h> -#include <uk/plat/config.h> -#include <uk/assert.h> - - -/* Gets run when a new thread is scheduled the first time ever, - * defined in x86_[32/64].S - */ -extern void thread_starter(void); - -/* Pushes the specified value onto the stack of the specified thread */ -static void stack_push(struct ukplat_thread_ctx *ctx, unsigned long value) -{ - ctx->sp -= sizeof(unsigned long); - *((unsigned long *) ctx->sp) = value; -} - -/* Architecture specific setup of thread creation */ -void arch_thread_init(struct ukplat_thread_ctx *ctx, void *stack, - void (*function)(void *), void *data) -{ - UK_ASSERT(ctx != NULL); - UK_ASSERT(stack != NULL); - - ctx->sp = (unsigned long) stack + STACK_SIZE; - /* Save pointer to the thread on the stack, used by current macro */ - *((unsigned long *) stack) = (unsigned long) ctx; - - /* Must ensure that (%rsp + 8) is 16-byte aligned - * at the start of thread_starter. - */ - ctx->sp -= sizeof(unsigned long); - - stack_push(ctx, (unsigned long) function); - stack_push(ctx, (unsigned long) data); - ctx->ip = (unsigned long) thread_starter; -} - -void arch_run_idle_thread(struct ukplat_thread_ctx *ctx) -{ - /* Switch stacks and run the thread */ - __asm__ __volatile__( -#if defined(__i386__) - "mov %0,%%esp\n\t" -#elif defined(__x86_64__) - "mov %0,%%rsp\n\t" -#endif - "push %1\n\t" - "ret" - : "=m" (ctx->sp) - : "m" (ctx->ip) - ); -} diff --git a/plat/xen/x86/entry64.S b/plat/xen/x86/entry64.S index db9c615..c266804 100644 --- a/plat/xen/x86/entry64.S +++ b/plat/xen/x86/entry64.S @@ -340,37 +340,6 @@ TRAP_ENTRY simd_error, 0 /* no Virtualization Exception */ -#if HAVE_SCHED -ENTRY(thread_starter) - popq %rdi - popq %rbx - pushq $0 - xorq %rbp,%rbp - call *%rbx - call exit_thread - -ENTRY(__arch_switch_threads) - pushq %rbp - pushq %rbx - pushq %r12 - pushq %r13 - pushq %r14 - pushq %r15 - movq %rsp, (%rdi) /* save ESP */ - movq (%rsi), %rsp /* restore ESP */ - movq $1f, 8(%rdi) /* save EIP */ - pushq 8(%rsi) /* restore EIP */ - ret -1: - popq %r15 - popq %r14 - popq %r13 - popq %r12 - popq %rbx - popq %rbp - ret -#endif - #ifndef CONFIG_PARAVIRT .data .globl page_table_base diff --git a/plat/xen/x86/setup.c b/plat/xen/x86/setup.c index 10f939d..1e0f0f7 100644 --- a/plat/xen/x86/setup.c +++ b/plat/xen/x86/setup.c @@ -78,9 +78,6 @@ #include <xen/xen.h> #include <common/console.h> #include <common/events.h> -#if LIBUKSCHED -#include <common/sched.h> -#endif #ifdef __X86_64__ #include <xen-x86/hypercall64.h> #else -- 2.1.4 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |