1 /* Copyright (c) 2007-2012. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smx_private.h"
8 #include "xbt/sysdep.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix,
14 "Logging specific to SIMIX (vms)");
15 /* **** create a VM **** */
18 * \brief Internal function to create a SIMIX host.
19 * \param name name of the host to create
20 * \param data some user data (may be NULL)
22 smx_host_t SIMIX_vm_create(const char *name, smx_host_t phys_host)
25 smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1);
28 // TODO check why we do not have any VM here and why we have the host_proc_hookup ?
31 smx_host->data = NULL;
32 smx_host->process_list =
33 xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
35 /* Update global variables */
36 xbt_lib_set(host_lib,name,SIMIX_HOST_LEVEL,smx_host);
38 /* Create surf associated resource */
39 // TODO change phys_host into the right workstation surf model
40 surf_vm_workstation_model->extension.vm_workstation.create(name, phys_host);
42 return xbt_lib_get_elm_or_null(host_lib, name);
46 smx_host_t SIMIX_pre_vm_create(smx_simcall_t simcall, const char *name, smx_host_t phys_host){
47 return SIMIX_vm_create(name, phys_host);
51 /* **** start a VM **** */
52 int __can_be_started(smx_host_t vm){
53 // TODO add checking code related to overcommitment or not.
56 void SIMIX_vm_start(smx_host_t vm){
58 //TODO only start the VM if you can
59 if (can_be_started(vm))
60 SIMIX_set_vm_state(vm, msg_vm_state_running);
62 THROWF(vm_error, 0, "The VM %s cannot be started", SIMIX_host_get_name(vm));
65 void SIMIX_pre_vm_start(smx_simcall_t simcall, smx_host_t vm){
69 /* ***** set/get state of a VM ***** */
70 void SIMIX_set_vm_state(smx_host_t vm, int state){
71 surf_vm_workstation_model->extension.vm_workstation.set_state(vm, state);
73 void SIMIX_prev_set_vm_state(smx_host_t vm, int state){
74 SIMIX_set_vm_state(vm, state);
77 int SIMIX_get_vm_state(smx_host_t vm){
78 return surf_vm_workstation_model->extension.vm_workstation.get_state(vm);
80 int SIMIX_pre_vm_state(smx_host_t vm){
81 return SIMIX_get_vm_state(vm);
85 * \brief Function to destroy a SIMIX VM host.
87 * \param host the vm host to destroy (a smx_host_t)
89 void SIMIX_vm_destroy(smx_host_t host)
91 /* this code basically performs a similar thing like SIMIX_host_destroy() */
93 xbt_assert((host != NULL), "Invalid parameters");
94 char *hostname = host->key;
96 smx_host_priv_t host_priv = SIMIX_host_priv(host);
98 /* this will call the registered callback function, i.e., SIMIX_host_destroy(). */
99 xbt_lib_unset(host_lib, hostname, SIMIX_HOST_LEVEL);
101 /* jump to vm_ws_destroy(). The surf level resource will be freed. */
102 surf_vm_workstation_model->extension.vm_workstation.destroy(host);
105 void SIMIX_pre_vm_destroy(smx_simcall_t simcall, smx_host_t vm){
106 SIMIX_vm_destroy(vm);