This is an automated email from the ASF dual-hosted git repository. ligd pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a56714888868399b5148ab84f8a100505bd3e974 Author: hujun5 <[email protected]> AuthorDate: Tue Jul 23 21:02:37 2024 +0800 sched: add up_this_task and up_change_task macro stub reason: We can utilize percpu storage to hold information about the current running task. If we intend to implement this feature, we would need to define two macros that help us manage this percpu information effectively. up_this_task: This macro is designed to read the contents of the percpu register to retrieve information about the current running task.This allows us to quickly access task-specific data without having to disable interrupts, access global variables and obtain the current cpu index. up_update_task: This macro is responsible for updating the contents of the percpu register.It is typically called during initialization or when a context switch occurs to ensure that the percpu register reflects the information of the newly running 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 <[email protected]> --- fs/procfs/fs_procfstcbinfo.c | 1 + include/nuttx/arch.h | 37 +++++++++++++++++++++++++++++++++++ libs/libc/time/lib_localtime.c | 1 + net/utils/net_snoop.c | 1 + sched/init/nx_start.c | 5 +++++ sched/sched/sched.h | 11 ++++++++--- sched/sched/sched_addreadytorun.c | 2 ++ sched/sched/sched_mergepending.c | 1 + sched/sched/sched_process_delivered.c | 1 + sched/sched/sched_profil.c | 1 + sched/sched/sched_removereadytorun.c | 3 +++ 11 files changed, 61 insertions(+), 3 deletions(-) diff --git a/fs/procfs/fs_procfstcbinfo.c b/fs/procfs/fs_procfstcbinfo.c index 7aa1f47459..23cc918a3d 100644 --- a/fs/procfs/fs_procfstcbinfo.c +++ b/fs/procfs/fs_procfstcbinfo.c @@ -41,6 +41,7 @@ #include <nuttx/fs/procfs.h> #include "fs_heap.h" +#include "sched/sched.h" #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \ defined(CONFIG_ARCH_HAVE_TCBINFO) && !defined(CONFIG_FS_PROCFS_EXCLUDE_TCBINFO) diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 86977e9512..a5d8b6280e 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -943,6 +943,43 @@ int up_copy_section(FAR void *dest, FAR const void *src, size_t n); # define up_getpicbase(ppicbase) #endif +/**************************************************************************** + * Percpu support + ****************************************************************************/ + +/**************************************************************************** + * Name: up_update_task + * + * Description: + * We can utilize percpu storage to hold information about the + * current running task. If we intend to implement this feature, we would + * need to define two macros that help us manage this percpu information + * effectively. + * + * up_this_task: This macro is designed to read the contents of the percpu + * register to retrieve information about the current + * running task.This allows us to quickly access + * task-specific data without having to disable interrupts, + * access global variables and obtain the current cpu index. + * + * up_update_task: This macro is responsible for updating the contents of + * the percpu register.It is typically called during + * initialization or when a context switch occurs to ensure + * that the percpu register reflects the information of the + * newly running task. + * + * Input Parameters: + * current tcb + * + * Returned Value: + * current tcb + * + ****************************************************************************/ + +#ifndef up_update_task +# define up_update_task(t) +#endif + /**************************************************************************** * Address Environment Interfaces * diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 64e79f2b06..8be9d17258 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -53,6 +53,7 @@ #include <sys/param.h> +#include <nuttx/arch.h> #include <nuttx/clock.h> #include <nuttx/init.h> #include <nuttx/fs/fs.h> diff --git a/net/utils/net_snoop.c b/net/utils/net_snoop.c index bdbca71291..38c16c9ff4 100644 --- a/net/utils/net_snoop.c +++ b/net/utils/net_snoop.c @@ -34,6 +34,7 @@ #include <sys/param.h> +#include <nuttx/arch.h> #include <nuttx/net/snoop.h> /**************************************************************************** diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index 750a55e17f..d45f68bbf1 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -429,6 +429,11 @@ static void idle_task_initialize(void) /* Mark the idle task as the running task */ g_running_tasks[i] = tcb; + + if (i == 0) + { + up_update_task(&g_idletcb[0]); /* Init idle task to percpu reg */ + } } } diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 23d8362ec0..edc287f75f 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -69,7 +69,6 @@ # define current_task(cpu) ((FAR struct tcb_s *)list_assignedtasks(cpu)->head) #else # define current_task(cpu) ((FAR struct tcb_s *)list_readytorun()->head) -# define this_task() (current_task(this_cpu())) #endif #define is_idle_task(t) ((t)->pid < CONFIG_SMP_NCPUS) @@ -365,7 +364,11 @@ void nxsched_sporadic_lowpriority(FAR struct tcb_s *tcb); void nxsched_suspend(FAR struct tcb_s *tcb); #endif -#ifdef CONFIG_SMP +#if defined(up_this_task) +# define this_task() up_this_task() +#elif !defined(CONFIG_SMP) +# define this_task() ((FAR struct tcb_s *)g_readytorun.head) +#else noinstrument_function static inline_function FAR struct tcb_s *this_task(void) { @@ -379,7 +382,7 @@ static inline_function FAR struct tcb_s *this_task(void) flags = up_irq_save(); - /* Obtain the TCB which is currently running on this CPU */ + /* Obtain the TCB which is current running on this CPU */ tcb = current_task(this_cpu()); @@ -388,7 +391,9 @@ static inline_function FAR struct tcb_s *this_task(void) up_irq_restore(flags); return tcb; } +#endif +#ifdef CONFIG_SMP void nxsched_process_delivered(int cpu); #else # define nxsched_select_cpu(a) (0) diff --git a/sched/sched/sched_addreadytorun.c b/sched/sched/sched_addreadytorun.c index 2667f12fe9..da01dec08d 100644 --- a/sched/sched/sched_addreadytorun.c +++ b/sched/sched/sched_addreadytorun.c @@ -100,6 +100,7 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb) btcb->task_state = TSTATE_TASK_RUNNING; btcb->flink->task_state = TSTATE_TASK_READYTORUN; + up_update_task(btcb); ret = true; } else @@ -269,6 +270,7 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb) */ dq_addfirst_nonempty((FAR dq_entry_t *)btcb, tasklist); + up_update_task(btcb); DEBUGASSERT(task_state == TSTATE_TASK_RUNNING); btcb->cpu = cpu; diff --git a/sched/sched/sched_mergepending.c b/sched/sched/sched_mergepending.c index 2aa515458c..a577932957 100644 --- a/sched/sched/sched_mergepending.c +++ b/sched/sched/sched_mergepending.c @@ -134,6 +134,7 @@ bool nxsched_merge_pending(void) = (FAR dq_entry_t *)ptcb; rtcb->task_state = TSTATE_TASK_READYTORUN; ptcb->task_state = TSTATE_TASK_RUNNING; + up_update_task(ptcb); ret = true; } else diff --git a/sched/sched/sched_process_delivered.c b/sched/sched/sched_process_delivered.c index b039435443..016f730712 100644 --- a/sched/sched/sched_process_delivered.c +++ b/sched/sched/sched_process_delivered.c @@ -120,6 +120,7 @@ void nxsched_process_delivered(int cpu) dq_addfirst_nonempty((FAR dq_entry_t *)btcb, tasklist); btcb->cpu = cpu; btcb->task_state = TSTATE_TASK_RUNNING; + up_update_task(btcb); DEBUGASSERT(btcb->flink != NULL); DEBUGASSERT(next == btcb->flink); diff --git a/sched/sched/sched_profil.c b/sched/sched/sched_profil.c index de77d4e60f..21294f6205 100644 --- a/sched/sched/sched_profil.c +++ b/sched/sched/sched_profil.c @@ -28,6 +28,7 @@ #include <nuttx/arch.h> #include <nuttx/wdog.h> #include <nuttx/spinlock.h> +#include "sched/sched.h" /**************************************************************************** * Pre-processor Definitions diff --git a/sched/sched/sched_removereadytorun.c b/sched/sched/sched_removereadytorun.c index abfff839bd..be7ebac2e2 100644 --- a/sched/sched/sched_removereadytorun.c +++ b/sched/sched/sched_removereadytorun.c @@ -85,6 +85,7 @@ bool nxsched_remove_readytorun(FAR struct tcb_s *rtcb) DEBUGASSERT(nxttcb != NULL); nxttcb->task_state = TSTATE_TASK_RUNNING; + up_update_task(nxttcb); doswitch = true; } @@ -270,6 +271,8 @@ void nxsched_remove_running(FAR struct tcb_s *tcb) /* Since the TCB is no longer in any list, it is now invalid */ tcb->task_state = TSTATE_TASK_INVALID; + + up_update_task(nxttcb); } void nxsched_remove_self(FAR struct tcb_s *tcb)
