ipp.cpp 5.09 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 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

void send_message(const std::string & destination_mailbox, IPMessageType type, void * data)
{
    IPMessage * message = new IPMessage;
    message->type = type;
    message->data = data;

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

    XBT_INFO("message from '%s' to '%s' of type '%s' with data %p",
             MSG_process_get_name(MSG_process_self()), destination_mailbox.c_str(), ipMessageTypeToString(type).c_str(), data);

    MSG_task_send(task_to_send, destination_mailbox.c_str());
}

std::string ipMessageTypeToString(IPMessageType type)
{
30 31 32
    string s;

    switch(type)
33
    {
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
        case IPMessageType::JOB_SUBMITTED:
            s = "JOB_SUBMITTED";
            break;
        case IPMessageType::JOB_COMPLETED:
            s = "JOB_COMPLETED";
            break;
        case IPMessageType::PSTATE_MODIFICATION:
            s = "PSTATE_MODIFICATION";
            break;
        case IPMessageType::SCHED_ALLOCATION:
            s = "SCHED_ALLOCATION";
            break;
        case IPMessageType::SCHED_REJECTION:
            s = "SCHED_REJECTION";
            break;
        case IPMessageType::SCHED_NOP:
            s = "SCHED_NOP";
            break;
        case IPMessageType::SCHED_NOP_ME_LATER:
            s = "SCHED_NOP_ME_LATER";
            break;
55 56 57
        case IPMessageType::SCHED_TELL_ME_ENERGY:
            s = "SCHED_TELL_ME_ENERGY";
            break;
58 59 60 61 62 63 64 65 66
        case IPMessageType::SCHED_READY:
            s = "SCHED_READY";
            break;
        case IPMessageType::WAITING_DONE:
            s = "WAITING_DONE";
            break;
        case IPMessageType::SUBMITTER_HELLO:
            s = "SUBMITTER_HELLO";
            break;
67 68 69
        case IPMessageType::SUBMITTER_CALLBACK:
            s = "SUBMITTER_CALLBACK";
            break;
70 71 72 73 74 75 76 77 78 79
        case IPMessageType::SUBMITTER_BYE:
            s = "SUBMITTER_BYE";
            break;
        case IPMessageType::SWITCHED_ON:
            s = "SWITCHED_ON";
            break;
        case IPMessageType::SWITCHED_OFF:
            s = "SWITCHED_OFF";
            break;
    }
80

81
    return s;
82
}
83 84 85 86 87 88

void send_message(const char *destination_mailbox, IPMessageType type, void *data)
{
    const string str = destination_mailbox;
    send_message(str, type, data);
}
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

IPMessage::~IPMessage()
{
    switch (type)
    {
        case IPMessageType::JOB_SUBMITTED:
        {
            JobSubmittedMessage * msg = (JobSubmittedMessage *) data;
            delete msg;
        } break;
        case IPMessageType::JOB_COMPLETED:
        {
            JobCompletedMessage * msg = (JobCompletedMessage *) data;
            delete msg;
        } break;
        case IPMessageType::PSTATE_MODIFICATION:
        {
            PStateModificationMessage * msg = (PStateModificationMessage *) data;
            delete msg;
        } break;
        case IPMessageType::SCHED_ALLOCATION:
        {
            SchedulingAllocationMessage * msg = (SchedulingAllocationMessage *) data;
112
            // The Allocations themselves are not memory-deallocated there but at the end of the job execution.
113 114
            delete msg;
        } break;
115 116 117 118 119 120 121 122 123 124
        case IPMessageType::SCHED_REJECTION:
        {
            JobRejectedMessage * msg = (JobRejectedMessage *) data;
            delete msg;
        } break;
        case IPMessageType::SCHED_NOP_ME_LATER:
        {
            NOPMeLaterMessage * msg = (NOPMeLaterMessage*) data;
            delete msg;
        } break;
125 126 127
        case IPMessageType::SCHED_NOP:
        {
        } break;
128 129 130
        case IPMessageType::SCHED_TELL_ME_ENERGY:
        {
        } break;
131 132 133 134 135
        case IPMessageType::SCHED_READY:
        {
        } break;
        case IPMessageType::SUBMITTER_HELLO:
        {
136 137 138 139 140 141 142
            SubmitterHelloMessage * msg = (SubmitterHelloMessage *) data;
            delete msg;
        } break;
        case IPMessageType::SUBMITTER_CALLBACK:
        {
            SubmitterJobCompletionCallbackMessage * msg = (SubmitterJobCompletionCallbackMessage *) data;
            delete msg;
143 144 145
        } break;
        case IPMessageType::SUBMITTER_BYE:
        {
146 147
            SubmitterByeMessage * msg = (SubmitterByeMessage *) data;
            delete msg;
148 149 150
        } break;
        case IPMessageType::SWITCHED_ON:
        {
151
            SwitchONMessage * msg = (SwitchONMessage *) data;
152 153 154 155
            delete msg;
        } break;
        case IPMessageType::SWITCHED_OFF:
        {
156
            SwitchOFFMessage * msg = (SwitchOFFMessage *) data;
157 158
            delete msg;
        } break;
159 160 161
        case IPMessageType::WAITING_DONE:
        {
        } break;
162 163 164 165
    }

    data = nullptr;
}
166

167 168 169 170 171 172 173
JobIdentifier::JobIdentifier(const string &workload_name, int job_number) :
    workload_name(workload_name),
    job_number(job_number)
{

}

174 175 176 177
string JobIdentifier::to_string() const
{
    return workload_name + '!' + std::to_string(job_number);
}
178 179 180 181 182

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