smp_call.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024/9/12 zhujiale the first version
  9. * 2024/10/24 Shell added non-blocking IPI calling method
  10. */
  11. #ifndef __SMP_IPI_H__
  12. #define __SMP_IPI_H__
  13. #include <rtthread.h>
  14. #ifdef RT_USING_SMP
  15. /* callback of smp call */
  16. typedef void (*rt_smp_call_cb_t)(void *data);
  17. typedef rt_bool_t (*rt_smp_cond_t)(int cpu, void *info);
  18. #define SMP_CALL_EVENT_GLOB_ASYNC 0x1
  19. #define SMP_CALL_EVENT_GLOB_SYNC 0x2
  20. #define SMP_CALL_EVENT_REQUEST 0x4
  21. #define SMP_CALL_WAIT_ALL (1ul << 0)
  22. #define SMP_CALL_NO_LOCAL (1ul << 1)
  23. #define SMP_CALL_SIGNAL (1ul << 2)
  24. #define RT_ALL_CPU ((1 << RT_CPUS_NR) - 1)
  25. struct rt_smp_event
  26. {
  27. int event_id;
  28. void *data;
  29. rt_smp_call_cb_t func;
  30. union
  31. {
  32. rt_atomic_t *calling_cpu_mask;
  33. rt_atomic_t usage_tracer;
  34. } typed;
  35. };
  36. struct rt_smp_call_req
  37. {
  38. /* handle the busy status synchronization */
  39. rt_hw_spinlock_t freed_lock;
  40. struct rt_smp_event event;
  41. rt_ll_slist_t slist_node;
  42. };
  43. void rt_smp_call_ipi_handler(int vector, void *param);
  44. void rt_smp_call_each_cpu(rt_smp_call_cb_t func, void *data, rt_uint8_t flags);
  45. 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);
  46. void rt_smp_call_cpu_mask(rt_ubase_t cpu_mask, rt_smp_call_cb_t func, void *data, rt_uint8_t flags);
  47. 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);
  48. void rt_smp_call_init(void);
  49. rt_err_t rt_smp_call_request(int callcpu, rt_uint8_t flags, struct rt_smp_call_req *call_req);
  50. void rt_smp_call_req_init(struct rt_smp_call_req *call_req,
  51. rt_smp_call_cb_t func, void *data);
  52. void rt_smp_request_wait_freed(struct rt_smp_call_req *req);
  53. #define rt_smp_for_each_cpu(_iter) for (_iter = 0; (_iter) < RT_CPUS_NR; (_iter)++)
  54. rt_inline size_t rt_smp_get_next_remote(size_t iter, size_t cpuid)
  55. {
  56. iter++;
  57. return iter == cpuid ? iter + 1 : iter;
  58. }
  59. #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))
  60. #endif // RT_USING_SMP
  61. #endif // __SMP_IPI_H__