diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-06 14:53:04 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-08-13 10:46:43 +0200 |
commit | 94b264aca5685aeba5fb6babc097d64b78478a11 (patch) | |
tree | 2bdf35e281171806dbfa188ce22948c5402ae285 /commands/Kconfig | |
parent | f9f67c7827c90d9f54d392673e459679f7ce3bd6 (diff) | |
download | barebox-94b264aca5685aeba5fb6babc097d64b78478a11.tar.gz barebox-94b264aca5685aeba5fb6babc097d64b78478a11.tar.xz |
Introduce slices
slices, the barebox idea of locking
barebox has pollers which execute code in the background whenever one of the
delay functions (udelay, mdelay, ...) or is_timeout() are called. This
introduces resource problems when some device triggers a poller by calling
a delay function and then the poller code calls into the same device again.
As an example consider a I2C GPIO expander which drives a LED which shall
be used as a heartbeat LED:
poller -> LED on/off -> GPIO high/low -> I2C transfer
The I2C controller has a timeout loop using is_timeout() and thus can trigger
a poller run. With this the following can happen during an unrelated I2C
transfer:
I2C transfer -> is_timeout() -> poller -> LED on/off -> GPIO high/low -> I2C transfer
We end up with issuing an I2C transfer during another I2C transfer and
things go downhill.
Due to the lack of interrupts we can't do real locking in barebox. We use
a mechanism called slices instead. A slice describes a resource to which
other slices can be attached. Whenever a slice is needed it must be acquired.
Acquiring a slice never fails, it just increases the acquired counter of
the slice and its dependent slices. when a slice shall be used inside a
poller it must first be tested if the slice is already in use. If it is,
we can't do the operation on the slice now and must return and hope that
we have more luck in the next poller call.
slices can be attached other slices as dependencies. In the example above
LED driver would add a dependency to the GPIO controller and the GPIO driver
would add a dependency to the I2C bus:
GPIO driver probe:
slice_add(&gpio->slice, i2c_device_slice(i2cdev));
LED driver probe:
slice_add(&led->slice, gpio_slice(gpio));
The GPIO code would call slice_acquire(&gpio->slice) before doing any
operation on the GPIO chip providing this GPIO, likewise the I2C core
would call slice_acquire(&i2cbus->slice) before doing an operation on
this I2C bus.
The heartbeat poller code would call slice_acquired(led_slice(led)) and
only continue when the slice is not acquired.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/Kconfig')
-rw-r--r-- | commands/Kconfig | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig index 3789f33c3b..608643fceb 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -253,6 +253,14 @@ config CMD_POLLER is_timeout() or one of the various delay functions. The poller command prints informations about registered pollers. +config CMD_SLICE + tristate + prompt "slice" + help + slices are a way to protect resources from being accessed by pollers. The slice + command can be used to print informations about slices and also to manipulate + them on the command line for debugging purposes. + # end Information commands endmenu |