From 4f3b4328b9ba4f0356eb6a2457980be7aa6e9ae2 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Tue, 26 Mar 2024 16:40:01 +0800 Subject: [PATCH] arch: inline this_task Configuring NuttX and compile: $ ./tools/configure.sh -l qemu-armv8a:nsh_smp $ make Running with qemu $ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \ -machine virt,virtualization=on,gic-version=3 \ -net none -chardev stdio,id=con,mux=on -serial chardev:con \ -mon chardev=con,mode=readline -kernel ./nuttx Signed-off-by: hujun5 --- sched/sched/CMakeLists.txt | 4 -- sched/sched/Make.defs | 4 -- sched/sched/sched.h | 23 ++++++++++- sched/sched/sched_thistask.c | 76 ------------------------------------ 4 files changed, 22 insertions(+), 85 deletions(-) delete mode 100644 sched/sched/sched_thistask.c diff --git a/sched/sched/CMakeLists.txt b/sched/sched/CMakeLists.txt index 998c82f0c32ff..4f5b4c624f2ab 100644 --- a/sched/sched/CMakeLists.txt +++ b/sched/sched/CMakeLists.txt @@ -108,10 +108,6 @@ else() list(APPEND SRCS sched_processtimer.c) endif() -if(CONFIG_SMP) - list(APPEND SRCS sched_thistask.c) -endif() - if(CONFIG_SCHED_CRITMONITOR) list(APPEND SRCS sched_critmonitor.c) endif() diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs index 2ff311780e467..8c94be1778f44 100644 --- a/sched/sched/Make.defs +++ b/sched/sched/Make.defs @@ -84,10 +84,6 @@ else CSRCS += sched_processtimer.c endif -ifeq ($(CONFIG_SMP),y) -CSRCS += sched_thistask.c -endif - ifeq ($(CONFIG_SCHED_CRITMONITOR),y) CSRCS += sched_critmonitor.c endif diff --git a/sched/sched/sched.h b/sched/sched/sched.h index bdf3a60097b65..be950451b9148 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -353,7 +353,28 @@ void nxsched_suspend(FAR struct tcb_s *tcb); #endif #ifdef CONFIG_SMP -FAR struct tcb_s *this_task(void) noinstrument_function; +noinstrument_function +static inline_function FAR struct tcb_s *this_task(void) +{ + FAR struct tcb_s *tcb; + irqstate_t flags; + + /* If the CPU supports suppression of interprocessor interrupts, then + * simple disabling interrupts will provide sufficient protection for + * the following operations. + */ + + flags = up_irq_save(); + + /* Obtain the TCB which is currently running on this CPU */ + + tcb = current_task(this_cpu()); + + /* Enable local interrupts */ + + up_irq_restore(flags); + return tcb; +} int nxsched_select_cpu(cpu_set_t affinity); int nxsched_pause_cpu(FAR struct tcb_s *tcb); diff --git a/sched/sched/sched_thistask.c b/sched/sched/sched_thistask.c deleted file mode 100644 index 57a146757cfa2..0000000000000 --- a/sched/sched/sched_thistask.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * sched/sched/sched_thistask.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include - -#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() - * - * Returned Value: - * the TCB that is currently running on the current CPU. - * - ****************************************************************************/ - -FAR struct tcb_s *this_task(void) -{ - FAR struct tcb_s *tcb; - irqstate_t flags; - - /* If the CPU supports suppression of interprocessor interrupts, then - * simple disabling interrupts will provide sufficient protection for - * the following operations. - */ - - flags = up_irq_save(); - - /* Obtain the TCB which is currently running on this CPU */ - - tcb = current_task(this_cpu()); - - /* Enable local interrupts */ - - up_irq_restore(flags); - return tcb; -} - -#endif /* CONFIG_SMP */