From 0af39e1493ea9be5a5fb3ed3ad0dfd5cd0931d27 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 24 Nov 2018 18:20:57 -0600 Subject: [PATCH] arch/: Update all _exit() implementations for all architectures so that they correctly called the scheduler instumentation layer for the new task that runs when the old one exits. This missing instrumentation was confusing the Critical Section Monitor logic with uses this instrumentation to track the state of critical sections. --- arch/arm/src/common/up_exit.c | 15 ++++++++++++--- arch/avr/src/common/up_exit.c | 15 ++++++++++++--- arch/hc/src/common/up_exit.c | 15 ++++++++++++--- arch/mips/src/common/up_exit.c | 15 ++++++++++++--- arch/misoc/src/lm32/lm32_exit.c | 19 ++++++++++++------- arch/or1k/src/common/up_exit.c | 12 ++++++++++-- arch/renesas/src/common/up_exit.c | 17 +++++++++++++---- arch/risc-v/src/common/up_exit.c | 15 ++++++++++++--- arch/sim/src/up_exit.c | 12 ++++++++++-- arch/x86/src/common/up_exit.c | 15 ++++++++++++--- arch/xtensa/src/common/xtensa_exit.c | 15 +++++++++++---- arch/z16/src/common/up_exit.c | 13 +++++++++++-- arch/z80/src/common/up_exit.c | 13 +++++++++++-- 13 files changed, 150 insertions(+), 41 deletions(-) diff --git a/arch/arm/src/common/up_exit.c b/arch/arm/src/common/up_exit.c index d46e1db585c..8f0d2322dc3 100644 --- a/arch/arm/src/common/up_exit.c +++ b/arch/arm/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2007-2009, 201-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 201-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -145,7 +146,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -153,13 +154,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -180,6 +185,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/avr/src/common/up_exit.c b/arch/avr/src/common/up_exit.c index a82c640d69d..c6b8d9354fb 100644 --- a/arch/avr/src/common/up_exit.c +++ b/arch/avr/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/avr/src/common/up_exit.c * - * Copyright (C) 2010, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -144,7 +145,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -152,13 +153,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -179,6 +184,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/hc/src/common/up_exit.c b/arch/hc/src/common/up_exit.c index 9b20fc8abaf..096d2c0a687 100644 --- a/arch/hc/src/common/up_exit.c +++ b/arch/hc/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/hc/src/common/up_exit.c * - * Copyright (C) 2011, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -144,7 +145,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s* tcb; + struct tcb_s* tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -152,13 +153,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -179,6 +184,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/mips/src/common/up_exit.c b/arch/mips/src/common/up_exit.c index 936cf4f11ae..06229bd3931 100644 --- a/arch/mips/src/common/up_exit.c +++ b/arch/mips/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/mips/src/common/up_exit.c * - * Copyright (C) 2011, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,7 +147,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -154,13 +155,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -181,6 +186,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/misoc/src/lm32/lm32_exit.c b/arch/misoc/src/lm32/lm32_exit.c index 8dd96b0a3ac..5995b940298 100644 --- a/arch/misoc/src/lm32/lm32_exit.c +++ b/arch/misoc/src/lm32/lm32_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/misoc/src/lm32/lm32_exit.c * - * Copyright (C) 2010, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * Ramtin Amin * @@ -56,10 +57,6 @@ #include "group/group.h" #include "lm32.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -143,7 +140,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -151,13 +148,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -178,6 +179,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/or1k/src/common/up_exit.c b/arch/or1k/src/common/up_exit.c index eef08e4c541..b7ab42a2467 100644 --- a/arch/or1k/src/common/up_exit.c +++ b/arch/or1k/src/common/up_exit.c @@ -145,7 +145,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -153,13 +153,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -180,6 +184,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/renesas/src/common/up_exit.c b/arch/renesas/src/common/up_exit.c index 81843c5ccc1..9ad643d4fae 100644 --- a/arch/renesas/src/common/up_exit.c +++ b/arch/renesas/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/renesas/src/=common/up_exit.c * - * Copyright (C) 2008-2009, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -144,7 +145,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s* tcb; + struct tcb_s* tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -152,13 +153,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -179,7 +184,11 @@ void _exit(int status) (void)group_addrenv(tcb); #endif - /* Then switch contexts */ + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); } diff --git a/arch/risc-v/src/common/up_exit.c b/arch/risc-v/src/common/up_exit.c index 0f4b56e7ef8..c3fc4307162 100644 --- a/arch/risc-v/src/common/up_exit.c +++ b/arch/risc-v/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/risc-v/src/common/up_exit.c * - * Copyright (C) 2011, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,7 +147,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -154,13 +155,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -181,6 +186,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/sim/src/up_exit.c b/arch/sim/src/up_exit.c index 2a17a8075b8..18cc0339ca2 100644 --- a/arch/sim/src/up_exit.c +++ b/arch/sim/src/up_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/sim/src/up_exit.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -65,10 +65,14 @@ void _exit(int status) { - FAR struct tcb_s *tcb; + FAR struct tcb_s *tcb = this_task(); sinfo("TCB=%p exiting\n", tcb); + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -80,6 +84,10 @@ void _exit(int status) tcb = this_task(); sinfo("New Active Task TCB=%p\n", tcb); + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* The way that we handle signals in the simulation is kind of * a kludge. This would be unsafe in a truly multi-threaded, interrupt * driven environment. diff --git a/arch/x86/src/common/up_exit.c b/arch/x86/src/common/up_exit.c index e5bcd30b465..434d16932a4 100644 --- a/arch/x86/src/common/up_exit.c +++ b/arch/x86/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * common/up_exit.c * - * Copyright (C) 2011, 2013-2014, 2016-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2014, 2016-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -144,7 +145,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s* tcb; + struct tcb_s* tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -152,13 +153,17 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -179,6 +184,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_fullcontextrestore(tcb->xcp.regs); diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c index 6d063c7ce32..a289dc950b7 100644 --- a/arch/xtensa/src/common/xtensa_exit.c +++ b/arch/xtensa/src/common/xtensa_exit.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/xtensa/src/common/xtensa_exit.c * - * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,7 +146,7 @@ static void _xtensa_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - struct tcb_s *tcb; + struct tcb_s *tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -154,17 +154,20 @@ void _exit(int status) (void)enter_critical_section(); - sinfo("TCB=%p exiting\n", this_task()); + sinfo("TCB=%p exiting\n", tcb); #ifdef CONFIG_DUMP_ON_EXIT sinfo("Other tasks:\n"); sched_foreach(_xtensa_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + #if XCHAL_CP_NUM > 0 /* Disable co-processor support for the task that is exit-ing. */ - tcb = this_task(); xtensa_coproc_disable(&tcb->xcp.cpstate, XTENSA_CP_ALLSET); #endif @@ -194,6 +197,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ xtensa_context_restore(tcb->xcp.regs); diff --git a/arch/z16/src/common/up_exit.c b/arch/z16/src/common/up_exit.c index 58b2a542869..807812d55d7 100644 --- a/arch/z16/src/common/up_exit.c +++ b/arch/z16/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/z16/src/common/up_exit.c * - * Copyright (C) 2008-2009, 2013, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2013, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -144,7 +145,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - FAR struct tcb_s* tcb; + FAR struct tcb_s* tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -159,6 +160,10 @@ void _exit(int status) sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -170,6 +175,10 @@ void _exit(int status) tcb = this_task(); sinfo("New Active Task TCB=%p\n", tcb); + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ RESTORE_USERCONTEXT(tcb); diff --git a/arch/z80/src/common/up_exit.c b/arch/z80/src/common/up_exit.c index 71e8ff5193a..044bacb5388 100644 --- a/arch/z80/src/common/up_exit.c +++ b/arch/z80/src/common/up_exit.c @@ -1,7 +1,8 @@ /**************************************************************************** * arch/z80/src/common/up_exit.c * - * Copyright (C) 2007-2009, 2013-2014, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013-2014, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,7 +147,7 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) void _exit(int status) { - FAR struct tcb_s* tcb; + FAR struct tcb_s* tcb = this_task(); /* Make sure that we are in a critical section with local interrupts. * The IRQ state will be restored when the next task is started. @@ -161,6 +162,10 @@ void _exit(int status) sched_foreach(_up_dumponexit, NULL); #endif + /* Update scheduler parameters */ + + sched_suspend_scheduler(tcb); + /* Destroy the task at the head of the ready to run list. */ (void)task_exit(); @@ -182,6 +187,10 @@ void _exit(int status) (void)group_addrenv(tcb); #endif + /* Reset scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ RESTORE_USERCONTEXT(tcb);