mirror of
https://github.com/apache/nuttx.git
synced 2026-05-25 18:27:56 +08:00
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 <hujun5@xiaomi.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/net/snoop.h>
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include "sched/sched.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user