Skip to content

Conversation

@niaow
Copy link
Member

@niaow niaow commented Mar 29, 2020

This PR is based off of #1006 and #1002. As of now, the queue is not yet exposed to anything. I will add that in a bit.

@niaow niaow marked this pull request as ready for review March 29, 2020 22:12
@niaow niaow added this to the v0.14 milestone Apr 8, 2020
Comment on lines +91 to +92
// poll checks for any expired timers and schedules them.
// This must be called periodically by the scheduler.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a possible problem. Why is there a need for polling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have 2 kinds of platforms in TinyGo:

  1. microcontrollers - where all events come from interrupts
  2. "hosted" platforms (wasm, embedded linux, etc.) - where we need to periodically poll for events

We could use 2 different scheduler implementations, one interrupt based and one polling, but that would make some stuff more complicated and result in 2 different sets of behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kinds of events need to be polled for on hosted platforms? Epoll?
I may need to look more into it to understand the problem better.

@aykevl
Copy link
Member

aykevl commented May 23, 2020

I looked at the code, but I'm not fully grasping what it is doing. I looked at #1002 (which is pretty clear), this PR, and #1010 but I miss the big picture. Reading through the code I see a lot of newly added code and some changed code but somehow I'm missing the purpose. Questions I get are:

  • Is the legacy scheduler intended to be removed eventually? Because I suspect it will be fine for WebAssembly for example. If not, I don't think it should be called 'legacy'.
  • A function like ticks has been moved, but I'm not sure why? It certainly distracts from the actual changes.
  • I see a lot of references to polling. Is there really any polling going on? Why? Because generally you'd want to avoid polling and I can't think of a reason why you would need it.
  • There is a whole new timer controller that I'm wondering about.

So can you maybe give a high level overview of what this particular PR is doing, why things are done the way they are, and what's up with all the polling? Also, how this will eventually result in things like interrupt-safe conditional variables?

@aykevl
Copy link
Member

aykevl commented May 23, 2020

I'm a bit late here. But still. Is there a reason why you went for this almost entirely lock-free approach? I do not think it's a problem to disable interrupts for a short time when working with the runqueue.

@niaow
Copy link
Member Author

niaow commented May 23, 2020

Is the legacy scheduler intended to be removed eventually? Because I suspect it will be fine for WebAssembly for example. If not, I don't think it should be called 'legacy'.

It is legacy. WebAssembly has somewhat different semantics - we never need to re-check the timer, and all of the time queueing can be done at the end.

A function like ticks has been moved, but I'm not sure why? It certainly distracts from the actual changes.

Ticks was not moved. The code before it was deleted, and new code was put there, and git decided that was how it wanted the diff to appear.

I see a lot of references to polling. Is there really any polling going on? Why? Because generally you'd want to avoid polling and I can't think of a reason why you would need it.

On hosted systems, there is no way around polling. On microcontrollers, we need to copy awoken tasks to the runqueue (although we may want to look into more frequent polling there, since it is cheap).

There is a whole new timer controller that I'm wondering about.

I think the timer system still currently makes sense to leave separate, since we have to constantly reorder and reschedule things. The timer controller mechanism is designed to be a simplified version of working with interrupt timers, and is supposed to become the standard mechanism for implementing runtime timers.

@niaow
Copy link
Member Author

niaow commented May 23, 2020

Also, how this will eventually result in things like interrupt-safe conditional variables?

The interrupt-safe condition variables push awoken tasks onto the interrupt queue. This change feeds those tasks into the runqueue and lets them be resumed.

I'm a bit late here. But still. Is there a reason why you went for this almost entirely lock-free approach? I do not think it's a problem to disable interrupts for a short time when working with the runqueue.

I guess we could do this. I was just worried that we could potentially be doing a lot of manipulations to the runqueue, and this would mean that a large total time would end up spent with interrupts off. If you want, I can redesign this a bit to instead disable interrupts.

@niaow
Copy link
Member Author

niaow commented Jun 5, 2020

Closing in favor of #1142

@niaow niaow closed this Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants