/*Initialize status_queues structure Function Variable Definition: -- header: header pointer of process_info structure -- signal: signal that decide process priority Return value: status_queues structure pointer */ STATUS_QUEUES *initStatusQueues(PROCESS_INFO *header, const char signal){ STATUS_QUEUES *schedule = (STATUS_QUEUES*)malloc(sizeof(STATUS_QUEUES)); //status_queues structure int count; //counter //Sort the process by id number sortProcess(&header, NULL); //Set the process priority as start_time setProcessPriority(header, 'S'); //Re-sort the process by start_time sortProcess(&header, NULL); //Set the process priority as "signal" decided setProcessPriority(header, signal); //Initialize the unarrival queue schedule->queues[0] = header; //Initialize the other four queues for (count = 1; count < QUEUES_SIZE; count++){ //Allocate the memory for new queue front pointer schedule->queues[count] = (PROCESS_INFO*)malloc(sizeof(PROCESS_INFO)); //Assign the front's next as NULL(empty queue) schedule->queues[count]->next = NULL; } return schedule; }
/*Insert a Element in Queue Function Variable Definition: -- front: queue front pointer -- node: process_info structure need to insert -- signal: signal that decide process priority Return value: NULL */ void insertInQueue(PROCESS_INFO *front, PROCESS_INFO *node, const char signal){ PROCESS_INFO *temp_before; //the location before the insert node PROCESS_INFO *temp; //the location after the insert node //Set the process priority as "signal" decided setProcessPriority(front->next, signal); //Set the insert node's priority as "signal" decided setProcessPriority(node, signal); //Test the queue is empty if (front->next == NULL){ //Insert the node after the front pointer front->next = node; node->next = NULL; } //Initialize process_info structure temp temp = front->next; temp_before = front; //Find the location which the node insert while (temp != NULL){ //Compare priority of node and element in queue if (node->priority < temp->priority){ //If smaller, then find it break; } else if (node->priority == temp->priority){ //If equal, then compare the id number while ((temp != NULL) && (node->priority == temp->priority)){ if (node->id < temp->id){ break; } //Move the pointer to the next element in queue temp_before = temp; temp = temp->next; } break; } //Move the pointer to the next element in queue temp_before = temp; temp = temp->next; } //Insert the node temp_before->next = node; if (temp != NULL){ node->next = temp; } else{ node->next = NULL; } return; }
int main(int argc, char* argv[]) { ArgumentParser argParser; if(!argParser.parseArgs(argc, argv)) { Logger::ERROR("Invalid arguments provided!"); Logger::ERROR(argParser.getUsage()); return 1; } Config* config = Config::getConfig(); config->testnodePrioritySwitcher = new PrioritySwitcher(0, config->fifoScheduling); if(!setProcessPriority()) { Logger::ERROR("Couldn't set priority appropriately, maybe not running as root?"); return 1; } ros::init(argc, argv, "oneshot_timer_tests"); config->nodeHandle = new ros::NodeHandle; Logger::INFO("Performing ROS Timer latency measurements..."); OneShotLatencyMeasurer* measurer; if(config->busyMode) { Logger::INFO("Running in busy mode"); measurer = new BusyOneShotLatencyMeasurer(); } else { Logger::INFO("Running in default mode"); measurer = new IdleOneShotLatencyMeasurer(); } measurer->measure(); measurer->printMeasurementResults(); measurer->saveMeasuredLatencyGnuplotData(); return 0; }