tinyos / tinyos-main

Main development repository for TinyOS (an OS for embedded, wireless devices).
1.41k stars 518 forks source link

Document Arbiter usage from SoftwareInit. Immediate only. #215

Open cire831 opened 11 years ago

cire831 commented 11 years ago

Using non-immediate arbitration from SoftwareInit (the one called from boot up) is problematic.

Some code (for example the cc2420x driver) uses arbitration via Resource.request to access arbitrated resources (ie. the SPI bus) during initilization. This gets called from SoftwareInit on the way up.

Resource.request uses an Arbiter which uses data structures (typically FIFO) that also get initilized by SoftwareInit. But the order of initilization isn't specified so this initilization may happen after users of the arbiters try to access these structures.

It sort of works even unitiliized but that is just because not because of reasonable design.

This should be fixed. One reasonable way is to introduce a first level initilization, say SystemInit with the same symantics as Init. Critical system code would use this to initialize key system components prior to use by other components.

Another approach would be to force the initilization code to use Resource.immediateRequest instead. Which doesn't use the data structures that need to be initilized but this approach makes a boat load of assumption about what works and what doesn't. A better approach is given above because it is structured to initilize explicitly those components that are dependencies of later components.

phil-levis commented 11 years ago

This has come up before. There are four solutions I know of:

1) Use dependent, ordered initialization like Boomerang did. The challenge is that it depends on unique() resolution order, which is undefined in the nesC compiler. So changes to nesC would break it.

2) Use more levels of init. E.g., HardwareInit, SoftwareInit, PeripheralInit, where the first two relate to the MCU only.

3) Do not use split-phase calls in Init. Request resources immediately.

4) Initialize peripherals in Boot.booted().

Of these, the conclusion was that 3) is the best answer. Since Init is blocking, there is no parallelism and serialized execution is expected. Therefore there shouldn't be split-phase calls. They end up moving initialization outside of Init. For example, adding another Init as in approach 2) doesn't help if the new, later Init is called before the resource is granted. You'd end up needing some kind of barrier on resource grants.

Phil


Philip Levis Associate Professor Computer Science and Electrical Engineering Stanford University http://csl.stanford.edu/~pal

On Jul 8, 2013, at 5:41 PM, Eric Decker notifications@github.com wrote:

Using non-immediate arbitration from SoftwareInit (the one called from boot up) is problematic.

Some code (for example the cc2420x driver) uses arbitration via Resource.request to access arbitrated resources (ie. the SPI bus) during initilization. This gets called from SoftwareInit on the way up.

Resource.request uses an Arbiter which uses data structures (typically FIFO) that also get initilized by SoftwareInit. But the order of initilization isn't specified so this initilization may happen after users of the arbiters try to access these structures.

It sort of works even unitiliized but that is just because not because of reasonable design.

This should be fixed. One reasonable way is to introduce a first level initilization, say SystemInit with the same symantics as Init. Critical system code would use this to initialize key system components prior to use by other components.

— Reply to this email directly or view it on GitHub.

cire831 commented 11 years ago

3 above (using immediate resource requests) is the best solution.

This should get added to the Design/Implementation notes section of the Wiki

andrasbiro commented 11 years ago

This also means that every bus driver must provide blocking interfaces. There is no official blocking I2C interface right now.

cire831 commented 11 years ago

We should put the arbitration above the drivers.

although it makes sense to seperate out the buses and provide an arbiter for the bus.

The newer chips have enough ports so that typically we don't need to arbitrate.

On Mon, Sep 16, 2013 at 9:39 AM, András Bíró notifications@github.comwrote:

This also means that every bus driver must provide blocking interfaces. There is no official blocking I2C interface right now.

— Reply to this email directly or view it on GitHubhttps://github.com/tinyos/tinyos-main/issues/215#issuecomment-24524504 .

Eric B. Decker Senior (over 50 :-) Researcher

andrasbiro commented 11 years ago

It's not exactly an arbitration problem, but it's related to this issue: If one shouldn't call a split-phase command from Init (which makes sense, since it should return a proper error_t), than one must do every initialization in blocking code. This is not possible with i2c chips, since there's no blocking i2c interfaces in tos/interfaces. (I'm planning to do this on AVRs for a while, until that, I just want to warn other MCU driver developers that it's missing)

cire831 commented 11 years ago

The issue with arbitration from Init code is ordering, which isn't worth the pain of dealing with.

So the resultant is one should not call split phase arbitration code from Init code (doing so would rely on the underlying arbritation init being done which you can't rely on).

I don't understand what you mean by blocking code in this context.

On Mon, Sep 16, 2013 at 10:48 AM, András Bíró notifications@github.comwrote:

It's not exactly an arbitration problem, but it's related to this issue: If one shouldn't call a split-phase command from Init (which makes sense, since it should return a proper error_t), than one must do every initialization in blocking code. This is not possible with i2c chips, since there's no blocking i2c interfaces in tos/interfaces. (I'm planning to do this on AVRs for a while, until that, I just want to warn other MCU driver developers that it's missing)

— Reply to this email directly or view it on GitHubhttps://github.com/tinyos/tinyos-main/issues/215#issuecomment-24529616 .

Eric B. Decker Senior (over 50 :-) Researcher