Jump to content

end_of_simulation is not triggered


thundium

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

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

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

Link to post
Share on other sites
  • 11 months later...

@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??

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...