Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smpcall: add nxsched_smp_call_async and nxsched_smp_call_single_async #14656

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 70 additions & 6 deletions include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
# define get_task_name(tcb) "<noname>"
#endif

#define SMP_CALL_INITIALIZER(func, arg) {(func), (arg)}

/* 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.
*/
Expand Down Expand Up @@ -833,6 +835,15 @@ typedef CODE void (*nxsched_foreach_t)(FAR struct tcb_s *tcb, FAR void *arg);

#ifdef CONFIG_SMP
typedef CODE int (*nxsched_smp_call_t)(FAR void *arg);

struct smp_call_cookie_s;
struct smp_call_data_s
{
nxsched_smp_call_t func;
FAR void *arg;
FAR struct smp_call_cookie_s *cookie;
sq_entry_t node[CONFIG_SMP_NCPUS];
};
#endif

#endif /* __ASSEMBLY__ */
Expand Down Expand Up @@ -1698,45 +1709,98 @@ void nxsched_dumponexit(void);
int nxsched_smp_call_handler(int irq, FAR void *context,
FAR void *arg);

/****************************************************************************
* Name: nxsched_smp_call_init
*
* Description:
* Init call_data
*
* Input Parameters:
* data - Call data
* func - Function
* arg - Function args
*
* Returned Value:
* Result
*
****************************************************************************/

void nxsched_smp_call_init(FAR struct smp_call_data_s *data,
nxsched_smp_call_t func, FAR void *arg);

/****************************************************************************
* Name: nxsched_smp_call_single
*
* Description:
* Call function on single processor
* Call function on single processor, wait function callback
*
* Input Parameters:
* cpuid - Target cpu id
* func - Function
* arg - Function args
* wait - Wait function callback or not
*
* Returned Value:
* Result
*
****************************************************************************/

int nxsched_smp_call_single(int cpuid, nxsched_smp_call_t func,
FAR void *arg, bool wait);
FAR void *arg);

/****************************************************************************
* Name: nxsched_smp_call
*
* Description:
* Call function on multi processors
* Call function on multi processors, wait function callback
*
* Input Parameters:
* cpuset - Target cpuset
* func - Function
* arg - Function args
* wait - Wait function callback or not
*
* Returned Value:
* Result
*
****************************************************************************/

int nxsched_smp_call(cpu_set_t cpuset, nxsched_smp_call_t func,
FAR void *arg, bool wait);
FAR void *arg);

/****************************************************************************
* Name: nxsched_smp_call_single_async
*
* Description:
* Call function on single processor async
*
* Input Parameters:
* cpuset - Target cpuset
* data - Call data
*
* Returned Value:
* Result
*
****************************************************************************/

int nxsched_smp_call_single_async(int cpuid,
FAR struct smp_call_data_s *data);

/****************************************************************************
* Name: nxsched_smp_call_async
*
* Description:
* Call function on multi processors async
*
* Input Parameters:
* cpuset - Target cpuset
* data - Call data
*
* Returned Value:
* Result
*
****************************************************************************/

int nxsched_smp_call_async(cpu_set_t cpuset,
FAR struct smp_call_data_s *data);
#endif

#undef EXTERN
Expand Down
6 changes: 3 additions & 3 deletions libs/libc/gdbstub/lib_gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ int gdb_debugpoint_add(int type, FAR void *addr, size_t size,
point.callback = callback;
point.arg = arg;
return nxsched_smp_call((1 << CONFIG_SMP_NCPUS) - 1,
gdb_smp_debugpoint_add, &point, true);
gdb_smp_debugpoint_add, &point);
#else
return up_debugpoint_add(type, addr, size, callback, arg);
#endif
Expand All @@ -1897,8 +1897,8 @@ int gdb_debugpoint_remove(int type, FAR void *addr, size_t size)
point.addr = addr;
point.size = size;

return nxsched_smp_call((1 << CONFIG_SMP_NCPUS) - 1,
gdb_smp_debugpoint_remove, &point, true);
retrun nxsched_smp_call((1 << CONFIG_SMP_NCPUS) - 1,
gdb_smp_debugpoint_remove, &point);
#else
return up_debugpoint_remove(type, addr, size);
#endif
Expand Down
15 changes: 14 additions & 1 deletion sched/misc/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
# define XCPTCONTEXT_ALIGN 16
#endif

/****************************************************************************
* Private Types
****************************************************************************/

#ifdef CONFIG_SMP
static noreturn_function int pause_cpu_handler(FAR void *arg);
#endif

/****************************************************************************
* Private Data
****************************************************************************/
Expand All @@ -124,6 +132,11 @@ static FAR const char * const g_ttypenames[4] =
};
#endif

#ifdef CONFIG_SMP
static struct smp_call_data_s g_call_data =
SMP_CALL_INITIALIZER(pause_cpu_handler, NULL);
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -610,7 +623,7 @@ static void pause_all_cpu(void)
int delay = CONFIG_ASSERT_PAUSE_CPU_TIMEOUT;

CPU_CLR(this_cpu(), &cpus);
nxsched_smp_call(cpus, pause_cpu_handler, NULL, false);
nxsched_smp_call_async(cpus, &g_call_data);
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
g_cpu_paused[this_cpu()] = true;

/* Check if all CPUs paused with timeout */
Expand Down
2 changes: 1 addition & 1 deletion sched/sched/sched_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int sched_backtrace(pid_t tid, FAR void **buffer, int size, int skip)
arg.skip = skip;
ret = nxsched_smp_call_single(tcb->cpu,
sched_backtrace_handler,
&arg, true);
&arg);
}
else
#endif
Expand Down
12 changes: 10 additions & 2 deletions sched/sched/sched_profil.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ struct profinfo_s
spinlock_t lock; /* Lock for this structure */
};

#ifdef CONFIG_SMP
static int profil_timer_handler_cpu(FAR void *arg);
#endif

/****************************************************************************
* Private Data
****************************************************************************/

static struct profinfo_s g_prof;

#ifdef CONFIG_SMP
static struct smp_call_data_s g_call_data =
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
SMP_CALL_INITIALIZER(profil_timer_handler_cpu, &g_prof);
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -89,8 +98,7 @@ static void profil_timer_handler(wdparm_t arg)
#ifdef CONFIG_SMP
cpu_set_t cpus = (1 << CONFIG_SMP_NCPUS) - 1;
CPU_CLR(this_cpu(), &cpus);
nxsched_smp_call(cpus, profil_timer_handler_cpu,
(FAR void *)arg, false);
nxsched_smp_call_async(cpus, &g_call_data);
#endif

profil_timer_handler_cpu(prof);
Expand Down
23 changes: 15 additions & 8 deletions sched/sched/sched_roundrobin.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
#if CONFIG_RR_INTERVAL > 0

#ifdef CONFIG_SMP

/****************************************************************************
* Private Data
****************************************************************************/

#ifdef CONFIG_SMP
static struct smp_call_data_s g_call_data;
#endif

/****************************************************************************
* Private Type Declarations
****************************************************************************/
Expand All @@ -55,12 +64,12 @@ struct roundrobin_arg_s

static int nxsched_roundrobin_handler(FAR void *cookie)
{
FAR struct roundrobin_arg_s *arg = cookie;
pid_t pid = (uintptr_t)cookie;
FAR struct tcb_s *tcb;
irqstate_t flags;

flags = enter_critical_section();
tcb = nxsched_get_tcb(arg->pid);
tcb = nxsched_get_tcb(pid);

if (!tcb || tcb->task_state == TSTATE_TASK_INVALID ||
(tcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0)
Expand Down Expand Up @@ -185,12 +194,10 @@ uint32_t nxsched_process_roundrobin(FAR struct tcb_s *tcb, uint32_t ticks,
if (tcb->task_state == TSTATE_TASK_RUNNING &&
tcb->cpu != this_cpu())
{
struct roundrobin_arg_s arg;

arg.pid = tcb->pid;
nxsched_smp_call_single(tcb->cpu,
nxsched_roundrobin_handler,
&arg, false);
nxsched_smp_call_init(&g_call_data,
nxsched_roundrobin_handler,
(FAR void *)(uintptr_t)tcb->pid);
nxsched_smp_call_single_async(tcb->cpu, &g_call_data);
}
else
#endif
Expand Down
3 changes: 1 addition & 2 deletions sched/sched/sched_setpriority.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ static inline void nxsched_running_setpriority(FAR struct tcb_s *tcb,
}

arg.sched_priority = sched_priority;
nxsched_smp_call_single(tcb->cpu, reprioritize_handler,
&arg, true);
nxsched_smp_call_single(tcb->cpu, reprioritize_handler, &arg);
}
else
#endif
Expand Down
Loading
Loading