Jump to content

SystemC without Signals


ashwathgan

Recommended Posts

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?

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...