Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add first steps to explain How to add a new model in Simgrid
authornavarro <navarro@caraja.(none)>
Fri, 12 Oct 2012 09:48:51 +0000 (11:48 +0200)
committernavarro <navarro@caraja.(none)>
Fri, 12 Oct 2012 09:49:12 +0000 (11:49 +0200)
buildtools/Cmake/DefinePackages.cmake
src/include/surf/surf.h
src/simix/smx_io.c
src/simix/smx_new_api.c
src/surf/new_model.c [new file with mode: 0644]
src/surf/new_model_private.h [new file with mode: 0644]

index da66cbd..9c8456d 100644 (file)
@@ -273,7 +273,7 @@ set(MSG_SRC
   )
 
 #* ****************************************************************************************** *#
-#* TUTORIAL: New API                                                                        *#
+#* TUTORIAL: New API                                                                          *#
 
 set(MSG_SRC
   ${MSG_SRC}
@@ -289,6 +289,19 @@ set(SIMIX_SRC
 )
 #* ****************************************************************************************** *#
 
+#* ****************************************************************************************** *#
+#* TUTORIAL: New Model                                                                        *#
+
+set(SURF_SRC
+  ${SURF_SRC}
+  src/surf/new_model.c
+  )
+set(EXTRA_DIST
+  ${EXTRA_DIST}
+  src/surf/new_model_private.c
+  )
+#* ****************************************************************************************** *#
+
 set(PLATFGEN_SRC
   include/simgrid/platf_generator.h
   src/surf/platf_generator.c
index 475f9da..d072e4b 100644 (file)
@@ -153,6 +153,17 @@ typedef struct surf_action_state {
 typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t;
 XBT_PUBLIC_DATA(routing_platf_t) routing_platf;
 
+/**
+ *  TUTORIAL: New model
+ *  New model extension public
+ *  Public functions specific to a New model.
+ */
+
+typedef struct surf_new_model_extension_public {
+  surf_action_t(*fct) ();
+  void* (*create_resource) ();
+} s_surf_model_extension_new_model_t;
+
 
 /** \ingroup SURF_models
  *  \brief Private data available on all models
@@ -331,6 +342,7 @@ typedef struct surf_model {
     s_surf_model_extension_network_t network;
     s_surf_model_extension_storage_t storage;
     s_surf_model_extension_workstation_t workstation;
+    s_surf_model_extension_new_model_t new_model;
   } extension;
 } s_surf_model_t;
 
index 23aa928..0a11720 100644 (file)
@@ -46,7 +46,7 @@ smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size, size
 #endif
 
   action->io.host = host;
-  action->io.surf_io = surf_workstation_model->extension.workstation.read(host->host, ptr, size, nmemb, stream->surf_file),
+  action->io.surf_io = surf_workstation_model->extension.workstation.read(host->host, ptr, size, nmemb, stream->surf_file);
 
   surf_workstation_model->action_data_set(action->io.surf_io, action);
   XBT_DEBUG("Create io action %p", action);
index e2c2890..7c5498d 100644 (file)
@@ -80,7 +80,8 @@ smx_action_t SIMIX_new_api_fct(smx_process_t process, const char* param1, double
   action->category = NULL;
 #endif
 
-  action->new_api.surf_new_api = NULL;
+  // Called the function from the new model
+  action->new_api.surf_new_api = surf_workstation_model->extension.new_model.fct();
 
   surf_workstation_model->action_data_set(action->new_api.surf_new_api, action);
   XBT_DEBUG("Create NEW MODEL action %p", action);
diff --git a/src/surf/new_model.c b/src/surf/new_model.c
new file mode 100644 (file)
index 0000000..76a6086
--- /dev/null
@@ -0,0 +1,176 @@
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. 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 "xbt/file_stat.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 ();
+
+static surf_action_t new_model_action_fct()
+{
+  surf_action_t action = new_model_action_execute();
+  return action;
+}
+
+static surf_action_t new_model_action_execute ()
+{
+  THROW_UNIMPLEMENTED;
+  return NULL;
+}
+
+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(void)
+{
+  THROW_UNIMPLEMENTED;
+}
+
+static void new_model_update_actions_state(double now, double delta)
+{
+  THROW_UNIMPLEMENTED;
+}
+
+static double new_model_share_resources(double NOW)
+{
+  THROW_UNIMPLEMENTED;
+  return 0;
+}
+
+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_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 = "Storage";
+  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_model_init_default(void)
+{
+  surf_new_model_model_init_internal();
+  new_model_define_callbacks();
+
+  xbt_dynar_push(model_list, &surf_new_model);
+}
diff --git a/src/surf/new_model_private.h b/src/surf/new_model_private.h
new file mode 100644 (file)
index 0000000..3cdbeeb
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * TUTORIAL: New model
+ * new_model_private.h
+ *
+ *  Created on: 12 October 2012
+ *      Author: navarro
+ */
+
+#ifndef NEW_MODEL_PRIVATE_H_
+#define NEW_MODEL_PRIVATE_H_
+
+
+
+#endif /* NEW_MODEL_PRIVATE_H_ */