Fix-Point commented on code in PR #3936:
URL: https://github.com/apache/nuttx-apps/pull/3936#discussion_r4438591218


##########
testing/ostest/spinlock.c:
##########
@@ -236,37 +334,118 @@ void run_test_thread(void *lock, FAR void 
*(*thread_func)(FAR void *arg),
  ****************************************************************************/
 
 /****************************************************************************
- * Name: spinlock_test
+ * Name: spinlock_test_thread_num
+ *
+ * Description:
+ *   Run lock performance tests for a specific number of threads.
+ *   This function tests three different lock types:
+ *   - spinlock_t:  Basic spinlock
+ *   - rspinlock_t: Recursive spinlock
+ *   - seqcount_t:  Sequence counter lock
+ *
+ * Input Parameters:
+ *   thread_num - Number of threads to use in the test
+ *
+ * Returned Value:
+ *   None
+ *
  ****************************************************************************/
 
 static void spinlock_test_thread_num(unsigned thread_num)
 {
-  aligned_data(64) union
+  union
     {
       spinlock_t  spinlock;
       rspinlock_t rspinlock;
       seqcount_t  seqcount;
     } lock;
 
-  printf("Start Lock test:\n");
   printf("Thread num: %u, Loop times: %d\n\n", thread_num, LOOP_TIMES);
 
+  /* Test basic spinlock */
+
   spin_lock_init(&lock.spinlock);
   run_test_thread(&lock, spinlock_t_test_thread, thread_num, "spinlock");
 
+  /* Test read-write spinlock */
+
   rspin_lock_init(&lock.rspinlock);
   run_test_thread(&lock, rspinlock_t_test_thread, thread_num, "rspinlock");
 
+  /* Test sequence counter lock */
+
   seqlock_init(&lock.seqcount);
   run_test_thread(&lock, seqcount_t_test_thread, thread_num, "seqcount");
 }
 
-void spinlock_test(void)
+/****************************************************************************
+ * Name: spinlock_test_thread
+ *
+ * Description:
+ *   Main test thread function that runs tests with varying thread counts.
+ *   This function iterates through different thread counts (1 to
+ *   MAX_THREAD_NUM) to test lock performance under different concurrency
+ *   levels.
+ *
+ * Input Parameters:
+ *   arg - Unused argument
+ *
+ * Returned Value:
+ *   Always returns NULL
+ *
+ ****************************************************************************/
+
+static void *spinlock_test_thread(void *arg)
 {
   unsigned tnr;
 
   for (tnr = 1; tnr <= MAX_THREAD_NUM; tnr++)
     {
       spinlock_test_thread_num(tnr);
     }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: spinlock_test
+ *
+ * Description:
+ *   Entry point for the spinlock performance test suite.
+ *   This function creates a test thread with reduced priority to run
+ *   the lock performance tests. The tests measure throughput and
+ *   execution time for different lock types under varying thread counts.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void spinlock_test(void)
+{
+  pthread_t          tid;
+  pthread_attr_t     attr;
+  struct sched_param sparam;
+
+  /* Initialize thread attributes */
+
+  ASSERT(0 == pthread_attr_init(&attr));
+
+  /* Set thread priority to default - 1 */

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to