예제 #1
0
int main(int argc, char **argv){

	long vaddr;

	double arrive_time;

	load_config();
	print_config(NULL);

	Ssd ssd;

	printf("INITIALIZING SSD Bimodal\n");

	srandom(1);
	int preIO = SSD_SIZE * PACKAGE_SIZE * DIE_SIZE * PLANE_SIZE * BLOCK_SIZE;

	if (FTL_IMPLEMENTATION == 0) // PAGE
		preIO -= 16*BLOCK_SIZE;

	if (FTL_IMPLEMENTATION == 1) // BAST
		preIO -= (BAST_LOG_PAGE_LIMIT*BLOCK_SIZE)*2;

	if (FTL_IMPLEMENTATION == 2) // FAST
		preIO -= (FAST_LOG_PAGE_LIMIT*BLOCK_SIZE)*1.1;

	if (FTL_IMPLEMENTATION > 2) // DFTL BIFTL
		preIO -= 512;

	int deviceSize = 3145216;

	if (preIO > deviceSize)
		preIO = deviceSize;

	printf("Writes %i pages for startup out of %i total pages.\n", preIO, SSD_SIZE * PACKAGE_SIZE * DIE_SIZE * PLANE_SIZE * BLOCK_SIZE);

	double start_time = 0;
	double timeMultiplier = 10000;

	double read_time = 0;
	double write_time = 0;
	double trim_time = 0;

	unsigned long num_reads = 0;
	unsigned long num_writes = 0;
	unsigned long num_trims = 0;

	std::vector<double> avgsTrim;
	std::vector<double> avgsWrite1;
	std::vector<double> avgsRead1;
	std::vector<double> avgsRead2;
	std::vector<double> avgsRead3;
	std::vector<double> avgsTrim2;
	std::vector<double> avgsWrite2;
	std::vector<double> avgsRead4;
	std::vector<double> avgsWrite3;


	avgsTrim.reserve(1024*64);
	avgsWrite1.reserve(1024*64);
	avgsRead1.reserve(1024*64);
	avgsRead2.reserve(1024*64);
	avgsRead3.reserve(1024*64);
	avgsTrim2.reserve(1024*64);
	avgsWrite2.reserve(1024*64);
	avgsRead4.reserve(1024*64);
	avgsWrite3.reserve(1024*64);

	// Reset statistics
	ssd.reset_statistics();

	// 1. Write random to the size of the device
	srand(1);
	double afterFormatStartTime = 0;
	//for (int i=0; i<preIO/3*2;i++)
	for (int i=0; i<preIO*1.1;i++)
	//for (int i=0; i<700000;i++)
	{
		long int r = random()%preIO;
		double d = ssd.event_arrive(WRITE, r, 1, afterFormatStartTime);
		afterFormatStartTime += d;

		if (i % 10000 == 0)
			printf("Wrote %i %f\n", i,d );
	}

	start_time = afterFormatStartTime;
	// Reset statistics
	ssd.reset_statistics();

	// 2. Trim an area. ( We let in be 512MB (offset 131072 pages or 2048 blocks) into the address space, and then 256MB (1024 blocks or 65536 pages) )

	int startTrim = 2048*64; //131072
	int endTrim = 3072*64; //196608

	/* Test 1 */
	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(TRIM, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsTrim.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Trim: %i %f\n", i, trim_time);

	}

	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(READ, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsRead1.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Read: %i %f\n", i, trim_time);

	}

	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(READ, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsRead2.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Read: %i %f\n", i, trim_time);

	}

	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(WRITE, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsWrite1.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Write: %i %f\n", i, trim_time);

	}

	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(READ, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsRead3.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Read: %i %f\n", i, trim_time);

	}

	/* Test 1 */
	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(TRIM, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsTrim2.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (trim_time > 400)
			printf("Trim: %i %f\n", i, trim_time);

	}

	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(WRITE, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsWrite2.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Write: %i %f\n", i, trim_time);

	}

	for (int i=startTrim; i<endTrim;i++)
	{

		trim_time = ssd.event_arrive(READ, i, 1, ((start_time+arrive_time)*timeMultiplier));
		avgsRead4.push_back(trim_time);
		num_trims++;

		arrive_time += trim_time;

		if (i % 1000 == 0)
			printf("Read: %i %f\n", i, trim_time);

	}

//	// 1. Write random to the size of the device
//	for (int i=0; i<700000;i++)
//	{
//		long int r = (random()%preIO-200000)+200000;
//		double d = ssd.event_arrive(WRITE, r, 1, afterFormatStartTime);
//		afterFormatStartTime += d;
//
//		if (i % 10000 == 0)
//			printf("Wrote %i %f\n", i,d );
//	}
//
//	for (int i=startTrim; i<endTrim;i++)
//	{
//
//		trim_time = ssd.event_arrive(WRITE, i, 1, ((start_time+arrive_time)*timeMultiplier));
//		avgsWrite3.push_back(trim_time);
//		num_trims++;
//
//		arrive_time += trim_time;
//
//		if (i % 1000 == 0)
//			printf("Write: %i %f\n", i, trim_time);
//
//	}


	ssd.print_ftl_statistics();

	FILE *logFile = NULL;
	if ((logFile = fopen("output.log", "w")) == NULL)
	{
		printf("Output file cannot be written to.\n");
		exit(-1);
	}

	fprintf(logFile, "Trim;Read1;Read2;Write1;Read3;Trim2;Write2;Read4;Write3\n");

	for (size_t i=0;i<avgsTrim.size();i++)
	{
		fprintf(logFile, "%f;%f;%f;%f;%f;%f;%f;%f\n", avgsTrim[i],avgsRead1[i], avgsRead2[i], avgsWrite1[i], avgsRead3[i], avgsTrim2[i], avgsWrite2[i], avgsRead4[i]);
	}

	fclose(logFile);

	ssd.print_ftl_statistics();
	ssd.print_statistics();

	printf("Finished.\n");
	return 0;
}
예제 #2
0
int main(int argc, char **argv){

	long vaddr;
	ssd::uint queryTime;
	char ioPatternType; // (S)equential or (R)andom
	char ioType; // (R)ead or (W)rite
	double arrive_time;
	int ioSize;

	char line[80];

	double afterFormatStartTime = 0;

	load_config();
	print_config(NULL);

	Ssd ssd;

	printf("INITIALIZING SSD\n");
	
	unsigned long long deviceSize = SSD_SIZE * PACKAGE_SIZE * DIE_SIZE * PLANE_SIZE * BLOCK_SIZE ;

	//ARH: I don't understand what is the point of warm-up phase here.
	/*
	int preIO = SSD_SIZE * PACKAGE_SIZE * DIE_SIZE * PLANE_SIZE * BLOCK_SIZE;

	if (FTL_IMPLEMENTATION == 0) // PAGE
		preIO -= 16*BLOCK_SIZE;

	if (FTL_IMPLEMENTATION == 1) // BAST
		preIO -= (BAST_LOG_PAGE_LIMIT*BLOCK_SIZE)*1.2;

	if (FTL_IMPLEMENTATION == 2) // FAST
		preIO -= (FAST_LOG_PAGE_LIMIT*BLOCK_SIZE)*1.1;

	if (FTL_IMPLEMENTATION > 2) // DFTL BIFTL
		preIO -= 1000;

	//int deviceSize = 2827059;
	int deviceSize = 2097024;

	if (preIO > deviceSize)
		preIO = deviceSize;

	printf("Writes %i pages for startup out of %i total pages.\n", preIO, SSD_SIZE * PACKAGE_SIZE * DIE_SIZE * PLANE_SIZE * BLOCK_SIZE);

//	srand(1);
//	for (int i=0; i<preIO*3;i++)
//	{
//		long int r = random()%deviceSize;
//		double d = ssd.event_arrive(WRITE, r, 1, (double)i*1000.0);
//		//double d = ssd.event_arrive(WRITE, i, 1, i*1000);
//		afterFormatStartTime += 1000;
//
//		if (i % 1000 == 0)
//			printf("Wrote %i %f\n", i,d );
//	}
	*/

	DIR *working_directory = NULL;
	if ((working_directory = opendir(argv[1])) == NULL)
	{
		printf("Please provide trace file directory.\n");
		exit(-1);
	}

	std::vector<std::string> files;
	struct dirent *dirp;
	while ((dirp = readdir(working_directory)) != NULL)
	{
		if (dirp->d_type == DT_REG)
			files.push_back(dirp->d_name);
	}

	std::sort(files.begin(), files.end());

	double start_time = afterFormatStartTime;
	double timeMultiplier = 10000;


	long writeEvent = 0;
	long readEvent = 0;
	/* No pre-write
	for (unsigned int i=0; i<files.size();i++)
	{
		char *filename = NULL;
		asprintf(&filename, "%s%s", argv[1], files[i].c_str());

		FILE *trace = NULL;
		if((trace = fopen(filename, "r")) == NULL){
			printf("File was moved or access was denied.\n");
			exit(-1);
		}

		printf("-__- %s -__-\n", files[i].c_str());

		start_time = start_time + arrive_time;


		int addressDivisor = 1;
		float multiplier = 1;

		std::string fileName = files[i].c_str();
		std::string multiplerStr = fileName.substr(fileName.find('P',0)+1, fileName.find_last_of('_', std::string::npos)-fileName.find('P',0)-1);

		char pattern = fileName.substr(4,1).c_str()[0];
		switch (pattern)
		{
		case '5':
			multiplier = atof(multiplerStr.c_str());
			break;

		}
		
		//ARH: access one page per iteration
		// first go through and write to all read addresses to prepare the SSD 
		while(fgets(line, 80, trace) != NULL){
			sscanf(line, "%c; %c; %li; %u; %i; %lf", &ioPatternType, &ioType, &vaddr, &queryTime, &ioSize, &arrive_time);


			double local_loop_time = 0;

			if (ioType == 'R')
			{
				for (int i=0;i<ioSize;i++)
				{
					local_loop_time += ssd.event_arrive(READ, ((vaddr+(i*(int)multiplier))/addressDivisor)%deviceSize, 1, ((start_time+arrive_time)*timeMultiplier)+local_loop_time);
					readEvent++;
				}


			}
			else if(ioType == 'W')
			{
				for (int i=0;i<ioSize;i++)
				{
					local_loop_time += ssd.event_arrive(WRITE, ((vaddr+(i*(int)multiplier))/addressDivisor)%deviceSize, 1, ((start_time+arrive_time)*timeMultiplier)+local_loop_time);
					writeEvent++;
				}


			}

			arrive_time += local_loop_time;
		}

		fclose(trace);
	}

	printf("Pre write done------------------------------\n");
	ssd.print_ftl_statistics();
	printf("Num read %li write %li\n", readEvent, writeEvent);
	getchar();
	
	*/
		
	FILE *logFile = NULL;
	if ((logFile = fopen("output.csv", "w")) == NULL)
	{
		printf("Output file cannot be written to.\n");
		exit(-1);
	}

	fprintf(logFile, "File;NumIOReads;ReadIOTime;NumIOWrites;WriteIOTime;NumIOTotal;IOTime;");
	ssd.write_header(logFile);

	double read_time = 0;
	double write_time = 0;

	unsigned long num_reads = 0;
	unsigned long num_writes = 0;

	for (unsigned int i=0; i<files.size();i++)
	{
		char *filename = NULL;
		asprintf(&filename, "%s%s", argv[1], files[i].c_str());
		
		FILE *trace = NULL;
		if((trace = fopen(filename, "r")) == NULL){
			printf("File was moved or access was denied.\n");
			exit(-1);
		}

		fprintf(logFile, "%s;", files[i].c_str());

		printf("-__- %s -__-\n", files[i].c_str());

		start_time = start_time + arrive_time;

		// Reset statistics
		ssd.reset_statistics();

		num_reads = 0;
		read_time = 0;

		num_writes = 0;
		write_time = 0;

		int addressDivisor = 1;
		float multiplier = 1;

		std::string fileName = files[i].c_str();
		std::string multiplerStr = fileName.substr(fileName.find('P',0)+1, fileName.find_last_of('_', std::string::npos)-fileName.find('P',0)-1);


		/* first go through and write to all read addresses to prepare the SSD */
		while(fgets(line, 80, trace) != NULL){
			sscanf(line, "%c; %c; %li; %u; %i; %lf", &ioPatternType, &ioType, &vaddr, &queryTime, &ioSize, &arrive_time);

			//printf("%li %c %c %li %u %lf %lf %li\n", ++cnt, ioPatternType, ioType, vaddr, queryTime, arrive_time, start_time+arrive_time);

			double local_loop_time = 0;

			if (ioType == 'R')
			{
				for (int i=0;i<ioSize;i++)
				{
					local_loop_time += ssd.event_arrive(READ, ((vaddr+(i*(int)multiplier))/addressDivisor)%deviceSize, 1, ((start_time+arrive_time)*timeMultiplier)+local_loop_time);
				}
				num_reads++;

				read_time += local_loop_time;
			}
			else if(ioType == 'W')
			{
				for (int i=0;i<ioSize;i++)
				{
					local_loop_time += ssd.event_arrive(WRITE, ((vaddr+(i*(int)multiplier))/addressDivisor)%deviceSize, 1, ((start_time+arrive_time)*timeMultiplier)+local_loop_time);

				}
				num_writes++;
				write_time += local_loop_time;

			}

			arrive_time += local_loop_time;
		}
		// Write all statistics
		fprintf(logFile, "%lu;%f;%lu;%f;%lu;%f;", num_reads, read_time, num_writes, write_time, num_reads+num_writes, read_time+write_time);
		ssd.write_statistics(logFile);
		fclose(trace);
		fflush(logFile);
	}

	fclose(logFile);

	closedir(working_directory);

	printf("Finished.\n");
	return 0;
}