コード例 #1
0
ファイル: MSSharedMem.cpp プロジェクト: aissat/trick
int Trick::MSSharedMem::connect() {
    int ret ; 
    /** @par Detailed Design */
    /** @li Call tsm_init to create shared memory for slave. */
    if (tsm_dev.size == 0) {
        tsm_dev.size = sizeof(MSSharedMemData);
        ret = tsm_init(&tsm_dev);
    } else {
    // handle reconnecting for dmtcp restart
        ret = tsm_reconnect(&tsm_dev);
    }
    shm_addr = (MSSharedMemData*) tsm_dev.addr;
    return(ret) ;
}
コード例 #2
0
ファイル: MSSharedMem.cpp プロジェクト: aissat/trick
int Trick::MSSharedMem::accept() {

    int ret ; 
    /** @par Detailed Design */
    /** @li Call tsm_init to create shared memory for master. */
    tsm_dev.size = sizeof(MSSharedMemData);
    ret = tsm_init(&tsm_dev);
    shm_addr = (MSSharedMemData*) tsm_dev.addr;
    /** @li Save master process id so we can keep master and slave data seperate. */
    // (the master calls accept)
    if (ret==TSM_SUCCESS) {
        shm_addr->master_pid = getpid();
//fprintf(stderr, "====accept master=%d\n", getpid());
        MSQ_INIT(shm_addr->master_time);
        MSQ_INIT(shm_addr->master_command);
        MSQ_INIT(shm_addr->slave_command);
        shm_addr->slave_port = MS_ERROR_PORT;
        shm_addr->chkpnt_name[0] = MS_ERROR_NAME;
    } else {
//fprintf(stderr, "====accept SHARED MEMORY ERROR\n");
    }
    return(ret) ;
}
コード例 #3
0
ファイル: test_tsmapi.c プロジェクト: tstibor/ltsm
void test_fcalls(CuTest *tc)
{
	int rc;
	struct login_t login;
	char fpath[][5 + LEN_RND_STR + 1] = {"/tmp/",
					     "/tmp/",
					     "/tmp/",
					     "/tmp/"};

	for (uint8_t r = 0; r < sizeof(fpath)/sizeof(fpath[0]); r++) {
		char rnd_s[LEN_RND_STR + 1] = {0};
		rnd_str(rnd_s, LEN_RND_STR);
		snprintf(fpath[r] + 5, LEN_RND_STR + 1, "%s", rnd_s);
	}

	login_fill(&login, SERVERNAME, NODE, PASSWORD,
		   OWNER, LINUX_PLATFORM, DEFAULT_FSNAME,
		   DEFAULT_FSTYPE);

	struct session_t session;
	memset(&session, 0, sizeof(struct session_t));

	rc = tsm_init(DSM_SINGLETHREAD);
	CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc);

	rc = tsm_fconnect(&login, &session);
	CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc);

	srand(time(NULL));
	FILE *file = NULL;

        for (uint8_t r = 0; r < sizeof(fpath)/sizeof(fpath[0]); r++) {

		unlink(fpath[r]);

                file = fopen(fpath[r], "w+");
		CuAssertPtrNotNull(tc, file);

		rc = tsm_fopen(DEFAULT_FSNAME, fpath[r], "written by cutest",
			       &session);
		CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc);

                unsigned char *buf = NULL;
                for (uint8_t b = 0; b < 16; b++) {
			size_t buf_size = 1 + (rand() % 1048576); /* 2^20 = 1 MiB */
			buf = calloc(buf_size, sizeof(unsigned char));
			CuAssertPtrNotNull(tc, buf);

			for (size_t r = 0; r < buf_size; r++)
				buf[r] = rand() % 256;

			size_t written = 0;
			size_t total_written = 0;
			size_t rand_nmemb;
			size_t to_write = buf_size;

			size_t written_tsm = 0;
			size_t total_written_tsm = 0;
			do {
				rand_nmemb = 1 + (rand() % buf_size);
				written = fwrite(buf, 1, rand_nmemb, file);
				total_written += written;
				written_tsm = tsm_fwrite(buf, 1, rand_nmemb, &session);
				total_written_tsm += written_tsm;

				buf_size -= rand_nmemb;
			} while (buf_size != 0 || written == 0);

			CuAssertIntEquals(tc, to_write, total_written);
			CuAssertIntEquals(tc, to_write, total_written_tsm);
			free(buf);
		}

		fclose(file);
		file = NULL;

		uint32_t crc32sum = 0;
		rc = crc32file(fpath[r], &crc32sum);
		CuAssertIntEquals(tc, 0, rc);

		CuAssertIntEquals(tc, crc32sum ,
				  session.tsm_file->archive_info.obj_info.crc32);

		rc = tsm_fclose(&session);
		CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc);

		rc = tsm_delete_fpath(DEFAULT_FSNAME, fpath[r], &session);
		CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc);
	}

	tsm_fdisconnect(&session);
	tsm_cleanup(DSM_SINGLETHREAD);
}
コード例 #4
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;
}