ashwathgan Posted March 9, 2015 Report Posted March 9, 2015 Hi All I tried to implement a simple Task Scheduler in SystemC. It works as follows: I have three modules "TaskA" , "TaskB" and "CPU". The algorithm works in such a way that the CPU gives full utilization if only one task is present at a time and gives 50% utilization if both the tasks are present. The Arrival times of both the tasks are assigned before the start of the simulation. I was able to implement it with ports and signals, but now i want to measure the performace without ports and signals (i.e) using the C++ and the internal clock of systemc( sc_time_stamp(), sc_start() etc ). Presently, i have the following: class Task : sc_module { void taskA() { .... bool tskA = true; if(tskA) { eventA.notify(10,SC_NS); // Arrival time of A as a Event tskA = false } else { outA= true // So that we get the event after 10ns of simualtion time } void taskB() { ..... bool tskB = true; if(tskB) { eventB.notify(20,SC_NS); // Arrival Time of B as a Event tskB = false; } else { outB = true; // To get taskB after 20ns after the start simulation } } SC_CTOR() { SC_METHOD(taskA); SC_METHOD(taskB); sensitive << eventA; sensitive << eventB; } class CPU: sc_module { Task A; Task B; void cpu() { A.taskA(); B.taskB(); if(outA) { //Debug statement cout << "A arrives @"<< sc_time_stamp() << endl; some calculation } else if (outA && outB) { //Debug Statement cout << "B arrives @" << sc_time_stamp() << endl; some calculation} } } SC_CTOR(CPU) : A("AT"), B("BT") { SC_METHOD(cpu); sensitive << eventA; sensitive << eventB; } But, the problem is the modules gets executed always. To me more precise: What I expect as Output is: A arrives @ 10ns B arrives @ 20ns But, What I am getting now is A arrives @ 10ns B arrives @ 10ns A arrives @ 20ns B arrives @ 20ns I am not able to figure out where I am going wrong, can anyone please give me suggestions/ point out the msitake i am doing here? Quote
David Black Posted March 12, 2015 Report Posted March 12, 2015 SC_METHOD's and SC_THREAD's are always called once at the start of simulation (to allow reset/startup behavior). If you use dont_initialize() after each registration, you can avoid that: SC_METHOD(my_func); sensitive << my_event; dont_initialize(); SC_METHOD(other_func); sensitive << other_event; dont_initialize(); Quote
ashwathgan Posted March 13, 2015 Author Report Posted March 13, 2015 Thank you, it solved the trouble for me. Quote
dakupoto Posted March 14, 2015 Report Posted March 14, 2015 Hi All I tried to implement a simple Task Scheduler in SystemC. It works as follows: I have three modules "TaskA" , "TaskB" and "CPU". The algorithm works in such a way that the CPU gives full utilization if only one task is present at a time and gives 50% utilization if both the tasks are present. The Arrival times of both the tasks are assigned before the start of the simulation. I was able to implement it with ports and signals, but now i want to measure the performace without ports and signals (i.e) using the C++ and the internal clock of systemc( sc_time_stamp(), sc_start() etc ). Presently, i have the following: class Task : sc_module { void taskA() { .... bool tskA = true; if(tskA) { eventA.notify(10,SC_NS); // Arrival time of A as a Event tskA = false } else { outA= true // So that we get the event after 10ns of simualtion time } void taskB() { ..... bool tskB = true; if(tskB) { eventB.notify(20,SC_NS); // Arrival Time of B as a Event tskB = false; } else { outB = true; // To get taskB after 20ns after the start simulation } } SC_CTOR() { SC_METHOD(taskA); SC_METHOD(taskB); sensitive << eventA; sensitive << eventB; } class CPU: sc_module { Task A; Task B; void cpu() { A.taskA(); B.taskB(); if(outA) { //Debug statement cout << "A arrives @"<< sc_time_stamp() << endl; some calculation } else if (outA && outB) { //Debug Statement cout << "B arrives @" << sc_time_stamp() << endl; some calculation} } } SC_CTOR(CPU) : A("AT"), B("BT") { SC_METHOD(cpu); sensitive << eventA; sensitive << eventB; } But, the problem is the modules gets executed always. To me more precise: What I expect as Output is: A arrives @ 10ns B arrives @ 20ns But, What I am getting now is A arrives @ 10ns B arrives @ 10ns A arrives @ 20ns B arrives @ 20ns I am not able to figure out where I am going wrong, can anyone please give me suggestions/ point out the msitake i am doing here? Hello Sir, It is all very fine to use explicit event handling with the wait-notify pair scheme for small systems with e.g., 5 - 10 events. But what would one do in a complicated system with e.g., 30 events ? The programmer would HAVE to correctly add the wait/notify at the correct positions in the code, else there would be a complete, useless mess. So, why bother ? With sensitivity lists and implicit events, the SystemC runtime kernel keeps track of/manages all these confusing but vital event tracking tasks. Hope that helps. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.