mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 04:16:35 +08:00
sched/sched: SMP: Fix this_task() to be an atomic operation. In the previous implementation, this_task() was defined in sched.h by using just a macro current_task(this_cpu()). However, I found that this is not atomic and actually sometimes switching CPU happened in executing the macro when we tested audio steaming plus executing commands via telnet. This change resolves this issue by implementing atomic this_task()in sched_thistask.c which is newly introduced.
This commit is contained in:
committed by
Gregory Nutt
parent
31278bc163
commit
c8a372702a
@@ -247,6 +247,7 @@ config ARCH_CHIP_SAM4CM
|
||||
default n
|
||||
select ARCH_HAVE_MULTICPU
|
||||
select ARCH_HAVE_TICKLESS
|
||||
select ARCH_GLOBAL_IRQDISABLE
|
||||
|
||||
config ARCH_CHIP_SAM4L
|
||||
bool
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -100,6 +100,7 @@ endif
|
||||
|
||||
ifeq ($(CONFIG_SMP),y)
|
||||
CSRCS += sched_tasklistlock.c
|
||||
CSRCS += sched_thistask.c
|
||||
endif
|
||||
|
||||
# Include sched build support
|
||||
|
||||
+4
-1
@@ -72,6 +72,7 @@
|
||||
|
||||
/* These are macros to access the current CPU and the current task on a CPU.
|
||||
* These macros are intended to support a future SMP implementation.
|
||||
* NOTE: this_task() for SMP is implemented in sched_thistask.c
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
@@ -80,8 +81,8 @@
|
||||
#else
|
||||
# define current_task(cpu) ((FAR struct tcb_s *)g_readytorun.head)
|
||||
# define this_cpu() (0)
|
||||
# define this_task() (current_task(this_cpu()))
|
||||
#endif
|
||||
#define this_task() (current_task(this_cpu()))
|
||||
|
||||
/* List attribute flags */
|
||||
|
||||
@@ -427,6 +428,8 @@ void sched_sporadic_lowpriority(FAR struct tcb_s *tcb);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
FAR struct tcb_s *this_task(void);
|
||||
|
||||
int sched_cpu_select(cpu_set_t affinity);
|
||||
int sched_cpu_pause(FAR struct tcb_s *tcb);
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
* sched/sched/sched_thistask.c
|
||||
*
|
||||
* Copyright (C) 2018 Sony Corporation. All rights reserved.
|
||||
* Author: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
|
||||
* Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#include "sched/sched.h"
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: this_task
|
||||
*
|
||||
* Description:
|
||||
* The functions will safely obtain the TCB that is currently running
|
||||
* on the current CPU. In SMP, this must be done by disabling local
|
||||
* interrupts to avoid CPU switching during access to current_task()
|
||||
*
|
||||
* Return Value:
|
||||
* the TCB that is currently running on the current CPU.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct tcb_s *this_task(void)
|
||||
{
|
||||
irqstate_t flags;
|
||||
FAR struct tcb_s *tcb;
|
||||
|
||||
#ifdef CONDIF_ARCH_GLOBAL_IRQDISABLE
|
||||
/* Disable local interrupts to avoid CPU switching */
|
||||
|
||||
flags = up_irq_save();
|
||||
#else
|
||||
/* Enter a critical section */
|
||||
|
||||
flags = enter_critical_section();
|
||||
#endif
|
||||
|
||||
/* Obtain the TCB which is currently running on this CPU */
|
||||
|
||||
tcb = current_task(this_cpu());
|
||||
|
||||
/* Enable local interrupts */
|
||||
|
||||
#ifdef CONDIF_ARCH_GLOBAL_IRQDISABLE
|
||||
up_irq_restore(flags);
|
||||
#else
|
||||
leave_critical_section(flags);
|
||||
#endif
|
||||
return tcb;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SMP */
|
||||
Reference in New Issue
Block a user