Jump to content
Sign in to follow this  
thundium

end_of_simulation is not triggered

Recommended Posts

Hi All:

 

I got a given SystemC code running without end_of_simulation called. And I know "end_of_simulation" won't be called if sc_stop is not called.

 

I debug into the code and see following situation. Code looks like

 

void thread_a()  //it is a sc thread

{

  while(xxx) {

     wait(sc_time(x,SC_NS));  break 1

     cout<<"xxxxx"<<endl;       break 2

     ---logics----

  }

  sc_stop;

}

 

The last time I was stopped at breakpoint 1, then I did step next. Then instead of stopping at breakpoint 2 , I stopped at sc_main after sc_start.

So it looks like the entire thread is stopped by others? What else than "sc_stop" can terminate the thread?  Since my code in "end_of_simulation" is not triggered, I am sure that there is no other sc_stop in my programme that calling sc_stop. So what can be the backend hand doing that?

 

Thanks a lot for all your help

Share this post


Link to post
Share on other sites

The LRM (section 4.4.4) specifies that end_of_simulation() will be called either after sc_stop(), or if sc_main is not used.

Sometimes people call sc_stop() after sc_start() just to trigger the end_of_simulation() callback.

 

Regarding your first question, you've left out the vital piece of information! What is "xxx" in wait(xxx). If it is the word true, then of course the loop will never exit and sc_stop() will never get called.

 

regards

Alan

Share this post


Link to post
Share on other sites

I typically use the following code following sc_start():

  sc_start();
  if (not sc_end_of_simulation_invoked()) {
    SC_REPORT_INFO(MSGID,"ERROR: Simulation stopped without explicit sc_stop()");
    sc_stop();
  }//endif

That way I always know end_of_simulation() will be invoked.

 

I also put try/catch blocks around both the design instantiation and sc_start itself to be certain I know why my simulation stopped.

  std::unique_ptr<Top_module> top_instance; //NOTE: Use std::auto_ptr<> for pre-C++11
  try {
    top_instance.reset( new Top_module("top_instance") );
  } catch (std::exception& e) {
    SC_REPORT_ERROR(MSGID,(string(e.what())+" Please fix elaboration errors and retry.").c_str());
    return 1;
  } catch (...) {
    SC_REPORT_ERROR(MSGID,"Caught exception during elaboration");
    return 1;
  }//endtry

  // Simulate
  try {
    SC_REPORT_INFO(MSGID,"Starting kernal");
    sc_start(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<< START SIMULATOR
    SC_REPORT_INFO(MSGID,"Exited kernal");
  } catch (std::exception& e) {
    SC_REPORT_WARNING(MSGID,(string("Caught exception ")+e.what()).c_str());
  } catch (...) {
    SC_REPORT_ERROR(MSGID,"Caught exception during simulation.");
  }//endtry

Share this post


Link to post
Share on other sites

@apfitch and @ david, i understood the concept of end of simulation... But i had the query that is there a way to stop the simulation at any point under some conditions?? Can i use sc_stop() any where in the code or it is mandatory to use it in main().

 

WellThe LRM (section 4.4.4) specifies that end_of_simulation() will be called either after sc_stop(), or if sc_main is not used.

Can i use sc_stop at any part of my program??

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  

×