N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/server/xen/sensor_node-xen.cpp

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 
00036 #include <xenctrl.h>
00037 #include <xenguest.h>
00038 #include <sensor_node.h>
00039 
00040 
00041 int Sensor_node::launch(node_t *node)
00042 {
00043         int error = 0;
00044         int handle = xc_interface_open();
00045         uint32_t ssidref;
00046         xen_domain_handle_t dom_handle;
00047         unsigned long store_mfn, console_mfn;
00048         unsigned int store_evtchn, console_evtchn;
00049         unsigned int vcpus, pae, acpi, apic;
00050 #ifdef XEN_3_0_4
00051         struct sched_credit_adjdom *slice;
00052 #else
00053         struct sched_credit_adjdom *slice;
00054 #endif
00055         double bogomips;
00056         FILE *cpuinfo;
00057         int len = 1024;
00058         char line[len];
00059 
00060         if ((error = 
00061              xc_domain_create(handle, ssidref, dom_handle, &thread_id)) < 0)
00062                 goto end;
00063 
00064         if (node->os_type == LINUX) {
00065                 error = xc_linux_build(handle, thread_id, 
00066                                        node->blkdev.image_path, 
00067                                        NULL, NULL, NULL, XCFLAGS_LIVE, 
00068                                        store_evtchn, &store_mfn, 
00069                                        console_evtchn, &console_mfn);
00070         } else if (node->os_type == EMULATED) {
00071                 vcpus = 1;
00072                 pae = acpi = apic = 0;
00073                 error = xc_hvm_build(handle, thread_id, node->memory_MB, 
00074                                      node->blkdev.image_path, 
00075                                      vcpus, pae, acpi, apic, 
00076                                      store_evtchn, &store_mfn);
00077         } else
00078                 error = -1;
00079 
00080         cpuinfo = fopen("/proc/cpuinfo", "r");
00082         while (fgets(line, len, cpuinfo) != NULL) {
00083                 if (strncmp(line, "bogomips", 8) == 0) {
00084                         char *mipstr = rindex(line, ':') + 2;
00085                         sscanf(mipstr, "%lf\n", &bogomips);
00086                 }
00087         }
00088         fclose(cpuinfo);
00089 
00090         xc_sched_credit_domain_get(handle, thread_id, slice);
00091         slice->cap = (int) bogomips / node->processor_MHz;
00092         xc_sched_credit_domain_set(handle, thread_id, slice);
00093 
00094  end:
00095         xc_interface_close(handle);
00096         return error;
00097 }
00098 
00099 
00100 
00101 int Sensor_node::pause()
00102 {
00103         int error = 0;
00104         int handle = xc_interface_open();
00105 
00106         error = xc_domain_pause(handle, thread_id);
00107 
00108         xc_interface_close(handle);
00109         return error;
00110 }
00111 
00112 
00113 int Sensor_node::unpause()
00114 {
00115         int error = 0;
00116         int handle = xc_interface_open();
00117 
00118         error = xc_domain_unpause(handle, thread_id);
00119 
00120         xc_interface_close(handle);
00121         return error;
00122 }
00123 
00124 
00125 
00126 int Sensor_node::save()
00127 {
00129         int io_fd, os_type, error = 0;
00130         uint32_t max_iters, max_factor;
00131         int (*suspend_fctn)(int domid);
00132         int xc_handle = xc_interface_open();
00133 
00134         if (os_type == LINUX) {
00135                 error = xc_linux_save(xc_handle, io_fd, thread_id, max_iters, 
00136                                       max_factor, XCFLAGS_LIVE, suspend_fctn);
00137         } else if (node->os_type == EMULATED) {
00138                 error = xc_hvm_save(xc_handle, io_fd, thread_id, max_iters,
00139                                     max_factor, XCFLAGS_LIVE, suspend_fctn);
00140         } else
00141                 error = -1;
00142 
00143         xc_interface_close(xc_handle);
00144         return error;
00145 }
00146 
00147 
00148 int Sensor_node::restore()
00149 {
00151         int io_fd, os_type, error = 0;
00152         unsigned long nr_pfns, store_mfn, console_mfn;
00153         unsigned int store_evtchn, console_evtchn;
00154         int xc_handle = xc_interface_open();
00155 
00156         if (os_type == LINUX) {
00157                 error = xc_linux_restore(xc_handle, io_fd, thread_id, nr_pfns,
00158                                          store_evtchn, &store_mfn,
00159                                          console_evtchn, &console_mfn);
00160         } else if (os_type == EMULATED) {
00161                 error = xc_hvm_restore(xc_handle, io_fd, thread_id, nr_pfns,
00162                                          store_evtchn, &store_mfn,
00163                                          console_evtchn, &console_mfn);
00164         } else
00165                 error = -1;
00166 
00167         xc_interface_close(xc_handle);
00168         return error;
00169 }


© 2007, Los Alamos National Security, LLC.