コード例 #1
0
ファイル: bench_rpc.c プロジェクト: fovecifer/mpaxos
int main(int argc, char **argv) {
//    for (int i=1; i<NSIG; i++) {
//        //if (signal(SIGINT, sig_handler) == SIG_ERR) printf("\ncan't catch SIGINT\n");
//        if (signal(i, sig_handler) == SIG_ERR) printf("\ncan't catch %s\n", strsignal(i));
//    }
    signal(SIGPIPE, SIG_IGN);

    apr_initialize();
    apr_pool_create(&mp_rpc_, NULL);
    apr_thread_cond_create(&cd_rpc_, mp_rpc_);
    apr_thread_mutex_create(&mx_rpc_, APR_THREAD_MUTEX_UNNESTED, mp_rpc_);
    rpc_init();

    arg_parse(argc, argv);

    bool exit = false;

    exit |=  !(is_server_ || is_client_);
    exit |= (addr_ == NULL);
    exit |= (port_ == 0);

    if (exit) {
	fprintf(stderr, "wrong arguments.\n");
	usage(argv[0]);
	return 0;
    }

    if (is_server_) {
        server_t *server = NULL;
        server_create(&server, NULL);    
        strcpy(server->comm->ip, addr_);
        server->comm->port = port_;
        server_reg(server, ADD, add); 
        server_start(server);
        LOG_INFO("server started start on %s, port %d.", addr_, port_);
    } 
    
    if (is_client_) {
	LOG_INFO("client to %s:%d, test for %d rpc in total, outstanding rpc: %d", addr_, port_, max_rpc_, max_outst_);
       
        apr_thread_mutex_lock(mx_rpc_);
        for (int i = 0; i < n_client_; i++) {
            apr_thread_t *th;
            apr_thread_create(&th, NULL, client_thread, NULL, mp_rpc_);
        }
        LOG_INFO("rpc triggered for %d adds on %d threads.", max_rpc_ * n_client_, n_client_);
        apr_thread_cond_wait(cd_rpc_, mx_rpc_);
        apr_thread_mutex_unlock(mx_rpc_);

        int period = (tm_end_ - tm_begin_); //micro seconds
        LOG_INFO("finish %d rpc in %d ms.", max_rpc_ * n_client_, period/1000);
        float rate = (float) max_rpc_ * n_client_ / period;
        LOG_INFO("rpc rate %f million per sec.", rate);
    }

    fflush(stdout);
    fflush(stderr);

    while(is_server_) {
	apr_sleep(1000000);
    }

    rpc_destroy();
    atexit(apr_terminate);
}
コード例 #2
0
ファイル: bench_rpc.c プロジェクト: Abioy/mpaxos
int main(int argc, char **argv) {
//    for (int i=1; i<NSIG; i++) {
//        //if (signal(SIGINT, sig_handler) == SIG_ERR) printf("\ncan't catch SIGINT\n");
//        if (signal(i, sig_handler) == SIG_ERR) printf("\ncan't catch %s\n", strsignal(i));
//    }
    signal(SIGPIPE, SIG_IGN);

    apr_initialize();

    apr_pool_create(&mp_rpc_, NULL);
    apr_thread_cond_create(&cd_rpc_, mp_rpc_);
    apr_thread_mutex_create(&mx_rpc_, APR_THREAD_MUTEX_UNNESTED, mp_rpc_);
    rpc_init();

    arg_parse(argc, argv);
    ADD = is_fast_ ? FAST_ADD : SLOW_ADD;
    bool exit = false;

    exit |=  !(is_server_ || is_client_);
    exit |= (addr_ == NULL);
    exit |= (port_ == 0);

    if (exit) {
	fprintf(stderr, "wrong arguments.\n");
	usage(argv[0]);
	return 0;
    }

    if (is_server_) {
        server_t *server = NULL;
	poll_mgr_t *mgr_server = NULL;
	poll_mgr_create(&mgr_server, n_server_thread_);
        server_create(&server, mgr_server);    
        strcpy(server->comm->ip, addr_);
        server->comm->port = port_;
        server_reg(server, ADD, add); 
        server_start(server);
        LOG_INFO("server started start on %s, port %d.", addr_, port_);
    } 
    
    if (is_client_) {
	LOG_INFO("client to %s:%d, test for %d rpc in total, outstanding rpc: %d",
		 addr_, port_, max_rpc_, max_outst_);

	mgrs_ = (poll_mgr_t **) malloc(n_client_ * sizeof(poll_mgr_t*));
	clis_ = (client_t **) malloc(n_client_ * sizeof(client_t *));
	n_issues_ = (uint64_t*) malloc(n_client_ * sizeof(uint64_t));	
	n_callbacks_ = (uint64_t*) malloc(n_client_ * sizeof(uint64_t));
	n_active_cli_ = n_client_;
       
        apr_thread_mutex_lock(mx_rpc_);
        for (int i = 0; i < n_client_; i++) {
            apr_thread_t *th;
            apr_thread_create(&th, NULL, client_thread, (intptr_t) i, mp_rpc_);
        }
	
	
	if (max_rpc_ < 0) {
	    LOG_INFO("infinite rpc on %d threads (clients)", n_client_);
	} else {
	    LOG_INFO("%d threads (clients), each client run for %d rpc.", 
		     n_client_, max_rpc_ * n_client_);
	}

        apr_thread_cond_wait(cd_rpc_, mx_rpc_);
        apr_thread_mutex_unlock(mx_rpc_);

        int period = (tm_end_ - tm_begin_); //micro seconds
        LOG_INFO("finish %d rpc in %d ms.", max_rpc_ * n_client_, period/1000);
        float rate = (float) max_rpc_ * n_client_ / period;
        LOG_INFO("rpc rate %f million per sec.", rate);
	
	for (int i = 0; i < n_client_; i++) {
	    client_destroy(clis_[i]);
	    poll_mgr_destroy(mgrs_[i]);
	}
	free (clis_);
	free (n_issues_);
    }

    fflush(stdout);
    fflush(stderr);

    while(is_server_) {
	apr_sleep(1000000);
    }

    rpc_destroy();
    atexit(apr_terminate);
}
コード例 #3
0
ファイル: tpg_main.c プロジェクト: Rao-DS/warp17
/*****************************************************************************
 * main()
 ****************************************************************************/
int main(int argc, char **argv)
{
    global_config_t *cfg;
    int              ret;

    /*
     * Initialize DPDK infrastructure before we do anything else
     */
    ret = rte_eal_init(argc, argv);
    if (ret < 0)
        rte_panic("Cannot init EAL\n");

    /*
     * Initialize RTE timer library
     */
    rte_timer_subsystem_init();
    /*
     * Precalculate the number of cycles per us so we don't do it everytime.
     */
    cycles_per_us = (rte_get_timer_hz() / 1000000);

    /*
     * Return value above to be used to scan app specific options
     */
    argc -= ret;
    argv += ret;

    /*
     * General checks
     */
    if (rte_lcore_count() < 3)
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n",
                       "WARP17 needs at least three cores!");
    /* We only support at most 64 cores right now (to make parsing easier). */
    if (rte_lcore_count() > (sizeof(uint64_t) * 8))
        TPG_ERROR_EXIT(EXIT_FAILURE,
                       "ERROR: WARP17 supports at most %"PRIu32" cores!\n",
                       (uint32_t)sizeof(uint64_t) * 8);
    if (rte_eth_dev_count() > TPG_ETH_DEV_MAX)
        TPG_ERROR_EXIT(EXIT_FAILURE,
                       "ERROR: WARP17 works with at most %u ports!\n",
                       TPG_ETH_DEV_MAX);

    /*
     * Initialize various submodules
     */

    if (!cli_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the command line interface");

    if (!rpc_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RPC server");

    if (!cfg_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n",
                       "Failed initializing default configuration!\n");

    if (!cfg_handle_command_line(argc, argv))
        exit(EXIT_FAILURE); /* Error reporting is handled by the function itself */

    if (!trace_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the tracing module");

    if (!trace_filter_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the trace filter module");

    if (!mem_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed allocating required mbufs");

    /* WARNING: Careful when adding code above this point. Up until ports are
     * initialized DPDK can't know that there might be ring interfaces that
     * still need to be created. Therefore any call to rte_eth_dev_count()
     * doesn't include them.
     */
    if (!port_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Ethernets ports");

    if (!msg_sys_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the message queues");

    if (!test_mgmt_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing test mgmt");

    if (!test_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing tests");

    if (!eth_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Ethernets pkt handler");

    if (!arp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the ARP pkt handler");

    if (!route_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the ROUTE module");

    if (!ipv4_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the IPv4 pkt handler");

    if (!tcp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP pkt handler");

    if (!udp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the UDP pkt handler");

    if (!tlkp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Session lookup engine");

    if (!tlkp_tcp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP lookup engine");

    if (!tlkp_udp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the UDP lookup engine");

    if (!tsm_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TSM module");

    if (!timer_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP timers module");

    if (!pkt_loop_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the pkt loop");

    if (!raw_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RAW Application module");

    if (!http_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RAW Application module");

    start_cores();

    /*
     * Process startup command file, if any.
     */
    cfg = cfg_get_config();
    if (cfg != NULL && cfg->gcfg_cmd_file) {
        if (!cli_run_input_file(cfg->gcfg_cmd_file))
            TPG_ERROR_EXIT(EXIT_FAILURE, "Failed to run command file: %s!\n",
                           cfg->gcfg_cmd_file);
    }

    /*
     * Process CLI commands, and other house keeping tasks...
     */
    cli_interact();
    tpg_exit = true;

    /*
     * Exit!!!
     */
    rte_eal_mp_wait_lcore();

    /*
     * Destroy the CLI.
     */
    cli_exit();

    /*
     * Destroy the mgmt RPC server.
     */
    rpc_destroy();
    return 0;
}