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

[Minios-devel] [UNIKRAFT PATCH 12/23] plat/xen: Paravirtualization context - Yield thread to a previously interrupted thread


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 8 Jul 2019 11:33:41 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Mon, 08 Jul 2019 08:52:25 +0000
  • Ironport-phdr: 9a23:Dko1BhXDA4WWDzUsXMagPpGjqj3V8LGtZVwlr6E/grcLSJyIuqrYbRWEt8tkgFKBZ4jH8fUM07OQ7/m6HzBYqs7d+Fk5M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAiooQnLucQanYRuJro+xxDUvnZGZuNayH9yK1mOhRj8/MCw/JBi8yRUpf0s8tNLXLv5caolU7FWFSwqPG8p6sLlsxnDVhaP6WAHUmoKiBpIAhPK4w/8U5zsryb1rOt92C2dPc3rUbA5XCmp4ql3RBP0jioMKjg0+3zVhMNtlqJWuBKvqQJizYDaY4+bM/hxfq3GcN8GWWZMRNpdWjZdDo+gaYYEEuoPPfxfr4n4v1YDsxy+BRKwBOPuzD9Dm3n43bAi0+Q8DArL2xAvH9UVsHTIrdX1Mr0eUeSozKnQ0DXOdO9Z2Szn5IjQbxAuuuuAXah3ccfIz0QkCg3LjlKVqYP/PjOV0PwAvHad7+p8T+Kui28qpg5rrji03cghjJTCiIENyl3c6Cl0z5s5Kce7RUN7e9KoDoVcuiOAO4Z4Ws8uXm5ltDsgxrAFuZO3ZjYGxZopyhLFdvCKfJaE7xT+X+iLOzh4nmhqeLeniha39kiv1/PzW9Gv0FZPsipFit7Mtm0R1xDL6siIVP99/kC51DaR0gDc8OBEIUQumaXHMJ4t2KYwlocIvkjZBC/2n136jK6Qdko65uil8/nrb7r7qpOGNIJ5ihvyProwlsG9G+g1PBACX22B9uS90L3j81f5QLJPjvAujqbZt4vaJdgapq6/GQNV1psj6w6iDzq9zNsYhmMLLEpYeB2clYTpIVbOLOjiDfijm1SsjCtrx/feM73kA5XNKHnDkLD6fbpk9kFT1hQzws5b559PDrEBIenzWlPqtNDCAR42LQq0z/zgCNVn2YMUQXiPDbOBMKPOrV+I4foiI+eSa48RuTb9M+Yq6+TujX8kmF8SYaip0IARaH+mAvtmJ1+WbmH2jtgfDGcAphA+Q/DyiF2eTT5TYG6/X7k95jE+D4KmC53PRoOwgLOf2ie6H4NZZnpdB1CKD3jna4GEVO0XZy6IPMBhj29Mab/0To4n1Ba18QP31bdjBu7V4TED84Lu0p5y/eKAuws18GlfCN+B0mfFa3xsgytcTDgtwKF550hg0kqr2rM+m+FSU8ZUsaAaGjwmPILRmrQpQ+v5XRjMK4+E
  • Ironport-sdr: KP8pdoG0mKJoINqFP68DNoGyYcfL42AvwIUqArPR5DxKwyNHeIgJJWfhe3fyFWg4NtLTPAu7f9 SyGR6i22GHNA==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Saving the context for the yielding thread is the same as for software
contexts. Restoring the context and resuming the execution of the next thread
tries to mimic the same behaviour as for hardware contexts, but explicitly
enabling events before returning to user.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 plat/xen/Makefile.uk              |  1 +
 plat/xen/include/xen-x86/pv_ctx.h |  3 +++
 plat/xen/x86/entry64.S            | 18 ++++++++++++++++++
 plat/xen/x86/pv_ctx.c             |  2 ++
 4 files changed, 24 insertions(+)

diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 57589e6f..aaf645f5 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -55,6 +55,7 @@ LIBXENPLAT_ASFLAGS-y           += -DCONFIG_PARAVIRT
 LIBXENPLAT_CFLAGS-y            += -DCONFIG_PARAVIRT
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/cpu_pv.c
 ifeq ($(CONFIG_HAVE_SCHED_PREEMPT),y)
+LIBXENPLAT_ASINCLUDES-$(CONFIG_ARCH_X86_64) += -I$(UK_PLAT_COMMON_BASE)/x86
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += $(LIBXENPLAT_BASE)/x86/pv_ctx.c
 endif # CONFIG_HAVE_SCHED_PREEMPT
 else
diff --git a/plat/xen/include/xen-x86/pv_ctx.h 
b/plat/xen/include/xen-x86/pv_ctx.h
index c7a6fa63..b07c2be7 100644
--- a/plat/xen/include/xen-x86/pv_ctx.h
+++ b/plat/xen/include/xen-x86/pv_ctx.h
@@ -47,4 +47,7 @@ struct pv_ctx {
 void pv_ctx_callbacks_init(struct ukplat_ctx_callbacks *ctx_cbs);
 #endif
 
+#define OFFSETOF_SW_CTX_SP      0
+#define OFFSETOF_SW_CTX_IP      8
+
 #endif /* __PLAT_XEN_PV_CTX_H__ */
diff --git a/plat/xen/x86/entry64.S b/plat/xen/x86/entry64.S
index 0df593e5..c1bbdbe4 100644
--- a/plat/xen/x86/entry64.S
+++ b/plat/xen/x86/entry64.S
@@ -417,6 +417,24 @@ TRAP_ENTRY alignment_check,     1
 TRAP_ENTRY simd_error,          0
 /* no Virtualization Exception */
 
+#if CONFIG_HAVE_SCHED_PREEMPT
+#include "thread_macros.S"
+
+ENTRY(asm_pv_ctx_switch_yld2intd)
+       PROTECTED_REGS_SAVE                     # save current protected regs
+       movq %rsp, OFFSETOF_SW_CTX_SP(%rdi)     # save current SP
+       movq OFFSETOF_SW_CTX_SP(%rsi), %rsp     # restore next SP
+       movq $1f, OFFSETOF_SW_CTX_IP(%rdi)      # save current IP
+
+       XEN_GET_VCPU_INFO(%rax)                 # safe to use rax since it is 
saved
+       XEN_LOCKED_UNBLOCK_EVENTS(%rax)         # enable events
+
+       RESTORE_ALL
+       HYPERVISOR_IRET
+1:
+       PROTECTED_REGS_RESTORE
+       ret
+#endif /* CONFIG_HAVE_SCHED_PREEMPT */
 
 #ifndef CONFIG_PARAVIRT
 .data
diff --git a/plat/xen/x86/pv_ctx.c b/plat/xen/x86/pv_ctx.c
index 9203e6de..603fdf15 100644
--- a/plat/xen/x86/pv_ctx.c
+++ b/plat/xen/x86/pv_ctx.c
@@ -99,6 +99,7 @@ static void pv_ctx_start(void *ctx)
 }
 
 extern void asm_sw_ctx_switch(void *prevctx, void *nextctx);
+extern void asm_pv_ctx_switch_yld2intd(void *prevctx, void *nextctx);
 
 static void pv_ctx_switch(void *prevctx, void *nextctx)
 {
@@ -130,6 +131,7 @@ static void pv_ctx_switch(void *prevctx, void *nextctx)
                if (next_hw_ctx->interrupted) {
                        /* switching yielding to interrupted */
                        next_hw_ctx->interrupted = false;
+                       asm_pv_ctx_switch_yld2intd(prevctx, nextctx);
 
                } else
                        /* switching yielding to yielding */
-- 
2.20.1


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