Jump to content

yaohe

Members
  • Posts

    3
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by yaohe

  1. Hi Eyck, My goal is to NOT involve any simulation time advancing in the SC modules. So I'm expecting a solution like: Even with remove the "main" function in module(Foo), I can still make the standalone "wait(GenSvEvent)" keeps waiting for an external event (which is like SC simulation kernel is halt), instead of simulation quit. This requirement is mentioned in the Greensoc slides I posted, but I have no idea how to implement it.
  2. Hi Eyck, Thanks for your prompt repsonse! I'm a bit confused about your proposal since my goal is to remove polling thread but still makes SC kernel alive. I pasted my code below. You can see I made "polling thread" as an external thread, it notifies the "proccessing thread" by ThreadSafeEvent. However, to keep SC kernel not exits, I must put an extra SC_THREAD "main", otherwise there is only one single "wait" (in processing thread) event in sc kernel and it will ends. The extra SC_THREAD "main" gets unexpected time advancing involved which is not what I expect. #include <systemc> #include <pthread.h> #include <unistd.h> using namespace sc_core; class ThreadSafeEventIf : public sc_interface { virtual void notify(sc_time delay = SC_ZERO_TIME) = 0; virtual const sc_event &default_event(void) const = 0; protected: virtual void update(void) = 0; }; class ThreadSafeEvent : public sc_prim_channel, public ThreadSafeEventIf { public: ThreadSafeEvent(const char *name = ""): event(name) {} void notify(sc_time delay = SC_ZERO_TIME) { this->delay = delay; async_request_update(); } const sc_event &default_event(void) const { return event; } protected: virtual void update(void) { event.notify(delay); } sc_event event; sc_time delay; }; sc_event GenScEvent; SC_MODULE(Foo) { public: SC_CTOR(Foo) { SC_THREAD(main); SC_METHOD(eventTriggered); sensitive << threadSafeEvent; dont_initialize(); } private: void main() { //extra forever thread to avoid simulation exit while (1) { wait(100, SC_NS); } } void eventTriggered() { printf("Foo: Got event from pthread \n"); GenScEvent.notify(); } public: ThreadSafeEvent threadSafeEvent; }; void *PollingThread(void *arg) { int cnt = 0; while (1) { cnt++; printf("[POLL]: %d: Before generating event from PollingThread \n", cnt); usleep(3*1000*1000); Foo *foo = (Foo*)(arg); foo->threadSafeEvent.notify(); printf("[POLL]: %d: Event notified from PollingThread \n", cnt); } }; class sc_top : public sc_module { private: SC_HAS_PROCESS(sc_top); public: sc_top(sc_module_name name="SCTOP"): sc_module(name) { SC_THREAD(processing_thread); } void processing_thread(); }; void sc_top::processing_thread() { int cnt =0; while (1) { printf("[PROC]: processing_thread called \n"); printf("[PROC]: Wait GenScEvent \n"); wait(GenScEvent); cnt++; printf("[PROC]: Got %d GenScEvent \n", cnt); } } int sc_main(int argc, char *argv[]) { Foo foo("foo"); sc_top u_sc_top("u_sc_top"); pthread_t thread; pthread_create(&thread, NULL, PollingThread, &foo); sc_start(); printf("after sc_start \n"); return 0; } BTW, I found below slides from GreenSoc which mentioned "async wait", but there is no details or examples. https://workspace.accellera.org/document/dl/10932
  3. Hi Experts, I'm making a "polling-processing" mechanism with systemc. In my original SC env, I have two SC_THREAD in a SC module: one is "polling_thread", which actually acts as a socket server, polls messages from socket client; the other SC_THREAD is "processing_thread", which consumes the received messages; To make "polling_thread" keep active, I simply use some code like: while (1) { wait(10, SC_NS); //polling function to get message from socket //notify processing_thread to process the message } In "processing_thread", I do something like: while (1) { wait(notify_ev_from_polling_thread); //process the message, AND THE LOGIC IS TIME CONSUMING! } And it works well. Now, consider "processing_thread" is the user logic I only care about, for simulation accuracy and deterministic, I only expect "processing_thread" to advance SC simulation time and I can record the behavior by getting SC time, e.g. sc_get_timestamp() For the above purpose, I'm changing "polling_thread" from a SC_THREAD into an external host thread by e.g. pthread. By following the example code of async_request_update() ( Then, there is only one SC_THREAD left in the SC kernel control which is "processing_thread", and looks like the "wait" in "processing_thread" will cause the kernel switch behavior but there is no other thread controlled by kernel. I expected to see "processing_thread" keeps waiting until the external thread notify it, and do such turn-around in the while loop. But in fact, sc_start() directly returned when wait() is called in "processing_thread". I'm wondering, is it my mistake of using something or it's just the systemC mechanism. If so, is there any workaround to my requirement? thanks!
×
×
  • Create New...