betabandido Posted August 14, 2015 Report Posted August 14, 2015 I'm developing a performance simulator for a hardware unit. The hardware runs at 1GHz and therefore I define a clock cycle as: sc_time clk(1, SC_NS) In a specific module requests arrive to the input port, triggering a method that places them into a request buffer. At some point requests that are ready for processing are moved out from the request buffer and placed into another buffer. The overall design would look like: void Receive() { auto x = input.read(); buffer_.push_back(x); process_buffer_event_.notify(clk); } void ProcessBuffer() { for (auto it = begin(buffer_); it != end(buffer_); ++it) { if (process_entry(*it)) { // returns true if a request was successfully moved to the second buffer buffer_.erase(it); break; // only one request can be processed per cycle } } if (!buffer_.empty()) process_buffer_event_.notify(clk); } So, ProcessBuffer will trigger either when a new request arrives or when a request is processed and there are still requests in the buffer. However, there is another case when ProcessBuffer should trigger. In the module there are some resources that can be either in use or idle. Whenever a resource becomes idle, ProcessBuffer must immediately trigger (without waiting until the next cycle): void ReleaseResources() { bool any_released = false; for (auto& r : resources_) any_released = r->try_to_release() || any_released; if (any_released) process_buffer_event_.notify(SC_ZERO_TIME); } However, because of this piece of code, ProcessBuffer now may trigger twice in a given cycle (in the same nanosecond). I suspect it is related to using SC_ZERO_TIME, but I'm not really sure. This creates an issue since now two requests might be moved into the second buffer. I suppose I could guard against executing ProcessBuffer twice by doing something like: void ProcessBuffer() { if (sc_time_stamp() == last_time_processed) return; last_time_processed = sc_time_stamp(); for (auto it = begin(buffer_); it != end(buffer_); ++it) { if (process_entry(*it)) { buffer_.erase(it); break; // only one request can be processed per cycle } } if (!buffer_.empty()) process_buffer_event_.notify(clk); } But I was just wondering whether there is some mechanism in SystemC to properly prevent a method from triggering more than once. Quote
Recommended Posts
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.