Esempio n. 1
0
/**
 * \brief Main..
 */
int main(int argc, char **argv, char **envp) {
    int i, last;
    Load load_data;
    char **load_names = NULL;
    int load_filesize = 0;
    char *load_buffer = NULL;
    int config_filesize = 0;
    char *config_buffer = NULL;
    char *config_file = NULL;
    char *log_file = NULL;
    int num_loads = 0;
    struct timeval StartTime, CurrentTime;

    int **errorFlags;
    int err = ERR_CLEAN;
    int pflag = 0;
    Plan *CommPlan;
    int iflag;
    unsigned int nap;

    comm_setup(&argc, &argv);
    MyRank = comm_getrank();

    last = 0;

    num_loads = initialize(argc, argv, &log_file, &config_file, &load_names);

    /* Initialize ROOT's global variables using input files. */
    if(MyRank == ROOT) {
        config_filesize = initConfigOptions(config_file, &config_buffer);         /* parse configuration file. */
        if((config_filesize <= 0) || (config_buffer == NULL) ) {
            EmitLog(MyRank, SCHEDULER_THREAD, "Aborting run - A config file could not be opened/read.", -1, PRINT_ALWAYS);
            config_filesize = 0;
            if(config_buffer != NULL) {
                free(config_buffer);
            }
        }
        comm_broadcast_int(&config_filesize);
    } else {
        comm_broadcast_int(&config_filesize);
        config_buffer = getFileBuffer(config_filesize);
    }

    if(config_filesize == 0) {
        comm_finalize();
        exit(1);
    }

    err = broadcast_buffer(config_buffer, config_filesize);

    err += parseConfig(config_buffer, config_filesize);
    free(config_buffer);

    if(MyRank == ROOT) {
        if(PRINT_RARELY <= verbose_flag) {          /* Print status info. */
            printf("num_loads                = %d\n", num_loads);
            printf("num_workers              = %d\n", num_workers);
            printf("thermal_panic            = %d\n", thermal_panic);
            printf("thermal_relaxation_time  = %d\n", thermal_relaxation_time);
            printf("monitor_frequency        = %d\n", monitor_frequency);
            printf("monitor_output_frequency = %d\n", monitor_output_frequency);
            printf("temperature_path         = %s\n", temperature_path);
            for(i = 0; i < num_loads; i++) {
                printf("load_names[%d]           = %s\n", i, load_names[i]);
            }
            printf("log_file                 = %s\n", log_file);
        }
    }

    // num_loads = bcastConfig(num_loads); // Broadcast global variables from ROOT to all others.
    if(num_loads <= 0) {                    // If there are no loads to run, exit the program.
        comm_finalize();
        exit(0);
    }

    /* Initialize the communication load if it is to be run */
    if(comm_flag != 0) {
        data pass;
        pass.isize = 1;
        pass.i = &comm_flag;
        CommPlan = makeCommPlan(&pass);
    } else {
        CommPlan = 0;
    }
    if(CommPlan != 0) {
        iflag = (CommPlan->fptr_initplan)(CommPlan);
    }

    /* Initialize the array of ThreadHandle structures for the workers. */
    WorkerHandle = (ThreadHandle *)malloc(num_workers * sizeof(ThreadHandle));
    if(WorkerHandle == NULL) {
        EmitLog(MyRank, SCHEDULER_THREAD, "Aborting run - Insufficient memory for the WorkerHandle struct", -1, PRINT_ALWAYS);
        comm_finalize();
        exit(1);
    }

    errorFlags = initErrorFlags();
    initWorkerFlags();

    if(DO_PERF) {
        performance_init();
    }     //DO_PERF

    if(MyRank == ROOT) {
        EmitLog(MyRank, SCHEDULER_THREAD, "Initialization complete. Beginning run.", -1, PRINT_ALWAYS);
    }

    StartMonitorThread();
    StartWorkerThreads();

    sleep(thermal_relaxation_time);     /* idle for a baseline */
    reduceTemps();
    sleep(thermal_relaxation_time);

    /*********************************************************************************
    * The following code will subscribe plans and their sizes to worker threads.
    * This is a temporary load distribution being that it comes from a single load.
    * In the future we would like to have several loads lined up to distribute to the
    * worker threads in a simlar fashion. This will allow us to run the benchmark
    * for different time durations depending on the total load schedule.
    *********************************************************************************/
    nap = monitor_output_frequency / 4;
    if(nap < 1) {
        nap = 1;
    }
    for(i = 0; i < num_loads; i++) {
        if(MyRank == ROOT) {                                    // Pull load data from a load file.
            assert(load_names);
            load_filesize = initLoadOptions(load_names[i], &load_buffer);
            if((load_filesize <= 0) || (load_buffer == NULL) ) {
                // /* Redundant */fprintf(stderr, "This load file could not be opened/read... trying next (if available).\n");
                EmitLog(MyRank, SCHEDULER_THREAD, "This load file could not be opened/read... trying next (if available).", -1, PRINT_ALWAYS);
                load_filesize = 0;
                if(load_buffer != NULL) {
                    free(load_buffer);
                }
            }
            comm_broadcast_int(&load_filesize);
            if(load_filesize == 0) {
                continue;
            }
        } else {
            comm_broadcast_int(&load_filesize);
            if(load_filesize == 0) {
                continue;
            }
            load_buffer = getFileBuffer(load_filesize);
        }
        err = broadcast_buffer(load_buffer, load_filesize);
        err += parseLoad(load_buffer, &load_data);
        free(load_buffer);
        // err = bcastLoad(&load_data);             // Broadcast the load structure to all nodes (processes).
        err = WorkerSched(&load_data);                                  // Assign the load to worker threads and check for errors
        if(MyRank == ROOT) {
            printLoad(&load_data);                                      // Print the load data to the terminal.
        }
        if(err != ERR_CLEAN) {
            errorFlags[SYSTEM + 1][err]++;
        }
#define SB_CONTINUE      0x0
#define SB_LAST_TRIP     0x1
#define SB_DO_REDUCTIONS 0x2
        if(MyRank == ROOT) {                                            // ROOT notes when we start this load
            gettimeofday(&StartTime, NULL);
            last = StartTime.tv_sec;
        }
        do {            // DELAY WHILE LOAD RUNS: loop while the load executes until ROOT's clock says stop.  Sleep if CommPlan isn't valid.
            if((comm_flag != 0) && (CommPlan) && (CommPlan->fptr_execplan) && (CommPlan->vptr)) {
                iflag = (CommPlan->fptr_execplan)(CommPlan);                             // run an iteration of the comm plan if enabled
            } else {
                gettimeofday(&CurrentTime, NULL);
                if(nap + CurrentTime.tv_sec < StartTime.tv_sec + load_data.runtime) {
                    sleep(nap);
                } else {
                    sleep((StartTime.tv_sec + load_data.runtime)-CurrentTime.tv_sec);
                }
            }
            if(MyRank == ROOT) {
                gettimeofday(&CurrentTime, NULL);
                pflag = ((CurrentTime.tv_sec > last + monitor_output_frequency) << 1) | (CurrentTime.tv_sec < StartTime.tv_sec + load_data.runtime);
            }
            comm_broadcast_int(&pflag);
            if(pflag & SB_DO_REDUCTIONS) {
                assert(errorFlags);
                reduceFlags(errorFlags);
                reduceTemps();
                if(MyRank == ROOT) {
                    last = CurrentTime.tv_sec;
                }
            }
        } while(pflag & SB_LAST_TRIP);
        // LOAD COMPLETE
        if(MyRank == ROOT) {
            EmitLog(MyRank, SCHEDULER_THREAD, "Elapsed time for this load:", CurrentTime.tv_sec - StartTime.tv_sec, PRINT_ALWAYS);
        }
        freeLoad(&load_data);
    }
    sleep(thermal_relaxation_time);
    reduceTemps();
    StopWorkerThreads();                        // tell them all to finish

    // Clean up the Communication Plan
    if((comm_flag != 0) && (CommPlan) && (CommPlan->vptr)) {
        if(CommPlan->fptr_perfplan) {
            iflag = (CommPlan->fptr_perfplan)(CommPlan);
        }
        if(CommPlan->fptr_killplan) {
            CommPlan = (CommPlan->fptr_killplan)(CommPlan);
        }
    }

    sleep(thermal_relaxation_time);

    if(DO_PERF) {
        sleep(30);
        perf_table_print(LOCAL, PRINT_OFTEN);
        perf_table_reduce();

        perf_table_maxreduce();
        perf_table_minreduce();

        if(MyRank == ROOT) {
            perf_table_print(GLOBAL, PRINT_ALWAYS);
        }
    } //DO_PERF

    if(MyRank == ROOT) {
        EmitLog(MyRank, SCHEDULER_THREAD, "Run Completed. Exiting.", -1, PRINT_ALWAYS);
    }

    comm_finalize();
    exit(0);
} /* main */
int
main(
    int                                 argc,
    char *                              argv[])
{
    int                                 rc;
    globus_bool_t                       server = GLOBUS_FALSE;
    char                                gets_buffer[1024];
    http_test_info_t *			info;
    performance_t                       perf;

    info = (http_test_info_t *) globus_malloc(sizeof(http_test_info_t));
    info->version = GLOBUS_XIO_HTTP_VERSION_UNSET;
    info->transfer_encoding = NULL;
    info->iterations = 100;
    info->temp_iterations = 100;
    info->size = 0;
    info->contact = NULL;
    while ((rc = getopt(argc, argv, "h:cst:b:v:i:")) != EOF)
    {
        switch (rc)
        {
            case 'h':
                usage(argv[0]);
                exit(0);
            case 'c':
                server = GLOBUS_FALSE;
                info->contact = fgets(gets_buffer, sizeof(gets_buffer), stdin);
                break;
            case 's':
                server = GLOBUS_TRUE;
                info->contact = NULL;
                break;
            case 't':
                if ((strcmp(optarg, CHUNKED) == 0)
                        || (strcmp(optarg, IDENTITY) == 0))
                {
                    info->transfer_encoding = optarg;
                }
                else
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'b':
                sscanf(optarg, "%zd", &info->size);

                if (rc != 1)
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'v':
                if (strcmp(optarg, HTTP_1_0) == 0)
                {
                    info->version = GLOBUS_XIO_HTTP_VERSION_1_0;
                }
                else if (strcmp(optarg, HTTP_1_1) == 0)
                {
                    info->version = GLOBUS_XIO_HTTP_VERSION_1_1;
                }
                else
                {
                    usage(argv[0]);
                    exit(1);
                }
                break;
            case 'i':
                info->iterations = atoi(optarg);

                if (info->iterations <= 0)
                {
                    usage(argv[0]);
                    exit(1);
                }
		info->temp_iterations = info->iterations;
                break;
            default:
                usage(argv[0]);
                exit(1);
        }
    }
    if ((!server) && (info->contact == NULL))
    {
        usage(argv[0]);
        exit(1);
    }

    if (info->iterations > 1 && info->version == GLOBUS_XIO_HTTP_VERSION_1_0)
    {
        fprintf(stderr,
                "Can't have multiple iterations with HTTP/1.0 server\n");
        usage(argv[0]);
        exit(1);
    }

    rc = http_test_initialize(
		&info->tcp_driver, &info->http_driver, &info->stack);

    if (rc != 0)
    {
        goto error_exit;
    }

    if (server)
    {
	performance_init(
	    &perf,
	    server_test,
	    throughput_next_size,
	    info->iterations,
	    "throughput-globus-xio-http",
	    info->size);
	performance_start_slave(&perf, info);
    }
    else
    {
	performance_init(
	    &perf,
	    client_test,
	    throughput_next_size,
	    info->iterations,
	    "throughput-globus-xio-http",
	    info->size);
	rc = performance_start_master(&perf, info);
	if (rc != 0)
	{
	    goto error_exit;
	}
	performance_write_timers(&perf);
    }

    globus_xio_stack_destroy(info->stack);
    globus_xio_driver_unload(info->tcp_driver);
    globus_xio_driver_unload(info->http_driver);

    globus_module_deactivate_all();

error_exit:
    if (rc == 0)
    {
        printf("Success\n");
    }
    else
    {
        printf("Error\n");
    }
    return rc;
}
int main(int argc, char **argv)
{
	int i;
	char condition[MAX_FILTER_LEN];
	
	if(argc != 2)
	{
		fprintf(stderr,"Usage : %s num_of_flows_to_open\n",argv[0]);
		exit(1);
	}
	
	nosocks = atoi(argv[1]);
	nosocks++;

	for( i = 0 ; i < nosocks ; i++)
	{
		if((sock[i] = socket(PF_MAPI,SOCK_RAW,htons(ETH_P_ALL))) < 0)
		{
			perror("socket");
			exit(1);
		}
	}
	
	atexit(terminate);
	
	if(bind_if_name(sock[0],IFNAME))
	{
		perror("bind_if_name");
		exit(1);
	}

	if(ioctl(sock[0],SIOCSCOUNT_BYTES,&cbs))
	{
		perror("ioctl");
		exit(1);
	}

	for( i = 1 ; i < nosocks ; i++)
	{
		int len;
		int start;
		
		start = i;

		len = sprintf(condition,"ether dst %.2x:%.2x:%.2x:%.2x:%.2x:%.2x or ",
			      start%0xFF,(start+1)%0xFF,(start+2)%0xFF,(start+3)%0xFF,(start+4)%0xFF,(start+5)%0xFF);
		start += 6;
		len += sprintf(condition + len,"ether src %.2x:%.2x:%.2x:%.2x:%.2x:%.2x or ",
			      start%0xFF,(start+1)%0xFF,(start+2)%0xFF,(start+3)%0xFF,(start+4)%0xFF,(start+5)%0xFF);
		start += 6;
		len += sprintf(condition + len,"ether host %.2x:%.2x:%.2x:%.2x:%.2x:%.2x or ",
			      start%0xFF,(start+1)%0xFF,(start+2)%0xFF,(start+3)%0xFF,(start+4)%0xFF,(start+5)%0xFF);
		start += 6;
		len += sprintf(condition + len,"( ( ether proto \\ip ) and ( ( ip proto \\udp or ip proto \\tcp or ip proto \\icmp) and ");

		len += sprintf(condition + len,"( src host %u.%u.%u.%u or src host %u.%u.%u.%u or ",
			       start%0xFF,(start+1)%0xFF,(start+2)%0xFF,(start+3)%0xFF,(start+4)%0xFF,(start+5)%0xFF,(start+6)%0xFF,(start+7)%0xFF);
		
		start += 8;
		len += sprintf(condition + len,"src host %u.%u.%u.%u or src host %u.%u.%u.%u ) ) )",
			       start%0xFF,(start+1)%0xFF,(start+2)%0xFF,(start+3)%0xFF,(start+4)%0xFF,(start+5)%0xFF,(start+6)%0xFF,(start+7)%0xFF);
		
		//sprintf(condition,"port %d",i);

		apply_bpf_filter(sock[i],condition);
		
		if(bind_if_name(sock[i],IFNAME))
		{
			perror("bind_if_name");
			exit(1);
		}

		if(ioctl(sock[i],SIOCSCOUNT_BYTES,&cbs))
		{
			perror("ioctl");
			exit(1);
		}
	}
	
	performance_init();

	signal(SIGINT,handler);
	
	pause();

	return 0;
}