Ejemplo n.º 1
0
void allPath(s *r,int i)
{
    if(r!=NULL)
    {
        a[i++]=r->data;
        allPath(r->left,i);
        allPath(r->right,i);
        if(r->left==NULL && r->right==NULL)
        {
            a[i--]='\0';
            print(a);
            return;
        }
    }
    return;
bool AffinityTask::staticStrongAnalysis(const TaskSet& taskSet, Time overhead)
{
	AffinityTask::Compare compare;
	std::unordered_map<AffinityTask*, Time> responseTime;
	Affinity allCPU;
	for(AffinityTask* task : taskSet)
	{
		responseTime.insert(std::pair<AffinityTask*, Time>(task, task->worstExecution));
		for(auto cpu : task->affinity)
			allCPU.insert(cpu);
	}

	while(true)
	{
		bool changed = false;
		bool overflow = false;
		std::unordered_map<AffinityTask*, Time> newResponseTime;

		for(auto current : responseTime)
		{
			AffinityTask* curTask = current.first;
			std::set<Affinity> powerSet = AffinityTask::powerSet(curTask->affinity);
			Time currentResponse = responseTime.find(curTask)->second;
			TaskSet ignoreTask;
			ignoreTask.insert(curTask);

			Time min_sumInterfere = std::numeric_limits<Time>::max();
			for(Affinity s : powerSet)
			{
				assert(s.size() != 0);
				Size s_Size = s.size();
				//Time sumInterference = 0;
				std::unordered_map<CPUID, std::list<TaskSet>> possibleReplacement;
				for(auto cpu : s)
				{
					possibleReplacement.insert(std::pair<CPUID, std::list<TaskSet>>
							(cpu, std::list<TaskSet>()));
				}

				for(CPUID selectedCPU : s)
				{
					Affinity ignoreCPU(s);
					ignoreCPU.erase(selectedCPU);
					for(auto alternative : allCPU)
					{
						if(ignoreCPU.find(alternative) != ignoreCPU.end())
							continue;
						auto allPaths = allPath(taskSet, selectedCPU, alternative, ignoreCPU, ignoreTask);
						for(auto path : allPaths)
						{
							if(path.size() > 0)
							{
								TaskSet ignoredTask;
								Affinity moreCheck;
								for(auto item : path)
								{
									if(item.isTask())
										ignoredTask.insert(item.getTask());
									else
										moreCheck.insert(item.getCPUID());
								}
								TaskSet highTaskSet;
								for(AffinityTask* highPriorityTask : taskSet)
								{
									//if(compare(curTask, highPriorityTask))
									//	continue;
									if(highPriorityTask == curTask)
										continue;
									if(ignoredTask.find(highPriorityTask) != ignoredTask.end())
										continue;

									bool intersect = false;
									for(auto cpu : highPriorityTask->affinity)
									{
										if(moreCheck.find(cpu) != moreCheck.end())
										{
											intersect = true;
											break;
										}
									}
									if(!intersect)
										continue;

									highTaskSet.insert(highPriorityTask);
								}
								possibleReplacement.find(selectedCPU)->second.push_back(highTaskSet);
							}
						}
					}
				}


				for(auto possibleSet : combinePossibleTaskSet(possibleReplacement))
				{
					Time sumInterference = 0;
					/*
					if(possibleSet.size() ==0)
						continue;

					assert(possibleSet.size() > 0);
					*/
					sumInterference += overhead;
					for(auto highPriorityTask : possibleSet)
					{

						Time interferenceCount = currentResponse/highPriorityTask->minPeriod;
						Time remaining = currentResponse % highPriorityTask->minPeriod;
						Time interference = interferenceCount * highPriorityTask->worstExecution
								+ std::min(remaining, highPriorityTask->worstExecution);

						Time contextSwitchCount = interferenceCount;
						if(remaining > 0)
							contextSwitchCount++;

						sumInterference += 2*(contextSwitchCount) * overhead;

						if(compare(curTask, highPriorityTask))
							continue;

						sumInterference += interference;
					}


					Time floorValue = floor((Real)sumInterference / (Real)s_Size);

					min_sumInterfere = std::min(min_sumInterfere, floorValue);
				}
			}
			assert(min_sumInterfere != std::numeric_limits<Time>::max());

			Time nextResponse = curTask->worstExecution + min_sumInterfere;
			newResponseTime.insert(std::pair<AffinityTask*, Time>(curTask, nextResponse));
			if(currentResponse != nextResponse)
				changed = true;
			if(currentResponse > curTask->minPeriod)
				overflow = true;
		}

		if(changed)
			responseTime = newResponseTime;
		else
			break;
		if(overflow)
			break;
	}

	bool possible = true;
	for(auto iter : responseTime)
	{
		if(iter.second > iter.first->minPeriod)
		{
			possible = false;
			iter.first->print_log(WARN, "Execution time: %lu, Period: %lu, Response time: %lu",
					iter.first->worstExecution, iter.first->minPeriod, iter.second);
		}
		else
		{
			iter.first->print_log(INFO, "Execution time: %lu, Period: %lu, Response time: %lu",
					iter.first->worstExecution, iter.first->minPeriod, iter.second);
		}
	}

	return possible;
}
Ejemplo n.º 3
0
int main()
{
    s *root=NULL;
    root=create('A');
    root->left=create('B');
    root->right=create('C');
    root->left->left=create('D');
    root->left->right=create('E');
    root->left->right->left=create('I');
    root->left->right->right=create('J');
    root->left->right->right->left=create('K');
    root->right->left=create('F');
    root->right->right=create('G');
    root->right->right->left=create('H');
    int n,num,h;
    while(1)
    {
        printf("1. All possible paths\n");
        printf("2. Height of the tree\n");
        printf("3. In Order\n");
        printf("4. Level Order\n");
        printf("5. Spiral Order\n");
        printf("6. Exit\n");
        printf("\nSelect an option: ");
        scanf("%d",&num);
        system("cls");
        switch(num)
        {
            case 1: allPath(root,0);
                    getch();
                    system("cls");
                    break;
            case 2: h= height(root);
                    printf("height = %d ",h);
                    getch();
                    system("cls");
                    break;
            case 3: inOrder(root);
                    printf("end");
                    getch();
                    system("cls");
                    break;

            case 4: printf("Enter the level you want to print: ");
                    scanf("%d",&n);
                    levelOrder(root,n);
                    printf("end");
                    getch();
                    system("cls");
                    break;

            case 5: spiralOrder(root,height(root));
                    getch();
                    system("cls");
                    break;

            case 6: exit(0);

            default: printf("Invalid Input!!");
                     getch();
                     system("cls");
        }
    }
    return 0;