static ssize_t sock_rx_ctx_cancel(struct sock_rx_ctx *rx_ctx, void *context) { struct dlist_entry *entry; ssize_t ret = -FI_ENOENT; struct sock_rx_entry *rx_entry; struct sock_pe_entry pe_entry; fastlock_acquire(&rx_ctx->lock); for (entry = rx_ctx->rx_entry_list.next; entry != &rx_ctx->rx_entry_list; entry = entry->next) { rx_entry = container_of(entry, struct sock_rx_entry, entry); if (rx_entry->is_busy) continue; if ((uintptr_t) context == rx_entry->context) { if (rx_ctx->comp.recv_cq) { memset(&pe_entry, 0, sizeof(pe_entry)); pe_entry.comp = &rx_ctx->comp; pe_entry.tag = rx_entry->tag; pe_entry.context = rx_entry->context; pe_entry.flags = (FI_MSG | FI_RECV); if (rx_entry->is_tagged) pe_entry.flags |= FI_TAGGED; if (sock_cq_report_error(pe_entry.comp->recv_cq, &pe_entry, 0, FI_ECANCELED, -FI_ECANCELED, NULL, 0)) { SOCK_LOG_ERROR("failed to report error\n"); } } if (rx_ctx->comp.recv_cntr) fi_cntr_adderr(&rx_ctx->comp.recv_cntr->cntr_fid, 1); dlist_remove(&rx_entry->entry); sock_rx_release_entry(rx_entry); ret = 0; break; } } fastlock_release(&rx_ctx->lock); return ret; }
static int cntr_loop() { size_t i, opened, cntr_cnt; uint64_t value, expected; struct timespec start, stop; int ret, testret = FAIL, timeout = 5000; cntr_cnt = MIN(fi->domain_attr->cntr_cnt, MAX_COUNTER_CHECK); struct fid_cntr **cntrs = calloc(cntr_cnt, sizeof(struct fid_cntr *)); if (!cntrs) { perror("calloc"); return -FI_ENOMEM; } for (opened = 0; opened < cntr_cnt; opened++) { ret = ft_cntr_open(&cntrs[opened]); if (ret) { FT_PRINTERR("fi_cntr_open", ret); goto close; } } for (i = 0; i < opened; i++) { ret = fi_cntr_set(cntrs[i], i); if (ret) { FT_PRINTERR("fi_cntr_set", ret); goto close; } ret = fi_cntr_seterr(cntrs[i], i << 1); if (ret) { FT_PRINTERR("fi_cntr_seterr", ret); goto close; } } for (i = 0; i < opened; i++) { ret = fi_cntr_add(cntrs[i], i); if (ret) { FT_PRINTERR("fi_cntr_add", ret); goto close; } ret = fi_cntr_adderr(cntrs[i], i); if (ret) { FT_PRINTERR("fi_cntr_adderr", ret); goto close; } } for (i = 0; i < opened; i++) { clock_gettime(CLOCK_MONOTONIC, &start); expected = i + i; do { value = fi_cntr_read(cntrs[i]); clock_gettime(CLOCK_MONOTONIC, &stop); sched_yield(); } while ((value != expected) && ((stop.tv_sec - start.tv_sec) > timeout)); if (value != expected) { FT_PRINTERR("fi_cntr_read", value); goto close; } clock_gettime(CLOCK_MONOTONIC, &start); expected = (i << 1) + i; do { value = fi_cntr_readerr(cntrs[i]); clock_gettime(CLOCK_MONOTONIC, &stop); sched_yield(); } while ((value != expected) && ((stop.tv_sec - start.tv_sec) > timeout)); if (value != expected) { FT_PRINTERR("fi_cntr_readerr", value); goto close; } } testret = PASS; close: for (i = 0; i < opened; i++) { ret = fi_close(&(cntrs[i])->fid); if (ret) { FT_PRINTERR("fi_cntr_close", ret); break; } } if (i < cntr_cnt) testret = FAIL; free(cntrs); return TEST_RET_VAL(ret, testret); }