question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clock event put, get, and wait

See original GitHub issue

I found that my simulation was hanging when I called queue.put on a queue with maxlen=1. I also hung awaiting Event.wait()

I’ve fixed the problem by creating versions of the queue and event that loop on a clock-based event so that control goes back to the simulator. Now you pass uvm_root().run_test() the clock as well as the test name. This gets stored in ConfigDB() and can be used anywhere in the testbench.

Clock-based blocking

Here is the event:

class UVMEvent(Event):

    def __init__(self, name, clock):
        super().__init__(name=name)
        self.trigger = Timer(10, units="step")
    
    async def wait(self):
        while True:
            await self.trigger
            if self.is_set:
                return self.fired
            else:
                continue

And here are the put and get:

    async def put(self, item):
        while True:
            await self.trigger
            try:
                self.put_nowait(item)
                break
            except QueueFull:
                continue        

    async def get(self):
        while True:
            await self.trigger
            try:
                item =  self.get_nowait()
                print("GOT:", item)
                return item
            except QueueEmpty:
                continue

Do you think this a generalizable feature in cocotb?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
marlonjamescommented, Aug 9, 2021

There is no inherit problem with a task calling await q.put() on a Queue with maxlen = 1. The calling task will suspend until there is room in q, which can only happen if another task calls await q.get() or q.get_nowait().

I don’t see value in adding extra Timer triggers or waiting on clock edges inside these coroutines, as they are already waiting on some Event to be triggered. If your simulation is not progressing, there is some other underlying issue.

1reaction
eric-wiesercommented, Aug 9, 2021

I think there’s a misunderstanding here. Control is returned to the simulator simply when there are no coroutines left to run, right? The scheduler loop is roughly:

  • Simulator triggers a “real” event and wakes up some coroutines
  • Those coroutines set events and may wake up other coroutines
  • Coroutines go to sleep again by awaiting
  • Eventually the last coroutine awaits and control returns to the simulator

The only thing that makes “real” triggers special is that they start the chain of events. Any type of trigger can end a chain of events.

If you end up in a situation where the only events waiting to fire are “virtual”, your testbench has a deadlock and is itself the problem; no change to your dut can ever wake it.

If you end up in a situation where your coroutines wake each other up forever, then your testbench has an infinite loop in which no time passes and is itself the problem; no simulator events will ever be able to fire.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pygame.time — pygame v2.1.4 documentation
repeatedly create an event on the event queue. pygame.time.Clock ... Most platforms have a limited time resolution of around 10 milliseconds.
Read more >
How to wait some time in pygame? - Stack Overflow
If you just wait for some time, you can use pygame.time.wait or ... while run: for event in pygame.event.get(): if event.type == pygame....
Read more >
Descriptions of Wait Events - Database - Oracle Help Center
A session has issued a statement ALTER SYSTEM SET DISPATCHER = string and is waiting for the dispatchers to get started. Wait Time:...
Read more >
Define a Wait for Time or Event for an Automation Process ...
Wait for Time: Step that waits for a defined amount of time before the process continues to the next step. Wait from: Select...
Read more >
How to use Wait On and Wait Until in VHDL - VHDLwhiz
We learned that signals have a broader scope than variables, ... The Wait Until statement will pause until an event causes the condition...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found