예제 #1
0
static int poll_recv_cqs(void)
{
    struct ibv_wc wc[POLL_BATCH];
    int done, i, ret, poll_ret;
    long total_counter = 0;

    struct timespec ts0;
    ts0.tv_sec = -1;
    ts0.tv_nsec = -1;

    if(is_sender) {
        printf(" called poll_rec_cqs() with sender side \n");
        return -1;
    }

    if (print_base == -1) print_base = message_buffer * message_batch;

    for (i = 0; i < connections; i++) {
        if (!test.nodes[i].connected)
            continue;

        do {
            for (done = 0; done < message_buffer * message_batch; done += poll_ret) {
                poll_ret = ibv_poll_cq(test.nodes[i].cq, POLL_BATCH, wc);
                total_counter += poll_ret;

                if (poll_ret < 0) {
                    printf("rxe_send_mc: failed polling CQ: %d\n", poll_ret);
                    return poll_ret;
                }
                else if (poll_ret > 0) {
                    if(ts0.tv_sec == -1 && ts0.tv_nsec == -1) {
                        clock_gettime(CLOCK_REALTIME, &ts0);
                    }

                    ret = recv_check_psn(wc,poll_ret,total_counter);
                    if ( ret < 0) {
                        return ret;
                    }

                    ret = post_recvs(&test.nodes[i],poll_ret);
                    if (ret < 0) {
                        printf("rxe_send_mc: failed post receives after polling CQ: %d\n", ret);
                        return ret;
                    }

                    if (done != 0 && done % print_base == 0) {
                        print_line(&ts0, done, print_base);
                    }
                }
            }
            printf ("Have sent the last message %u of %lu \n", done, total_counter);
            fprintf (pFile,"Have sent the last message %u of %lu \n", done, total_counter);
        } while (message_batch >= 1000 && if_continue());
    }
    return 0;
}
예제 #2
0
ret ThreadPool::init(int _num)
{
    if_return(0 >= _num, ret_args_error);
    this->task_queue_ = new(std::nothrow) ThreadPoolTaskQueue();
    if_return(nullptr_t == this->task_queue_, ret_fail);
    this->task_queue_ ->add_ref();

    for (int i = 0; i < _num; ++i)
    {
        pthread_t _t;
        pthread_attr_t _attr;
        ::pthread_attr_init(&_attr);
        ::pthread_attr_setdetachstate(&_attr, PTHREAD_CREATE_DETACHED);
        int _ret = ::pthread_create(&_t, &_attr, ThreadPool::__thread_function, (void*)task_queue_);
        ::pthread_attr_destroy(&_attr);
        if_continue(0 != _ret);
    }

    this->task_queue_ ->del_ref();
    return ret_success;
}
예제 #3
0
static int poll_send_cqs(void)
{
    struct ibv_wc wc[POLL_BATCH];
    int done, i, ret, poll_ret;
    long total_counter = 0;

    struct timespec ts0;
    ts0.tv_sec = -1;
    ts0.tv_nsec = -1;
    struct timespec tslow, remp;
    tslow.tv_sec = 0;
    tslow.tv_nsec = 1;

    if(!is_sender) {
        printf(" called poll_send_cqs() with receiving side \n");
        return -1;
    }

    if (print_base == -1) print_base = message_buffer * message_batch;

    for (i = 0; i < connections; i++) {
        if (!test.nodes[i].connected)
            continue;

        do {
            for (done = 0; done < message_buffer * message_batch; done += poll_ret) {
                poll_ret = ibv_poll_cq(test.nodes[i].cq, POLL_BATCH, wc);
                total_counter += poll_ret;

                if (poll_ret < 0) {
                    printf("rxe_send_mc: failed polling CQ: %d\n", poll_ret);
                    return poll_ret;
                }
                else if (poll_ret > 0) {
                    if(ts0.tv_sec == -1 && ts0.tv_nsec == -1) {
                        clock_gettime(CLOCK_REALTIME, &ts0);
                    }

                    if(wc->opcode == IBV_WC_SEND && wc->status == IBV_WC_SUCCESS ) {
                        /*					if(done % 20 == 0) {
                        						if(nanosleep(&tslow,&remp)) {
                        							printf("sleep error\n");
                        							return -1;
                        						}
                        					}
                        */
                        ret = post_sends(&test.nodes[i],IBV_SEND_SIGNALED,poll_ret);
                        if (ret < 0) {
                            printf("rxe_send_mc: failed post sends after polling CQ: %d\n", ret);
                            return ret;
                        }
                        if(done != 0 && done % print_base == 0) {
                            print_line(&ts0, done, print_base);
                        }
                    }
                }
            }
            printf ("Have the last message %u of %lu \n", done, total_counter);
//		fprintf (pFile,"Have the last message %u of %lu \n", done, total_counter);
        } while (message_batch >= 1000 && if_continue());
    }
    return 0;
}