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

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

commit df2709085cafef5f919263180fb8037311ff699f
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Mon Apr 14 10:57:54 2025 +0800

    drivers/sensors: using worker to broadcast advertisement message
    when remote core connect.
    
    using worker instead of rptun thread to broadcast advertisement
    message because the rptun thread can't process rx message when it
    calls the ns_bound function.
    
    And the advertisement message to remote core will generate many
    the advertisement ack message from remote core, these advertisement
    ack messages can't be processed at times by rptun thread.
    
    This can cause rptun thread to block when the number of advertisement
    message exceeds the number of ipc buffers between local core and
    remote core.
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 drivers/sensors/sensor_rpmsg.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c
index 16e97f6a2ba..4c0714ea62c 100644
--- a/drivers/sensors/sensor_rpmsg.c
+++ b/drivers/sensors/sensor_rpmsg.c
@@ -106,6 +106,7 @@ struct sensor_rpmsg_ept_s
   struct list_node               node;
   struct rpmsg_endpoint          ept;
   struct work_s                  work;
+  struct work_s                  bound_work;
   rmutex_t                       lock;
   FAR void                      *buffer;
   uint64_t                       expire;
@@ -1404,19 +1405,11 @@ static int sensor_rpmsg_ept_cb(FAR struct 
rpmsg_endpoint *ept,
   return -EINVAL;
 }
 
-static void sensor_rpmsg_device_ns_bound(FAR struct rpmsg_endpoint *ept)
+static void sensor_rpmsg_bound_worker(FAR void *arg)
 {
-  FAR struct sensor_rpmsg_ept_s *sre;
+  FAR struct sensor_rpmsg_ept_s *sre = arg;
   FAR struct sensor_rpmsg_dev_s *dev;
 
-  sre = container_of(ept, struct sensor_rpmsg_ept_s, ept);
-
-  down_write(&g_ept_lock);
-  list_add_tail(&g_eptlist, &sre->node);
-  up_write(&g_ept_lock);
-
-  /* Broadcast all device to ready ept */
-
   down_read(&g_dev_lock);
   list_for_every_entry(&g_devlist, dev,
                        struct sensor_rpmsg_dev_s, node)
@@ -1424,12 +1417,12 @@ static void sensor_rpmsg_device_ns_bound(FAR struct 
rpmsg_endpoint *ept)
       sensor_rpmsg_lock(dev);
       if (dev->nadvertisers > 0)
         {
-          sensor_rpmsg_advsub_one(dev, ept, SENSOR_RPMSG_ADVERTISE);
+          sensor_rpmsg_advsub_one(dev, &sre->ept, SENSOR_RPMSG_ADVERTISE);
         }
 
       if (dev->nsubscribers > 0)
         {
-          sensor_rpmsg_advsub_one(dev, ept, SENSOR_RPMSG_SUBSCRIBE);
+          sensor_rpmsg_advsub_one(dev, &sre->ept, SENSOR_RPMSG_SUBSCRIBE);
         }
 
       sensor_rpmsg_unlock(dev);
@@ -1438,6 +1431,21 @@ static void sensor_rpmsg_device_ns_bound(FAR struct 
rpmsg_endpoint *ept)
   up_read(&g_dev_lock);
 }
 
+static void sensor_rpmsg_device_ns_bound(FAR struct rpmsg_endpoint *ept)
+{
+  FAR struct sensor_rpmsg_ept_s *sre;
+
+  sre = container_of(ept, struct sensor_rpmsg_ept_s, ept);
+
+  down_write(&g_ept_lock);
+  list_add_tail(&g_eptlist, &sre->node);
+  up_write(&g_ept_lock);
+
+  /* Broadcast all device to ready ept in work context */
+
+  work_queue(HPWORK, &sre->bound_work, sensor_rpmsg_bound_worker, sre, 0);
+}
+
 static void sensor_rpmsg_ept_release(FAR struct rpmsg_endpoint *ept)
 {
   FAR struct sensor_rpmsg_ept_s *sre;

Reply via email to