arch: inline this_task to improve performence

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 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-03-26 16:40:01 +08:00 committed by Alan Carvalho de Assis
parent 08e6f56176
commit 14d94ddd76
4 changed files with 22 additions and 85 deletions

View File

@ -108,10 +108,6 @@ else()
list(APPEND SRCS sched_processtimer.c) list(APPEND SRCS sched_processtimer.c)
endif() endif()
if(CONFIG_SMP)
list(APPEND SRCS sched_thistask.c)
endif()
if(CONFIG_SCHED_CRITMONITOR) if(CONFIG_SCHED_CRITMONITOR)
list(APPEND SRCS sched_critmonitor.c) list(APPEND SRCS sched_critmonitor.c)
endif() endif()

View File

@ -84,10 +84,6 @@ else
CSRCS += sched_processtimer.c CSRCS += sched_processtimer.c
endif endif
ifeq ($(CONFIG_SMP),y)
CSRCS += sched_thistask.c
endif
ifeq ($(CONFIG_SCHED_CRITMONITOR),y) ifeq ($(CONFIG_SCHED_CRITMONITOR),y)
CSRCS += sched_critmonitor.c CSRCS += sched_critmonitor.c
endif endif

View File

@ -353,7 +353,28 @@ void nxsched_suspend(FAR struct tcb_s *tcb);
#endif #endif
#ifdef CONFIG_SMP #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_select_cpu(cpu_set_t affinity);
int nxsched_pause_cpu(FAR struct tcb_s *tcb); int nxsched_pause_cpu(FAR struct tcb_s *tcb);

View File

@ -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 <nuttx/config.h>
#include <sys/types.h>
#include <arch/irq.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.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()
*
* 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 */