This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 8f39ba6ae4 arch: update g_running_tasks when context switch occurred
8f39ba6ae4 is described below
commit 8f39ba6ae48e44bc48a0ef123137ad9e11dfb904
Author: zhangyuan21 <[email protected]>
AuthorDate: Thu Jul 13 17:49:30 2023 +0800
arch: update g_running_tasks when context switch occurred
When supporting high-priority interrupts, updating the
g_running_tasks within a high-priority interrupt may be
cause problems. The g_running_tasks should only be updated
when it is determined that a task context switch has occurred.
Signed-off-by: zhangyuan21 <[email protected]>
---
arch/arm/src/arm/arm_doirq.c | 12 ++++++++++--
arch/arm/src/armv6-m/arm_doirq.c | 8 ++++++++
arch/arm/src/armv7-a/arm_doirq.c | 19 +++++++++----------
arch/arm/src/armv7-m/arm_doirq.c | 8 ++++++++
arch/arm/src/armv7-r/arm_doirq.c | 8 ++++++++
arch/arm/src/armv8-m/arm_doirq.c | 8 ++++++++
arch/arm64/src/common/arm64_doirq.c | 7 +++++++
arch/avr/src/avr/avr_doirq.c | 11 +++++++++++
arch/avr/src/avr32/avr_doirq.c | 10 ++++++++--
arch/ceva/src/common/ceva_doirq.c | 7 +++++++
arch/hc/src/common/hc_doirq.c | 10 ++++++++--
arch/mips/src/mips32/mips_doirq.c | 10 ++++++++--
arch/misoc/src/lm32/lm32_doirq.c | 10 ++++++++--
arch/misoc/src/minerva/minerva_doirq.c | 18 ++++++++++++------
arch/or1k/src/common/or1k_doirq.c | 11 +++++++++++
arch/renesas/src/common/renesas_doirq.c | 10 ++++++++--
arch/risc-v/src/common/riscv_doirq.c | 13 +++++++++----
arch/sim/src/sim/CMakeLists.txt | 1 +
arch/sim/src/sim/sim_doirq.c | 11 +++++++++++
arch/sparc/src/sparc_v8/sparc_v8_doirq.c | 10 ++++++++--
arch/x86/src/qemu/qemu_handlers.c | 10 ++++++++--
arch/x86_64/src/intel64/intel64_handlers.c | 9 +++++++--
arch/xtensa/src/common/xtensa_irqdispatch.c | 9 +++++++--
arch/z16/src/common/z16_doirq.c | 11 +++++++++++
arch/z80/src/common/z80_doirq.c | 17 ++++++++++-------
sched/irq/irq_dispatch.c | 6 ------
26 files changed, 211 insertions(+), 53 deletions(-)
diff --git a/arch/arm/src/arm/arm_doirq.c b/arch/arm/src/arm/arm_doirq.c
index 5386a67f65..59e16a7155 100644
--- a/arch/arm/src/arm/arm_doirq.c
+++ b/arch/arm/src/arm/arm_doirq.c
@@ -32,6 +32,7 @@
#include <nuttx/addrenv.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "arm_internal.h"
@@ -79,7 +80,6 @@ void arm_doirq(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#ifdef CONFIG_ARCH_ADDRENV
/* Check for a context switch. If a context switch occurred, then
* CURRENT_REGS will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -89,6 +89,7 @@ void arm_doirq(int irq, uint32_t *regs)
if (regs != CURRENT_REGS)
{
+#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
* MMU flushed) and set up the address environment for the new
@@ -96,9 +97,16 @@ void arm_doirq(int irq, uint32_t *regs)
*/
addrenv_switch(NULL);
- }
#endif
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+ }
+
/* Set CURRENT_REGS to NULL to indicate that we are no longer in an
* interrupt handler.
*/
diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c
index 977976f043..7abd54145f 100644
--- a/arch/arm/src/armv6-m/arm_doirq.c
+++ b/arch/arm/src/armv6-m/arm_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "arm_internal.h"
@@ -81,6 +82,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
if (regs != CURRENT_REGS)
{
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
restore_critical_section();
regs = (uint32_t *)CURRENT_REGS;
}
diff --git a/arch/arm/src/armv7-a/arm_doirq.c b/arch/arm/src/armv7-a/arm_doirq.c
index 94df1c1224..652de6a233 100644
--- a/arch/arm/src/armv7-a/arm_doirq.c
+++ b/arch/arm/src/armv7-a/arm_doirq.c
@@ -33,6 +33,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "arm_internal.h"
#include "gic.h"
@@ -70,15 +71,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#ifdef CONFIG_ARCH_ADDRENV
- /* Check for a context switch. If a context switch occurred, then
- * CURRENT_REGS will have a different value than it did on entry. If an
- * interrupt level context switch has occurred, then establish the correct
- * address environment before returning from the interrupt.
- */
+ /* Restore the cpu lock */
if (regs != CURRENT_REGS)
{
+#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
* MMU flushed) and set up the address environment for the new
@@ -86,13 +83,15 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
*/
addrenv_switch(NULL);
- }
#endif
- /* Restore the cpu lock */
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
- if (regs != CURRENT_REGS)
- {
restore_critical_section();
regs = (uint32_t *)CURRENT_REGS;
}
diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c
index 358aefad65..564b903142 100644
--- a/arch/arm/src/armv7-m/arm_doirq.c
+++ b/arch/arm/src/armv7-m/arm_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "arm_internal.h"
@@ -81,6 +82,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
if (regs != CURRENT_REGS)
{
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
restore_critical_section();
regs = (uint32_t *)CURRENT_REGS;
}
diff --git a/arch/arm/src/armv7-r/arm_doirq.c b/arch/arm/src/armv7-r/arm_doirq.c
index f7b2d5f881..de5929dc9d 100644
--- a/arch/arm/src/armv7-r/arm_doirq.c
+++ b/arch/arm/src/armv7-r/arm_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "arm_internal.h"
@@ -63,6 +64,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
if (regs != CURRENT_REGS)
{
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
restore_critical_section();
regs = (uint32_t *)CURRENT_REGS;
}
diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c
index 1d10b520c6..d4e9b29d14 100644
--- a/arch/arm/src/armv8-m/arm_doirq.c
+++ b/arch/arm/src/armv8-m/arm_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "arm_internal.h"
#include "exc_return.h"
@@ -82,6 +83,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
if (regs != CURRENT_REGS)
{
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
restore_critical_section();
regs = (uint32_t *)CURRENT_REGS;
}
diff --git a/arch/arm64/src/common/arm64_doirq.c
b/arch/arm64/src/common/arm64_doirq.c
index d0ab7e011a..c7ece5b76d 100644
--- a/arch/arm64/src/common/arm64_doirq.c
+++ b/arch/arm64/src/common/arm64_doirq.c
@@ -92,6 +92,13 @@ uint64_t *arm64_doirq(int irq, uint64_t * regs)
addrenv_switch(NULL);
#endif
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
/* Restore the cpu lock */
restore_critical_section();
diff --git a/arch/avr/src/avr/avr_doirq.c b/arch/avr/src/avr/avr_doirq.c
index 9ec194a34e..ba6519a317 100644
--- a/arch/avr/src/avr/avr_doirq.c
+++ b/arch/avr/src/avr/avr_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "avr_internal.h"
@@ -87,6 +88,16 @@ uint8_t *avr_doirq(uint8_t irq, uint8_t *regs)
* switch occurred during interrupt processing.
*/
+ if (regs != (uint8_t *)g_current_regs)
+ {
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+ }
+
regs = (uint8_t *)g_current_regs; /* Cast removes volatile attribute */
/* Restore the previous value of g_current_regs. NULL would indicate that
diff --git a/arch/avr/src/avr32/avr_doirq.c b/arch/avr/src/avr32/avr_doirq.c
index a32f5cfaef..82475c380f 100644
--- a/arch/avr/src/avr32/avr_doirq.c
+++ b/arch/avr/src/avr32/avr_doirq.c
@@ -32,6 +32,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "avr_internal.h"
@@ -74,7 +75,6 @@ uint32_t *avr_doirq(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry.
* If an interrupt level context switch has occurred, then restore
@@ -99,8 +99,14 @@ uint32_t *avr_doirq(int irq, uint32_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
diff --git a/arch/ceva/src/common/ceva_doirq.c
b/arch/ceva/src/common/ceva_doirq.c
index 532d3c4463..0763410e94 100644
--- a/arch/ceva/src/common/ceva_doirq.c
+++ b/arch/ceva/src/common/ceva_doirq.c
@@ -78,6 +78,13 @@ uint32_t *ceva_doirq(int irq, uint32_t *regs)
if (regs != CURRENT_REGS)
{
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
restore_critical_section();
regs = CURRENT_REGS;
}
diff --git a/arch/hc/src/common/hc_doirq.c b/arch/hc/src/common/hc_doirq.c
index 873fa0265a..086e1fbacd 100644
--- a/arch/hc/src/common/hc_doirq.c
+++ b/arch/hc/src/common/hc_doirq.c
@@ -32,6 +32,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "hc_internal.h"
@@ -74,7 +75,6 @@ uint8_t *hc_doirq(int irq, uint8_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -99,8 +99,14 @@ uint8_t *hc_doirq(int irq, uint8_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
diff --git a/arch/mips/src/mips32/mips_doirq.c
b/arch/mips/src/mips32/mips_doirq.c
index 93f2f578c4..af44bfceac 100644
--- a/arch/mips/src/mips32/mips_doirq.c
+++ b/arch/mips/src/mips32/mips_doirq.c
@@ -32,6 +32,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "mips_internal.h"
@@ -80,7 +81,6 @@ uint32_t *mips_doirq(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -105,8 +105,14 @@ uint32_t *mips_doirq(int irq, uint32_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
diff --git a/arch/misoc/src/lm32/lm32_doirq.c b/arch/misoc/src/lm32/lm32_doirq.c
index 734101157a..697397c94f 100644
--- a/arch/misoc/src/lm32/lm32_doirq.c
+++ b/arch/misoc/src/lm32/lm32_doirq.c
@@ -35,6 +35,7 @@
#include <arch/irq.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "lm32.h"
@@ -65,7 +66,6 @@ uint32_t *lm32_doirq(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -90,8 +90,14 @@ uint32_t *lm32_doirq(int irq, uint32_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
diff --git a/arch/misoc/src/minerva/minerva_doirq.c
b/arch/misoc/src/minerva/minerva_doirq.c
index d7baca8445..7fcccde163 100644
--- a/arch/misoc/src/minerva/minerva_doirq.c
+++ b/arch/misoc/src/minerva/minerva_doirq.c
@@ -35,6 +35,7 @@
#include <arch/irq.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "minerva.h"
@@ -64,7 +65,6 @@ uint32_t *minerva_doirq(int irq, uint32_t * regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -74,13 +74,13 @@ uint32_t *minerva_doirq(int irq, uint32_t * regs)
if (regs != g_current_regs)
{
-# ifdef CONFIG_ARCH_FPU
+#ifdef CONFIG_ARCH_FPU
/* Restore floating point registers */
up_restorefpu((uint32_t *) g_current_regs);
-# endif
+#endif
-# ifdef CONFIG_ARCH_ADDRENV
+#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously running
* task is closed down gracefully (data caches dump, MMU flushed) and
* set up the address environment for the new thread at the head of
@@ -88,10 +88,16 @@ uint32_t *minerva_doirq(int irq, uint32_t * regs)
*/
addrenv_switch(NULL);
-# endif
- }
#endif
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+ }
+
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
* from the input regs, then the lower level will know that a context
diff --git a/arch/or1k/src/common/or1k_doirq.c
b/arch/or1k/src/common/or1k_doirq.c
index 2464e07b74..00c29714de 100644
--- a/arch/or1k/src/common/or1k_doirq.c
+++ b/arch/or1k/src/common/or1k_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "or1k_internal.h"
@@ -69,6 +70,16 @@ uint32_t *or1k_doirq(int irq, uint32_t *regs)
* switch occurred during interrupt processing.
*/
+ if (regs != (uint32_t *)CURRENT_REGS)
+ {
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+ }
+
regs = (uint32_t *)CURRENT_REGS;
/* Restore the previous value of CURRENT_REGS. NULL would indicate that
diff --git a/arch/renesas/src/common/renesas_doirq.c
b/arch/renesas/src/common/renesas_doirq.c
index 5fe85b0530..e5ca50fb37 100644
--- a/arch/renesas/src/common/renesas_doirq.c
+++ b/arch/renesas/src/common/renesas_doirq.c
@@ -31,6 +31,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "renesas_internal.h"
#include "group/group.h"
@@ -77,7 +78,6 @@ uint32_t *renesas_doirq(int irq, uint32_t * regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry.
* If an interrupt level context switch has occurred, then restore the
@@ -102,9 +102,15 @@ uint32_t *renesas_doirq(int irq, uint32_t * regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* Get the current value of regs... it may have changed because
* of a context switch performed during interrupt processing.
*/
diff --git a/arch/risc-v/src/common/riscv_doirq.c
b/arch/risc-v/src/common/riscv_doirq.c
index a1faf2aa0c..953e5bad33 100644
--- a/arch/risc-v/src/common/riscv_doirq.c
+++ b/arch/risc-v/src/common/riscv_doirq.c
@@ -32,6 +32,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "riscv_internal.h"
@@ -89,9 +90,9 @@ uintptr_t *riscv_doirq(int irq, uintptr_t *regs)
* returning from the interrupt.
*/
-#ifdef CONFIG_ARCH_ADDRENV
if (regs != CURRENT_REGS)
{
+#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
* running task is closed down gracefully (data caches dump,
* MMU flushed) and set up the address environment for the new
@@ -99,11 +100,15 @@ uintptr_t *riscv_doirq(int irq, uintptr_t *regs)
*/
addrenv_switch(NULL);
- }
#endif
- if (regs != CURRENT_REGS)
- {
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+
/* Restore the cpu lock */
restore_critical_section();
diff --git a/arch/sim/src/sim/CMakeLists.txt b/arch/sim/src/sim/CMakeLists.txt
index 55456fbe06..670fde3404 100644
--- a/arch/sim/src/sim/CMakeLists.txt
+++ b/arch/sim/src/sim/CMakeLists.txt
@@ -234,6 +234,7 @@ endif()
target_include_directories(nuttx PRIVATE ${CMAKE_BINARY_DIR}/include/nuttx)
target_include_directories(nuttx PRIVATE ${CMAKE_CURRENT_LIST_DIR})
+target_include_directories(sim_head PUBLIC ${NUTTX_DIR}/sched)
target_sources(sim_head PUBLIC sim_head.c sim_doirq.c)
target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/sim/src/sim/sim_doirq.c b/arch/sim/src/sim/sim_doirq.c
index 4cf7c1f68c..81ecb60df2 100644
--- a/arch/sim/src/sim/sim_doirq.c
+++ b/arch/sim/src/sim/sim_doirq.c
@@ -26,6 +26,7 @@
#include <stdbool.h>
#include <nuttx/arch.h>
+#include <sched/sched.h>
#include "sim_internal.h"
@@ -64,6 +65,16 @@ void *sim_doirq(int irq, void *context)
* context switch occurred during interrupt processing.
*/
+ if (regs != CURRENT_REGS)
+ {
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+ }
+
regs = (void *)CURRENT_REGS;
/* Restore the previous value of CURRENT_REGS. NULL would indicate
diff --git a/arch/sparc/src/sparc_v8/sparc_v8_doirq.c
b/arch/sparc/src/sparc_v8/sparc_v8_doirq.c
index a77e855b10..d434e3c7e0 100644
--- a/arch/sparc/src/sparc_v8/sparc_v8_doirq.c
+++ b/arch/sparc/src/sparc_v8/sparc_v8_doirq.c
@@ -32,6 +32,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "sparc_internal.h"
@@ -75,7 +76,6 @@ uint32_t *sparc_doirq(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* CURRENT_REGS will have a different value than it did on entry.
* If an interrupt level context switch has occurred, then restore
@@ -100,8 +100,14 @@ uint32_t *sparc_doirq(int irq, uint32_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* CURRENT_REGS may have change value. If we return any value different
diff --git a/arch/x86/src/qemu/qemu_handlers.c
b/arch/x86/src/qemu/qemu_handlers.c
index 7ac7465350..6792bfee09 100644
--- a/arch/x86/src/qemu/qemu_handlers.c
+++ b/arch/x86/src/qemu/qemu_handlers.c
@@ -30,6 +30,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/io.h>
+#include <sched/sched.h>
#include "x86_internal.h"
@@ -90,7 +91,6 @@ static uint32_t *common_handler(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -115,8 +115,14 @@ static uint32_t *common_handler(int irq, uint32_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
diff --git a/arch/x86_64/src/intel64/intel64_handlers.c
b/arch/x86_64/src/intel64/intel64_handlers.c
index eca17611dc..3c9b175d22 100644
--- a/arch/x86_64/src/intel64/intel64_handlers.c
+++ b/arch/x86_64/src/intel64/intel64_handlers.c
@@ -77,7 +77,6 @@ static uint64_t *common_handler(int irq, uint64_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_FPU) || defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* g_current_regs will have a different value than it did on entry. If an
* interrupt level context switch has occurred, then restore the floating
@@ -102,8 +101,14 @@ static uint64_t *common_handler(int irq, uint64_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* If a context switch occurred while processing the interrupt then
* g_current_regs may have change value. If we return any value different
diff --git a/arch/xtensa/src/common/xtensa_irqdispatch.c
b/arch/xtensa/src/common/xtensa_irqdispatch.c
index d9193f47db..17457147e0 100644
--- a/arch/xtensa/src/common/xtensa_irqdispatch.c
+++ b/arch/xtensa/src/common/xtensa_irqdispatch.c
@@ -66,7 +66,6 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs)
irq_dispatch(irq, regs);
-#if defined(CONFIG_ARCH_ADDRENV)
/* Check for a context switch. If a context switch occurred, then
* CURRENT_REGS will have a different value than it did on entry.
*/
@@ -82,8 +81,14 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs)
addrenv_switch(NULL);
#endif
+
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
}
-#endif
/* Restore the cpu lock */
diff --git a/arch/z16/src/common/z16_doirq.c b/arch/z16/src/common/z16_doirq.c
index 91f9f62308..b9c7841d1b 100644
--- a/arch/z16/src/common/z16_doirq.c
+++ b/arch/z16/src/common/z16_doirq.c
@@ -30,6 +30,7 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
+#include <sched/sched.h>
#include "chip.h"
#include "z16_internal.h"
@@ -84,6 +85,16 @@ FAR chipreg_t *z16_doirq(int irq, FAR chipreg_t *regs)
irq_dispatch(irq, regs);
+ if (regs != g_current_regs)
+ {
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
+
+ g_running_tasks[this_cpu()] = this_task();
+ }
+
/* Restore the previous value of g_current_regs. NULL would indicate
* that we are no longer in an interrupt handler. It will be non-NULL
* if we are returning from a nested interrupt.
diff --git a/arch/z80/src/common/z80_doirq.c b/arch/z80/src/common/z80_doirq.c
index 106993f359..81bbc2b51b 100644
--- a/arch/z80/src/common/z80_doirq.c
+++ b/arch/z80/src/common/z80_doirq.c
@@ -33,6 +33,7 @@
#include <nuttx/board.h>
#include <arch/irq.h>
+#include <sched/sched.h>
#include "chip/switch.h"
#include "z80_internal.h"
@@ -69,13 +70,13 @@ FAR chipreg_t *z80_doirq(uint8_t irq, FAR chipreg_t *regs)
irq_dispatch(irq, regs);
-#ifdef CONFIG_ARCH_ADDRENV
/* If a context switch occurred, 'newregs' will hold the new context */
newregs = IRQ_STATE();
if (newregs != regs)
{
+#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
* running task is closed down gracefully and set up the
* address environment for the new thread at the head of the
@@ -83,15 +84,17 @@ FAR chipreg_t *z80_doirq(uint8_t irq, FAR chipreg_t *regs)
*/
addrenv_switch(NULL);
- }
+#endif
- regs = newregs;
+ /* Record the new "running" task when context switch occurred.
+ * g_running_tasks[] is only used by assertion logic for reporting
+ * crashes.
+ */
-#else
- /* If a context switch occurred, 'regs' will hold the new context */
+ g_running_tasks[this_cpu()] = this_task();
+ }
- regs = IRQ_STATE();
-#endif
+ regs = newregs;
/* Indicate that we are no longer in interrupt processing logic */
diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c
index baa314deb7..be9f17607d 100644
--- a/sched/irq/irq_dispatch.c
+++ b/sched/irq/irq_dispatch.c
@@ -182,10 +182,4 @@ void irq_dispatch(int irq, FAR void *context)
kmm_checkcorruption();
}
#endif
-
- /* Record the new "running" task. g_running_tasks[] is only used by
- * assertion logic for reporting crashes.
- */
-
- g_running_tasks[this_cpu()] = this_task();
}