src/msg/msg_vm.c
)
+#* ****************************************************************************************** *#
+#* TUTORIAL: New API *#
+
+set(MSG_SRC
+ ${MSG_SRC}
+ src/msg/msg_new_api.c
+ )
+set(EXTRA_DIST
+ ${EXTRA_DIST}
+ src/simix/smx_new_api_private.h
+ )
+set(SIMIX_SRC
+ ${SIMIX_SRC}
+ src/simix/smx_new_api.c
+)
+#* ****************************************************************************************** *#
+
set(PLATFGEN_SRC
include/simgrid/platf_generator.h
src/surf/platf_generator.c
/* Used only by the bindings -- unclean pimple, please ignore if you're not writing a binding */
XBT_PUBLIC(smx_context_t) MSG_process_get_smx_ctx(msg_process_t process);
+/* ****************************************************************************************** */
+/* TUTORIAL: New API */
+/* Declare all functions for the API */
+/* ****************************************************************************************** */
+XBT_PUBLIC(int) MSG_new_API_fct(const char* param1, double param2);
+
SG_END_DECL()
#endif
--- /dev/null
+/* 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. */
+
+#include "msg_private.h"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_new_API, msg,
+ "Logging specific to MSG (new_API)");
+
+
+/* ****************************************************************************************** */
+/* TUTORIAL: New API */
+/* All functions for the API */
+/* ****************************************************************************************** */
+int MSG_new_API_fct(const char* param1, double param2)
+{
+ int result = simcall_new_api_fct(param1, param2);
+ return result;
+}
--- /dev/null
+/* Copyright (c) 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. */
+
+/* ****************************************************************************************** */
+/* TUTORIAL: New API */
+/* ****************************************************************************************** */
+#include "smx_private.h"
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+#include "xbt/dict.h"
+#include "mc/mc.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_new_api, simix,
+ "Logging specific to SIMIX (new_api)");
+
+
+//SIMIX NEW MODEL INIT
+void SIMIX_pre_new_api_fct(smx_simcall_t simcall)
+{
+ smx_action_t action = SIMIX_new_api_fct(simcall->issuer,
+ simcall->new_api.param1,
+ simcall->new_api.param2);
+ xbt_fifo_push(action->simcalls, simcall);
+ simcall->issuer->waiting_action = action;
+}
+
+void SIMIX_post_new_api(smx_action_t action)
+{
+ xbt_fifo_item_t i;
+ smx_simcall_t simcall;
+
+ xbt_fifo_foreach(action->simcalls,i,simcall,smx_simcall_t) {
+ switch (simcall->call) {
+ case SIMCALL_NEW_API_INIT:
+ simcall->new_api.result = 0;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ switch (surf_workstation_model->action_state_get(action->new_api.surf_new_api)) {
+
+ case SURF_ACTION_FAILED:
+ action->state = SIMIX_FAILED;
+ break;
+
+ case SURF_ACTION_DONE:
+ action->state = SIMIX_DONE;
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ break;
+ }
+
+ SIMIX_new_api_finish(action);
+}
+
+smx_action_t SIMIX_new_api_fct(smx_process_t process, const char* param1, double param2)
+{
+ smx_action_t action;
+ smx_host_t host = process->smx_host;
+
+ /* check if the host is active */
+ if (surf_workstation_model->extension.
+ workstation.get_state(host->host) != SURF_RESOURCE_ON) {
+ THROWF(host_error, 0, "Host %s failed, you cannot call this function",
+ host->name);
+ }
+
+ action = xbt_mallocator_get(simix_global->action_mallocator);
+ action->type = SIMIX_ACTION_NEW_API;
+ action->name = NULL;
+#ifdef HAVE_TRACING
+ action->category = NULL;
+#endif
+
+ action->new_api.surf_new_api = NULL;
+
+ surf_workstation_model->action_data_set(action->new_api.surf_new_api, action);
+ XBT_DEBUG("Create NEW MODEL action %p", action);
+
+ return action;
+}
+
+void SIMIX_new_api_destroy(smx_action_t action)
+{
+ XBT_DEBUG("Destroy action %p", action);
+ if (action->new_api.surf_new_api)
+ action->new_api.surf_new_api->model_type->action_unref(action->new_api.surf_new_api);
+ xbt_mallocator_release(simix_global->action_mallocator, action);
+}
+
+void SIMIX_new_api_finish(smx_action_t action)
+{
+ xbt_fifo_item_t item;
+ smx_simcall_t simcall;
+
+ xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
+
+ switch (action->state) {
+
+ case SIMIX_DONE:
+ /* do nothing, action done */
+ break;
+
+ case SIMIX_FAILED:
+ SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
+ break;
+
+ case SIMIX_CANCELED:
+ SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
+ break;
+
+ default:
+ xbt_die("Internal error in SIMIX_NEW_MODEL_finish: unexpected action state %d",
+ (int)action->state);
+ }
+
+ if (surf_workstation_model->extension.
+ workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) {
+ simcall->issuer->context->iwannadie = 1;
+ }
+
+ simcall->issuer->waiting_action = NULL;
+ SIMIX_simcall_answer(simcall);
+ }
+
+ /* We no longer need it */
+ SIMIX_new_api_destroy(action);
+}
--- /dev/null
+/* Copyright (c) 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. */
+
+/* ****************************************************************************************** */
+/* TUTORIAL: New API */
+/* ****************************************************************************************** */
+#ifndef _SIMIX_NEW_API_PRIVATE_H
+#define _SIMIX_NEW_API_PRIVATE_H
+
+#include "simgrid/simix.h"
+#include "smx_smurf_private.h"
+
+void SIMIX_pre_new_api_fct(smx_simcall_t simcall);
+smx_action_t SIMIX_new_api_fct(smx_process_t process, const char* param1, double param2);
+
+void SIMIX_post_new_api(smx_action_t action);
+void SIMIX_new_api_destroy(smx_action_t action);
+void SIMIX_new_api_finish(smx_action_t action);
+
+#endif
#include "smx_network_private.h"
#include "smx_smurf_private.h"
#include "smx_synchro_private.h"
+/* ****************************************************************************************** */
+/* TUTORIAL: New API */
+/* ****************************************************************************************** */
+#include "smx_new_api_private.h"
/* Define only for SimGrid benchmarking purposes */
//#define TIME_BENCH_PER_SR /* this aims at measuring the time spent in each scheduling round per each thread. The code is thus run in sequential to bench separately each SSR */
SIMIX_ACTION_COMMUNICATE,
SIMIX_ACTION_SLEEP,
SIMIX_ACTION_SYNCHRO,
- SIMIX_ACTION_IO
+ SIMIX_ACTION_IO,
+ /* ****************************************************************************************** */
+ /* TUTORIAL: New API */
+ /* ****************************************************************************************** */
+ SIMIX_ACTION_NEW_API
} e_smx_action_type_t;
typedef enum {
smx_host_t host;
surf_action_t surf_io;
} io;
+
+ /* ****************************************************************************************** */
+ /* TUTORIAL: New API */
+ /* ****************************************************************************************** */
+ struct {
+ surf_action_t surf_new_api;
+ } new_api;
};
#ifdef HAVE_LATENCY_BOUND_TRACKING
SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
);
break;
+
+ /* ****************************************************************************************** */
+ /* TUTORIAL: New API */
+ /* ****************************************************************************************** */
+ case SIMCALL_NEW_API_INIT:
+ SIMIX_pre_new_api_fct(simcall);
+ break;
}
}
case SIMIX_ACTION_IO:
SIMIX_post_io(action);
break;
+
+ /* ****************************************************************************************** */
+ /* TUTORIAL: New API */
+ /* ****************************************************************************************** */
+ case SIMIX_ACTION_NEW_API:
+ SIMIX_post_new_model(action);
+ break;
}
}
SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_STAT), \
SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_UNLINK),\
SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_LS),\
-SIMCALL_ENUM_ELEMENT(SIMCALL_ASR_GET_PROPERTIES)
+SIMCALL_ENUM_ELEMENT(SIMCALL_ASR_GET_PROPERTIES), \
+/* ****************************************************************************************** */ \
+/* TUTORIAL: New API */ \
+/* ****************************************************************************************** */ \
+SIMCALL_ENUM_ELEMENT(SIMCALL_NEW_API_INIT)
/* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
xbt_dict_t result;
} asr_get_properties;
+ /* ****************************************************************************************** */
+ /* TUTORIAL: New API */
+ /* ****************************************************************************************** */
+ struct {
+ const char* param1;
+ double param2;
+ int result;
+ } new_api;
+
};
} s_smx_simcall_t, *smx_simcall_t;
return simcall->file_ls.result;
}
+/* ****************************************************************************************** */
+/* TUTORIAL: New API */
+/* All functions for simcall */
+/* ****************************************************************************************** */
+int simcall_new_api_fct(const char* param1, double param2){
+ smx_simcall_t simcall = SIMIX_simcall_mine();
+ simcall->call = SIMCALL_NEW_API_INIT;
+ simcall->new_api.param1 = param1;
+ simcall->new_api.param2 = param2;
+
+ SIMIX_simcall_push(simcall->issuer);
+ return simcall->new_api.result;
+}
+
/* ************************************************************************** */
/** @brief returns a printable string representing a simcall */