Debian Codegraph @

armci/src/devices/openib/pendbufs.c

raw symbols SCIP
1 #if HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4
5 #if defined(PEND_BUFS)
6
7 #include "pendbufs.h"
8 #include "armcip.h"
9 #if HAVE_STDIO_H
10 # include <stdio.h>
11 #endif
12 #if HAVE_ASSERT_H
13 # include <assert.h>
14 #endif
15 #if HAVE_STDLIB_H
16 # include <stdlib.h>
17 #endif
18 #if HAVE_STRING_H
19 # include <string.h>
20 #endif
21
22 #define DEBUG_SERVER 0
23
24 /*-------------------Attributes-------------------------*/
25
26 /**Attributes to control buffer count and sizes. Implement this way to
27 hide the global variables, and provide get/set methods.*/
28
29 #define NUM_ATTRIBUTES 4
30 #define ATTRIB_IMMBUF_LEN 0
31 #define ATTRIB_IMMBUF_NUM 1
32 #define ATTRIB_PNDBUF_LEN 2
33 #define ATTRIB_PNDBUF_NUM 3
34
35 /** List of hidden attributes and their operations.
36 * @param attid IN Attribute id. Choose from the list above
37 * @param gs IN Get(=0)/Set(=1)
38 * @param v IN Value (used only when gs==1)
39 * @return Value of the attribute on return
40 */
41 static int att_ops(int attid, int gs, int v) {
42 static not_first[NUM_ATTRIBUTES]; /*auto-init to zero*/
43 static val[NUM_ATTRIBUTES];
44 assert(attid>=0 && attid<NUM_ATTRIBUTES);
45 assert(gs==0 || gs==1);
46 if(!((gs && !not_first[attid]) || (!gs && not_first[attid]))) {
47 printf("%d(%d) pausing...\n", armci_me, (int)getpid());
48 pause();
49 }
50 if(gs) {
51 not_first[attid]=1;
52 val[attid]=v;
53 }
54 return val[attid];
55 }
56
57 int get_immbuf_len() { return att_ops(ATTRIB_IMMBUF_LEN,0,-1);}
58 void set_immbuf_len(int val) { att_ops(ATTRIB_IMMBUF_LEN,1,val);}
59 int get_immbuf_num() { return att_ops(ATTRIB_IMMBUF_NUM,0,-1);}
60 void set_immbuf_num(int val) { att_ops(ATTRIB_IMMBUF_NUM,1,val);}
61 int get_pendbuf_len() { return att_ops(ATTRIB_PNDBUF_LEN,0,-1);}
62 void set_pendbuf_len(int val) { att_ops(ATTRIB_PNDBUF_LEN,1,val);}
63 int get_pendbuf_num() { return att_ops(ATTRIB_PNDBUF_NUM,0,-1);}
64 void set_pendbuf_num(int val) { att_ops(ATTRIB_PNDBUF_NUM,1,val);}
65
66 #undef NUM_ATTRIBUTES
67 #undef ATTRIB_IMMBUF_LEN
68 #undef ATTRIB_IMMBUF_NUM
69 #undef ATTRIB_PNDBUF_LEN
70 #undef ATTRIB_PNDBUF_NUM
71
72 void armci_pbuf_init_buffer_env() {
73 set_immbuf_len(IMM_BUF_LEN_DEFAULT);
74 set_immbuf_num(IMM_BUF_NUM_DEFAULT);
75 set_pendbuf_len(PENDING_BUF_LEN_DEFAULT);
76 set_pendbuf_num(PENDING_BUF_NUM_DEFAULT);
77 }
78
79 /*---------------Waiting lists for ordering--------------------*/
80
81 /** Waiting procs list. This is a structure to maintain a list of
82 * processes with any waiting messages (immediate or non-immediate).
83 * Invariants:
84 * - !prev equivals !next (boolean type)
85 * - !immbuf_wlist_head equivals !immbuf_wlist_tail (boolean type)
86 * - !prev equivals !immbuf_wlist_head (boolean type)
87 * - !immbuf_waitlist_head equivals (n_pending!=0) (boolean type)
88 * - !order_head equivals !order_tail (boolean type)
89 * In particular, note that order_head and order_tail are set and
90 * reset independent of any immbufs waiting to be processed.
91 */
92 typedef struct proc_waitlist_t {
93 struct proc_waitlist_t *prev; /*<Previous proc in list of procs with
94 waiting immbufs (circular dlist)*/
95 struct proc_waitlist_t *next; /*<Next proc in list of procs with
96 waiting immbufs*/
97 immbuf_t *immbuf_wlist_head; /**<Waiting immbufs for this proc - head*/
98 immbuf_t *immbuf_wlist_tail; /**<Waiting immbufs for this proc - tail*/
99 pendbuf_t *order_head,*order_tail; /**<List of pending buffers processing requests from this proc*/
100 /* vapibuf_pend_t *waiting_on; /\**<This pendbuf is for req from the */
101 /* same proc*\/ */
102 int n_pending; /**<#pending reqs fromt his proc*/
103 } proc_waitlist_t;
104
105
106 /** #pending buffers being used.
107 */
108 static int _nPendBufsUsed=0;
109
110 /** The ordering semantics used. Need to provide accessors later if
111 * necessory.
112 */
113 static enum PendBufOrderingRule _pbufOrder = GET_GET_REORDER;
114
115 /*static*/ pendbuf_t *serv_pendbuf_arr; /**<Array of pending buffers*/
116
117 static proc_waitlist_t *pbuf_ordering_plist_head; /**<Head of list of procs
118 with waiting immbufs*/
119 static proc_waitlist_t *pbuf_proc_list_info; /**<Array of structs for
120 all the procs*/
121
122 /*-------------Pending states---------------------------*/
123
124 /**Status of pending buffers. Used in pending making progress and
125 * implementing teh corresponding finite-state-machine.
126 */
127 enum PendBufStatus {
128 RECV_DATA_DONE=4, /**<Done recv-ing data. Used for PUT/ACCs*/
129 SEND_DATA_DONE=5, /**<Done sending data. For GETs*/
130 RECV_DSCR_DONE=6, /**<Done recv-ing descriptor. When
131 request_header_t+dscrlen>IMM_BUF_LEN*/
132 INIT=7, /**<Initial state for buffer*/
133 RECV_DATA_PENDING=0,/**<Data recv posted and not completed*/
134 SEND_DATA_PENDING=1,/**<Data send posted and not completed*/
135 RECV_DSCR_PENDING=2 /**<Descriptor recv posted & not completed*/
136 };
137
138
139
140
141 /**Get a buffer to process an incoming request with non-immediate
142 * data.
143 * @return Pointer to available pending buffer
144 */
145 static void* _armci_serv_pendbuf_getbuf(){
146 int i;
147 for(i=0; i<PENDING_BUF_NUM; i++) {
148 if(serv_pendbuf_arr[i].avail) {
149 serv_pendbuf_arr[i].status = INIT;
150 serv_pendbuf_arr[i].avail=0;
151 serv_pendbuf_arr[i].order_prev = NULL;
152 serv_pendbuf_arr[i].order_next = NULL;
153 serv_pendbuf_arr[i].commit_me = 0;
154 /*fprintf(stderr, "%d:: getbuf returns idx=%d pbuf=%p\n",
155 armci_me, i, &serv_pendbuf_arr[i]);*/
156 _nPendBufsUsed += 1;
157 assert(_nPendBufsUsed<=PENDING_BUF_NUM);
158 ARMCI_PR_DBG("exit",0);
159 return &serv_pendbuf_arr[i];
160 }
161 }
162 return NULL;
163 }
164
165 /**Assign a pending buffer for this immediate buffer. If a buffer is
166 * available, it initializes the pending buffer appropriately.
167 * @param vbuf IN Immediate buffer to be assign a pending buffer
168 * @return Pointer to pending buffer, it assigned. NULL otherwise.
169 */
170 static pendbuf_t* _armci_serv_pendbuf_assignbuf(immbuf_t *vbuf) {
171 pendbuf_t *pbuf;
172 const request_header_t *msginfo = (request_header_t *)vbuf->buf;
173 proc_waitlist_t *info = &pbuf_proc_list_info[msginfo->from];
174 assert(msginfo->tag.imm_msg == 0);
175 pbuf = _armci_serv_pendbuf_getbuf();
176 if(pbuf) {
177 pbuf->status = INIT;
178 pbuf->avail = 0;
179 pbuf->vbuf = vbuf;
180 memcpy(pbuf->buf, vbuf->buf, sizeof(request_header_t)+msginfo->dscrlen);
181 /* pbuf_proc_list_info[msginfo->from].waiting_on=pbuf; */
182 pbuf->order_prev = info->order_tail;
183 if(info->order_tail) info->order_tail->order_next = pbuf;
184 info->order_tail = pbuf;
185 if(!info->order_head) info->order_head = pbuf;
186 }
187 return pbuf;
188 }
189
190
191 /**Free a pending buffer
192 * @param pbuf IN Pointer to Pending buffer to be freed
193 * @return none
194 */
195 static void _armci_serv_pendbuf_freebuf(pendbuf_t *pbuf){
196 const request_header_t *msginfo = (request_header_t *)pbuf->buf;
197 proc_waitlist_t *info = &pbuf_proc_list_info[msginfo->from];
198 ARMCI_PR_DBG("enter",0);
199 assert(pbuf != NULL);
200 pbuf->avail=1;
201 pbuf->status = -1;
202 pbuf->vbuf = NULL;
203 /* assert(info->waiting_on == pbuf); */
204 /* info->waiting_on = NULL; */
205 if(pbuf->order_prev)
206 pbuf->order_prev->order_next = pbuf->order_next;
207 if(pbuf->order_next)
208 pbuf->order_next->order_prev = pbuf->order_prev;
209 if(info->order_head == pbuf) {
210 assert(pbuf->order_prev == NULL);
211 info->order_head = pbuf->order_next;
212 }
213 if(info->order_tail == pbuf) {
214 assert(pbuf->order_next == NULL);
215 info->order_tail = pbuf->order_prev;
216 }
217 pbuf->order_prev = pbuf->order_next = NULL; /*not necessary here*/
218
219 _nPendBufsUsed -= 1;
220 assert(_nPendBufsUsed>=0);
221 ARMCI_PR_DBG("exit",0);
222 }
223
224 #if 0
225 /*Messages are processed in-place in immediate buffers or issued
226 into pending buffers for progress in order (like
227 ONE_PBUF_PER_MESG). This rule relaxes ONE_PBUF_PER_MESG by
228 allowing ACCs to be processed in-place/issued
229 without waiting for the prior reqs to complete*/
230 static int _can_progress_accnoorder(immbuf_t *vbuf) {
231 const request_header_t *msginfo=(request_header_t*)vbuf->buf;
232 const int proc = msginfo->from;
233 const proc_waitlist_t *info = &pbuf_proc_list_info[proc];
234 int i, nwaiting_on, nacc;
235 pendbuf_t *ptr;
236
237 assert(_pbufOrder == ACC_NO_ORDER);
238 if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) {
239 /* printf("%d(s): op=%d from=%d datalen=%d waiting for pending buffers\n",armci_me,msginfo->operation,msginfo->from,msginfo->tag.data_len); */
240 /* fflush(stdout); */
241 return 0; /*This buffer needs a free pending buffer*/
242 }
243 if(IS_IMM_MSG(*msginfo) && ARMCI_ACC(msginfo->operation)) {
244 return 1;
245 }
246 if(info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf) {
247 /* printf("%d(s): op=%d from=%d datalen=%d not queue head\n",armci_me,msginfo->operation,msginfo->from,msginfo->tag.data_len); */
248 /* fflush(stdout); */
249 return 0; /*in order issue*/
250 }
251
252 if(!ARMCI_ACC(msginfo->operation)) {
253 if(info->order_head)
254 return 0;
255 return 1;
256 }
257
258 int check = ARMCI_ACC(msginfo->operation);
259 assert(check);
260 for(ptr=info->order_head; ptr!=NULL; ptr=ptr->order_next) {
261 request_header_t *m = (request_header_t *)ptr->buf;
262 assert(m->from == msginfo->from);
263 if(!ARMCI_ACC(m->operation))
264 break;
265 }
266 if(ptr != NULL)
267 return 0;
268 return 1;
269 }
270
271 static int _can_progress_putaccsplitorder(immbuf_t*vbuf) {
272 if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) {
273 return 0; /*This buffer needs a free pending buffer*/
274 }
275 if(IS_IMM_MSG(*msginfo) && ARMCI_ACC(msginfo->operation)) {
276 return 1;
277 }
278 if(info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf) {
279 return 0;
280 }
281 if(msginfo->operation!=PUT && !ARMCI_ACC(msginfo->operation)) {
282 if(info->order_head)
283 return 0;
284 return 1;
285 }
286 if(IS_IMM_MSG(*msginfo) && info->order_head)
287 return 0;
288 return 1;
289 }
290 #endif
291
292 /** Implement ordering between messages. This function needs to be
293 * implemented in conjunction with @_armci_serv_pendbuf_promote to
294 * ensure ordered processing of messages.
295 * @param vbuf IN Message in immediate buffer being checked
296 * @return 1 if the message can be progressed (either in-place or
297 * after copying to a pending buffer). 0 therwise.
298 */
299 static int _armci_serv_pendbuf_can_progress(immbuf_t *vbuf) {
300 const request_header_t *msginfo=(request_header_t*)vbuf->buf;
301 const int proc = msginfo->from;
302 const proc_waitlist_t *info = &pbuf_proc_list_info[proc];
303
304 if(_pbufOrder == ONE_PBUF_MESG) {
305 /*Only one pending buffer used at any time*/
306 if(_nPendBufsUsed>0)
307 return 0;
308 return 1;
309 }
310 if(_pbufOrder == ONE_PBUF_MESG_PER_PROC) {
311 /*Only one non-immediate mesg can be assigned to the pending
312 buffers at any time*/
313 if(info->order_head
314 || (info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf)) {
315 return 0;/*other requests from this process remain*/
316 }
317 if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) {
318 return 0; /*This buffer needs a free pending buffer*/
319 }
320 assert(info->n_pending == 0 || info->immbuf_wlist_head==vbuf);
321 return 1;
322 }
323 if(_pbufOrder == ACC_NO_ORDER) {
324 /*Messages are processed in-place in immediate buffers or issued
325 into pending buffers for progress in order (like
326 ONE_PBUF_PER_MESG). This rule relaxes ONE_PBUF_PER_MESG by
327 allowing a sequence of ACCs to be processed in-place/issued
328 without waiting for the prior ones to complete*/
329 int i, nwaiting_on, nacc;
330 pendbuf_t *ptr;
331 if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) {
332 /* printf("%d(s): op=%d from=%d datalen=%d waiting for pending buffers\n",armci_me,msginfo->operation,msginfo->from,msginfo->tag.data_len); */
333 /* fflush(stdout); */
334 return 0; /*This buffer needs a free pending buffer*/
335 }
336 #if 1 /*commented for now: it does work*/
337 if(IS_IMM_MSG(*msginfo) && ARMCI_ACC(msginfo->operation)) {
338 return 1;
339 }
340 #endif
341 if(info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf) {
342 /* printf("%d(s): op=%d from=%d datalen=%d not queue head\n",armci_me,msginfo->operation,msginfo->from,msginfo->tag.data_len); */
343 /* fflush(stdout); */
344 return 0; /*in order issue*/
345 }
346
347 if(!ARMCI_ACC(msginfo->operation)) {
348 if(info->order_head)
349 return 0;
350 return 1;
351 }
352
353 assert(ARMCI_ACC(msginfo->operation));
354 for(ptr=info->order_head; ptr!=NULL; ptr=ptr->order_next) {
355 request_header_t *m = (request_header_t *)ptr->buf;
356 assert(m->from == msginfo->from);
357 if(!ARMCI_ACC(m->operation))
358 break;
359 }
360 if(ptr != NULL)
361 return 0;
362 return 1;
363 }
364 if(_pbufOrder == PUTACC_SPLIT_ORDER) {
365 if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) {
366 return 0; /*This buffer needs a free pending buffer*/
367 }
368 if(info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf) {
369 return 0;
370 }
371 if(msginfo->operation!=PUT && !ARMCI_ACC(msginfo->operation)) {
372 if(info->order_head)
373 return 0;
374 return 1;
375 }
376 if(IS_IMM_MSG(*msginfo) && ARMCI_ACC(msginfo->operation)) {
377 return 1;
378 }
379 if(IS_IMM_MSG(*msginfo) && info->order_head)
380 return 0;
381 return 1;
382 }
383 if(_pbufOrder == GET_GET_REORDER) {
384 if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) {
385 return 0; /*This buffer needs a free pending buffer*/
386 }
387 if(IS_IMM_MSG(*msginfo) && ARMCI_ACC(msginfo->operation)) {
388 return 1;
389 }
390 if(info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf) {
391 return 0;
392 }
393 if(msginfo->operation!=PUT && !ARMCI_ACC(msginfo->operation)) {
394 if(info->order_tail) {
395 request_header_t *m=(request_header_t*)info->order_tail->buf;
396 if(msginfo->operation==GET && m->operation == GET) {
397 /* printf("%d: Get Get progressing\n", armci_me); */
398 return 1;
399 }
400 return 0;
401 }
402 return 1;
403 }
404 if(IS_IMM_MSG(*msginfo) && info->order_head)
405 return 0;
406 return 1;
407 }
408 armci_die("Unknown pbuf ordering rule",_pbufOrder);
409 return 0;
410 }
411
412 /** Goes through the set of immediate buffers waiting to be processed
413 * and completed, and identifies a buffer that can be processed
414 * now. Removes it from the list and returns it. Promote also
415 * considers availability of pending buffers if need be.
416 * @return Pointer to buffer that can be processed now. NULL if none exists.
417 */
418 static immbuf_t* _armci_serv_pendbuf_promote() {
419 immbuf_t *immbuf = NULL;
420 proc_waitlist_t *info;
421
422 ARMCI_PR_DBG("enter",0);
423
424 assert(_nPendBufsUsed>=0);
425 if(!pbuf_ordering_plist_head) {
426 return NULL; /*nothing to promote*/
427 }
428
429 info = pbuf_ordering_plist_head;
430 do {
431 if(info->immbuf_wlist_head==NULL) {
432 printf("%d(s): Why is info->immbuf_wlist_head NULL\n", armci_me);
433 fflush(stdout);
434 pause();
435 }
436 assert(info->immbuf_wlist_head!=NULL);
437 assert(info->n_pending>0);
438 if(_armci_serv_pendbuf_can_progress(info->immbuf_wlist_head)) {
439 immbuf = info->immbuf_wlist_head;
440 info->immbuf_wlist_head = immbuf->immbuf_list_next;
441 info->n_pending -= 1;
442 immbuf->immbuf_list_next = NULL;
443 if(!info->immbuf_wlist_head) {
444 assert(info->immbuf_wlist_tail == immbuf);
445 info->immbuf_wlist_tail = NULL;
446 /*remove this proc from proc list*/
447 info->prev->next = info->next;
448 info->next->prev = info->prev;
449 if(pbuf_ordering_plist_head == info) {
450 pbuf_ordering_plist_head = (info->next==info)?NULL:info->next;
451 }
452 info->prev = info->next = NULL;
453 }
454 break;
455 }
456 info = info->next;
457 } while(info != pbuf_ordering_plist_head);
458
459 if(DEBUG_SERVER) if(immbuf) {
460 request_header_t *msginfo=(request_header_t*)immbuf->buf;
461 printf("%d:: promoting a buffer immbuf=%p op=%d from=%d n_pending=%d\n",
462 armci_me,immbuf,msginfo->operation,msginfo->from,info->n_pending);
463 fflush(stdout);
464 }
465 ARMCI_PR_DBG("exit",0);
466 return immbuf;
467 }
468
469 /** Enqueue a message. It could be an immediate message that cannot
470 * make progress or a non-immediate message that cannot make progress
471 * either due to ordering constraints or lack of pending buffers.
472 * @param vbuf IN Immediate buffer to be enqueud
473 * @return Pending buffer into which the message was enqueued. NULL
474 * if no pending buffer was allocated (which is always the case for
475 * immediate messages)
476 */
477 static pendbuf_t* _armci_serv_pendbuf_enqueue(immbuf_t *vbuf) {
478 request_header_t *msginfo=(request_header_t *)vbuf->buf;
479 int from = msginfo->from;
480 pendbuf_t *pbuf;
481 immbuf_t *ibuf;
482 proc_waitlist_t *info = &pbuf_proc_list_info[msginfo->from];
483 ARMCI_PR_DBG("enter",0);
484
485 /* printf("%d: Entered serv_pbuf_enqueue\n", armci_me); */
486
487 pbuf=NULL;
488 if(msginfo->tag.imm_msg) {
489 assert(!_armci_serv_pendbuf_can_progress(vbuf));
490 }
491 else if(_armci_serv_pendbuf_can_progress(vbuf)) {
492 pbuf = _armci_serv_pendbuf_assignbuf(vbuf);
493 assert(pbuf != NULL); /*can_progress() should ensure this*/
494 }
495 if(pbuf == NULL) {
496 /* printf("%d(s):: Enqueing op=%d imm=%d from %d. n_pending=%d\n", armci_me, msginfo->operation, msginfo->tag.imm_msg, msginfo->from,info->n_pending); */
497 /* fflush(stdout); */
498 vbuf->immbuf_list_next = NULL;
499 assert(info->n_pending < IMM_BUF_NUM); /*How another message now?*/
500 for(ibuf=info->immbuf_wlist_head;ibuf!=NULL;ibuf=ibuf->immbuf_list_next) {
501 assert(vbuf != ibuf); /*enqueueing the same buffer twice*/
502 }
503
504 info->n_pending += 1;
505
506 if(!info->immbuf_wlist_head) {
507 assert(!info->immbuf_wlist_tail);
508 assert(!info->prev && !info->next);
509 /*insert proc into proc list*/
510 if(!pbuf_ordering_plist_head) {
511 pbuf_ordering_plist_head=info->next=info->prev=info;
512 }
513 else {
514 info->next = pbuf_ordering_plist_head;
515 info->prev = pbuf_ordering_plist_head->prev;
516 pbuf_ordering_plist_head->prev->next = info;
517 pbuf_ordering_plist_head->prev = info;
518 }
519 }
520 /*insert vbuf into immbuf list for this proc*/
521 if(info->immbuf_wlist_tail)
522 info->immbuf_wlist_tail->immbuf_list_next=vbuf;
523 info->immbuf_wlist_tail = vbuf;
524 if(!info->immbuf_wlist_head)
525 info->immbuf_wlist_head = vbuf;
526 }
527 /* printf("%d: Leaving serv_pbuf_enqueue\n", armci_me); */
528 ARMCI_PR_DBG("exit",0);
529 return pbuf;
530 }
531
532 /** Progress GET requests.
533 * @param pbuf IN Pending buffer containing the GET request
534 * @return none
535 */
536 static void _armci_serv_pendbuf_progress_get(pendbuf_t *pbuf) {
537 int index = (pbuf - serv_pendbuf_arr);
538 request_header_t *msginfo = (request_header_t *)pbuf->buf;
539 void *buffer =((char *)(msginfo+1)+msginfo->dscrlen);
540 int *status = &pbuf->status;
541
542 assert(sizeof(request_header_t)+msginfo->dscrlen+msginfo->datalen<PENDING_BUF_LEN);
543 switch(*status) {
544 case INIT:
545 if(sizeof(request_header_t)+msginfo->dscrlen <= IMM_BUF_LEN) {
546 /*Have the header and descriptor; go process*/
547 armci_complete_pendbuf(pbuf);
548 if(msginfo->pinned) {
549 *status = SEND_DATA_DONE;
550 _armci_serv_pendbuf_freebuf(pbuf);
551 }
552 else {
553 *status = SEND_DATA_PENDING;
554 }
555 }
556 else { /*Need to get rest of descriptor*/
557 const int bytes = sizeof(request_header_t)+msginfo->dscrlen-IMM_BUF_LEN;
558 #warning "PEND_BUFS: Abusing msginfo->tag.ack_ptr for GETS with large descriptors!"
559 assert(msginfo->tag.ack_ptr != NULL); /*sanity check. Should point to tag.ack on the client side*/
560 void *lptr = ((char *)msginfo)+IMM_BUF_LEN;
561 void *rptr = ((char *)msginfo->tag.ack_ptr) - (int)(&((request_header_t *)0)->tag.ack) + IMM_BUF_LEN;
562 /* printf("%d(s):: GET getting rest of descriptor index=%d bytes=%d ptr=%p from=%d\n", */
563 /* armci_me,index,bytes,rptr,msginfo->from); */
564 /* fflush(stdout); */
565 assert(IMM_BUF_LEN+bytes < PENDING_BUF_LEN);
566 armci_pbuf_start_get(msginfo,rptr,lptr,bytes,msginfo->from,index);
567 *status = RECV_DSCR_PENDING;
568 }
569 break;
570 case RECV_DSCR_PENDING:
571 armci_die("call_data_server should set status to RECV_DSCR_DONE before calling progress",*status);
572 break;
573 case SEND_DATA_PENDING:
574 armci_die("call_data_server should set status to SEND_DATA_DONE before calling progress",*status);
575 break;
576 case RECV_DSCR_DONE:
577 /* printf("%d(s):: GET. Done recving descriptor index=%d op=%d datalen=%d from=%d\n", */
578 /* armci_me,index,msginfo->operation,msginfo->datalen,msginfo->from); */
579 /* fflush(stdout); */
580 armci_complete_pendbuf(pbuf);
581 if(msginfo->pinned) {
582 *status = SEND_DATA_DONE;
583 _armci_serv_pendbuf_freebuf(pbuf);
584 }
585 else {
586 *status = SEND_DATA_PENDING;
587 }
588 break;
589 case SEND_DATA_DONE:
590 _armci_serv_pendbuf_freebuf(pbuf);
591 break;
592 case RECV_DATA_PENDING:
593 case RECV_DATA_DONE:
594 default:
595 armci_die("pendbuf_progress_get: invalid status", *status);
596 }
597 }
598
599 /** Progress PUT/ACC requests.
600 * @param pbuf IN Pending buffer containing the PUT/ACC request
601 * @return none
602 */
603 static void _armci_serv_pendbuf_progress_putacc(pendbuf_t *pbuf) {
604 int index = (pbuf - serv_pendbuf_arr);
605 request_header_t *msginfo = (request_header_t *)pbuf->buf;
606 void *buffer =((char *)(msginfo+1))+msginfo->dscrlen;
607 int *status = &pbuf->status;
608
609 assert(msginfo->operation==PUT || ARMCI_ACC(msginfo->operation));
610 assert(sizeof(request_header_t)+msginfo->dscrlen+msginfo->datalen<PENDING_BUF_LEN);
611 switch(*status) {
612 case INIT:
613 /* printf("%d(s): progressing new msg. index=%d op=%d from=%d\n", armci_me,index,msginfo->operation,msginfo->from); */
614 /* fflush(stdout); */
615 if(sizeof(request_header_t)+msginfo->dscrlen <= IMM_BUF_LEN) {
616 /*Have the header and descriptor; go process*/
617 assert(sizeof(request_header_t)+msginfo->dscrlen+msginfo->tag.data_len < PENDING_BUF_LEN);
618 armci_pbuf_start_get(msginfo,msginfo->tag.data_ptr,buffer,msginfo->tag.data_len,
619 msginfo->from, index);
620 /* printf("%d(s): PUT/ACC getting data. pbuf_num=%d data_ptr=%p data_len=%d bytes=%d\n", armci_me,index,msginfo->tag.data_ptr, msginfo->tag.data_len,msginfo->bytes); */
621 *status = RECV_DATA_PENDING;
622 }
623 else { /*Need to get rest of descriptor*/
624 const int bytes = sizeof(request_header_t)+msginfo->dscrlen-IMM_BUF_LEN;
625 #warning "PEND_BUFS: Abusing msginfo->tag.ack_ptr for GETS with large descriptors!"
626 assert(msginfo->tag.ack_ptr != NULL); /*sanity check. Should point to tag.ack on the client side*/
627 void *lptr = ((char *)msginfo)+IMM_BUF_LEN;
628 void *rptr = ((char *)msginfo->tag.ack_ptr) - (int)(&((request_header_t *)0)->tag.ack) + IMM_BUF_LEN;
629 /* printf("%d(s):: PUT getting rest of descriptor index=%d bytes=%d ptr=%p from=%d\n", */
630 /* armci_me,index,bytes,rptr,msginfo->from); */
631 /* fflush(stdout); */
632 assert(IMM_BUF_LEN+bytes < PENDING_BUF_LEN);
633 armci_pbuf_start_get(msginfo,rptr,lptr,bytes,msginfo->from,index);
634 *status = RECV_DSCR_PENDING;
635 }
636 break;
637 case RECV_DSCR_PENDING:
638 armci_die("call_data_server should set status to RECV_DSCR_DONE before calling progress",*status);
639 break;
640 case RECV_DATA_PENDING:
641 armci_die("call_data_server should set status to RECV_DONE before calling progress",*status);
642 break;
643 case RECV_DSCR_DONE:
644 assert(sizeof(request_header_t)+msginfo->dscrlen+msginfo->tag.data_len < PENDING_BUF_LEN);
645 armci_pbuf_start_get(msginfo,msginfo->tag.data_ptr,buffer,msginfo->tag.data_len,
646 msginfo->from, index);
647 /* printf("%d(s): PUT/ACC getting data. pbuf_num=%d data_ptr=%p data_len=%d bytes=%d\n", armci_me,index,msginfo->tag.data_ptr, msginfo->tag.data_len,msginfo->bytes); */
648 *status = RECV_DATA_PENDING;
649 break;
650 case RECV_DATA_DONE:
651 /* printf("%d(s):: Done PUT/ACC with buf index=%d op=%d datalen=%d from=%d\n", */
652 /* armci_me,index,msginfo->operation,msginfo->datalen,msginfo->from); */
653 /* fflush(stdout); */
654 if(msginfo->operation == PUT && pbuf->order_prev!=NULL) {
655 assert(pbuf->commit_me == 0); /*Why called so many times in thie
656 state?*/
657 pbuf->commit_me = 1;
658 break;
659 }
660 pbuf->commit_me = 0;
661 armci_complete_pendbuf(pbuf);
662 _armci_serv_pendbuf_freebuf(pbuf);
663 break;
664 case SEND_DATA_PENDING:
665 case SEND_DATA_DONE:
666 default:
667 armci_die("pendbuf_progress_putacc: invalid status", *status);
668 }
669 }
670
671
672 /** Make progress on processing a pending buffer. This function, also
673 * ensures any other waiting messages get processed if they can
674 * be. Thus, progress and eventual termination is guaranteed by this
675 * function.
676 * @param _pbuf IN Pending buffer to make progress on
677 * @return none
678 */
679 static void _armci_serv_pendbuf_progress(pendbuf_t *_pbuf){
680 request_header_t *msginfo = (request_header_t *)_pbuf->buf;
681 immbuf_t *vbuf = _pbuf->vbuf;
682 pendbuf_t *pbuf = _pbuf;
683
684 assert(pbuf->vbuf!=NULL);
685 do {
686 if(vbuf && !IS_IMM_MSG(*msginfo)) { assert(pbuf->vbuf == vbuf); }
687 /* printf("%d(s):: progressing op=%d imm=%d from=%d datalen=%d pbuf=%p vbuf=%p n_pending=%d\n", armci_me, */
688 /* msginfo->operation,msginfo->tag.imm_msg,msginfo->from,msginfo->datalen, pbuf,vbuf,pbuf_proc_list_info[msginfo->from].n_pending); */
689 /* fflush(stdout); */
690 if(IS_IMM_MSG(*msginfo)) {
691 armci_complete_immbuf(vbuf);
692 }
693 else { /*non-immediate message*/
694 proc_waitlist_t* info = &pbuf_proc_list_info[msginfo->from];
695
696 do {
697 assert(pbuf->vbuf == vbuf);
698 if(msginfo->operation == PUT || ARMCI_ACC(msginfo->operation)) {
699 _armci_serv_pendbuf_progress_putacc(pbuf);
700 }
701 else if (msginfo->operation == GET) {
702 _armci_serv_pendbuf_progress_get(pbuf);
703 }
704 else {
705 armci_die("pending buffer processing for this op not yet implemented", msginfo->operation);
706 }
707 pbuf = info->order_head;
708 vbuf = pbuf ? pbuf->vbuf : NULL;
709 } while(info->order_head && info->order_head->commit_me);
710 }
711 /* sleep(2); */
712 vbuf = _armci_serv_pendbuf_promote();
713 if(vbuf) {
714 msginfo = (request_header_t *)vbuf->buf;
715 if(!msginfo->tag.imm_msg) {
716 pbuf = _armci_serv_pendbuf_assignbuf(vbuf);
717 assert(pbuf != NULL);
718 }
719 }
720 } while(vbuf != NULL);
721 }
722
723
724
725 /*----------------External functions--------------------*/
726
727
728 /** Initialize array of pending buffers
729 * @return none
730 */
731 void armci_pendbuf_init() {
732 int i;
733
734 ARMCI_PR_DBG("enter",0);
735
736 /* bzero(serv_pendbuf_arr, sizeof(pendbuf_t)*PENDING_BUF_NUM); */
737 for(i=0; i<PENDING_BUF_NUM; i++) {
738 pendbuf_t *pbuf = &serv_pendbuf_arr[i];
739 char *buf = pbuf->buf;
740 bzero(pbuf, sizeof(pendbuf_t));
741 pbuf->buf = buf;
742 pbuf->avail=1;
743 }
744
745 pbuf_ordering_plist_head=NULL;
746 pbuf_proc_list_info = (proc_waitlist_t *)malloc(sizeof(proc_waitlist_t)*armci_nproc);
747 assert(pbuf_proc_list_info != NULL);
748 bzero(pbuf_proc_list_info, sizeof(proc_waitlist_t)*armci_nproc);
749 ARMCI_PR_DBG("exit",0);
750 }
751
752 void armci_pendbuf_service_req(immbuf_t *immbuf) {
753 pendbuf_t *pbuf;
754 request_header_t *msginfo=(request_header_t*)immbuf->buf;
755
756 if(IS_IMM_MSG(*msginfo) && _armci_serv_pendbuf_can_progress(immbuf)) {
757 /* printf("%d: msg vbuf=%p op=%d from=%d imm=%d datalen=%d bytes=%d data_ptr=%p can progress. Completing it now!\n", */
758 /* armci_me, vbuf, msginfo->operation, msginfo->from, msginfo->tag.imm_msg,msginfo->datalen,msginfo->bytes,msginfo->tag.data_ptr); */
759 /* fflush(stdout); */
760 armci_complete_immbuf(immbuf);
761 }
762 else if((pbuf = _armci_serv_pendbuf_enqueue(immbuf))) {
763 /* printf("%d: msg vbuf=%p op=%d from=%d imm=%d datalen=%d bytes=%d data_ptr=%p got pending buf. Progressing it!\n", */
764 /* armci_me, vbuf, msginfo->operation, msginfo->from, msginfo->tag.imm_msg,msginfo->datalen,msginfo->bytes,msginfo->tag.data_ptr); */
765 /* fflush(stdout); */
766 _armci_serv_pendbuf_progress(pbuf);
767 }
768 else {
769 /* printf("%d: msg vbuf=%p op=%d from=%d imm=%d datalen=%d bytes=%d data_ptr=%p in waitlist!\n", armci_me, vbuf, msginfo->operation, msginfo->from, msginfo->tag.imm_msg,msginfo->datalen,msginfo->bytes,msginfo->tag.data_ptr); */
770 /* fflush(stdout); */
771 }
772 }
773
774 /**Network layer reporting to split buffers code that a put completed
775 * on a pending buffer.
776 * @param pbufid IN Pending buffer id (specified when starting a
777 * put).
778 * @return void
779 */
780 void armci_pendbuf_done_put(int pbufid) {
781 assert(pbufid>=0 && pbufid<PENDING_BUF_NUM);
782 assert(serv_pendbuf_arr[pbufid].status == SEND_DATA_PENDING);
783 serv_pendbuf_arr[pbufid].status = SEND_DATA_DONE;
784 _armci_serv_pendbuf_progress(&serv_pendbuf_arr[pbufid]);
785 }
786
787 /**Network layer reporting to split buffers code that a get completed
788 * on a pending buffer.
789 * @param pbufid IN Pending buffer id (specified when starting a
790 * get).
791 * @return void
792 */
793 void armci_pendbuf_done_get(int pbufid) {
794 pendbuf_t *pbuf;
795 assert(pbufid>=0 && pbufid<PENDING_BUF_NUM);
796 pbuf = &serv_pendbuf_arr[pbufid];
797
798 switch(pbuf->status) {
799 case RECV_DSCR_PENDING:
800 pbuf->status = RECV_DSCR_DONE;
801 break;
802 case RECV_DATA_PENDING:
803 pbuf->status = RECV_DATA_DONE;
804 break;
805 default:
806 armci_die("Reporting get done on buf with inappropriate status",pbufid);
807 }
808 _armci_serv_pendbuf_progress(pbuf);
809 }
810
811
812 #endif /*PEND_BUFS*/
813