/*
 * Instrumentation functions to trace MSG processes (msg_process_t)
 */
void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host, msg_host_t new_host)
{
  if (TRACE_msg_process_is_enabled()){
    static long long int counter = 0;

    char key[INSTR_DEFAULT_STR_SIZE];
    snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);

    int len = INSTR_DEFAULT_STR_SIZE;
    char str[INSTR_DEFAULT_STR_SIZE];

    //start link
    container_t msg = PJ_container_get (instr_process_id(process, str, len));
    type_t type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
    new_pajeStartLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);

    //destroy existing container of this process
    TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process));

    //create new container on the new_host location
    TRACE_msg_process_create (MSG_process_get_name (process), MSG_process_get_PID (process), new_host);

    //end link
    msg = PJ_container_get(instr_process_id(process, str, len));
    type = PJ_type_get ("MSG_PROCESS_LINK", PJ_type_get_root());
    new_pajeEndLink (MSG_get_clock(), PJ_container_get_root(), type, msg, "M", key);
  }
}
Beispiel #2
0
static int master(int argc, char *argv[])
{
    xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
    msg_process_t process = NULL;
    MSG_process_sleep(1);
    xbt_swag_foreach(process, process_list) {
        XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process),
                 MSG_process_get_name(process));
        if (MSG_process_self_PID() != MSG_process_get_PID(process))
            MSG_process_kill(process);
    }
Beispiel #3
0
static int client(int argc, char *argv[])
{
  int my_pid = MSG_process_get_PID(MSG_process_self());
  char *my_mailbox = xbt_strdup(argv[1]);

  while(1){
    XBT_INFO("Client (%s) asks the request", my_mailbox);
    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");

    msg_task_t answer = NULL;
    MSG_task_receive(&answer, my_mailbox);

    const char* kind = MSG_task_get_name(answer);

    if (!strcmp(kind, "grant")) {
      XBT_INFO("Client (%s) got the answer (grant). Sleep a bit and release it", my_mailbox);
      if(!strcmp(my_mailbox, "1"))
        cs = 1;
    }else{
      XBT_INFO("Client (%s) got the answer (not grant). Try again", my_mailbox);
    }

    MSG_task_destroy(answer);
    kind = NULL;

    MSG_process_sleep(my_pid);
  }
  return 0;
}
Beispiel #4
0
static void send_mrsg_data (msg_task_t msg)
{
    char         mailbox[MAILBOX_ALIAS_SIZE];
    double       data_size;
    size_t       my_id;
    mrsg_task_info_t  ti;

    my_id = get_mrsg_worker_id (MSG_host_self ());

    sprintf (mailbox, TASK_MRSG_MAILBOX,
	    get_mrsg_worker_id (MSG_task_get_source (msg)),
	    MSG_process_get_PID (MSG_task_get_sender (msg)));

    if (mrsg_message_is (msg, SMS_GET_MRSG_CHUNK))
    {
	MSG_task_dsend (MSG_task_create ("DATA-C", 0.0, config_mrsg.mrsg_chunk_size, NULL), mailbox, NULL);
    }
    else if (mrsg_message_is (msg, SMS_GET_INTER_MRSG_PAIRS))
    {
	ti = (mrsg_task_info_t) MSG_task_get_data (msg);
	data_size = job_mrsg.map_output[my_id][ti->mrsg_tid] - ti->map_output_copied[my_id];
	MSG_task_dsend (MSG_task_create ("DATA-IP", 0.0, data_size, NULL), mailbox, NULL);
    }

    MSG_task_destroy (msg);
}
Beispiel #5
0
void TRACE_msg_process_kill(msg_process_t process)
{
  if (TRACE_msg_process_is_enabled()){
    //kill means that this process no longer exists, let's destroy it
    TRACE_msg_process_destroy (MSG_process_get_name (process), MSG_process_get_PID (process), MSG_process_get_host (process));
  }
}
Beispiel #6
0
static int client(int argc, char *argv[])
{
  int my_pid = MSG_process_get_PID(MSG_process_self());

  char *my_mailbox = xbt_strdup(argv[1]);
  msg_task_t grant = NULL, release = NULL;

  while(1){
    XBT_INFO("Ask the request");
    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");

    if(strcmp(my_mailbox, "1") == 0){
      r = 1;
      cs = 0;
      XBT_INFO("Propositions changed : r=1, cs=0");
    }

    MSG_task_receive(&grant, my_mailbox);
    const char *kind = MSG_task_get_name(grant);

    if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
      cs = 1;
      r = 0;
      XBT_INFO("Propositions changed : r=0, cs=1");
    }

    MSG_task_destroy(grant);
    grant = NULL;
    kind = NULL;

    XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);

    MSG_process_sleep(1);

    release = MSG_task_create("release", 0, 1000, NULL);
    MSG_task_send(release, "coordinator");

    release = NULL;

    MSG_process_sleep(my_pid);

    if(strcmp(my_mailbox, "1") == 0){
      cs=0;
      r=0;
      XBT_INFO("Propositions changed : r=0, cs=0");
    }
    
  }
  return 0;
}
Beispiel #7
0
/** \ingroup m_process_management
 * \brief Creates and runs a new #m_process_t.

 * A constructor for #m_process_t taking four arguments and returning the
 * corresponding object. The structure (and the corresponding thread) is
 * created, and put in the list of ready process.
 * \param name a name for the object. It is for user-level information
   and can be NULL.
 * \param code is a function describing the behavior of the agent. It
   should then only use functions described in \ref
   m_process_management (to create a new #m_process_t for example),
   in \ref m_host_management (only the read-only functions i.e. whose
   name contains the word get), in \ref m_task_management (to create
   or destroy some #m_task_t for example) and in \ref
   msg_gos_functions (to handle file transfers and task processing).
 * \param data a pointer to any data one may want to attach to the new
   object.  It is for user-level information and can be NULL. It can
   be retrieved with the function \ref MSG_process_get_data.
 * \param host the location where the new agent is executed.
 * \param argc first argument passed to \a code
 * \param argv second argument passed to \a code
 * \param properties list a properties defined for this process
 * \see m_process_t
 * \return The new corresponding object.
 */
m_process_t MSG_process_create_with_environment(const char *name,
                                                xbt_main_func_t code,
                                                void *data, m_host_t host,
                                                int argc, char **argv,
                                                xbt_dict_t properties)
{
  xbt_assert(code != NULL && host != NULL, "Invalid parameters");
  simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
  m_process_t process;

  /* Simulator data for MSG */
  simdata->PID = msg_global->PID++;
  simdata->waiting_action = NULL;
  simdata->waiting_task = NULL;
  simdata->m_host = host;
  simdata->argc = argc;
  simdata->argv = argv;
  simdata->data = data;
  simdata->last_errno = MSG_OK;

  if (SIMIX_process_self()) {
    simdata->PPID = MSG_process_get_PID(MSG_process_self());
  } else {
    simdata->PPID = -1;
  }

  /* Let's create the process: SIMIX may decide to start it right now,
   * even before returning the flow control to us */
  SIMIX_req_process_create(&process, name, code, simdata, host->name,
                           argc, argv, properties);

#ifdef HAVE_TRACING
  TRACE_msg_process_create(process);
#endif

  if (!process) {
    /* Undo everything we have just changed */
    msg_global->PID--;
    xbt_free(simdata);
    return NULL;
  }

  return process;
}
Beispiel #8
0
/** Create a Java org.simgrid.msg.Process with the arguments and run it */
static int java_main(int argc, char *argv[])
{
  JNIEnv *env = get_current_thread_env();
  simgrid::java::JavaContext* context = (simgrid::java::JavaContext*) SIMIX_context_self();

  //Change the "." in class name for "/".
  xbt_str_subst(argv[0],'.','/',0);
  jclass class_Process = env->FindClass(argv[0]);
  xbt_str_subst(argv[0],'/','.',0);
  //Retrieve the methodID for the constructor
  xbt_assert((class_Process != nullptr), "Class not found (%s). The deployment file must use the fully qualified class name, including the package. The case is important.", argv[0]);
  jmethodID constructor_Process = env->GetMethodID(class_Process, "<init>", "(Lorg/simgrid/msg/Host;Ljava/lang/String;[Ljava/lang/String;)V");
  xbt_assert((constructor_Process != nullptr), "Constructor not found for class %s. Is there a (Host, String ,String[]) constructor in your class ?", argv[0]);

  //Retrieve the name of the process.
  jstring jname = env->NewStringUTF(argv[0]);
  //Build the arguments
  jobjectArray args = (jobjectArray)env->NewObjectArray(argc - 1,
    env->FindClass("java/lang/String"),
    env->NewStringUTF(""));
  int i;
  for (i = 1; i < argc; i++)
      env->SetObjectArrayElement(args,i - 1, env->NewStringUTF(argv[i]));
  //Retrieve the host for the process.
  jstring jhostName = env->NewStringUTF(MSG_host_get_name(MSG_host_self()));
  jobject jhost = Java_org_simgrid_msg_Host_getByName(env, nullptr, jhostName);
  //creates the process
  jobject jprocess = env->NewObject(class_Process, constructor_Process, jhost, jname, args);
  xbt_assert((jprocess != nullptr), "Process allocation failed.");
  jprocess = env->NewGlobalRef(jprocess);
  //bind the process to the context
  msg_process_t process = MSG_process_self();

  context->jprocess = jprocess;
  /* sets the PID and the PPID of the process */
  env->SetIntField(jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
  env->SetIntField(jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
  jprocess_bind(jprocess, process, env);

  run_jprocess(env, context->jprocess);
  return 0;
}
Beispiel #9
0
int client(int argc, char *argv[])
{
  int my_pid = MSG_process_get_PID(MSG_process_self());
  // use my pid as name of mailbox to contact me
  char *my_mailbox = bprintf("%d", my_pid);
  // request the CS 3 times, sleeping a bit in between
  int i;
  for (i = 0; i < CS_PER_PROCESS; i++) {
    XBT_INFO("Ask the request");
    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox),
                  "coordinator");
    // wait the answer
    msg_task_t grant = NULL;
    MSG_task_receive(&grant, my_mailbox);
    MSG_task_destroy(grant);
    XBT_INFO("got the answer. Sleep a bit and release it");
    MSG_process_sleep(1);
    MSG_task_send(MSG_task_create("release", 0, 1000, NULL),
                  "coordinator");
    MSG_process_sleep(my_pid);
  }
  XBT_INFO("Got all the CS I wanted, quit now");
  return 0;
}
Beispiel #10
0
/** \ingroup m_process_management
 * \brief Return the PID of the current process.
 *
 * This function returns the PID of the currently running #msg_process_t.
 */
int MSG_process_self_PID()
{
  return MSG_process_get_PID(MSG_process_self());
}
Beispiel #11
0
{
  xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
  msg_process_t process = NULL;
  MSG_process_sleep(1);
  xbt_swag_foreach(process, process_list) {
    XBT_INFO("Process(pid=%d, ppid=%d, name=%s)",
             MSG_process_get_PID(process), MSG_process_get_PPID(process),
             MSG_process_get_name(process));
    if (MSG_process_self_PID() != MSG_process_get_PID(process))
      MSG_process_kill(process);
  }
  process = MSG_process_create("slave from master",
                               slave, NULL, MSG_host_self());
  MSG_process_sleep(2);

  XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
  MSG_process_suspend(process);

  XBT_INFO("Process(pid=%d) is %ssuspended",
           MSG_process_get_PID(process),
           (MSG_process_is_suspended(process)) ? "" : "not ");
  MSG_process_sleep(2);

  XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
  MSG_process_resume(process);

  XBT_INFO("Process(pid=%d) is %ssuspended",
           MSG_process_get_PID(process),
           (MSG_process_is_suspended(process)) ? "" : "not ");
  MSG_process_sleep(2);
  MSG_process_kill(process);
Beispiel #12
0
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                    jobject jprocess_arg,
                                    jobject jhostname)
{


  jobject jprocess;             /* the global reference to the java process instance    */
  jstring jname;                /* the name of the java process instance                */
  const char *name;             /* the C name of the process                            */
  const char *hostname;
  msg_process_t process;          /* the native process to create                         */
  msg_host_t host;                /* Where that process lives */

  hostname = (*env)->GetStringUTFChars(env, jhostname, 0);

  /* get the name of the java process */
  jname = jprocess_get_name(jprocess_arg, env);
  if (!jname) {
    jxbt_throw_null(env,
            xbt_strdup("Internal error: Process name cannot be NULL"));
    return;
  }

  /* bind/retrieve the msg host */
  host = MSG_host_by_name(hostname);

  if (!(host)) {    /* not bound */
    jxbt_throw_host_not_found(env, hostname);
    return;
  }

  /* create a global java process instance */
  jprocess = jprocess_new_global_ref(jprocess_arg, env);
  if (!jprocess) {
    jxbt_throw_jni(env, "Can't get a global ref to the java process");
    return;
  }

  /* build the C name of the process */
  name = (*env)->GetStringUTFChars(env, jname, 0);
  name = xbt_strdup(name);

  /* Retrieve the kill time from the process */
  jdouble jkill = (*env)->GetDoubleField(env, jprocess, jprocess_field_Process_killTime);
  /* Actually build the MSG process */
  process = MSG_process_create_with_environment(name,
						(xbt_main_func_t) jprocess,
						/*data*/ jprocess,
						host,
						/*argc, argv, properties*/
						0,NULL,NULL);
  MSG_process_set_kill_time(process, (double)jkill);
  /* bind the java process instance to the native process */
  jprocess_bind(jprocess, process, env);

  /* release our reference to the process name (variable name becomes invalid) */
  //FIXME : This line should be uncommented but with mac it doesn't work. BIG WARNING
  //(*env)->ReleaseStringUTFChars(env, jname, name);
  (*env)->ReleaseStringUTFChars(env, jhostname, hostname);

  /* sets the PID and the PPID of the process */
  (*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
  (*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
  /* sets the Host of the process */
  jobject jhost = Java_org_simgrid_msg_Host_getByName(env,NULL,jhostname);

  (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
}
Beispiel #13
0
static int master(int argc, char *argv[])
{
    xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
    msg_process_t process = NULL;
    MSG_process_sleep(1);
    xbt_swag_foreach(process, process_list) {
        XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process),
                 MSG_process_get_name(process));
        if (MSG_process_self_PID() != MSG_process_get_PID(process))
            MSG_process_kill(process);
    }
    process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
    MSG_process_sleep(2);

    XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
    MSG_process_suspend(process);

    XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
             (MSG_process_is_suspended(process)) ? "" : "not ");
    MSG_process_sleep(2);

    XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
    MSG_process_resume(process);

    XBT_INFO("Process(pid=%d) is %ssuspended", MSG_process_get_PID(process),
             (MSG_process_is_suspended(process)) ? "" : "not ");
    MSG_process_sleep(2);
    MSG_process_kill(process);

    XBT_INFO("Goodbye now!");