Exemplo n.º 1
0
int _tmain(int argc, char* argv[])
{
//1cmd_file.txt 2config_file.txt 3mem_init.txt 4regs_dump.txt 5mem_dump.txt 6time.txt 7committed.txt 8hitrate.txt 9L1i.txt 10L1d.txt 11L2i.txt 12L2d.txt
//1cmd_file1.txt 2cmd_file2.txt 3config_file.txt 4mem_init.txt 5regs_dump.txt 6mem_dump.txt 7time.txt 8committed.txt 9hitrate.txt 10trace1.txt 11trace2.txt

	if(argc!=12)
	{
		printf("Wrong number of command line arguments!\n");
		exit(1);
	}

	if (ini_parse(argv[3], handler, &configuration) < 0) {
		printf("Can't load '%s' file\n",argv[1]);
		exit(1);
	}

	ram = new int[MEMORY_SIZE/4];
	if (ram == NULL)
		exit(1);

	ReadMemInitFile(argv[4]);

	ParseCMDfile(argv[1]);

	InitCaches(&configuration);

	StartSimulator();

	printf("simulation done!\n");

	WriteMemoryDumpToFile(argv[6]);

	WriteRegisterDumpToFile(argv[5]);

	WriteExceutionTime(argv[7]);

	WriteInstructionCount(argv[8]);

	WriteHitRatioAndAMAT(argv[9]);

	
	printf("all results written to files!\n");

//	DestroyCaches();

	free(ram);

	return 0;
}
int main(void)
{
    
	
	

	
	
	
	int sensorDescriptors[10];
	StartSimulator(sensorDescriptors, 5); // Use 5 or 10
	// Generates 5 values per descriptor

	memset(&total_lag, 0, sizeof(struct timespec));
	
	
	fd_set fdset, exfdset;
	int n;
	int maxfd = 0;
	int flags[10] = { 0 };
	int nsensors_active = 10;
	Tmeas measurement;
	
	
	struct sigaction sigact, oldact;
	
	
	sigemptyset(&sigact.sa_mask);
    sigact.sa_sigaction = char_ready_handler;
    sigact.sa_flags = SA_SIGINFO;
    if (sigaction(SIGIO, &sigact, &oldact) < 0) {
        fprintf(stderr, "\nCannot set signal handler");
        exit(0);
    } 
	

	
	for (int i = 0; i < 10; i++) {
		aiocb[i].aio_buf = &measurement;
		aiocb[i].aio_nbytes = sizeof(Tmeas);
		aiocb[i].aio_offset = 0;
		aiocb[i].aio_reqprio = 0;
		aiocb[i].aio_sigevent.sigev_notify = SIGEV_SIGNAL ;
		aiocb[i].aio_sigevent.sigev_signo = SIGIO ;
		aiocb[i].aio_sigevent.sigev_value.sival_ptr = &aiocb[i];
		aiocb[i].aio_lio_opcode = 0;
		
		
		aiocb[i].aio_fildes = sensorDescriptors[i];
		aio_read(&aiocb[i]);
	}
	
	
	
	//sleep(45);
	//sleep(45);	
	//for(int i = 0; i<50; i++)
	//	sleep(5);
	while(NSENS);
	printf("All is done, the total lag is %d nanosecs\n", total_lag.tv_nsec);
    return 0;
}
int main(void) {
	int retval = -1;
	fd_set rfds;
	int fdmax = 0;
	int n = 0;
	int i = 0;
	int k = 0;
	struct timespec sumOfDelays;
	struct timespec delay;
	struct timespec timeNow;
	int sensorDescriptors[10];
	Tmeas measurement;
	int eofArray[10];
	int eofCount = 0;
	int counter = 0;
	
	// Initialize struct timespec variables
	memset(&sumOfDelays, 0, sizeof(sumOfDelays));
	for (i = 0; i < 10; i++) {
		eofArray[i] = 1;
	}
	
	// Specify 5 values per sensor
	if (StartSimulator(sensorDescriptors, 5) < 0) {
		fprintf(stderr, "Error: Cannot initialize sensor simulator\n");
		exit(EXIT_FAILURE);
	}
	fdmax = findMaxFileDescriptor(sensorDescriptors, 10);
		
	do {
		FD_ZERO(&rfds);
		for (i = 0; i < 10; i++) {
			if (eofArray[i] != 0) 	// Add file descriptors that haven't reached EOF to the set 
				FD_SET(sensorDescriptors[i], &rfds);
		}
		n = select(fdmax+1, &rfds, NULL, NULL, NULL);
		if (n > 0) {
			for (i = 0; i < 10; i++) {
				if (FD_ISSET(sensorDescriptors[i], &rfds)) {
					k++;
					/*
					 *	Sensor descriptor is ready, but it is also ready on EOF
					 *	So check for EOF condition, if EOF, then don't read it
					 */
					if (eofArray[i] == 0) 	// 0 indicates EOF condition
						break;
					else {
						retval = read(sensorDescriptors[i], &measurement, sizeof(Tmeas));
						
						if (retval == 0) {
							eofArray[i] = 0;
							eofCount++;
						} else {
							counter++;
						}
						if (clock_gettime(CLOCK_REALTIME, &timeNow) == -1) {
							perror("clock gettime");
							exit(EXIT_FAILURE);
						}
						delay = diff_timespec(&measurement.moment, &timeNow);
						increment_timespec(&sumOfDelays, &delay);
					}
					
				}
				// All ready file descriptors have been processed
				// So it's not necessary for looping to the end of loop
				if (k == n)
					break;
			}
			k = 0;
		}
	} while (eofCount != 10);
	
	// Display the total delay
	printf("Sum of delay %ld s %ld ns\n", sumOfDelays.tv_sec, sumOfDelays.tv_nsec);
	printf("counter %d\n", counter);

	return EXIT_SUCCESS;
}