Beispiel #1
0
static int mmap_events(synth_cb synth)
{
	struct machines machines;
	struct machine *machine;
	int err, i;

	/*
	 * The threads_create will not return before all threads
	 * are spawned and all created memory map.
	 *
	 * They will loop until threads_destroy is called, so we
	 * can safely run synthesizing function.
	 */
	TEST_ASSERT_VAL("failed to create threads", !threads_create());

	machines__init(&machines);
	machine = &machines.host;

	dump_trace = verbose > 1 ? 1 : 0;

	err = synth(machine);

	dump_trace = 0;

	TEST_ASSERT_VAL("failed to destroy threads", !threads_destroy());
	TEST_ASSERT_VAL("failed to synthesize maps", !err);

	/*
	 * All data is synthesized, try to find map for each
	 * thread object.
	 */
	for (i = 0; i < THREADS; i++) {
		struct thread_data *td = &threads[i];
		struct addr_location al;
		struct thread *thread;

		thread = machine__findnew_thread(machine, getpid(), td->tid);

		pr_debug("looking for map %p\n", td->map);

		thread__find_addr_map(thread,
				      PERF_RECORD_MISC_USER, MAP__FUNCTION,
				      (unsigned long) (td->map + 1), &al);

		thread__put(thread);

		if (!al.map) {
			pr_debug("failed, couldn't find map\n");
			err = -1;
			break;
		}

		pr_debug("map %p, addr %" PRIx64 "\n", al.map, al.map->start);
	}

	machine__delete_threads(machine);
	machines__exit(&machines);
	return err;
}
/*------------------------------------------------------
 Proceso principal
 -----------------------------------------------------*/
int main(int argc, char **argv) {

    global_config config;
    pthread_t* threads;

    if (get_params(argv + 1, argc - 1, &config) != SUCCESS) {
        printf("Error en los argumentos recibidos.\nEjemplo de uso:");
        printf("%s cantidadDeThreds fileSizeInKbytes directory filePrefix\n", argv[0]);
        return EXIT_FAILURE;
    }

    print_a_global_header(config);

    threads = threads_create(config);

    threads_get_and_print_results(threads, config.threads_amount,
                                  config.location, config.files_prefix);

    threads_destroy(threads, 0);

    destroy_params(config);

    return EXIT_SUCCESS;
}
Beispiel #3
0
	void platform_init()
	{
		char buffer[512] = {0};

		/* this environment variable is set by Microsoft Visual Studio
			when building. It causes cl.exe to redirect it's output to
			the specified pipe id. this causes loads of problems with
			output.
		*/ 
		SetEnvironmentVariable("VS_UNICODE_OUTPUT", NULL);

		/* check if we are being spawned by bam in msvc mode so we should be singleton */
		if(GetEnvironmentVariable("BAM_SINGLETON", buffer, sizeof(buffer)-1))
		{
			DWORD ret;
			SetEnvironmentVariable("BAM_SINGLETON", NULL);

			singleton_mutex = CreateMutex(NULL, FALSE, "Global\\bam_singleton_mutex");
			if(!singleton_mutex)
			{
				printf("bam is already running, wait for it to finish and then try again 1\n");
				exit(1);
			}

			while(1)
			{
				ret = WaitForSingleObject( singleton_mutex, 100 );
				if(ret == WAIT_OBJECT_0)
					break;
				else
				{
					/* printf("bam is already running, wait for it to finish and then try again 2 (%d)\n", ret); */
					printf("bam is already running, waiting for it to finish\n"); fflush(stdout);
					Sleep(1000);
				}
			}
		}

		/* this environment variable can be setup so that bam can observe if
			a specific process dies and abort the building if it does. This
			is used in conjunction with Microsoft Visual Studio to make sure
			that it doesn't kill processes wildly.
		*/
		if(GetEnvironmentVariable("BAM_OBSERVE_PID", buffer, sizeof(buffer)-1))
		{
			observe_pid = atoi(buffer);
			threads_create(observer_thread, NULL);

			/* protect process from being killed */
			protect_process();
		}
		else
		{
			if( session.win_msvcmode )
			{
				DWORD errcode;
				PROCESS_INFORMATION pi;
				STARTUPINFO si;

				/* setup ourself to be watched */
				sprintf(buffer, "%d", GetCurrentProcessId());
				SetEnvironmentVariable("BAM_OBSERVE_PID", buffer);

				/* signal that we want to be singleton */
				SetEnvironmentVariable("BAM_SINGLETON", "1");

				/* init structs and create process */
				ZeroMemory( &si, sizeof(si) );
				si.cb = sizeof(si);
				ZeroMemory( &pi, sizeof(pi) );

				if( CreateProcess(
					NULL,      /* No module name (use command line) */
					GetCommandLine(),   /* Command line */
					NULL,      /* Process handle not inheritable */
					NULL,      /* Thread handle not inheritable */
					TRUE,      /* Set handle inheritance to FALSE */
					0,         /* No creation flags */
					NULL,      /* Use parent's environment block */
					NULL,      /* Use parent's starting directory */
					&si,       /* Pointer to STARTUPINFO structure */
					&pi        /* Pointer to PROCESS_INFORMATION structure */
				) ) {
					/* wait for the child to complete */
					WaitForSingleObject(pi.hProcess, INFINITE);
					GetExitCodeProcess(pi.hProcess, &errcode);
					CloseHandle(pi.hProcess);
					CloseHandle(pi.hThread);
					exit(errcode);
				} else {
					printf("failed to spawn new bam process in msvc mode\n");
					printf("%s\n", GetCommandLine());
					exit(1);
				}
			}
		}

		InitializeCriticalSection(&criticalsection);
	}
Beispiel #4
0
int main(int argc, char **argv) {

	gc_attach(main_gc);

	/* Catch all exit signals for gc */
	gc_catch();

	log_shell_enable();
	log_file_disable();
	log_level_set(LOG_NOTICE);

	struct options_t *options = NULL;
	
	char *args = NULL;
	char *hwfile = NULL;
	pid_t pid = 0;

	if(!(settingsfile = malloc(strlen(SETTINGS_FILE)+1))) {
		logprintf(LOG_ERR, "out of memory");
		exit(EXIT_FAILURE);
	}
	strcpy(settingsfile, SETTINGS_FILE);	
	
	if(!(progname = malloc(12))) {
		logprintf(LOG_ERR, "out of memory");
		exit(EXIT_FAILURE);
	}
	strcpy(progname, "pilight-raw");	

	options_add(&options, 'H', "help", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL);
	options_add(&options, 'V', "version", OPTION_NO_VALUE, 0, JSON_NULL, NULL, NULL);
	options_add(&options, 'S', "settings", OPTION_HAS_VALUE, 0, JSON_NULL, NULL, NULL);

	while (1) {
		int c;
		c = options_parse(&options, argc, argv, 1, &args);
		if(c == -1)
			break;
		if(c == -2)
			c = 'H';
		switch (c) {
			case 'H':
				printf("Usage: %s [options]\n", progname);
				printf("\t -H --help\t\tdisplay usage summary\n");
				printf("\t -V --version\t\tdisplay version\n");		
				printf("\t -S --settings\t\tsettings file\n");
				return (EXIT_SUCCESS);
			break;
			case 'V':
				printf("%s %s\n", progname, VERSION);
				return (EXIT_SUCCESS);
			break;	
			case 'S': 
				if(access(args, F_OK) != -1) {
					settingsfile = realloc(settingsfile, strlen(args)+1);
					if(!settingsfile) {
						logprintf(LOG_ERR, "out of memory");
						exit(EXIT_FAILURE);
					}
					strcpy(settingsfile, args);
					settings_set_file(args);
				} else {
					fprintf(stderr, "%s: the settings file %s does not exists\n", progname, args);
					return EXIT_FAILURE;
				}
			break;
			default:
				printf("Usage: %s [options]\n", progname);
				return (EXIT_FAILURE);
			break;
		}
	}
	options_delete(options);

	char pilight_daemon[] = "pilight-daemon";
	char pilight_learn[] = "pilight-learn";
	char pilight_debug[] = "pilight-debug";
	if((pid = findproc(pilight_daemon, NULL)) > 0) {
		logprintf(LOG_ERR, "pilight-daemon instance found (%d)", (int)pid);
		return (EXIT_FAILURE);
	}

	if((pid = findproc(pilight_learn, NULL)) > 0) {
		logprintf(LOG_ERR, "pilight-learn instance found (%d)", (int)pid);
		return (EXIT_FAILURE);
	}

	if((pid = findproc(pilight_debug, NULL)) > 0) {
		logprintf(LOG_ERR, "pilight-debug instance found (%d)", (int)pid);
		return (EXIT_FAILURE);
	}	
	
	if(access(settingsfile, F_OK) != -1) {
		if(settings_read() != 0) {
			return EXIT_FAILURE;
		}
	}	
	
	hardware_init();
	
	if(settings_find_string("hardware-file", &hwfile) == 0) {
		hardware_set_file(hwfile);
		if(hardware_read() == EXIT_FAILURE) {
			goto clear;
		}
	}

	/* Start threads library that keeps track of all threads used */
	threads_create(&pth, NULL, &threads_start, (void *)NULL);

	struct conf_hardware_t *tmp_confhw = conf_hardware;
	while(tmp_confhw) {
		if(tmp_confhw->hardware->init() == EXIT_FAILURE) {
			logprintf(LOG_ERR, "could not initialize %s hardware mode", tmp_confhw->hardware->id);
			goto clear;
		}
		threads_register(tmp_confhw->hardware->id, &receive_code, (void *)tmp_confhw->hardware, 0);
		tmp_confhw = tmp_confhw->next;
	}

	while(main_loop) {
		sleep(1);
	}

clear:
	main_gc();
	return (EXIT_FAILURE);
}
/// Main function, primary avionics functions, thread 0, highest priority.
int main(int argc, char **argv) {

	// Data Structures
	struct  imu   imuData;
	struct  xray  xrayData;
	struct  gps   gpsData;
	struct  nav   navData;
	struct  control controlData;

	uint16_t cpuLoad;

	// Timing variables
	double etime_daq, etime_datalog, etime_telemetry;

	// Include datalog definition
	#include DATALOG_CONFIG

	// Populate dataLog members with initial values //
	dataLog.saveAsDoubleNames = &saveAsDoubleNames[0];
	dataLog.saveAsDoublePointers = &saveAsDoublePointers[0];
	dataLog.saveAsFloatNames = &saveAsFloatNames[0];
	dataLog.saveAsFloatPointers = &saveAsFloatPointers[0];
	dataLog.saveAsXrayNames = &saveAsXrayNames[0];
	dataLog.saveAsXrayPointers = &saveAsXrayPointers[0];
	dataLog.saveAsIntNames = &saveAsIntNames[0];
	dataLog.saveAsIntPointers = &saveAsIntPointers[0];
	dataLog.saveAsShortNames = &saveAsShortNames[0];
	dataLog.saveAsShortPointers = &saveAsShortPointers[0];
	dataLog.logArraySize = LOG_ARRAY_SIZE;
	dataLog.numDoubleVars = NUM_DOUBLE_VARS;
	dataLog.numFloatVars = NUM_FLOAT_VARS;
	dataLog.numXrayVars = NUM_XRAY_VARS;
	dataLog.numIntVars = NUM_INT_VARS;
	dataLog.numShortVars = NUM_SHORT_VARS;

	double tic,time,t0=0;
	static int t0_latched = FALSE;
	int loop_counter = 0;
	pthread_mutex_t	mutex;

	uint32_t cpuCalibrationData;//, last100ms, last1s, last10s;
	cyg_cpuload_t cpuload;
	cyg_handle_t loadhandle;

	// Populate sensorData structure with pointers to data structures //
	sensorData.imuData_ptr = &imuData;
	sensorData.gpsData_ptr = &gpsData;
	sensorData.xrayData_ptr = &xrayData;

	// Set main thread to highest priority //
	struct sched_param param;
	param.sched_priority = sched_get_priority_max(SCHED_FIFO);
	pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);

	// Setup CPU load measurements //
	cyg_cpuload_calibrate(&cpuCalibrationData);
	cyg_cpuload_create(&cpuload, cpuCalibrationData, &loadhandle);

	// Initialize set_actuators (PWM or serial) at zero //
//	init_actuators();
//	set_actuators(&controlData);

	// Initialize mutex variable. Needed for pthread_cond_wait function //
	pthread_mutex_init(&mutex, NULL);
	pthread_mutex_lock(&mutex);

	// Initialize functions	//
	init_daq(&sensorData, &navData, &controlData);
	init_telemetry();

	while(1){
		//Init Interrupts
			printf("intr init");
			
			cyg_uint32 uChannel = MPC5XXX_GPW_GPIO_WKUP_7;
			
			BOOL enable = true;
			BOOL bInput = 1;		
			
			// uChannel initialisation
			GPIO_GPW_EnableGPIO(uChannel, enable);
			GPIO_GPW_SetDirection(uChannel, bInput);
			GPIO_GPW_EnableInterrupt(uChannel, enable, MPC5XXX_GPIO_INTTYPE_RISING);
			GPIO_GPW_ClearInterrupt(uChannel);
			HAL_WRITE_UINT32(MPC5XXX_GPW+MPC5XXX_GPW_ME, 0x01000000);
			cyg_uint32 temp;
			HAL_READ_UINT32(MPC5XXX_ICTL_MIMR, temp);
			HAL_WRITE_UINT32(MPC5XXX_ICTL_MIMR, temp&0xFFFFFEFF);
	
			// wake-up interrupt service routine initialisation
			cyg_vector_t int1_vector = CYGNUM_HAL_INTERRUPT_GPIO_WAKEUP;
			cyg_priority_t int1_priority = 0;
			cyg_bool_t edge = 0;
			cyg_bool_t rise = 1;
			cyg_drv_interrupt_create(int1_vector, int1_priority,0,interrupt_1_isr, interrupt_1_dsr,&int1_handle,&int1);
			cyg_drv_interrupt_attach(int1_handle);
			cyg_drv_interrupt_configure(int1_vector,edge,rise);
			cyg_drv_interrupt_unmask(int1_vector);
			
			hasp_mpc5xxx_i2c_init(); 	// Append: Initialise I2C bus and I2C interrupt routine; device defined in i2c_mpc5xxx.h and .c
			
			cyg_interrupt_enable();
			HAL_ENABLE_INTERRUPTS();

		controlData.mode = 1; 		// initialize to manual mode
		controlData.run_num = 0; 	// reset run counter

		reset_Time();				// initialize real time clock at zero
		init_scheduler();			// Initialize scheduling
		threads_create();			// start additional threads
		init_datalogger();			// Initialize data logging

		//+++++++++++//
		// Main Loop //
		//+++++++++++//
		
		while (controlData.mode != 0) {
			
			loop_counter++; //.increment loop counter

			//**** DATA ACQUISITION **************************************************
			pthread_cond_wait (&trigger_daq, &mutex);
			tic = get_Time();			
			get_daq(&sensorData, &navData, &controlData);		
			etime_daq = get_Time() - tic - DAQ_OFFSET; // compute execution time
			
			//************************************************************************

			//**** NAVIGATION ********************************************************
//			pthread_cond_wait (&trigger_nav, &mutex);
//			if(navData.err_type == got_invalid){ // check if get_nav filter has been initialized
//				if(gpsData.navValid == 0) // check if GPS is locked
//					init_nav(&sensorData, &navData, &controlData);// Initialize get_nav filter
//			}
//			else
//				get_nav(&sensorData, &navData, &controlData);// Call NAV filter

			//************************************************************************

			if (controlData.mode == 2) { // autopilot mode
				if (t0_latched == FALSE) {
					t0 = get_Time();
					t0_latched = TRUE;
				}
				time = get_Time()-t0; // Time since in auto mode		
			}
			else{
				if (t0_latched == TRUE) {				
					t0_latched = FALSE;
				}
				//reset_control(&controlData); // reset controller states and set get_control surfaces to zero
			} // end if (controlData.mode == 2) 

			// Add trim biases to get_control surface commands
			//add_trim_bias(&controlData);

			//**** DATA LOGGING ******************************************************
			
			pthread_cond_wait (&trigger_datalogger, &mutex);
			datalogger(&sensorData, &navData, &controlData, cpuLoad);
			cyg_drv_interrupt_mask(int1_vector); 
			xray_dump = dataprinter(sensorData, xray_dump);
			cyg_drv_interrupt_unmask(int1_vector); 
			etime_datalog = get_Time() - tic - DATALOG_OFFSET; // compute execution time
			
			//************************************************************************

			//**** TELEMETRY *********************************************************
			if(loop_counter >= BASE_HZ/TELEMETRY_HZ){
				loop_counter = 0;
				pthread_cond_wait (&trigger_telemetry, &mutex);
//
				// get current cpu load
//				cyg_cpuload_get (loadhandle, &last100ms, &last1s, &last10s);
//				cpuLoad = (uint16_t)last100ms;
//
				send_telemetry(&sensorData, &navData, &controlData, cpuLoad);
//
//				etime_telemetry = get_Time() - tic - TELEMETRY_OFFSET; // compute execution time
			}
					
			//************************************************************************	
		} //end while (controlData.mode != 0)

		close_scheduler();
		close_datalogger(); // dump data

	} // end while(1)
	/**********************************************************************
	 * close
	 **********************************************************************/
	pthread_mutex_destroy(&mutex);
//	close_actuators();	
	//close_nav();

	return 0;

} // end main
Beispiel #6
0
int main(int argc, char** argv)
{
    int iter = 100;
    uint32_t i;
    uint32_t j;
    int globalNumberOfThreads = 0;
    int optPrintDomains = 0;
    int c;
    ThreadUserData myData;
    bstring testcase = bfromcstr("none");
    uint32_t numberOfWorkgroups = 0;
    int tmp = 0;
    double time;
    const TestCase* test = NULL;
    Workgroup* currentWorkgroup = NULL;
    Workgroup* groups = NULL;

    cpuid_init();
    numa_init();
    affinity_init();

    /* Handling of command line options */
    if (argc ==  1) { HELP_MSG; }

    while ((c = getopt (argc, argv, "g:w:t:i:l:aphv")) != -1) {
        switch (c)
        {
            case 'h':
                HELP_MSG;
                exit (EXIT_SUCCESS);    
            case 'v':
                VERSION_MSG;
                exit (EXIT_SUCCESS);    
            case 'a':
                printf(TESTS"\n");
                exit (EXIT_SUCCESS);    
            case 'w':
                tmp--;

                if (tmp == -1)
                {
                    fprintf (stderr, "More workgroups configured than allocated!\n");
                    return EXIT_FAILURE;
                }
                if (!test)
                {
                    fprintf (stderr, "You need to specify a test case first!\n");
                    return EXIT_FAILURE;
                }
                testcase = bfromcstr(optarg);
                currentWorkgroup = groups+tmp;  /*FIXME*/
                bstr_to_workgroup(currentWorkgroup, testcase, test->type, test->streams);
                bdestroy(testcase);

                for (i=0; i<  test->streams; i++)
                {
                    if (currentWorkgroup->streams[i].offset%test->stride)
                    {
                        fprintf (stderr, "Stream %d: offset is not a multiple of stride!\n",i);
                        return EXIT_FAILURE;
                    }

                    allocator_allocateVector(&(currentWorkgroup->streams[i].ptr),
                            PAGE_ALIGNMENT,
                            currentWorkgroup->size,
                            currentWorkgroup->streams[i].offset,
                            test->type,
                            currentWorkgroup->streams[i].domain);
                }

                break;
            case 'i':
                iter =  atoi(optarg);
                break;
            case 'l':
                testcase = bfromcstr(optarg);
                for (i=0; i<NUMKERNELS; i++)
                {
                    if (biseqcstr(testcase, kernels[i].name))
                    {
                        test = kernels+i;
                        break;
                    }
                }

                if (biseqcstr(testcase,"none"))
                {
                    fprintf (stderr, "Unknown test case %s\n",optarg);
                    return EXIT_FAILURE;
                }
                else
                {
                    printf("Name: %s\n",test->name);
                    printf("Number of streams: %d\n",test->streams);
                    printf("Loop stride: %d\n",test->stride);
                    printf("Flops: %d\n",test->flops);
                    printf("Bytes: %d\n",test->bytes);
                    switch (test->type)
                    {
                        case SINGLE:
                            printf("Data Type: Single precision float\n");
                            break;
                        case DOUBLE:
                            printf("Data Type: Double precision float\n");
                            break;
                    }
                }
                bdestroy(testcase);
                exit (EXIT_SUCCESS);    

                break;
            case 'p':
                optPrintDomains = 1;
                break;
            case 'g':
                numberOfWorkgroups =  atoi(optarg);
                allocator_init(numberOfWorkgroups * MAX_STREAMS);
                tmp = numberOfWorkgroups;
                groups = (Workgroup*) malloc(numberOfWorkgroups*sizeof(Workgroup));
                break;
            case 't':
                testcase = bfromcstr(optarg);

                for (i=0; i<NUMKERNELS; i++)
                {
                    if (biseqcstr(testcase, kernels[i].name))
                    {
                        test = kernels+i;
                        break;
                    }
                }

                if (biseqcstr(testcase,"none"))
                {
                    fprintf (stderr, "Unknown test case %s\n",optarg);
                    return EXIT_FAILURE;
                }
                bdestroy(testcase);
                break;
            case '?':
                if (isprint (optopt))
                    fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                else
                    fprintf (stderr,
                            "Unknown option character `\\x%x'.\n",
                            optopt);
                return EXIT_FAILURE;
            default:
                HELP_MSG;
        }
    }


    if (optPrintDomains)
    {
        affinity_printDomains();
        exit (EXIT_SUCCESS);    
    }
    timer_init();

 /* :WARNING:05/04/2010 08:58:05 AM:jt: At the moment the thread
  * module only allows equally sized thread groups*/
    for (i=0; i<numberOfWorkgroups; i++)
    {
        globalNumberOfThreads += groups[i].numberOfThreads;
    }

    threads_init(globalNumberOfThreads);
    threads_createGroups(numberOfWorkgroups);

    /* we configure global barriers only */
    barrier_init(1);
    barrier_registerGroup(globalNumberOfThreads);

#ifdef PERFMON
    printf("Using likwid\n");
    likwid_markerInit();
#endif


    /* initialize data structures for threads */
    for (i=0; i<numberOfWorkgroups; i++)
    {
        myData.iter = iter;
        myData.size = groups[i].size;
        myData.test = test;
        myData.numberOfThreads = groups[i].numberOfThreads;
        myData.processors = (int*) malloc(myData.numberOfThreads * sizeof(int));
        myData.streams = (void**) malloc(test->streams * sizeof(void*));

        for (j=0; j<groups[i].numberOfThreads; j++)
        {
            myData.processors[j] = groups[i].processorIds[j];
        }

        for (j=0; j<  test->streams; j++)
        {
            myData.streams[j] = groups[i].streams[j].ptr;
        }

        threads_registerDataGroup(i, &myData, copyThreadData);

        free(myData.processors);
        free(myData.streams);
    }

    printf(HLINE);
    printf("LIKWID MICRO BENCHMARK\n"); 
    printf("Test: %s\n",test->name); 
    printf(HLINE);
    printf("Using %d work groups\n",numberOfWorkgroups);
    printf("Using %d threads\n",globalNumberOfThreads);
    printf(HLINE);

    threads_create(runTest); 
    threads_destroy();
    allocator_finalize();

    time = (double) threads_data[0].cycles / (double) timer_getCpuClock();
    printf("Cycles: %llu \n", LLU_CAST threads_data[0].cycles);
    printf("Iterations: %llu \n", LLU_CAST iter);
    printf("Size: %d \n",  currentWorkgroup->size );
    printf("Vectorlength: %d \n", threads_data[0].data.size);
    printf("Time: %e sec\n", time);
    printf("MFlops/s:\t%.2f\n",
            1.0E-06 * ((double) numberOfWorkgroups * iter * currentWorkgroup->size *  test->flops/  time));
    printf("MByte/s:\t%.2f\n",
            1.0E-06 * ( (double) numberOfWorkgroups * iter * currentWorkgroup->size *  test->bytes/ time));
    printf("Cycles per update:\t%f\n",
            ((double) threads_data[0].cycles / (double) (iter * threads_data[0].data.size)));

	switch ( test->type )
    {
        case SINGLE:
    printf("Cycles per cacheline:\t%f\n",
            (16.0 * (double) threads_data[0].cycles / (double) (iter * threads_data[0].data.size)));
            break;
        case DOUBLE:
    printf("Cycles per cacheline:\t%f\n",
            (8.0 * (double) threads_data[0].cycles / (double) (iter * threads_data[0].data.size)));
            break;
    }

    printf(HLINE);
#ifdef PERFMON
   likwid_markerClose();
#endif

    return EXIT_SUCCESS;
}
Beispiel #7
0
int programCreateCode(JsonNode *code) {
	char *name = NULL;
	double itmp = -1;
	int state = -1;
	int pid = 0;

	if(json_find_string(code, "name", &name) == 0) {
		if(strstr(progname, "daemon") != NULL) {
			struct programs_t *tmp = programs;
			while(tmp) {
				if(strcmp(tmp->name, name) == 0) {
					if(tmp->wait == 0 && tmp->pth == 0) {
						if(tmp->name != NULL && tmp->stop != NULL && tmp->start != NULL) {
						
							if(json_find_number(code, "running", &itmp) == 0)
								state = 1;
							else if(json_find_number(code, "stopped", &itmp) == 0)
								state = 0;

							if((pid = (int)findproc(tmp->program, tmp->arguments)) > 0 && state == 1) {
								logprintf(LOG_ERR, "program \"%s\" already running", tmp->name);
							} else if(pid == -1 && state == 0) {
								logprintf(LOG_ERR, "program \"%s\" already stopped", tmp->name);
								break;
							} else {
								if(state > -1) {
									program->message = json_mkobject();
									JsonNode *code1 = json_mkobject();
									json_append_member(code1, "name", json_mkstring(name));

									if(state == 1) {
										json_append_member(code1, "state", json_mkstring("running"));
									} else {
										json_append_member(code1, "state", json_mkstring("stopped"));
									}
									
									json_append_member(program->message, "message", code1);
									json_append_member(program->message, "origin", json_mkstring("receiver"));
									json_append_member(program->message, "protocol", json_mkstring(program->id));
														
									pilight.broadcast(program->id, program->message);
									json_delete(program->message);
									program->message = NULL;
								}
							
								tmp->wait = 1;
								threads_create(&tmp->pth, NULL, programThread, (void *)tmp);
								pthread_detach(tmp->pth);

								program->message = json_mkobject();
								json_append_member(program->message, "name", json_mkstring(name));					
								json_append_member(program->message, "state", json_mkstring("pending"));
							}
						} else {
							logprintf(LOG_ERR, "program \"%s\" cannot be controlled", tmp->name);
						}
					} else {
						logprintf(LOG_ERR, "please wait for program \"%s\" to finish it's state change", tmp->name);
					}
					break;
				}
				tmp = tmp->next;
			}
		} else {
			program->message = json_mkobject();

			if(json_find_number(code, "running", &itmp) == 0)
				json_append_member(program->message, "state", json_mkstring("running"));
			else if(json_find_number(code, "stopped", &itmp) == 0)
				json_append_member(program->message, "state", json_mkstring("stopped"));

			json_append_member(program->message, "name", json_mkstring(name));					
			json_append_member(program->message, "state", json_mkstring("pending"));
		}
	} else {
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Beispiel #8
0
static int createCode(JsonNode *code) {
	double itmp = 0;
	int state = -1;
	double id = 0;
	int free_response = 0;
	char *response = NULL;
	
	if(json_find_number(code, "id", &id) == 0) {
		struct settings_t *tmp = settings;
		while(tmp) {
			if(tmp->id == id) {
				if(tmp->wait == 0) {
					if(tmp->method != NULL && tmp->on_uri != NULL && tmp->off_uri != NULL
						&& tmp->on_success != NULL && tmp->off_success != NULL && tmp->response != NULL ) {

						if(json_find_number(code, "running", &itmp) == 0)
							state = 1;
						else if(json_find_number(code, "stopped", &itmp) == 0)
							state = 0;

						if(state > -1) {
							webswitch->message = json_mkobject();
							JsonNode *code1 = json_mkobject();
							json_append_member(code1, "id", json_mknumber(id, 0));

							if(state == 1) {
								json_append_member(code1, "state", json_mkstring("running"));
							} else {
								json_append_member(code1, "state", json_mkstring("stopped"));
							}

							json_append_member(webswitch->message, "message", code1);
							json_append_member(webswitch->message, "origin", json_mkstring("receiver"));
							json_append_member(webswitch->message, "protocol", json_mkstring(webswitch->id));
							if(pilight.broadcast != NULL) {
								pilight.broadcast(webswitch->id, webswitch->message, PROTOCOL);
							}
							json_delete(webswitch->message);
							webswitch->message = NULL;
						}

						tmp->wait = 1;

						threads_create(&tmp->pth, NULL, execute, (void *)tmp);

						tmp->hasthread = 1;
						pthread_detach(tmp->pth);

						webswitch->message = json_mkobject();
						json_append_member(webswitch->message, "id", json_mknumber(id, 0));
						json_append_member(webswitch->message, "state", json_mkstring("pending"));

					} else {
						logprintf(LOG_NOTICE, "webswitch \"%i\" cannot operate due to missing parameters", tmp->id);
					}
				} else {
					logprintf(LOG_NOTICE, "please wait for webswitch \"%i\" to finish it's state change", tmp->id);
				}
				break;
			}
			tmp = tmp->next;
		}
	} else {
		return EXIT_FAILURE;
	}
	if(free_response) {
		FREE(response);
	}
	return EXIT_SUCCESS;
}
Beispiel #9
0
int main(int argc, char** argv)
{
    uint64_t iter = 100;
    uint32_t i;
    uint32_t j;
    int globalNumberOfThreads = 0;
    int optPrintDomains = 0;
    int c;
    ThreadUserData myData;
    bstring testcase = bfromcstr("none");
    uint64_t numberOfWorkgroups = 0;
    int tmp = 0;
    double time;
    double cycPerUp = 0.0;
    const TestCase* test = NULL;
    uint64_t realSize = 0;
    uint64_t realIter = 0;
    uint64_t maxCycles = 0;
    uint64_t minCycles = UINT64_MAX;
    uint64_t cyclesClock = 0;
    uint64_t demandIter = 0;
    TimerData itertime;
    Workgroup* currentWorkgroup = NULL;
    Workgroup* groups = NULL;
    uint32_t min_runtime = 1; /* 1s */
    bstring HLINE = bfromcstr("");
    binsertch(HLINE, 0, 80, '-');
    binsertch(HLINE, 80, 1, '\n');
    int (*ownprintf)(const char *format, ...);
    ownprintf = &printf;

    /* Handling of command line options */
    if (argc ==  1)
    {
        HELP_MSG;
        exit(EXIT_SUCCESS);
    }

    while ((c = getopt (argc, argv, "w:t:s:l:aphvi:")) != -1) {
        switch (c)
        {
            case 'h':
                HELP_MSG;
                exit (EXIT_SUCCESS);
            case 'v':
                VERSION_MSG;
                exit (EXIT_SUCCESS);
            case 'a':
                ownprintf(TESTS"\n");
                exit (EXIT_SUCCESS);
            case 'w':
                numberOfWorkgroups++;
                break;
            case 's':
                min_runtime = atoi(optarg);
                break;
            case 'i':
                demandIter = strtoul(optarg, NULL, 10);
                if (demandIter <= 0)
                {
                    fprintf (stderr, "Error: Iterations must be greater than 0\n");
                    return EXIT_FAILURE;
                }
                break;
            case 'l':
                bdestroy(testcase);
                testcase = bfromcstr(optarg);
                for (i=0; i<NUMKERNELS; i++)
                {
                    if (biseqcstr(testcase, kernels[i].name))
                    {
                        test = kernels+i;
                        break;
                    }
                }

                if (test == NULL)
                {
                    fprintf (stderr, "Error: Unknown test case %s\n",optarg);
                    return EXIT_FAILURE;
                }
                else
                {
                    ownprintf("Name: %s\n",test->name);
                    ownprintf("Number of streams: %d\n",test->streams);
                    ownprintf("Loop stride: %d\n",test->stride);
                    ownprintf("Flops: %d\n",test->flops);
                    ownprintf("Bytes: %d\n",test->bytes);
                    switch (test->type)
                    {
                        case INT:
                            ownprintf("Data Type: Integer\n");
                            break;
                        case SINGLE:
                            ownprintf("Data Type: Single precision float\n");
                            break;
                        case DOUBLE:
                            ownprintf("Data Type: Double precision float\n");
                            break;
                    }
                    if (test->loads >= 0)
                    {
                        ownprintf("Load Ops: %d\n",test->loads);
                    }
                    if (test->stores >= 0)
                    {
                        ownprintf("Store Ops: %d\n",test->stores);
                    }
                    if (test->branches >= 0)
                    {
                        ownprintf("Branches: %d\n",test->branches);
                    }
                    if (test->instr_const >= 0)
                    {
                        ownprintf("Constant instructions: %d\n",test->instr_const);
                    }
                    if (test->instr_loop >= 0)
                    {
                        ownprintf("Loop instructions: %d\n",test->instr_loop);
                    }
                }
                bdestroy(testcase);
                exit (EXIT_SUCCESS);

                break;
            case 'p':
                optPrintDomains = 1;
                break;
            case 'g':
                numberOfWorkgroups = LLU_CAST atol(optarg);

                tmp = numberOfWorkgroups;

                break;
            case 't':
                bdestroy(testcase);
                testcase = bfromcstr(optarg);

                for (i=0; i<NUMKERNELS; i++)
                {
                    if (biseqcstr(testcase, kernels[i].name))
                    {
                        test = kernels+i;
                        break;
                    }
                }

                if (test == NULL)
                {
                    fprintf (stderr, "Error: Unknown test case %s\n",optarg);
                    return EXIT_FAILURE;
                }
                bdestroy(testcase);
                break;
            case '?':
                if (isprint (optopt))
                    fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                else
                    fprintf (stderr,
                            "Unknown option character `\\x%x'.\n",
                            optopt);
                return EXIT_FAILURE;
            default:
                HELP_MSG;
        }
    }
    if ((numberOfWorkgroups == 0) && (!optPrintDomains))
    {
        fprintf(stderr, "Error: At least one workgroup (-w) must be set on commandline\n");
        exit (EXIT_FAILURE);
    }

    if (topology_init() != EXIT_SUCCESS)
    {
        fprintf(stderr, "Error: Unsupported processor!\n");
        exit(EXIT_FAILURE);
    }

    if ((test == NULL) && (!optPrintDomains))
    {
        fprintf(stderr, "Unknown test case. Please check likwid-bench -a for available tests\n");
        fprintf(stderr, "and select one using the -t commandline option\n");
        exit(EXIT_FAILURE);
    }

    numa_init();
    affinity_init();
    timer_init();

    if (optPrintDomains)
    {
        bdestroy(testcase);
        AffinityDomains_t affinity = get_affinityDomains();
        ownprintf("Number of Domains %d\n",affinity->numberOfAffinityDomains);
        for (i=0; i < affinity->numberOfAffinityDomains; i++ )
        {
            ownprintf("Domain %d:\n",i);
            ownprintf("\tTag %s:",bdata(affinity->domains[i].tag));

            for ( uint32_t j=0; j < affinity->domains[i].numberOfProcessors; j++ )
            {
                ownprintf(" %d",affinity->domains[i].processorList[j]);
            }
            ownprintf("\n");
        }
        exit (EXIT_SUCCESS);
    }

    allocator_init(numberOfWorkgroups * MAX_STREAMS);
    groups = (Workgroup*) malloc(numberOfWorkgroups*sizeof(Workgroup));
    tmp = 0;

    optind = 0;
    while ((c = getopt (argc, argv, "w:t:s:l:i:aphv")) != -1)
    {
        switch (c)
        {
            case 'w':
                currentWorkgroup = groups+tmp;
                bstring groupstr = bfromcstr(optarg);
                i = bstr_to_workgroup(currentWorkgroup, groupstr, test->type, test->streams);
                bdestroy(groupstr);
                if (i == 0)
                {
                    for (i=0; i<  test->streams; i++)
                    {
                        if (currentWorkgroup->streams[i].offset%test->stride)
                        {
                            fprintf (stderr, "Error: Stream %d: offset is not a multiple of stride!\n",i);
                            return EXIT_FAILURE;
                        }
                        allocator_allocateVector(&(currentWorkgroup->streams[i].ptr),
                                PAGE_ALIGNMENT,
                                currentWorkgroup->size,
                                currentWorkgroup->streams[i].offset,
                                test->type,
                                currentWorkgroup->streams[i].domain);
                    }
                    tmp++;
                }
                else
                {
                    exit(EXIT_FAILURE);
                }
                break;
            default:
                continue;
                break;
        }
    }

    /* :WARNING:05/04/2010 08:58:05 AM:jt: At the moment the thread
     * module only allows equally sized thread groups*/
    for (i=0; i<numberOfWorkgroups; i++)
    {
        globalNumberOfThreads += groups[i].numberOfThreads;
    }

    ownprintf(bdata(HLINE));
    ownprintf("LIKWID MICRO BENCHMARK\n");
    ownprintf("Test: %s\n",test->name);
    ownprintf(bdata(HLINE));
    ownprintf("Using %" PRIu64 " work groups\n",numberOfWorkgroups);
    ownprintf("Using %d threads\n",globalNumberOfThreads);
    ownprintf(bdata(HLINE));


    threads_init(globalNumberOfThreads);
    threads_createGroups(numberOfWorkgroups);

    /* we configure global barriers only */
    barrier_init(1);
    barrier_registerGroup(globalNumberOfThreads);
    cyclesClock = timer_getCycleClock();

#ifdef LIKWID_PERFMON
    if (getenv("LIKWID_FILEPATH") != NULL)
    {
        ownprintf("Using Likwid Marker API\n");
    }
    LIKWID_MARKER_INIT;
    ownprintf(bdata(HLINE));
#endif


    /* initialize data structures for threads */
    for (i=0; i<numberOfWorkgroups; i++)
    {
        myData.iter = iter;
        if (demandIter > 0)
        {
            myData.iter = demandIter;
        }
        myData.min_runtime = min_runtime;
        myData.size = groups[i].size;
        myData.test = test;
        myData.cycles = 0;
        myData.numberOfThreads = groups[i].numberOfThreads;
        myData.processors = (int*) malloc(myData.numberOfThreads * sizeof(int));
        myData.streams = (void**) malloc(test->streams * sizeof(void*));

        for (j=0; j<groups[i].numberOfThreads; j++)
        {
            myData.processors[j] = groups[i].processorIds[j];
        }

        for (j=0; j<  test->streams; j++)
        {
            myData.streams[j] = groups[i].streams[j].ptr;
        }

        threads_registerDataGroup(i, &myData, copyThreadData);

        free(myData.processors);
        free(myData.streams);
    }

    if (demandIter == 0)
    {
        getIterSingle((void*) &threads_data[0]);
        for (i=0; i<numberOfWorkgroups; i++)
        {
            iter = threads_updateIterations(i, demandIter);
        }
    }
#ifdef DEBUG_LIKWID
    else
    {
        ownprintf("Using manually selected iterations per thread\n");
    }
#endif

    threads_create(runTest);
    threads_join();

    for (int i=0; i<globalNumberOfThreads; i++)
    {
        realSize += threads_data[i].data.size;
        realIter += threads_data[i].data.iter;
        if (threads_data[i].cycles > maxCycles)
        {
            maxCycles = threads_data[i].cycles;
        }
        if (threads_data[i].cycles < minCycles)
        {
            minCycles = threads_data[i].cycles;
        }
    }



    time = (double) maxCycles / (double) cyclesClock;
    ownprintf(bdata(HLINE));
    ownprintf("Cycles:\t\t\t%" PRIu64 "\n", maxCycles);
    ownprintf("CPU Clock:\t\t%" PRIu64 "\n", timer_getCpuClock());
    ownprintf("Cycle Clock:\t\t%" PRIu64 "\n", cyclesClock);
    ownprintf("Time:\t\t\t%e sec\n", time);
    ownprintf("Iterations:\t\t%" PRIu64 "\n", realIter);
    ownprintf("Iterations per thread:\t%" PRIu64 "\n",threads_data[0].data.iter);
    ownprintf("Inner loop executions:\t%.0f\n", ((double)realSize)/((double)test->stride));
    ownprintf("Size:\t\t\t%" PRIu64 "\n",  realSize*test->bytes );
    ownprintf("Size per thread:\t%" PRIu64 "\n", threads_data[0].data.size*test->bytes);
    ownprintf("Number of Flops:\t%" PRIu64 "\n", (threads_data[0].data.iter * realSize *  test->flops));
    ownprintf("MFlops/s:\t\t%.2f\n",
            1.0E-06 * ((double) threads_data[0].data.iter * realSize *  test->flops/  time));
    
    ownprintf("Data volume (Byte):\t%llu\n", LLU_CAST (threads_data[0].data.iter * realSize *  test->bytes));
    ownprintf("MByte/s:\t\t%.2f\n",
            1.0E-06 * ( (double) threads_data[0].data.iter * realSize *  test->bytes/ time));

    cycPerUp = ((double) maxCycles / (double) (threads_data[0].data.iter * realSize));
    ownprintf("Cycles per update:\t%f\n", cycPerUp);

    switch ( test->type )
    {
        case INT:
        case SINGLE:
            ownprintf("Cycles per cacheline:\t%f\n", (16.0 * cycPerUp));
            break;
        case DOUBLE:
            ownprintf("Cycles per cacheline:\t%f\n", (8.0 * cycPerUp));
            break;
    }
    ownprintf("Loads per update:\t%ld\n", test->loads );
    ownprintf("Stores per update:\t%ld\n", test->stores );
    if ((test->loads > 0) && (test->stores > 0))
    {
        ownprintf("Load/store ratio:\t%.2f\n", ((double)test->loads)/((double)test->stores) );
    }
    if ((test->instr_loop > 0) && (test->instr_const > 0))
    {
        ownprintf("Instructions:\t\t%" PRIu64 "\n", LLU_CAST ((double)realSize/test->stride)*test->instr_loop*threads_data[0].data.iter + test->instr_const );
    }
    if (test->uops > 0)
    {
        ownprintf("UOPs:\t\t\t%" PRIu64 "\n", LLU_CAST ((double)realSize/test->stride)*test->uops*threads_data[0].data.iter);
    }

    ownprintf(bdata(HLINE));
    threads_destroy(numberOfWorkgroups, test->streams);
    allocator_finalize();
    workgroups_destroy(&groups, numberOfWorkgroups, test->streams);

#ifdef LIKWID_PERFMON
    if (getenv("LIKWID_FILEPATH") != NULL)
    {
        ownprintf("Writing Likwid Marker API results to file %s\n", getenv("LIKWID_FILEPATH"));
    }
    LIKWID_MARKER_CLOSE;
#endif

    bdestroy(HLINE);
    return EXIT_SUCCESS;
}