wangtao13 opened a new issue, #19370:
URL: https://github.com/apache/nuttx/issues/19370

   ### Description
   
   I want to compare the scheduler of Nuttx with other RTOS, so I wrote a 
simple test and run it in hello.c
   ยทยทยท
   static pthread_mutex_t g_mutex;
   static volatile uint32_t g_count1 = 0;
   static volatile uint32_t g_count2 = 0;
   static volatile int isexit = 0;
   
   static void *low_task1(char *argv)
   {
       while (!isexit) {
           pthread_mutex_lock(&g_mutex);
           g_count1++;
           pthread_mutex_unlock(&g_mutex);
       }
       return 0;
   }
   
   static void * low_task2(char *arg)
   {
       while (!isexit) {
           pthread_mutex_lock(&g_mutex);
           g_count2++;
           pthread_mutex_unlock(&g_mutex);
       }
       return 0;
   }
   
   static void *hi_task(char *argv)
   {
       struct timespec start, end;
       uint32_t total_ops;
       double elapsed_ms;
   
       pthread_mutex_init(&g_mutex, NULL);
   
       clock_gettime(CLOCK_MONOTONIC, &start);
   
       sleep(5);
   
       clock_gettime(CLOCK_MONOTONIC, &end);
   
       total_ops = g_count1 + g_count2;
       elapsed_ms = (end.tv_sec - start.tv_sec) * 1000.0 +
                    (end.tv_nsec - start.tv_nsec) / 1000000.0;
   
       printf("Low task 1 count: %" PRIu32 "\n", g_count1);
       printf("Low task 2 count: %" PRIu32 "\n", g_count2);
       printf("Total operations: %" PRIu32 "\n", total_ops);
       printf("Elapsed time: %.2f ms\n", elapsed_ms);
       if (total_ops > 0) {
           printf("Average time per operation: %.3f us\n",
                  (elapsed_ms * 1000.0) / total_ops);
       }
   
       pthread_mutex_destroy(&g_mutex);
       isexit = 1;
   
       return 0;
   }
   
   int cs_test_main(int argc, char *argv[])
   {
       pthread_t hi, low1, low2;
       pthread_attr_t attr_hi, attr_low;
       struct sched_param param_hi, param_low;
   
       pthread_attr_init(&attr_hi);
       pthread_attr_init(&attr_low);
   
       param_hi.sched_priority = 200;
       pthread_attr_setschedpolicy(&attr_hi, SCHED_RR);
       pthread_attr_setschedparam(&attr_hi, &param_hi);
       pthread_attr_setinheritsched(&attr_low, PTHREAD_EXPLICIT_SCHED);
   
       if (pthread_create(&hi, &attr_hi, hi_task, NULL) != 0) {
           perror("pthread_create hi");
           return 1;
       }
   
       if (pthread_create(&low1, &attr_low, low_task1, NULL) != 0) {
           perror("pthread_create low1");
           return 1;
       }
       if (pthread_create(&low2, &attr_low, low_task2, NULL) != 0) {
           perror("pthread_create low2");
           return 1;
       }
   
       pthread_attr_destroy(&attr_hi);
       pthread_attr_destroy(&attr_low);
   
       pthread_join(hi, NULL);
       pthread_join(low1, NULL);
       pthread_join(low2, NULL);
   
       return 0;
   }
   ```
   A high prio task sleeps 5 seconds, then 2 lower tasks runs in ping-pong way 
be getting/putting mutex. After 5 seconds, high task shows the results.
   
   Here is my testing results.
   ```
   Low task 1 count: 1828625
   Low task 2 count: 1716974
   Total operations: 3545599
   Elapsed time: *float* ms
   Average time per operation: *float* us
   ```
   
   In the same hardware, another RTOS got followings.
   
   ```
   Low task 1 count: 1519473
   Low task 2 count: 1519472
   Total operations: 3038945
   ```
   
   My question is: Why counts of 2 two lower prio tasks are different too much, 
while in another RTOS, the two counts are very close?
   
   
   
   ### Verification
   
   - [x] I have verified before submitting the report.


-- 
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