root/dmtcpmessagetypes.h
/* [<][>][^][v][top][bottom][index][help] */
1 /****************************************************************************
2 * Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, and Gene Cooperman *
3 * jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu *
4 * *
5 * This file is part of DMTCP. *
6 * *
7 * DMTCP is free software: you can redistribute it and/or *
8 * modify it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * DMTCP is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with DMTCP:dmtcp/src. If not, see *
19 * <http://www.gnu.org/licenses/>. *
20 ****************************************************************************/
21
22 #ifndef DMTCPMESSAGETYPES_H
23 #define DMTCPMESSAGETYPES_H
24
25 #include "dmtcpalloc.h"
26 #include "uniquepid.h"
27 #include "../jalib/jassert.h"
28 #include "../jalib/jalloc.h"
29 #include "constants.h"
30
31 namespace dmtcp
32 {
33
34 enum DmtcpMessageType
35 {
36 DMT_NULL,
37 DMT_NEW_WORKER, // on connect established worker-coordinator
38 DMT_NAME_SERVICE_WORKER,
39 DMT_RESTART_WORKER, // on connect established worker-coordinator
40 DMT_ACCEPT, // on connect established coordinator-worker
41 DMT_REJECT_NOT_RESTARTING,
42 DMT_REJECT_WRONG_COMP,
43 DMT_REJECT_NOT_RUNNING,
44
45 DMT_UPDATE_PROCESS_INFO_AFTER_FORK,
46 DMT_UPDATE_PROCESS_INFO_AFTER_INIT_OR_EXEC,
47
48 DMT_GET_CKPT_DIR,
49 DMT_GET_CKPT_DIR_RESULT,
50 DMT_UPDATE_CKPT_DIR,
51 DMT_CKPT_FILENAME, // a slave sending it's checkpoint filename to coordinator
52 DMT_UNIQUE_CKPT_FILENAME,// same as DMT_CKPT_FILENAME, except when
53 // unique-ckpt plugin is being used.
54
55 DMT_USER_CMD, // on connect established dmtcp_command -> coordinator
56 DMT_USER_CMD_RESULT, // on reply coordinator -> dmtcp_command
57
58 DMT_DO_SUSPEND, // when coordinator wants slave to suspend 8
59 DMT_DO_RESUME, // when coordinator wants slave to resume (after checkpoint)
60 DMT_DO_FD_LEADER_ELECTION, // when coordinator wants slaves to do leader election
61 DMT_DO_DRAIN, // when coordinator wants slave to flush
62 DMT_DO_CHECKPOINT, // when coordinator wants slave to checkpoint
63 #ifdef COORD_NAMESERVICE
64 DMT_DO_REGISTER_NAME_SERVICE_DATA,
65 DMT_DO_SEND_QUERIES,
66 #endif
67 DMT_DO_REFILL, // when coordinator wants slave to refill buffers
68 DMT_KILL_PEER, // send kill message to peer
69
70 DMT_REGISTER_NAME_SERVICE_DATA,
71 DMT_REGISTER_NAME_SERVICE_DATA_SYNC,
72 DMT_REGISTER_NAME_SERVICE_DATA_SYNC_RESPONSE,
73 DMT_NAME_SERVICE_QUERY,
74 DMT_NAME_SERVICE_QUERY_RESPONSE,
75
76 DMT_OK, // slave telling coordinator it is done (response
77 // to DMT_DO_*) this means slave reached barrier
78 };
79
80 namespace CoordCmdStatus {
81 enum ErrorCodes {
82 NOERROR = 0,
83 ERROR_INVALID_COMMAND = -1,
84 ERROR_NOT_RUNNING_STATE = -2,
85 ERROR_COORDINATOR_NOT_FOUND = -3
86 };
87 }
88
89 ostream& operator << (ostream& o, const DmtcpMessageType& s);
90
91 class WorkerState
92 {
93 public:
94 #ifdef JALIB_ALLOCATOR
95 static void* operator new(size_t nbytes, void* p) { return p; }
96 static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
97 static void operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
98 #endif
99 enum eWorkerState
100 {
101 UNKNOWN,
102 RUNNING,
103 SUSPENDED,
104 FD_LEADER_ELECTION,
105 DRAINED,
106 RESTARTING,
107 CHECKPOINTED,
108 #ifdef COORD_NAMESERVICE
109 NAME_SERVICE_DATA_REGISTERED,
110 DONE_QUERYING,
111 #endif
112 REFILLED,
113 _MAX
114 };
115 WorkerState ( eWorkerState s = UNKNOWN ) : _state ( s ) {}
116
117 static void setCurrentState ( const WorkerState& theValue );
118 static WorkerState currentState();
119
120 eWorkerState value() const;
121
122 bool operator== ( const WorkerState& v ) const{return _state == v.value();}
123 bool operator!= ( const WorkerState& v ) const{return _state != v.value();}
124
125 const char* toString() const;
126 private:
127 int32_t _state;
128 };
129
130 #define DMTCPMESSAGE_NUM_PARAMS 2
131 #define DMTCPMESSAGE_SAME_CKPT_INTERVAL (~0u) /* default value */
132
133 // Make sure the struct is of same size on 32-bit and 64-bit systems.
134 struct DmtcpMessage
135 {
136 char _magicBits[16];
137
138 uint32_t _msgSize;
139 uint32_t extraBytes;
140
141 DmtcpMessageType type;
142 WorkerState state;
143
144 UniquePid from;
145 UniquePid compGroup;
146
147 pid_t virtualPid;
148 pid_t realPid;
149
150 //#ifdef COORD_NAMESERVICE
151 char nsid[8];
152 uint32_t keyLen;
153 uint32_t valLen;
154 //#endif
155
156 uint32_t numPeers;
157 uint32_t isRunning;
158 uint32_t coordCmd;
159 int32_t coordCmdStatus;
160
161 uint64_t coordTimeStamp;
162
163 uint32_t theCheckpointInterval;
164 struct in_addr ipAddr;
165
166 static void setDefaultCoordinator ( const DmtcpUniqueProcessId& id );
167 static void setDefaultCoordinator ( const UniquePid& id );
168 DmtcpMessage ( DmtcpMessageType t = DMT_NULL );
169 void assertValid() const;
170 bool isValid() const;
171 void poison();
172 };
173
174
175 dmtcp::ostream& operator << ( dmtcp::ostream& o, const WorkerState& s );
176
177
178
179 }//namespace dmtcp
180
181
182
183 #endif
184
185
186