Sign in to follow this  
Followers 0
VanTeo

Take one clock cycle for each thread

4 posts in this topic

Hi,

I have 6 thread s1, s2, s3 and I want to that these thread each take one clock cycle. Thread s1 is sensitive at first clock posedge and run in one clock cycle, s2 is sensitive at sencond clock posedge and run in one clock cycle, s3 is sensitive at third clock posedge and run in one clock cycle.

Regard,

VanTeo

Share this post


Link to post
Share on other sites

Becasue I am modeling a CPU, I have threads: Fetch, Decode, EvaluateAddress, FetchOperands, Execute, Store. I want to each thread will run in one clock cycle, the Fetch thread will run in first one clock cycle (sensitive by clock posedge) then will suspend and Decode thread will run after (in one clock cycle too), and the next wil be EvaluateAddress, FetchOperands, Execute, Store .... I don't know how to do it. Please help me.

Regard,

Huy

Share this post


Link to post
Share on other sites

:D I just saw the new features in systemc-2.3.1a, they helped me solve this problem

SC_CTHREAD(Fetch, clk.pos());
Fe = sc_get_current_process_handle();

SC_CTHREAD(Decode, clk.pos());
De = sc_get_current_process_handle();

SC_CTHREAD(EvaluateAddress, clk.pos());
Ev = sc_get_current_process_handle();

SC_CTHREAD(FetchOperands, clk.pos());
FeO = sc_get_current_process_handle();

SC_CTHREAD(Execute, clk.pos());
Ex = sc_get_current_process_handle();

SC_CTHREAD(Store, clk.pos());
St = sc_get_current_process_handle();
sc_process_handle Fe;
sc_process_handle De;
sc_process_handle Ev;
sc_process_handle FeO;
sc_process_handle Ex;
sc_process_handle St;

void Fetch()
{
   while(true);
   wait(1);
   ...
   Fe.disable();
   De.enable();
}

void Decode()
{
   while(true);
   wait(2);
   ...
   De.disable();
   Ev.enable();
}

void Evaluate()
{
   while(true);
   wait(3);
   ...
   Ev.disable();
   FeO.enable();
}

void FetchOperands()
{
   while(true);
   wait(4);
   ...
   FeO.disable();
   Ex.enable();
}

void Excute()
{
   while(true);
   wait(5);
   ...
   Ex.disable();
   St.enable();
}

void Store()
{
   while(true);
   wait(6);
   ...
   St.disable();
   Fe.enable();
}

Share this post


Link to post
Share on other sites

For a pipeline, that is cycle accurate, you would need a reference to clock somewhere. Your implementation might work, but I am not sure what it actually implements / represents !

You could do an event based synchronization. And the below code assumes an ideal pipeline. (ie) there is no interprocess dependencies / bubbles and hence no pipeline stalls.

If there is a pipeline stall & also during the initial pipeline fill, a suitable synchronization is to be used.

sc_event do_decode_ev;
sc_event do_evaladdr_ev;
sc_event do_fetchop_ev;
sc_event do_execute_ev;
sc_event do_store_ev;


SC_THREAD(Fetch);
sensitive << clock.pos();
SC_THREAD(Decode);
sensitive << do_decode_ev;
SC_THREAD(Evaluate);
sensitive << do_evaladdr_ev;
SC_THREAD(FetchOperands);
sensitive << do_fetchop_ev;
SC_THREAD(Excute);
sensitive << do_execute_ev;
SC_THREAD(Store);
sensitive << do_store_ev;


void Fetch()
{
while(1){
wait();  //! will do a fetch every cycle.
//! do the fetch and trigger decode in next delta  
do_decode_ev.notify(SC_ZERO_TIME);
}
}


void Decode()
{
while(1){
wait();  //! waits for do_decode_ev <-- IMP --> decode the fetch done in previous cycle | not the one done in this cycle | In first cycle there is no operand, so wait till operand is there.
//! notify the next process in pipeline
do_evaladdr_ev.notify(SC_ZERO_TIME);
}
}


void Evaluate()
{
while(1){
wait();  //! waits for do_execute_ev  <-- evaluate for inputs from previous cycle
//! notify the next process in pipeline
do_execute_ev.notify(SC_ZERO_TIME);
}
}


void FetchOperands()
{
while(1){
wait();  //! waits for do_fetchop_ev
//! notify the next process in pipeline
do_execute_ev.notify(SC_ZERO_TIME);
}
}
 //! etc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0