| 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 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
static int att_ops(int attid, int gs, int v) { |
| 42 |
static not_first[NUM_ATTRIBUTES]; |
| 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 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
typedef struct proc_waitlist_t { |
| 93 |
struct proc_waitlist_t *prev; |
| 94 |
|
| 95 |
struct proc_waitlist_t *next; |
| 96 |
|
| 97 |
immbuf_t *immbuf_wlist_head; |
| 98 |
immbuf_t *immbuf_wlist_tail; |
| 99 |
pendbuf_t *order_head,*order_tail; |
| 100 |
|
| 101 |
|
| 102 |
int n_pending; |
| 103 |
} proc_waitlist_t; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static int _nPendBufsUsed=0; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
static enum PendBufOrderingRule _pbufOrder = GET_GET_REORDER; |
| 114 |
|
| 115 |
pendbuf_t *serv_pendbuf_arr; |
| 116 |
|
| 117 |
static proc_waitlist_t *pbuf_ordering_plist_head; |
| 118 |
|
| 119 |
static proc_waitlist_t *pbuf_proc_list_info; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
enum PendBufStatus { |
| 128 |
RECV_DATA_DONE=4, |
| 129 |
SEND_DATA_DONE=5, |
| 130 |
RECV_DSCR_DONE=6, |
| 131 |
|
| 132 |
INIT=7, |
| 133 |
RECV_DATA_PENDING=0, |
| 134 |
SEND_DATA_PENDING=1, |
| 135 |
RECV_DSCR_PENDING=2 |
| 136 |
}; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 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 |
|
| 155 |
|
| 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 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 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 |
|
| 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 |
|
| 192 |
|
| 193 |
|
| 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 |
|
| 204 |
|
| 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; |
| 218 |
|
| 219 |
_nPendBufsUsed -= 1; |
| 220 |
assert(_nPendBufsUsed>=0); |
| 221 |
ARMCI_PR_DBG("exit",0); |
| 222 |
} |
| 223 |
|
| 224 |
#if 0 |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 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 |
|
| 240 |
|
| 241 |
return 0; |
| 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 |
|
| 248 |
|
| 249 |
return 0; |
| 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; |
| 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 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 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 |
|
| 306 |
if(_nPendBufsUsed>0) |
| 307 |
return 0; |
| 308 |
return 1; |
| 309 |
} |
| 310 |
if(_pbufOrder == ONE_PBUF_MESG_PER_PROC) { |
| 311 |
|
| 312 |
|
| 313 |
if(info->order_head |
| 314 |
|| (info->immbuf_wlist_head && info->immbuf_wlist_head!=vbuf)) { |
| 315 |
return 0; |
| 316 |
} |
| 317 |
if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) { |
| 318 |
return 0; |
| 319 |
} |
| 320 |
assert(info->n_pending == 0 || info->immbuf_wlist_head==vbuf); |
| 321 |
return 1; |
| 322 |
} |
| 323 |
if(_pbufOrder == ACC_NO_ORDER) { |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
int i, nwaiting_on, nacc; |
| 330 |
pendbuf_t *ptr; |
| 331 |
if(!IS_IMM_MSG(*msginfo) && _nPendBufsUsed==PENDING_BUF_NUM) { |
| 332 |
|
| 333 |
|
| 334 |
return 0; |
| 335 |
} |
| 336 |
#if 1 |
| 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 |
|
| 343 |
|
| 344 |
return 0; |
| 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; |
| 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; |
| 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 |
|
| 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 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 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; |
| 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 |
|
| 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 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 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 |
|
| 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); |
| 494 |
} |
| 495 |
if(pbuf == NULL) { |
| 496 |
|
| 497 |
|
| 498 |
vbuf->immbuf_list_next = NULL; |
| 499 |
assert(info->n_pending < IMM_BUF_NUM); |
| 500 |
for(ibuf=info->immbuf_wlist_head;ibuf!=NULL;ibuf=ibuf->immbuf_list_next) { |
| 501 |
assert(vbuf != ibuf); |
| 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 |
|
| 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 |
|
| 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 |
|
| 528 |
ARMCI_PR_DBG("exit",0); |
| 529 |
return pbuf; |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 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 |
|
| 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 { |
| 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); |
| 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 |
|
| 563 |
|
| 564 |
|
| 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 |
|
| 578 |
|
| 579 |
|
| 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 |
|
| 600 |
|
| 601 |
|
| 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 |
|
| 614 |
|
| 615 |
if(sizeof(request_header_t)+msginfo->dscrlen <= IMM_BUF_LEN) { |
| 616 |
|
| 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 |
|
| 621 |
*status = RECV_DATA_PENDING; |
| 622 |
} |
| 623 |
else { |
| 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); |
| 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 |
|
| 630 |
|
| 631 |
|
| 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 |
|
| 648 |
*status = RECV_DATA_PENDING; |
| 649 |
break; |
| 650 |
case RECV_DATA_DONE: |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
if(msginfo->operation == PUT && pbuf->order_prev!=NULL) { |
| 655 |
assert(pbuf->commit_me == 0); |
| 656 |
|
| 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 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 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 |
|
| 688 |
|
| 689 |
|
| 690 |
if(IS_IMM_MSG(*msginfo)) { |
| 691 |
armci_complete_immbuf(vbuf); |
| 692 |
} |
| 693 |
else { |
| 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 |
|
| 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 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
void armci_pendbuf_init() { |
| 732 |
int i; |
| 733 |
|
| 734 |
ARMCI_PR_DBG("enter",0); |
| 735 |
|
| 736 |
|
| 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 |
|
| 758 |
|
| 759 |
|
| 760 |
armci_complete_immbuf(immbuf); |
| 761 |
} |
| 762 |
else if((pbuf = _armci_serv_pendbuf_enqueue(immbuf))) { |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
_armci_serv_pendbuf_progress(pbuf); |
| 767 |
} |
| 768 |
else { |
| 769 |
|
| 770 |
|
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 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 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 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 |
| 813 |
|