zephyr/include
Andy Ross 15c400774e kernel: Rework SMP irq_lock() compatibility layer
This was wrong in two ways, one subtle and one awful.

The subtle problem was that the IRQ lock isn't actually globally
recursive, it gets reset when you context switch (i.e. a _Swap()
implicitly releases and reacquires it).  So the recursive count I was
keeping needs to be per-thread or else we risk deadlock any time we
swap away from a thread holding the lock.

And because part of my brain apparently knew this, there was an
"optimization" in the code that tested the current count vs. zero
outside the lock, on the argument that if it was non-zero we must
already hold the lock.  Which would be true of a per-thread counter,
but NOT a global one: the other CPU may be holding that lock, and this
test will tell you *you* do.  The upshot is that a recursive
irq_lock() would almost always SUCCEED INCORRECTLY when there was lock
contention.  That this didn't break more things is amazing to me.

The rework is actually simpler than the original, thankfully.  Though
there are some further subtleties:

* The lock state implied by irq_lock() allows the lock to be
  implicitly released on context switch (i.e. you can _Swap() with the
  lock held at a recursion level higher than 1, which needs to allow
  other processes to run).  So return paths into threads from _Swap()
  and interrupt/exception exit need to check and restore the global
  lock state, spinning as needed.

* The idle loop design specifies a k_cpu_idle() function that is on
  common architectures expected to enable interrupts (for obvious
  reasons), but there is no place to put non-arch code to wire it into
  the global lock accounting.  So on SMP, even CPU0 needs to use the
  "dumb" spinning idle loop.

Finally this patch contains a simple bugfix too, found by inspection:
the interrupt return code used when CONFIG_SWITCH is enabled wasn't
correctly setting the active flag on the threads, opening up the
potential for a race that might result in a thread being scheduled on
two CPUs simultaneously.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-05-02 10:00:17 -07:00
..
arch POSIX arch: Fix linker -T warning 2018-05-02 10:19:09 -04:00
bluetooth Bluetooth: Mesh: Remove unnecessary #ifdefs from header file 2018-05-02 15:45:16 +01:00
crypto
debug debug: remove DEBUG_INFO option 2018-02-12 13:58:28 -08:00
dfu subsys: dfu: boot: Remove unused ver query code. 2018-02-21 18:53:42 -05:00
display doc: APIs: group display drivers 2017-11-17 17:14:18 -05:00
drivers drivers/spi: Switch Intel driver to new SPI API 2018-04-04 19:02:35 +02:00
dt-bindings dts: gpio: create gpio dt-bingings and inlude in stm32 dtsi files 2018-04-13 13:36:45 -05:00
fs subsys: fs: Add Virtual File system Switch (VFS) support 2018-03-10 21:38:04 -05:00
linker userspace: add support for dynamic kernel objects 2018-04-24 12:27:54 -07:00
logging subsys: kernel_event_logger: change kernel event values 2018-02-23 07:29:29 -05:00
mgmt mgmt: Bluetooth transport for SMP (mcumgr). 2018-02-20 22:07:52 +01:00
misc slist: abstract node and list implementation 2018-04-30 13:15:51 -04:00
net net: Implement VLAN priority to packet priority conversion 2018-05-02 13:40:32 +03:00
posix lib: posix: Move posix layer from 'kernel' to 'lib' 2018-04-05 16:43:05 -04:00
random subsys: Add random subsystem 2017-11-01 08:26:29 -04:00
settings susbsys: settings: fix coverity issues 2018-04-25 22:25:32 +05:30
shell subsys: mgmt: Shell transport for SMP (mcumgr). 2018-02-20 22:07:52 +01:00
toolchain xtensa: provide XCC compiler support for Xtensa 2018-05-01 16:46:41 -04:00
usb include: usb: add USB DFU class header 2018-04-30 17:42:40 -04:00
zephyr
adc.h drivers: adc: add system call handlers 2017-10-30 13:20:19 -07:00
aio_comparator.h drivers: aio_comparator: add system calls 2017-10-30 13:20:19 -07:00
atomic.h
base64.h lib: base64: Add statement of changes 2018-03-23 13:54:48 +01:00
cache.h
clock_control.h
console.h doc: fix misspellings in include (API docs) 2017-08-10 12:22:19 -04:00
counter.h doc: add missing API content 2017-12-01 08:58:56 -05:00
crc8.h crc: make crc8_ccitt() match the other CRC functions. 2018-03-10 21:49:07 -05:00
crc16.h include: improve compatibility with C++ apps. 2018-04-09 23:21:52 -04:00
device.h include: improve compatibility with C++ apps. 2018-04-09 23:21:52 -04:00
disk_access.h disk: delete the GET_DISK_SIZE IOCTL. 2018-01-31 09:14:40 -05:00
dma.h dma: Fix building when system calls are disabled 2018-02-13 10:32:41 -05:00
entropy.h drivers: Rename random to entropy 2017-11-01 08:26:29 -04:00
eth.h
fcb.h subsys: fs: fcb: remove f_area_id from fcb structure 2018-02-07 09:51:26 -05:00
flash_map.h subsys: storage: flash_map: Fix warning 2018-02-14 14:36:52 -05:00
flash.h flash: minor documentation improvements. 2017-11-28 12:25:19 -05:00
fs.h doc: misspellings in public API doxygen comments 2018-04-05 19:16:24 -04:00
gpio.h dts: gpio: create gpio dt-bingings and inlude in stm32 dtsi files 2018-04-13 13:36:45 -05:00
i2c.h drivers: i2c: add system call handlers 2017-10-30 13:20:19 -07:00
i2s.h drivers: i2s: introduce CAVS I2S 2018-05-01 16:46:41 -04:00
init.h init.h: Fix english in comment 2018-03-26 13:17:39 -04:00
ipm.h drivers: ipm: add system calls 2017-10-30 13:20:19 -07:00
irq_nextlevel.h drivers: interrupts: introduce CAVS interrupt logic 2018-05-01 16:46:41 -04:00
irq_offload.h
irq.h kernel: Make irq_{un}lock() APIs into a global spinlock in SMP mode 2018-02-16 10:44:29 -05:00
json.h lib: json: Efficiently pack field name, offset, alignment, type 2018-05-01 15:44:09 -04:00
kernel_version.h kernel: version: parenthesize macro value 2018-01-04 13:29:03 -05:00
kernel.h kernel: Rework SMP irq_lock() compatibility layer 2018-05-02 10:00:17 -07:00
led_strip.h include: improve compatibility with C++ apps. 2018-04-09 23:21:52 -04:00
led.h drivers: led: Add public API for LED drivers 2018-04-27 10:46:53 -05:00
pinmux.h pinmux: add two more entries to the function enum. 2018-02-05 06:31:35 -08:00
power.h
pwm.h drivers: pwm: add system call handlers 2017-10-30 13:20:19 -07:00
ring_buffer.h ring_buffer: remove broken object_tracing support 2018-01-18 17:44:38 -05:00
rtc.h drivers: rtc: add system calls 2017-10-30 13:20:19 -07:00
sensor.h sensors: Add separation between ambient and die temperature 2018-04-03 22:29:11 -04:00
shared_irq.h
spi.h include: improve compatibility with C++ apps. 2018-04-09 23:21:52 -04:00
spinlock.h kernel: Simple spinlock API 2018-02-16 10:44:29 -05:00
stats.h doc: misspellings in public API doxygen comments 2018-04-05 19:16:24 -04:00
sw_isr_table.h sw_isr_table.h: fix includes 2017-10-27 16:08:54 -04:00
sys_clock.h
sys_io.h sys_io.h: don't pull in kernel.h 2017-11-02 13:25:01 -07:00
syscall.h license: fix spdx identifier in a few files 2018-04-12 15:19:51 -04:00
toolchain.h
uart.h include: improve compatibility with C++ apps. 2018-04-09 23:21:52 -04:00
watchdog.h include: improve compatibility with C++ apps. 2018-04-09 23:21:52 -04:00
zephyr.h