+++ /dev/null
-/* Copyright (c) 2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef _SURF_CPU_CAS01_PRIVATE_H
-#define _SURF_CPU_CAS01_PRIVATE_H
-
-#undef GENERIC_LMM_ACTION
-#undef GENERIC_ACTION
-#undef ACTION_GET_CPU
-#define GENERIC_LMM_ACTION(action) action->generic_lmm_action
-#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
-#define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_t) action)->cpu
-
-typedef struct surf_action_cpu_cas01 {
- s_surf_action_lmm_t generic_lmm_action;
-} s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t;
-
-/*
- * Energy-related properties for the cpu_cas01 model
- */
-typedef struct energy_cpu_cas01 {
- xbt_dynar_t power_range_watts_list; /*< List of (min_power,max_power) pairs corresponding to each cpu pstate */
- double total_energy; /*< Total energy consumed by the host */
- double last_updated; /*< Timestamp of the last energy update event*/
-} s_energy_cpu_cas01_t, *energy_cpu_cas01_t;
-
-
-typedef struct cpu_Cas01 {
- s_surf_resource_t generic_resource;
- s_xbt_swag_hookup_t modified_cpu_hookup;
- double power_peak;
- double power_scale;
- tmgr_trace_event_t power_event;
- int core;
- e_surf_resource_state_t state_current;
- tmgr_trace_event_t state_event;
- lmm_constraint_t constraint;
-
- xbt_dynar_t power_peak_list; /*< List of supported CPU capacities */
- int pstate; /*< Current pstate (index in the power_peak_list)*/
- energy_cpu_cas01_t energy;
-
- /* Note (hypervisor): */
- lmm_constraint_t *constraint_core;
-
-} s_cpu_Cas01_t, *cpu_Cas01_t;
-
-void *cpu_cas01_create_resource(const char *name,
- xbt_dynar_t power_peak,
- int pstate,
- double power_scale,
- tmgr_trace_t power_trace,
- int core,
- e_surf_resource_state_t state_initial,
- tmgr_trace_t state_trace,
- xbt_dict_t cpu_properties,
- surf_model_t cpu_model);
-
-xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model);
-void cpu_update_energy(cpu_Cas01_t cpu_model, double cpu_load);
-
-#endif /* _SURF_CPU_CAS01_PRIVATE_H */
+++ /dev/null
-/* Copyright (c) 2008-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "surf_private.h"
-#include "surf/random_mgr.h"
-#include "xbt/dict.h"
-#include "xbt/str.h"
-#include "xbt/log.h"
-
-typedef struct surf_action_network_Constant {
- s_surf_action_t generic_action;
- double latency;
- double lat_init;
- int suspended;
-} s_surf_action_network_Constant_t, *surf_action_network_Constant_t;
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
-static int host_number_int = 0;
-
-static void netcste_count_hosts(sg_platf_host_cbarg_t h) {
- host_number_int++;
-}
-
-static void netcste_define_callbacks(void) {
- sg_platf_host_add_cb(netcste_count_hosts);
-}
-
-static int netcste_resource_used(void *resource_id)
-{
- return 0;
-}
-
-static int netcste_action_unref(surf_action_t action)
-{
- action->refcount--;
- if (!action->refcount) {
- xbt_swag_remove(action, action->state_set);
- surf_action_free(&action);
- return 1;
- }
- return 0;
-}
-
-static void netcste_action_cancel(surf_action_t action)
-{
- return;
-}
-
-static double netcste_share_resources(surf_model_t network_model, double now)
-{
- surf_action_network_Constant_t action = NULL;
- xbt_swag_t running_actions =
- network_model->states.running_action_set;
- double min = -1.0;
-
- xbt_swag_foreach(action, running_actions) {
- if (action->latency > 0) {
- if (min < 0)
- min = action->latency;
- else if (action->latency < min)
- min = action->latency;
- }
- }
-
- return min;
-}
-
-static void netcste_update_actions_state(surf_model_t network_model, double now, double delta)
-{
- surf_action_network_Constant_t action = NULL;
- surf_action_network_Constant_t next_action = NULL;
- xbt_swag_t running_actions =
- network_model->states.running_action_set;
-
- xbt_swag_foreach_safe(action, next_action, running_actions) {
- if (action->latency > 0) {
- if (action->latency > delta) {
- double_update(&(action->latency), delta);
- } else {
- action->latency = 0.0;
- }
- }
- double_update(&(action->generic_action.remains),
- action->generic_action.cost * delta / action->lat_init);
- if (action->generic_action.max_duration != NO_MAX_DURATION)
- double_update(&(action->generic_action.max_duration), delta);
-
- if (action->generic_action.remains <= 0) {
- action->generic_action.finish = surf_get_clock();
- network_model->action_state_set((surf_action_t) action,
- SURF_ACTION_DONE);
- } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
- && (action->generic_action.max_duration <= 0)) {
- action->generic_action.finish = surf_get_clock();
- network_model->action_state_set((surf_action_t) action,
- SURF_ACTION_DONE);
- }
- }
-}
-
-static void netcste_update_resource_state(void *id,
- tmgr_trace_event_t event_type,
- double value, double time)
-{
- DIE_IMPOSSIBLE;
-}
-
-static surf_action_t netcste_communicate(sg_routing_edge_t src,
- sg_routing_edge_t dst,
- double size, double rate)
-{
- surf_action_network_Constant_t action = NULL;
-
- char *src_name = src->name;
- char *dst_name = dst->name;
-
- XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
-
- action =
- surf_action_new(sizeof(s_surf_action_network_Constant_t), size,
- surf_network_model, 0);
-
- action->suspended = 0;
-
- action->latency = sg_latency_factor;
- action->lat_init = action->latency;
-
- if (action->latency <= 0.0) {
- action->generic_action.state_set =
- surf_network_model->states.done_action_set;
- xbt_swag_insert(action, action->generic_action.state_set);
- }
-
- XBT_OUT();
-
- return (surf_action_t) action;
-}
-
-#ifdef HAVE_TRACING
-static void netcste_action_set_category(surf_action_t action, const char *category)
-{
- //ignore completely the categories in constant model, they are not traced
-}
-#endif
-
-static double netcste_get_link_bandwidth(const void *link)
-{
- DIE_IMPOSSIBLE;
- return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
-}
-
-static double netcste_get_link_latency(const void *link)
-{
- DIE_IMPOSSIBLE;
- return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
-}
-
-static int link_shared(const void *link)
-{
- DIE_IMPOSSIBLE;
- return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
-}
-
-static void netcste_action_suspend(surf_action_t action)
-{
- ((surf_action_network_Constant_t) action)->suspended = 1;
-}
-
-static void netcste_action_resume(surf_action_t action)
-{
- if (((surf_action_network_Constant_t) action)->suspended)
- ((surf_action_network_Constant_t) action)->suspended = 0;
-}
-
-static int netcste_action_is_suspended(surf_action_t action)
-{
- return ((surf_action_network_Constant_t) action)->suspended;
-}
-
-static void netcste_finalize(surf_model_t network_model)
-{
- surf_model_exit(network_model);
- network_model = NULL;
-}
-
-
-
-void surf_network_model_init_Constant()
-{
- xbt_assert(surf_network_model == NULL);
- if (surf_network_model)
- return;
- surf_network_model = surf_model_init();
-
- surf_network_model->name = "constant time network";
- surf_network_model->action_unref = netcste_action_unref;
- surf_network_model->action_cancel = netcste_action_cancel;
- surf_network_model->action_recycle = net_action_recycle;
- surf_network_model->get_remains = surf_action_get_remains;
-#ifdef HAVE_LATENCY_BOUND_TRACKING
- surf_network_model->get_latency_limited = net_get_link_latency_limited;
-#endif
-
- surf_network_model->model_private->resource_used = netcste_resource_used;
- surf_network_model->model_private->share_resources =
- netcste_share_resources;
- surf_network_model->model_private->update_actions_state =
- netcste_update_actions_state;
- surf_network_model->model_private->update_resource_state =
- netcste_update_resource_state;
- surf_network_model->model_private->finalize = netcste_finalize;
-
- surf_network_model->suspend = netcste_action_suspend;
- surf_network_model->resume = netcste_action_resume;
- surf_network_model->is_suspended = netcste_action_is_suspended;
-
- xbt_assert(surf_cpu_model_pm);
- xbt_assert(surf_cpu_model_vm);
- surf_cpu_model_pm->set_max_duration = surf_action_set_max_duration;
- surf_cpu_model_vm->set_max_duration = surf_action_set_max_duration;
-
- surf_network_model->extension.network.communicate = netcste_communicate;
- surf_network_model->extension.network.get_link_bandwidth =
- netcste_get_link_bandwidth;
- surf_network_model->extension.network.get_link_latency =
- netcste_get_link_latency;
- surf_network_model->extension.network.link_shared = link_shared;
-#ifdef HAVE_TRACING
- surf_network_model->set_category = netcste_action_set_category;
-#endif
-
- netcste_define_callbacks();
- xbt_dynar_push(model_list, &surf_network_model);
-
- routing_model_create(NULL);
-}
+++ /dev/null
-/* Copyright (c) 2004-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-/* ********************************************************************* */
-/* TUTORIAL: New model */
-/* ********************************************************************* */
-
-#include "xbt/ex.h"
-#include "xbt/dict.h"
-#include "portable.h"
-#include "surf_private.h"
-#include "new_model_private.h"
-#include "surf/surf_resource.h"
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_new_model, surf,
- "Logging specific to the SURF new model module");
-
-surf_model_t surf_new_model = NULL;
-lmm_system_t new_model_maxmin_system = NULL;
-static int new_model_selective_update = 0;
-static xbt_swag_t
- new_model_running_action_set_that_does_not_need_being_checked = NULL;
-
-#define GENERIC_LMM_ACTION(action) action->generic_lmm_action
-#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
-
-static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state);
-
-static surf_action_t new_model_action_execute ()
-{
- THROW_UNIMPLEMENTED;
- return NULL;
-}
-
-static surf_action_t new_model_action_fct()
-{
- surf_action_t action = new_model_action_execute();
- return action;
-}
-
-static void* new_model_create_resource(const char* id, const char* model,const char* type_id,const char* content_name)
-{
- THROW_UNIMPLEMENTED;
- return NULL;
-}
-
-static void new_model_finalize(surf_model_t new_model)
-{
- lmm_system_free(new_model_maxmin_system);
- new_model_maxmin_system = NULL;
-
- surf_model_exit(new_model);
- new_model = NULL;
-
- xbt_swag_free
- (new_model_running_action_set_that_does_not_need_being_checked);
- new_model_running_action_set_that_does_not_need_being_checked = NULL;
-}
-
-static void new_model_update_actions_state(surf_model_t new_model, double now, double delta)
-{
- return;
-}
-
-static double new_model_share_resources(surf_model_t new_model, double NOW)
-{
- return -1;
-}
-
-static int new_model_resource_used(void *resource_id)
-{
- THROW_UNIMPLEMENTED;
- return 0;
-}
-
-static void new_model_resources_state(void *id, tmgr_trace_event_t event_type,
- double value, double time)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static int new_model_action_unref(surf_action_t action)
-{
- THROW_UNIMPLEMENTED;
- return 0;
-}
-
-static void new_model_action_cancel(surf_action_t action)
-{
- surf_action_state_set(action, SURF_ACTION_FAILED);
- return;
-}
-
-static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state)
-{
- surf_action_state_set(action, state);
- return;
-}
-
-static void new_model_action_suspend(surf_action_t action)
-{
- XBT_IN("(%p)", action);
- if (((surf_action_lmm_t) action)->suspended != 2) {
- lmm_update_variable_weight(new_model_maxmin_system,
- ((surf_action_lmm_t) action)->variable,
- 0.0);
- ((surf_action_lmm_t) action)->suspended = 1;
- }
- XBT_OUT();
-}
-
-static void new_model_action_resume(surf_action_t action)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static int new_model_action_is_suspended(surf_action_t action)
-{
- return (((surf_action_lmm_t) action)->suspended == 1);
-}
-
-static void new_model_action_set_max_duration(surf_action_t action, double duration)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static void new_model_action_set_priority(surf_action_t action, double priority)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static void new_model_define_callbacks()
-{
-}
-
-static void surf_new_model_init_internal(void)
-{
- s_surf_action_t action;
-
- XBT_DEBUG("surf_new_model_model_init_internal");
- surf_new_model = surf_model_init();
-
- new_model_running_action_set_that_does_not_need_being_checked =
- xbt_swag_new(xbt_swag_offset(action, state_hookup));
-
- surf_new_model->name = "New Model";
- surf_new_model->type = SURF_MODEL_TYPE_NEW_MODEL;
- surf_new_model->action_unref = new_model_action_unref;
- surf_new_model->action_cancel = new_model_action_cancel;
- surf_new_model->action_state_set = new_model_action_state_set;
-
- surf_new_model->model_private->finalize = new_model_finalize;
- surf_new_model->model_private->update_actions_state = new_model_update_actions_state;
- surf_new_model->model_private->share_resources = new_model_share_resources;
- surf_new_model->model_private->resource_used = new_model_resource_used;
- surf_new_model->model_private->update_resource_state = new_model_resources_state;
-
- surf_new_model->suspend = new_model_action_suspend;
- surf_new_model->resume = new_model_action_resume;
- surf_new_model->is_suspended = new_model_action_is_suspended;
- surf_new_model->set_max_duration = new_model_action_set_max_duration;
- surf_new_model->set_priority = new_model_action_set_priority;
-
- surf_new_model->extension.new_model.fct = new_model_action_fct;
- surf_new_model->extension.new_model.create_resource = new_model_create_resource;
-
- if (!new_model_maxmin_system) {
- new_model_maxmin_system = lmm_system_new(new_model_selective_update);
- }
-
-}
-
-void surf_new_model_init_default(void)
-{
- surf_new_model_init_internal();
- new_model_define_callbacks();
-
- xbt_dynar_push(model_list, &surf_new_model);
-}
+++ /dev/null
-/* Copyright (c) 2004-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "xbt/ex.h"
-#include "xbt/dict.h"
-#include "portable.h"
-#include "surf_private.h"
-#include "storage_private.h"
-#include "surf/surf_resource.h"
-#include <inttypes.h>
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
- "Logging specific to the SURF storage module");
-
-xbt_lib_t storage_lib;
-int ROUTING_STORAGE_LEVEL; //Routing for storagelevel
-int ROUTING_STORAGE_HOST_LEVEL;
-int SURF_STORAGE_LEVEL;
-xbt_lib_t storage_type_lib;
-int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level
-
-xbt_dynar_t mount_list = NULL; /* temporary store of current mount storage */
-
-surf_model_t surf_storage_model = NULL;
-lmm_system_t storage_maxmin_system = NULL;
-static int storage_selective_update = 0;
-static xbt_swag_t
- storage_running_action_set_that_does_not_need_being_checked = NULL;
-
-static xbt_dynar_t storage_list;
-
-#define GENERIC_LMM_ACTION(action) action->generic_lmm_action
-#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
-
-static xbt_dict_t parse_storage_content(char *filename, sg_storage_size_t *used_size);
-static int storage_action_unref(surf_action_t action);
-static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state);
-static surf_action_t storage_action_execute (void *storage, sg_storage_size_t size, e_surf_action_storage_type_t type);
-
-static surf_action_t storage_action_ls(void *storage, const char* path)
-{
- surf_action_t action = storage_action_execute(storage,0, LS);
- action->ls_dict = NULL;
- xbt_dict_t ls_dict = xbt_dict_new_homogeneous(xbt_free);
-
- char* key;
- sg_storage_size_t size = 0;
- xbt_dict_cursor_t cursor = NULL;
-
- xbt_dynar_t dyn = NULL;
- char* file = NULL;
-
- // for each file in the storage content
- xbt_dict_foreach(((storage_t)storage)->content,cursor,key,size){
- // Search if file start with the prefix 'path'
- if(xbt_str_start_with(key,path)){
- file = &key[strlen(path)];
-
- // Split file with '/'
- dyn = xbt_str_split(file,"/");
- file = xbt_dynar_get_as(dyn,0,char*);
-
- // file
- if(xbt_dynar_length(dyn) == 1){
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t,1);
- *psize=size;
- xbt_dict_set(ls_dict,file,psize,NULL);
- }
- // Directory
- else
- {
- // if directory does not exist yet in the dictionary
- if(!xbt_dict_get_or_null(ls_dict,file))
- xbt_dict_set(ls_dict,file,NULL,NULL);
- }
- xbt_dynar_free(&dyn);
- }
- }
-
- action->ls_dict = ls_dict;
- return action;
-}
-
-static surf_action_t storage_action_open(void *storage, const char* mount,
- const char* path)
-{
- XBT_DEBUG("\tOpen file '%s'",path);
- xbt_dict_t content_dict = ((storage_t)storage)->content;
- sg_storage_size_t size, *psize;
- psize = (sg_storage_size_t*) xbt_dict_get_or_null(content_dict, path);
- if (psize)
- size = *psize;
- else {
- // if file does not exist create an empty file
- psize = xbt_new(sg_storage_size_t,1);
- size = 0;
- *psize = size;
- xbt_dict_set(content_dict,path,psize,NULL);
- XBT_DEBUG("File '%s' was not found, file created.",path);
- }
- surf_file_t file = xbt_new0(s_surf_file_t,1);
- file->name = xbt_strdup(path);
- file->size = size;
- file->mount = xbt_strdup(mount);
-
- surf_action_t action = storage_action_execute(storage,0, OPEN);
- action->file = (void *)file;
- return action;
-}
-
-static surf_action_t storage_action_close(void *storage, surf_file_t fd)
-{
- char *filename = fd->name;
- XBT_DEBUG("\tClose file '%s' size '%" PRIu64 "'", filename, fd->size);
- // unref write actions from storage
- surf_action_storage_t write_action;
- unsigned int i;
- xbt_dynar_foreach(((storage_t)storage)->write_actions,i,write_action) {
- if ((write_action->generic_lmm_action.generic_action.file) == fd) {
- xbt_dynar_cursor_rm(((storage_t)storage)->write_actions, &i);
- storage_action_unref((surf_action_t) write_action);
- }
- }
- free(fd->name);
- free(fd->mount);
- xbt_free(fd);
- surf_action_t action = storage_action_execute(storage,0, CLOSE);
- return action;
-}
-
-static surf_action_t storage_action_read(void *storage, surf_file_t fd, sg_storage_size_t size)
-{
- if(size > fd->size)
- size = fd->size;
- surf_action_t action = storage_action_execute(storage,size,READ);
- return action;
-}
-
-static surf_action_t storage_action_write(void *storage, surf_file_t fd, sg_storage_size_t size)
-{
- char *filename = fd->name;
- XBT_DEBUG("\tWrite file '%s' size '%" PRIu64 "/%" PRIu64 "'",
- filename, size, fd->size);
-
- surf_action_t action = storage_action_execute(storage,size,WRITE);
- action->file = fd;
-
- // If the storage is full
- if(((storage_t)storage)->used_size==((storage_t)storage)->size) {
- storage_action_state_set((surf_action_t) action, SURF_ACTION_FAILED);
- }
- return action;
-}
-
-static surf_action_t storage_action_execute (void *storage, sg_storage_size_t size, e_surf_action_storage_type_t type)
-{
- surf_action_storage_t action = NULL;
- storage_t STORAGE = storage;
-
- XBT_IN("(%s,%" PRIu64, surf_resource_name(STORAGE), size);
- action =
- surf_action_new(sizeof(s_surf_action_storage_t), size, surf_storage_model,
- STORAGE->state_current != SURF_RESOURCE_ON);
-
- // Save the storage on action
- action->storage = storage;
- GENERIC_LMM_ACTION(action).suspended = 0; /* Should be useless because of the
- calloc but it seems to help valgrind... */
-
- GENERIC_LMM_ACTION(action).variable =
- lmm_variable_new(storage_maxmin_system, action, 1.0, -1.0 , 3);
-
- // Must be less than the max bandwidth for all actions
- lmm_expand(storage_maxmin_system, STORAGE->constraint,
- GENERIC_LMM_ACTION(action).variable, 1.0);
-
- switch(type) {
- case OPEN:
- case CLOSE:
- case STAT:
- case LS:
- break;
- case READ:
- lmm_expand(storage_maxmin_system, STORAGE->constraint_read,
- GENERIC_LMM_ACTION(action).variable, 1.0);
- break;
- case WRITE:
- lmm_expand(storage_maxmin_system, STORAGE->constraint_write,
- GENERIC_LMM_ACTION(action).variable, 1.0);
- xbt_dynar_push(((storage_t)storage)->write_actions,&action);
- surf_action_ref((surf_action_t) action);
- break;
- }
- action->type = type;
- XBT_OUT();
- return (surf_action_t) action;
-}
-
-static xbt_dict_t storage_get_properties(const void *storage)
-{
- return surf_resource_properties(surf_storage_resource_priv(storage));
-}
-
-static xbt_dict_t storage_get_content(void *storage)
-{
- /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
- /*surf_action_t action = storage_action_execute(storage,0, LS);*/
-
- void *storage_resource = surf_storage_resource_priv(storage);
- xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
- xbt_dict_cursor_t cursor = NULL;
- char *file;
- sg_storage_size_t *psize;
-
- xbt_dict_foreach(((storage_t)storage_resource)->content, cursor, file, psize){
- xbt_dict_set(content_dict,file,psize,NULL);
- }
- return content_dict;
-}
-
-static sg_storage_size_t storage_get_size(void *storage){
- void *storage_resource = surf_storage_resource_priv(storage);
- return ((storage_t)storage_resource)->size;
-}
-
-static void storage_file_rename(void *storage, const char *src, const char *dest)
-{
- void *storage_resource = surf_storage_resource_priv(storage);
-
- sg_storage_size_t *psize, *new_psize;
- psize = (sg_storage_size_t*) xbt_dict_get_or_null(((storage_t)storage_resource)->content,src);
- new_psize = xbt_new(sg_storage_size_t, 1);
- *new_psize = *psize;
- if (psize){// src file exists
- xbt_dict_remove(((storage_t)storage_resource)->content, src);
- xbt_dict_set(((storage_t)storage_resource)->content, dest, new_psize,NULL);
- XBT_DEBUG("Change file name from %s to %s, size '%" PRIu64 "'",src, dest, *psize);
- }
- else
- XBT_DEBUG("File %s doesn't exist",src);
-}
-
-
-static void* storage_create_resource(const char* id, const char* model,
- const char* type_id, const char* content_name, const char* content_type, xbt_dict_t properties){
- storage_t storage = NULL;
-
- xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)),
- "Storage '%s' declared several times in the platform file",
- id);
- storage = (storage_t) surf_resource_new(sizeof(s_storage_t),
- surf_storage_model, id, properties, NULL);
-
- storage->state_current = SURF_RESOURCE_ON;
- storage->used_size = 0;
- storage->size = 0;
- storage->write_actions = xbt_dynar_new(sizeof(char *),NULL);
-
- storage_type_t storage_type = xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL);
- double Bread =
- surf_parse_get_bandwidth(xbt_dict_get(storage_type->properties,"Bread"));
- double Bwrite =
- surf_parse_get_bandwidth(xbt_dict_get(storage_type->properties,"Bwrite"));
- double Bconnection =
- surf_parse_get_bandwidth(xbt_dict_get(storage_type->properties,
- "Bconnection"));
- XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'",Bconnection,Bread,Bwrite,(unsigned long)storage_type->size);
- storage->constraint = lmm_constraint_new(storage_maxmin_system, storage, Bconnection);
- storage->constraint_read = lmm_constraint_new(storage_maxmin_system, storage, Bread);
- storage->constraint_write = lmm_constraint_new(storage_maxmin_system, storage, Bwrite);
- storage->content = parse_storage_content((char*)content_name,&(storage->used_size));
- storage->content_type = xbt_strdup(content_type);
- storage->size = storage_type->size;
- storage->type_id = xbt_strdup(type_id);
-
- xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
-
- XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tproperties '%p'\n\t\tBread '%f'\n",
- id,
- model,
- type_id,
- storage_type->properties,
- Bread);
-
- if (!storage_list)
- storage_list = xbt_dynar_new(sizeof(char *),NULL);
- xbt_dynar_push(storage_list,&storage);
-
- return storage;
-}
-
-static void storage_finalize(surf_model_t storage_model)
-{
- lmm_system_free(storage_maxmin_system);
- storage_maxmin_system = NULL;
-
- surf_model_exit(storage_model);
- storage_model = NULL;
-
- xbt_dynar_free(&storage_list);
-
- xbt_swag_free
- (storage_running_action_set_that_does_not_need_being_checked);
- storage_running_action_set_that_does_not_need_being_checked = NULL;
-}
-
-static void storage_update_actions_state(surf_model_t storage_model, double now, double delta)
-{
- surf_action_storage_t action = NULL;
- surf_action_storage_t next_action = NULL;
- xbt_swag_t running_actions = storage_model->states.running_action_set;
-
-
- xbt_swag_foreach_safe(action, next_action, running_actions) {
- if(action->type == WRITE)
- {
- // Update the disk usage
- // Update the file size
- // Update the storage content (with file size)
- double rate = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
- /* Hack to avoid rounding differences between x86 and x86_64
- * (note that the next sizes are of type sg_storage_size_t). */
- long incr = delta * rate + MAXMIN_PRECISION;
- ((storage_t)(action->storage))->used_size += incr; // disk usage
- ((surf_action_t)action)->file->size += incr; // file size
-
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t,1);
- *psize = ((surf_action_t)action)->file->size;
-
- xbt_dict_t content_dict = ((storage_t)(action->storage))->content;
- xbt_dict_set(content_dict,((surf_action_t)action)->file->name,psize,NULL);
- }
-
- double_update(&(GENERIC_ACTION(action).remains),
- lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
-
- if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
- double_update(&(GENERIC_ACTION(action).max_duration), delta);
-
- if(GENERIC_ACTION(action).remains > 0 &&
- lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0 &&
- ((storage_t)action->storage)->used_size == ((storage_t)action->storage)->size)
- {
- GENERIC_ACTION(action).finish = surf_get_clock();
- storage_action_state_set((surf_action_t) action, SURF_ACTION_FAILED);
- } else if ((GENERIC_ACTION(action).remains <= 0) &&
- (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0))
- {
- GENERIC_ACTION(action).finish = surf_get_clock();
- storage_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
- } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
- (GENERIC_ACTION(action).max_duration <= 0))
- {
- GENERIC_ACTION(action).finish = surf_get_clock();
- storage_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
- }
- }
-
- return;
-}
-
-static double storage_share_resources(surf_model_t storage_model, double NOW)
-{
- XBT_DEBUG("storage_share_resources %f",NOW);
- s_surf_action_storage_t action;
- unsigned int i,j;
- storage_t storage;
- surf_action_storage_t write_action;
-
- double min_completion = generic_maxmin_share_resources(storage_model->states.running_action_set,
- xbt_swag_offset(action, generic_lmm_action.variable),
- storage_maxmin_system, lmm_solve);
-
- double rate;
- // Foreach disk
- xbt_dynar_foreach(storage_list,i,storage)
- {
- rate = 0;
- // Foreach write action on disk
- xbt_dynar_foreach(storage->write_actions,j,write_action)
- {
- rate += lmm_variable_getvalue(write_action->generic_lmm_action.variable);
- }
- if(rate > 0)
- min_completion = MIN(min_completion, (storage->size-storage->used_size)/rate);
- }
-
- return min_completion;
-}
-
-static int storage_resource_used(void *resource_id)
-{
- THROW_UNIMPLEMENTED;
- return 0;
-}
-
-static void storage_resources_state(void *id, tmgr_trace_event_t event_type,
- double value, double time)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static int storage_action_unref(surf_action_t action)
-{
- action->refcount--;
- if (!action->refcount) {
- xbt_swag_remove(action, action->state_set);
- if (((surf_action_lmm_t) action)->variable)
- lmm_variable_free(storage_maxmin_system,
- ((surf_action_lmm_t) action)->variable);
-#ifdef HAVE_TRACING
- xbt_free(action->category);
-#endif
- surf_action_free(&action);
- return 1;
- }
- return 0;
-}
-
-static void storage_action_cancel(surf_action_t action)
-{
- surf_action_state_set(action, SURF_ACTION_FAILED);
- return;
-}
-
-static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state)
-{
- surf_action_state_set(action, state);
- return;
-}
-
-static void storage_action_suspend(surf_action_t action)
-{
- XBT_IN("(%p)", action);
- if (((surf_action_lmm_t) action)->suspended != 2) {
- lmm_update_variable_weight(storage_maxmin_system,
- ((surf_action_lmm_t) action)->variable,
- 0.0);
- ((surf_action_lmm_t) action)->suspended = 1;
- }
- XBT_OUT();
-}
-
-static void storage_action_resume(surf_action_t action)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static int storage_action_is_suspended(surf_action_t action)
-{
- return (((surf_action_lmm_t) action)->suspended == 1);
-}
-
-static void storage_action_set_max_duration(surf_action_t action, double duration)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static void storage_action_set_priority(surf_action_t action, double priority)
-{
- THROW_UNIMPLEMENTED;
-}
-
-static void parse_storage_init(sg_platf_storage_cbarg_t storage)
-{
- void* stype = xbt_lib_get_or_null(storage_type_lib,
- storage->type_id,
- ROUTING_STORAGE_TYPE_LEVEL);
- if(!stype) xbt_die("No storage type '%s'",storage->type_id);
-
- // if storage content is not specified use the content of storage_type if exist
- if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
- storage->content = ((storage_type_t) stype)->content;
- storage->content_type = ((storage_type_t) stype)->content_type;
- XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
- storage->id,((storage_type_t) stype)->content_type,
- ((storage_type_t) stype)->type_id);
- }
-
- XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
- "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
- "\n\t\tproperties '%p'\n",
- storage->id,
- ((storage_type_t) stype)->model,
- ((storage_type_t) stype)->type_id,
- storage->content,
- storage->content_type,
- ((storage_type_t) stype)->properties);
-
- storage_create_resource(storage->id,
- ((storage_type_t) stype)->model,
- ((storage_type_t) stype)->type_id,
- storage->content,
- storage->content_type,
- storage->properties);
-}
-
-static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage)
-{
- XBT_DEBUG("parse_mstorage_init");
-}
-
-static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_)
-{
- XBT_DEBUG("parse_storage_type_init");
-}
-
-static void parse_mount_init(sg_platf_mount_cbarg_t mount)
-{
- XBT_DEBUG("parse_mount_init");
-}
-
-static void storage_define_callbacks()
-{
- sg_platf_storage_add_cb(parse_storage_init);
- sg_platf_storage_type_add_cb(parse_storage_type_init);
- sg_platf_mstorage_add_cb(parse_mstorage_init);
- sg_platf_mount_add_cb(parse_mount_init);
-}
-
-static void surf_storage_model_init_internal(void)
-{
- s_surf_action_t action;
-
- XBT_DEBUG("surf_storage_model_init_internal");
- surf_storage_model = surf_model_init();
-
- storage_running_action_set_that_does_not_need_being_checked =
- xbt_swag_new(xbt_swag_offset(action, state_hookup));
-
- surf_storage_model->name = "Storage";
- surf_storage_model->type = SURF_MODEL_TYPE_STORAGE;
- surf_storage_model->action_unref = storage_action_unref;
- surf_storage_model->action_cancel = storage_action_cancel;
- surf_storage_model->action_state_set = storage_action_state_set;
-
- surf_storage_model->model_private->finalize = storage_finalize;
- surf_storage_model->model_private->update_actions_state = storage_update_actions_state;
- surf_storage_model->model_private->share_resources = storage_share_resources;
- surf_storage_model->model_private->resource_used = storage_resource_used;
- surf_storage_model->model_private->update_resource_state = storage_resources_state;
-
- surf_storage_model->suspend = storage_action_suspend;
- surf_storage_model->resume = storage_action_resume;
- surf_storage_model->is_suspended = storage_action_is_suspended;
- surf_storage_model->set_max_duration = storage_action_set_max_duration;
- surf_storage_model->set_priority = storage_action_set_priority;
-
- surf_storage_model->extension.storage.open = storage_action_open;
- surf_storage_model->extension.storage.close = storage_action_close;
- surf_storage_model->extension.storage.read = storage_action_read;
- surf_storage_model->extension.storage.write = storage_action_write;
- surf_storage_model->extension.storage.ls = storage_action_ls;
- surf_storage_model->extension.storage.get_properties = storage_get_properties;
- surf_storage_model->extension.storage.get_content = storage_get_content;
- surf_storage_model->extension.storage.get_size = storage_get_size;
- surf_storage_model->extension.storage.rename = storage_file_rename;
- if (!storage_maxmin_system) {
- storage_maxmin_system = lmm_system_new(storage_selective_update);
- }
-}
-
-void surf_storage_model_init_default(void)
-{
- surf_storage_model_init_internal();
- storage_define_callbacks();
-
- xbt_dynar_push(model_list, &surf_storage_model);
-}
-
-static void storage_parse_storage(sg_platf_storage_cbarg_t storage)
-{
- xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
- "Reading a storage, processing unit \"%s\" already exists", storage->id);
-
- // Verification of an existing type_id
-#ifndef NDEBUG
- void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
-#endif
- xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
-
- XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
- storage->id,
- storage->type_id,
- storage->content);
-
- xbt_lib_set(storage_lib,
- storage->id,
- ROUTING_STORAGE_LEVEL,
- (void *) xbt_strdup(storage->type_id));
-}
-
-static xbt_dict_t parse_storage_content(char *filename, sg_storage_size_t *used_size)
-{
- *used_size = 0;
- if ((!filename) || (strcmp(filename, "") == 0))
- return NULL;
-
- xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
- FILE *file = NULL;
-
- file = surf_fopen(filename, "r");
- xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
- xbt_str_join(surf_path, ":"));
-
- char *line = NULL;
- size_t len = 0;
- ssize_t read;
- char path[1024];
- sg_storage_size_t size;
-
- while ((read = xbt_getline(&line, &len, file)) != -1) {
- if (read){
- if (sscanf(line,"%s %" SCNu64, path, &size) == 2) {
- *used_size += size;
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
- *psize = size;
- xbt_dict_set(parse_content,path,psize,NULL);
- } else {
- xbt_die("Be sure of passing a good format for content file.\n");
- }
- }
- }
- free(line);
- fclose(file);
- return parse_content;
-}
-
-static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type)
-{
- xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
- "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
-
- storage_type_t stype = xbt_new0(s_storage_type_t, 1);
- stype->model = xbt_strdup(storage_type->model);
- stype->properties = storage_type->properties;
- stype->content = xbt_strdup(storage_type->content);
- stype->content_type = xbt_strdup(storage_type->content_type);
- stype->type_id = xbt_strdup(storage_type->id);
- stype->size = storage_type->size;
-
- XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
- "content '%s', and content_type '%s'",
- stype->type_id,
- stype->model,
- storage_type->content,
- storage_type->content_type);
-
- xbt_lib_set(storage_type_lib,
- stype->type_id,
- ROUTING_STORAGE_TYPE_LEVEL,
- (void *) stype);
-}
-static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage)
-{
- THROW_UNIMPLEMENTED;
-// mount_t mnt = xbt_new0(s_mount_t, 1);
-// mnt->id = xbt_strdup(mstorage->type_id);
-// mnt->name = xbt_strdup(mstorage->name);
-//
-// if(!mount_list){
-// XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
-// mount_list = xbt_dynar_new(sizeof(char *), NULL);
-// }
-// xbt_dynar_push(mount_list,(void *) mnt);
-// free(mnt->id);
-// free(mnt->name);
-// xbt_free(mnt);
-// XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
-}
-
-static void mount_free(void *p)
-{
- mount_t mnt = p;
- xbt_free(mnt->name);
-}
-
-static void storage_parse_mount(sg_platf_mount_cbarg_t mount)
-{
- // Verification of an existing storage
-#ifndef NDEBUG
- void* storage = xbt_lib_get_or_null(storage_lib, mount->storageId,ROUTING_STORAGE_LEVEL);
-#endif
- xbt_assert(storage,"Disk id \"%s\" does not exists", mount->storageId);
-
- XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
-
- s_mount_t mnt;
- mnt.storage =
- surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
- mnt.name = xbt_strdup(mount->name);
-
- if(!mount_list){
- XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
- mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
- }
- xbt_dynar_push(mount_list,&mnt);
-}
-
-static XBT_INLINE void routing_storage_type_free(void *r)
-{
- storage_type_t stype = r;
- free(stype->model);
- free(stype->type_id);
- free(stype->content);
- free(stype->content_type);
- xbt_dict_free(&(stype->properties));
- free(stype);
-}
-
-static XBT_INLINE void surf_storage_resource_free(void *r)
-{
- // specific to storage
- storage_t storage = r;
- xbt_dict_free(&storage->content);
- xbt_dynar_free(&storage->write_actions);
- free(storage->type_id);
- free(storage->content_type);
- // generic resource
- surf_resource_free(r);
-}
-
-static XBT_INLINE void routing_storage_host_free(void *r)
-{
- xbt_dynar_t dyn = r;
- xbt_dynar_free(&dyn);
-}
-
-void storage_register_callbacks() {
-
- ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,xbt_free);
- ROUTING_STORAGE_HOST_LEVEL = xbt_lib_add_level(storage_lib,routing_storage_host_free);
- ROUTING_STORAGE_TYPE_LEVEL = xbt_lib_add_level(storage_type_lib,routing_storage_type_free);
- SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_resource_free);
-
- sg_platf_storage_add_cb(storage_parse_storage);
- sg_platf_mstorage_add_cb(storage_parse_mstorage);
- sg_platf_storage_type_add_cb(storage_parse_storage_type);
- sg_platf_mount_add_cb(storage_parse_mount);
-}
-
+++ /dev/null
-/* Copyright (c) 2004-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "surf_private.h"
-#include "xbt/module.h"
-#include "mc/mc.h"
-#include "simix/smx_host_private.h"
-#include "surf/surf_resource.h"
-#include "xbt/xbt_os_thread.h"
-#include "simgrid/sg_config.h"
-
-#include <ctype.h>
-
-XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf,
- "Logging specific to SURF (kernel)");
-
-/* Additional declarations for Windows portability. */
-
-#ifndef MAX_DRIVE
-#define MAX_DRIVE 26
-#endif
-
-#ifdef _XBT_WIN32
-#include <windows.h>
-static const char *disk_drives_letter_table[MAX_DRIVE] = {
- "A:\\",
- "B:\\",
- "C:\\",
- "D:\\",
- "E:\\",
- "F:\\",
- "G:\\",
- "H:\\",
- "I:\\",
- "J:\\",
- "K:\\",
- "L:\\",
- "M:\\",
- "N:\\",
- "O:\\",
- "P:\\",
- "Q:\\",
- "R:\\",
- "S:\\",
- "T:\\",
- "U:\\",
- "V:\\",
- "W:\\",
- "X:\\",
- "Y:\\",
- "Z:\\"
-};
-#endif /* #ifdef _XBT_WIN32 */
-
-/*
- * Returns the initial path. On Windows the initial path is
- * the current directory for the current process in the other
- * case the function returns "./" that represents the current
- * directory on Unix/Linux platforms.
- */
-
-const char *__surf_get_initial_path(void)
-{
-
-#ifdef _XBT_WIN32
- unsigned i;
- char current_directory[MAX_PATH + 1] = { 0 };
- unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory);
- char root[4] = { 0 };
-
- if (!len)
- return NULL;
-
- strncpy(root, current_directory, 3);
-
- for (i = 0; i < MAX_DRIVE; i++) {
- if (toupper(root[0]) == disk_drives_letter_table[i][0])
- return disk_drives_letter_table[i];
- }
-
- return NULL;
-#else
- return "./";
-#endif
-}
-
-/* The __surf_is_absolute_file_path() returns 1 if
- * file_path is a absolute file path, in the other
- * case the function returns 0.
- */
-int __surf_is_absolute_file_path(const char *file_path)
-{
-#ifdef _XBT_WIN32
- WIN32_FIND_DATA wfd = { 0 };
- HANDLE hFile = FindFirstFile(file_path, &wfd);
-
- if (INVALID_HANDLE_VALUE == hFile)
- return 0;
-
- FindClose(hFile);
- return 1;
-#else
- return (file_path[0] == '/');
-#endif
-}
-
-double NOW = 0;
-
-/* model_list_invoke contains only surf_workstation and surf_vm_workstation.
- * The callback functions of cpu_model and network_model will be called from
- * those of these workstation models. */
-xbt_dynar_t model_list = NULL; /* for destroying all models correctly */
-xbt_dynar_t model_list_invoke = NULL; /* for invoking callbacks */
-tmgr_history_t history = NULL;
-lmm_system_t maxmin_system = NULL;
-xbt_dynar_t surf_path = NULL;
-xbt_dynar_t host_that_restart = NULL;
-xbt_dict_t watched_hosts_lib;
-
-/* Don't forget to update the option description in smx_config when you change this */
-s_surf_model_description_t surf_network_model_description[] = {
- {"LV08",
- "Realistic network analytic model (slow-start modeled by multiplying latency by 10.4, bandwidth by .92; bottleneck sharing uses a payload of S=8775 for evaluating RTT). ",
- surf_network_model_init_LegrandVelho},
- {"Constant",
- "Simplistic network model where all communication take a constant time (one second). This model provides the lowest realism, but is (marginally) faster.",
- surf_network_model_init_Constant},
- {"SMPI",
- "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
- surf_network_model_init_SMPI},
- {"CM02",
- "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of small messages are thus poorly modeled).",
- surf_network_model_init_CM02},
-#ifdef HAVE_GTNETS
- {"GTNets",
- "Network pseudo-model using the GTNets simulator instead of an analytic model",
- surf_network_model_init_GTNETS},
-#endif
-#ifdef HAVE_NS3
- {"NS3",
- "Network pseudo-model using the NS3 tcp model instead of an analytic model",
- surf_network_model_init_NS3},
-#endif
- {"Reno",
- "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
- surf_network_model_init_Reno},
- {"Reno2",
- "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
- surf_network_model_init_Reno2},
- {"Vegas",
- "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
- surf_network_model_init_Vegas},
- {NULL, NULL, NULL} /* this array must be NULL terminated */
-};
-
-s_surf_model_description_t surf_cpu_model_description[] = {
- {"Cas01",
- "Simplistic CPU model (time=size/power).",
- surf_cpu_model_init_Cas01},
- {NULL, NULL, NULL} /* this array must be NULL terminated */
-};
-
-s_surf_model_description_t surf_workstation_model_description[] = {
- {"default",
- "Default workstation model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)",
- surf_workstation_model_init_current_default},
- {"compound",
- "Workstation model that is automatically chosen if you change the network and CPU models",
- surf_workstation_model_init_compound},
- {"ptask_L07", "Workstation model somehow similar to Cas01+CM02 but allowing parallel tasks",
- surf_workstation_model_init_ptask_L07},
- {NULL, NULL, NULL} /* this array must be NULL terminated */
-};
-
-s_surf_model_description_t surf_optimization_mode_description[] = {
- {"Lazy",
- "Lazy action management (partial invalidation in lmm + heap in action remaining).",
- NULL},
- {"TI",
- "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).",
- NULL},
- {"Full",
- "Full update of remaining and variables. Slow but may be useful when debugging.",
- NULL},
- {NULL, NULL, NULL} /* this array must be NULL terminated */
-};
-
-s_surf_model_description_t surf_storage_model_description[] = {
- {"default",
- "Simplistic storage model.",
- surf_storage_model_init_default},
- {NULL, NULL, NULL} /* this array must be NULL terminated */
-};
-
-/* ********************************************************************* */
-/* TUTORIAL: New model */
-s_surf_model_description_t surf_new_model_description[] = {
- {"default",
- "Tutorial model.",
- surf_new_model_init_default},
- {NULL, NULL, NULL} /* this array must be NULL terminated */
-};
-/* ********************************************************************* */
-
-#ifdef CONTEXT_THREADS
-static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
-#endif
-
-static double *surf_mins = NULL; /* return value of share_resources for each model */
-static int surf_min_index; /* current index in surf_mins */
-static double min; /* duration determined by surf_solve */
-
-static void surf_share_resources(surf_model_t model);
-static void surf_update_actions_state(surf_model_t model);
-
-/** Displays the long description of all registered models, and quit */
-void model_help(const char *category, s_surf_model_description_t * table)
-{
- int i;
- printf("Long description of the %s models accepted by this simulator:\n",
- category);
- for (i = 0; table[i].name; i++)
- printf(" %s: %s\n", table[i].name, table[i].description);
-}
-
-int find_model_description(s_surf_model_description_t * table,
- const char *name)
-{
- int i;
- char *name_list = NULL;
-
- for (i = 0; table[i].name; i++)
- if (!strcmp(name, table[i].name)) {
- return i;
- }
- if (!table[0].name)
- xbt_die("No model is valid! This is a bug.");
- name_list = xbt_strdup(table[0].name);
- for (i = 1; table[i].name; i++) {
- name_list =
- xbt_realloc(name_list,
- strlen(name_list) + strlen(table[i].name) + 3);
- strcat(name_list, ", ");
- strcat(name_list, table[i].name);
- }
- xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
- return -1;
-}
-
-double generic_maxmin_share_resources(xbt_swag_t running_actions,
- size_t offset,
- lmm_system_t sys,
- void (*solve) (lmm_system_t))
-{
- surf_action_t action = NULL;
- double min = -1;
- double value = -1;
-#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + (offset))))
-
- solve(sys);
-
- xbt_swag_foreach(action, running_actions) {
- value = lmm_variable_getvalue(VARIABLE(action));
- if ((value > 0) || (action->max_duration >= 0))
- break;
- }
-
- if (!action)
- return -1.0;
-
- if (value > 0) {
- if (action->remains > 0)
- min = action->remains / value;
- else
- min = 0.0;
- if ((action->max_duration >= 0) && (action->max_duration < min))
- min = action->max_duration;
- } else
- min = action->max_duration;
-
-
- for (action = xbt_swag_getNext(action, running_actions->offset);
- action;
- action = xbt_swag_getNext(action, running_actions->offset)) {
- value = lmm_variable_getvalue(VARIABLE(action));
- if (value > 0) {
- if (action->remains > 0)
- value = action->remains / value;
- else
- value = 0.0;
- if (value < min) {
- min = value;
- XBT_DEBUG("Updating min (value) with %p: %f", action, min);
- }
- }
- if ((action->max_duration >= 0) && (action->max_duration < min)) {
- min = action->max_duration;
- XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
- }
- }
- XBT_DEBUG("min value : %f", min);
-
-#undef VARIABLE
- return min;
-}
-
-double generic_share_resources_lazy(double now, surf_model_t model)
-{
- surf_action_lmm_t action = NULL;
- double min = -1;
- double value;
-
- XBT_DEBUG
- ("Before share resources, the size of modified actions set is %d",
- xbt_swag_size(model->model_private->modified_set));
-
- lmm_solve(model->model_private->maxmin_system);
-
- XBT_DEBUG
- ("After share resources, The size of modified actions set is %d",
- xbt_swag_size(model->model_private->modified_set));
-
- while((action = xbt_swag_extract(model->model_private->modified_set))) {
- int max_dur_flag = 0;
-
- if (action->generic_action.state_set !=
- model->states.running_action_set)
- continue;
-
- /* bogus priority, skip it */
- if (action->generic_action.priority <= 0)
- continue;
-
- generic_update_action_remaining_lazy(action,now);
-
- min = -1;
- value = lmm_variable_getvalue(action->variable);
- if (value > 0) {
- if (action->generic_action.remains > 0) {
- value = action->generic_action.remains / value;
- min = now + value;
- } else {
- value = 0.0;
- min = now;
- }
- }
-
- if ((action->generic_action.max_duration != NO_MAX_DURATION)
- && (min == -1
- || action->generic_action.start +
- action->generic_action.max_duration < min)) {
- min = action->generic_action.start +
- action->generic_action.max_duration;
- max_dur_flag = 1;
- }
-
- XBT_DEBUG("Action(%p) Start %f Finish %f Max_duration %f", action,
- action->generic_action.start, now + value,
- action->generic_action.max_duration);
-
- if (min != -1) {
- surf_action_lmm_heap_remove(model->model_private->action_heap,action);
- surf_action_lmm_heap_insert(model->model_private->action_heap,action, min, max_dur_flag ? MAX_DURATION : NORMAL);
- XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min,
- now);
- } else DIE_IMPOSSIBLE;
- }
-
- //hereafter must have already the min value for this resource model
- if (xbt_heap_size(model->model_private->action_heap) > 0)
- min = xbt_heap_maxkey(model->model_private->action_heap) - now;
- else
- min = -1;
-
- XBT_DEBUG("The minimum with the HEAP %f", min);
-
- return min;
-}
-static XBT_INLINE void routing_asr_host_free(void *p)
-{
- sg_routing_edge_t elm = p;
- free(elm->name);
- xbt_free(elm);
-}
-
-static XBT_INLINE void routing_asr_prop_free(void *p)
-{
- xbt_dict_t elm = p;
- xbt_dict_free(&elm);
-}
-
-void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
- *ver_major = SIMGRID_VERSION_MAJOR;
- *ver_minor = SIMGRID_VERSION_MINOR;
- *ver_patch = SIMGRID_VERSION_PATCH;
-}
-
-void surf_init(int *argc, char **argv)
-{
- XBT_DEBUG("Create all Libs");
- host_lib = xbt_lib_new();
- link_lib = xbt_lib_new();
- as_router_lib = xbt_lib_new();
- storage_lib = xbt_lib_new();
- storage_type_lib = xbt_lib_new();
- watched_hosts_lib = xbt_dict_new_homogeneous(NULL);
-
- XBT_DEBUG("Add routing levels");
- ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
- ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free);
- ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
-
- XBT_DEBUG("Add SURF levels");
- SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_resource_free);
- SURF_WKS_LEVEL = xbt_lib_add_level(host_lib,surf_resource_free);
- SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_resource_free);
-
- xbt_init(argc, argv);
- if (!model_list)
- model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL);
- if (!model_list_invoke)
- model_list_invoke = xbt_dynar_new(sizeof(surf_model_private_t), NULL);
- if (!history)
- history = tmgr_history_new();
-
-#ifdef HAVE_TRACING
- TRACE_add_start_function(TRACE_surf_alloc);
- TRACE_add_end_function(TRACE_surf_release);
-#endif
-
- sg_config_init(argc, argv);
-
- surf_action_init();
- if (MC_is_active())
- MC_memory_init();
-}
-
-#ifdef _XBT_WIN32
-# define FILE_DELIM "\\"
-#else
-# define FILE_DELIM "/" /* FIXME: move to better location */
-#endif
-
-FILE *surf_fopen(const char *name, const char *mode)
-{
- unsigned int cpt;
- char *path_elm = NULL;
- char *buff;
- FILE *file = NULL;
-
- xbt_assert(name);
-
- if (__surf_is_absolute_file_path(name)) /* don't mess with absolute file names */
- return fopen(name, mode);
-
- /* search relative files in the path */
- xbt_dynar_foreach(surf_path, cpt, path_elm) {
- buff = bprintf("%s" FILE_DELIM "%s", path_elm, name);
- file = fopen(buff, mode);
- free(buff);
-
- if (file)
- return file;
- }
- return NULL;
-}
-
-void surf_exit(void)
-{
- unsigned int iter;
- surf_model_t model = NULL;
-
-#ifdef HAVE_TRACING
- TRACE_end(); /* Just in case it was not called by the upper
- * layer (or there is no upper layer) */
-#endif
-
- sg_config_finalize();
-
- xbt_dynar_foreach(model_list, iter, model)
- model->model_private->finalize(model);
- xbt_dynar_free(&model_list);
-
- xbt_dynar_free(&model_list_invoke);
-
- routing_exit();
-
- if (maxmin_system) {
- lmm_system_free(maxmin_system);
- maxmin_system = NULL;
- }
- if (history) {
- tmgr_history_free(history);
- history = NULL;
- }
- surf_action_exit();
-
-#ifdef CONTEXT_THREADS
- xbt_parmap_destroy(surf_parmap);
- xbt_free(surf_mins);
- surf_mins = NULL;
-#endif
- xbt_dynar_free(&host_that_restart);
- xbt_dynar_free(&surf_path);
-
- xbt_lib_free(&host_lib);
- xbt_lib_free(&link_lib);
- xbt_lib_free(&as_router_lib);
- xbt_lib_free(&storage_lib);
- xbt_lib_free(&storage_type_lib);
-
- xbt_dict_free(&watched_hosts_lib);
-
- tmgr_finalize();
- surf_parse_lex_destroy();
- surf_parse_free_callbacks();
-
- NOW = 0; /* Just in case the user plans to restart the simulation afterward */
-}
-
-void surf_presolve(void)
-{
- double next_event_date = -1.0;
- tmgr_trace_event_t event = NULL;
- double value = -1.0;
- surf_resource_t resource = NULL;
- surf_model_t model = NULL;
- unsigned int iter;
-
- XBT_DEBUG
- ("First Run! Let's \"purge\" events and put models in the right state");
- while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
- if (next_event_date > NOW)
- break;
- while ((event =
- tmgr_history_get_next_event_leq(history, next_event_date,
- &value,
- (void **) &resource))) {
- if (value >= 0){
- resource->model->model_private->update_resource_state(resource,
- event, value,
- NOW);
- }
- }
- }
-
- /* FIXME: see what is check_update_action_state(). if necessary, use model_list_invoke. */
- xbt_dynar_foreach(model_list, iter, model)
- model->model_private->update_actions_state(model, NOW, 0.0);
-}
-
-double surf_solve(double max_date)
-{
-
- min = -1.0; /* duration */
- double next_event_date = -1.0;
- double model_next_action_end = -1.0;
- double value = -1.0;
- surf_resource_t resource = NULL;
- surf_model_t model = NULL;
- tmgr_trace_event_t event = NULL;
- unsigned int iter;
-
- if(!host_that_restart)
- host_that_restart = xbt_dynar_new(sizeof(char*), NULL);
-
- if (max_date != -1.0 && max_date != NOW) {
- min = max_date - NOW;
- }
-
- XBT_DEBUG("Looking for next action end for all models except NS3");
-
- if (surf_mins == NULL) {
- surf_mins = xbt_new(double, xbt_dynar_length(model_list_invoke));
- }
- surf_min_index = 0;
-
- /* sequential version */
- xbt_dynar_foreach(model_list_invoke, iter, model) {
- surf_share_resources(model);
- }
- unsigned i;
- for (i = 0; i < xbt_dynar_length(model_list_invoke); i++) {
- if ((min < 0.0 || surf_mins[i] < min)
- && surf_mins[i] >= 0.0) {
- min = surf_mins[i];
- }
- }
-
- XBT_DEBUG("Min for resources (remember that NS3 don't update that value) : %f", min);
-
- XBT_DEBUG("Looking for next trace event");
-
- do {
- XBT_DEBUG("Next TRACE event : %f", next_event_date);
-
- next_event_date = tmgr_history_next_date(history);
-
- if(surf_network_model->name && !strcmp(surf_network_model->name,"network NS3")){
- if(next_event_date!=-1.0 && min!=-1.0) {
- min = MIN(next_event_date - NOW, min);
- } else{
- min = MAX(next_event_date - NOW, min);
- }
-
- XBT_DEBUG("Run for network at most %f", min);
- // run until min or next flow
- model_next_action_end = surf_network_model->model_private->share_resources(surf_network_model, min);
-
- XBT_DEBUG("Min for network : %f", model_next_action_end);
- if(model_next_action_end>=0.0)
- min = model_next_action_end;
- }
-
- if (next_event_date < 0.0) {
- XBT_DEBUG("no next TRACE event. Stop searching for it");
- break;
- }
-
- if ((min == -1.0) || (next_event_date > NOW + min)) break;
-
- XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)",min, NOW, next_event_date);
- while ((event =
- tmgr_history_get_next_event_leq(history, next_event_date,
- &value,
- (void **) &resource))) {
- if (resource->model->model_private->resource_used(resource) ||
- xbt_dict_get_or_null(watched_hosts_lib,resource->name)
- ) {
- min = next_event_date - NOW;
- XBT_DEBUG
- ("This event will modify model state. Next event set to %f",
- min);
- }
- /* update state of model_obj according to new value. Does not touch lmm.
- It will be modified if needed when updating actions */
- XBT_DEBUG("Calling update_resource_state for resource %s with min %f",
- resource->name, min);
-
- resource->model->model_private->update_resource_state(resource,
- event, value,
- next_event_date);
- }
- } while (1);
-
- /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are with availability = 0.
- * This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a trace with periodicity > 0.
- * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed */
- if (min == -1.0) {
- XBT_DEBUG("No next event at all. Bail out now.");
- return -1.0;
- }
-
- XBT_DEBUG("Duration set to %f", min);
-
- NOW = NOW + min;
- /* FIXME: model_list or model_list_invoke? revisit here later */
- /* sequential version */
- xbt_dynar_foreach(model_list, iter, model) {
- surf_update_actions_state(model);
- }
-
-#ifdef HAVE_TRACING
- TRACE_paje_dump_buffer (0);
-#endif
-
- return min;
-}
-
-XBT_INLINE double surf_get_clock(void)
-{
- return NOW;
-}
-
-static void surf_share_resources(surf_model_t model)
-{
- double next_action_end = -1.0;
- int i = __sync_fetch_and_add(&surf_min_index, 1);
- if (strcmp(model->name,"network NS3")) {
- XBT_DEBUG("Running for Resource [%s]", model->name);
- next_action_end = model->model_private->share_resources(model, NOW);
- XBT_DEBUG("Resource [%s] : next action end = %f",
- model->name, next_action_end);
- }
- surf_mins[i] = next_action_end;
-}
-
-static void surf_update_actions_state(surf_model_t model)
-{
- model->model_private->update_actions_state(model, NOW, min);
-}
-
+++ /dev/null
-/* Copyright (c) 2009-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "surf_private.h"
-#include "network_private.h"
-#include "maxmin_private.h"
-#include "surf/datatypes.h"
-#include "cpu_cas01_private.h"
-#include "xbt/mallocator.h"
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
-
-/*
- * Generic action
- */
-
-const char *surf_action_state_names[6] = {
- "SURF_ACTION_READY",
- "SURF_ACTION_RUNNING",
- "SURF_ACTION_FAILED",
- "SURF_ACTION_DONE",
- "SURF_ACTION_TO_FREE",
- "SURF_ACTION_NOT_IN_THE_SYSTEM"
-};
-
-/* Surf actions mallocator */
-static xbt_mallocator_t action_mallocator = NULL;
-static int action_mallocator_allocated_size = 0;
-static void* surf_action_mallocator_new_f(void);
-#define surf_action_mallocator_free_f xbt_free_f
-static void surf_action_mallocator_reset_f(void* action);
-
-/**
- * \brief Initializes the action module of Surf.
- */
-void surf_action_init(void) {
-
- /* the action mallocator will always provide actions of the following size,
- * so this size should be set to the maximum size of the surf action structures
- */
- action_mallocator_allocated_size = sizeof(s_surf_action_network_CM02_t);
- action_mallocator = xbt_mallocator_new(65536, surf_action_mallocator_new_f,
- surf_action_mallocator_free_f, surf_action_mallocator_reset_f);
-}
-
-/**
- * \brief Uninitializes the action module of Surf.
- */
-void surf_action_exit(void) {
-
- xbt_mallocator_free(action_mallocator);
-}
-
-static void* surf_action_mallocator_new_f(void) {
- return xbt_malloc(action_mallocator_allocated_size);
-}
-
-static void surf_action_mallocator_reset_f(void* action) {
- memset(action, 0, action_mallocator_allocated_size);
-}
-
-void *surf_action_new(size_t size, double cost, surf_model_t model,
- int failed)
-{
- xbt_assert(size <= action_mallocator_allocated_size,
- "Cannot create a surf action of size %zu: the mallocator only provides actions of size %d",
- size, action_mallocator_allocated_size);
-
- surf_action_t action = xbt_mallocator_get(action_mallocator);
- action->refcount = 1;
- action->cost = cost;
- action->remains = cost;
- action->priority = 1.0;
- action->max_duration = NO_MAX_DURATION;
- action->start = surf_get_clock();
- action->finish = -1.0;
- action->model_obj = model;
-#ifdef HAVE_TRACING
- action->category = NULL;
-#endif
-
- if (failed)
- action->state_set = model->states.failed_action_set;
- else
- action->state_set = model->states.running_action_set;
-
- xbt_swag_insert(action, action->state_set);
-
- return action;
-}
-
-e_surf_action_state_t surf_action_state_get(surf_action_t action)
-{
- surf_action_state_t action_state = &(action->model_obj->states);
-
- if (action->state_set == action_state->ready_action_set)
- return SURF_ACTION_READY;
- if (action->state_set == action_state->running_action_set)
- return SURF_ACTION_RUNNING;
- if (action->state_set == action_state->failed_action_set)
- return SURF_ACTION_FAILED;
- if (action->state_set == action_state->done_action_set)
- return SURF_ACTION_DONE;
- return SURF_ACTION_NOT_IN_THE_SYSTEM;
-}
-
-double surf_action_get_start_time(surf_action_t action)
-{
- return action->start;
-}
-
-double surf_action_get_finish_time(surf_action_t action)
-{
- /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
- return action->remains == 0 ? action->finish : -1;
-}
-
-XBT_INLINE void surf_action_free(surf_action_t * action)
-{
- xbt_mallocator_release(action_mallocator, *action);
- *action = NULL;
-}
-
-void surf_action_state_set(surf_action_t action,
- e_surf_action_state_t state)
-{
- surf_action_state_t action_state = &(action->model_obj->states);
- XBT_IN("(%p,%s)", action, surf_action_state_names[state]);
- xbt_swag_remove(action, action->state_set);
-
- if (state == SURF_ACTION_READY)
- action->state_set = action_state->ready_action_set;
- else if (state == SURF_ACTION_RUNNING)
- action->state_set = action_state->running_action_set;
- else if (state == SURF_ACTION_FAILED)
- action->state_set = action_state->failed_action_set;
- else if (state == SURF_ACTION_DONE)
- action->state_set = action_state->done_action_set;
- else
- action->state_set = NULL;
-
- if (action->state_set)
- xbt_swag_insert(action, action->state_set);
- XBT_OUT();
-}
-
-void surf_action_data_set(surf_action_t action, void *data)
-{
- action->data = data;
-}
-
-XBT_INLINE void surf_action_ref(surf_action_t action)
-{
- action->refcount++;
-}
-
-/*
- * Maxmin action
- */
-
-/* added to manage the communication action's heap */
-void surf_action_lmm_update_index_heap(void *action, int i) {
- surf_action_lmm_t a = action;
- a->index_heap = i;
-}
-/* insert action on heap using a given key and a hat (heap_action_type)
- * a hat can be of three types for communications:
- *
- * NORMAL = this is a normal heap entry stating the date to finish transmitting
- * LATENCY = this is a heap entry to warn us when the latency is payed
- * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
- */
-void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action, double key,
- enum heap_action_type hat)
-{
- action->hat = hat;
- xbt_heap_push(heap, action, key);
-}
-
-void surf_action_lmm_heap_remove(xbt_heap_t heap, surf_action_lmm_t action)
-{
- action->hat = NOTSET;
- if (action->index_heap >= 0) {
- xbt_heap_remove(heap, action->index_heap);
- }
-}
-
-void surf_action_cancel(surf_action_t action)
-{
- surf_model_t model = action->model_obj;
- surf_action_state_set(action, SURF_ACTION_FAILED);
- if (model->model_private->update_mechanism == UM_LAZY) {
- xbt_swag_remove(action, model->model_private->modified_set);
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- }
- return;
-}
-
-int surf_action_unref(surf_action_t action)
-{
- surf_model_t model = action->model_obj;
- action->refcount--;
- if (!action->refcount) {
- xbt_swag_remove(action, action->state_set);
- if (((surf_action_lmm_t) action)->variable)
- lmm_variable_free(model->model_private->maxmin_system,
- ((surf_action_lmm_t) action)->variable);
- if (model->model_private->update_mechanism == UM_LAZY) {
- /* remove from heap */
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- xbt_swag_remove(action, model->model_private->modified_set);
- }
-#ifdef HAVE_TRACING
- xbt_free(action->category);
-#endif
- surf_action_free(&action);
- return 1;
- }
- return 0;
-}
-
-void surf_action_suspend(surf_action_t action)
-{
- surf_model_t model = action->model_obj;
- XBT_IN("(%p)", action);
- if (((surf_action_lmm_t) action)->suspended != 2) {
- lmm_update_variable_weight(model->model_private->maxmin_system,
- ((surf_action_lmm_t) action)->variable,
- 0.0);
- ((surf_action_lmm_t) action)->suspended = 1;
- if (model->model_private->update_mechanism == UM_LAZY)
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- }
- XBT_OUT();
-}
-
-void surf_action_resume(surf_action_t action)
-{
- surf_model_t model = action->model_obj;
- XBT_IN("(%p)", action);
- if (((surf_action_lmm_t) action)->suspended != 2) {
- lmm_update_variable_weight(model->model_private->maxmin_system,
- ((surf_action_lmm_t) action)->variable,
- action->priority);
- ((surf_action_lmm_t) action)->suspended = 0;
- if (model->model_private->update_mechanism == UM_LAZY)
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- }
- XBT_OUT();
-}
-
-int surf_action_is_suspended(surf_action_t action)
-{
- return (((surf_action_lmm_t) action)->suspended == 1);
-}
-
-void surf_action_set_max_duration(surf_action_t action, double duration)
-{
- surf_model_t model = action->model_obj;
- XBT_IN("(%p,%g)", action, duration);
- action->max_duration = duration;
- if (model->model_private->update_mechanism == UM_LAZY) // remove action from the heap
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- XBT_OUT();
-}
-
-void surf_action_set_priority(surf_action_t action, double priority)
-{
- surf_model_t model = action->model_obj;
- XBT_IN("(%p,%g)", action, priority);
- action->priority = priority;
- lmm_update_variable_weight(model->model_private->maxmin_system,
- ((surf_action_lmm_t) action)->variable,
- priority);
-
- if (model->model_private->update_mechanism == UM_LAZY)
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- XBT_OUT();
-}
-
-void surf_action_set_bound(surf_action_t action, double bound)
-{
- surf_model_t model = action->model_obj;
- XBT_IN("(%p,%g)", action, bound);
- action->bound = bound;
- lmm_update_variable_bound(model->model_private->maxmin_system, ((surf_action_lmm_t) action)->variable, bound);
-
- if (model->model_private->update_mechanism == UM_LAZY)
- surf_action_lmm_heap_remove(model->model_private->action_heap, (surf_action_lmm_t) action);
- XBT_OUT();
-}
-
-#ifdef HAVE_TRACING
-void surf_action_set_category(surf_action_t action,
- const char *category)
-{
- XBT_IN("(%p,%s)", action, category);
- action->category = xbt_strdup(category);
- XBT_OUT();
-}
-#endif
-
-void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now)
-{
- double delta = 0.0;
- surf_model_t model = action->generic_action.model_obj;
-
- if(model == surf_network_model)
- {
- if (action->suspended != 0)
- return;
- }
- else
- {
- xbt_assert(action->generic_action.state_set == model->states.running_action_set,
- "You're updating an action that is not running.");
-
- /* bogus priority, skip it */
- xbt_assert(action->generic_action.priority > 0,
- "You're updating an action that seems suspended.");
- }
-
- delta = now - action->last_update;
-
- if (action->generic_action.remains > 0) {
- XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", action, action->generic_action.remains, action->last_update);
- double_update(&(action->generic_action.remains),
- action->last_value * delta);
-
-#ifdef HAVE_TRACING
- if (model->type == SURF_MODEL_TYPE_CPU && TRACE_is_enabled()) {
- surf_resource_t cpu =
- lmm_constraint_id(lmm_get_cnst_from_var
- (model->model_private->maxmin_system,
- action->variable, 0));
- TRACE_surf_host_set_utilization(cpu->name,
- action->generic_action.category,
- action->last_value,
- action->last_update,
- now - action->last_update);
- }
-#endif
- XBT_DEBUG("Updating action(%p): remains is now %f", action,
- action->generic_action.remains);
- }
-
- if(model == surf_network_model)
- {
- if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
- double_update(&(((surf_action_t)action)->max_duration), delta);
-
- if ((((surf_action_t)action)->remains <= 0) &&
- (lmm_get_variable_weight(action->variable) > 0)) {
- ((surf_action_t)action)->finish = surf_get_clock();
- model->action_state_set((surf_action_t) action,
- SURF_ACTION_DONE);
-
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- } else if (((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
- && (((surf_action_t)action)->max_duration <= 0))) {
- ((surf_action_t)action)->finish = surf_get_clock();
- model->action_state_set((surf_action_t) action,
- SURF_ACTION_DONE);
- surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action);
- }
- }
-
- action->last_update = now;
- action->last_value = lmm_variable_getvalue(action->variable);
-}
-
-double surf_action_get_remains(surf_action_t action)
-{
- XBT_IN("(%p)", action);
- surf_model_t model = action->model_obj;
- /* update remains before return it */
- if (model->model_private->update_mechanism == UM_LAZY) /* update remains before return it */
- generic_update_action_remaining_lazy((surf_action_lmm_t)action, surf_get_clock());
- XBT_OUT();
- return action->remains;
-}
-
-/**
- * Update the CPU total energy for a finished action
- *
- */
-void update_resource_energy(surf_model_t model, surf_action_lmm_t action)
-{
- if(model->type == SURF_MODEL_TYPE_CPU){
- cpu_Cas01_t cpu_model = (cpu_Cas01_t)lmm_constraint_id(lmm_get_cnst_from_var
- (model->model_private->maxmin_system,
- action->variable, 0));
-
- if( cpu_model->energy->last_updated < surf_get_clock()) {
- double load = lmm_constraint_get_usage(cpu_model->constraint) / cpu_model->power_peak;
- cpu_update_energy(cpu_model, load);
- }
- }
-}
-
-
-
-
-void generic_update_actions_state_lazy(double now, double delta, surf_model_t model)
-{
- surf_action_lmm_t action;
- while ((xbt_heap_size(model->model_private->action_heap) > 0)
- && (double_equals(xbt_heap_maxkey(model->model_private->action_heap), now))) {
- action = xbt_heap_pop(model->model_private->action_heap);
- XBT_DEBUG("Something happened to action %p", action);
-#ifdef HAVE_TRACING
- if (TRACE_is_enabled()) {
- if(model->type == SURF_MODEL_TYPE_CPU){
- surf_resource_t cpu =
- lmm_constraint_id(lmm_get_cnst_from_var
- (model->model_private->maxmin_system,
- action->variable, 0));
- TRACE_surf_host_set_utilization(cpu->name,
- ((surf_action_t)action)->category,
- lmm_variable_getvalue(action->variable),
- action->last_update,
- now - action->last_update);
- }
- else{
- int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable);
- unsigned int i;
- for (i = 0; i < n; i++){
- lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system,
- action->variable,
- i);
- link_CM02_t link = lmm_constraint_id(constraint);
- TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
- ((surf_action_t)action)->category,
- (lmm_variable_getvalue(action->variable)*
- lmm_get_cnst_weight_from_var(model->model_private->maxmin_system,
- action->variable,
- i)),
- action->last_update,
- now - action->last_update);
- }
- }
- }
-#endif
-
- if(model->type == SURF_MODEL_TYPE_CPU){
- action->generic_action.finish = surf_get_clock();
-
- update_resource_energy(model, action);
-
- /* set the remains to 0 due to precision problems when updating the remaining amount */
- action->generic_action.remains = 0;
- surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
- surf_action_lmm_heap_remove(model->model_private->action_heap,action); //FIXME: strange call since action was already popped
- }
- else{
- // if I am wearing a latency hat
- if (action->hat == LATENCY) {
- XBT_DEBUG("Latency paid for action %p. Activating", action);
- lmm_update_variable_weight(model->model_private->maxmin_system, action->variable,
- ((surf_action_network_CM02_t)(action))->weight);
- surf_action_lmm_heap_remove(model->model_private->action_heap,action);
- action->last_update = surf_get_clock();
-
- // if I am wearing a max_duration or normal hat
- } else if (action->hat == MAX_DURATION ||
- action->hat == NORMAL) {
- // no need to communicate anymore
- // assume that flows that reached max_duration have remaining of 0
- action->generic_action.finish = surf_get_clock();
- XBT_DEBUG("Action %p finished", action);
- action->generic_action.remains = 0;
- ((surf_action_t)action)->finish = surf_get_clock();
- model->action_state_set((surf_action_t) action,
- SURF_ACTION_DONE);
- surf_action_lmm_heap_remove(model->model_private->action_heap,action);
-
- if (model->gap_remove && model == surf_network_model)
- model->gap_remove(action);
- }
- }
- }
-#ifdef HAVE_TRACING
- if (TRACE_is_enabled() && model->type == SURF_MODEL_TYPE_CPU) {
- //defining the last timestamp that we can safely dump to trace file
- //without losing the event ascending order (considering all CPU's)
- double smaller = -1;
- xbt_swag_t running_actions = model->states.running_action_set;
- xbt_swag_foreach(action, running_actions) {
- if (smaller < 0) {
- smaller = action->last_update;
- continue;
- }
- if (action->last_update < smaller) {
- smaller = action->last_update;
- }
- }
- if (smaller > 0) {
- TRACE_last_timestamp_to_dump = smaller;
- }
- }
-#endif
- return;
-}
-
-void generic_update_actions_state_full(double now, double delta, surf_model_t model)
-{
- surf_action_lmm_t action = NULL;
- surf_action_lmm_t next_action = NULL;
- xbt_swag_t running_actions = model->states.running_action_set;
-
- xbt_swag_foreach_safe(action, next_action, running_actions) {
-
- if(model == surf_network_model)
- {
- double deltap = 0.0;
- deltap = delta;
- if (((surf_action_network_CM02_t)action)->latency > 0) {
- if (((surf_action_network_CM02_t)action)->latency > deltap) {
- double_update(&(((surf_action_network_CM02_t)action)->latency), deltap);
- deltap = 0.0;
- } else {
- double_update(&(deltap), ((surf_action_network_CM02_t)action)->latency);
- ((surf_action_network_CM02_t)action)->latency = 0.0;
- }
- if ((((surf_action_network_CM02_t)action)->latency == 0.0) && !(action->suspended))
- lmm_update_variable_weight(model->model_private->maxmin_system, action->variable,
- ((surf_action_network_CM02_t)action)->weight);
- }
- #ifdef HAVE_TRACING
- if (TRACE_is_enabled()) {
- int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable);
- unsigned int i;
- for (i = 0; i < n; i++){
- lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system,
- action->variable,
- i);
- link_CM02_t link = lmm_constraint_id(constraint);
- TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
- ((surf_action_t)action)->category,
- (lmm_variable_getvalue(action->variable)*
- lmm_get_cnst_weight_from_var(model->model_private->maxmin_system,
- action->variable,
- i)),
- now - delta,
- delta);
- }
- }
- #endif
- if (!lmm_get_number_of_cnst_from_var
- (model->model_private->maxmin_system, action->variable)) {
- /* There is actually no link used, hence an infinite bandwidth.
- * This happens often when using models like vivaldi.
- * In such case, just make sure that the action completes immediately.
- */
- double_update(&(action->generic_action.remains),
- action->generic_action.remains);
- }
- }
- else
- {
-#ifdef HAVE_TRACING
- if (TRACE_is_enabled()) {
- surf_resource_t x =
- lmm_constraint_id(lmm_get_cnst_from_var
- (model->model_private->maxmin_system,
- action->variable, 0));
-
- TRACE_surf_host_set_utilization(x->name,
- ((surf_action_t)action)->category,
- lmm_variable_getvalue(action->variable),
- now - delta,
- delta);
- TRACE_last_timestamp_to_dump = now - delta;
- }
-#endif
- }
-
- double_update(&(action->generic_action.remains),
- lmm_variable_getvalue(action->variable) * delta);
-
-
- if (action->generic_action.max_duration != NO_MAX_DURATION)
- double_update(&(action->generic_action.max_duration), delta);
-
-
- if ((action->generic_action.remains <= 0) &&
- (lmm_get_variable_weight(action->variable) > 0)) {
- action->generic_action.finish = surf_get_clock();
- surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-
- if (model->gap_remove && model == surf_network_model)
- model->gap_remove(action);
- } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
- (action->generic_action.max_duration <= 0)) {
- action->generic_action.finish = surf_get_clock();
- surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-
- if (model->gap_remove && model == surf_network_model)
- model->gap_remove(action);
- }
-
- update_resource_energy(model, action);
- }
-
- return;
-}
+++ /dev/null
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "xbt/ex.h"
-#include "xbt/dict.h"
-#include "portable.h"
-#include "surf_private.h"
-#include "surf/surf_resource.h"
-#include "simgrid/sg_config.h"
-#include "vm_workstation_private.h"
-#include "cpu_cas01_private.h"
-#include "maxmin_private.h"
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
- "Logging specific to the SURF VM workstation module");
-
-
-surf_model_t surf_vm_workstation_model = NULL;
-
-/* ind means ''indirect'' that this is a reference on the whole dict_elm
- * structure (i.e not on the surf_resource_private infos) */
-
-static void vm_ws_create(const char *name, void *ind_phys_workstation)
-{
- workstation_CLM03_t sub_ws = surf_workstation_resource_priv(ind_phys_workstation);
- const char *sub_ws_name = sub_ws->generic_resource.name;
-
- /* The workstation_VM2013 struct inherits the workstation_CLM03 struct. We
- * create a physical workstation resource, but specifying the size of
- * s_workstation_VM2013_t and the vm workstation model object. */
- workstation_CLM03_t ws = (workstation_CLM03_t) surf_resource_new(sizeof(s_workstation_VM2013_t),
- surf_vm_workstation_model, name, NULL, NULL);
-
- /* Currently, we assume a VM has no storage. */
- ws->storage = NULL;
-
- /* Currently, a VM uses the network resource of its physical host. In
- * host_lib, this network resource object is refered from two different keys.
- * When deregistering the reference that points the network resource object
- * from the VM name, we have to make sure that the system does not call the
- * free callback for the network resource object. The network resource object
- * is still used by the physical machine. */
- ws->net_elm = xbt_lib_get_or_null(host_lib, sub_ws_name, ROUTING_HOST_LEVEL);
- xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, ws->net_elm);
-
- /* The SURF_WKS_LEVEL at host_lib saves workstation_CLM03 objects. Please
- * note workstation_VM2013 objects, inheriting the workstation_CLM03
- * structure, are also saved there.
- *
- * If you want to get a workstation_VM2013 object from host_lib, see
- * ws->generic_resouce.model->type first. If it is
- * SURF_MODEL_TYPE_VM_WORKSTATION, you can cast ws to vm_ws. */
- XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, sub_ws_name, xbt_dynar_length(ws->storage));
- xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws);
-
-
- /* We initialize the VM-specific members. */
- workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
- vm_ws->sub_ws = sub_ws;
- vm_ws->current_state = SURF_VM_STATE_CREATED;
-
-
-
- // //// CPU RELATED STUFF ////
- // Roughly, create a vcpu resource by using the values of the sub_cpu one.
- cpu_Cas01_t sub_cpu = surf_cpu_resource_priv(ind_phys_workstation);
-
- /* We can assume one core and cas01 cpu for the first step.
- * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */
- cpu_cas01_create_resource(name, // name
- sub_cpu->power_peak_list, // host->power_peak,
- sub_cpu->pstate,
- 1, // host->power_scale,
- NULL, // host->power_trace,
- 1, // host->core_amount,
- SURF_RESOURCE_ON, // host->initial_state,
- NULL, // host->state_trace,
- NULL, // host->properties,
- surf_cpu_model_vm);
-
-
-
- /* We create cpu_action corresponding to a VM process on the host operating system. */
- /* FIXME: TODO: we have to peridocally input GUESTOS_NOISE to the system? how ? */
- // vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_phys_workstation, GUESTOS_NOISE);
- vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_phys_workstation, 0);
-
-
- /* TODO:
- * - check how network requests are scheduled between distinct processes competing for the same card.
- */
-}
-
-/*
- * Update the physical host of the given VM
- */
-static void vm_ws_migrate(void *ind_vm, void *ind_dst_pm)
-{
- /* ind_phys_workstation equals to smx_host_t */
- workstation_VM2013_t ws_vm2013 = surf_workstation_resource_priv(ind_vm);
- workstation_CLM03_t ws_clm03_dst = surf_workstation_resource_priv(ind_dst_pm);
- const char *vm_name = ws_vm2013->ws.generic_resource.name;
- const char *pm_name_src = ws_vm2013->sub_ws->generic_resource.name;
- const char *pm_name_dst = ws_clm03_dst->generic_resource.name;
-
- xbt_assert(ws_vm2013);
- xbt_assert(ws_clm03_dst);
-
- /* do something */
-
- /* update net_elm with that of the destination physical host */
- void *old_net_elm = ws_vm2013->ws.net_elm;
- void *new_net_elm = xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL);
- xbt_assert(new_net_elm);
-
- /* Unregister the current net_elm from host_lib. Do not call the free callback. */
- xbt_lib_unset(host_lib, vm_name, ROUTING_HOST_LEVEL, 0);
-
- /* Then, resister the new one. */
- ws_vm2013->ws.net_elm = new_net_elm;
- xbt_lib_set(host_lib, vm_name, ROUTING_HOST_LEVEL, ws_vm2013->ws.net_elm);
-
- ws_vm2013->sub_ws = ws_clm03_dst;
-
- /* Update vcpu's action for the new pm */
- {
-#if 0
- XBT_INFO("cpu_action->remains %g", ws_vm2013->cpu_action->remains);
- XBT_INFO("cost %f remains %f start %f finish %f", ws_vm2013->cpu_action->cost,
- ws_vm2013->cpu_action->remains,
- ws_vm2013->cpu_action->start,
- ws_vm2013->cpu_action->finish
- );
- XBT_INFO("cpu_action state %d", surf_action_state_get(ws_vm2013->cpu_action));
-#endif
-
- /* create a cpu action bound to the pm model at the destination. */
- surf_action_t new_cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_dst_pm, 0);
-
- e_surf_action_state_t state = surf_action_state_get(ws_vm2013->cpu_action);
- if (state != SURF_ACTION_DONE)
- XBT_CRITICAL("FIXME: may need a proper handling, %d", state);
- if (ws_vm2013->cpu_action->remains > 0)
- XBT_CRITICAL("FIXME: need copy the state(?), %f", ws_vm2013->cpu_action->remains);
-
- int ret = surf_cpu_model_pm->action_unref(ws_vm2013->cpu_action);
- xbt_assert(ret == 1, "Bug: some resource still remains");
-
- ws_vm2013->cpu_action = new_cpu_action;
- }
-
- XBT_DEBUG("migrate VM(%s): change net_elm (%p to %p)", vm_name, old_net_elm, new_net_elm);
- XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst);
-}
-
-/*
- * A physical host does not disapper in the current SimGrid code, but a VM may
- * disapper during a simulation.
- */
-static void vm_ws_destroy(void *ind_vm_workstation)
-{
- /* ind_phys_workstation equals to smx_host_t */
-
- /* Before clearing the entries in host_lib, we have to pick up resources. */
- workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_workstation);
- cpu_Cas01_t cpu = surf_cpu_resource_priv(ind_vm_workstation);
- const char *name = vm_ws->ws.generic_resource.name;
-
- xbt_assert(vm_ws);
- xbt_assert(vm_ws->ws.generic_resource.model == surf_vm_workstation_model);
-
-
- /* We deregister objects from host_lib, without invoking the freeing callback
- * of each level.
- *
- * Do not call xbt_lib_remove() here. It deletes all levels of the key,
- * including MSG_HOST_LEVEL and others. We should unregister only what we know.
- */
- xbt_lib_unset(host_lib, name, SURF_CPU_LEVEL, 0);
- xbt_lib_unset(host_lib, name, ROUTING_HOST_LEVEL, 0);
- xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL, 0);
-
- /* TODO: comment out when VM stroage is implemented. */
- // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
-
-
- /* Free the cpu_action of the VM. */
- int ret = surf_cpu_model_pm->action_unref(vm_ws->cpu_action);
- xbt_assert(ret == 1, "Bug: some resource still remains");
-
- /* Free the cpu resource of the VM. If using power_trace, we will have to
- * free other objects than lmm_constraint. */
- surf_model_t cpu_model = cpu->generic_resource.model;
- lmm_constraint_free(cpu_model->model_private->maxmin_system, cpu->constraint);
- {
- unsigned long i;
- for (i = 0; i < cpu->core; i++) {
- void *cnst_id = cpu->constraint_core[i]->id;
- lmm_constraint_free(cpu_model->model_private->maxmin_system, cpu->constraint_core[i]);
- xbt_free(cnst_id);
- }
-
- xbt_free(cpu->constraint_core);
- }
-
- surf_resource_free(cpu);
-
- /* Free the network resource of the VM. */
- // Nothing has to be done, because net_elmts is just a pointer on the physical one
-
- /* Free the storage resource of the VM. */
- // Not relevant yet
-
- /* Free the workstation resource of the VM. */
- surf_resource_free(vm_ws);
-}
-
-static int vm_ws_get_state(void *ind_vm_ws)
-{
- return ((workstation_VM2013_t) surf_workstation_resource_priv(ind_vm_ws))->current_state;
-}
-
-static void vm_ws_set_state(void *ind_vm_ws, int state)
-{
- ((workstation_VM2013_t) surf_workstation_resource_priv(ind_vm_ws))->current_state = state;
-}
-
-static void vm_ws_suspend(void *ind_vm_ws)
-{
- workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_ws);
-
- surf_action_suspend(vm_ws->cpu_action);
-
- vm_ws->current_state = SURF_VM_STATE_SUSPENDED;
-}
-
-static void vm_ws_resume(void *ind_vm_ws)
-{
- workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_ws);
-
- surf_action_resume(vm_ws->cpu_action);
-
- vm_ws->current_state = SURF_VM_STATE_RUNNING;
-}
-
-static void vm_ws_save(void *ind_vm_ws)
-{
- workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_ws);
-
- vm_ws->current_state = SURF_VM_STATE_SAVING;
-
- /* FIXME: do something here */
- surf_action_suspend(vm_ws->cpu_action);
-
- vm_ws->current_state = SURF_VM_STATE_SAVED;
-}
-
-static void vm_ws_restore(void *ind_vm_ws)
-{
- workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_ws);
-
- vm_ws->current_state = SURF_VM_STATE_RESTORING;
-
- /* FIXME: do something here */
- surf_action_resume(vm_ws->cpu_action);
-
- vm_ws->current_state = SURF_VM_STATE_RUNNING;
-}
-
-static double get_solved_value(surf_action_t cpu_action)
-{
- lmm_variable_t var = ((surf_action_lmm_t) cpu_action)->variable;
-
- return var->value;
-}
-
-/* In the real world, processes on the guest operating system will be somewhat
- * degraded due to virtualization overhead. The total CPU share that these
- * processes get is smaller than that of the VM process gets on a host
- * operating system. */
-// const double virt_overhead = 0.95;
-const double virt_overhead = 1;
-
-static double vm_ws_share_resources(surf_model_t workstation_model, double now)
-{
- /* TODO: udpate action's cost with the total cost of processes on the VM. */
-
-
- /* 0. Make sure that we already calculated the resource share at the physical
- * machine layer. */
- {
- unsigned int index_of_pm_ws_model = xbt_dynar_search(model_list_invoke, &surf_workstation_model);
- unsigned int index_of_vm_ws_model = xbt_dynar_search(model_list_invoke, &surf_vm_workstation_model);
- xbt_assert((index_of_pm_ws_model < index_of_vm_ws_model), "Cannot assume surf_workstation_model comes before");
-
- /* Another option is that we call sub_ws->share_resource() here. The
- * share_resource() function has no side-effect. We can call it here to
- * ensure that. */
- }
-
-
- /* 1. Now we know how many resource should be assigned to each virtual
- * machine. We update constraints of the virtual machine layer.
- *
- *
- * If we have two virtual machine (VM1 and VM2) on a physical machine (PM1).
- * X1 + X2 = C (Equation 1)
- * where
- * the resource share of VM1: X1
- * the resource share of VM2: X2
- * the capacity of PM1: C
- *
- * Then, if we have two process (P1 and P2) on VM1.
- * X1_1 + X1_2 = X1 (Equation 2)
- * where
- * the resource share of P1: X1_1
- * the resource share of P2: X1_2
- * the capacity of VM1: X1
- *
- * Equation 1 was solved in the physical machine layer.
- * Equation 2 is solved in the virtual machine layer (here).
- * X1 must be passed to the virtual machine laye as a constraint value.
- *
- **/
-
- /* iterate for all hosts including virtual machines */
- xbt_lib_cursor_t cursor;
- char *key;
- void **ind_host;
- xbt_lib_foreach(host_lib, cursor, key, ind_host) {
- workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL];
- cpu_Cas01_t cpu_cas01 = ind_host[SURF_CPU_LEVEL];
-
- if (!ws_clm03)
- continue;
- /* skip if it is not a virtual machine */
- if (ws_clm03->generic_resource.model != surf_vm_workstation_model)
- continue;
- xbt_assert(cpu_cas01, "cpu-less workstation");
-
- /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
- workstation_VM2013_t ws_vm2013 = (workstation_VM2013_t) ws_clm03;
-
- double solved_value = get_solved_value(ws_vm2013->cpu_action);
- XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value,
- ws_clm03->generic_resource.name, ws_vm2013->sub_ws->generic_resource.name);
-
- // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution.
- // cpu_cas01->constraint->bound = solved_value;
- surf_model_t cpu_model = cpu_cas01->generic_resource.model;
- xbt_assert(cpu_model == surf_cpu_model_vm);
- lmm_system_t vcpu_system = cpu_model->model_private->maxmin_system;
- lmm_update_constraint_bound(vcpu_system, cpu_cas01->constraint, virt_overhead * solved_value);
- }
-
-
- /* 2. Calculate resource share at the virtual machine layer. */
- double ret = ws_share_resources(workstation_model, now);
-
-
- /* FIXME: 3. do we have to re-initialize our cpu_action object? */
-#if 0
- /* iterate for all hosts including virtual machines */
- xbt_lib_foreach(host_lib, cursor, key, ind_host) {
- workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL];
-
- /* skip if it is not a virtual machine */
- if (!ws_clm03)
- continue;
- if (ws_clm03->generic_resource.model != surf_vm_workstation_model)
- continue;
-
- /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
- {
-#if 0
- workstation_VM2013_t ws_vm2013 = (workstation_VM2013_t) ws_clm03;
- XBT_INFO("cost %f remains %f start %f finish %f", ws_vm2013->cpu_action->cost,
- ws_vm2013->cpu_action->remains,
- ws_vm2013->cpu_action->start,
- ws_vm2013->cpu_action->finish
- );
-#endif
-#if 0
- void *ind_sub_host = xbt_lib_get_elm_or_null(host_lib, ws_vm2013->sub_ws->generic_resource.name);
- surf_cpu_model_pm->action_unref(ws_vm2013->cpu_action);
- /* FIXME: this means busy loop? */
- // ws_vm2013->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_sub_host, GUESTOS_NOISE);
- ws_vm2013->cpu_action = surf_cpu_model_pm->extension.cpu.execute(ind_sub_host, 0);
-#endif
-
- }
- }
-#endif
-
-
- return ret;
-}
-
-
-/*
- * A surf level object will be useless in the upper layer. Returing the
- * dict_elm of the host.
- **/
-static void *vm_ws_get_pm(void *ind_vm_ws)
-{
- workstation_VM2013_t vm_ws = surf_workstation_resource_priv(ind_vm_ws);
- const char *sub_ws_name = vm_ws->sub_ws->generic_resource.name;
-
- return xbt_lib_get_elm_or_null(host_lib, sub_ws_name);
-}
-
-
-/* Adding a task to a VM updates the VCPU task on its physical machine. */
-static surf_action_t vm_ws_execute(void *workstation, double size)
-{
- surf_resource_t ws = ((surf_resource_t) surf_workstation_resource_priv(workstation));
-
- xbt_assert(ws->model->type == SURF_MODEL_TYPE_VM_WORKSTATION);
- workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
-
- double old_cost = vm_ws->cpu_action->cost;
- double new_cost = old_cost + size;
-
- XBT_DEBUG("VM(%s)@PM(%s): update dummy action's cost (%f -> %f)",
- ws->name, vm_ws->sub_ws->generic_resource.name,
- old_cost, new_cost);
-
- vm_ws->cpu_action->cost = new_cost;
-
- return ws_execute(workstation, size);
-}
-
-static void vm_ws_action_cancel(surf_action_t action)
-{
- XBT_CRITICAL("FIXME: Not yet implemented. Reduce dummy action's cost by %f", action->cost);
-
- ws_action_cancel(action);
-}
-
-
-/* Now we can set bound for each task by using MSG_task_set_bound. But, it does
- * not work for the dummy CPU action of a VM. Here, we add the set_bound
- * function for the dummy CPU action. */
-static void vm_ws_set_vm_bound(void *vm, double bound)
-{
- surf_resource_t ws = ((surf_resource_t) surf_workstation_resource_priv(vm));
- xbt_assert(ws->model->type == SURF_MODEL_TYPE_VM_WORKSTATION);
- workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
-
- surf_action_set_bound(vm_ws->cpu_action, bound);
-}
-
-
-/* set the affinity of a VM to the CPU cores of a PM */
-static void vm_ws_set_vm_affinity(void *vm, void *pm, unsigned long mask)
-{
- surf_resource_t ws = ((surf_resource_t) surf_workstation_resource_priv(vm));
- xbt_assert(ws->model->type == SURF_MODEL_TYPE_VM_WORKSTATION);
- workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
-
- surf_cpu_model_pm->set_affinity(vm_ws->cpu_action, pm, mask);
-}
-
-
-static void surf_vm_workstation_model_init_internal(void)
-{
- surf_model_t model = surf_model_init();
-
- model->name = "Virtual Workstation";
- model->type = SURF_MODEL_TYPE_VM_WORKSTATION;
-
- model->action_unref = ws_action_unref;
- model->action_cancel = vm_ws_action_cancel;
- // model->action_state_set = ws_action_state_set;
-
-
- model->model_private->share_resources = vm_ws_share_resources;
- model->model_private->resource_used = ws_resource_used;
- model->model_private->update_actions_state = ws_update_actions_state;
- model->model_private->update_resource_state = ws_update_resource_state;
- model->model_private->finalize = ws_finalize;
-
-
- /* operation for an action, not for VM it self */
- model->suspend = ws_action_suspend;
- model->resume = ws_action_resume;
-// model->is_suspended = ws_action_is_suspended;
-// model->set_max_duration = ws_action_set_max_duration;
- model->set_priority = ws_action_set_priority;
- model->set_bound = ws_action_set_bound;
- model->set_affinity = ws_action_set_affinity;
-// #ifdef HAVE_TRACING
-// model->set_category = ws_action_set_category;
-// #endif
- model->get_remains = ws_action_get_remains;
-// #ifdef HAVE_LATENCY_BOUND_TRACKING
-// model->get_latency_limited = ws_get_latency_limited;
-// #endif
-
-
-
-
-
-
-
- xbt_assert(surf_cpu_model_vm);
- model->extension.workstation.cpu_model = surf_cpu_model_vm;
-
- model->extension.workstation.execute = vm_ws_execute;
- model->extension.workstation.sleep = ws_action_sleep;
- model->extension.workstation.get_state = ws_get_state;
- model->extension.workstation.get_speed = ws_get_speed;
- // model->extension.workstation.get_available_speed = ws_get_available_speed;
-
- // model->extension.workstation.communicate = ws_communicate;
- // model->extension.workstation.get_route = ws_get_route;
- // model->extension.workstation.execute_parallel_task = ws_execute_parallel_task;
- // model->extension.workstation.get_link_bandwidth = ws_get_link_bandwidth;
- // model->extension.workstation.get_link_latency = ws_get_link_latency;
- // model->extension.workstation.link_shared = ws_link_shared;
- // model->extension.workstation.get_properties = ws_get_properties;
-
- // model->extension.workstation.open = ws_action_open;
- // model->extension.workstation.close = ws_action_close;
- // model->extension.workstation.read = ws_action_read;
- // model->extension.workstation.write = ws_action_write;
- // model->extension.workstation.stat = ws_action_stat;
- // model->extension.workstation.unlink = ws_action_unlink;
- // model->extension.workstation.ls = ws_action_ls;
-
-
- model->extension.vm_workstation.create = vm_ws_create;
- model->extension.vm_workstation.set_state = vm_ws_set_state;
- model->extension.vm_workstation.get_state = vm_ws_get_state;
- model->extension.vm_workstation.migrate = vm_ws_migrate;
- model->extension.vm_workstation.destroy = vm_ws_destroy;
- model->extension.vm_workstation.suspend = vm_ws_suspend;
- model->extension.vm_workstation.resume = vm_ws_resume;
- model->extension.vm_workstation.save = vm_ws_save;
- model->extension.vm_workstation.restore = vm_ws_restore;
- model->extension.vm_workstation.get_pm = vm_ws_get_pm;
- model->extension.vm_workstation.set_vm_bound = vm_ws_set_vm_bound;
- model->extension.vm_workstation.set_vm_affinity = vm_ws_set_vm_affinity;
-
- model->extension.workstation.set_params = ws_set_params;
- model->extension.workstation.get_params = ws_get_params;
-
- surf_vm_workstation_model = model;
-}
-
-void surf_vm_workstation_model_init(void)
-{
- surf_vm_workstation_model_init_internal();
- xbt_dynar_push(model_list, &surf_vm_workstation_model);
- xbt_dynar_push(model_list_invoke, &surf_vm_workstation_model);
-}
+++ /dev/null
-/* Copyright (c) 2009, 2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef VM_WS_PRIVATE_H_
-#define VM_WS_PRIVATE_H_
-
-#define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
- // It corresponds to the cost of a VM running no tasks.
-
-#include "workstation_private.h"
-
-/* NOTE:
- * The workstation_VM2013 struct includes the workstation_CLM03 struct in
- * its first member. The workstation_VM2013_t struct inherites all
- * characteristics of the workstation_CLM03 struct. So, we can treat a
- * workstation_VM2013 object as a workstation_CLM03 if necessary.
- **/
-typedef struct workstation_VM2013 {
- s_workstation_CLM03_t ws; /* a VM is a ''v''host */
-
- /* The workstation object of the lower layer */
- workstation_CLM03_t sub_ws; // Pointer to the ''host'' OS
-
- e_surf_vm_state_t current_state;
-
-
- surf_action_t cpu_action;
-
-} s_workstation_VM2013_t, *workstation_VM2013_t;
-
-
-void surf_vm_workstation_model_init(void);
-
-#endif /* VM_WS_PRIVATE_H_ */
+++ /dev/null
-/* Copyright (c) 2004-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "xbt/ex.h"
-#include "xbt/dict.h"
-#include "portable.h"
-#include "surf_private.h"
-#include "storage_private.h"
-#include "surf/surf_resource.h"
-#include "simgrid/sg_config.h"
-<<<<<<< HEAD
-#include <inttypes.h>
-
-typedef struct workstation_CLM03 {
- s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
- void *net_elm;
- xbt_dynar_t storage;
-} s_workstation_CLM03_t, *workstation_CLM03_t;
-||||||| merged common ancestors
-
-typedef struct workstation_CLM03 {
- s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
- void *net_elm;
- xbt_dynar_t storage;
-} s_workstation_CLM03_t, *workstation_CLM03_t;
-=======
-#include "workstation_private.h"
-#include "vm_workstation_private.h"
-#include "cpu_cas01_private.h"
-#include "maxmin_private.h"
->>>>>>> surf++
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
- "Logging specific to the SURF workstation module");
-
-surf_model_t surf_workstation_model = NULL;
-
-
-static void workstation_new(sg_platf_host_cbarg_t host)
-{
- const char *name = host->id;
-
- /* NOTE: The properties object is NULL, because the current code uses that of
- * that of a cpu resource. */
- workstation_CLM03_t ws = (workstation_CLM03_t) surf_resource_new(sizeof(s_workstation_CLM03_t), surf_workstation_model, name, NULL, NULL);
-
- ws->storage = xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL);
- ws->net_elm = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
-
- XBT_DEBUG("Create ws %s with %ld mounted disks", name, xbt_dynar_length(ws->storage));
- xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws);
-}
-
-static void ws_parallel_action_cancel(surf_action_t action)
-{
- THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
-}
-
-static int ws_parallel_action_free(surf_action_t action)
-{
- THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
- return -1;
-}
-
-int ws_action_unref(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- return surf_network_model->action_unref(action);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- return action->model_obj->action_unref(action);
- // previously was: Adrien/Arnaud 6 feb
- // surf_cpu_model->action_unref(action);
- else if (action->model_obj->type == SURF_MODEL_TYPE_WORKSTATION)
- return ws_parallel_action_free(action);
- else
- DIE_IMPOSSIBLE;
- return 0;
-}
-
-void ws_action_cancel(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->action_cancel(action);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->action_cancel(action);
- else if (action->model_obj->type == SURF_MODEL_TYPE_WORKSTATION)
- ws_parallel_action_cancel(action);
- else
- DIE_IMPOSSIBLE;
- return;
-}
-
-static void ws_action_state_set(surf_action_t action,
- e_surf_action_state_t state)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->action_state_set(action, state);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->action_state_set(action, state);
- else if (action->model_obj->type == SURF_MODEL_TYPE_WORKSTATION)
- surf_action_state_set(action, state);
- else
- DIE_IMPOSSIBLE;
- return;
-}
-
-
-/* -- The callback functions at model_private -- */
-/* These callbacks are also used for the vm workstation model. */
-int ws_resource_used(void *resource_id)
-{
- /* This model does not implement parallel tasks */
- THROW_IMPOSSIBLE;
- return -1;
-}
-
-
-/* TODO: iterating active constraint_set may be faster? */
-#if 0
-static void deactivate_dummy_cpu_action(void)
-{
- lmm_system_t sys = surf_cpu_model_vm->model_private->maxmin_system;
-
- lmm_constraint_t cnst;
- xbt_swag_foreach(cnst, &sys->active_constraint_set) {
- /* get vcpu resource */
- surf_resource_t cpu = lmm_constraint_id(cnst);
- xbt_assert(cpu->model == surf_cpu_model_vm);
-
- /* get vm_ws resource */
- workstation_CLM03_t ws = xbt_lib_get_or_null(host_lib, cpu->name, SURF_WKS_LEVEL);
-
- /* make sure we can cast */
- xbt_assert(ws->generic_resouce.model == surf_vm_workstation_model);
- workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
-
- /* make it active in the PM layer */
- surf_action_set_priority(vm_ws->cpu_action, 1);
- }
-}
-#endif
-
-
-/* TODO: Delete this unused code if everything looks good. */
-#if 0
-static int constraint_is_active(cpu_Cas01_t cpu_cas01)
-{
- surf_model_t cpu_model = cpu_cas01->generic_resource.model;
- lmm_system_t sys = cpu_model->model_private->maxmin_system;
- int found = 0;
- lmm_constraint_t cnst_tmp;
-
- xbt_swag_foreach(cnst_tmp, &sys->active_constraint_set) {
- if (cnst_tmp == cpu_cas01->constraint) {
- found = 1;
- break;
- }
- }
-
- return found;
-}
-#endif
-
-
-/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the
- * constraint (capacity) of the VM in the PM layer. If the VM does not have any
- * active task, the dummy CPU action must be deactivated, so that the VM does
- * not get any CPU share in the PM layer. */
-static void adjust_weight_of_dummy_cpu_actions(void)
-{
- /* iterate for all hosts including virtual machines */
- xbt_lib_cursor_t cursor;
- char *key;
- void **ind_host;
-
- xbt_lib_foreach(host_lib, cursor, key, ind_host) {
- workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL];
- cpu_Cas01_t cpu_cas01 = ind_host[SURF_CPU_LEVEL];
-
- if (!ws_clm03)
- continue;
- /* skip if it is not a virtual machine */
- if (ws_clm03->generic_resource.model != surf_vm_workstation_model)
- continue;
- xbt_assert(cpu_cas01, "cpu-less workstation");
-
- /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
- workstation_VM2013_t ws_vm2013 = (workstation_VM2013_t) ws_clm03;
-
- lmm_system_t sys = surf_cpu_model_vm->model_private->maxmin_system;
- int is_active = lmm_constraint_used(sys, cpu_cas01->constraint);
- // int is_active_old = constraint_is_active(cpu_cas01);
-
- // {
- // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old);
- // }
-
- if (is_active) {
- /* some tasks exist on this VM */
- XBT_DEBUG("set the weight of the dummy CPU action on PM to 1");
-
- /* FIXME: we shoud use lmm_update_variable_weight() ? */
- /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */
- surf_action_set_priority(ws_vm2013->cpu_action, 1);
-
- } else {
- /* no task exits on this VM */
- XBT_DEBUG("set the weight of the dummy CPU action on PM to 0");
-
- surf_action_set_priority(ws_vm2013->cpu_action, 0);
- }
- }
-}
-
-
-double ws_share_resources(surf_model_t workstation_model, double now)
-{
- if (workstation_model->type == SURF_MODEL_TYPE_WORKSTATION)
- adjust_weight_of_dummy_cpu_actions();
-
- /* Invoke the share_resources() callback of the physical cpu model object and
- * the network model objects. */
- surf_model_t cpu_model = workstation_model->extension.workstation.cpu_model;
- surf_model_t net_model = surf_network_model;
-
- double min_by_cpu = cpu_model->model_private->share_resources(cpu_model, now);
- double min_by_net = net_model->model_private->share_resources(net_model, now);
-
- XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f",
- workstation_model, cpu_model->name, min_by_cpu, net_model->name, min_by_net);
-
- if (min_by_cpu >= 0.0 && min_by_net >= 0.0)
- return min(min_by_cpu, min_by_net);
- else if (min_by_cpu >= 0.0)
- return min_by_cpu;
- else if (min_by_net >= 0.0)
- return min_by_net;
- else
- return min_by_cpu; /* probably min_by_cpu == min_by_net == -1 */
-}
-
-void ws_update_actions_state(surf_model_t workstation_model, double now, double delta)
-{
- return;
-}
-
-void ws_update_resource_state(void *id, tmgr_trace_event_t event_type, double value, double date)
-{
- /* This model does not implement parallel tasks */
- THROW_IMPOSSIBLE;
-}
-
-void ws_finalize(surf_model_t workstation_model)
-{
- surf_model_exit(workstation_model);
- workstation_model = NULL;
-}
-
-
-
-surf_action_t ws_execute(void *workstation, double size)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.execute(workstation, size);
-}
-
-surf_action_t ws_action_sleep(void *workstation, double duration)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.sleep(workstation, duration);
-}
-
-void ws_action_suspend(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->suspend(action);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->suspend(action);
- else
- DIE_IMPOSSIBLE;
-}
-
-void ws_action_resume(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->resume(action);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->resume(action);
- else
- DIE_IMPOSSIBLE;
-}
-
-static int ws_action_is_suspended(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- return surf_network_model->is_suspended(action);
- if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- return action->model_obj->is_suspended(action);
- DIE_IMPOSSIBLE;
- return -1;
-}
-
-static void ws_action_set_max_duration(surf_action_t action,
- double duration)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->set_max_duration(action, duration);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->set_max_duration(action, duration);
- else
- DIE_IMPOSSIBLE;
-}
-
-void ws_action_set_priority(surf_action_t action, double priority)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->set_priority(action, priority);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->set_priority(action, priority);
- else
- DIE_IMPOSSIBLE;
-}
-
-void ws_action_set_bound(surf_action_t action, double bound)
-{
- /* FIXME: only for CPU model object? */
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->set_bound(action, bound);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->set_bound(action, bound);
- else
- DIE_IMPOSSIBLE;
-}
-
-void ws_action_set_affinity(surf_action_t action, void *workstation, unsigned long mask)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- DIE_IMPOSSIBLE;
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->set_affinity(action, workstation, mask);
- else
- DIE_IMPOSSIBLE;
-}
-
-#ifdef HAVE_TRACING
-static void ws_action_set_category(surf_action_t action, const char *category)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- surf_network_model->set_category(action, category);
- else if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- action->model_obj->set_category(action, category);
- else
- DIE_IMPOSSIBLE;
-}
-#endif
-
-#ifdef HAVE_LATENCY_BOUND_TRACKING
-static int ws_get_latency_limited(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- return surf_network_model->get_latency_limited(action);
- else
- return 0;
-}
-#endif
-
-double ws_action_get_remains(surf_action_t action)
-{
- if (action->model_obj->type == SURF_MODEL_TYPE_NETWORK)
- return surf_network_model->get_remains(action);
- if (action->model_obj->type == SURF_MODEL_TYPE_CPU)
- return action->model_obj->get_remains(action);
- DIE_IMPOSSIBLE;
- return -1.0;
-}
-
-static surf_action_t ws_communicate(void *workstation_src,
- void *workstation_dst, double size,
- double rate)
-{
- workstation_CLM03_t src = surf_workstation_resource_priv(workstation_src);
- workstation_CLM03_t dst = surf_workstation_resource_priv(workstation_dst);
- return surf_network_model->extension.network.
- communicate(src->net_elm,
- dst->net_elm, size, rate);
-}
-
-e_surf_resource_state_t ws_get_state(void *workstation)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.get_state(workstation);
-}
-
-static void ws_set_state(void *workstation, e_surf_resource_state_t state)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- cpu->model->extension.cpu.set_state(workstation, state);
-}
-
-double ws_get_speed(void *workstation, double load)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.get_speed(workstation, load);
-}
-
-static int ws_get_core(void *workstation)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.get_core(workstation);
-}
-static double ws_get_available_speed(void *workstation)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.get_available_speed(workstation);
-}
-
-static double ws_get_current_power_peak(void *workstation)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.
- get_current_power_peak(workstation);
-}
-
-static double ws_get_power_peak_at(void *workstation, int pstate_index)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.
- get_power_peak_at(workstation, pstate_index);
-}
-
-static int ws_get_nb_pstates(void *workstation)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.
- get_nb_pstates(workstation);
-}
-
-static void ws_set_power_peak_at(void *workstation, int pstate_index)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- cpu->model->extension.cpu.
- set_power_peak_at(workstation, pstate_index);
-}
-
-static double ws_get_consumed_energy(void *workstation)
-{
- surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
- return cpu->model->extension.cpu.
- get_consumed_energy(workstation);
-}
-
-
-static surf_action_t ws_execute_parallel_task(int workstation_nb,
- void **workstation_list,
- double *computation_amount,
- double *communication_amount,
- double rate)
-{
-#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
- if ((workstation_nb == 1)
- && (cost_or_zero(communication_amount, 0) == 0.0))
- return ws_execute(workstation_list[0], computation_amount[0]);
- else if ((workstation_nb == 1)
- && (cost_or_zero(computation_amount, 0) == 0.0))
- return ws_communicate(workstation_list[0], workstation_list[0],communication_amount[0], rate);
- else if ((workstation_nb == 2)
- && (cost_or_zero(computation_amount, 0) == 0.0)
- && (cost_or_zero(computation_amount, 1) == 0.0)) {
- int i,nb = 0;
- double value = 0.0;
-
- for (i = 0; i < workstation_nb * workstation_nb; i++) {
- if (cost_or_zero(communication_amount, i) > 0.0) {
- nb++;
- value = cost_or_zero(communication_amount, i);
- }
- }
- if (nb == 1)
- return ws_communicate(workstation_list[0], workstation_list[1],value, rate);
- }
-#undef cost_or_zero
-
- THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
- return NULL;
-}
-
-
-/* returns an array of network_link_CM02_t */
-static xbt_dynar_t ws_get_route(void *workstation_src, void *workstation_dst)
-{
- XBT_DEBUG("ws_get_route");
- workstation_CLM03_t src = surf_workstation_resource_priv(workstation_src);
- workstation_CLM03_t dst = surf_workstation_resource_priv(workstation_dst);
- return surf_network_model->extension.
- network.get_route(src->net_elm,
- dst->net_elm);
-}
-
-static double ws_get_link_bandwidth(const void *link)
-{
- return surf_network_model->extension.network.get_link_bandwidth(link);
-}
-
-static double ws_get_link_latency(const void *link)
-{
- return surf_network_model->extension.network.get_link_latency(link);
-}
-
-static int ws_link_shared(const void *link)
-{
- return surf_network_model->extension.network.link_shared(link);
-}
-
-static xbt_dict_t ws_get_properties(const void *ws)
-{
- return surf_resource_properties(surf_cpu_resource_priv(ws));
-}
-
-static storage_t find_storage_on_mount_list(void *workstation,const char* mount)
-{
- storage_t st = NULL;
- s_mount_t mnt;
- unsigned int cursor;
- workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation);
- xbt_dynar_t storage_list = ws->storage;
-
- XBT_DEBUG("Search for storage name '%s' on '%s'",mount,ws->generic_resource.name);
- xbt_dynar_foreach(storage_list,cursor,mnt)
- {
- XBT_DEBUG("See '%s'",mnt.name);
- if(!strcmp(mount,mnt.name)){
- st = mnt.storage;
- break;
- }
- }
- if(!st) xbt_die("Can't find mount '%s' for '%s'",mount,ws->generic_resource.name);
- return st;
-}
-
-static xbt_dict_t ws_get_storage_list(void *workstation)
-{
- s_mount_t mnt;
- unsigned int i;
- xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
- char *storage_name = NULL;
-
- workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation);
- xbt_dynar_t storages = ws->storage;
-
- xbt_dynar_foreach(storages,i,mnt){
- storage_name = ((storage_t)mnt.storage)->generic_resource.name;
- xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
- }
- return storage_list;
-}
-
-static surf_action_t ws_action_open(void *workstation, const char* mount,
- const char* path)
-{
- storage_t st = find_storage_on_mount_list(workstation, mount);
- XBT_DEBUG("OPEN on disk '%s'",st->generic_resource.name);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.open(st, mount, path);
-}
-
-static surf_action_t ws_action_close(void *workstation, surf_file_t fd)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- XBT_DEBUG("CLOSE on disk '%s'",st->generic_resource.name);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.close(st, fd);
-}
-
-static surf_action_t ws_action_read(void *workstation, surf_file_t fd, sg_storage_size_t size)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- XBT_DEBUG("READ on disk '%s'",st->generic_resource.name);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.read(st, fd, size);
-}
-
-static surf_action_t ws_action_write(void *workstation, surf_file_t fd, sg_storage_size_t size)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.write(st, fd, size);
-}
-
-static int ws_file_unlink(void *workstation, surf_file_t fd)
-{
- if (!fd){
- XBT_WARN("No such file descriptor. Impossible to unlink");
- return 0;
- } else {
-// XBT_INFO("%s %zu", fd->storage, fd->size);
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- xbt_dict_t content_dict = (st)->content;
- /* Check if the file is on this storage */
- if (!xbt_dict_get_or_null(content_dict, fd->name)){
- XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
- st->generic_resource.name);
- return 0;
- } else {
- XBT_DEBUG("UNLINK on disk '%s'",st->generic_resource.name);
- st->used_size -= fd->size;
-
- // Remove the file from storage
- xbt_dict_remove(content_dict,fd->name);
-
- free(fd->name);
- free(fd->mount);
- xbt_free(fd);
- return 1;
- }
- }
-}
-
-static surf_action_t ws_action_ls(void *workstation, const char* mount,
- const char *path)
-{
- XBT_DEBUG("LS on mount '%s' and file '%s'",mount, path);
- storage_t st = find_storage_on_mount_list(workstation, mount);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.ls(st, path);
-}
-
-static sg_storage_size_t ws_file_get_size(void *workstation, surf_file_t fd)
-{
- return fd->size;
-}
-
-static xbt_dynar_t ws_file_get_info(void *workstation, surf_file_t fd)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
- *psize = fd->size;
- xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
- xbt_dynar_push_as(info, sg_storage_size_t *, psize);
- xbt_dynar_push_as(info, void *, fd->mount);
- xbt_dynar_push_as(info, void *, st->generic_resource.name);
- xbt_dynar_push_as(info, void *, st->type_id);
- xbt_dynar_push_as(info, void *, st->content_type);
-
- return info;
-}
-
-static sg_storage_size_t ws_storage_get_free_size(void *workstation,const char* name)
-{
- storage_t st = find_storage_on_mount_list(workstation, name);
- return st->size - st->used_size;
-}
-
-static sg_storage_size_t ws_storage_get_used_size(void *workstation,const char* name)
-{
- storage_t st = find_storage_on_mount_list(workstation, name);
- return st->used_size;
-}
-
-void ws_get_params(void *ws, ws_params_t params)
-{
- workstation_CLM03_t ws_clm03 = surf_workstation_resource_priv(ws);
- memcpy(params, &ws_clm03->params, sizeof(s_ws_params_t));
-}
-
-void ws_set_params(void *ws, ws_params_t params)
-{
- workstation_CLM03_t ws_clm03 = surf_workstation_resource_priv(ws);
- /* may check something here. */
- memcpy(&ws_clm03->params, params, sizeof(s_ws_params_t));
-}
-
-static xbt_dynar_t ws_get_vms(void *pm)
-{
- xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL);
-
- /* iterate for all hosts including virtual machines */
- xbt_lib_cursor_t cursor;
- char *key;
- void **ind_host;
- xbt_lib_foreach(host_lib, cursor, key, ind_host) {
- workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL];
- if (!ws_clm03)
- continue;
- /* skip if it is not a virtual machine */
- if (ws_clm03->generic_resource.model != surf_vm_workstation_model)
- continue;
-
- /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
- workstation_VM2013_t ws_vm2013 = (workstation_VM2013_t) ws_clm03;
- if (pm == ws_vm2013->sub_ws)
- xbt_dynar_push(dyn, &ws_vm2013->sub_ws);
- }
-
- return dyn;
-}
-
-
-static void surf_workstation_model_init_internal(void)
-{
- surf_model_t model = surf_model_init();
-
- model->name = "Workstation";
- model->type = SURF_MODEL_TYPE_WORKSTATION;
- model->action_unref = ws_action_unref;
- model->action_cancel = ws_action_cancel;
- model->action_state_set = ws_action_state_set;
-
- model->model_private->resource_used = ws_resource_used;
- model->model_private->share_resources = ws_share_resources;
- model->model_private->update_actions_state = ws_update_actions_state;
- model->model_private->update_resource_state = ws_update_resource_state;
- model->model_private->finalize = ws_finalize;
-
- model->suspend = ws_action_suspend;
- model->resume = ws_action_resume;
- model->is_suspended = ws_action_is_suspended;
- model->set_max_duration = ws_action_set_max_duration;
- model->set_priority = ws_action_set_priority;
- model->set_bound = ws_action_set_bound;
- model->set_affinity = ws_action_set_affinity;
- #ifdef HAVE_TRACING
- model->set_category = ws_action_set_category;
- #endif
- model->get_remains = ws_action_get_remains;
- #ifdef HAVE_LATENCY_BOUND_TRACKING
- model->get_latency_limited = ws_get_latency_limited;
- #endif
-
- /* For VM support, we have a surf cpu model object for each workstation model
- * object. The physical workstation model object has the cpu model object of
- * the physical machine layer. */
- xbt_assert(surf_cpu_model_pm);
- model->extension.workstation.cpu_model = surf_cpu_model_pm;
-
- model->extension.workstation.execute = ws_execute;
- model->extension.workstation.sleep = ws_action_sleep;
- model->extension.workstation.get_state = ws_get_state;
- model->extension.workstation.set_state = ws_set_state;
- model->extension.workstation.get_core = ws_get_core;
- model->extension.workstation.get_speed = ws_get_speed;
- model->extension.workstation.get_available_speed =
- ws_get_available_speed;
- model->extension.workstation.get_current_power_peak = ws_get_current_power_peak;
- model->extension.workstation.get_power_peak_at = ws_get_power_peak_at;
- model->extension.workstation.get_nb_pstates = ws_get_nb_pstates;
- model->extension.workstation.set_power_peak_at = ws_set_power_peak_at;
- model->extension.workstation.get_consumed_energy = ws_get_consumed_energy;
-
- model->extension.workstation.communicate = ws_communicate;
- model->extension.workstation.get_route = ws_get_route;
- model->extension.workstation.execute_parallel_task = ws_execute_parallel_task;
- model->extension.workstation.get_link_bandwidth = ws_get_link_bandwidth;
- model->extension.workstation.get_link_latency = ws_get_link_latency;
- model->extension.workstation.link_shared = ws_link_shared;
- model->extension.workstation.get_properties = ws_get_properties;
-
- model->extension.workstation.open = ws_action_open;
- model->extension.workstation.close = ws_action_close;
- model->extension.workstation.read = ws_action_read;
- model->extension.workstation.write = ws_action_write;
- model->extension.workstation.unlink = ws_file_unlink;
- model->extension.workstation.ls = ws_action_ls;
- model->extension.workstation.get_size = ws_file_get_size;
- model->extension.workstation.get_info = ws_file_get_info;
- model->extension.workstation.get_free_size = ws_storage_get_free_size;
- model->extension.workstation.get_used_size = ws_storage_get_used_size;
- model->extension.workstation.get_storage_list = ws_get_storage_list;
-
- model->extension.workstation.get_params = ws_get_params;
- model->extension.workstation.set_params = ws_set_params;
- model->extension.workstation.get_vms = ws_get_vms;
-
- surf_workstation_model = model;
-}
-
-void surf_workstation_model_init_current_default(void)
-{
- xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
- surf_cpu_model_init_Cas01();
- surf_network_model_init_LegrandVelho();
-
- /* surf_cpu_mode_pm and surf_network_model must be initialized in advance. */
- xbt_assert(surf_cpu_model_pm);
- xbt_assert(surf_network_model);
- surf_workstation_model_init_internal();
-
- xbt_dynar_push(model_list, &surf_workstation_model);
- xbt_dynar_push(model_list_invoke, &surf_workstation_model);
- sg_platf_host_add_cb(workstation_new);
-}
-
-void surf_workstation_model_init_compound()
-{
- xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
- xbt_assert(surf_network_model, "No network model defined yet!");
-
- surf_workstation_model_init_internal();
- xbt_dynar_push(model_list, &surf_workstation_model);
- xbt_dynar_push(model_list_invoke, &surf_workstation_model);
- sg_platf_host_add_cb(workstation_new);
-}
+++ /dev/null
-/* Copyright (c) 2009, 2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#ifndef WS_PRIVATE_H_
-#define WS_PRIVATE_H_
-typedef struct workstation_CLM03 {
- s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
- void *net_elm;
- xbt_dynar_t storage;
-
- /* common with vm */
- s_ws_params_t params;
-
-} s_workstation_CLM03_t, *workstation_CLM03_t;
-
-int ws_action_unref(surf_action_t action);
-
-int ws_resource_used(void *resource_id);
-double ws_share_resources(surf_model_t workstation_model, double now);
-void ws_update_actions_state(surf_model_t workstation_model, double now, double delta);
-void ws_update_resource_state(void *id, tmgr_trace_event_t event_type, double value, double date);
-void ws_finalize(surf_model_t workstation_model);
-
-void ws_action_set_priority(surf_action_t action, double priority);
-void ws_action_set_bound(surf_action_t action, double bound);
-void ws_action_set_affinity(surf_action_t action, void *workstation, unsigned long mask);
-
-surf_action_t ws_execute(void *workstation, double size);
-surf_action_t ws_action_sleep(void *workstation, double duration);
-void ws_action_suspend(surf_action_t action);
-void ws_action_resume(surf_action_t action);
-void ws_action_cancel(surf_action_t action);
-e_surf_resource_state_t ws_get_state(void *workstation);
-double ws_get_speed(void *workstation, double load);
-double ws_action_get_remains(surf_action_t action);
-
-void ws_get_params(void *ws, ws_params_t params);
-void ws_set_params(void *ws, ws_params_t params);
-#endif /* WS_PRIVATE_H_ */
+++ /dev/null
-/* Copyright (c) 2007-2013. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "xbt/ex.h"
-#include "xbt/str.h"
-#include "xbt/dict.h"
-#include "surf_private.h"
-#include "surf/surf_resource.h"
-//#include "surf/surf_resource_lmm.h"
-
-typedef enum {
- SURF_WORKSTATION_RESOURCE_CPU,
- SURF_WORKSTATION_RESOURCE_LINK
-} e_surf_workstation_model_type_t;
-
-/**************************************/
-/********* cpu object *****************/
-/**************************************/
-typedef struct cpu_L07 {
- s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
- e_surf_workstation_model_type_t type; /* Do not move this field: must match link_L07_t */
- lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
- double power_scale;
- double power_current;
- tmgr_trace_event_t power_event;
- tmgr_trace_event_t state_event;
- e_surf_resource_state_t state_current;
- sg_routing_edge_t info;
-} s_cpu_L07_t, *cpu_L07_t;
-
-/**************************************/
-/*********** network object ***********/
-/**************************************/
-
-typedef struct link_L07 {
- s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
- e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
- lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
- double lat_current;
- tmgr_trace_event_t lat_event;
- double bw_current;
- tmgr_trace_event_t bw_event;
- e_surf_resource_state_t state_current;
- tmgr_trace_event_t state_event;
-} s_link_L07_t, *link_L07_t;
-
-/**************************************/
-/*************** actions **************/
-/**************************************/
-typedef struct surf_action_workstation_L07 {
- s_surf_action_t generic_action;
- lmm_variable_t variable;
- int workstation_nb;
- cpu_L07_t *workstation_list;
- double *computation_amount;
- double *communication_amount;
- double latency;
- double rate;
- int suspended;
-} s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t;
-
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
-
-static int ptask_host_count = 0;
-static xbt_dict_t ptask_parallel_task_link_set = NULL;
-lmm_system_t ptask_maxmin_system = NULL;
-
-static surf_action_t die_impossible_communicate (sg_routing_edge_t src,
- sg_routing_edge_t dst,
- double size, double rate)
-{
- DIE_IMPOSSIBLE;
- return NULL;
-}
-
-static xbt_dynar_t die_impossible_get_route(void *src, void *dst)
-{
- DIE_IMPOSSIBLE;
- return NULL;
-}
-
-static void ptask_update_action_bound(surf_action_workstation_L07_t action)
-{
- int workstation_nb = action->workstation_nb;
- double lat_current = 0.0;
- double lat_bound = -1.0;
- int i, j;
-
- for (i = 0; i < workstation_nb; i++) {
- for (j = 0; j < workstation_nb; j++) {
- xbt_dynar_t route=NULL;
-
- if (action->communication_amount[i * workstation_nb + j] > 0) {
- double lat = 0.0;
- routing_get_route_and_latency(((cpu_L07_t)surf_workstation_resource_priv(action->workstation_list[i]))->info,
- ((cpu_L07_t)surf_workstation_resource_priv(action->workstation_list[j]))->info,
- &route, &lat);
- lat_current =
- MAX(lat_current,
- lat * action->communication_amount[i * workstation_nb + j]);
- }
- }
- }
- lat_bound = sg_tcp_gamma / (2.0 * lat_current);
- XBT_DEBUG("action (%p) : lat_bound = %g", action, lat_bound);
- if ((action->latency == 0.0) && (action->suspended == 0)) {
- if (action->rate < 0)
- lmm_update_variable_bound(ptask_maxmin_system, action->variable,
- lat_bound);
- else
- lmm_update_variable_bound(ptask_maxmin_system, action->variable,
- min(action->rate, lat_bound));
- }
-}
-
-/**************************************/
-/******* Resource Public **********/
-/**************************************/
-
-static int ptask_action_unref(surf_action_t action)
-{
- action->refcount--;
-
- if (!action->refcount) {
- xbt_swag_remove(action, action->state_set);
- if (((surf_action_workstation_L07_t) action)->variable)
- lmm_variable_free(ptask_maxmin_system,
- ((surf_action_workstation_L07_t)
- action)->variable);
- free(((surf_action_workstation_L07_t) action)->workstation_list);
- free(((surf_action_workstation_L07_t) action)->communication_amount);
- free(((surf_action_workstation_L07_t) action)->computation_amount);
-#ifdef HAVE_TRACING
- xbt_free(action->category);
-#endif
- surf_action_free(&action);
- return 1;
- }
- return 0;
-}
-
-static void ptask_action_cancel(surf_action_t action)
-{
- surf_action_state_set(action, SURF_ACTION_FAILED);
- return;
-}
-
-/* action_change_state is inherited from the surf module */
-/* action_set_data is inherited from the surf module */
-
-static void ptask_action_suspend(surf_action_t action)
-{
- XBT_IN("(%p))", action);
- if (((surf_action_workstation_L07_t) action)->suspended != 2) {
- ((surf_action_workstation_L07_t) action)->suspended = 1;
- lmm_update_variable_weight(ptask_maxmin_system,
- ((surf_action_workstation_L07_t)
- action)->variable, 0.0);
- }
- XBT_OUT();
-}
-
-static void ptask_action_resume(surf_action_t action)
-{
- surf_action_workstation_L07_t act =
- (surf_action_workstation_L07_t) action;
-
- XBT_IN("(%p)", act);
- if (act->suspended != 2) {
- lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0);
- act->suspended = 0;
- }
- XBT_OUT();
-}
-
-static int ptask_action_is_suspended(surf_action_t action)
-{
- return (((surf_action_workstation_L07_t) action)->suspended == 1);
-}
-
-static void ptask_action_set_max_duration(surf_action_t action,
- double duration)
-{ /* FIXME: should inherit */
- XBT_IN("(%p,%g)", action, duration);
- action->max_duration = duration;
- XBT_OUT();
-}
-
-
-static void ptask_action_set_priority(surf_action_t action,
- double priority)
-{ /* FIXME: should inherit */
- XBT_IN("(%p,%g)", action, priority);
- action->priority = priority;
- XBT_OUT();
-}
-
-static double ptask_action_get_remains(surf_action_t action)
-{
- XBT_IN("(%p)", action);
- XBT_OUT();
- return action->remains;
-}
-
-/**************************************/
-/******* Resource Private **********/
-/**************************************/
-
-static int ptask_resource_used(void *resource_id)
-{
- /* We can freely cast as a link_L07_t because it has
- the same prefix as cpu_L07_t */
- return lmm_constraint_used(ptask_maxmin_system,
- ((link_L07_t) resource_id)->constraint);
-
-}
-
-static double ptask_share_resources(surf_model_t workstation_model, double now)
-{
- s_surf_action_workstation_L07_t s_action;
- surf_action_workstation_L07_t action = NULL;
-
- xbt_swag_t running_actions =
- workstation_model->states.running_action_set;
- double min = generic_maxmin_share_resources(running_actions,
- xbt_swag_offset(s_action,
- variable),
- ptask_maxmin_system,
- bottleneck_solve);
-
- xbt_swag_foreach(action, running_actions) {
- if (action->latency > 0) {
- if (min < 0) {
- min = action->latency;
- XBT_DEBUG("Updating min (value) with %p (start %f): %f", action,
- action->generic_action.start, min);
- } else if (action->latency < min) {
- min = action->latency;
- XBT_DEBUG("Updating min (latency) with %p (start %f): %f", action,
- action->generic_action.start, min);
- }
- }
- }
-
- XBT_DEBUG("min value : %f", min);
-
- return min;
-}
-
-static void ptask_update_actions_state(surf_model_t workstation_model, double now, double delta)
-{
- double deltap = 0.0;
- surf_action_workstation_L07_t action = NULL;
- surf_action_workstation_L07_t next_action = NULL;
- xbt_swag_t running_actions =
- workstation_model->states.running_action_set;
-
- xbt_swag_foreach_safe(action, next_action, running_actions) {
- deltap = delta;
- if (action->latency > 0) {
- if (action->latency > deltap) {
- double_update(&(action->latency), deltap);
- deltap = 0.0;
- } else {
- double_update(&(deltap), action->latency);
- action->latency = 0.0;
- }
- if ((action->latency == 0.0) && (action->suspended == 0)) {
- ptask_update_action_bound(action);
- lmm_update_variable_weight(ptask_maxmin_system, action->variable,
- 1.0);
- }
- }
- XBT_DEBUG("Action (%p) : remains (%g) updated by %g.",
- action, action->generic_action.remains,
- lmm_variable_getvalue(action->variable) * delta);
- double_update(&(action->generic_action.remains),
- lmm_variable_getvalue(action->variable) * delta);
-
- if (action->generic_action.max_duration != NO_MAX_DURATION)
- double_update(&(action->generic_action.max_duration), delta);
-
- XBT_DEBUG("Action (%p) : remains (%g).",
- action, action->generic_action.remains);
- if ((action->generic_action.remains <= 0) &&
- (lmm_get_variable_weight(action->variable) > 0)) {
- action->generic_action.finish = surf_get_clock();
- surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
- } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
- (action->generic_action.max_duration <= 0)) {
- action->generic_action.finish = surf_get_clock();
- surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
- } else {
- /* Need to check that none of the model has failed */
- lmm_constraint_t cnst = NULL;
- int i = 0;
- void *constraint_id = NULL;
-
- while ((cnst =
- lmm_get_cnst_from_var(ptask_maxmin_system, action->variable,
- i++))) {
- constraint_id = lmm_constraint_id(cnst);
-
-/* if(((link_L07_t)constraint_id)->type== */
-/* SURF_WORKSTATION_RESOURCE_LINK) { */
-/* XBT_DEBUG("Checking for link %s (%p)", */
-/* ((link_L07_t)constraint_id)->name, */
-/* ((link_L07_t)constraint_id)); */
-/* } */
-/* if(((cpu_L07_t)constraint_id)->type== */
-/* SURF_WORKSTATION_RESOURCE_CPU) { */
-/* XBT_DEBUG("Checking for cpu %s (%p) : %s", */
-/* ((cpu_L07_t)constraint_id)->name, */
-/* ((cpu_L07_t)constraint_id), */
-/* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */
-/* } */
-
- if (((((link_L07_t) constraint_id)->type ==
- SURF_WORKSTATION_RESOURCE_LINK) &&
- (((link_L07_t) constraint_id)->state_current ==
- SURF_RESOURCE_OFF)) ||
- ((((cpu_L07_t) constraint_id)->type ==
- SURF_WORKSTATION_RESOURCE_CPU) &&
- (((cpu_L07_t) constraint_id)->state_current ==
- SURF_RESOURCE_OFF))) {
- XBT_DEBUG("Action (%p) Failed!!", action);
- action->generic_action.finish = surf_get_clock();
- surf_action_state_set((surf_action_t) action,
- SURF_ACTION_FAILED);
- break;
- }
- }
- }
- }
- return;
-}
-
-static void ptask_update_resource_state(void *id,
- tmgr_trace_event_t event_type,
- double value, double date)
-{
- cpu_L07_t cpu = id;
- link_L07_t nw_link = id;
-
- if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
- XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g",
- surf_resource_name(nw_link), nw_link, value, date);
- if (event_type == nw_link->bw_event) {
- nw_link->bw_current = value;
- lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
- nw_link->bw_current);
- if (tmgr_trace_event_free(event_type))
- nw_link->bw_event = NULL;
- } else if (event_type == nw_link->lat_event) {
- lmm_variable_t var = NULL;
- surf_action_workstation_L07_t action = NULL;
- lmm_element_t elem = NULL;
-
- nw_link->lat_current = value;
- while ((var = lmm_get_var_from_cnst
- (ptask_maxmin_system, nw_link->constraint, &elem))) {
-
-
- action = lmm_variable_id(var);
- ptask_update_action_bound(action);
- }
- if (tmgr_trace_event_free(event_type))
- nw_link->lat_event = NULL;
-
- } else if (event_type == nw_link->state_event) {
- if (value > 0)
- nw_link->state_current = SURF_RESOURCE_ON;
- else
- nw_link->state_current = SURF_RESOURCE_OFF;
- if (tmgr_trace_event_free(event_type))
- nw_link->state_event = NULL;
- } else {
- XBT_CRITICAL("Unknown event ! \n");
- xbt_abort();
- }
- return;
- } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
- XBT_DEBUG("Updating cpu %s (%p) with value %g", surf_resource_name(cpu),
- cpu, value);
- if (event_type == cpu->power_event) {
- cpu->power_current = value;
- lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
- cpu->power_current * cpu->power_scale);
- if (tmgr_trace_event_free(event_type))
- cpu->power_event = NULL;
- } else if (event_type == cpu->state_event) {
- if (value > 0)
- cpu->state_current = SURF_RESOURCE_ON;
- else
- cpu->state_current = SURF_RESOURCE_OFF;
- if (tmgr_trace_event_free(event_type))
- cpu->state_event = NULL;
- } else {
- XBT_CRITICAL("Unknown event ! \n");
- xbt_abort();
- }
- return;
- } else {
- DIE_IMPOSSIBLE;
- }
- return;
-}
-
-static void ptask_finalize(surf_model_t workstation_model)
-{
- xbt_dict_free(&ptask_parallel_task_link_set);
-
- surf_model_exit(workstation_model);
- workstation_model = NULL;
- surf_model_exit(surf_network_model);
- surf_network_model = NULL;
-
- ptask_host_count = 0;
-
- if (ptask_maxmin_system) {
- lmm_system_free(ptask_maxmin_system);
- ptask_maxmin_system = NULL;
- }
-}
-
-/**************************************/
-/******* Resource Private **********/
-/**************************************/
-
-static e_surf_resource_state_t ptask_resource_get_state(void *cpu)
-{
- return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->state_current;
-}
-
-static double ptask_get_speed(void *cpu, double load)
-{
- return load * ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_scale;
-}
-
-static double ptask_get_available_speed(void *cpu)
-{
- return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_current;
-}
-
-static double ws_get_current_power_peak(void *cpu)
-{
- return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_current;
-}
-
-static double ws_get_power_peak_at(void *cpu, int pstate_index)
-{
- XBT_DEBUG("[ws_get_power_peak_at] Not implemented for workstation_ptask_L07");
- return 0.0;
-}
-
-static int ws_get_nb_pstates(void *workstation)
-{
- XBT_DEBUG("[ws_get_nb_pstates] Not implemented for workstation_ptask_L07");
- return 0.0;
-}
-
-static void ws_set_power_peak_at(void *cpu, int pstate_index)
-{
- XBT_DEBUG("[ws_set_power_peak_at] Not implemented for workstation_ptask_L07");
-}
-
-static double ws_get_consumed_energy(void *cpu)
-{
- XBT_DEBUG("[ws_get_consumed_energy] Not implemented for workstation_ptask_L07");
- return 0.0;
-}
-
-static surf_action_t ptask_execute_parallel_task(int workstation_nb,
- void **workstation_list,
- double
- *computation_amount, double
- *communication_amount,
- double rate)
-{
- surf_action_workstation_L07_t action = NULL;
- int i, j;
- unsigned int cpt;
- int nb_link = 0;
- int nb_host = 0;
- double latency = 0.0;
-
- if (ptask_parallel_task_link_set == NULL)
- ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL);
-
- xbt_dict_reset(ptask_parallel_task_link_set);
-
- /* Compute the number of affected resources... */
- for (i = 0; i < workstation_nb; i++) {
- for (j = 0; j < workstation_nb; j++) {
- xbt_dynar_t route=NULL;
-
- if (communication_amount[i * workstation_nb + j] > 0) {
- double lat=0.0;
- unsigned int cpt;
- link_L07_t link;
-
- routing_get_route_and_latency(
- ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->info,
- ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[j]))->info,
- &route,&lat);
- latency = MAX(latency, lat);
-
- xbt_dynar_foreach(route, cpt, link) {
- xbt_dict_set(ptask_parallel_task_link_set,link->generic_resource.name,link,NULL);
- }
- }
- }
- }
-
- nb_link = xbt_dict_length(ptask_parallel_task_link_set);
- xbt_dict_reset(ptask_parallel_task_link_set);
-
- for (i = 0; i < workstation_nb; i++)
- if (computation_amount[i] > 0)
- nb_host++;
-
- action =
- surf_action_new(sizeof(s_surf_action_workstation_L07_t), 1,
- surf_workstation_model, 0);
- XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.",
- action, workstation_nb, nb_link);
- action->suspended = 0; /* Should be useless because of the
- calloc but it seems to help valgrind... */
- action->workstation_nb = workstation_nb;
- action->workstation_list = (cpu_L07_t *) workstation_list;
- action->computation_amount = computation_amount;
- action->communication_amount = communication_amount;
- action->latency = latency;
- action->rate = rate;
-
- action->variable =
- lmm_variable_new(ptask_maxmin_system, action, 1.0,
- (action->rate > 0) ? action->rate : -1.0,
- workstation_nb + nb_link);
-
- if (action->latency > 0)
- lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
-
- for (i = 0; i < workstation_nb; i++)
- lmm_expand(ptask_maxmin_system,
- ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->constraint,
- action->variable, computation_amount[i]);
-
- for (i = 0; i < workstation_nb; i++) {
- for (j = 0; j < workstation_nb; j++) {
- link_L07_t link;
- xbt_dynar_t route=NULL;
- if (communication_amount[i * workstation_nb + j] == 0.0)
- continue;
-
- routing_get_route_and_latency(
- ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->info,
- ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[j]))->info,
- &route,NULL);
-
- xbt_dynar_foreach(route, cpt, link) {
- lmm_expand_add(ptask_maxmin_system, link->constraint,
- action->variable,
- communication_amount[i * workstation_nb + j]);
- }
- }
- }
-
- if (nb_link + nb_host == 0) {
- action->generic_action.cost = 1.0;
- action->generic_action.remains = 0.0;
- }
-
- return (surf_action_t) action;
-}
-
-static surf_action_t ptask_execute(void *cpu, double size)
-{
- void **workstation_list = xbt_new0(void *, 1);
- double *computation_amount = xbt_new0(double, 1);
- double *communication_amount = xbt_new0(double, 1);
-
- workstation_list[0] = cpu;
- communication_amount[0] = 0.0;
- computation_amount[0] = size;
-
- return ptask_execute_parallel_task(1, workstation_list,
- computation_amount,
- communication_amount, -1);
-}
-
-static surf_action_t ptask_communicate(void *src, void *dst, double size,
- double rate)
-{
- void **workstation_list = xbt_new0(void *, 2);
- double *computation_amount = xbt_new0(double, 2);
- double *communication_amount = xbt_new0(double, 4);
- surf_action_t res = NULL;
-
- workstation_list[0] = src;
- workstation_list[1] = dst;
- communication_amount[1] = size;
-
- res = ptask_execute_parallel_task(2, workstation_list,
- computation_amount,
- communication_amount, rate);
-
- return res;
-}
-
-static surf_action_t ptask_action_sleep(void *cpu, double duration)
-{
- surf_action_workstation_L07_t action = NULL;
-
- XBT_IN("(%s,%g)", surf_resource_name(cpu), duration);
-
- action = (surf_action_workstation_L07_t) ptask_execute(cpu, 1.0);
- action->generic_action.max_duration = duration;
- action->suspended = 2;
- lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0);
-
- XBT_OUT();
- return (surf_action_t) action;
-}
-
-static xbt_dynar_t ptask_get_route(void *src, void *dst) // FIXME: kill that callback kind?
-{
- xbt_dynar_t route=NULL;
- routing_get_route_and_latency(
- ((cpu_L07_t)surf_workstation_resource_priv(src))->info, ((cpu_L07_t)surf_workstation_resource_priv(dst))->info,
- &route,NULL);
- return route;
-}
-
-static double ptask_get_link_bandwidth(const void *link)
-{
- return ((link_L07_t) link)->bw_current;
-}
-
-static double ptask_get_link_latency(const void *link)
-{
- return ((link_L07_t) link)->lat_current;
-}
-
-static int ptask_link_shared(const void *link)
-{
- return lmm_constraint_is_shared(((link_L07_t) link)->constraint);
-}
-
-/**************************************/
-/*** Resource Creation & Destruction **/
-/**************************************/
-
-static void* ptask_cpu_create_resource(const char *name, double power_scale,
- double power_initial,
- tmgr_trace_t power_trace,
- e_surf_resource_state_t state_initial,
- tmgr_trace_t state_trace,
- xbt_dict_t cpu_properties)
-{
- cpu_L07_t cpu = NULL;
- xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)),
- "Host '%s' declared several times in the platform file.",
- name);
-
- cpu = (cpu_L07_t) surf_resource_new(sizeof(s_cpu_L07_t),
- surf_workstation_model, name,cpu_properties, NULL);
-
- cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
- cpu->info = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
- if(!(cpu->info)) xbt_die("Don't find ROUTING_HOST_LEVEL for '%s'",name);
-
- cpu->power_scale = power_scale;
- xbt_assert(cpu->power_scale > 0, "Power has to be >0");
-
- cpu->power_current = power_initial;
- if (power_trace)
- cpu->power_event =
- tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
-
- cpu->state_current = state_initial;
- if (state_trace)
- cpu->state_event =
- tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
-
- cpu->constraint =
- lmm_constraint_new(ptask_maxmin_system, cpu,
- cpu->power_current * cpu->power_scale);
-
- xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, cpu);
-
- return xbt_lib_get_elm_or_null(host_lib, name);
-}
-
-static void ptask_parse_cpu_init(sg_platf_host_cbarg_t host)
-{
- double power_peak = xbt_dynar_get_as(host->power_peak, host->pstate, double);
- //cpu->power_peak = power_peak;
- xbt_dynar_free(&(host->power_peak)); /* kill memory leak */
- ptask_cpu_create_resource(
- host->id,
- power_peak,
- host->power_scale,
- host->power_trace,
- host->initial_state,
- host->state_trace,
- host->properties);
-}
-
-static void* ptask_link_create_resource(const char *name,
- double bw_initial,
- tmgr_trace_t bw_trace,
- double lat_initial,
- tmgr_trace_t lat_trace,
- e_surf_resource_state_t
- state_initial,
- tmgr_trace_t state_trace,
- e_surf_link_sharing_policy_t
- policy, xbt_dict_t properties)
-{
- link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
- xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
- "Link '%s' declared several times in the platform file.",
- name);
-
- nw_link->generic_resource.model = surf_workstation_model;
- nw_link->generic_resource.properties = properties;
- nw_link->generic_resource.name = xbt_strdup(name);
- nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
- nw_link->bw_current = bw_initial;
- if (bw_trace)
- nw_link->bw_event =
- tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link);
- nw_link->state_current = state_initial;
- nw_link->lat_current = lat_initial;
- if (lat_trace)
- nw_link->lat_event =
- tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
- if (state_trace)
- nw_link->state_event =
- tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link);
-
- nw_link->constraint =
- lmm_constraint_new(ptask_maxmin_system, nw_link,
- nw_link->bw_current);
-
- if (policy == SURF_LINK_FATPIPE)
- lmm_constraint_shared(nw_link->constraint);
-
- xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
- return nw_link;
-}
-
-static void ptask_parse_link_init(sg_platf_link_cbarg_t link)
-{
- if (link->policy == SURF_LINK_FULLDUPLEX) {
- char *link_id;
- link_id = bprintf("%s_UP", link->id);
- ptask_link_create_resource(link_id,
- link->bandwidth,
- link->bandwidth_trace,
- link->latency,
- link->latency_trace,
- link->state,
- link->state_trace,
- link->policy,
- link->properties);
- xbt_free(link_id);
- link_id = bprintf("%s_DOWN", link->id);
- ptask_link_create_resource(link_id,
- link->bandwidth,
- link->bandwidth_trace,
- link->latency,
- link->latency_trace,
- link->state,
- link->state_trace,
- link->policy,
- NULL); /* FIXME: We need to deep copy the
- * properties or we won't be able to free
- * it */
- xbt_free(link_id);
- } else {
- ptask_link_create_resource(link->id,
- link->bandwidth,
- link->bandwidth_trace,
- link->latency,
- link->latency_trace,
- link->state,
- link->state_trace,
- link->policy,
- link->properties);
- }
-
- current_property_set = NULL;
-}
-
-static void ptask_add_traces(void)
-{
- xbt_dict_cursor_t cursor = NULL;
- char *trace_name, *elm;
-
- if (!trace_connect_list_host_avail)
- return;
-
- /* Connect traces relative to cpu */
- xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
- tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_L07_t host = surf_workstation_resource_priv(surf_workstation_resource_by_name(elm));
-
- xbt_assert(host, "Host %s undefined", elm);
- xbt_assert(trace, "Trace %s undefined", trace_name);
-
- host->state_event =
- tmgr_history_add_trace(history, trace, 0.0, 0, host);
- }
-
- xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
- tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_L07_t host = surf_workstation_resource_priv(surf_workstation_resource_by_name(elm));
-
- xbt_assert(host, "Host %s undefined", elm);
- xbt_assert(trace, "Trace %s undefined", trace_name);
-
- host->power_event =
- tmgr_history_add_trace(history, trace, 0.0, 0, host);
- }
-
- /* Connect traces relative to network */
- xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
- tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- link_L07_t link =
- xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
-
- xbt_assert(link, "Link %s undefined", elm);
- xbt_assert(trace, "Trace %s undefined", trace_name);
-
- link->state_event =
- tmgr_history_add_trace(history, trace, 0.0, 0, link);
- }
-
- xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
- tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- link_L07_t link =
- xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
-
- xbt_assert(link, "Link %s undefined", elm);
- xbt_assert(trace, "Trace %s undefined", trace_name);
-
- link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
- }
-
- xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
- tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- link_L07_t link =
- xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
-
- xbt_assert(link, "Link %s undefined", elm);
- xbt_assert(trace, "Trace %s undefined", trace_name);
-
- link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
- }
-}
-
-static void ptask_define_callbacks()
-{
- sg_platf_host_add_cb(ptask_parse_cpu_init);
- sg_platf_link_add_cb(ptask_parse_link_init);
- sg_platf_postparse_add_cb(ptask_add_traces);
-}
-
-/**************************************/
-/********* Module creation ***********/
-/**************************************/
-
-static void ptask_model_init_internal(void)
-{
- surf_workstation_model = surf_model_init();
-
- surf_workstation_model->action_unref = ptask_action_unref;
- surf_workstation_model->action_cancel = ptask_action_cancel;
- surf_workstation_model->action_state_set = surf_action_state_set;
- surf_workstation_model->suspend = ptask_action_suspend;
- surf_workstation_model->resume = ptask_action_resume;
- surf_workstation_model->is_suspended = ptask_action_is_suspended;
- surf_workstation_model->set_max_duration = ptask_action_set_max_duration;
- surf_workstation_model->set_priority = ptask_action_set_priority;
- surf_workstation_model->get_remains = ptask_action_get_remains;
- surf_workstation_model->name = "Workstation ptask_L07";
- surf_workstation_model->type = SURF_MODEL_TYPE_WORKSTATION;
-
- surf_workstation_model->model_private->resource_used =
- ptask_resource_used;
- surf_workstation_model->model_private->share_resources =
- ptask_share_resources;
- surf_workstation_model->model_private->update_actions_state =
- ptask_update_actions_state;
- surf_workstation_model->model_private->update_resource_state =
- ptask_update_resource_state;
- surf_workstation_model->model_private->finalize = ptask_finalize;
-
-
- surf_workstation_model->extension.workstation.execute = ptask_execute;
- surf_workstation_model->extension.workstation.sleep = ptask_action_sleep;
- surf_workstation_model->extension.workstation.get_state =
- ptask_resource_get_state;
- surf_workstation_model->extension.workstation.get_speed =
- ptask_get_speed;
- surf_workstation_model->extension.workstation.get_available_speed =
- ptask_get_available_speed;
- surf_workstation_model->extension.workstation.get_current_power_peak = ws_get_current_power_peak;
- surf_workstation_model->extension.workstation.get_power_peak_at = ws_get_power_peak_at;
- surf_workstation_model->extension.workstation.get_nb_pstates = ws_get_nb_pstates;
- surf_workstation_model->extension.workstation.set_power_peak_at = ws_set_power_peak_at;
- surf_workstation_model->extension.workstation.get_consumed_energy = ws_get_consumed_energy;
-
- surf_workstation_model->extension.workstation.communicate =
- ptask_communicate;
- surf_workstation_model->extension.workstation.get_route =
- ptask_get_route;
- surf_workstation_model->extension.workstation.execute_parallel_task =
- ptask_execute_parallel_task;
- surf_workstation_model->extension.workstation.get_link_bandwidth =
- ptask_get_link_bandwidth;
- surf_workstation_model->extension.workstation.get_link_latency =
- ptask_get_link_latency;
- surf_workstation_model->extension.workstation.link_shared =
- ptask_link_shared;
- surf_workstation_model->extension.workstation.get_properties =
- surf_resource_properties;
- surf_workstation_model->extension.workstation.add_traces =
- ptask_add_traces;
-
- if (!ptask_maxmin_system)
- ptask_maxmin_system = lmm_system_new(1);
-
- routing_model_create(ptask_link_create_resource("__loopback__",
- 498000000, NULL,
- 0.000015, NULL,
- SURF_RESOURCE_ON, NULL,
- SURF_LINK_FATPIPE, NULL));
-
- surf_network_model = surf_model_init();
-
- surf_network_model->extension.network.communicate = die_impossible_communicate;
- surf_network_model->extension.network.get_route = die_impossible_get_route;
- surf_network_model->extension.network.get_link_bandwidth = ptask_get_link_bandwidth;
- surf_network_model->extension.network.get_link_latency = ptask_get_link_latency;
- surf_network_model->extension.network.link_shared = ptask_link_shared;
- surf_network_model->extension.network.add_traces = NULL;
-}
-
-/**************************************/
-/*************** Generic **************/
-/**************************************/
-void surf_workstation_model_init_ptask_L07(void)
-{
- XBT_INFO("surf_workstation_model_init_ptask_L07");
- xbt_assert(!surf_cpu_model_pm, "CPU model type already defined");
- xbt_assert(!surf_network_model, "network model type already defined");
- ptask_define_callbacks();
- ptask_model_init_internal();
- xbt_dynar_push(model_list, &surf_workstation_model);
-}