mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-17 07:05:31 +08:00
feat: smp_call: added signaling call_req
This patch introduces `rt_smp_call_request` API to handle queued requests across cores with user provided data buffer, which provides a way to request IPI through a non-blocking pattern. It also resolved several issues in the old implementation: - Multiple requests from different cores can not be queued in the work object of the target core. - Data racing on `rt_smp_work` of same core. If multiple requests came in turns, or if the call is used by the target cpu, while a new request is coming, the value will be overwrite. - Memory vulnerability. The rt_smp_event is allocated on stack, though the caller may not wait until the call is done. - API naming problem. Actually we don't provide a way to issue an IPI to ANY core in mask. What the API do is aligned to MANY pattern. - FUNC_IPI registering to PIC. Changes: - Declared and configured the new `RT_SMP_CALL_IPI` to support functional IPIs for task requests across cores. - Replaced the single `rt_smp_work` array with `call_req_cores` to manage per-core call requests safely. - Added `_call_req_take` and `_call_req_release` functions for atomic handling of request lifetimes, preventing data race conditions. - Replaced single event handling with a queue-based approach (`call_queue`) for efficient multi-request processing per core. - Introduced `rt_smp_call_ipi_handler` to process queued requests, reducing IPI contention by only sending new requests when needed. - Implemented `_smp_call_remote_request` to handle remote requests with specific flags, enabling more flexible core-to-core task signaling. - Refined `rt_smp_call_req_init` to initialize and track requests with atomic usage flags, mitigating potential memory vulnerabilities. Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
1 parent
285fee9d4c
commit
2f6d98bfcb
6 files changed
+364
-95
No files matched your search
@@ -71,8 +71,9 @@ void gic_common_sgi_config(void *base, void *data, int irq_base)
|
||||
pirq = rt_pic_find_ipi(data, ipi); \
|
||||
pirq->mode = RT_IRQ_MODE_EDGE_RISING; \
|
||||
|
||||
DECLARE_GIC_IPI(RT_SCHEDULE_IPI, 0);
|
||||
DECLARE_GIC_IPI(RT_STOP_IPI, 1);
|
||||
DECLARE_GIC_IPI(RT_SCHEDULE_IPI, RT_SCHEDULE_IPI);
|
||||
DECLARE_GIC_IPI(RT_STOP_IPI, RT_STOP_IPI);
|
||||
DECLARE_GIC_IPI(RT_SMP_CALL_IPI, RT_SMP_CALL_IPI);
|
||||
|
||||
#undef DECLARE_GIC_IPI
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ static int _ipi_hash[] =
|
||||
#ifdef RT_USING_SMP
|
||||
[RT_SCHEDULE_IPI] = RT_SCHEDULE_IPI,
|
||||
[RT_STOP_IPI] = RT_STOP_IPI,
|
||||
[RT_SMP_CALL_IPI] = RT_SMP_CALL_IPI,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
+302
-71
File diff suppressed because it is too large.
Load diff
@@ -1,34 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024/9/12 zhujiale the first version
|
||||
* 2024/10/24 Shell added non-blocking IPI calling method
|
||||
*/
|
||||
|
||||
#ifndef __SMP_IPI_H__
|
||||
#define __SMP_IPI_H__
|
||||
#include <rtthread.h>
|
||||
typedef void (*rt_smp_call_func_back)(void *data);
|
||||
typedef rt_bool_t (*rt_smp_cond)(int cpu, void *info);
|
||||
|
||||
#define SMP_CALL_EVENT_FUNC 0x1
|
||||
/* callback of smp call */
|
||||
typedef void (*rt_smp_call_cb_t)(void *data);
|
||||
typedef rt_bool_t (*rt_smp_cond_t)(int cpu, void *info);
|
||||
|
||||
#define SMP_CALL_WAIT_ALL (1 << 0)
|
||||
#define SMP_CALL_NO_WAIT (1 << 1)
|
||||
#define SMP_CALL_EVENT_GLOB_ASYNC 0x1
|
||||
#define SMP_CALL_EVENT_GLOB_SYNC 0x2
|
||||
#define SMP_CALL_EVENT_REQUEST 0x4
|
||||
|
||||
#define SMP_CALL_WAIT_ALL (1ul << 0)
|
||||
#define SMP_CALL_NO_LOCAL (1ul << 1)
|
||||
#define SMP_CALL_SIGNAL (1ul << 2)
|
||||
|
||||
#define RT_ALL_CPU ((1 << RT_CPUS_NR) - 1)
|
||||
struct rt_smp_event
|
||||
{
|
||||
int cpu_mask;
|
||||
int event_id;
|
||||
void *data;
|
||||
rt_smp_call_func_back func;
|
||||
};
|
||||
struct rt_smp_call
|
||||
{
|
||||
struct rt_spinlock lock;
|
||||
struct rt_smp_event event;
|
||||
rt_smp_call_cb_t func;
|
||||
|
||||
union
|
||||
{
|
||||
rt_atomic_t *calling_cpu_mask;
|
||||
rt_atomic_t usage_tracer;
|
||||
} typed;
|
||||
};
|
||||
|
||||
struct rt_smp_call_req
|
||||
{
|
||||
/* handle the busy status synchronization */
|
||||
rt_hw_spinlock_t freed_lock;
|
||||
struct rt_smp_event event;
|
||||
rt_ll_slist_t slist_node;
|
||||
};
|
||||
|
||||
void rt_smp_call_ipi_handler(int vector, void *param);
|
||||
void rt_smp_call_each_cpu(rt_smp_call_func_back func, void *data, rt_uint8_t flag);
|
||||
void rt_smp_call_each_cpu_cond(rt_smp_call_func_back func, void *data, rt_uint8_t flag, rt_smp_cond cond_func);
|
||||
void rt_smp_call_any_cpu(int cpu_mask, rt_smp_call_func_back func, void *data, rt_uint8_t flag);
|
||||
void rt_smp_call_any_cpu_cond(int cpu_mask, rt_smp_call_func_back func, void *data, rt_uint8_t flag, rt_smp_cond cond_func);
|
||||
void rt_smp_init(void);
|
||||
void rt_smp_call_each_cpu(rt_smp_call_cb_t func, void *data, rt_uint8_t flags);
|
||||
void rt_smp_call_each_cpu_cond(rt_smp_call_cb_t func, void *data, rt_uint8_t flag, rt_smp_cond_t cond_func);
|
||||
void rt_smp_call_cpu_mask(rt_ubase_t cpu_mask, rt_smp_call_cb_t func, void *data, rt_uint8_t flags);
|
||||
void rt_smp_call_cpu_mask_cond(rt_ubase_t cpu_mask, rt_smp_call_cb_t func, void *data, rt_uint8_t flag, rt_smp_cond_t cond_func);
|
||||
void rt_smp_call_init(void);
|
||||
|
||||
rt_err_t rt_smp_call_request(int callcpu, rt_uint8_t flags, struct rt_smp_call_req *call_req);
|
||||
void rt_smp_call_req_init(struct rt_smp_call_req *call_req,
|
||||
rt_smp_call_cb_t func, void *data);
|
||||
void rt_smp_request_wait_freed(struct rt_smp_call_req *req);
|
||||
|
||||
#define rt_smp_for_each_cpu(_iter) for (_iter = 0; (_iter) < RT_CPUS_NR; (_iter)++)
|
||||
rt_inline size_t rt_smp_get_next_remote(size_t iter, size_t cpuid)
|
||||
{
|
||||
iter++;
|
||||
return iter == cpuid ? iter + 1 : iter;
|
||||
}
|
||||
#define rt_smp_for_each_remote_cpu(_iter, _cpuid) for (_iter = rt_smp_get_next_remote(-1, _cpuid); (_iter) < RT_CPUS_NR; _iter=rt_smp_get_next_remote(_iter, _cpuid))
|
||||
#endif
|
||||
Reference in new issue
Block a user