| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include <sys/types.h> |
| 36 |
#include <sys/mman.h> |
| 37 |
#include <fcntl.h> |
| 38 |
#include <signal.h> |
| 39 |
|
| 40 |
#include "psm_user.h" |
| 41 |
#include "psm_mq_internal.h" |
| 42 |
#include "psm_am_internal.h" |
| 43 |
#include "kcopyrw.h" |
| 44 |
#include "knemrw.h" |
| 45 |
#include "scifrw.h" |
| 46 |
|
| 47 |
struct psm_am_max_sizes { |
| 48 |
uint32_t nargs; |
| 49 |
uint32_t request_short; |
| 50 |
uint32_t reply_short; |
| 51 |
uint32_t request_long; |
| 52 |
uint32_t reply_long; |
| 53 |
}; |
| 54 |
|
| 55 |
int psmi_shm_mq_rv_thresh = PSMI_MQ_RV_THRESH_NO_KASSIST; |
| 56 |
|
| 57 |
#ifdef PSM_HAVE_SCIF |
| 58 |
#define PSM_SCIF_CONNECT_RETRIES_DEFAULT 40 |
| 59 |
int psmi_scif_connect_retries = PSM_SCIF_CONNECT_RETRIES_DEFAULT; |
| 60 |
#endif |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
#define AMSH_BULK_PUSH 1 |
| 66 |
|
| 67 |
|
| 68 |
#define AMSH_HUGE_BYTES 1024*1024 |
| 69 |
|
| 70 |
#define AMMED_SZ 2048 |
| 71 |
#define AMLONG_SZ 8192 |
| 72 |
#define AMHUGE_SZ (524288+sizeof(am_pkt_bulk_t)) |
| 73 |
|
| 74 |
|
| 75 |
static const amsh_qinfo_t amsh_qcounts = |
| 76 |
{ 1024, 256, 16, 1, 1024, 256, 16, 8 }; |
| 77 |
|
| 78 |
|
| 79 |
static const amsh_qinfo_t amsh_qelemsz = |
| 80 |
{ sizeof(am_pkt_short_t), AMMED_SZ+64, AMLONG_SZ, AMHUGE_SZ, |
| 81 |
sizeof(am_pkt_short_t), AMMED_SZ+64, AMLONG_SZ, AMHUGE_SZ }; |
| 82 |
|
| 83 |
|
| 84 |
static const amsh_qinfo_t amsh_qpkt_max = |
| 85 |
{ NSHORT_ARGS*8, AMMED_SZ, AMLONG_SZ-sizeof(am_pkt_bulk_t), |
| 86 |
AMHUGE_SZ-sizeof(am_pkt_bulk_t), |
| 87 |
NSHORT_ARGS*8, AMMED_SZ, AMLONG_SZ-sizeof(am_pkt_bulk_t), |
| 88 |
AMHUGE_SZ-sizeof(am_pkt_bulk_t), |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
static const struct psm_am_max_sizes psmi_am_max_sizes = |
| 93 |
{ 6, AMMED_SZ, (uint32_t) -1, |
| 94 |
AMMED_SZ, (uint32_t) -1 }; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
#define QGETPTR(ptl, _shmidx_, _fifo, _fifotyp, _idx) \ |
| 105 |
(am_pkt_ ## _fifotyp ## _t *) \ |
| 106 |
(((uintptr_t)ptl->ep->amsh_qdir[(_shmidx_)].q ## _fifo) + \ |
| 107 |
(_idx) *amsh_qelemsz.q ## _fifo) |
| 108 |
|
| 109 |
#define QGETPTR_SCIF(ptl, _shmidx_, _node_, _fifo, _fifotyp, _idx) \ |
| 110 |
(am_pkt_ ## _fifotyp ## _t *) \ |
| 111 |
(((uintptr_t)ptl->ep->amsh_qdir[(_shmidx_)].qptrs[_node_].q ## _fifo) +\ |
| 112 |
(_idx) *amsh_qelemsz.q ## _fifo) |
| 113 |
|
| 114 |
#ifdef PSM_HAVE_SCIF |
| 115 |
static void *am_ctl_accept_thread(void *arg); |
| 116 |
static psm_error_t amsh_scif_detach(psm_ep_t ep); |
| 117 |
#endif |
| 118 |
static psm_error_t amsh_poll(ptl_t *ptl, int replyonly); |
| 119 |
static psm_error_t amsh_poll_internal_inner(ptl_t *ptl, int replyonly, int is_internal); |
| 120 |
static void process_packet(ptl_t *ptl, am_pkt_short_t *pkt, int isreq); |
| 121 |
static void amsh_conn_handler(void *toki, psm_amarg_t *args, int narg, |
| 122 |
void *buf, size_t len); |
| 123 |
static void am_update_directory(ptl_t *ptl, int shmidx); |
| 124 |
|
| 125 |
|
| 126 |
static const char * psmi_kassist_getmode(int mode); |
| 127 |
static int psmi_get_kassist_mode(); |
| 128 |
|
| 129 |
|
| 130 |
#ifdef PSM_HAVE_SCIF |
| 131 |
static const char * psmi_scif_dma_getmode(int mode); |
| 132 |
static int psmi_get_scif_dma_mode(); |
| 133 |
static int psmi_get_scif_dma_threshold(); |
| 134 |
#endif |
| 135 |
|
| 136 |
|
| 137 |
int psmi_epaddr_kcopy_pid(psm_epaddr_t epaddr); |
| 138 |
static int psmi_kcopy_find_minor(int *minor); |
| 139 |
static int psmi_kcopy_open_minor(int minor); |
| 140 |
|
| 141 |
static inline void |
| 142 |
am_ctl_qhdr_init(volatile am_ctl_qhdr_t *q, int elem_cnt, int elem_sz) |
| 143 |
{ |
| 144 |
q->head = 0; |
| 145 |
q->elem_cnt = elem_cnt; |
| 146 |
q->elem_sz = elem_sz; |
| 147 |
} |
| 148 |
|
| 149 |
static void |
| 150 |
am_ctl_bulkpkt_init(am_pkt_bulk_t *base_ptr, size_t elemsz, int nelems) |
| 151 |
{ |
| 152 |
int i; |
| 153 |
am_pkt_bulk_t *bulkpkt; |
| 154 |
uintptr_t bulkptr = (uintptr_t) base_ptr; |
| 155 |
|
| 156 |
for (i = 0; i < nelems; i++, bulkptr += elemsz) { |
| 157 |
bulkpkt = (am_pkt_bulk_t *) bulkptr; |
| 158 |
bulkpkt->idx = i; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
#define _PA(type) PSMI_ALIGNUP(amsh_qcounts.q ## type * amsh_qelemsz.q ## type, \ |
| 163 |
PSMI_PAGESIZE) |
| 164 |
static inline uintptr_t |
| 165 |
am_ctl_sizeof_block() |
| 166 |
{ |
| 167 |
return |
| 168 |
PSMI_ALIGNUP( |
| 169 |
PSMI_ALIGNUP(AMSH_BLOCK_HEADER_SIZE, PSMI_PAGESIZE) + |
| 170 |
PSMI_ALIGNUP(sizeof(am_ctl_blockhdr_t), PSMI_PAGESIZE) + |
| 171 |
_PA(reqFifoShort) + _PA(reqFifoMed) + _PA(reqFifoLong) + |
| 172 |
_PA(reqFifoHuge) + |
| 173 |
PSMI_ALIGNUP(sizeof(am_ctl_blockhdr_t), PSMI_PAGESIZE) + |
| 174 |
_PA(repFifoShort) + _PA(repFifoMed) + _PA(repFifoLong) + |
| 175 |
_PA(repFifoHuge), |
| 176 |
PSMI_PAGESIZE); |
| 177 |
} |
| 178 |
#undef _PA |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
static |
| 184 |
size_t |
| 185 |
psmi_amsh_segsize(int num_pe, int num_nodes) |
| 186 |
{ |
| 187 |
size_t segsz; |
| 188 |
segsz = PSMI_ALIGNUP(sizeof(struct am_ctl_dirpage), PSMI_PAGESIZE); |
| 189 |
segsz += am_ctl_sizeof_block() * num_pe * num_nodes; |
| 190 |
return segsz; |
| 191 |
} |
| 192 |
|
| 193 |
static |
| 194 |
void |
| 195 |
amsh_atexit() |
| 196 |
{ |
| 197 |
static pthread_mutex_t mutex_once = PTHREAD_MUTEX_INITIALIZER; |
| 198 |
static int atexit_once = 0; |
| 199 |
psm_ep_t ep; |
| 200 |
extern psm_ep_t psmi_opened_endpoint; |
| 201 |
|
| 202 |
pthread_mutex_lock(&mutex_once); |
| 203 |
if (atexit_once) { |
| 204 |
pthread_mutex_unlock(&mutex_once); |
| 205 |
return; |
| 206 |
} |
| 207 |
else |
| 208 |
atexit_once = 1; |
| 209 |
pthread_mutex_unlock(&mutex_once); |
| 210 |
|
| 211 |
ep = psmi_opened_endpoint; |
| 212 |
while (ep) { |
| 213 |
if (ep->amsh_keyname != NULL) { |
| 214 |
_IPATH_VDBG("unlinking shm file %s\n", ep->amsh_keyname); |
| 215 |
shm_unlink(ep->amsh_keyname); |
| 216 |
} |
| 217 |
|
| 218 |
if (ep->psmi_kassist_fd != -1) { |
| 219 |
close(ep->psmi_kassist_fd); |
| 220 |
ep->psmi_kassist_fd = -1; |
| 221 |
} |
| 222 |
ep = ep->user_ep_next; |
| 223 |
} |
| 224 |
|
| 225 |
return; |
| 226 |
} |
| 227 |
|
| 228 |
static |
| 229 |
void |
| 230 |
amsh_mmap_fault(int sig) |
| 231 |
{ |
| 232 |
static char shm_errmsg[256]; |
| 233 |
|
| 234 |
snprintf(shm_errmsg, sizeof shm_errmsg, |
| 235 |
"%s: Unable to allocate shared memory for intra-node messaging.\n" |
| 236 |
"%s: Delete stale shared memory files in /dev/shm.\n", |
| 237 |
psmi_gethostname(), psmi_gethostname()); |
| 238 |
amsh_atexit(); |
| 239 |
if (write(2, shm_errmsg, strlen(shm_errmsg)+1) == -1) |
| 240 |
exit(2); |
| 241 |
else |
| 242 |
exit(1); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
#ifdef PSM_HAVE_SCIF |
| 249 |
static |
| 250 |
psm_error_t |
| 251 |
amsh_scif_init(psm_ep_t ep) |
| 252 |
{ |
| 253 |
scif_epd_t epd; |
| 254 |
int port, nnodes; |
| 255 |
uint16_t self; |
| 256 |
psm_error_t err; |
| 257 |
union psmi_envvar_val env_retries; |
| 258 |
|
| 259 |
if(!psmi_getenv("PSM_SCIF_CONNECT_RETRIES", |
| 260 |
"PSM SCIF connection retry count", |
| 261 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_UINT, |
| 262 |
(union psmi_envvar_val) psmi_scif_connect_retries, |
| 263 |
&env_retries)) { |
| 264 |
psmi_scif_connect_retries = env_retries.e_uint; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
if ((epd = scif_open()) < 0) { |
| 269 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 270 |
"scif_open() failed with err %d", errno); |
| 271 |
return err; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
if ((port = scif_bind(epd, 0)) < 0) { |
| 276 |
scif_close(epd); |
| 277 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 278 |
"scif_bind() failed with err %d", errno); |
| 279 |
return err; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
if (scif_listen(epd, 40) != 0) { |
| 285 |
scif_close(epd); |
| 286 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 287 |
"scif_listen() failed with err %d", errno); |
| 288 |
return err; |
| 289 |
} |
| 290 |
|
| 291 |
if ((nnodes = scif_get_nodeIDs(NULL, 0, &self)) < 0) { |
| 292 |
scif_close(epd); |
| 293 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 294 |
"scif_get_nodeIDs() failed with err %d", errno); |
| 295 |
return err; |
| 296 |
} |
| 297 |
|
| 298 |
_IPATH_VDBG("listening on SCIF %d:%d\n", self, port); |
| 299 |
|
| 300 |
|
| 301 |
ep->scif_epd = epd; |
| 302 |
ep->scif_mynodeid = (int)self; |
| 303 |
ep->scif_nnodes = nnodes; |
| 304 |
|
| 305 |
|
| 306 |
ep->epid |= (((uint64_t)self)&0xFF)<<48; |
| 307 |
ep->epid |= (((uint64_t)port)&0xFFFF)<<32; |
| 308 |
|
| 309 |
return PSM_OK; |
| 310 |
} |
| 311 |
#endif |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
psm_error_t |
| 319 |
psmi_shm_attach(psm_ep_t ep, int *shmidx_o) |
| 320 |
{ |
| 321 |
int ismaster = 1; |
| 322 |
int i; |
| 323 |
int use_kcopy, use_kassist; |
| 324 |
int shmidx; |
| 325 |
int kcopy_minor = -1; |
| 326 |
char shmbuf[256]; |
| 327 |
void *mapptr; |
| 328 |
size_t segsz; |
| 329 |
psm_error_t err = PSM_OK; |
| 330 |
|
| 331 |
if (ep->amsh_shmidx != -1) { |
| 332 |
*shmidx_o = ep->amsh_shmidx; |
| 333 |
return PSM_OK; |
| 334 |
} |
| 335 |
|
| 336 |
*shmidx_o = -1; |
| 337 |
if (ep->amsh_keyname != NULL) { |
| 338 |
if (psmi_uuid_compare(ep->amsh_keyno, ep->key) != 0) { |
| 339 |
psmi_uuid_unparse(ep->amsh_keyno, shmbuf); |
| 340 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 341 |
"Shared memory segment already initialized with key=%s", |
| 342 |
shmbuf); |
| 343 |
goto fail; |
| 344 |
} |
| 345 |
} |
| 346 |
else { |
| 347 |
char *p; |
| 348 |
memcpy(&ep->amsh_keyno, ep->key, sizeof(psm_uuid_t)); |
| 349 |
strncpy(shmbuf, "/psm_shm.", sizeof shmbuf); |
| 350 |
p = shmbuf + strlen(shmbuf); |
| 351 |
psmi_uuid_unparse(ep->amsh_keyno, p); |
| 352 |
ep->amsh_keyname = psmi_strdup(NULL, shmbuf); |
| 353 |
if (ep->amsh_keyname == NULL) { |
| 354 |
err = PSM_NO_MEMORY; |
| 355 |
goto fail; |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
#ifdef PSM_HAVE_SCIF |
| 360 |
ep->amsh_qdir = psmi_calloc(NULL, PER_PEER_ENDPOINT, |
| 361 |
PTL_AMSH_MAX_LOCAL_PROCS*ep->scif_nnodes, |
| 362 |
sizeof(struct amsh_qdirectory)); |
| 363 |
#else |
| 364 |
ep->amsh_qdir = psmi_calloc(NULL, PER_PEER_ENDPOINT, |
| 365 |
PTL_AMSH_MAX_LOCAL_PROCS, |
| 366 |
sizeof(struct amsh_qdirectory)); |
| 367 |
#endif |
| 368 |
|
| 369 |
if (ep->amsh_qdir == NULL) { |
| 370 |
err = PSM_NO_MEMORY; |
| 371 |
goto fail; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
ep->psmi_kassist_mode = psmi_get_kassist_mode(); |
| 376 |
use_kassist = (ep->psmi_kassist_mode != PSMI_KASSIST_OFF); |
| 377 |
use_kcopy = (ep->psmi_kassist_mode & PSMI_KASSIST_KCOPY); |
| 378 |
|
| 379 |
#ifdef PSM_HAVE_SCIF |
| 380 |
ep->scif_dma_mode = psmi_get_scif_dma_mode(); |
| 381 |
ep->scif_dma_threshold = psmi_get_scif_dma_threshold(); |
| 382 |
#endif |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
#ifdef PSM_HAVE_SCIF |
| 393 |
segsz = psmi_amsh_segsize(PTL_AMSH_MAX_LOCAL_PROCS, |
| 394 |
PTL_AMSH_MAX_LOCAL_NODES); |
| 395 |
#else |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
int nranks, rankid, nprocs; |
| 402 |
psmi_sharedcontext_params(&nranks, &rankid); |
| 403 |
nprocs = (nranks <= 0) ? sysconf(_SC_NPROCESSORS_ONLN) : nranks; |
| 404 |
segsz = psmi_amsh_segsize(nprocs, PTL_AMSH_MAX_LOCAL_NODES); |
| 405 |
#endif |
| 406 |
|
| 407 |
ep->amsh_shmfd = shm_open(ep->amsh_keyname, |
| 408 |
O_RDWR | O_CREAT | O_EXCL | O_TRUNC, S_IRWXU); |
| 409 |
if (ep->amsh_shmfd < 0) { |
| 410 |
ismaster = 0; |
| 411 |
if (errno != EEXIST) { |
| 412 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 413 |
"Error creating shared memory object in shm_open%s%s", |
| 414 |
errno != EACCES ? ": " : |
| 415 |
"(/dev/shm may have stale shm files that need to be removed): ", |
| 416 |
strerror(errno)); |
| 417 |
goto fail; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
ep->amsh_shmfd = shm_open(ep->amsh_keyname, O_RDWR, S_IRWXU); |
| 422 |
if (ep->amsh_shmfd < 0) { |
| 423 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 424 |
"Error attaching to shared memory object in shm_open: %s", |
| 425 |
strerror(errno)); |
| 426 |
goto fail; |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
atexit(amsh_atexit); |
| 432 |
|
| 433 |
_IPATH_PRDBG("Registered as %s to key %s\n", ismaster ? "master" : "slave", |
| 434 |
ep->amsh_keyname); |
| 435 |
|
| 436 |
if (ismaster) { |
| 437 |
if (ftruncate(ep->amsh_shmfd, segsz) != 0) { |
| 438 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 439 |
"Error setting size of shared memory object to %u bytes in " |
| 440 |
"ftruncate: %s\n", (uint32_t) segsz, strerror(errno)); |
| 441 |
goto fail; |
| 442 |
} |
| 443 |
} |
| 444 |
else { |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
struct stat fdstat; |
| 449 |
off_t cursize = 0; |
| 450 |
while (cursize == 0) { |
| 451 |
if (fstat(ep->amsh_shmfd, &fdstat)) { |
| 452 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 453 |
"Error querying size of shared memory object: %s", |
| 454 |
strerror(errno)); |
| 455 |
goto fail; |
| 456 |
} |
| 457 |
cursize = fdstat.st_size; |
| 458 |
if (cursize == 0) |
| 459 |
usleep(1); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
mapptr = mmap(NULL, segsz, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 469 |
ep->amsh_shmfd, 0); |
| 470 |
if (mapptr == MAP_FAILED) { |
| 471 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 472 |
"Error mmapping shared memory: %s", strerror(errno)); |
| 473 |
goto fail; |
| 474 |
} |
| 475 |
|
| 476 |
ep->amsh_shmbase = (uintptr_t) mapptr; |
| 477 |
ep->amsh_dirpage = (struct am_ctl_dirpage *) ep->amsh_shmbase; |
| 478 |
ep->amsh_blockbase = ep->amsh_shmbase + psmi_amsh_segsize(0, 0); |
| 479 |
|
| 480 |
|
| 481 |
void (*old_handler_segv)(int) = signal (SIGSEGV, amsh_mmap_fault); |
| 482 |
void (*old_handler_bus)(int) = signal (SIGBUS, amsh_mmap_fault); |
| 483 |
|
| 484 |
_IPATH_PRDBG("Mapped shm control object at %p\n", mapptr); |
| 485 |
if (ismaster) { |
| 486 |
pthread_mutexattr_t attr; |
| 487 |
pthread_mutexattr_init(&attr); |
| 488 |
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); |
| 489 |
pthread_mutex_init(&(ep->amsh_dirpage->lock), &attr); |
| 490 |
pthread_mutexattr_destroy(&attr); |
| 491 |
|
| 492 |
ep->amsh_dirpage->num_attached = 0; |
| 493 |
ep->amsh_dirpage->max_idx = -1; |
| 494 |
|
| 495 |
for (i = 0; i < PTL_AMSH_MAX_LOCAL_PROCS; i++) { |
| 496 |
ep->amsh_dirpage->shmidx_map_epid[i] = 0; |
| 497 |
ep->amsh_dirpage->kassist_pids[i] = 0; |
| 498 |
} |
| 499 |
|
| 500 |
for(i = 0; i < PTL_AMSH_MAX_LOCAL_PROCS*PTL_AMSH_MAX_LOCAL_NODES; i++) { |
| 501 |
struct amsh_qtail* qtail = &ep->amsh_dirpage->qtails[i]; |
| 502 |
|
| 503 |
qtail->reqFifoShort.tail = 0; |
| 504 |
qtail->reqFifoMed.tail = 0; |
| 505 |
qtail->reqFifoLong.tail = 0; |
| 506 |
qtail->reqFifoHuge.tail = 0; |
| 507 |
|
| 508 |
qtail->repFifoShort.tail = 0; |
| 509 |
qtail->repFifoMed.tail = 0; |
| 510 |
qtail->repFifoLong.tail = 0; |
| 511 |
qtail->repFifoHuge.tail = 0; |
| 512 |
|
| 513 |
pthread_spin_init(&qtail->reqFifoShort.lock, PTHREAD_PROCESS_SHARED); |
| 514 |
pthread_spin_init(&qtail->reqFifoMed.lock, PTHREAD_PROCESS_SHARED); |
| 515 |
pthread_spin_init(&qtail->reqFifoLong.lock, PTHREAD_PROCESS_SHARED); |
| 516 |
pthread_spin_init(&qtail->reqFifoHuge.lock, PTHREAD_PROCESS_SHARED); |
| 517 |
|
| 518 |
pthread_spin_init(&qtail->repFifoShort.lock, PTHREAD_PROCESS_SHARED); |
| 519 |
pthread_spin_init(&qtail->repFifoMed.lock, PTHREAD_PROCESS_SHARED); |
| 520 |
pthread_spin_init(&qtail->repFifoLong.lock, PTHREAD_PROCESS_SHARED); |
| 521 |
pthread_spin_init(&qtail->repFifoHuge.lock, PTHREAD_PROCESS_SHARED); |
| 522 |
} |
| 523 |
|
| 524 |
if (use_kassist) { |
| 525 |
if (use_kcopy) { |
| 526 |
ep->psmi_kassist_fd = psmi_kcopy_find_minor(&kcopy_minor); |
| 527 |
if (ep->psmi_kassist_fd >= 0) |
| 528 |
ep->amsh_dirpage->kcopy_minor = kcopy_minor; |
| 529 |
else |
| 530 |
ep->amsh_dirpage->kcopy_minor = -1; |
| 531 |
} |
| 532 |
else { |
| 533 |
psmi_assert_always(ep->psmi_kassist_mode & PSMI_KASSIST_KNEM); |
| 534 |
ep->psmi_kassist_fd = knem_open_device(); |
| 535 |
} |
| 536 |
|
| 537 |
} |
| 538 |
else |
| 539 |
ep->psmi_kassist_fd = -1; |
| 540 |
|
| 541 |
ips_mb(); |
| 542 |
|
| 543 |
ep->amsh_dirpage->is_init = 1; |
| 544 |
_IPATH_PRDBG("Mapped and initialized shm object control page at %p," |
| 545 |
"size=%zu, kcopy minor is %d (mode=%s)\n", mapptr, |
| 546 |
segsz, kcopy_minor, |
| 547 |
psmi_kassist_getmode(ep->psmi_kassist_mode)); |
| 548 |
} |
| 549 |
else { |
| 550 |
volatile int *is_init = &ep->amsh_dirpage->is_init; |
| 551 |
while (*is_init == 0) |
| 552 |
usleep(1); |
| 553 |
_IPATH_PRDBG("Slave synchronized object control page at " |
| 554 |
"%p, size=%d, kcopy minor is %d (mode=%s)\n", |
| 555 |
mapptr, (int) segsz, kcopy_minor, |
| 556 |
psmi_kassist_getmode(ep->psmi_kassist_mode)); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
pthread_mutex_lock((pthread_mutex_t *) &(ep->amsh_dirpage->lock)); |
| 567 |
shmidx = -1; |
| 568 |
for (i = 0; i < PTL_AMSH_MAX_LOCAL_PROCS; i++) { |
| 569 |
if (ep->amsh_dirpage->shmidx_map_epid[i] == 0) { |
| 570 |
ep->amsh_dirpage->shmidx_map_epid[i] = 1; |
| 571 |
ep->amsh_dirpage->psm_verno[i] = PSMI_VERNO; |
| 572 |
ep->amsh_dirpage->kassist_pids[i] = (int) getpid(); |
| 573 |
|
| 574 |
if (use_kassist) { |
| 575 |
if (!use_kcopy) { |
| 576 |
if (!ismaster) |
| 577 |
ep->psmi_kassist_fd = knem_open_device(); |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
if (ep->psmi_kassist_fd >= 0) { |
| 584 |
ep->amsh_dirpage->amsh_features[i] |= AMSH_HAVE_KNEM; |
| 585 |
psmi_shm_mq_rv_thresh = PSMI_MQ_RV_THRESH_KNEM; |
| 586 |
} |
| 587 |
else { |
| 588 |
ep->psmi_kassist_mode = PSMI_KASSIST_OFF; |
| 589 |
use_kassist = 0; |
| 590 |
psmi_shm_mq_rv_thresh = PSMI_MQ_RV_THRESH_NO_KASSIST; |
| 591 |
} |
| 592 |
} |
| 593 |
else if(use_kcopy) { |
| 594 |
psmi_assert_always(use_kcopy); |
| 595 |
kcopy_minor = ep->amsh_dirpage->kcopy_minor; |
| 596 |
if (!ismaster && kcopy_minor >= 0) |
| 597 |
ep->psmi_kassist_fd = psmi_kcopy_open_minor(kcopy_minor); |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
if (ep->psmi_kassist_fd >= 0) { |
| 604 |
ep->amsh_dirpage->amsh_features[i] |= AMSH_HAVE_KCOPY; |
| 605 |
psmi_shm_mq_rv_thresh = PSMI_MQ_RV_THRESH_KCOPY; |
| 606 |
} |
| 607 |
else { |
| 608 |
ep->psmi_kassist_mode = PSMI_KASSIST_OFF; |
| 609 |
use_kassist = 0; use_kcopy = 0; |
| 610 |
psmi_shm_mq_rv_thresh = PSMI_MQ_RV_THRESH_NO_KASSIST; |
| 611 |
} |
| 612 |
} |
| 613 |
} |
| 614 |
else |
| 615 |
psmi_shm_mq_rv_thresh = PSMI_MQ_RV_THRESH_NO_KASSIST; |
| 616 |
_IPATH_PRDBG("KASSIST MODE: %s\n", psmi_kassist_getmode(ep->psmi_kassist_mode)); |
| 617 |
#ifdef PSM_HAVE_SCIF |
| 618 |
_IPATH_PRDBG("SCIF DMA MODE: %s\n", psmi_scif_dma_getmode(ep->scif_dma_mode)); |
| 619 |
_IPATH_PRDBG("SCIF DMA THRESHOLD: %d\n", ep->scif_dma_threshold); |
| 620 |
#endif |
| 621 |
|
| 622 |
ep->amsh_shmidx = shmidx = *shmidx_o = i; |
| 623 |
_IPATH_PRDBG("Grabbed shmidx %d\n", shmidx); |
| 624 |
ep->amsh_dirpage->num_attached++; |
| 625 |
break; |
| 626 |
} |
| 627 |
} |
| 628 |
pthread_mutex_unlock((pthread_mutex_t *) &(ep->amsh_dirpage->lock)); |
| 629 |
|
| 630 |
|
| 631 |
signal(SIGSEGV, old_handler_segv); |
| 632 |
signal(SIGBUS, old_handler_bus); |
| 633 |
|
| 634 |
if (shmidx == -1) |
| 635 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 636 |
"Exceeded maximum of %d support local endpoints: %s", |
| 637 |
PTL_AMSH_MAX_LOCAL_PROCS, strerror(errno)); |
| 638 |
|
| 639 |
fail: |
| 640 |
return err; |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
#define AMSH_QSIZE(type) \ |
| 656 |
PSMI_ALIGNUP(amsh_qelemsz.q ## type * amsh_qcounts.q ## type, \ |
| 657 |
PSMI_PAGESIZE) |
| 658 |
|
| 659 |
static |
| 660 |
psm_error_t |
| 661 |
amsh_init_segment(ptl_t *ptl) |
| 662 |
{ |
| 663 |
struct amsh_qptrs* qptrs; |
| 664 |
int shmidx; |
| 665 |
int i; |
| 666 |
psm_error_t err = PSM_OK; |
| 667 |
int scif_nnodes; |
| 668 |
|
| 669 |
|
| 670 |
psmi_assert_always(ptl != NULL); |
| 671 |
psmi_assert_always(ptl->ep != NULL); |
| 672 |
psmi_assert_always(ptl->epaddr != NULL); |
| 673 |
psmi_assert_always(ptl->ep->epid != 0); |
| 674 |
psmi_assert_always(ptl->ep->amsh_shmidx != -1); |
| 675 |
|
| 676 |
shmidx = ptl->ep->amsh_shmidx; |
| 677 |
|
| 678 |
ptl->amsh_qsizes.qreqFifoShort = AMSH_QSIZE(reqFifoShort); |
| 679 |
ptl->amsh_qsizes.qreqFifoMed = AMSH_QSIZE(reqFifoMed); |
| 680 |
ptl->amsh_qsizes.qreqFifoLong = AMSH_QSIZE(reqFifoLong); |
| 681 |
ptl->amsh_qsizes.qreqFifoHuge = AMSH_QSIZE(reqFifoHuge); |
| 682 |
ptl->amsh_qsizes.qrepFifoShort = AMSH_QSIZE(repFifoShort); |
| 683 |
ptl->amsh_qsizes.qrepFifoMed = AMSH_QSIZE(repFifoMed); |
| 684 |
ptl->amsh_qsizes.qrepFifoLong = AMSH_QSIZE(repFifoLong); |
| 685 |
ptl->amsh_qsizes.qrepFifoHuge = AMSH_QSIZE(repFifoHuge); |
| 686 |
|
| 687 |
|
| 688 |
void (*old_handler_segv)(int) = signal (SIGSEGV, amsh_mmap_fault); |
| 689 |
void (*old_handler_bus)(int) = signal (SIGBUS, amsh_mmap_fault); |
| 690 |
|
| 691 |
pthread_mutex_lock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
ptl->ep->amsh_dirpage->shmidx_map_epid[shmidx] = ptl->ep->epid; |
| 697 |
|
| 698 |
if (shmidx > ptl->ep->amsh_dirpage->max_idx) { |
| 699 |
ptl->ep->amsh_dirpage->max_idx = shmidx; |
| 700 |
} |
| 701 |
|
| 702 |
ptl->shmidx = shmidx; |
| 703 |
ptl->ep->amsh_qdir[shmidx].amsh_epaddr = ptl->ep->epaddr; |
| 704 |
for(i = 0; i < PTL_AMSH_MAX_LOCAL_NODES; i++) { |
| 705 |
ptl->reqH[i].base = ptl->reqH[i].head = ptl->reqH[i].end = NULL; |
| 706 |
ptl->repH[i].base = ptl->repH[i].head = ptl->repH[i].end = NULL; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
for(i = 0; i < PTL_AMSH_MAX_LOCAL_PROCS; i++) { |
| 711 |
ptl->ep->amsh_qdir[i].amsh_base = |
| 712 |
(void *)(ptl->ep->amsh_blockbase + |
| 713 |
am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES * i); |
| 714 |
|
| 715 |
ptl->ep->amsh_qdir[i].amsh_shmidx = ptl->shmidx; |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
#ifdef PSM_HAVE_SCIF |
| 723 |
ptl->ep->amsh_qdir[i].amsh_epid = |
| 724 |
((psm_epid_t)ptl->ep->scif_mynodeid & 0xff) << 48; |
| 725 |
#endif |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
am_update_directory(ptl, i); |
| 733 |
} |
| 734 |
|
| 735 |
#ifdef PSM_HAVE_SCIF |
| 736 |
scif_nnodes = ptl->ep->scif_nnodes; |
| 737 |
#else |
| 738 |
|
| 739 |
scif_nnodes = 1; |
| 740 |
#endif |
| 741 |
|
| 742 |
|
| 743 |
memset(ptl->ep->amsh_qdir[shmidx].amsh_base, |
| 744 |
0, am_ctl_sizeof_block() * scif_nnodes); |
| 745 |
|
| 746 |
for(i = 0; i < scif_nnodes; i++) { |
| 747 |
qptrs = &ptl->ep->amsh_qdir[shmidx].qptrs[i]; |
| 748 |
|
| 749 |
am_ctl_qhdr_init(&qptrs->qreqH->shortq, |
| 750 |
amsh_qcounts.qreqFifoShort, amsh_qelemsz.qreqFifoShort); |
| 751 |
am_ctl_qhdr_init(&qptrs->qreqH->medbulkq, |
| 752 |
amsh_qcounts.qreqFifoMed, amsh_qelemsz.qreqFifoMed); |
| 753 |
am_ctl_qhdr_init(&qptrs->qreqH->longbulkq, |
| 754 |
amsh_qcounts.qreqFifoLong, amsh_qelemsz.qreqFifoLong); |
| 755 |
am_ctl_qhdr_init(&qptrs->qreqH->hugebulkq, |
| 756 |
amsh_qcounts.qreqFifoHuge, amsh_qelemsz.qreqFifoHuge); |
| 757 |
|
| 758 |
am_ctl_qhdr_init(&qptrs->qrepH->shortq, |
| 759 |
amsh_qcounts.qrepFifoShort, amsh_qelemsz.qrepFifoShort); |
| 760 |
am_ctl_qhdr_init(&qptrs->qrepH->medbulkq, |
| 761 |
amsh_qcounts.qrepFifoMed, amsh_qelemsz.qrepFifoMed); |
| 762 |
am_ctl_qhdr_init(&qptrs->qrepH->longbulkq, |
| 763 |
amsh_qcounts.qrepFifoLong, amsh_qelemsz.qrepFifoLong); |
| 764 |
am_ctl_qhdr_init(&qptrs->qrepH->hugebulkq, |
| 765 |
amsh_qcounts.qrepFifoHuge, amsh_qelemsz.qrepFifoHuge); |
| 766 |
|
| 767 |
|
| 768 |
am_ctl_bulkpkt_init(qptrs->qreqFifoMed, |
| 769 |
amsh_qelemsz.qreqFifoMed, |
| 770 |
amsh_qcounts.qreqFifoMed); |
| 771 |
am_ctl_bulkpkt_init(qptrs->qreqFifoLong, |
| 772 |
amsh_qelemsz.qreqFifoLong, |
| 773 |
amsh_qcounts.qreqFifoLong); |
| 774 |
am_ctl_bulkpkt_init(qptrs->qreqFifoHuge, |
| 775 |
amsh_qelemsz.qreqFifoHuge, |
| 776 |
amsh_qcounts.qreqFifoHuge); |
| 777 |
|
| 778 |
am_ctl_bulkpkt_init(qptrs->qrepFifoMed, |
| 779 |
amsh_qelemsz.qrepFifoMed, |
| 780 |
amsh_qcounts.qrepFifoMed); |
| 781 |
am_ctl_bulkpkt_init(qptrs->qrepFifoLong, |
| 782 |
amsh_qelemsz.qrepFifoLong, |
| 783 |
amsh_qcounts.qrepFifoLong); |
| 784 |
am_ctl_bulkpkt_init(qptrs->qrepFifoHuge, |
| 785 |
amsh_qelemsz.qrepFifoHuge, |
| 786 |
amsh_qcounts.qrepFifoHuge); |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
signal(SIGSEGV, old_handler_segv); |
| 791 |
signal(SIGBUS, old_handler_bus); |
| 792 |
|
| 793 |
pthread_mutex_unlock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 794 |
return err; |
| 795 |
} |
| 796 |
|
| 797 |
psm_error_t |
| 798 |
psmi_shm_detach(psm_ep_t ep) |
| 799 |
{ |
| 800 |
psm_error_t err = PSM_OK; |
| 801 |
|
| 802 |
if (ep->amsh_shmidx == -1 || ep->amsh_keyname == NULL) |
| 803 |
return err; |
| 804 |
|
| 805 |
#ifdef PSM_HAVE_SCIF |
| 806 |
if (amsh_scif_detach(ep)) { |
| 807 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 808 |
"Error with amsh_scif_detach() of shared segment: %s", |
| 809 |
strerror(errno)); |
| 810 |
goto fail; |
| 811 |
} |
| 812 |
#endif |
| 813 |
|
| 814 |
_IPATH_VDBG("unlinking shm file %s\n", ep->amsh_keyname+1); |
| 815 |
shm_unlink(ep->amsh_keyname); |
| 816 |
psmi_free(ep->amsh_keyname); |
| 817 |
ep->amsh_keyname = NULL; |
| 818 |
|
| 819 |
if (ep->psmi_kassist_fd != -1) { |
| 820 |
close(ep->psmi_kassist_fd); |
| 821 |
ep->psmi_kassist_fd = -1; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
pthread_mutex_lock((pthread_mutex_t *) &(ep->amsh_dirpage->lock)); |
| 826 |
|
| 827 |
ep->amsh_dirpage->num_attached--; |
| 828 |
ep->amsh_dirpage->shmidx_map_epid[ep->amsh_shmidx] = 0; |
| 829 |
ep->amsh_shmidx = -1; |
| 830 |
|
| 831 |
if (ep->amsh_dirpage->num_attached == 0) { |
| 832 |
pthread_mutex_unlock((pthread_mutex_t *) &(ep->amsh_dirpage->lock)); |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
#ifdef PSM_HAVE_SCIF |
| 842 |
if (munmap((void *) ep->amsh_shmbase, |
| 843 |
psmi_amsh_segsize(PTL_AMSH_MAX_LOCAL_PROCS, |
| 844 |
PTL_AMSH_MAX_LOCAL_NODES))) { |
| 845 |
#else |
| 846 |
int nranks, rankid, nprocs; |
| 847 |
psmi_sharedcontext_params(&nranks, &rankid); |
| 848 |
nprocs = (nranks <= 0) ? sysconf(_SC_NPROCESSORS_ONLN) : nranks; |
| 849 |
if (munmap((void *) ep->amsh_shmbase, |
| 850 |
psmi_amsh_segsize(nprocs, PTL_AMSH_MAX_LOCAL_NODES))) { |
| 851 |
#endif |
| 852 |
err = psmi_handle_error(NULL, PSM_SHMEM_SEGMENT_ERR, |
| 853 |
"Error with munamp of shared segment: %s", strerror(errno)); |
| 854 |
goto fail; |
| 855 |
} |
| 856 |
} |
| 857 |
else { |
| 858 |
int i, new_max_idx = ep->amsh_dirpage->max_idx; |
| 859 |
for (i = ep->amsh_dirpage->max_idx; i >= 0; i--) { |
| 860 |
if (ep->amsh_dirpage->shmidx_map_epid[i] == 0) |
| 861 |
new_max_idx = i; |
| 862 |
else |
| 863 |
break; |
| 864 |
} |
| 865 |
|
| 866 |
ep->amsh_dirpage->max_idx = new_max_idx; |
| 867 |
|
| 868 |
pthread_mutex_unlock((pthread_mutex_t *) &(ep->amsh_dirpage->lock)); |
| 869 |
} |
| 870 |
|
| 871 |
ep->amsh_max_idx = -1; |
| 872 |
ep->amsh_shmfd = -1; |
| 873 |
|
| 874 |
ep->amsh_shmbase = ep->amsh_blockbase = 0; |
| 875 |
ep->amsh_dirpage = NULL; |
| 876 |
memset(ep->amsh_keyno, 0, sizeof(ep->amsh_keyno)); |
| 877 |
|
| 878 |
return PSM_OK; |
| 879 |
|
| 880 |
fail: |
| 881 |
return err; |
| 882 |
} |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
static |
| 890 |
void |
| 891 |
am_hdrcache_update_short(ptl_t *ptl, int shmidx, |
| 892 |
am_ctl_qshort_cache_t *reqH, |
| 893 |
am_ctl_qshort_cache_t *repH) |
| 894 |
{ |
| 895 |
int node; |
| 896 |
|
| 897 |
for(node = 0; node < PTL_AMSH_MAX_LOCAL_NODES; node++) { |
| 898 |
reqH[node].base = QGETPTR_SCIF(ptl, shmidx, node, |
| 899 |
reqFifoShort, short, 0); |
| 900 |
reqH[node].head = QGETPTR_SCIF(ptl, shmidx, node, |
| 901 |
reqFifoShort, short, 0); |
| 902 |
reqH[node].end = QGETPTR_SCIF(ptl, shmidx, node, |
| 903 |
reqFifoShort, short, amsh_qcounts.qreqFifoShort); |
| 904 |
|
| 905 |
repH[node].base = QGETPTR_SCIF(ptl, shmidx, node, |
| 906 |
repFifoShort, short, 0); |
| 907 |
repH[node].head = QGETPTR_SCIF(ptl, shmidx, node, |
| 908 |
repFifoShort, short, 0); |
| 909 |
repH[node].end = QGETPTR_SCIF(ptl, shmidx, node, |
| 910 |
repFifoShort, short, amsh_qcounts.qrepFifoShort); |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
static |
| 921 |
void |
| 922 |
am_update_directory(ptl_t *ptl, int shmidx) |
| 923 |
{ |
| 924 |
psm_ep_t ep = ptl->ep; |
| 925 |
uintptr_t base_this; |
| 926 |
uintptr_t base_node; |
| 927 |
struct amsh_qptrs* qptrs; |
| 928 |
int i; |
| 929 |
|
| 930 |
psmi_assert_always(shmidx != -1); |
| 931 |
base_this = |
| 932 |
(uintptr_t)ep->amsh_qdir[shmidx].amsh_base + AMSH_BLOCK_HEADER_SIZE; |
| 933 |
|
| 934 |
if (shmidx < PTL_AMSH_MAX_LOCAL_PROCS) { |
| 935 |
if(ep->amsh_dirpage->amsh_features[shmidx] & AMSH_HAVE_KASSIST) { |
| 936 |
ep->amsh_qdir[shmidx].kassist_pid = |
| 937 |
ep->amsh_dirpage->kassist_pids[shmidx]; |
| 938 |
} |
| 939 |
} else { |
| 940 |
ep->amsh_qdir[shmidx].kassist_pid = 0; |
| 941 |
} |
| 942 |
|
| 943 |
for(i = 0; i < PTL_AMSH_MAX_LOCAL_NODES; i++) { |
| 944 |
qptrs = &ep->amsh_qdir[shmidx].qptrs[i]; |
| 945 |
|
| 946 |
base_node = base_this + (i * am_ctl_sizeof_block()); |
| 947 |
|
| 948 |
|
| 949 |
qptrs->qreqH = (am_ctl_blockhdr_t *) base_node; |
| 950 |
|
| 951 |
qptrs->qreqFifoShort = (am_pkt_short_t *) |
| 952 |
((uintptr_t) qptrs->qreqH + |
| 953 |
PSMI_ALIGNUP(sizeof(am_ctl_blockhdr_t), PSMI_PAGESIZE)); |
| 954 |
qptrs->qreqFifoMed = (am_pkt_bulk_t *) |
| 955 |
((uintptr_t) qptrs->qreqFifoShort + |
| 956 |
ptl->amsh_qsizes.qreqFifoShort); |
| 957 |
qptrs->qreqFifoLong = (am_pkt_bulk_t *) |
| 958 |
((uintptr_t) qptrs->qreqFifoMed + |
| 959 |
ptl->amsh_qsizes.qreqFifoMed); |
| 960 |
qptrs->qreqFifoHuge = (am_pkt_bulk_t *) |
| 961 |
((uintptr_t) qptrs->qreqFifoLong + |
| 962 |
ptl->amsh_qsizes.qreqFifoLong); |
| 963 |
|
| 964 |
|
| 965 |
qptrs->qrepH = (am_ctl_blockhdr_t *) |
| 966 |
((uintptr_t) qptrs->qreqFifoHuge + |
| 967 |
ptl->amsh_qsizes.qreqFifoHuge); |
| 968 |
|
| 969 |
qptrs->qrepFifoShort = (am_pkt_short_t *) |
| 970 |
((uintptr_t) qptrs->qrepH + |
| 971 |
PSMI_ALIGNUP(sizeof(am_ctl_blockhdr_t), PSMI_PAGESIZE)); |
| 972 |
qptrs->qrepFifoMed = (am_pkt_bulk_t *) |
| 973 |
((uintptr_t) qptrs->qrepFifoShort + |
| 974 |
ptl->amsh_qsizes.qrepFifoShort); |
| 975 |
qptrs->qrepFifoLong = (am_pkt_bulk_t *) |
| 976 |
((uintptr_t) qptrs->qrepFifoMed + |
| 977 |
ptl->amsh_qsizes.qrepFifoMed); |
| 978 |
qptrs->qrepFifoHuge = (am_pkt_bulk_t *) |
| 979 |
((uintptr_t) qptrs->qrepFifoLong + |
| 980 |
ptl->amsh_qsizes.qrepFifoLong); |
| 981 |
|
| 982 |
_IPATH_VDBG("shmidx=%d node=%d Request Hdr=%p,Pkt=%p,Med=%p,Long=%p,Huge=%p\n", |
| 983 |
shmidx, i, |
| 984 |
qptrs->qreqH, |
| 985 |
qptrs->qreqFifoShort, |
| 986 |
qptrs->qreqFifoMed, |
| 987 |
qptrs->qreqFifoLong, |
| 988 |
qptrs->qreqFifoHuge); |
| 989 |
_IPATH_VDBG("shmidx=%d node=%d Reply Hdr=%p,Pkt=%p,Med=%p,Long=%p,Huge=%p\n", |
| 990 |
shmidx, i, |
| 991 |
qptrs->qrepH, |
| 992 |
qptrs->qrepFifoShort, |
| 993 |
qptrs->qrepFifoMed, |
| 994 |
qptrs->qrepFifoLong, |
| 995 |
qptrs->qrepFifoHuge); |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
#ifdef PSM_HAVE_SCIF |
| 1000 |
qptrs = &ep->amsh_qdir[shmidx].qptrs[ptl->ep->scif_mynodeid]; |
| 1001 |
#else |
| 1002 |
qptrs = &ep->amsh_qdir[shmidx].qptrs[0]; |
| 1003 |
#endif |
| 1004 |
|
| 1005 |
ep->amsh_qdir[shmidx].qreqH = qptrs->qreqH; |
| 1006 |
ep->amsh_qdir[shmidx].qreqFifoShort = qptrs->qreqFifoShort; |
| 1007 |
ep->amsh_qdir[shmidx].qreqFifoMed = qptrs->qreqFifoMed; |
| 1008 |
ep->amsh_qdir[shmidx].qreqFifoLong = qptrs->qreqFifoLong; |
| 1009 |
ep->amsh_qdir[shmidx].qreqFifoHuge = qptrs->qreqFifoHuge; |
| 1010 |
|
| 1011 |
ep->amsh_qdir[shmidx].qrepH = qptrs->qrepH; |
| 1012 |
ep->amsh_qdir[shmidx].qrepFifoShort = qptrs->qrepFifoShort; |
| 1013 |
ep->amsh_qdir[shmidx].qrepFifoMed = qptrs->qrepFifoMed; |
| 1014 |
ep->amsh_qdir[shmidx].qrepFifoLong = qptrs->qrepFifoLong; |
| 1015 |
ep->amsh_qdir[shmidx].qrepFifoHuge = qptrs->qrepFifoHuge; |
| 1016 |
|
| 1017 |
|
| 1018 |
if (ptl->shmidx == shmidx) |
| 1019 |
am_hdrcache_update_short(ptl, shmidx, |
| 1020 |
(am_ctl_qshort_cache_t *) ptl->reqH, |
| 1021 |
(am_ctl_qshort_cache_t *) ptl->repH); |
| 1022 |
|
| 1023 |
|
| 1024 |
uintptr_t base_next = |
| 1025 |
(uintptr_t) ep->amsh_qdir[shmidx].qptrs[PTL_AMSH_MAX_LOCAL_NODES - 1].qrepFifoHuge + ptl->amsh_qsizes.qrepFifoHuge; |
| 1026 |
|
| 1027 |
psmi_assert_always(base_next - base_this <= |
| 1028 |
am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES); |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
static |
| 1033 |
int |
| 1034 |
amsh_epid_reachable(ptl_t *ptl, psm_epid_t epid) |
| 1035 |
{ |
| 1036 |
int result; |
| 1037 |
psm_error_t err; |
| 1038 |
err = psm_ep_epid_share_memory(ptl->ep, epid, &result); |
| 1039 |
psmi_assert_always(err == PSM_OK); |
| 1040 |
return result; |
| 1041 |
} |
| 1042 |
|
| 1043 |
static |
| 1044 |
psm_error_t |
| 1045 |
amsh_epaddr_add(ptl_t *ptl, psm_epid_t epid, int shmidx, psm_epaddr_t *epaddr_o) |
| 1046 |
{ |
| 1047 |
psm_epaddr_t epaddr; |
| 1048 |
psm_error_t err = PSM_OK; |
| 1049 |
|
| 1050 |
psmi_assert(psmi_epid_lookup(ptl->ep, epid) == NULL); |
| 1051 |
|
| 1052 |
if (epid == ptl->epid) { |
| 1053 |
epaddr = ptl->epaddr; |
| 1054 |
} else { |
| 1055 |
epaddr = (psm_epaddr_t) psmi_calloc(ptl->ep, PER_PEER_ENDPOINT, |
| 1056 |
1, sizeof(struct psm_epaddr)); |
| 1057 |
if (epaddr == NULL) { |
| 1058 |
return PSM_NO_MEMORY; |
| 1059 |
} |
| 1060 |
psmi_assert_always(ptl->ep->amsh_qdir[shmidx].amsh_epaddr == NULL); |
| 1061 |
} |
| 1062 |
|
| 1063 |
epaddr->ptl = ptl; |
| 1064 |
epaddr->ptlctl = ptl->ctl; |
| 1065 |
STAILQ_INIT(&epaddr->egrlong); |
| 1066 |
epaddr->mctxt_prev = epaddr; |
| 1067 |
epaddr->mctxt_next = epaddr; |
| 1068 |
epaddr->mctxt_master = epaddr; |
| 1069 |
epaddr->epid = epid; |
| 1070 |
epaddr->ep = ptl->ep; |
| 1071 |
epaddr->_shmidx = shmidx; |
| 1072 |
AMSH_CSTATE_TO_SET(epaddr, NONE); |
| 1073 |
AMSH_CSTATE_FROM_SET(epaddr, NONE); |
| 1074 |
if ((err = psmi_epid_set_hostname(psm_epid_nid(epid), |
| 1075 |
psmi_gethostname(), 0))) |
| 1076 |
goto fail; |
| 1077 |
|
| 1078 |
ptl->ep->amsh_qdir[shmidx].amsh_epaddr = epaddr; |
| 1079 |
|
| 1080 |
|
| 1081 |
if ((err = psmi_epid_add(ptl->ep, epid, epaddr))) |
| 1082 |
goto fail; |
| 1083 |
|
| 1084 |
_IPATH_VDBG("epaddr=%s added to ptl=%p\n", |
| 1085 |
psmi_epaddr_get_name(epid), ptl); |
| 1086 |
|
| 1087 |
*epaddr_o = epaddr; |
| 1088 |
return PSM_OK; |
| 1089 |
fail: |
| 1090 |
if (epaddr != ptl->epaddr) psmi_free(epaddr); |
| 1091 |
return err; |
| 1092 |
} |
| 1093 |
|
| 1094 |
struct ptl_connection_req |
| 1095 |
{ |
| 1096 |
int isdone; |
| 1097 |
int op; |
| 1098 |
int numep; |
| 1099 |
int numep_left; |
| 1100 |
int phase; |
| 1101 |
|
| 1102 |
int *epid_mask; |
| 1103 |
const psm_epid_t *epids; |
| 1104 |
psm_epaddr_t *epaddr; |
| 1105 |
psm_error_t *errors; |
| 1106 |
|
| 1107 |
|
| 1108 |
psm_amarg_t args[4]; |
| 1109 |
}; |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
#ifdef PSM_HAVE_SCIF |
| 1115 |
static int |
| 1116 |
amsh_scif_send(scif_epd_t epd, void *buf, size_t len) |
| 1117 |
{ |
| 1118 |
int ret; |
| 1119 |
while (len) { |
| 1120 |
ret = scif_send(epd, buf, (uint32_t)len, SCIF_SEND_BLOCK); |
| 1121 |
if (ret < 0) { |
| 1122 |
if (errno == EINTR) continue; |
| 1123 |
return ret; |
| 1124 |
} |
| 1125 |
buf += ret; |
| 1126 |
len -= ret; |
| 1127 |
} |
| 1128 |
return 0; |
| 1129 |
} |
| 1130 |
|
| 1131 |
static int |
| 1132 |
amsh_scif_recv(scif_epd_t epd, void *buf, size_t len) |
| 1133 |
{ |
| 1134 |
int ret; |
| 1135 |
while (len) { |
| 1136 |
ret = scif_recv(epd, buf, (uint32_t)len, SCIF_RECV_BLOCK); |
| 1137 |
if (ret < 0) { |
| 1138 |
if (errno == EINTR) continue; |
| 1139 |
return ret; |
| 1140 |
} |
| 1141 |
buf += ret; |
| 1142 |
len -= ret; |
| 1143 |
} |
| 1144 |
return 0; |
| 1145 |
} |
| 1146 |
|
| 1147 |
static |
| 1148 |
psm_error_t |
| 1149 |
amsh_scif_connect(uint16_t nodeid, uint16_t port, scif_epd_t *epd_o) |
| 1150 |
{ |
| 1151 |
int tries; |
| 1152 |
struct scif_portID portID; |
| 1153 |
scif_epd_t epd; |
| 1154 |
psm_error_t err; |
| 1155 |
|
| 1156 |
epd = scif_open(); |
| 1157 |
if (epd < 0) { |
| 1158 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 1159 |
"scif_open failed with error %d\n", errno); |
| 1160 |
return err; |
| 1161 |
} |
| 1162 |
|
| 1163 |
portID.port = port; |
| 1164 |
portID.node = nodeid; |
| 1165 |
|
| 1166 |
_IPATH_VDBG("scif connecting to %d:%d\n", nodeid, port); |
| 1167 |
|
| 1168 |
for(tries = 0; tries < psmi_scif_connect_retries; tries++) { |
| 1169 |
if (scif_connect(epd, &portID) >= 0) { |
| 1170 |
break; |
| 1171 |
} else if(errno != ECONNREFUSED) { |
| 1172 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 1173 |
"scif_connect failed with error %d (%s)\n", |
| 1174 |
errno, strerror(errno)); |
| 1175 |
scif_close(epd); |
| 1176 |
return err; |
| 1177 |
} |
| 1178 |
|
| 1179 |
|
| 1180 |
if(tries < 20) { |
| 1181 |
usleep(100000); |
| 1182 |
} else { |
| 1183 |
usleep(250000); |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1187 |
if(tries == psmi_scif_connect_retries) { |
| 1188 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 1189 |
"scif_connect retry limit exceeded\n"); |
| 1190 |
return err; |
| 1191 |
} |
| 1192 |
|
| 1193 |
*epd_o = epd; |
| 1194 |
return PSM_OK; |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
static psm_error_t amsh_scif_setup(ptl_t* ptl, psm_epid_t epid) |
| 1199 |
{ |
| 1200 |
psm_ep_t ep = ptl->ep; |
| 1201 |
psm_error_t err = PSM_OK; |
| 1202 |
scif_epd_t epd = -1; |
| 1203 |
void* addr; |
| 1204 |
int peeridx; |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
struct { off_t offset; int verno; psm_epid_t epid; } buf; |
| 1209 |
|
| 1210 |
int port = (int)((epid>>32)&0xffff); |
| 1211 |
int nodeid = (int)((epid>>48)&0xff); |
| 1212 |
int shmidx = (int)((epid>>56)&0xff); |
| 1213 |
|
| 1214 |
|
| 1215 |
if (nodeid == ep->scif_mynodeid) { |
| 1216 |
return PSM_OK; |
| 1217 |
} |
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
if(nodeid > ep->scif_mynodeid) { |
| 1223 |
peeridx = (PTL_AMSH_MAX_LOCAL_PROCS * nodeid) + shmidx; |
| 1224 |
} else { |
| 1225 |
peeridx = (PTL_AMSH_MAX_LOCAL_PROCS * (nodeid + 1)) + shmidx; |
| 1226 |
} |
| 1227 |
|
| 1228 |
_IPATH_VDBG("%lx scif_connect to %d:%d %d %lx\n", |
| 1229 |
ep->epid, nodeid, port, peeridx, epid); |
| 1230 |
|
| 1231 |
if(ep->amsh_qdir[peeridx].amsh_epd[0] != 0) { |
| 1232 |
|
| 1233 |
return err; |
| 1234 |
} |
| 1235 |
|
| 1236 |
buf.offset = 0; |
| 1237 |
buf.verno = PSMI_VERNO; |
| 1238 |
buf.epid = ep->epid; |
| 1239 |
|
| 1240 |
err = amsh_scif_connect(nodeid, port, &epd); |
| 1241 |
if(err) { |
| 1242 |
return err; |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
if (amsh_scif_send(epd, &buf, sizeof(buf))) { |
| 1247 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 1248 |
"scif_send failed: %d %s\n", errno, strerror(errno)); |
| 1249 |
scif_close(epd); |
| 1250 |
return err; |
| 1251 |
} |
| 1252 |
|
| 1253 |
|
| 1254 |
if(amsh_scif_recv(epd, &buf, sizeof(buf))) { |
| 1255 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 1256 |
"scif_recv failed: %d %s\n", errno, strerror(errno)); |
| 1257 |
scif_close(epd); |
| 1258 |
return err; |
| 1259 |
} |
| 1260 |
|
| 1261 |
addr = scif_mmap(NULL, am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES, |
| 1262 |
SCIF_PROT_READ|SCIF_PROT_WRITE, 0, epd, buf.offset); |
| 1263 |
if(addr == SCIF_MMAP_FAILED) { |
| 1264 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 1265 |
"scif_mmap failed: %d %s\n", errno, strerror(errno)); |
| 1266 |
scif_close(epd); |
| 1267 |
return err; |
| 1268 |
} |
| 1269 |
|
| 1270 |
_IPATH_PRDBG("%lx scif_mmap offset %p -> %p to addr %p -> %p length %ld\n", |
| 1271 |
ep->epid, (void*)buf.offset, |
| 1272 |
(void*)(buf.offset + am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES), |
| 1273 |
addr, |
| 1274 |
(void*)((uintptr_t)addr + am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES), |
| 1275 |
am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES); |
| 1276 |
|
| 1277 |
ep->amsh_qdir[peeridx].amsh_offset = buf.offset; |
| 1278 |
ep->amsh_qdir[peeridx].amsh_base = addr; |
| 1279 |
ep->amsh_qdir[peeridx].amsh_epid = buf.epid; |
| 1280 |
ep->amsh_qdir[peeridx].amsh_verno = buf.verno; |
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
if(ep->scif_mynodeid < nodeid) { |
| 1286 |
ep->amsh_qdir[peeridx].amsh_shmidx = |
| 1287 |
(PTL_AMSH_MAX_LOCAL_PROCS * (ep->scif_mynodeid + 1)) + |
| 1288 |
ep->amsh_shmidx; |
| 1289 |
} else { |
| 1290 |
ep->amsh_qdir[peeridx].amsh_shmidx = |
| 1291 |
(PTL_AMSH_MAX_LOCAL_PROCS * ep->scif_mynodeid) + |
| 1292 |
ep->amsh_shmidx; |
| 1293 |
} |
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
ep->amsh_qdir[peeridx].amsh_epd[0] = epd; |
| 1300 |
|
| 1301 |
am_update_directory(ptl, peeridx); |
| 1302 |
|
| 1303 |
_IPATH_VDBG("shmidx %d connected! set peeridx %d amsh_shmidx %d epd %d\n", |
| 1304 |
ep->amsh_shmidx, peeridx, |
| 1305 |
ep->amsh_qdir[peeridx].amsh_shmidx, |
| 1306 |
ep->amsh_qdir[peeridx].amsh_epd[0]); |
| 1307 |
return err; |
| 1308 |
} |
| 1309 |
|
| 1310 |
static |
| 1311 |
psm_error_t |
| 1312 |
amsh_scif_detach(psm_ep_t ep) |
| 1313 |
{ |
| 1314 |
int i; |
| 1315 |
int size = am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES; |
| 1316 |
|
| 1317 |
|
| 1318 |
for (i = 0; i < ep->scif_nnodes*PTL_AMSH_MAX_LOCAL_PROCS; i++) { |
| 1319 |
if (ep->amsh_qdir[i].amsh_epd[0] == 0) continue; |
| 1320 |
|
| 1321 |
if(i >= PTL_AMSH_MAX_LOCAL_PROCS) { |
| 1322 |
if(scif_munmap(ep->amsh_qdir[i].amsh_base, size)) { |
| 1323 |
_IPATH_INFO("SCIF: unmapping addr %p length %d failed: (%d) %s\n", |
| 1324 |
ep->amsh_qdir[i].amsh_base, size, |
| 1325 |
errno, strerror(errno)); |
| 1326 |
return PSM_INTERNAL_ERR; |
| 1327 |
} |
| 1328 |
|
| 1329 |
ep->amsh_qdir[i].amsh_base = NULL; |
| 1330 |
} |
| 1331 |
|
| 1332 |
if(scif_close(ep->amsh_qdir[i].amsh_epd[0])) { |
| 1333 |
_IPATH_INFO("SCIF: closing epd[0] %d failed: (%d) %s\n", |
| 1334 |
ep->amsh_qdir[i].amsh_epd[0], |
| 1335 |
errno, strerror(errno)); |
| 1336 |
return PSM_INTERNAL_ERR; |
| 1337 |
} |
| 1338 |
|
| 1339 |
if(scif_close(ep->amsh_qdir[i].amsh_epd[1])) { |
| 1340 |
_IPATH_INFO("SCIF: closing epd[1] %d failed: (%d) %s\n", |
| 1341 |
ep->amsh_qdir[i].amsh_epd[1], |
| 1342 |
errno, strerror(errno)); |
| 1343 |
return PSM_INTERNAL_ERR; |
| 1344 |
} |
| 1345 |
|
| 1346 |
ep->amsh_qdir[i].amsh_epd[0] = 0; |
| 1347 |
ep->amsh_qdir[i].amsh_epd[1] = 0; |
| 1348 |
} |
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
if(scif_close(ep->scif_epd)) { |
| 1353 |
_IPATH_INFO("SCIF: closing listen epd %d failed: (%d) %s\n", |
| 1354 |
ep->scif_epd, |
| 1355 |
errno, strerror(errno)); |
| 1356 |
return PSM_INTERNAL_ERR; |
| 1357 |
} |
| 1358 |
|
| 1359 |
pthread_join(ep->scif_thread, NULL); |
| 1360 |
|
| 1361 |
return PSM_OK; |
| 1362 |
} |
| 1363 |
|
| 1364 |
#endif |
| 1365 |
|
| 1366 |
#define PTL_OP_CONNECT 0 |
| 1367 |
#define PTL_OP_DISCONNECT 1 |
| 1368 |
#define PTL_OP_ABORT 2 |
| 1369 |
|
| 1370 |
static |
| 1371 |
psm_error_t |
| 1372 |
amsh_ep_connreq_init(ptl_t *ptl, |
| 1373 |
int op, |
| 1374 |
int numep, |
| 1375 |
const psm_epid_t *array_of_epid, |
| 1376 |
const int array_of_epid_mask[], |
| 1377 |
psm_error_t *array_of_errors, |
| 1378 |
psm_epaddr_t *array_of_epaddr, |
| 1379 |
struct ptl_connection_req **req_o) |
| 1380 |
{ |
| 1381 |
int i, cstate; |
| 1382 |
psm_epaddr_t epaddr; |
| 1383 |
psm_epid_t epid; |
| 1384 |
struct ptl_connection_req *req = NULL; |
| 1385 |
|
| 1386 |
req = (struct ptl_connection_req *) |
| 1387 |
psmi_calloc(ptl->ep, PER_PEER_ENDPOINT, 1, |
| 1388 |
sizeof(struct ptl_connection_req)); |
| 1389 |
if (req == NULL) |
| 1390 |
return PSM_NO_MEMORY; |
| 1391 |
|
| 1392 |
req->isdone = 0; |
| 1393 |
req->op = op; |
| 1394 |
req->numep = numep; |
| 1395 |
req->numep_left = 0; |
| 1396 |
req->phase = ptl->connect_phase; |
| 1397 |
req->epid_mask = (int *) |
| 1398 |
psmi_calloc(ptl->ep, PER_PEER_ENDPOINT, numep, sizeof(int)); |
| 1399 |
|
| 1400 |
if (req->epid_mask == NULL) { |
| 1401 |
psmi_free(req); |
| 1402 |
return PSM_NO_MEMORY; |
| 1403 |
} |
| 1404 |
|
| 1405 |
req->epaddr = array_of_epaddr; |
| 1406 |
req->epids = array_of_epid; |
| 1407 |
req->errors = array_of_errors; |
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
for (i = 0; i < numep; i++) { |
| 1412 |
req->epid_mask[i] = AMSH_CMASK_NONE; |
| 1413 |
if (!array_of_epid_mask[i]) |
| 1414 |
continue; |
| 1415 |
if (op == PTL_OP_CONNECT) { |
| 1416 |
epid = array_of_epid[i]; |
| 1417 |
if (!amsh_epid_reachable(ptl, epid)) { |
| 1418 |
array_of_errors[i] = PSM_EPID_UNREACHABLE; |
| 1419 |
array_of_epaddr[i] = NULL; |
| 1420 |
continue; |
| 1421 |
} |
| 1422 |
_IPATH_VDBG("looking at epid %llx\n", (unsigned long long) epid); |
| 1423 |
epaddr = psmi_epid_lookup(ptl->ep, epid); |
| 1424 |
if (epaddr != NULL) { |
| 1425 |
if (epaddr->ptl != ptl) { |
| 1426 |
array_of_errors[i] = PSM_EPID_UNREACHABLE; |
| 1427 |
array_of_epaddr[i] = NULL; |
| 1428 |
continue; |
| 1429 |
} |
| 1430 |
cstate = AMSH_CSTATE_TO_GET(epaddr); |
| 1431 |
if (cstate == AMSH_CSTATE_TO_ESTABLISHED) { |
| 1432 |
array_of_epaddr[i] = epaddr; |
| 1433 |
array_of_errors[i] = PSM_OK; |
| 1434 |
} |
| 1435 |
else { |
| 1436 |
psmi_assert(cstate == AMSH_CSTATE_TO_NONE); |
| 1437 |
array_of_errors[i] = PSM_TIMEOUT; |
| 1438 |
array_of_epaddr[i] = epaddr; |
| 1439 |
req->epid_mask[i] = AMSH_CMASK_PREREQ; |
| 1440 |
} |
| 1441 |
} |
| 1442 |
else { |
| 1443 |
req->epid_mask[i] = AMSH_CMASK_PREREQ; |
| 1444 |
array_of_epaddr[i] = NULL; |
| 1445 |
|
| 1446 |
#ifdef PSM_HAVE_SCIF |
| 1447 |
psm_error_t err = amsh_scif_setup(ptl, req->epids[i]); |
| 1448 |
if(err != PSM_OK) { |
| 1449 |
psmi_free(req->epid_mask); |
| 1450 |
psmi_free(req); |
| 1451 |
return err; |
| 1452 |
} |
| 1453 |
#endif |
| 1454 |
} |
| 1455 |
} |
| 1456 |
else { |
| 1457 |
epaddr = array_of_epaddr[i]; |
| 1458 |
psmi_assert(epaddr != NULL); |
| 1459 |
cstate = AMSH_CSTATE_TO_GET(epaddr); |
| 1460 |
if (cstate == AMSH_CSTATE_TO_ESTABLISHED) { |
| 1461 |
req->epid_mask[i] = AMSH_CMASK_PREREQ; |
| 1462 |
_IPATH_VDBG("Just set index %d to AMSH_CMASK_PREREQ\n", i); |
| 1463 |
} |
| 1464 |
|
| 1465 |
} |
| 1466 |
if (req->epid_mask[i] != AMSH_CMASK_NONE) |
| 1467 |
req->numep_left++; |
| 1468 |
} |
| 1469 |
|
| 1470 |
if (req->numep_left == 0) { |
| 1471 |
psmi_free(req->epid_mask); |
| 1472 |
psmi_free(req); |
| 1473 |
_IPATH_VDBG("Nothing to connect, bump up phase\n"); |
| 1474 |
ptl->connect_phase++; |
| 1475 |
*req_o = NULL; |
| 1476 |
return PSM_OK; |
| 1477 |
} |
| 1478 |
else { |
| 1479 |
*req_o = req; |
| 1480 |
return PSM_OK_NO_PROGRESS; |
| 1481 |
} |
| 1482 |
} |
| 1483 |
|
| 1484 |
static |
| 1485 |
psm_error_t |
| 1486 |
amsh_ep_connreq_poll(ptl_t *ptl, struct ptl_connection_req *req) |
| 1487 |
{ |
| 1488 |
int i, j, cstate, shmidx; |
| 1489 |
psm_error_t err = PSM_OK; |
| 1490 |
psm_epid_t epid; |
| 1491 |
psm_epaddr_t epaddr; |
| 1492 |
|
| 1493 |
if (req == NULL || req->isdone) |
| 1494 |
return PSM_OK; |
| 1495 |
|
| 1496 |
psmi_assert_always(ptl->ep->amsh_dirpage != NULL); |
| 1497 |
psmi_assert_always(ptl->connect_phase == req->phase); |
| 1498 |
|
| 1499 |
if (req->op == PTL_OP_DISCONNECT || req->op == PTL_OP_ABORT) { |
| 1500 |
for (i = 0; i < req->numep; i++) { |
| 1501 |
if (req->epid_mask[i] == AMSH_CMASK_NONE || |
| 1502 |
req->epid_mask[i] == AMSH_CMASK_DONE) |
| 1503 |
continue; |
| 1504 |
|
| 1505 |
epaddr = req->epaddr[i]; |
| 1506 |
psmi_assert(epaddr != NULL); |
| 1507 |
if (req->epid_mask[i] == AMSH_CMASK_PREREQ) { |
| 1508 |
int shmidx = epaddr->_shmidx; |
| 1509 |
#ifdef PSM_HAVE_SCIF |
| 1510 |
if (shmidx < PTL_AMSH_MAX_LOCAL_PROCS) { |
| 1511 |
#endif |
| 1512 |
|
| 1513 |
pthread_mutex_lock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 1514 |
if (ptl->ep->amsh_dirpage->shmidx_map_epid[shmidx] != epaddr->epid) { |
| 1515 |
req->numep_left--; |
| 1516 |
req->epid_mask[i] = AMSH_CMASK_DONE; |
| 1517 |
AMSH_CSTATE_TO_SET(epaddr, NONE); |
| 1518 |
} |
| 1519 |
pthread_mutex_unlock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 1520 |
#ifdef PSM_HAVE_SCIF |
| 1521 |
} |
| 1522 |
#endif |
| 1523 |
} |
| 1524 |
|
| 1525 |
if (req->epid_mask[i] == AMSH_CMASK_PREREQ) { |
| 1526 |
req->args[0].u32w0 = PSMI_AM_DISC_REQ; |
| 1527 |
req->args[0].u32w1 = ptl->connect_phase; |
| 1528 |
req->args[1].u64w0 = (uint64_t) ptl->epid; |
| 1529 |
req->args[2].u32w0 = PSMI_VERNO; |
| 1530 |
req->args[2].u32w1 = PSM_OK; |
| 1531 |
req->args[3].u64w0 = (uint64_t)(uintptr_t)&req->errors[i]; |
| 1532 |
psmi_amsh_short_request(ptl, epaddr, |
| 1533 |
amsh_conn_handler_hidx, |
| 1534 |
req->args, 4, NULL, 0, 0); |
| 1535 |
req->epid_mask[i] = AMSH_CMASK_POSTREQ; |
| 1536 |
} |
| 1537 |
else if (req->epid_mask[i] == AMSH_CMASK_POSTREQ) { |
| 1538 |
cstate = AMSH_CSTATE_TO_GET(epaddr); |
| 1539 |
if (cstate == AMSH_CSTATE_TO_DISC_REPLIED) { |
| 1540 |
req->numep_left--; |
| 1541 |
req->epid_mask[i] = AMSH_CMASK_DONE; |
| 1542 |
AMSH_CSTATE_TO_SET(epaddr, NONE); |
| 1543 |
} |
| 1544 |
} |
| 1545 |
} |
| 1546 |
} |
| 1547 |
else { |
| 1548 |
|
| 1549 |
int n_prereq = 0; |
| 1550 |
for (i = 0; i < req->numep; i++) { |
| 1551 |
int cstate; |
| 1552 |
if (req->epid_mask[i] != AMSH_CMASK_POSTREQ) { |
| 1553 |
if (req->epid_mask[i] == AMSH_CMASK_PREREQ) |
| 1554 |
n_prereq++; |
| 1555 |
continue; |
| 1556 |
} |
| 1557 |
epaddr = req->epaddr[i]; |
| 1558 |
psmi_assert(epaddr != NULL); |
| 1559 |
cstate = AMSH_CSTATE_TO_GET(epaddr); |
| 1560 |
if (cstate == AMSH_CSTATE_TO_REPLIED) { |
| 1561 |
req->numep_left--; |
| 1562 |
AMSH_CSTATE_TO_SET(epaddr, ESTABLISHED); |
| 1563 |
req->epid_mask[i] = AMSH_CMASK_DONE; |
| 1564 |
continue; |
| 1565 |
} |
| 1566 |
} |
| 1567 |
if (n_prereq > 0) { |
| 1568 |
char buf[32]; |
| 1569 |
uint16_t their_verno; |
| 1570 |
|
| 1571 |
psmi_assert(req->numep_left > 0); |
| 1572 |
|
| 1573 |
|
| 1574 |
pthread_mutex_lock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 1575 |
for (i = 0; i < req->numep; i++) { |
| 1576 |
if (req->epid_mask[i] != AMSH_CMASK_PREREQ) |
| 1577 |
continue; |
| 1578 |
epid = req->epids[i]; |
| 1579 |
epaddr = req->epaddr[i]; |
| 1580 |
|
| 1581 |
#if PSM_HAVE_SCIF |
| 1582 |
|
| 1583 |
int nodeid = (int)((epid>>48)&0xff); |
| 1584 |
if (nodeid != ptl->ep->scif_mynodeid) { |
| 1585 |
int peeridx = (int)((epid>>56)&0xff); |
| 1586 |
|
| 1587 |
|
| 1588 |
if(nodeid < ptl->ep->scif_mynodeid) { |
| 1589 |
shmidx = |
| 1590 |
(nodeid + 1) * PTL_AMSH_MAX_LOCAL_PROCS + peeridx; |
| 1591 |
} else { |
| 1592 |
shmidx = nodeid * PTL_AMSH_MAX_LOCAL_PROCS + peeridx; |
| 1593 |
} |
| 1594 |
|
| 1595 |
psmi_assert(shmidx >= PTL_AMSH_MAX_LOCAL_PROCS); |
| 1596 |
their_verno = ptl->ep->amsh_qdir[shmidx].amsh_verno; |
| 1597 |
} else |
| 1598 |
#endif |
| 1599 |
{ |
| 1600 |
|
| 1601 |
for (shmidx = -1, j = 0; j <= |
| 1602 |
ptl->ep->amsh_dirpage->max_idx; j++) { |
| 1603 |
|
| 1604 |
if (ptl->ep->amsh_dirpage->shmidx_map_epid[j] == epid) { |
| 1605 |
shmidx = j; |
| 1606 |
break; |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
if (shmidx == -1) |
| 1611 |
continue; |
| 1612 |
their_verno = ptl->ep->amsh_dirpage->psm_verno[shmidx]; |
| 1613 |
} |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
if (!psmi_verno_isinteroperable(their_verno)) { |
| 1618 |
snprintf(buf,sizeof buf, "%d.%d", |
| 1619 |
PSMI_VERNO_GET_MAJOR(their_verno), |
| 1620 |
PSMI_VERNO_GET_MINOR(their_verno)); |
| 1621 |
|
| 1622 |
_IPATH_INFO( |
| 1623 |
"Local endpoint id %" PRIx64 " has version %s " |
| 1624 |
"which is not supported by library version %d.%d", |
| 1625 |
epid, buf, PSM_VERNO_MAJOR, PSM_VERNO_MINOR); |
| 1626 |
req->errors[i] = PSM_EPID_INVALID_VERSION; |
| 1627 |
req->numep_left--; |
| 1628 |
req->epid_mask[i] = AMSH_CMASK_DONE; |
| 1629 |
continue; |
| 1630 |
} |
| 1631 |
|
| 1632 |
if (epaddr != NULL) { |
| 1633 |
psmi_assert(epaddr->_shmidx == shmidx); |
| 1634 |
} |
| 1635 |
else if ((epaddr = psmi_epid_lookup(ptl->ep, epid)) == NULL) { |
| 1636 |
if ((err = amsh_epaddr_add(ptl, epid, shmidx, &epaddr))) { |
| 1637 |
pthread_mutex_unlock( |
| 1638 |
(pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 1639 |
return err; |
| 1640 |
} |
| 1641 |
} |
| 1642 |
|
| 1643 |
req->epaddr[i] = epaddr; |
| 1644 |
req->args[0].u32w0 = PSMI_AM_CONN_REQ; |
| 1645 |
req->args[0].u32w1 = ptl->connect_phase; |
| 1646 |
req->args[1].u64w0 = (uint64_t) ptl->epid; |
| 1647 |
req->args[2].u32w0 = PSMI_VERNO; |
| 1648 |
req->args[2].u32w1 = PSM_OK; |
| 1649 |
req->args[3].u64w0 = (uint64_t)(uintptr_t)&req->errors[i]; |
| 1650 |
req->epid_mask[i] = AMSH_CMASK_POSTREQ; |
| 1651 |
psmi_amsh_short_request(ptl, epaddr, amsh_conn_handler_hidx, |
| 1652 |
req->args, 4, NULL, 0, 0); |
| 1653 |
_IPATH_PRDBG("epaddr=%p, epid=%" PRIx64 " at shmidx=%d\n", |
| 1654 |
epaddr, epid, shmidx); |
| 1655 |
} |
| 1656 |
pthread_mutex_unlock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 1657 |
} |
| 1658 |
} |
| 1659 |
|
| 1660 |
if (req->numep_left == 0) { |
| 1661 |
req->isdone = 1; |
| 1662 |
return PSM_OK; |
| 1663 |
} |
| 1664 |
else { |
| 1665 |
sched_yield(); |
| 1666 |
return PSM_OK_NO_PROGRESS; |
| 1667 |
} |
| 1668 |
} |
| 1669 |
|
| 1670 |
static |
| 1671 |
psm_error_t |
| 1672 |
amsh_ep_connreq_fini(ptl_t *ptl, struct ptl_connection_req *req) |
| 1673 |
{ |
| 1674 |
psm_error_t err = PSM_OK; |
| 1675 |
int i; |
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
if (req == NULL) |
| 1680 |
return PSM_OK; |
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
ptl->connect_phase++; |
| 1685 |
|
| 1686 |
|
| 1687 |
for (i = 0; i < req->numep; i++) { |
| 1688 |
if (req->epid_mask[i] == AMSH_CMASK_NONE) |
| 1689 |
continue; |
| 1690 |
else if (req->epid_mask[i] == AMSH_CMASK_POSTREQ) { |
| 1691 |
int cstate; |
| 1692 |
req->epid_mask[i] = AMSH_CMASK_DONE; |
| 1693 |
cstate = AMSH_CSTATE_TO_GET(req->epaddr[i]); |
| 1694 |
if (cstate == AMSH_CSTATE_TO_REPLIED) { |
| 1695 |
req->numep_left--; |
| 1696 |
AMSH_CSTATE_TO_SET(req->epaddr[i], ESTABLISHED); |
| 1697 |
} |
| 1698 |
else { |
| 1699 |
req->errors[i] = PSM_TIMEOUT; |
| 1700 |
} |
| 1701 |
} |
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
else if (req->epid_mask[i] == AMSH_CMASK_PREREQ) { |
| 1706 |
req->errors[i] = PSM_TIMEOUT; |
| 1707 |
req->numep_left--; |
| 1708 |
req->epaddr[i] = NULL; |
| 1709 |
req->epid_mask[i] = AMSH_CMASK_DONE; |
| 1710 |
} |
| 1711 |
} |
| 1712 |
|
| 1713 |
|
| 1714 |
for (i = 0; i < req->numep; i++) { |
| 1715 |
if (req->epid_mask[i] == AMSH_CMASK_NONE) |
| 1716 |
continue; |
| 1717 |
psmi_assert(req->epid_mask[i] == AMSH_CMASK_DONE); |
| 1718 |
|
| 1719 |
err = psmi_error_cmp(err, req->errors[i]); |
| 1720 |
|
| 1721 |
|
| 1722 |
} |
| 1723 |
|
| 1724 |
psmi_free(req->epid_mask); |
| 1725 |
psmi_free(req); |
| 1726 |
|
| 1727 |
return err; |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
#define CONNREQ_ZERO_POLLS_BEFORE_YIELD 20 |
| 1733 |
static |
| 1734 |
psm_error_t |
| 1735 |
amsh_ep_connreq_wrap(ptl_t *ptl, int op, |
| 1736 |
int numep, |
| 1737 |
const psm_epid_t *array_of_epid, |
| 1738 |
const int array_of_epid_mask[], |
| 1739 |
psm_error_t *array_of_errors, |
| 1740 |
psm_epaddr_t *array_of_epaddr, |
| 1741 |
uint64_t timeout_ns) |
| 1742 |
{ |
| 1743 |
psm_error_t err; |
| 1744 |
uint64_t t_start; |
| 1745 |
struct ptl_connection_req *req = NULL; |
| 1746 |
int num_polls_noprogress = 0; |
| 1747 |
static int shm_polite_attach = -1; |
| 1748 |
|
| 1749 |
if (shm_polite_attach == -1) { |
| 1750 |
char *p = getenv("PSM_SHM_POLITE_ATTACH"); |
| 1751 |
if (p && *p && atoi(p) != 0) { |
| 1752 |
fprintf(stderr, "%s: Using Polite SHM segment attach\n", |
| 1753 |
psmi_gethostname()); |
| 1754 |
shm_polite_attach = 1; |
| 1755 |
} |
| 1756 |
shm_polite_attach = 0; |
| 1757 |
} |
| 1758 |
|
| 1759 |
|
| 1760 |
err = amsh_ep_connreq_init(ptl, op, numep, |
| 1761 |
array_of_epid, array_of_epid_mask, array_of_errors, |
| 1762 |
array_of_epaddr, &req); |
| 1763 |
if (err != PSM_OK_NO_PROGRESS) |
| 1764 |
|
| 1765 |
return err; |
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
t_start = get_cycles(); |
| 1772 |
do { |
| 1773 |
psmi_poll_internal(ptl->ep, 1); |
| 1774 |
err = amsh_ep_connreq_poll(ptl, req); |
| 1775 |
if (err == PSM_OK) |
| 1776 |
break; |
| 1777 |
else if (err != PSM_OK_NO_PROGRESS) { |
| 1778 |
psmi_free(req->epid_mask); |
| 1779 |
psmi_free(req); |
| 1780 |
goto fail; |
| 1781 |
} else if (shm_polite_attach && |
| 1782 |
++num_polls_noprogress == CONNREQ_ZERO_POLLS_BEFORE_YIELD) { |
| 1783 |
num_polls_noprogress = 0; |
| 1784 |
PSMI_PYIELD(); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
while (psmi_cycles_left(t_start, timeout_ns)); |
| 1788 |
|
| 1789 |
err = amsh_ep_connreq_fini(ptl, req); |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
#if 0 |
| 1798 |
if(op == PTL_OP_CONNECT) { |
| 1799 |
while(ptl->connect_to > ptl->connect_from) { |
| 1800 |
psmi_poll_internal(ptl->ep, 1); |
| 1801 |
} |
| 1802 |
} else { |
| 1803 |
while(ptl->connect_to < ptl->connect_from) { |
| 1804 |
psmi_poll_internal(ptl->ep, 1); |
| 1805 |
} |
| 1806 |
} |
| 1807 |
#endif |
| 1808 |
|
| 1809 |
fail: |
| 1810 |
return err; |
| 1811 |
} |
| 1812 |
|
| 1813 |
static |
| 1814 |
psm_error_t |
| 1815 |
amsh_ep_connect(ptl_t *ptl, |
| 1816 |
int numep, |
| 1817 |
const psm_epid_t *array_of_epid, |
| 1818 |
const int array_of_epid_mask[], |
| 1819 |
psm_error_t *array_of_errors, |
| 1820 |
psm_epaddr_t *array_of_epaddr, |
| 1821 |
uint64_t timeout_ns) |
| 1822 |
{ |
| 1823 |
return amsh_ep_connreq_wrap(ptl, PTL_OP_CONNECT, numep, array_of_epid, |
| 1824 |
array_of_epid_mask, array_of_errors, |
| 1825 |
array_of_epaddr, timeout_ns); |
| 1826 |
} |
| 1827 |
|
| 1828 |
static |
| 1829 |
psm_error_t |
| 1830 |
amsh_ep_disconnect(ptl_t *ptl, int force, int numep, |
| 1831 |
const psm_epaddr_t array_of_epaddr[], |
| 1832 |
const int array_of_epaddr_mask[], |
| 1833 |
psm_error_t array_of_errors[], |
| 1834 |
uint64_t timeout_ns) |
| 1835 |
{ |
| 1836 |
return amsh_ep_connreq_wrap(ptl, force ? PTL_OP_ABORT : PTL_OP_DISCONNECT, |
| 1837 |
numep, NULL, array_of_epaddr_mask, array_of_errors, |
| 1838 |
(psm_epaddr_t *) array_of_epaddr, timeout_ns); |
| 1839 |
} |
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
static |
| 1846 |
am_pkt_short_t* |
| 1847 |
am_ctl_getslot_pkt_inner(struct amsh_qtail_info* tailinfo, |
| 1848 |
volatile am_ctl_qhdr_t *shq, |
| 1849 |
am_pkt_short_t *pkt0) |
| 1850 |
{ |
| 1851 |
am_pkt_short_t* pkt; |
| 1852 |
uint32_t idx; |
| 1853 |
|
| 1854 |
|
| 1855 |
pthread_spin_lock(&tailinfo->lock); |
| 1856 |
idx = tailinfo->tail; |
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
pkt = (void*)((uintptr_t)pkt0 + idx * shq->elem_sz); |
| 1861 |
if(pkt->flag == QFREE) { |
| 1862 |
ips_sync_reads(); |
| 1863 |
pkt->flag = QUSED; |
| 1864 |
|
| 1865 |
tailinfo->tail += 1; |
| 1866 |
if(tailinfo->tail == shq->elem_cnt) { |
| 1867 |
tailinfo->tail = 0; |
| 1868 |
} |
| 1869 |
} else { |
| 1870 |
pkt = NULL; |
| 1871 |
} |
| 1872 |
pthread_spin_unlock(&tailinfo->lock); |
| 1873 |
|
| 1874 |
return pkt; |
| 1875 |
} |
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
#if 0 |
| 1880 |
#undef CSWAP |
| 1881 |
|
| 1882 |
PSMI_ALWAYS_INLINE( |
| 1883 |
int32_t |
| 1884 |
cswap(volatile uint32_t *p, uint32_t old_value, uint32_t new_value)) |
| 1885 |
{ |
| 1886 |
asm volatile ("lock cmpxchg %2, %0" : |
| 1887 |
"+m" (*p), "+a" (old_value) : |
| 1888 |
"r" (new_value) : |
| 1889 |
"memory"); |
| 1890 |
return old_value; |
| 1891 |
} |
| 1892 |
|
| 1893 |
PSMI_ALWAYS_INLINE( |
| 1894 |
am_pkt_short_t * |
| 1895 |
am_ctl_getslot_pkt_inner(volatile am_ctl_qhdr_t *shq, am_pkt_short_t *pkt0) |
| 1896 |
) |
| 1897 |
{ |
| 1898 |
am_pkt_short_t *pkt; |
| 1899 |
uint32_t idx; |
| 1900 |
#ifndef CSWAP |
| 1901 |
pthread_spin_lock(&shq->lock); |
| 1902 |
idx = shq->tail; |
| 1903 |
pkt = (am_pkt_short_t *)((uintptr_t) pkt0 + idx * shq->elem_sz); |
| 1904 |
if (pkt->flag == QFREE) { |
| 1905 |
ips_sync_reads(); |
| 1906 |
pkt->flag = QUSED; |
| 1907 |
shq->tail += 1; |
| 1908 |
if (shq->tail == shq->elem_cnt) |
| 1909 |
shq->tail = 0; |
| 1910 |
} else { |
| 1911 |
pkt = NULL; |
| 1912 |
} |
| 1913 |
pthread_spin_unlock(&shq->lock); |
| 1914 |
#else |
| 1915 |
uint32_t idx_next; |
| 1916 |
do { |
| 1917 |
idx = shq->tail; |
| 1918 |
idx_next = (idx+1 == shq->elem_cnt) ? 0 : idx+1; |
| 1919 |
} while (cswap(&shq->tail, idx, idx_next) != idx); |
| 1920 |
|
| 1921 |
pkt = (am_pkt_short_t *)((uintptr_t) pkt0 + idx * shq->elem_sz); |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
while (cswap(&pkt->flag, QFREE, QUSED) != QFREE) |
| 1926 |
; |
| 1927 |
#endif |
| 1928 |
return pkt; |
| 1929 |
} |
| 1930 |
#endif |
| 1931 |
|
| 1932 |
|
| 1933 |
#define am_ctl_getslot_bulkpkt_inner(shq,pkt0) ((am_pkt_bulk_t *) \ |
| 1934 |
am_ctl_getslot_pkt_inner(shq,(am_pkt_short_t *)(pkt0))) |
| 1935 |
|
| 1936 |
PSMI_ALWAYS_INLINE( |
| 1937 |
am_pkt_short_t * |
| 1938 |
am_ctl_getslot_pkt(ptl_t *ptl, int shmidx, int is_reply) |
| 1939 |
) |
| 1940 |
{ |
| 1941 |
struct amsh_qtail_info* tailinfo; |
| 1942 |
volatile am_ctl_qhdr_t *shq; |
| 1943 |
am_pkt_short_t *pkt0; |
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
#ifdef PSM_HAVE_SCIF |
| 1950 |
if(shmidx >= PTL_AMSH_MAX_LOCAL_PROCS && |
| 1951 |
ptl->ep->amsh_qdir[shmidx].amsh_epd[0] == 0) { |
| 1952 |
if(amsh_scif_setup(ptl, ptl->ep->amsh_qdir[shmidx].amsh_epid) |
| 1953 |
!= PSM_OK) { |
| 1954 |
psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR, |
| 1955 |
"am_ctl_getslot_remote(): amsh_scif_setup failed"); |
| 1956 |
} |
| 1957 |
} |
| 1958 |
#endif |
| 1959 |
|
| 1960 |
if(!is_reply) { |
| 1961 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].reqFifoShort; |
| 1962 |
shq = &(ptl->ep->amsh_qdir[shmidx].qreqH->shortq); |
| 1963 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qreqFifoShort; |
| 1964 |
} else { |
| 1965 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].repFifoShort; |
| 1966 |
shq = &(ptl->ep->amsh_qdir[shmidx].qrepH->shortq); |
| 1967 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qrepFifoShort; |
| 1968 |
} |
| 1969 |
|
| 1970 |
return am_ctl_getslot_pkt_inner(tailinfo, shq, pkt0); |
| 1971 |
} |
| 1972 |
|
| 1973 |
PSMI_ALWAYS_INLINE( |
| 1974 |
am_pkt_bulk_t * |
| 1975 |
am_ctl_getslot_med(ptl_t *ptl, int shmidx, int is_reply) |
| 1976 |
) |
| 1977 |
{ |
| 1978 |
struct amsh_qtail_info* tailinfo; |
| 1979 |
volatile am_ctl_qhdr_t *shq; |
| 1980 |
am_pkt_bulk_t *pkt0; |
| 1981 |
|
| 1982 |
if(!is_reply) { |
| 1983 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].reqFifoMed; |
| 1984 |
shq = &(ptl->ep->amsh_qdir[shmidx].qreqH->medbulkq); |
| 1985 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qreqFifoMed; |
| 1986 |
} else { |
| 1987 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].repFifoMed; |
| 1988 |
shq = &(ptl->ep->amsh_qdir[shmidx].qrepH->medbulkq); |
| 1989 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qrepFifoMed; |
| 1990 |
} |
| 1991 |
|
| 1992 |
return (am_pkt_bulk_t*)am_ctl_getslot_pkt_inner(tailinfo, |
| 1993 |
shq, (am_pkt_short_t*)pkt0); |
| 1994 |
} |
| 1995 |
|
| 1996 |
PSMI_ALWAYS_INLINE( |
| 1997 |
am_pkt_bulk_t * |
| 1998 |
am_ctl_getslot_long(ptl_t *ptl, int shmidx, int is_reply) |
| 1999 |
) |
| 2000 |
{ |
| 2001 |
struct amsh_qtail_info* tailinfo; |
| 2002 |
volatile am_ctl_qhdr_t *shq; |
| 2003 |
am_pkt_bulk_t *pkt0; |
| 2004 |
|
| 2005 |
if(!is_reply) { |
| 2006 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].reqFifoLong; |
| 2007 |
shq = &(ptl->ep->amsh_qdir[shmidx].qreqH->longbulkq); |
| 2008 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qreqFifoLong; |
| 2009 |
} else { |
| 2010 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].repFifoLong; |
| 2011 |
shq = &(ptl->ep->amsh_qdir[shmidx].qrepH->longbulkq); |
| 2012 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qrepFifoLong; |
| 2013 |
} |
| 2014 |
|
| 2015 |
return (am_pkt_bulk_t*)am_ctl_getslot_pkt_inner(tailinfo, |
| 2016 |
shq, (am_pkt_short_t*)pkt0); |
| 2017 |
} |
| 2018 |
|
| 2019 |
PSMI_ALWAYS_INLINE( |
| 2020 |
am_pkt_bulk_t * |
| 2021 |
am_ctl_getslot_huge(ptl_t *ptl, int shmidx, int is_reply) |
| 2022 |
) |
| 2023 |
{ |
| 2024 |
struct amsh_qtail_info* tailinfo; |
| 2025 |
volatile am_ctl_qhdr_t *shq; |
| 2026 |
am_pkt_bulk_t *pkt0; |
| 2027 |
|
| 2028 |
if(!is_reply) { |
| 2029 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].reqFifoHuge; |
| 2030 |
shq = &(ptl->ep->amsh_qdir[shmidx].qreqH->hugebulkq); |
| 2031 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qreqFifoHuge; |
| 2032 |
} else { |
| 2033 |
tailinfo = &ptl->ep->amsh_dirpage->qtails[shmidx].repFifoHuge; |
| 2034 |
shq = &(ptl->ep->amsh_qdir[shmidx].qrepH->hugebulkq); |
| 2035 |
pkt0 = ptl->ep->amsh_qdir[shmidx].qrepFifoHuge; |
| 2036 |
} |
| 2037 |
|
| 2038 |
return (am_pkt_bulk_t*)am_ctl_getslot_pkt_inner(tailinfo, |
| 2039 |
shq, (am_pkt_short_t*)pkt0); |
| 2040 |
} |
| 2041 |
|
| 2042 |
psmi_handlertab_t psmi_allhandlers[] = { |
| 2043 |
{ 0 }, |
| 2044 |
{ amsh_conn_handler }, |
| 2045 |
{ psmi_am_mq_handler }, |
| 2046 |
{ psmi_am_mq_handler_data }, |
| 2047 |
{ psmi_am_mq_handler_rtsmatch }, |
| 2048 |
{ psmi_am_mq_handler_rtsdone }, |
| 2049 |
{ psmi_am_handler } |
| 2050 |
}; |
| 2051 |
|
| 2052 |
PSMI_ALWAYS_INLINE( |
| 2053 |
void |
| 2054 |
advance_head(volatile am_ctl_qshort_cache_t *hdr)) |
| 2055 |
{ |
| 2056 |
QMARKFREE(hdr->head); |
| 2057 |
hdr->head++; |
| 2058 |
if (hdr->head == hdr->end) |
| 2059 |
hdr->head = hdr->base; |
| 2060 |
} |
| 2061 |
|
| 2062 |
#define AMSH_ZERO_POLLS_BEFORE_YIELD 64 |
| 2063 |
#define AMSH_POLLS_BEFORE_PSM_POLL 16 |
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
PSMI_ALWAYS_INLINE( |
| 2073 |
psm_error_t |
| 2074 |
amsh_poll_internal_inner(ptl_t *ptl, int replyonly, int is_internal)) |
| 2075 |
{ |
| 2076 |
psm_error_t err = PSM_OK_NO_PROGRESS; |
| 2077 |
|
| 2078 |
|
| 2079 |
#ifdef PSM_HAVE_SCIF |
| 2080 |
int node; |
| 2081 |
int nnodes = ptl->ep->scif_nnodes; |
| 2082 |
|
| 2083 |
for(node = 0; node < nnodes; node++) { |
| 2084 |
if (!QISEMPTY(ptl->repH[node].head->flag)) { |
| 2085 |
do { |
| 2086 |
ips_sync_reads(); |
| 2087 |
process_packet(ptl, (am_pkt_short_t *) ptl->repH[node].head, 0); |
| 2088 |
advance_head(&ptl->repH[node]); |
| 2089 |
err = PSM_OK; |
| 2090 |
} while (!QISEMPTY(ptl->repH[node].head->flag)); |
| 2091 |
} |
| 2092 |
} |
| 2093 |
#else |
| 2094 |
if (!QISEMPTY(ptl->repH[0].head->flag)) { |
| 2095 |
do { |
| 2096 |
ips_sync_reads(); |
| 2097 |
process_packet(ptl, (am_pkt_short_t *) ptl->repH[0].head, 0); |
| 2098 |
advance_head(&ptl->repH[0]); |
| 2099 |
err = PSM_OK; |
| 2100 |
} while (!QISEMPTY(ptl->repH[0].head->flag)); |
| 2101 |
} |
| 2102 |
#endif |
| 2103 |
|
| 2104 |
if (!replyonly) { |
| 2105 |
|
| 2106 |
|
| 2107 |
if (!is_internal && ptl->psmi_am_reqq_fifo.first != NULL) { |
| 2108 |
psmi_am_reqq_drain(ptl); |
| 2109 |
err = PSM_OK; |
| 2110 |
} |
| 2111 |
|
| 2112 |
#ifdef PSM_HAVE_SCIF |
| 2113 |
for(node = 0; node < nnodes; node++) { |
| 2114 |
if (!QISEMPTY(ptl->reqH[node].head->flag)) { |
| 2115 |
do { |
| 2116 |
ips_sync_reads(); |
| 2117 |
process_packet(ptl, |
| 2118 |
(am_pkt_short_t *) ptl->reqH[node].head, 1); |
| 2119 |
advance_head(&ptl->reqH[node]); |
| 2120 |
err = PSM_OK; |
| 2121 |
} while (!QISEMPTY(ptl->reqH[node].head->flag)); |
| 2122 |
} |
| 2123 |
} |
| 2124 |
#else |
| 2125 |
if (!QISEMPTY(ptl->reqH[0].head->flag)) { |
| 2126 |
do { |
| 2127 |
ips_sync_reads(); |
| 2128 |
process_packet(ptl, |
| 2129 |
(am_pkt_short_t *) ptl->reqH[0].head, 1); |
| 2130 |
advance_head(&ptl->reqH[0]); |
| 2131 |
err = PSM_OK; |
| 2132 |
} while (!QISEMPTY(ptl->reqH[0].head->flag)); |
| 2133 |
} |
| 2134 |
#endif |
| 2135 |
} |
| 2136 |
|
| 2137 |
if (is_internal) { |
| 2138 |
if (err == PSM_OK) |
| 2139 |
ptl->zero_polls = 0; |
| 2140 |
else if (++ptl->zero_polls == AMSH_ZERO_POLLS_BEFORE_YIELD) { |
| 2141 |
|
| 2142 |
sched_yield(); |
| 2143 |
ptl->zero_polls = 0; |
| 2144 |
} |
| 2145 |
|
| 2146 |
if (++ptl->amsh_only_polls == AMSH_POLLS_BEFORE_PSM_POLL) { |
| 2147 |
psmi_poll_internal(ptl->ep, 0); |
| 2148 |
ptl->amsh_only_polls = 0; |
| 2149 |
} |
| 2150 |
} |
| 2151 |
return err; |
| 2152 |
} |
| 2153 |
|
| 2154 |
|
| 2155 |
static |
| 2156 |
psm_error_t |
| 2157 |
amsh_poll_internal(ptl_t *ptl, int replyonly) |
| 2158 |
{ |
| 2159 |
return amsh_poll_internal_inner(ptl, replyonly, 1); |
| 2160 |
} |
| 2161 |
|
| 2162 |
#ifdef PSM_PROFILE |
| 2163 |
#define AMSH_POLL_UNTIL(ptl,isreply,cond) do { \ |
| 2164 |
PSMI_PROFILE_BLOCK(); \ |
| 2165 |
while (!(cond)) { \ |
| 2166 |
PSMI_PROFILE_REBLOCK( \ |
| 2167 |
amsh_poll_internal(ptl,isreply) == \ |
| 2168 |
PSM_OK_NO_PROGRESS); \ |
| 2169 |
} \ |
| 2170 |
PSMI_PROFILE_UNBLOCK(); \ |
| 2171 |
} while (0) |
| 2172 |
#else |
| 2173 |
#define AMSH_POLL_UNTIL(ptl,isreply,cond) do { \ |
| 2174 |
while (!(cond)) { \ |
| 2175 |
amsh_poll_internal(ptl,isreply); \ |
| 2176 |
} \ |
| 2177 |
} while (0) |
| 2178 |
#endif |
| 2179 |
|
| 2180 |
static |
| 2181 |
psm_error_t |
| 2182 |
amsh_poll(ptl_t *ptl, int replyonly) |
| 2183 |
{ |
| 2184 |
return amsh_poll_internal_inner(ptl, replyonly, 0); |
| 2185 |
} |
| 2186 |
|
| 2187 |
PSMI_ALWAYS_INLINE( |
| 2188 |
void |
| 2189 |
am_send_pkt_short(ptl_t *ptl, uint32_t destidx, uint32_t bulkidx, |
| 2190 |
uint16_t fmt, uint16_t nargs, uint16_t handleridx, |
| 2191 |
psm_amarg_t *args, const void *src, uint32_t len, int isreply)) |
| 2192 |
{ |
| 2193 |
int i; |
| 2194 |
volatile am_pkt_short_t *pkt; |
| 2195 |
|
| 2196 |
AMSH_POLL_UNTIL(ptl, isreply, |
| 2197 |
(pkt = am_ctl_getslot_pkt(ptl, destidx, isreply)) != NULL); |
| 2198 |
|
| 2199 |
#ifdef __MIC__ |
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
am_pkt_short_t lcl_pkt; |
| 2206 |
|
| 2207 |
lcl_pkt.bulkidx = bulkidx; |
| 2208 |
lcl_pkt.shmidx = ptl->ep->amsh_qdir[destidx].amsh_shmidx; |
| 2209 |
lcl_pkt.type = fmt; |
| 2210 |
lcl_pkt.nargs = nargs; |
| 2211 |
lcl_pkt.handleridx = handleridx; |
| 2212 |
|
| 2213 |
for (i = 0; i < nargs; i++) |
| 2214 |
lcl_pkt.args[i] = args[i]; |
| 2215 |
|
| 2216 |
if (fmt == AMFMT_SHORT_INLINE) |
| 2217 |
mq_copy_tiny((uint32_t *) &lcl_pkt.args[nargs], (uint32_t *) src, len); |
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
lcl_pkt.flag = QREADY; |
| 2222 |
|
| 2223 |
|
| 2224 |
memcpy((void*)pkt, &lcl_pkt, sizeof(am_pkt_short_t)); |
| 2225 |
|
| 2226 |
#else |
| 2227 |
|
| 2228 |
pkt->bulkidx = bulkidx; |
| 2229 |
pkt->shmidx = ptl->ep->amsh_qdir[destidx].amsh_shmidx; |
| 2230 |
pkt->type = fmt; |
| 2231 |
pkt->nargs = nargs; |
| 2232 |
pkt->handleridx = handleridx; |
| 2233 |
|
| 2234 |
for (i = 0; i < nargs; i++) |
| 2235 |
pkt->args[i] = args[i]; |
| 2236 |
|
| 2237 |
if (fmt == AMFMT_SHORT_INLINE) |
| 2238 |
mq_copy_tiny((uint32_t *) &pkt->args[nargs], (uint32_t *) src, len); |
| 2239 |
|
| 2240 |
QMARKREADY(pkt); |
| 2241 |
#endif |
| 2242 |
} |
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
#define ALLOCA_AS_SCRATCH 0 |
| 2248 |
|
| 2249 |
#if ALLOCA_AS_SCRATCH |
| 2250 |
static char amsh_medscratch[AMMED_SZ]; |
| 2251 |
#endif |
| 2252 |
|
| 2253 |
#ifdef __MIC__ |
| 2254 |
#define amsh_shm_copy_short memcpy |
| 2255 |
#define amsh_shm_copy_long memcpy |
| 2256 |
#define amsh_shm_copy_huge psmi_memcpyo |
| 2257 |
#else |
| 2258 |
#define amsh_shm_copy_short psmi_mq_mtucpy |
| 2259 |
#define amsh_shm_copy_long psmi_mq_mtucpy |
| 2260 |
#define amsh_shm_copy_huge psmi_memcpyo |
| 2261 |
#endif |
| 2262 |
|
| 2263 |
PSMI_ALWAYS_INLINE( |
| 2264 |
int |
| 2265 |
psmi_amsh_generic_inner(uint32_t amtype, ptl_t *ptl, psm_epaddr_t epaddr, |
| 2266 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2267 |
const void *src, size_t len, void *dst, int flags)) |
| 2268 |
{ |
| 2269 |
uint16_t type; |
| 2270 |
uint32_t bulkidx; |
| 2271 |
uint16_t hidx = (uint16_t) handler; |
| 2272 |
int destidx = epaddr->_shmidx; |
| 2273 |
int is_reply = AM_IS_REPLY(amtype); |
| 2274 |
volatile am_pkt_bulk_t *bulkpkt; |
| 2275 |
|
| 2276 |
_IPATH_VDBG("%s epaddr=%s, shmidx=%d, type=%d LOOPBACK=%s\n", |
| 2277 |
is_reply ? "reply" : "request", |
| 2278 |
psmi_epaddr_get_name(epaddr->epid), epaddr->_shmidx, amtype, |
| 2279 |
ptl->epaddr == epaddr ? "YES" : "NO"); |
| 2280 |
if (ptl->epaddr == epaddr) { |
| 2281 |
amsh_am_token_t tok; |
| 2282 |
void *bufa; |
| 2283 |
|
| 2284 |
tok.tok.epaddr_from = epaddr; |
| 2285 |
tok.ptl = ptl; |
| 2286 |
tok.mq = ptl->ep->mq; |
| 2287 |
tok.shmidx = ptl->shmidx; |
| 2288 |
if (len > 0) { |
| 2289 |
if (AM_IS_LONG(amtype)) |
| 2290 |
bufa = dst; |
| 2291 |
else { |
| 2292 |
psmi_assert_always(len <= AMMED_SZ); |
| 2293 |
#if ALLOCA_AS_SCRATCH |
| 2294 |
bufa = (void *) amsh_medscratch; |
| 2295 |
#else |
| 2296 |
bufa = alloca(len); |
| 2297 |
#endif |
| 2298 |
} |
| 2299 |
psmi_assert(bufa != NULL); |
| 2300 |
amsh_shm_copy_short((void *) bufa, src, len); |
| 2301 |
} |
| 2302 |
else |
| 2303 |
bufa = NULL; |
| 2304 |
psmi_handler_fn_t fn = |
| 2305 |
(psmi_handler_fn_t) psmi_allhandlers[hidx].fn; |
| 2306 |
fn(&tok, args, nargs, bufa, len); |
| 2307 |
|
| 2308 |
return 1; |
| 2309 |
} |
| 2310 |
|
| 2311 |
switch (amtype) { |
| 2312 |
case AMREQUEST_SHORT: |
| 2313 |
case AMREPLY_SHORT: |
| 2314 |
if (len + (nargs<<3) <= (NSHORT_ARGS<<3)) { |
| 2315 |
|
| 2316 |
type = AMFMT_SHORT_INLINE; |
| 2317 |
bulkidx = len; |
| 2318 |
} |
| 2319 |
else { |
| 2320 |
psmi_assert(len < amsh_qelemsz.qreqFifoMed); |
| 2321 |
psmi_assert(src != NULL); |
| 2322 |
type = AMFMT_SHORT; |
| 2323 |
#if 1 |
| 2324 |
AMSH_POLL_UNTIL(ptl, is_reply, |
| 2325 |
(bulkpkt = am_ctl_getslot_med(ptl, destidx, is_reply)) != NULL); |
| 2326 |
#else |
| 2327 |
|
| 2328 |
while (1) { |
| 2329 |
bulkpkt = am_ctl_getslot_med(ptl, destidx, is_reply); |
| 2330 |
if (bulkpkt == NULL) |
| 2331 |
break; |
| 2332 |
amsh_poll_internal(ptl, is_reply); |
| 2333 |
} |
| 2334 |
#endif |
| 2335 |
bulkidx = bulkpkt->idx; |
| 2336 |
bulkpkt->len = len; |
| 2337 |
_IPATH_VDBG("bulkpkt %p flag is %d from idx %d\n", |
| 2338 |
bulkpkt, bulkpkt->flag, destidx); |
| 2339 |
amsh_shm_copy_short((void*) bulkpkt->payload, src, (uint32_t) len); |
| 2340 |
QMARKREADY(bulkpkt); |
| 2341 |
} |
| 2342 |
am_send_pkt_short(ptl, destidx, bulkidx, type, nargs, hidx, |
| 2343 |
args, src, len, is_reply); |
| 2344 |
break; |
| 2345 |
|
| 2346 |
case AMREQUEST_LONG: |
| 2347 |
case AMREPLY_LONG: |
| 2348 |
{ |
| 2349 |
uint32_t bytes_left = len; |
| 2350 |
uint8_t *src_this = (uint8_t *) src; |
| 2351 |
uint8_t *dst_this = (uint8_t *) dst; |
| 2352 |
uint32_t bytes_this; |
| 2353 |
uint32_t mtu_this; |
| 2354 |
type = (bytes_left >= AMSH_HUGE_BYTES ? AMFMT_HUGE : AMFMT_LONG); |
| 2355 |
|
| 2356 |
int destidx_l = AMSH_BULK_PUSH ? destidx : ptl->shmidx; |
| 2357 |
|
| 2358 |
if (type == AMFMT_HUGE) |
| 2359 |
mtu_this = is_reply ? amsh_qpkt_max.qrepFifoHuge : |
| 2360 |
amsh_qpkt_max.qreqFifoHuge; |
| 2361 |
else |
| 2362 |
mtu_this = is_reply ? amsh_qpkt_max.qrepFifoLong : |
| 2363 |
amsh_qpkt_max.qreqFifoLong; |
| 2364 |
|
| 2365 |
_IPATH_VDBG("[long][%s] src=%p,dest=%p,len=%d,hidx=%d\n", |
| 2366 |
is_reply ? "rep" : "req", src, dst, (uint32_t)len, hidx); |
| 2367 |
|
| 2368 |
while (bytes_left) { |
| 2369 |
if (type == AMFMT_HUGE) { |
| 2370 |
bytes_this = min(bytes_left, mtu_this); |
| 2371 |
|
| 2372 |
AMSH_POLL_UNTIL(ptl, is_reply, |
| 2373 |
(bulkpkt = am_ctl_getslot_huge(ptl, destidx_l, is_reply)) != NULL); |
| 2374 |
bytes_left -= bytes_this; |
| 2375 |
if (bytes_left == 0) |
| 2376 |
type = AMFMT_HUGE_END; |
| 2377 |
bulkidx = bulkpkt->idx; |
| 2378 |
amsh_shm_copy_huge((void *) bulkpkt->payload, |
| 2379 |
src_this, bytes_this); |
| 2380 |
} |
| 2381 |
else { |
| 2382 |
bytes_this = min(bytes_left, mtu_this); |
| 2383 |
AMSH_POLL_UNTIL(ptl, is_reply, |
| 2384 |
(bulkpkt = am_ctl_getslot_long(ptl, destidx_l, is_reply)) != NULL); |
| 2385 |
bytes_left -= bytes_this; |
| 2386 |
if (bytes_left == 0) |
| 2387 |
type = AMFMT_LONG_END; |
| 2388 |
bulkidx = bulkpkt->idx; |
| 2389 |
amsh_shm_copy_long((void *) bulkpkt->payload, src_this, |
| 2390 |
bytes_this); |
| 2391 |
|
| 2392 |
} |
| 2393 |
|
| 2394 |
bulkpkt->dest = (uintptr_t) dst; |
| 2395 |
bulkpkt->dest_off = |
| 2396 |
(uint32_t)((uintptr_t)dst_this - (uintptr_t)dst); |
| 2397 |
bulkpkt->len = bytes_this; |
| 2398 |
QMARKREADY(bulkpkt); |
| 2399 |
|
| 2400 |
am_send_pkt_short(ptl, destidx, bulkidx, type, nargs, |
| 2401 |
hidx, args, NULL, 0, is_reply); |
| 2402 |
src_this += bytes_this; |
| 2403 |
dst_this += bytes_this; |
| 2404 |
} |
| 2405 |
break; |
| 2406 |
} |
| 2407 |
default: |
| 2408 |
break; |
| 2409 |
} |
| 2410 |
return 1; |
| 2411 |
} |
| 2412 |
|
| 2413 |
|
| 2414 |
int |
| 2415 |
psmi_amsh_generic(uint32_t amtype, ptl_t *ptl, psm_epaddr_t epaddr, |
| 2416 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2417 |
const void *src, size_t len, void *dst, int flags) |
| 2418 |
{ |
| 2419 |
return psmi_amsh_generic_inner(amtype,ptl,epaddr,handler,args,nargs,src,len, |
| 2420 |
dst,flags); |
| 2421 |
} |
| 2422 |
|
| 2423 |
int |
| 2424 |
psmi_amsh_short_request(ptl_t *ptl, psm_epaddr_t epaddr, |
| 2425 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2426 |
const void *src, size_t len, int flags) |
| 2427 |
{ |
| 2428 |
return psmi_amsh_generic_inner(AMREQUEST_SHORT, ptl, epaddr, handler, args, nargs, |
| 2429 |
src, len, NULL, flags); |
| 2430 |
} |
| 2431 |
|
| 2432 |
int |
| 2433 |
psmi_amsh_long_request(ptl_t *ptl, psm_epaddr_t epaddr, |
| 2434 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2435 |
const void *src, size_t len, void *dest, int flags) |
| 2436 |
{ |
| 2437 |
return psmi_amsh_generic_inner(AMREQUEST_LONG, ptl, epaddr, handler, args, nargs, |
| 2438 |
src, len, dest, flags); |
| 2439 |
} |
| 2440 |
|
| 2441 |
void |
| 2442 |
psmi_amsh_short_reply(amsh_am_token_t *tok, |
| 2443 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2444 |
const void *src, size_t len, int flags) |
| 2445 |
{ |
| 2446 |
psmi_amsh_generic_inner(AMREPLY_SHORT, tok->ptl, tok->tok.epaddr_from, |
| 2447 |
handler, args, nargs, src, len, NULL, flags); |
| 2448 |
return; |
| 2449 |
} |
| 2450 |
|
| 2451 |
void |
| 2452 |
psmi_amsh_long_reply(amsh_am_token_t *tok, |
| 2453 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2454 |
const void *src, size_t len, void *dest, int flags) |
| 2455 |
{ |
| 2456 |
psmi_amsh_generic_inner(AMREPLY_LONG, tok->ptl, tok->tok.epaddr_from, |
| 2457 |
handler, args, nargs, src, len, dest, flags); |
| 2458 |
return; |
| 2459 |
} |
| 2460 |
|
| 2461 |
void |
| 2462 |
psmi_am_reqq_init(ptl_t *ptl) |
| 2463 |
{ |
| 2464 |
ptl->psmi_am_reqq_fifo.first = NULL; |
| 2465 |
ptl->psmi_am_reqq_fifo.lastp = &ptl->psmi_am_reqq_fifo.first; |
| 2466 |
} |
| 2467 |
|
| 2468 |
psm_error_t |
| 2469 |
psmi_am_reqq_drain(ptl_t *ptl) |
| 2470 |
{ |
| 2471 |
am_reqq_t *reqn = ptl->psmi_am_reqq_fifo.first; |
| 2472 |
am_reqq_t *req; |
| 2473 |
psm_error_t err = PSM_OK_NO_PROGRESS; |
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
ptl->psmi_am_reqq_fifo.first = NULL; |
| 2479 |
ptl->psmi_am_reqq_fifo.lastp = &ptl->psmi_am_reqq_fifo.first; |
| 2480 |
|
| 2481 |
while ((req = reqn) != NULL) { |
| 2482 |
err = PSM_OK; |
| 2483 |
reqn = req->next; |
| 2484 |
_IPATH_VDBG("push of reqq=%p epaddr=%s localreq=%p remotereq=%p\n", req, |
| 2485 |
psmi_epaddr_get_hostname(req->epaddr->epid), |
| 2486 |
(void *) (uintptr_t) req->args[1].u64w0, |
| 2487 |
(void *) (uintptr_t) req->args[0].u64w0); |
| 2488 |
psmi_amsh_generic(req->amtype, req->ptl, req->epaddr, |
| 2489 |
req->handler, req->args, req->nargs, req->src, |
| 2490 |
req->len, req->dest, req->amflags); |
| 2491 |
if (req->flags & AM_FLAG_SRC_TEMP) |
| 2492 |
psmi_free(req->src); |
| 2493 |
psmi_free(req); |
| 2494 |
} |
| 2495 |
return err; |
| 2496 |
} |
| 2497 |
|
| 2498 |
void |
| 2499 |
psmi_am_reqq_add(int amtype, ptl_t *ptl, psm_epaddr_t epaddr, |
| 2500 |
psm_handler_t handler, psm_amarg_t *args, int nargs, |
| 2501 |
void *src, size_t len, void *dest, int amflags) |
| 2502 |
{ |
| 2503 |
int i; |
| 2504 |
int flags = 0; |
| 2505 |
am_reqq_t *nreq = |
| 2506 |
(am_reqq_t *) psmi_malloc(ptl->ep, UNDEFINED, sizeof(am_reqq_t)); |
| 2507 |
psmi_assert_always(nreq != NULL); |
| 2508 |
_IPATH_VDBG("alloc of reqq=%p, to epaddr=%s, ptr=%p, len=%d, " |
| 2509 |
"localreq=%p, remotereq=%p\n", nreq, |
| 2510 |
psmi_epaddr_get_hostname(epaddr->epid), dest, |
| 2511 |
(int)len, (void *) (uintptr_t) args[1].u64w0, |
| 2512 |
(void *) (uintptr_t) args[0].u64w0); |
| 2513 |
|
| 2514 |
psmi_assert(nargs <= 8); |
| 2515 |
nreq->next = NULL; |
| 2516 |
nreq->amtype = amtype; |
| 2517 |
nreq->ptl = ptl; |
| 2518 |
nreq->epaddr = epaddr; |
| 2519 |
nreq->handler = handler; |
| 2520 |
for (i = 0; i < nargs; i++) |
| 2521 |
nreq->args[i] = args[i]; |
| 2522 |
nreq->nargs = nargs; |
| 2523 |
if (AM_IS_LONG(amtype) && src != NULL && |
| 2524 |
len > 0 && !(amflags & AM_FLAG_SRC_ASYNC)) |
| 2525 |
{ |
| 2526 |
abort(); |
| 2527 |
flags |= AM_FLAG_SRC_TEMP; |
| 2528 |
nreq->src = psmi_malloc(ptl->ep, UNDEFINED, len); |
| 2529 |
psmi_assert_always(nreq->src != NULL); |
| 2530 |
amsh_shm_copy_short(nreq->src, src, len); |
| 2531 |
} |
| 2532 |
else |
| 2533 |
nreq->src = src; |
| 2534 |
nreq->len = len; |
| 2535 |
nreq->dest = dest; |
| 2536 |
nreq->amflags = amflags; |
| 2537 |
nreq->flags = flags; |
| 2538 |
|
| 2539 |
nreq->next = NULL; |
| 2540 |
*(ptl->psmi_am_reqq_fifo.lastp) = nreq; |
| 2541 |
ptl->psmi_am_reqq_fifo.lastp = &nreq->next; |
| 2542 |
} |
| 2543 |
|
| 2544 |
static |
| 2545 |
void |
| 2546 |
process_packet(ptl_t *ptl, am_pkt_short_t *pkt, int isreq) |
| 2547 |
{ |
| 2548 |
amsh_am_token_t tok; |
| 2549 |
psmi_handler_fn_t fn; |
| 2550 |
int shmidx = pkt->shmidx; |
| 2551 |
|
| 2552 |
tok.tok.epaddr_from = ptl->ep->amsh_qdir[shmidx].amsh_epaddr; |
| 2553 |
tok.ptl = ptl; |
| 2554 |
tok.mq = ptl->ep->mq; |
| 2555 |
tok.shmidx = shmidx; |
| 2556 |
|
| 2557 |
uint16_t hidx = (uint16_t) pkt->handleridx; |
| 2558 |
int myshmidx = ptl->shmidx; |
| 2559 |
int shmidx_l = AMSH_BULK_PUSH ? myshmidx : shmidx; |
| 2560 |
uint32_t bulkidx = pkt->bulkidx; |
| 2561 |
uintptr_t bulkptr; |
| 2562 |
am_pkt_bulk_t *bulkpkt; |
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
#ifdef PSM_HAVE_SCIF |
| 2572 |
int nodeid = (int)((ptl->ep->amsh_qdir[shmidx].amsh_epid >> 48) & 0xff); |
| 2573 |
#else |
| 2574 |
const int nodeid = 0; |
| 2575 |
#endif |
| 2576 |
|
| 2577 |
fn = (psmi_handler_fn_t) psmi_allhandlers[hidx].fn; |
| 2578 |
psmi_assert(fn != NULL); |
| 2579 |
psmi_assert((uintptr_t) pkt > ptl->ep->amsh_blockbase); |
| 2580 |
|
| 2581 |
if (pkt->type == AMFMT_SHORT_INLINE) { |
| 2582 |
_IPATH_VDBG("%s inline flag=%d nargs=%d from_idx=%d pkt=%p hidx=%d\n", |
| 2583 |
isreq ? "request" : "reply", |
| 2584 |
pkt->flag, pkt->nargs, shmidx, pkt, hidx); |
| 2585 |
|
| 2586 |
fn(&tok, pkt->args, pkt->nargs, pkt->length > 0 ? |
| 2587 |
(void *) &pkt->args[pkt->nargs] : NULL, pkt->length); |
| 2588 |
} |
| 2589 |
else { |
| 2590 |
int isend = 0; |
| 2591 |
switch (pkt->type) { |
| 2592 |
case AMFMT_SHORT: |
| 2593 |
if (isreq) { |
| 2594 |
bulkptr = (uintptr_t) |
| 2595 |
ptl->ep->amsh_qdir[myshmidx].qptrs[nodeid].qreqFifoMed; |
| 2596 |
bulkptr += bulkidx * amsh_qelemsz.qreqFifoMed; |
| 2597 |
} else { |
| 2598 |
bulkptr = (uintptr_t) |
| 2599 |
ptl->ep->amsh_qdir[myshmidx].qptrs[nodeid].qrepFifoMed; |
| 2600 |
bulkptr += bulkidx * amsh_qelemsz.qrepFifoMed; |
| 2601 |
} |
| 2602 |
break; |
| 2603 |
|
| 2604 |
case AMFMT_LONG_END: |
| 2605 |
isend = 1; |
| 2606 |
case AMFMT_LONG: |
| 2607 |
if (isreq) { |
| 2608 |
bulkptr = (uintptr_t) |
| 2609 |
ptl->ep->amsh_qdir[shmidx_l].qptrs[nodeid].qreqFifoLong; |
| 2610 |
bulkptr += bulkidx * amsh_qelemsz.qreqFifoLong; |
| 2611 |
} |
| 2612 |
else { |
| 2613 |
bulkptr = (uintptr_t) |
| 2614 |
ptl->ep->amsh_qdir[shmidx_l].qptrs[nodeid].qrepFifoLong; |
| 2615 |
bulkptr += bulkidx * amsh_qelemsz.qrepFifoLong; |
| 2616 |
} |
| 2617 |
break; |
| 2618 |
|
| 2619 |
case AMFMT_HUGE_END: |
| 2620 |
isend = 1; |
| 2621 |
case AMFMT_HUGE: |
| 2622 |
if (isreq) { |
| 2623 |
bulkptr = (uintptr_t) ptl->ep->amsh_qdir[shmidx_l].qptrs[nodeid].qreqFifoHuge; |
| 2624 |
bulkptr += bulkidx * amsh_qelemsz.qreqFifoHuge; |
| 2625 |
} |
| 2626 |
else { |
| 2627 |
bulkptr = (uintptr_t) ptl->ep->amsh_qdir[shmidx_l].qptrs[nodeid].qrepFifoHuge; |
| 2628 |
bulkptr += bulkidx * amsh_qelemsz.qrepFifoHuge; |
| 2629 |
} |
| 2630 |
break; |
| 2631 |
default: |
| 2632 |
bulkptr = 0; |
| 2633 |
psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR, |
| 2634 |
"Unknown/unhandled packet type 0x%x", pkt->type); |
| 2635 |
return; |
| 2636 |
} |
| 2637 |
|
| 2638 |
bulkpkt = (am_pkt_bulk_t *) bulkptr; |
| 2639 |
_IPATH_VDBG("ep=%p mq=%p type=%d bulkidx=%d flag=%d/%d nargs=%d " |
| 2640 |
"from_idx=%d pkt=%p/%p hidx=%d\n", |
| 2641 |
ptl->ep, ptl->ep->mq, pkt->type, bulkidx, pkt->flag, |
| 2642 |
bulkpkt->flag, pkt->nargs, shmidx, pkt, bulkpkt, hidx); |
| 2643 |
psmi_assert(bulkpkt->flag == QREADY); |
| 2644 |
if (pkt->type == AMFMT_SHORT) { |
| 2645 |
fn(&tok, pkt->args, pkt->nargs, |
| 2646 |
(void *) bulkpkt->payload, bulkpkt->len); |
| 2647 |
QMARKFREE(bulkpkt); |
| 2648 |
} |
| 2649 |
else { |
| 2650 |
if (pkt->type == AMFMT_HUGE || pkt->type == AMFMT_HUGE_END) |
| 2651 |
amsh_shm_copy_huge((void *) (bulkpkt->dest + bulkpkt->dest_off), |
| 2652 |
bulkpkt->payload, bulkpkt->len); |
| 2653 |
else |
| 2654 |
amsh_shm_copy_long((void *) (bulkpkt->dest + bulkpkt->dest_off), |
| 2655 |
bulkpkt->payload, bulkpkt->len); |
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
if (isend) { |
| 2660 |
psm_amarg_t args[8]; |
| 2661 |
int nargs = pkt->nargs; |
| 2662 |
int i; |
| 2663 |
void *dest = (void *) bulkpkt->dest; |
| 2664 |
size_t len = (size_t) (bulkpkt->dest_off + bulkpkt->len); |
| 2665 |
for (i = 0; i < nargs; i++) |
| 2666 |
args[i] = pkt->args[i]; |
| 2667 |
QMARKFREE(bulkpkt); |
| 2668 |
fn(&tok, args, nargs, dest, len); |
| 2669 |
} |
| 2670 |
else |
| 2671 |
QMARKFREE(bulkpkt); |
| 2672 |
} |
| 2673 |
} |
| 2674 |
return; |
| 2675 |
} |
| 2676 |
|
| 2677 |
static |
| 2678 |
psm_error_t |
| 2679 |
amsh_mq_rndv(ptl_t *ptl, psm_mq_t mq, psm_mq_req_t req, |
| 2680 |
psm_epaddr_t epaddr, uint64_t tag, const void *buf, uint32_t len) |
| 2681 |
{ |
| 2682 |
psm_amarg_t args[5] = {}; |
| 2683 |
psm_error_t err = PSM_OK; |
| 2684 |
|
| 2685 |
args[0].u32w0 = MQ_MSG_RTS; |
| 2686 |
args[0].u32w1 = len; |
| 2687 |
args[1].u64w0 = tag; |
| 2688 |
args[2].u64w0 = (uint64_t)(uintptr_t) req; |
| 2689 |
args[3].u64w0 = (uint64_t)(uintptr_t) buf; |
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
#ifdef PSM_HAVE_SCIF |
| 2696 |
int shmidx = epaddr->_shmidx; |
| 2697 |
if(shmidx < PTL_AMSH_MAX_LOCAL_PROCS) { |
| 2698 |
#endif |
| 2699 |
|
| 2700 |
if (ptl->ep->psmi_kassist_mode == PSMI_KASSIST_KNEM_GET) |
| 2701 |
|
| 2702 |
args[4].u64w0 = knem_register_region((void*) buf, len, PSMI_FALSE); |
| 2703 |
else |
| 2704 |
args[4].u64w0 = 0; |
| 2705 |
#ifdef PSM_HAVE_SCIF |
| 2706 |
} else { |
| 2707 |
|
| 2708 |
if(ptl->ep->scif_dma_mode == PSMI_SCIF_DMA_GET && |
| 2709 |
ptl->ep->scif_dma_threshold <= len) { |
| 2710 |
|
| 2711 |
off_t offset; |
| 2712 |
|
| 2713 |
scif_epd_t epd = epaddr->ep->amsh_qdir[shmidx].amsh_epd[0]; |
| 2714 |
|
| 2715 |
err = scif_register_region(epd, (void*)buf, len, &offset); |
| 2716 |
if(err != PSM_OK) { |
| 2717 |
return err; |
| 2718 |
} |
| 2719 |
|
| 2720 |
args[4].u64w0 = offset; |
| 2721 |
} else { |
| 2722 |
args[4].u64w0 = 0; |
| 2723 |
} |
| 2724 |
} |
| 2725 |
#endif |
| 2726 |
|
| 2727 |
psmi_assert(req != NULL); |
| 2728 |
req->type = MQE_TYPE_SEND; |
| 2729 |
req->buf = (void *) buf; |
| 2730 |
req->buf_len = len; |
| 2731 |
req->send_msglen = len; |
| 2732 |
req->send_msgoff = 0; |
| 2733 |
|
| 2734 |
psmi_amsh_short_request(ptl, epaddr, mq_handler_hidx, args, 5, NULL, 0, 0); |
| 2735 |
|
| 2736 |
return err; |
| 2737 |
} |
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
PSMI_ALWAYS_INLINE( |
| 2743 |
psm_error_t |
| 2744 |
amsh_mq_send_inner(psm_mq_t mq, psm_mq_req_t req, psm_epaddr_t epaddr, |
| 2745 |
uint32_t flags, uint64_t tag, const void *ubuf, uint32_t len)) |
| 2746 |
{ |
| 2747 |
psm_amarg_t args[3] = {}; |
| 2748 |
psm_error_t err = PSM_OK; |
| 2749 |
int is_blocking = (req == NULL); |
| 2750 |
|
| 2751 |
if (!flags && len <= psmi_am_max_sizes.request_short) { |
| 2752 |
if (len <= 32) |
| 2753 |
args[0].u32w0 = MQ_MSG_TINY; |
| 2754 |
else |
| 2755 |
args[0].u32w0 = MQ_MSG_SHORT; |
| 2756 |
args[1].u64 = tag; |
| 2757 |
|
| 2758 |
psmi_amsh_short_request(epaddr->ptl, epaddr, mq_handler_hidx, args, 2, |
| 2759 |
ubuf, len, 0); |
| 2760 |
} |
| 2761 |
else if (flags & PSM_MQ_FLAG_SENDSYNC) |
| 2762 |
goto do_rendezvous; |
| 2763 |
else if (len <= mq->shm_thresh_rv) { |
| 2764 |
uint32_t bytes_left = len; |
| 2765 |
uint32_t bytes_this = min(bytes_left, psmi_am_max_sizes.request_short); |
| 2766 |
uint8_t *buf = (uint8_t *)ubuf; |
| 2767 |
args[0].u32w0 = MQ_MSG_LONG; |
| 2768 |
args[0].u32w1 = len; |
| 2769 |
args[1].u64 = tag; |
| 2770 |
psmi_amsh_short_request(epaddr->ptl, epaddr, mq_handler_hidx, args, 2, |
| 2771 |
buf, bytes_this, 0); |
| 2772 |
bytes_left -= bytes_this; |
| 2773 |
buf += bytes_this; |
| 2774 |
args[2].u32w0 = 0; |
| 2775 |
while (bytes_left) { |
| 2776 |
args[2].u32w0 += bytes_this; |
| 2777 |
bytes_this = min(bytes_left, psmi_am_max_sizes.request_short); |
| 2778 |
|
| 2779 |
|
| 2780 |
psmi_amsh_short_request(epaddr->ptl, epaddr, |
| 2781 |
mq_handler_data_hidx, args, |
| 2782 |
3, buf, bytes_this, 0); |
| 2783 |
buf += bytes_this; |
| 2784 |
bytes_left -= bytes_this; |
| 2785 |
} |
| 2786 |
} |
| 2787 |
else { |
| 2788 |
do_rendezvous: |
| 2789 |
if (is_blocking) { |
| 2790 |
req = psmi_mq_req_alloc(mq, MQE_TYPE_SEND); |
| 2791 |
if_pf (req == NULL) |
| 2792 |
return PSM_NO_MEMORY; |
| 2793 |
req->send_msglen = len; |
| 2794 |
req->tag = tag; |
| 2795 |
} |
| 2796 |
err = amsh_mq_rndv(epaddr->ptl,mq,req,epaddr,tag,ubuf,len); |
| 2797 |
|
| 2798 |
if (err == PSM_OK && is_blocking) { |
| 2799 |
err = psmi_mq_wait_internal(&req); |
| 2800 |
} |
| 2801 |
return err; |
| 2802 |
} |
| 2803 |
|
| 2804 |
|
| 2805 |
if (req != NULL) { |
| 2806 |
req->state = MQ_STATE_COMPLETE; |
| 2807 |
mq_qq_append(&mq->completed_q, req); |
| 2808 |
} |
| 2809 |
|
| 2810 |
mq->stats.tx_num++; |
| 2811 |
mq->stats.tx_shm_num++; |
| 2812 |
mq->stats.tx_eager_num++; |
| 2813 |
mq->stats.tx_eager_bytes += len; |
| 2814 |
|
| 2815 |
return err; |
| 2816 |
} |
| 2817 |
|
| 2818 |
static |
| 2819 |
psm_error_t |
| 2820 |
amsh_mq_isend(psm_mq_t mq, psm_epaddr_t epaddr, uint32_t flags, |
| 2821 |
uint64_t tag, const void *ubuf, uint32_t len, void *context, |
| 2822 |
psm_mq_req_t *req_o) |
| 2823 |
{ |
| 2824 |
psm_mq_req_t req = psmi_mq_req_alloc(mq, MQE_TYPE_SEND); |
| 2825 |
if_pf (req == NULL) |
| 2826 |
return PSM_NO_MEMORY; |
| 2827 |
|
| 2828 |
req->send_msglen = len; |
| 2829 |
req->tag = tag; |
| 2830 |
req->context = context; |
| 2831 |
|
| 2832 |
_IPATH_VDBG("[ishrt][%s->%s][n=0][b=%p][l=%d][t=%"PRIx64"]\n", |
| 2833 |
psmi_epaddr_get_name(epaddr->ep->epid), |
| 2834 |
psmi_epaddr_get_name(epaddr->epid), ubuf, len, tag); |
| 2835 |
|
| 2836 |
amsh_mq_send_inner(mq, req, epaddr, flags, tag, ubuf, len); |
| 2837 |
|
| 2838 |
*req_o = req; |
| 2839 |
return PSM_OK; |
| 2840 |
} |
| 2841 |
|
| 2842 |
static |
| 2843 |
psm_error_t |
| 2844 |
amsh_mq_send(psm_mq_t mq, psm_epaddr_t epaddr, uint32_t flags, |
| 2845 |
uint64_t tag, const void *ubuf, uint32_t len) |
| 2846 |
{ |
| 2847 |
amsh_mq_send_inner(mq, NULL, epaddr, flags, tag, ubuf, len); |
| 2848 |
|
| 2849 |
_IPATH_VDBG("[shrt][%s->%s][n=0][b=%p][l=%d][t=%"PRIx64"]\n", |
| 2850 |
psmi_epaddr_get_name(epaddr->ep->epid), |
| 2851 |
psmi_epaddr_get_name(epaddr->epid), ubuf, len, tag); |
| 2852 |
|
| 2853 |
return PSM_OK; |
| 2854 |
} |
| 2855 |
|
| 2856 |
|
| 2857 |
int |
| 2858 |
psmi_epaddr_kcopy_pid(psm_epaddr_t epaddr) |
| 2859 |
{ |
| 2860 |
int shmidx = epaddr->_shmidx; |
| 2861 |
return epaddr->ep->amsh_qdir[shmidx].kassist_pid; |
| 2862 |
} |
| 2863 |
|
| 2864 |
static |
| 2865 |
int |
| 2866 |
psmi_kcopy_find_minor(int *minor) |
| 2867 |
{ |
| 2868 |
int i; |
| 2869 |
char path[128]; |
| 2870 |
|
| 2871 |
|
| 2872 |
static int fd = -1; |
| 2873 |
static int kcopy_minor = -1; |
| 2874 |
|
| 2875 |
if (fd >= 0) { |
| 2876 |
*minor = kcopy_minor; |
| 2877 |
return fd; |
| 2878 |
} |
| 2879 |
|
| 2880 |
for (i = 0; i < 256; i++) { |
| 2881 |
snprintf(path, sizeof(path), "/dev/kcopy/%02d", i); |
| 2882 |
fd = open(path, O_WRONLY | O_EXCL); |
| 2883 |
if (fd >= 0) { |
| 2884 |
*minor = kcopy_minor = i; |
| 2885 |
break; |
| 2886 |
} |
| 2887 |
} |
| 2888 |
|
| 2889 |
return fd; |
| 2890 |
} |
| 2891 |
|
| 2892 |
static |
| 2893 |
int |
| 2894 |
psmi_kcopy_open_minor(int minor) |
| 2895 |
{ |
| 2896 |
char path[128]; |
| 2897 |
|
| 2898 |
|
| 2899 |
static int fd = -1; |
| 2900 |
if (fd >= 0) |
| 2901 |
return fd; |
| 2902 |
|
| 2903 |
if (minor >= 0 && minor < 256) { |
| 2904 |
snprintf(path, sizeof(path), "/dev/kcopy/%02d", minor); |
| 2905 |
fd = open(path, O_WRONLY); |
| 2906 |
} |
| 2907 |
return fd; |
| 2908 |
} |
| 2909 |
|
| 2910 |
static |
| 2911 |
const char * |
| 2912 |
psmi_kassist_getmode(int mode) |
| 2913 |
{ |
| 2914 |
switch (mode) { |
| 2915 |
case PSMI_KASSIST_OFF: |
| 2916 |
return "kassist off"; |
| 2917 |
case PSMI_KASSIST_KCOPY_PUT: |
| 2918 |
return "kcopy put"; |
| 2919 |
case PSMI_KASSIST_KCOPY_GET: |
| 2920 |
return "kcopy get"; |
| 2921 |
case PSMI_KASSIST_KNEM_GET: |
| 2922 |
return "knem get"; |
| 2923 |
case PSMI_KASSIST_KNEM_PUT: |
| 2924 |
return "knem put"; |
| 2925 |
default: |
| 2926 |
return "unknown"; |
| 2927 |
} |
| 2928 |
} |
| 2929 |
|
| 2930 |
static |
| 2931 |
int |
| 2932 |
psmi_get_kassist_mode() |
| 2933 |
{ |
| 2934 |
int mode = PSMI_KASSIST_MODE_DEFAULT; |
| 2935 |
union psmi_envvar_val env_kassist; |
| 2936 |
|
| 2937 |
|
| 2938 |
if (!psmi_getenv("PSM_SHM_KCOPY", |
| 2939 |
"PSM Shared Memory use kcopy (put,get,none)", |
| 2940 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_STR, |
| 2941 |
(union psmi_envvar_val) "put", |
| 2942 |
&env_kassist)) |
| 2943 |
{ |
| 2944 |
char *s = env_kassist.e_str; |
| 2945 |
if (strcasecmp(s, "put") == 0) |
| 2946 |
mode = PSMI_KASSIST_KCOPY_PUT; |
| 2947 |
else if (strcasecmp(s, "get") == 0) |
| 2948 |
mode = PSMI_KASSIST_KCOPY_PUT; |
| 2949 |
else |
| 2950 |
mode = PSMI_KASSIST_OFF; |
| 2951 |
} |
| 2952 |
else if(!psmi_getenv("PSM_KASSIST_MODE", |
| 2953 |
"PSM Shared memory kernel assist mode " |
| 2954 |
"(knem-put, knem-get, kcopy-put, kcopy-get, none)", |
| 2955 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_STR, |
| 2956 |
(union psmi_envvar_val) PSMI_KASSIST_MODE_DEFAULT_STRING, |
| 2957 |
&env_kassist)) |
| 2958 |
{ |
| 2959 |
char *s = env_kassist.e_str; |
| 2960 |
if (strcasecmp(s, "kcopy-put") == 0) |
| 2961 |
mode = PSMI_KASSIST_KCOPY_PUT; |
| 2962 |
else if (strcasecmp(s, "kcopy-get") == 0) |
| 2963 |
mode = PSMI_KASSIST_KCOPY_GET; |
| 2964 |
else if (strcasecmp(s, "knem-put") == 0) |
| 2965 |
mode = PSMI_KASSIST_KNEM_PUT; |
| 2966 |
else if (strcasecmp(s, "knem-get") == 0) |
| 2967 |
mode = PSMI_KASSIST_KNEM_GET; |
| 2968 |
else |
| 2969 |
mode = PSMI_KASSIST_OFF; |
| 2970 |
|
| 2971 |
#if !defined(PSM_USE_KNEM) |
| 2972 |
if (mode & PSMI_KASSIST_KNEM) { |
| 2973 |
_IPATH_ERROR("KNEM kassist mode requested which has not been compiled " |
| 2974 |
"into this version of PSM. Switching kassist mode off.\n"); |
| 2975 |
mode = PSMI_KASSIST_OFF; |
| 2976 |
} |
| 2977 |
#endif |
| 2978 |
} |
| 2979 |
else { |
| 2980 |
|
| 2981 |
#if defined(PSM_USE_KNEM) |
| 2982 |
int res; |
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
res = access(KNEM_DEVICE_FILENAME, R_OK | W_OK); |
| 2988 |
if (res == 0) |
| 2989 |
mode = PSMI_KASSIST_KNEM_PUT; |
| 2990 |
else |
| 2991 |
mode = PSMI_KASSIST_KCOPY_PUT; |
| 2992 |
#else |
| 2993 |
mode = PSMI_KASSIST_KCOPY_PUT; |
| 2994 |
#endif |
| 2995 |
} |
| 2996 |
|
| 2997 |
return mode; |
| 2998 |
} |
| 2999 |
|
| 3000 |
#ifdef PSM_HAVE_SCIF |
| 3001 |
static int |
| 3002 |
psmi_get_scif_dma_mode() |
| 3003 |
{ |
| 3004 |
int mode = PSMI_SCIF_DMA_MODE_DEFAULT; |
| 3005 |
union psmi_envvar_val env_scif_dma; |
| 3006 |
|
| 3007 |
if(!psmi_getenv("PSM_SCIF_DMA_MODE", |
| 3008 |
"PSM Shared memory SCIF DMA transport mode " |
| 3009 |
"(scif-put, scif-get, none)", |
| 3010 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_STR, |
| 3011 |
(union psmi_envvar_val) PSMI_SCIF_DMA_MODE_DEFAULT_STRING, |
| 3012 |
&env_scif_dma)) |
| 3013 |
{ |
| 3014 |
char *s = env_scif_dma.e_str; |
| 3015 |
if (strcasecmp(s, "scif-put") == 0) |
| 3016 |
mode = PSMI_SCIF_DMA_PUT; |
| 3017 |
else if (strcasecmp(s, "scif-get") == 0) |
| 3018 |
mode = PSMI_SCIF_DMA_GET; |
| 3019 |
else |
| 3020 |
mode = PSMI_SCIF_DMA_OFF; |
| 3021 |
} |
| 3022 |
|
| 3023 |
return mode; |
| 3024 |
} |
| 3025 |
|
| 3026 |
static int |
| 3027 |
psmi_get_scif_dma_threshold() |
| 3028 |
{ |
| 3029 |
int threshold = PSMI_MQ_RV_THRESH_SCIF_DMA; |
| 3030 |
union psmi_envvar_val env_scif_dma; |
| 3031 |
|
| 3032 |
if(!psmi_getenv("PSM_SCIF_DMA_THRESH", |
| 3033 |
"PSM SCIF DMA (rendezvous) switchover", |
| 3034 |
PSMI_ENVVAR_LEVEL_USER, PSMI_ENVVAR_TYPE_UINT, |
| 3035 |
(union psmi_envvar_val) threshold, |
| 3036 |
&env_scif_dma)) { |
| 3037 |
threshold = env_scif_dma.e_uint; |
| 3038 |
} |
| 3039 |
|
| 3040 |
return threshold; |
| 3041 |
} |
| 3042 |
|
| 3043 |
static |
| 3044 |
const char * |
| 3045 |
psmi_scif_dma_getmode(int mode) |
| 3046 |
{ |
| 3047 |
switch (mode) { |
| 3048 |
case PSMI_SCIF_DMA_OFF: |
| 3049 |
return "SCIF DMA off"; |
| 3050 |
case PSMI_SCIF_DMA_PUT: |
| 3051 |
return "SCIF put"; |
| 3052 |
case PSMI_SCIF_DMA_GET: |
| 3053 |
return "SCIF get"; |
| 3054 |
default: |
| 3055 |
return "unknown"; |
| 3056 |
} |
| 3057 |
} |
| 3058 |
#endif |
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
static |
| 3068 |
void |
| 3069 |
amsh_conn_handler(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len) |
| 3070 |
{ |
| 3071 |
int op = args[0].u32w0; |
| 3072 |
int phase = args[0].u32w1; |
| 3073 |
psm_epid_t epid = args[1].u64w0; |
| 3074 |
psm_error_t err = (psm_error_t) args[2].u32w1; |
| 3075 |
psm_error_t *perr = (psm_error_t *) (uintptr_t) args[3].u64w0; |
| 3076 |
|
| 3077 |
psm_epaddr_t epaddr; |
| 3078 |
amsh_am_token_t *tok = (amsh_am_token_t *) toki; |
| 3079 |
int shmidx = tok->shmidx; |
| 3080 |
int is_valid; |
| 3081 |
ptl_t *ptl = tok->ptl; |
| 3082 |
|
| 3083 |
|
| 3084 |
psmi_assert_always(buf == NULL && len == 0); |
| 3085 |
|
| 3086 |
_IPATH_VDBG("Conn op=%d, phase=%d, epid=%llx, err=%d\n", |
| 3087 |
op, phase, (unsigned long long) epid, err); |
| 3088 |
switch (op) { |
| 3089 |
case PSMI_AM_CONN_REQ: |
| 3090 |
_IPATH_VDBG("Connect from %d:%d\n", |
| 3091 |
(int) psm_epid_nid(epid), |
| 3092 |
(int) psm_epid_context(epid)); |
| 3093 |
|
| 3094 |
epaddr = psmi_epid_lookup(ptl->ep, epid); |
| 3095 |
if (epaddr == NULL) { |
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
if ((err = amsh_epaddr_add(ptl, epid, shmidx, &epaddr))) |
| 3100 |
|
| 3101 |
psmi_handle_error(PSMI_EP_NORETURN, err, "Fatal error " |
| 3102 |
"in connecting to shm segment"); |
| 3103 |
psmi_assert(psmi_epid_lookup(ptl->ep, epid) != NULL); |
| 3104 |
} |
| 3105 |
|
| 3106 |
|
| 3107 |
|
| 3108 |
ptl->connect_from++; |
| 3109 |
args[0].u32w0 = PSMI_AM_CONN_REP; |
| 3110 |
args[1].u64w0 = (psm_epid_t) ptl->epid; |
| 3111 |
args[2].u32w1 = PSM_OK; |
| 3112 |
AMSH_CSTATE_FROM_SET(epaddr, ESTABLISHED); |
| 3113 |
tok->tok.epaddr_from = epaddr; |
| 3114 |
psmi_amsh_short_reply(tok, amsh_conn_handler_hidx, |
| 3115 |
args, narg, NULL, 0, 0); |
| 3116 |
|
| 3117 |
break; |
| 3118 |
|
| 3119 |
case PSMI_AM_CONN_REP: |
| 3120 |
if (ptl->connect_phase != phase) { |
| 3121 |
_IPATH_VDBG("Out of phase connect reply\n"); |
| 3122 |
return; |
| 3123 |
} |
| 3124 |
epaddr = ptl->ep->amsh_qdir[shmidx].amsh_epaddr; |
| 3125 |
*perr = err; |
| 3126 |
AMSH_CSTATE_TO_SET(epaddr, REPLIED); |
| 3127 |
ptl->connect_to++; |
| 3128 |
break; |
| 3129 |
|
| 3130 |
case PSMI_AM_DISC_REQ: |
| 3131 |
epaddr = tok->tok.epaddr_from; |
| 3132 |
args[0].u32w0 = PSMI_AM_DISC_REP; |
| 3133 |
args[2].u32w1 = PSM_OK; |
| 3134 |
AMSH_CSTATE_FROM_SET(epaddr, DISC_REQ); |
| 3135 |
ptl->connect_from--; |
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
is_valid = 1; |
| 3140 |
#ifdef PSM_HAVE_SCIF |
| 3141 |
if (shmidx < PTL_AMSH_MAX_LOCAL_PROCS) { |
| 3142 |
#endif |
| 3143 |
pthread_mutex_lock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 3144 |
if (ptl->ep->amsh_dirpage->shmidx_map_epid[shmidx] != epaddr->epid) |
| 3145 |
is_valid = 0; |
| 3146 |
pthread_mutex_unlock((pthread_mutex_t *) &(ptl->ep->amsh_dirpage->lock)); |
| 3147 |
#ifdef PSM_HAVE_SCIF |
| 3148 |
} |
| 3149 |
#endif |
| 3150 |
|
| 3151 |
if (is_valid) { |
| 3152 |
psmi_amsh_short_reply(tok, amsh_conn_handler_hidx, |
| 3153 |
args, narg, NULL, 0, 0); |
| 3154 |
} |
| 3155 |
break; |
| 3156 |
|
| 3157 |
case PSMI_AM_DISC_REP: |
| 3158 |
if (ptl->connect_phase != phase) { |
| 3159 |
_IPATH_VDBG("Out of phase disconnect reply\n"); |
| 3160 |
return; |
| 3161 |
} |
| 3162 |
*perr = err; |
| 3163 |
epaddr = tok->tok.epaddr_from; |
| 3164 |
AMSH_CSTATE_TO_SET(epaddr, DISC_REPLIED); |
| 3165 |
ptl->connect_to--; |
| 3166 |
break; |
| 3167 |
|
| 3168 |
default: |
| 3169 |
psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR, |
| 3170 |
"Unknown/unhandled connect handler op=%d", op); |
| 3171 |
break; |
| 3172 |
} |
| 3173 |
return; |
| 3174 |
} |
| 3175 |
|
| 3176 |
static |
| 3177 |
size_t |
| 3178 |
amsh_sizeof(void) |
| 3179 |
{ |
| 3180 |
return sizeof(ptl_t); |
| 3181 |
} |
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
static |
| 3190 |
psm_error_t |
| 3191 |
amsh_init(psm_ep_t ep, ptl_t *ptl, ptl_ctl_t *ctl) |
| 3192 |
{ |
| 3193 |
int shmidx; |
| 3194 |
psm_error_t err = PSM_OK; |
| 3195 |
|
| 3196 |
_IPATH_VDBG("PSM Symmetric Mode!\n"); |
| 3197 |
|
| 3198 |
psmi_assert_always(ep != NULL); |
| 3199 |
psmi_assert_always(ep->epaddr != NULL); |
| 3200 |
psmi_assert_always(ep->epid != 0); |
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
#ifdef PSM_HAVE_SCIF |
| 3205 |
if ((err = amsh_scif_init(ep))) |
| 3206 |
goto fail; |
| 3207 |
#endif |
| 3208 |
|
| 3209 |
|
| 3210 |
if ((err = psmi_shm_attach(ep, &shmidx))) |
| 3211 |
goto fail; |
| 3212 |
|
| 3213 |
|
| 3214 |
ep->epid |= ((((uint64_t)shmidx)&0xFF)<<56); |
| 3215 |
|
| 3216 |
ptl->ep = ep; |
| 3217 |
ptl->epid = ep->epid; |
| 3218 |
ptl->epaddr = ep->epaddr; |
| 3219 |
ptl->ctl = ctl; |
| 3220 |
ptl->zero_polls = 0; |
| 3221 |
|
| 3222 |
pthread_mutex_init(&ptl->connect_lock, NULL); |
| 3223 |
ptl->connect_phase = 0; |
| 3224 |
ptl->connect_from = 0; |
| 3225 |
ptl->connect_to = 0; |
| 3226 |
|
| 3227 |
memset(&ptl->amsh_empty_shortpkt, 0, sizeof ptl->amsh_empty_shortpkt); |
| 3228 |
memset(&ptl->psmi_am_reqq_fifo, 0, sizeof ptl->psmi_am_reqq_fifo); |
| 3229 |
|
| 3230 |
if ((err = amsh_init_segment(ptl))) |
| 3231 |
goto fail; |
| 3232 |
|
| 3233 |
psmi_am_reqq_init(ptl); |
| 3234 |
memset(ctl, 0, sizeof(*ctl)); |
| 3235 |
|
| 3236 |
|
| 3237 |
ctl->ptl = ptl; |
| 3238 |
ctl->ep_poll = amsh_poll; |
| 3239 |
ctl->ep_connect = amsh_ep_connect; |
| 3240 |
ctl->ep_disconnect = amsh_ep_disconnect; |
| 3241 |
|
| 3242 |
ctl->mq_send = amsh_mq_send; |
| 3243 |
ctl->mq_isend = amsh_mq_isend; |
| 3244 |
|
| 3245 |
ctl->am_short_request = psmi_amsh_am_short_request; |
| 3246 |
ctl->am_short_reply = psmi_amsh_am_short_reply; |
| 3247 |
|
| 3248 |
|
| 3249 |
ctl->epaddr_stats_num = NULL; |
| 3250 |
ctl->epaddr_stats_init = NULL; |
| 3251 |
ctl->epaddr_stats_get = NULL; |
| 3252 |
|
| 3253 |
#ifdef PSM_HAVE_SCIF |
| 3254 |
|
| 3255 |
if (pthread_create(&ptl->ep->scif_thread, NULL, |
| 3256 |
am_ctl_accept_thread, (void*)ptl)) { |
| 3257 |
err = psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 3258 |
"amsh_init_segment(): pthread_create() failed: %d %s", |
| 3259 |
errno, strerror(errno)); |
| 3260 |
goto fail; |
| 3261 |
} |
| 3262 |
#endif |
| 3263 |
|
| 3264 |
fail: |
| 3265 |
return err; |
| 3266 |
} |
| 3267 |
|
| 3268 |
static |
| 3269 |
psm_error_t |
| 3270 |
amsh_fini(ptl_t *ptl, int force, uint64_t timeout_ns) |
| 3271 |
{ |
| 3272 |
struct psmi_eptab_iterator itor; |
| 3273 |
psm_epaddr_t epaddr; |
| 3274 |
psm_error_t err = PSM_OK; |
| 3275 |
psm_error_t err_seg; |
| 3276 |
uint64_t t_start = get_cycles(); |
| 3277 |
int i = 0; |
| 3278 |
|
| 3279 |
|
| 3280 |
if (ptl->connect_to > 0) { |
| 3281 |
int num_disc = 0; |
| 3282 |
int *mask; |
| 3283 |
psm_error_t *errs; |
| 3284 |
psm_epaddr_t *epaddr_array; |
| 3285 |
|
| 3286 |
psmi_epid_itor_init(&itor, ptl->ep); |
| 3287 |
while ((epaddr = psmi_epid_itor_next(&itor))) { |
| 3288 |
if (epaddr->ptl != ptl) |
| 3289 |
continue; |
| 3290 |
if (AMSH_CSTATE_TO_GET(epaddr) == AMSH_CSTATE_TO_ESTABLISHED) |
| 3291 |
num_disc++; |
| 3292 |
} |
| 3293 |
psmi_epid_itor_fini(&itor); |
| 3294 |
|
| 3295 |
mask = (int *) psmi_calloc(ptl->ep, UNDEFINED, num_disc, sizeof(int)); |
| 3296 |
errs = (psm_error_t *) |
| 3297 |
psmi_calloc(ptl->ep, UNDEFINED, num_disc, sizeof(psm_error_t)); |
| 3298 |
epaddr_array = (psm_epaddr_t *) |
| 3299 |
psmi_calloc(ptl->ep, UNDEFINED, num_disc, sizeof(psm_epaddr_t)); |
| 3300 |
|
| 3301 |
if (errs == NULL || epaddr_array == NULL || mask == NULL) { |
| 3302 |
if (epaddr_array) psmi_free(epaddr_array); |
| 3303 |
if (errs) psmi_free(errs); |
| 3304 |
if (mask) psmi_free(mask); |
| 3305 |
err = PSM_NO_MEMORY; |
| 3306 |
goto fail; |
| 3307 |
} |
| 3308 |
psmi_epid_itor_init(&itor, ptl->ep); |
| 3309 |
while ((epaddr = psmi_epid_itor_next(&itor))) { |
| 3310 |
if (epaddr->ptl == ptl) { |
| 3311 |
if (AMSH_CSTATE_TO_GET(epaddr) == AMSH_CSTATE_TO_ESTABLISHED) { |
| 3312 |
mask[i] = 1; |
| 3313 |
epaddr_array[i] = epaddr; |
| 3314 |
i++; |
| 3315 |
} |
| 3316 |
} |
| 3317 |
} |
| 3318 |
psmi_epid_itor_fini(&itor); |
| 3319 |
psmi_assert(i == num_disc && num_disc > 0); |
| 3320 |
err = amsh_ep_disconnect(ptl, force, num_disc, epaddr_array, |
| 3321 |
mask, errs, timeout_ns); |
| 3322 |
psmi_free(mask); |
| 3323 |
psmi_free(errs); |
| 3324 |
psmi_free(epaddr_array); |
| 3325 |
} |
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
if (ptl->connect_from > 0 || ptl->connect_to > 0) { |
| 3333 |
while (ptl->connect_from > 0 || ptl->connect_to > 0) { |
| 3334 |
if (!psmi_cycles_left(t_start, timeout_ns)) { |
| 3335 |
err = PSM_TIMEOUT; |
| 3336 |
_IPATH_VDBG("CCC timed out with from=%d,to=%d\n", |
| 3337 |
ptl->connect_from, |
| 3338 |
ptl->connect_to); |
| 3339 |
break; |
| 3340 |
} |
| 3341 |
psmi_poll_internal(ptl->ep, 1); |
| 3342 |
} |
| 3343 |
} |
| 3344 |
else { |
| 3345 |
_IPATH_VDBG("CCC complete disconnect from=%d,to=%d\n", |
| 3346 |
ptl->connect_from, |
| 3347 |
ptl->connect_to); |
| 3348 |
} |
| 3349 |
|
| 3350 |
if ((err_seg = psmi_shm_detach(ptl->ep))) { |
| 3351 |
err = err_seg; |
| 3352 |
goto fail; |
| 3353 |
} |
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
#ifdef PSM_HAVE_SCIF |
| 3358 |
for(i = 0; i < ptl->ep->scif_nnodes; i++) { |
| 3359 |
ptl->repH[i].head = &ptl->amsh_empty_shortpkt; |
| 3360 |
ptl->reqH[i].head = &ptl->amsh_empty_shortpkt; |
| 3361 |
} |
| 3362 |
#else |
| 3363 |
ptl->repH[0].head = &ptl->amsh_empty_shortpkt; |
| 3364 |
ptl->reqH[0].head = &ptl->amsh_empty_shortpkt; |
| 3365 |
#endif |
| 3366 |
|
| 3367 |
return PSM_OK; |
| 3368 |
fail: |
| 3369 |
return err; |
| 3370 |
|
| 3371 |
} |
| 3372 |
|
| 3373 |
static |
| 3374 |
psm_error_t |
| 3375 |
amsh_setopt(const void *component_obj, int optname, |
| 3376 |
const void *optval, uint64_t optlen) |
| 3377 |
{ |
| 3378 |
|
| 3379 |
return psmi_handle_error(NULL, PSM_PARAM_ERR, "Unknown AM ptl option %u.", optname); |
| 3380 |
} |
| 3381 |
|
| 3382 |
static |
| 3383 |
psm_error_t |
| 3384 |
amsh_getopt(const void *component_obj, int optname, |
| 3385 |
void *optval, uint64_t *optlen) |
| 3386 |
{ |
| 3387 |
|
| 3388 |
return psmi_handle_error(NULL, PSM_PARAM_ERR, "Unknown AM ptl option %u.", optname); |
| 3389 |
} |
| 3390 |
|
| 3391 |
|
| 3392 |
struct ptl_ctl_init |
| 3393 |
psmi_ptl_amsh = { |
| 3394 |
amsh_sizeof, amsh_init, amsh_fini, amsh_setopt, amsh_getopt |
| 3395 |
}; |
| 3396 |
|
| 3397 |
#ifdef PSM_HAVE_SCIF |
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
static void* am_ctl_accept_thread(void* arg) |
| 3403 |
{ |
| 3404 |
ptl_t* ptl = (ptl_t*)arg; |
| 3405 |
psm_ep_t ep = ptl->ep; |
| 3406 |
struct scif_portID peer; |
| 3407 |
scif_epd_t epd; |
| 3408 |
void* addr; |
| 3409 |
int peeridx; |
| 3410 |
int shmidx; |
| 3411 |
int nodeid; |
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
struct { off_t offset; int verno; psm_epid_t epid; } inbuf, outbuf; |
| 3416 |
|
| 3417 |
while(1) { |
| 3418 |
|
| 3419 |
if(scif_accept(ep->scif_epd, &peer, &epd, SCIF_ACCEPT_SYNC)) { |
| 3420 |
if(errno == EINTR) { |
| 3421 |
|
| 3422 |
_IPATH_VDBG("SCIF accept thread quitting\n"); |
| 3423 |
pthread_exit(NULL); |
| 3424 |
return NULL; |
| 3425 |
} |
| 3426 |
|
| 3427 |
psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR, |
| 3428 |
"scif_accept failed: %d %s\n", errno, strerror(errno)); |
| 3429 |
continue; |
| 3430 |
} |
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
addr = ep->amsh_qdir[ep->amsh_shmidx].amsh_base; |
| 3436 |
outbuf.offset = scif_register(epd, addr, |
| 3437 |
am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES, |
| 3438 |
(off_t)addr, SCIF_PROT_READ|SCIF_PROT_WRITE, SCIF_MAP_FIXED); |
| 3439 |
|
| 3440 |
_IPATH_PRDBG("registered addr %p at offset %p length %ld\n", |
| 3441 |
addr, (void*)outbuf.offset, |
| 3442 |
am_ctl_sizeof_block() * PTL_AMSH_MAX_LOCAL_NODES); |
| 3443 |
if(outbuf.offset == SCIF_REGISTER_FAILED) { |
| 3444 |
psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 3445 |
"scif_register failed: %d %s\n", errno, strerror(errno)); |
| 3446 |
scif_close(epd); |
| 3447 |
continue; |
| 3448 |
} |
| 3449 |
|
| 3450 |
outbuf.verno = PSMI_VERNO; |
| 3451 |
outbuf.epid = ep->epid; |
| 3452 |
|
| 3453 |
if (amsh_scif_send(epd, &outbuf, sizeof(outbuf))) { |
| 3454 |
psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 3455 |
"scif_send epd %d failed: %d %s\n", |
| 3456 |
epd, errno, strerror(errno)); |
| 3457 |
scif_close(epd); |
| 3458 |
continue; |
| 3459 |
} |
| 3460 |
|
| 3461 |
|
| 3462 |
if(amsh_scif_recv(epd, &inbuf, sizeof(inbuf))) { |
| 3463 |
psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 3464 |
"scif_recv failed: %d %s\n", errno, strerror(errno)); |
| 3465 |
scif_close(epd); |
| 3466 |
continue; |
| 3467 |
} |
| 3468 |
|
| 3469 |
|
| 3470 |
nodeid = (int)((inbuf.epid>>48)&0xff); |
| 3471 |
shmidx = (int)((inbuf.epid>>56)&0xff); |
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
if(peer.node != nodeid) { |
| 3476 |
psmi_handle_error(NULL, PSM_EP_NO_RESOURCES, |
| 3477 |
"SCIF node:port %d:%d does not match encoded epid nodeid %d", |
| 3478 |
peer.node, peer.port, nodeid); |
| 3479 |
scif_close(epd); |
| 3480 |
continue; |
| 3481 |
} |
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
if(nodeid > ep->scif_mynodeid) { |
| 3487 |
peeridx = (PTL_AMSH_MAX_LOCAL_PROCS * nodeid) + shmidx; |
| 3488 |
} else if(nodeid < ep->scif_mynodeid) { |
| 3489 |
peeridx = (PTL_AMSH_MAX_LOCAL_PROCS * (nodeid + 1)) + shmidx; |
| 3490 |
} else { |
| 3491 |
peeridx = shmidx; |
| 3492 |
} |
| 3493 |
|
| 3494 |
ptl->ep->amsh_qdir[peeridx].amsh_epid = inbuf.epid; |
| 3495 |
ptl->ep->amsh_qdir[peeridx].amsh_verno = inbuf.verno; |
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
ptl->ep->amsh_qdir[peeridx].amsh_epd[1] = epd; |
| 3502 |
|
| 3503 |
_IPATH_VDBG( |
| 3504 |
"shmidx %d accepted %d:%d peeridx %d epd %d shmidx %d\n", |
| 3505 |
ep->amsh_shmidx, peer.node, peer.port, peeridx, |
| 3506 |
ep->amsh_qdir[peeridx].amsh_epd[1], |
| 3507 |
ep->amsh_qdir[peeridx].amsh_shmidx); |
| 3508 |
} |
| 3509 |
|
| 3510 |
return NULL; |
| 3511 |
} |
| 3512 |
#endif |
| 3513 |
|