You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/27 15:30:48 UTC

(nuttx) 01/03: sched_smp:sync refcount before enqueue smp call queue

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d10c1563f78717a6f7ce0b9b7c00352442664cd6
Author: dulibo1 <du...@xiaomi.com>
AuthorDate: Thu Apr 18 11:23:28 2024 +0800

    sched_smp:sync refcount before enqueue smp call queue
    
    Signed-off-by: dulibo1 <du...@xiaomi.com>
    
    1.call_data->refcount is not remote_cpus;
    2.nxsched_smp_call_add enqueue  the call_data;
    3.maybe nxsched_smp_call_handler is just doing;
    4.dequeue the call_data but call_data->refcount is not corret;
    5.unpredictability case will occur;
---
 sched/sched/sched_smp.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/sched/sched/sched_smp.c b/sched/sched/sched_smp.c
index 98437cbb83..b9315ba91a 100644
--- a/sched/sched/sched_smp.c
+++ b/sched/sched/sched_smp.c
@@ -239,7 +239,8 @@ int nxsched_smp_call(cpu_set_t cpuset, nxsched_smp_call_t func,
       CPU_CLR(this_cpu(), &cpuset);
     }
 
-  if (CPU_COUNT(&cpuset) == 0)
+  remote_cpus = CPU_COUNT(&cpuset);
+  if (remote_cpus == 0)
     {
       goto out;
     }
@@ -261,22 +262,17 @@ int nxsched_smp_call(cpu_set_t cpuset, nxsched_smp_call_t func,
 
   call_data->func = func;
   call_data->arg  = arg;
+  call_data->refcount = remote_cpus;
 
   for (i = 0; i < CONFIG_SMP_NCPUS; i++)
     {
       if (CPU_ISSET(i, &cpuset))
         {
           nxsched_smp_call_add(i, call_data);
-          remote_cpus++;
         }
     }
 
-  call_data->refcount = remote_cpus;
-
-  if (remote_cpus > 0)
-    {
-      up_send_smp_call(cpuset);
-    }
+  up_send_smp_call(cpuset);
 
   if (wait)
     {