55
55
#include "orte/runtime/orte_globals.h"
56
56
#include "orte/mca/rml/rml_types.h"
57
57
#include "orte/util/threads.h"
58
+ #include "orte/mca/errmgr/errmgr.h"
58
59
59
60
BEGIN_C_DECLS
60
61
@@ -88,6 +89,7 @@ typedef struct {
88
89
bool pending ;
89
90
bool always_writable ;
90
91
opal_event_t * ev ;
92
+ struct timeval tv ;
91
93
int fd ;
92
94
opal_list_t outputs ;
93
95
} orte_iof_write_event_t ;
@@ -109,9 +111,11 @@ typedef struct {
109
111
opal_object_t super ;
110
112
struct orte_iof_proc_t * proc ;
111
113
opal_event_t * ev ;
114
+ struct timeval tv ;
112
115
int fd ;
113
116
orte_iof_tag_t tag ;
114
117
bool active ;
118
+ bool always_readable ;
115
119
orte_iof_sink_t * sink ;
116
120
} orte_iof_read_event_t ;
117
121
ORTE_DECLSPEC OBJ_CLASS_DECLARATION (orte_iof_read_event_t );
@@ -145,64 +149,120 @@ struct orte_iof_base_t {
145
149
};
146
150
typedef struct orte_iof_base_t orte_iof_base_t ;
147
151
152
+ /* Write event macro's */
153
+
154
+ static inline bool
155
+ orte_iof_base_fd_always_ready (int fd )
156
+ {
157
+ return opal_fd_is_regular (fd ) ||
158
+ (opal_fd_is_chardev (fd ) && !isatty (fd )) ||
159
+ opal_fd_is_blkdev (fd );
160
+ }
161
+
162
+ #define ORTE_IOF_SINK_BLOCKSIZE (1024)
163
+
164
+ #define ORTE_IOF_SINK_ACTIVATE (wev ) \
165
+ do { \
166
+ struct timeval *tv = NULL; \
167
+ wev->pending = true; \
168
+ ORTE_POST_OBJECT(wev); \
169
+ if (wev->always_writable) { \
170
+ /* Regular is always write ready. Use timer to activate */ \
171
+ tv = & wev -> tv ; \
172
+ } \
173
+ if (opal_event_add (wev -> ev , tv )) { \
174
+ ORTE_ERROR_LOG (ORTE_ERR_BAD_PARAM ); \
175
+ } \
176
+ } while (0 );
177
+
148
178
149
179
/* define an output "sink", adding it to the provided
150
180
* endpoint list for this proc */
151
- #define ORTE_IOF_SINK_DEFINE (snk , nm , fid , tg , wrthndlr ) \
152
- do { \
153
- orte_iof_sink_t *ep; \
154
- OPAL_OUTPUT_VERBOSE((1, orte_iof_base_framework.framework_output, \
155
- "defining endpt: file %s line %d fd %d",\
156
- __FILE__, __LINE__, (fid))); \
157
- ep = OBJ_NEW(orte_iof_sink_t); \
158
- ep->name.jobid = (nm)->jobid; \
159
- ep->name.vpid = (nm)->vpid; \
160
- ep->tag = (tg); \
161
- if (0 <= (fid)) { \
162
- ep->wev->fd = (fid); \
163
- ep->wev->always_writable = opal_fd_is_regular(fid) || \
164
- opal_fd_is_chardev(fid) || \
165
- opal_fd_is_blkdev(fid); \
166
- opal_event_set(orte_event_base, \
167
- ep->wev->ev, ep->wev->fd, \
168
- OPAL_EV_WRITE, \
169
- wrthndlr, ep); \
170
- opal_event_set_priority(ep->wev->ev, ORTE_MSG_PRI); \
171
- } \
172
- *(snk) = ep; \
173
- ORTE_POST_OBJECT(ep); \
181
+ #define ORTE_IOF_SINK_DEFINE (snk , nm , fid , tg , wrthndlr ) \
182
+ do { \
183
+ orte_iof_sink_t *ep; \
184
+ OPAL_OUTPUT_VERBOSE((1, \
185
+ orte_iof_base_framework.framework_output, \
186
+ "defining endpt: file %s line %d fd %d", \
187
+ __FILE__, __LINE__, (fid))); \
188
+ ep = OBJ_NEW(orte_iof_sink_t); \
189
+ ep->name.jobid = (nm)->jobid; \
190
+ ep->name.vpid = (nm)->vpid; \
191
+ ep->tag = (tg); \
192
+ if (0 <= (fid)) { \
193
+ ep->wev->fd = (fid); \
194
+ ep->wev->always_writable = \
195
+ orte_iof_base_fd_always_ready(fid); \
196
+ if(ep->wev->always_writable) { \
197
+ opal_event_evtimer_set(orte_event_base, \
198
+ ep->wev->ev, wrthndlr, ep); \
199
+ } else { \
200
+ opal_event_set(orte_event_base, \
201
+ ep->wev->ev, ep->wev->fd, \
202
+ OPAL_EV_WRITE, \
203
+ wrthndlr, ep); \
204
+ } \
205
+ opal_event_set_priority(ep->wev->ev, ORTE_MSG_PRI); \
206
+ } \
207
+ *(snk) = ep; \
208
+ ORTE_POST_OBJECT(ep); \
174
209
} while(0);
175
210
211
+ /* Read event macro's */
212
+ #define ORTE_IOF_READ_ADDEV (rev ) \
213
+ do { \
214
+ struct timeval *tv = NULL; \
215
+ if (rev->always_readable) { \
216
+ tv = &rev->tv; \
217
+ } \
218
+ if (opal_event_add(rev->ev, tv)) { \
219
+ ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM); \
220
+ } \
221
+ } while(0);
222
+
223
+ #define ORTE_IOF_READ_ACTIVATE (rev ) \
224
+ do { \
225
+ rev->active = true; \
226
+ ORTE_POST_OBJECT(rev); \
227
+ ORTE_IOF_READ_ADDEV(rev); \
228
+ } while(0);
229
+
230
+
176
231
/* add list of structs that has name of proc + orte_iof_tag_t - when
177
232
* defining a read event, search list for proc, add flag to the tag.
178
233
* when closing a read fd, find proc on list and zero out that flag
179
234
* when all flags = 0, then iof is complete - set message event to
180
235
* daemon processor indicating proc iof is terminated
181
236
*/
182
- #define ORTE_IOF_READ_EVENT (rv , p , fid , tg , cbfunc , actv ) \
183
- do { \
184
- orte_iof_read_event_t *rev; \
185
- OPAL_OUTPUT_VERBOSE((1, orte_iof_base_framework.framework_output, \
186
- "%s defining read event for %s: %s %d", \
187
- ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
188
- ORTE_NAME_PRINT(&(p)->name), \
189
- __FILE__, __LINE__)); \
190
- rev = OBJ_NEW(orte_iof_read_event_t); \
191
- OBJ_RETAIN((p)); \
192
- rev->proc = (struct orte_iof_proc_t*)(p); \
193
- rev->tag = (tg); \
194
- rev->fd = (fid); \
195
- *(rv) = rev; \
196
- opal_event_set(orte_event_base, \
197
- rev->ev, (fid), \
198
- OPAL_EV_READ, \
199
- (cbfunc), rev); \
200
- opal_event_set_priority(rev->ev, ORTE_MSG_PRI); \
201
- if ((actv)) { \
202
- rev->active = true; \
203
- ORTE_POST_OBJECT(rev); \
204
- opal_event_add(rev->ev, 0); \
205
- } \
237
+ #define ORTE_IOF_READ_EVENT (rv , p , fid , tg , cbfunc , actv ) \
238
+ do { \
239
+ orte_iof_read_event_t *rev; \
240
+ OPAL_OUTPUT_VERBOSE((1, \
241
+ orte_iof_base_framework.framework_output, \
242
+ "%s defining read event for %s: %s %d", \
243
+ ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
244
+ ORTE_NAME_PRINT(&(p)->name), \
245
+ __FILE__, __LINE__)); \
246
+ rev = OBJ_NEW(orte_iof_read_event_t); \
247
+ OBJ_RETAIN((p)); \
248
+ rev->proc = (struct orte_iof_proc_t*)(p); \
249
+ rev->tag = (tg); \
250
+ rev->fd = (fid); \
251
+ rev->always_readable = orte_iof_base_fd_always_ready(fid); \
252
+ *(rv) = rev; \
253
+ if(rev->always_readable) { \
254
+ opal_event_evtimer_set(orte_event_base, \
255
+ rev->ev, (cbfunc), rev); \
256
+ } else { \
257
+ opal_event_set(orte_event_base, \
258
+ rev->ev, (fid), \
259
+ OPAL_EV_READ, \
260
+ (cbfunc), rev); \
261
+ } \
262
+ opal_event_set_priority(rev->ev, ORTE_MSG_PRI); \
263
+ if ((actv)) { \
264
+ ORTE_IOF_READ_ACTIVATE(rev) \
265
+ } \
206
266
} while(0);
207
267
208
268
0 commit comments