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 2021/01/26 07:21:34 UTC

[incubator-nuttx-apps] branch master updated: testing: getprime: Introduce configurable thread priority

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/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new faaec65  testing: getprime: Introduce configurable thread priority
faaec65 is described below

commit faaec6513c9565af19054d18931f17c1142e634e
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Tue Jan 26 14:15:26 2021 +0900

    testing: getprime: Introduce configurable thread priority
    
    Summary:
    - This commit introduces configurable thread priority
    - Also, thread policy is set based on RR_INTERVAL
    
    Impact:
    - getprime only
    
    Testing:
    - Tested with spresense:wifi_smp
    
    Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
 testing/getprime/Kconfig         |  4 ++++
 testing/getprime/getprime_main.c | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/testing/getprime/Kconfig b/testing/getprime/Kconfig
index 5085ac7..2394921 100644
--- a/testing/getprime/Kconfig
+++ b/testing/getprime/Kconfig
@@ -27,4 +27,8 @@ config TESTING_GETPRIME_STACKSIZE
 	int "getprime stack size"
 	default DEFAULT_TASK_STACKSIZE
 
+config TESTING_GETPRIME_THREAD_PRIORITY
+	int "getprime thread priority"
+	default 10
+
 endif
diff --git a/testing/getprime/getprime_main.c b/testing/getprime/getprime_main.c
index bace610..b72b50e 100644
--- a/testing/getprime/getprime_main.c
+++ b/testing/getprime/getprime_main.c
@@ -111,7 +111,6 @@ static FAR void *thread_func(FAR void *param)
 static void get_prime_in_parallel(int n)
 {
   pthread_t thread[MAX_THREADS];
-  struct sched_param sparam;
   pthread_attr_t attr;
   pthread_addr_t result;
   int status;
@@ -120,16 +119,24 @@ static void get_prime_in_parallel(int n)
   status = pthread_attr_init(&attr);
   ASSERT(status == OK);
 
-  sparam.sched_priority = sched_get_priority_min(SCHED_FIFO);
+  struct sched_param sparam;
+  sparam.sched_priority = CONFIG_TESTING_GETPRIME_THREAD_PRIORITY;
   status = pthread_attr_setschedparam(&attr, &sparam);
   ASSERT(status == OK);
 
   printf("Set thread priority to %d\n",  sparam.sched_priority);
 
+#if CONFIG_RR_INTERVAL > 0
+  status = pthread_attr_setschedpolicy(&attr, SCHED_RR);
+  ASSERT(status == OK);
+
+  printf("Set thread policy to SCHED_RR \n");
+#else
   status = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
   ASSERT(status == OK);
 
   printf("Set thread policy to SCHED_FIFO \n");
+#endif
 
   for (i = 0; i < n; i++)
     {