ipp.cpp 7.14 KB
Newer Older
Millian Poquet's avatar
Millian Poquet committed
1 2
/**
 * @file ipp.cpp
Millian Poquet's avatar
Millian Poquet committed
3
 * @brief Inter-Process Protocol (within Batsim, not with the Decision real process)
Millian Poquet's avatar
Millian Poquet committed
4 5
 */

6 7 8 9 10 11
#include "ipp.hpp"

#include <simgrid/msg.h>

using namespace std;

Millian Poquet's avatar
Millian Poquet committed
12
XBT_LOG_NEW_DEFAULT_CATEGORY(ipp, "ipp"); //!< Logging
13

Millian Poquet's avatar
Millian Poquet committed
14 15 16 17
void generic_send_message(const std::string & destination_mailbox,
                          IPMessageType type,
                          void * data,
                          bool detached)
18 19 20 21 22 23 24
{
    IPMessage * message = new IPMessage;
    message->type = type;
    message->data = data;

    msg_task_t task_to_send = MSG_task_create(NULL, 0, 1e-6, message);

25 26
    XBT_DEBUG("message from '%s' to '%s' of type '%s' with data %p",
              MSG_process_get_name(MSG_process_self()), destination_mailbox.c_str(),
Millian Poquet's avatar
Millian Poquet committed
27
              ip_message_type_to_string(type).c_str(), data);
28

29
    if (detached)
30
        MSG_task_dsend(task_to_send, destination_mailbox.c_str(), NULL);
31
    else
32 33
        MSG_task_send(task_to_send, destination_mailbox.c_str());

34 35
    XBT_DEBUG("message from '%s' to '%s' of type '%s' with data %p done",
              MSG_process_get_name(MSG_process_self()), destination_mailbox.c_str(),
Millian Poquet's avatar
Millian Poquet committed
36
              ip_message_type_to_string(type).c_str(), data);
37 38 39 40 41 42 43 44 45 46
}

void send_message(const std::string & destination_mailbox, IPMessageType type, void * data)
{
  generic_send_message(destination_mailbox, type, data, false);
}

void dsend_message(const std::string & destination_mailbox, IPMessageType type, void * data)
{
  generic_send_message(destination_mailbox, type, data, true);
47 48
}

Millian Poquet's avatar
Millian Poquet committed
49
std::string ip_message_type_to_string(IPMessageType type)
50
{
51 52 53
    string s;

    switch(type)
54
    {
55 56 57
        case IPMessageType::JOB_SUBMITTED:
            s = "JOB_SUBMITTED";
            break;
58 59 60
        case IPMessageType::JOB_SUBMITTED_BY_DP:
            s = "JOB_SUBMITTED_BY_DP";
            break;
61 62 63 64 65 66
        case IPMessageType::JOB_COMPLETED:
            s = "JOB_COMPLETED";
            break;
        case IPMessageType::PSTATE_MODIFICATION:
            s = "PSTATE_MODIFICATION";
            break;
Millian Poquet's avatar
Millian Poquet committed
67 68
        case IPMessageType::SCHED_EXECUTE_JOB:
            s = "SCHED_EXECUTE_JOB";
69
            break;
Millian Poquet's avatar
Millian Poquet committed
70 71
        case IPMessageType::SCHED_REJECT_JOB:
            s = "SCHED_REJECT_JOB";
72
            break;
73 74 75
        case IPMessageType::SCHED_KILL_JOB:
            s = "SCHED_KILL_JOB";
            break;
Millian Poquet's avatar
Millian Poquet committed
76 77
        case IPMessageType::SCHED_CALL_ME_LATER:
            s = "SCHED_CALL_ME_LATER";
78
            break;
79 80 81
        case IPMessageType::SCHED_TELL_ME_ENERGY:
            s = "SCHED_TELL_ME_ENERGY";
            break;
Pierre-François's avatar
Pierre-François committed
82 83 84 85 86 87
        case IPMessageType::SCHED_WAIT_ANSWER:
            s = "SCHED_WAIT_ANSWER";
            break;
        case IPMessageType::WAIT_QUERY:
            s = "WAIT_QUERY";
            break;
88 89 90 91 92 93 94 95 96
        case IPMessageType::SCHED_READY:
            s = "SCHED_READY";
            break;
        case IPMessageType::WAITING_DONE:
            s = "WAITING_DONE";
            break;
        case IPMessageType::SUBMITTER_HELLO:
            s = "SUBMITTER_HELLO";
            break;
97 98 99
        case IPMessageType::SUBMITTER_CALLBACK:
            s = "SUBMITTER_CALLBACK";
            break;
100 101 102 103 104 105 106 107 108
        case IPMessageType::SUBMITTER_BYE:
            s = "SUBMITTER_BYE";
            break;
        case IPMessageType::SWITCHED_ON:
            s = "SWITCHED_ON";
            break;
        case IPMessageType::SWITCHED_OFF:
            s = "SWITCHED_OFF";
            break;
109
        case IPMessageType::KILLING_DONE:
Millian Poquet's avatar
Millian Poquet committed
110
            s = "KILLING_DONE";
111
            break;
112
    }
113

114
    return s;
115
}
116 117 118 119 120 121

void send_message(const char *destination_mailbox, IPMessageType type, void *data)
{
    const string str = destination_mailbox;
    send_message(str, type, data);
}
122

123 124 125 126 127 128
void dsend_message(const char *destination_mailbox, IPMessageType type, void *data)
{
    const string str = destination_mailbox;
    dsend_message(str, type, data);
}

129 130 131 132 133 134 135 136 137
IPMessage::~IPMessage()
{
    switch (type)
    {
        case IPMessageType::JOB_SUBMITTED:
        {
            JobSubmittedMessage * msg = (JobSubmittedMessage *) data;
            delete msg;
        } break;
138 139 140 141 142
        case IPMessageType::JOB_SUBMITTED_BY_DP:
        {
            JobSubmittedByDPMessage * msg = (JobSubmittedByDPMessage *) data;
            delete msg;
        } break;
143 144 145 146 147 148 149 150 151 152
        case IPMessageType::JOB_COMPLETED:
        {
            JobCompletedMessage * msg = (JobCompletedMessage *) data;
            delete msg;
        } break;
        case IPMessageType::PSTATE_MODIFICATION:
        {
            PStateModificationMessage * msg = (PStateModificationMessage *) data;
            delete msg;
        } break;
Millian Poquet's avatar
Millian Poquet committed
153
        case IPMessageType::SCHED_EXECUTE_JOB:
154
        {
155
            ExecuteJobMessage * msg = (ExecuteJobMessage *) data;
156
            // The Allocations themselves are not memory-deallocated there but at the end of the job execution.
157 158
            delete msg;
        } break;
Millian Poquet's avatar
Millian Poquet committed
159
        case IPMessageType::SCHED_REJECT_JOB:
160 161 162 163
        {
            JobRejectedMessage * msg = (JobRejectedMessage *) data;
            delete msg;
        } break;
164 165 166 167 168
        case IPMessageType::SCHED_KILL_JOB:
        {
            KillJobMessage * msg = (KillJobMessage *) data;
            delete msg;
        } break;
Millian Poquet's avatar
Millian Poquet committed
169
        case IPMessageType::SCHED_CALL_ME_LATER:
170
        {
Millian Poquet's avatar
Millian Poquet committed
171
            CallMeLaterMessage * msg = (CallMeLaterMessage*) data;
172 173
            delete msg;
        } break;
174 175 176
        case IPMessageType::SCHED_TELL_ME_ENERGY:
        {
        } break;
Pierre-François's avatar
Pierre-François committed
177 178 179 180 181 182 183 184
        case IPMessageType::WAIT_QUERY:
        {
            WaitQueryMessage * msg = (WaitQueryMessage *) data;
            delete msg;
        } break;
        case IPMessageType::SCHED_WAIT_ANSWER:
        {
            SchedWaitAnswerMessage * msg = (SchedWaitAnswerMessage *) data;
185
            delete msg;
Pierre-François's avatar
Pierre-François committed
186
        } break;
187 188 189 190 191
        case IPMessageType::SCHED_READY:
        {
        } break;
        case IPMessageType::SUBMITTER_HELLO:
        {
192 193 194 195 196 197 198
            SubmitterHelloMessage * msg = (SubmitterHelloMessage *) data;
            delete msg;
        } break;
        case IPMessageType::SUBMITTER_CALLBACK:
        {
            SubmitterJobCompletionCallbackMessage * msg = (SubmitterJobCompletionCallbackMessage *) data;
            delete msg;
199 200 201
        } break;
        case IPMessageType::SUBMITTER_BYE:
        {
202 203
            SubmitterByeMessage * msg = (SubmitterByeMessage *) data;
            delete msg;
204 205 206
        } break;
        case IPMessageType::SWITCHED_ON:
        {
207
            SwitchONMessage * msg = (SwitchONMessage *) data;
208 209 210 211
            delete msg;
        } break;
        case IPMessageType::SWITCHED_OFF:
        {
212
            SwitchOFFMessage * msg = (SwitchOFFMessage *) data;
213 214
            delete msg;
        } break;
215 216 217
        case IPMessageType::WAITING_DONE:
        {
        } break;
218 219 220 221 222
        case IPMessageType::KILLING_DONE:
        {
            KillingDoneMessage * msg = (KillingDoneMessage *) data;
            delete msg;
        } break;
223 224 225 226
    }

    data = nullptr;
}
227

228 229 230 231 232 233 234
JobIdentifier::JobIdentifier(const string &workload_name, int job_number) :
    workload_name(workload_name),
    job_number(job_number)
{

}

235 236 237 238
string JobIdentifier::to_string() const
{
    return workload_name + '!' + std::to_string(job_number);
}
239 240 241 242 243

bool operator<(const JobIdentifier &ji1, const JobIdentifier &ji2)
{
    return ji1.to_string() < ji2.to_string();
}