From: Bruno Alvisio <bruno.alvisio@gmail.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: jgross@suse.com, samuel.thibault@ens-lyon.org,
wei.liu2@citrix.com, Bruno Alvisio <bruno.alvisio@gmail.com>
Subject: [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c
Date: Tue, 19 Dec 2017 15:42:00 -0800 [thread overview]
Message-ID: <1513726931-7516-6-git-send-email-bruno.alvisio@gmail.com> (raw)
In-Reply-To: <1513726931-7516-1-git-send-email-bruno.alvisio@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 6655 bytes --]
Created shutdown.c for the shutdown thread and all the shutdown related
functions.
Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
---
Makefile | 1 +
include/shutdown.h | 11 ++++
shutdown.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 200 insertions(+)
create mode 100644 include/shutdown.h
create mode 100644 shutdown.c
diff --git a/Makefile b/Makefile
index 88315c4..6a05de6 100644
--- a/Makefile
+++ b/Makefile
@@ -53,6 +53,7 @@ src-y += mm.c
src-$(CONFIG_NETFRONT) += netfront.c
src-$(CONFIG_PCIFRONT) += pcifront.c
src-y += sched.c
+src-y += shutdown.c
src-$(CONFIG_TEST) += test.c
src-$(CONFIG_BALLOON) += balloon.c
diff --git a/include/shutdown.h b/include/shutdown.h
new file mode 100644
index 0000000..a5ec019
--- /dev/null
+++ b/include/shutdown.h
@@ -0,0 +1,11 @@
+#ifndef _SHUTDOWN_H_
+#define _SHUTDOWN_H_
+
+#include <mini-os/hypervisor.h>
+
+void init_shutdown(start_info_t *si);
+
+void kernel_shutdown(int reason) __attribute__((noreturn));
+void kernel_suspend(void);
+
+#endif
diff --git a/shutdown.c b/shutdown.c
new file mode 100644
index 0000000..b3cea6d
--- /dev/null
+++ b/shutdown.c
@@ -0,0 +1,188 @@
+/*
+ * MiniOS
+ *
+ * file: fromdevice.cc
+ *
+ * NEC Europe Ltd. PROPRIETARY INFORMATION
+ *
+ * This software is supplied under the terms of a license agreement
+ * or nondisclosure agreement with NEC Europe Ltd. and may not be
+ * copied or disclosed except in accordance with the terms of that
+ * agreement. The software and its source code contain valuable trade
+ * secrets and confidential information which have to be maintained in
+ * confidence.
+ * Any unauthorized publication, transfer to third parties or duplication
+ * of the object or source code - either totally or in part – is
+ * prohibited.
+ *
+ * Copyright (c) 2014 NEC Europe Ltd. All Rights Reserved.
+ *
+ * Authors: Filipe Manco <filipe.manco@neclab.eu>
+ *
+ * NEC Europe Ltd. DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE AND THE WARRANTY AGAINST LATENT
+ * DEFECTS, WITH RESPECT TO THE PROGRAM AND THE ACCOMPANYING
+ * DOCUMENTATION.
+ *
+ * No Liability For Consequential Damages IN NO EVENT SHALL NEC Europe
+ * Ltd., NEC Corporation OR ANY OF ITS SUBSIDIARIES BE LIABLE FOR ANY
+ * DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
+ * OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION, OR
+ * OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL, INCIDENTAL,
+ * ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF OR INABILITY
+ * TO USE THIS PROGRAM, EVEN IF NEC Europe Ltd. HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+#include <mini-os/os.h>
+#include <mini-os/events.h>
+#include <mini-os/kernel.h>
+#include <mini-os/sched.h>
+#include <mini-os/shutdown.h>
+#include <mini-os/lib.h>
+#include <mini-os/xenbus.h>
+#include <mini-os/xmalloc.h>
+
+
+static start_info_t *start_info_ptr;
+
+static const char *path = "control/shutdown";
+static const char *token = "control/shutdown";
+static xenbus_event_queue events = NULL;
+static int end_shutdown_thread = 0;
+
+#ifdef CONFIG_XENBUS
+/* This should be overridden by the application we are linked against. */
+__attribute__((weak)) void app_shutdown(unsigned reason)
+{
+ printk("Shutdown requested: %d\n", reason);
+ if (reason == SHUTDOWN_suspend) {
+ kernel_suspend();
+ } else {
+ struct sched_shutdown sched_shutdown = { .reason = reason };
+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+ }
+}
+
+static void shutdown_thread(void *p)
+{
+ char *shutdown, *err;
+ unsigned int shutdown_reason;
+
+ xenbus_watch_path_token(XBT_NIL, path, token, &events);
+
+ for ( ;; ) {
+ xenbus_wait_for_watch(&events);
+ if ((err = xenbus_read(XBT_NIL, path, &shutdown))) {
+ free(err);
+ do_exit();
+ }
+
+ if (end_shutdown_thread)
+ break;
+
+ if (!strcmp(shutdown, "")) {
+ /* Avoid spurious event on xenbus */
+ /* FIXME: investigate the reason of the spurious event */
+ free(shutdown);
+ continue;
+ } else if (!strcmp(shutdown, "poweroff")) {
+ shutdown_reason = SHUTDOWN_poweroff;
+ } else if (!strcmp(shutdown, "reboot")) {
+ shutdown_reason = SHUTDOWN_reboot;
+ } else if (!strcmp(shutdown, "suspend")) {
+ shutdown_reason = SHUTDOWN_suspend;
+ } else {
+ shutdown_reason = SHUTDOWN_crash;
+ }
+ free(shutdown);
+
+ /* Acknowledge shutdown request */
+ if ((err = xenbus_write(XBT_NIL, path, ""))) {
+ free(err);
+ do_exit();
+ }
+
+ app_shutdown(shutdown_reason);
+ }
+}
+#endif
+
+static void fini_shutdown(void)
+{
+ char *err;
+
+ end_shutdown_thread = 1;
+ xenbus_release_wait_for_watch(&events);
+ err = xenbus_unwatch_path_token(XBT_NIL, path, token);
+ if (err) {
+ free(err);
+ do_exit();
+ }
+}
+
+void init_shutdown(start_info_t *si)
+{
+ start_info_ptr = si;
+
+ end_shutdown_thread = 0;
+ create_thread("shutdown", shutdown_thread, NULL);
+}
+
+void kernel_shutdown(int reason)
+{
+ char* reason_str = NULL;
+
+ switch(reason) {
+ case SHUTDOWN_poweroff:
+ reason_str = "poweroff";
+ break;
+ case SHUTDOWN_reboot:
+ reason_str = "reboot";
+ break;
+ case SHUTDOWN_crash:
+ reason_str = "crash";
+ break;
+ default:
+ do_exit();
+ break;
+ }
+
+ printk("MiniOS will shutdown (reason = %s) ...\n", reason_str);
+
+ fini_shutdown();
+
+ stop_kernel();
+
+ for ( ;; ) {
+ struct sched_shutdown sched_shutdown = { .reason = reason };
+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+ }
+}
+
+void kernel_suspend(void)
+{
+ int rc;
+
+ printk("MiniOS will suspend ...\n");
+
+ pre_suspend();
+ arch_pre_suspend();
+
+ /*
+ * This hypercall returns 1 if the suspend
+ * was cancelled and 0 if resuming in a new domain
+ */
+ rc = HYPERVISOR_suspend(virt_to_mfn(start_info_ptr));
+
+ arch_post_suspend(rc);
+ post_suspend(rc);
+
+ if (rc) {
+ printk("MiniOS suspend canceled!");
+ } else {
+ printk("MiniOS resumed from suspend!\n");
+ }
+}
--
2.3.2 (Apple Git-55)
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2017-12-19 23:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-19 23:41 [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Bruno Alvisio
2017-12-19 23:41 ` [PATCH RFC 01/16] Save/Restore Support: Refactor HYPERVISOR_suspend hypercall Bruno Alvisio
2017-12-19 23:51 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:41 ` [PATCH RFC 02/16] Save/Restore Support: Refactor trap_init() and setup vector callbacks Bruno Alvisio
2017-12-19 23:51 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:41 ` [PATCH RFC 03/16] Save/Restore Support: Declare kernel and arch pre/post suspend functions Bruno Alvisio
2017-12-19 23:52 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:41 ` [PATCH RFC 04/16] Save/Restore Support: Add xenbus_release_wait_for_watch Bruno Alvisio
2017-12-20 0:14 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` Bruno Alvisio [this message]
2017-12-20 0:16 ` [Minios-devel] [PATCH RFC 05/16] Save/Restore Support: Add kernel shutdown logic to shutdown.c Samuel Thibault
2017-12-21 22:49 ` Konrad Rzeszutek Wilk
2017-12-19 23:42 ` [PATCH RFC 06/16] Save/Restore Support: Moved shutdown thread " Bruno Alvisio
2017-12-19 23:42 ` [PATCH RFC 07/16] Save/Restore Support: Add unmap_shared_info Bruno Alvisio
2017-12-20 0:23 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 08/16] Save/Restore Support: Add arch_mm_pre|post_suspend Bruno Alvisio
2017-12-20 0:24 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 09/16] Save/Restore Support: Disable/enable IRQs during suspend/restore Bruno Alvisio
2017-12-20 0:25 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 10/16] Save/Restore Support: Add suspend/resume support for timers Bruno Alvisio
2017-12-20 0:26 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 11/16] Save/Restore Support: Add suspend/restore support for console Bruno Alvisio
2017-12-19 23:42 ` [PATCH RFC 12/16] Save/Restore Support: Add support for suspend/restore events Bruno Alvisio
2017-12-20 0:37 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 13/16] Save/Restore Support: Add suspend/restore support for Grant Tables Bruno Alvisio
2017-12-20 0:40 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 14/16] Save/Restore Support: Add suspend/restore support for xenbus Bruno Alvisio
2017-12-20 0:43 ` [Minios-devel] " Samuel Thibault
2017-12-19 23:42 ` [PATCH RFC 15/16] Save/Restore Support: Add suspend/restore support for netfront Bruno Alvisio
2017-12-19 23:42 ` [PATCH RFC 16/16] Save/Restore Support: Implement code for arch suspend/resume Bruno Alvisio
2017-12-20 0:19 ` [Minios-devel] [PATCH RFC 00/16] Save/Restore Support for mini-OS PVH Samuel Thibault
2017-12-20 0:37 ` Samuel Thibault
2017-12-20 0:57 ` Samuel Thibault
2017-12-20 1:01 ` Samuel Thibault
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1513726931-7516-6-git-send-email-bruno.alvisio@gmail.com \
--to=bruno.alvisio@gmail.com \
--cc=jgross@suse.com \
--cc=minios-devel@lists.xenproject.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).