std::list<std::list<GraphNode>> AffinityTask::allPath(const TaskSet& taskSet, const GraphNode& start, const GraphNode& target, const Affinity& excludeID, const TaskSet& excludeTask) { std::list<std::list<GraphNode>> returnValue; //prepare link map std::unordered_map<CPUID, TaskSet> cpuToTaskList; std::unordered_map<AffinityTask*, Affinity> taskToCPUList; for(auto task : taskSet) { if(excludeTask.find(task) != excludeTask.end()) continue; Affinity affinityCopy(task->affinity); for(auto cpu : excludeID) affinityCopy.erase(cpu); taskToCPUList.insert(std::pair<AffinityTask*, Affinity>(task, affinityCopy)); for(CPUID cpu : affinityCopy) { if(cpuToTaskList.find(cpu) == cpuToTaskList.end()) cpuToTaskList.insert(std::pair<CPUID, TaskSet>(cpu, TaskSet())); cpuToTaskList.find(cpu)->second.insert(task); } } DFS(returnValue, cpuToTaskList, taskToCPUList, start, target, std::list<GraphNode>()); return returnValue; }
void main() { clearRAM(); //clear all ram DDR_init(); //intialize DDR copy registers //initialize and install VP's vpInit(); //must be called prior to other vp functions tx = vpInstall(TX1); //install virtual peripheral TX1 rx = vpInstall(RX1); //install virtual peripheral RX1 //setup tasks TaskInit(); //must be called prior to other task functions TaskSet(0,TXDEQUEUE+TASKSTART,2); // task slot 0, run "TxDequeue", every 2 taskticks TaskSet(1,RXENQUEUE+TASKSTART,2); // task slot 1, run "RxEnqueue", every 2 taskticks TaskEnable(); //master task enable (eg. enable task interrupts) //at this point, the interrupt should be enabled OPTION = RTCC_ON + RTCC_PS_OFF; sendString(WELCOME); while (1) { wresult = dequeue(); // get received byte (from receiver queue) if (wresult.high8 == 0) { //queue not empty, so result valid sendChar(wresult.low8); //echo received byte } } }
std::list<GraphNode> AffinityTask::BFS(const TaskSet& taskSet, const GraphNode& start, const GraphNode& target, const Affinity& excludeID, const TaskSet& excludeTask) { std::list<GraphNode> returnList; //prepare link map std::unordered_map<CPUID, TaskSet> cpuToTaskList; std::unordered_map<AffinityTask*, Affinity> taskToCPUList; for(auto task : taskSet) { if(excludeTask.find(task) != excludeTask.end()) continue; Affinity affinityCopy(task->affinity); for(auto cpu : excludeID) affinityCopy.erase(cpu); taskToCPUList.insert(std::pair<AffinityTask*, Affinity>(task, affinityCopy)); for(CPUID cpu : affinityCopy) { if(cpuToTaskList.find(cpu) == cpuToTaskList.end()) cpuToTaskList.insert(std::pair<CPUID, TaskSet>(cpu, TaskSet())); cpuToTaskList.find(cpu)->second.insert(task); } } //procedure BFS(G,v) is std::unordered_map<CPUID, AffinityTask*> cpuToPrevTask; std::unordered_map<AffinityTask*, CPUID> taskToPrevCPU; bool reachable = false; std::queue<GraphNode> queue;//create a queue Q, true is Job, false is processor std::unordered_set<CPUID> visitedCPU; //create a set V std::unordered_set<AffinityTask*> visitedTask; //create a set V if(start.isTask()) visitedTask.insert(start.getTask()); //add v to V else visitedCPU.insert(start.getCPUID()); queue.push(start); //enqueue v onto Q while(!queue.empty())//while Q is not empty loop { auto currentItem = queue.front(); //t ← Q.dequeue() queue.pop(); if(currentItem.isTask()) { if(target.isTask()) if(target.getTask() == currentItem.getTask()) //if t is what we are looking for then { //return t reachable = true; break; } } else { if(!target.isTask()) if(target.getCPUID() == currentItem.getCPUID()) //if t is what we are looking for then { //return t reachable = true; break; } } //for all edges e in G.adjacentEdges(t) loop if(currentItem.isTask()) { AffinityTask* curTask = currentItem.getTask(); assert(curTask != nullptr); for(CPUID adjacentCPU : taskToCPUList.find(curTask)->second) //u ← G.adjacentVertex(t,e) { if(visitedCPU.find(adjacentCPU) == visitedCPU.end()) //if u is not in V then { visitedCPU.insert(adjacentCPU); //add u to V queue.push(GraphNode(adjacentCPU)); //enqueue u onto Q assert(cpuToPrevTask.find(adjacentCPU) == cpuToPrevTask.end()); cpuToPrevTask.insert(std::pair<CPUID,AffinityTask*>(adjacentCPU, curTask)); } } } else { CPUID curCPU = currentItem.getCPUID(); auto iter = cpuToTaskList.find(curCPU); if(iter == cpuToTaskList.end()) { continue; } assert(iter->second.size() > 0); for(AffinityTask* adjacentTask : iter->second) //u ← G.adjacentVertex(t,e) { if(visitedTask.find(adjacentTask) == visitedTask.end()) { visitedTask.insert(adjacentTask); queue.push(GraphNode(adjacentTask)); assert(taskToPrevCPU.find(adjacentTask) == taskToPrevCPU.end()); taskToPrevCPU.insert(std::pair<AffinityTask*,CPUID>(adjacentTask, curCPU)); } } } } if(reachable) { GraphNode current = target; while(true) { returnList.push_front(current); if(current.isTask()) { auto cpu_iter = taskToPrevCPU.find(current.getTask()); if(cpu_iter == taskToPrevCPU.end()) { assert(start.isTask()); assert(current.getTask() == start.getTask()); break; } current = cpu_iter->second; } else { auto task_iter = cpuToPrevTask.find(current.getCPUID()); if(task_iter == cpuToPrevTask.end()) { assert(!start.isTask()); assert(current.getCPUID() == start.getCPUID()); break; } current = task_iter->second; } } } return returnList; }