예제 #1
0
파일: util.cpp 프로젝트: ayoosh/ece750
void read_tasksets(vector<task>*tasks, string fname) {
	ifstream taskfile;
	taskfile.open(fname.c_str(), ios::in);
	string comp, period, power, init;
	taskfile >> init;

	task temp;
	temp.taskset = 0;
	temp.computations = 0;
	temp.index = 0;
	while (!taskfile.eof()) {
		taskfile >> temp.computation_time >> temp.period >> temp.power;
	//	 cout << temp.computation_time << "|" << temp.period << "|"
          //                              << temp.power << endl;

		if (temp.computation_time > 0 && temp.period > 0) {
			cout << temp.computation_time << "|" << temp.period << "|"
					<< temp.power << endl;
			tasks->push_back(temp);
		}
		temp.computation_time = 0;
	}
	cout << "exited loop" << endl;
	int hyp_length = compute_lcm(tasks, 0);
	float total_impact = 0;
	cout << "size" << tasks->size() << endl;
	for (unsigned int j = 0; j < tasks->size(); j++) {

		cout<<"task:"<<j<<"taskset:"<<(*tasks)[j].taskset<<" computation time:"<<(*tasks)[j].computation_time<<" period:"<<(*tasks)[j].period<< " Utilization: "<<(float)(*tasks)[j].computation_time/(float)(*tasks)[j].period<<endl;
		cout << (*tasks)[j].power << "|" << (*tasks)[j].computation_time << "|"
				<< (*tasks)[j].period << endl;
		total_impact = total_impact
				+ (*tasks)[j].power * (*tasks)[j].computation_time
						* (hyp_length / (*tasks)[j].period) / beta;
	}
	cout << "tti calculated" << endl;
	taskset temp_set;
	temp_set.TTI = total_impact / GRANULARITY;
	temp_set.t_util = total_impact / (corrected_threshold * (hyp_length));
	temp_set.average_power = total_impact / (hyp_length * beta);
	temp_set.hyperperiod = hyp_length;
	tasksets.push_back(temp_set);
	cout << "read successfully" << endl;

}
예제 #2
0
int nullSpace(int* topo_matrix, int* brv, int nbEdges, int nbVertices){
	Rational* ratioMatrix = CREATE_MUL(TRANSFO_STACK, nbVertices*nbEdges, Rational);
	Rational* ratioResult = CREATE_MUL(TRANSFO_STACK, nbVertices, Rational);

//	printf("Topo Matrix:\n");
//	for(int i=0; i<nbEdges; i++){
//		for(int j=0; j<nbVertices; j++){
//			printf("%d : ", topo_matrix[i*nbVertices+j]);
//		}
////		printf("\033[2D");
//		printf("\n");
//	}

	/* Copy matrix into ratioMatrix */
	for(int i=0; i<nbEdges*nbVertices; i++){
		ratioMatrix[i] = topo_matrix[i];
	}

//	printf("Topo Matrix: Rational\n");
//	for(int i=0; i<nbEdges; i++){
//		for(int j=0; j<nbVertices; j++){
//			printf("%d,%d : ", ratioMatrix[i*nbVertices+j].getNominator(), ratioMatrix[i*nbVertices+j].getDenominator());
//		}
////		printf("\033[2D");
//		printf("\n");
//	}

	for (int i=0; i < nbEdges; i++) {
		Rational pivotMax = ratioMatrix[i*nbVertices+i].getAbs();
		int maxIndex = i;

		for (int t = i+1; t < nbEdges; t++) {
			Rational newPivot = ratioMatrix[t*nbVertices+i].getAbs();
			if (newPivot > pivotMax) {
				maxIndex = t;
				pivotMax = newPivot;
			}
		}

		if (pivotMax != 0 && maxIndex != i) {
			/* Switch Rows */
			Rational tmp;
			for (int t = 0; t < nbVertices; t++) {
				tmp = ratioMatrix[maxIndex*nbVertices+t];
				ratioMatrix[maxIndex*nbVertices+t] = ratioMatrix[i*nbVertices+t];
				ratioMatrix[i*nbVertices+t] = tmp;
			}
		} else if (maxIndex == i && (pivotMax != 0)) {
			/* Do nothing */
		} else {
			break;
		}

		Rational odlPivot = ratioMatrix[i*nbVertices+i];
		for (int t = i; t < nbVertices; t++) {
			ratioMatrix[i*nbVertices+t] = ratioMatrix[i*nbVertices+t] / odlPivot;
		}

		for (int j = i + 1; j < nbEdges; j++) {
			if (ratioMatrix[j*nbVertices+i] != 0) {
				Rational oldji = ratioMatrix[j*nbVertices+i];

				for (int k = 0; k < nbVertices; k++) {
					ratioMatrix[j*nbVertices+k] =
							ratioMatrix[j*nbVertices+k] - (oldji * ratioMatrix[i*nbVertices+k]);
				}
			}
		}
	}

	for (int i = 0; i < nbVertices; i++) {
		ratioResult[i] = 1;
	}

	for(int i = nbEdges-1; i >= 0; i--){
		Rational val = 0;

		for (int k = i + 1; k < nbVertices; k++) {
			val = val + (ratioMatrix[i*nbVertices+k] * ratioResult[k]);
		}
		if (val != 0) {
			if(ratioMatrix[i*nbVertices+i] == 0){
				throw "elt diagonal zero\n";
			}
			ratioResult[i] = val.getAbs() / ratioMatrix[i*nbVertices+i];
		}
	}

	int lcm = 1;
	for(int i=0; i<nbVertices; i++){
		lcm = compute_lcm(lcm, ratioResult[i].getDenominator());
	}
	for(int i=0; i<nbVertices; i++){
		brv[i] = abs(ratioResult[i].getNominator() * lcm / ratioResult[i].getDenominator());
	}

	StackMonitor::free(TRANSFO_STACK, ratioMatrix);
	StackMonitor::free(TRANSFO_STACK, ratioResult);

	return 0;
}
예제 #3
0
파일: w2fq.cpp 프로젝트: ayoosh/ece750
void generate_intervals_gps(vector<interval_s>* intervals, vector<long_task>*tasks)
{


	long hyperperiod=compute_lcm(tasks);
	interval_s tint;

	long start=0;

	for(unsigned int i=0;i<tasks->size();i++)
	{
		start=0;
		while(start<hyperperiod)
		{
			tint.start=start;
			tint.end=0;
			intervals->push_back(tint);
			start=start+(*tasks)[i].period;
		}
	}

	sort(intervals->begin(), intervals->end(),interval_ascend);

	for(unsigned int i=0;i<intervals->size();i++)
	{
		if(i>0)
		{
			if((*intervals)[i].start==(*intervals)[i-1].start)
			{
				intervals->erase(intervals->begin()+i);
				i=i-1;
			}
		}
	}

	for(unsigned int i=0;i<intervals->size();i++)
	{
		if(i<intervals->size()-1)
		{
			(*intervals)[i].end=(*intervals)[i+1].start;
		}
		else
		{
			(*intervals)[i].end=hyperperiod;
		}
	}

	for(unsigned int i=0;i<intervals->size();i++)
	{
		for(unsigned int j=0;j<tasks->size();j++)
		{
			(*intervals)[i].computations[j][0]= round(((double)((*intervals)[i].end-(*intervals)[i].start)) * ((double)(*tasks)[j].computation_time)/((double)(*tasks)[j].period));
			if(i>0)
			{
				(*intervals)[i].net_computations[j][0]=(*intervals)[i-1].net_computations[j][0]+(*intervals)[i].computations[j][0];

			}
			else
			{
				(*intervals)[i].net_computations[j][0]=(*intervals)[i].computations[j][0];
			}
		}
	}
}
예제 #4
0
파일: w2fq.cpp 프로젝트: ayoosh/ece750
void w2fq_schedule(vector<long_schedule>*sch, vector<long_task>*tasks, vector<interval_s>*intervals, int core)
{
	long_schedule temp_sch;
	long start;
	long end;
	long done_comps[tasks->size()];
	double rate[tasks->size()];

	long hyperperiod=compute_lcm(tasks);



	long done_comps_test[tasks->size()];

	temp_sch.arrival=0;
	temp_sch.speed=1;

	for(int z=0;z<intervals->size();z++)
	{

		start=(*intervals)[z].start;
		end=(*intervals)[z].end;


		for(unsigned int i=0;i<tasks->size();i++)
		{
			rate[i]=((double)((*intervals)[z].computations[i][core]))/(((double)((*intervals)[z].end-(*intervals)[z].start)));


//			cout<<"rate "<<i<<" computations "<<rate[i]<<endl;
			done_comps[i]=0;
			done_comps_test[i]=0;

		}

		bool slack_end=true;
		while(start<end)
		{
			//cout<<" start "<<start<<endl;
			int id=-1;
			double etime=end+1;
			for(unsigned int i=0;i<tasks->size();i++)
			{
				if(done_comps[i]<=round((double((start-(*intervals)[z].start))*rate[i])) 	&&
								 (double)(done_comps[i]+1)/rate[i]<=(etime + W_INT/10)  &&
								 (done_comps[i]+1)<=(*intervals)[z].computations[i][core])
				{
					etime=round((double((done_comps[i]+1)))/rate[i]);
					id=i;
				}
			}
			if(id>=0)
			{
				temp_sch.start=start;
				temp_sch.end=start+1;
				temp_sch.float_end=temp_sch.end;
				temp_sch.task_id=id;
				temp_sch.power=(*tasks)[id].power;
				temp_sch.core=core;
				done_comps[id]=done_comps[id]+1;
				sch->push_back(temp_sch);
				start=temp_sch.end;
			}
			else
			{
				start=start+1;
			}

		}

		for(unsigned int i=0;i<tasks->size();i++)
		{
			if (done_comps[i]!=(*intervals)[z].computations[i][core])
			{
				cout<<"less computations for task "<<i<<" in interval "<<z<<" start "<<(*intervals)[z].start<<" end "<<(*intervals)[z].end<<endl;

				for(unsigned int y=0;y<sch->size();y++)
				{
					if((*sch)[y].start>=round(interval_req[z][1]/W_INT) && (*sch)[y].end<=round(interval_req[z][2]/W_INT))
					{
						done_comps_test[(*sch)[y].task_id]=done_comps_test[(*sch)[y].task_id]+(*sch)[y].end-(*sch)[y].start;
						//cout<<"id "<<(*sch)[y].task_id<<" start "<<(*sch)[y].start<<" end "<<(*sch)[y].end<<endl;
					}
				}


				for(unsigned int j=0;j<tasks->size();j++)
				{
					cout<<"task "<<j<<" total computations "<<done_comps[j]<<" required computations "<<(*intervals)[z].computations[j]<<" test computations "<<done_comps_test[j]<<" rate "<<rate[j]<<endl;
				}
	//			cout<<"start "<<(*intervals)[z].start<<" end "<<end<<endl;
				exit(1);
			}
		}
	}

	double total_done_comps[tasks->size()];

	for(unsigned int i=0;i<tasks->size();i++)
	{
		total_done_comps[i]=0;
	}


	for(unsigned int i=0;i<sch->size();i++)
	{
		total_done_comps[(*sch)[i].task_id]=total_done_comps[(*sch)[i].task_id]+(*sch)[i].end-(*sch)[i].start;
//		cout<<"id "<<(*sch)[i].task_id<<" start "<<(*sch)[i].start<<" end "<<(*sch)[i].end<<endl;
	}

	//for(unsigned int i=0;i<tasks->size();i++)
	//{
	//	cout<<"task "<<i<<" total computations "<<total_done_comps[i]<<" required computations "<<(*intervals)[intervals->size()-1].net_computations[i]<<endl;
//	/	cout<<"task "<<i<<" total computations "<<total_done_comps[i]<<" required computations "<<total_comps[i]<<endl;
	//}
}
예제 #5
0
파일: util.cpp 프로젝트: ayoosh/ece750
void generate_tasksets(vector<task>* tasks, int num_tasksets, int hyperperiod,int min_util, int max_util)
{
//	cout << "entered generate tasksets" << endl;
	vector<int> factors;
	factorise(&factors, hyperperiod);

	task temp;
	for (int i = 0; i < num_tasksets; i++) {
		temp.taskset = i;
		int num_tasks = rand() % (11) + 10;
		
		//num_tasks=5;

		int utilization = 0;
		if ((max_util - min_util) > 0) {
			//utilization = 2*rand() % (max_util - min_util) + min_util;
            utilization = max_util;
		} else {
			utilization = min_util;
		}
        cout << "utilizatio = "<<utilization<< endl;
		for (int j = 0; j < num_tasks; j++) {
			temp.index = i;
			int index = rand() % factors.size();
			int task_utilization;
			temp.period = factors[index]; //* MULT_FACTOR;
			if (j < num_tasks - 1) {
				task_utilization = rand()
						% (utilization / ((num_tasks - j) / 2)
								- utilization / (2 * (num_tasks - j)))
						+ utilization / (2 * (num_tasks - j));

             //   task_utilization = utilization * ((( rand() % (num_tasks - j)) + 1) / (num_tasks - j));
                utilization = utilization - task_utilization;
			} else {
				task_utilization = utilization;
			}
            cout << "j:" << j << "util:" << task_utilization <<endl;
			temp.computation_time = temp.period * task_utilization / 100;
			//temp.stat_stream=new ifstream();
			temp.priority=20;
			temp.state=FINISHED;
			temp.core=CORE;
			if (temp.computation_time > 0) {
				tasks->push_back(temp);
			}
		}
	}

    cout << "tasks->size()="<<tasks->size()<<endl;

	for (unsigned int i = 0; i < tasks->size(); i++) {
		(*tasks)[i].tid = i;
	}

	taskset temp_set;
	for (int i = 0; i < num_tasksets; i++) {

		int hyp_length = compute_lcm(tasks, 0);
		float thermal_capacity = ((float) hyp_length) * corrected_threshold;
		int thermal_utilization = rand() % 51 + 50;
		float taskset_target_TTI = thermal_capacity
				* ((float) thermal_utilization) / 100;
		float average_power = taskset_target_TTI / hyp_length * 2; //*beta;//beta not added to reduce power

		int start = -1;
		int end;
		for (unsigned int j = 0; j < tasks->size(); j++) {
			if ((*tasks)[j].taskset == i) {
				end = j;
				if (start == -1) {
					start = j;
				}
			}
		}

		float total_util = 0;
		for (int j = start; j <= end; j++) {

			     //#if(ENABLE_PRINTS)
			cout << "task:" << j << "taskset:" << (*tasks)[j].taskset
					<< " computation time:" << (*tasks)[j].computation_time
					<< " period:" << (*tasks)[j].period << " Utilization: "
					<< (float) (*tasks)[j].computation_time
							/ (float) (*tasks)[j].period << endl;
			     //#endif
			total_util = total_util
					+ (float) (*tasks)[j].computation_time
							/ (float) (*tasks)[j].period;

		}
#if(ENABLE_PRINTS)

		cout<<"total_utilization="<<total_util<<endl;
#endif
		temp_set.c_util = total_util;
		average_power = average_power / total_util;
#if(ENABLE_PRINTS)

		cout<<"length of hyperperiod:"<<hyp_length<<endl;
		cout<<"thermal utilization: "<<thermal_utilization<<"average_power: "<<average_power<<endl;
#endif
		float deviation = average_power * 1.6;
		for (int j = start; j <= end; j++) {
			float power = average_power * 0.2
					+ ((double) (rand()) / RAND_MAX) * deviation;
			(*tasks)[j].power = power;
		}

		float total_impact = 0;
		for (int j = start; j < end; j++) {
			total_impact = total_impact
					+ (*tasks)[j].power * (*tasks)[j].computation_time
							* (hyp_length / (*tasks)[j].period) / beta;
		}
		temp_set.TTI = total_impact / GRANULARITY;
		temp_set.t_util = total_impact / (corrected_threshold * (hyp_length));
		temp_set.average_power = total_impact / hyp_length * beta;
		temp_set.hyperperiod = hyp_length;
		tasksets.push_back(temp_set);
#if(ENABLE_PRINTS)

		cout<<"required_impact "<<taskset_target_TTI<<" actual thermal impact: "<<total_impact<<endl;
#endif
	}
/*#if(OPT_ENABLE==1)
	generate_instances(tasks,"input");
#endif*/
//    exit(1);

//	cout << "taskset generated" << endl;
}