[PATCH] libblock: Add task stack size bdbuf configuration

sebastian.huber at embedded-brains.de sebastian.huber at embedded-brains.de
Tue May 29 16:04:51 UTC 2012


From: Sebastian Huber <sebastian.huber at embedded-brains.de>

The task stack size for the swap-out and worker tasks is now
configurable.  The bdbuf task resources are now included in the work
space size estimate.
---
 cpukit/libblock/include/rtems/bdbuf.h |   13 +++++-
 cpukit/libblock/src/bdbuf.c           |   70 ++++++++++++++++----------------
 cpukit/sapi/include/confdefs.h        |   24 ++++++++++-
 testsuites/libtests/block01/init.c    |    3 +-
 testsuites/libtests/block02/init.c    |    2 +-
 testsuites/libtests/block03/init.c    |    2 +-
 testsuites/libtests/block04/init.c    |    2 +-
 testsuites/libtests/block05/init.c    |    2 +-
 testsuites/libtests/block06/init.c    |   10 +++-
 testsuites/libtests/block07/init.c    |    2 +-
 testsuites/libtests/block09/init.c    |    2 +-
 testsuites/libtests/block10/init.c    |    2 +-
 testsuites/libtests/block11/init.c    |    3 +-
 testsuites/libtests/block12/init.c    |    4 +-
 14 files changed, 83 insertions(+), 58 deletions(-)

diff --git a/cpukit/libblock/include/rtems/bdbuf.h b/cpukit/libblock/include/rtems/bdbuf.h
index 134a0ce..ead4020 100644
--- a/cpukit/libblock/include/rtems/bdbuf.h
+++ b/cpukit/libblock/include/rtems/bdbuf.h
@@ -363,14 +363,16 @@ typedef struct rtems_bdbuf_config {
                                                 * at once. */
   rtems_task_priority swapout_priority;        /**< Priority of the swap out
                                                 * task. */
-  uint32_t            swapout_period;          /**< Period swapout checks buf
+  uint32_t            swapout_period;          /**< Period swap-out checks buf
                                                 * timers. */
   uint32_t            swap_block_hold;         /**< Period a buffer is held. */
   size_t              swapout_workers;         /**< The number of worker
-                                                * threads for the swapout
+                                                * threads for the swap-out
                                                 * task. */
   rtems_task_priority swapout_worker_priority; /**< Priority of the swap out
                                                 * task. */
+  size_t              task_stack_size;         /**< Task stack size for swap-out
+                                                * task and worker threads. */
   size_t              size;                    /**< Size of memory in the
                                                 * cache */
   uint32_t            buffer_min;              /**< Minimum buffer size. */
@@ -418,12 +420,17 @@ extern const rtems_bdbuf_config rtems_bdbuf_configuration;
 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT     0
 
 /**
- * Default swap-out worker task priority. The same as the swapout task.
+ * Default swap-out worker task priority. The same as the swap-out task.
  */
 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
                              RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
 
 /**
+ * Default task stack size for swap-out and worker tasks.
+ */
+#define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
+
+/**
  * Default size of memory allocated to the cache.
  */
 #define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
diff --git a/cpukit/libblock/src/bdbuf.c b/cpukit/libblock/src/bdbuf.c
index 593f19b..637ed8e 100644
--- a/cpukit/libblock/src/bdbuf.c
+++ b/cpukit/libblock/src/bdbuf.c
@@ -173,7 +173,6 @@ typedef struct rtems_bdbuf_cache
 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE       RTEMS_BLKDEV_FATAL_ERROR(20)
 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM      RTEMS_BLKDEV_FATAL_ERROR(21)
 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE  RTEMS_BLKDEV_FATAL_ERROR(22)
-#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START   RTEMS_BLKDEV_FATAL_ERROR(23)
 #define BLKDEV_FATAL_BDBUF_SWAPOUT_RE          RTEMS_BLKDEV_FATAL_ERROR(24)
 #define BLKDEV_FATAL_BDBUF_SWAPOUT_TS          RTEMS_BLKDEV_FATAL_ERROR(25)
 #define RTEMS_BLKDEV_FATAL_BDBUF_WAIT_EVNT     RTEMS_BLKDEV_FATAL_ERROR(26)
@@ -190,12 +189,6 @@ typedef struct rtems_bdbuf_cache
 #define RTEMS_BDBUF_SWAPOUT_SYNC   RTEMS_EVENT_2
 
 /**
- * The swap out task size. Should be more than enough for most drivers with
- * tracing turned on.
- */
-#define SWAPOUT_TASK_STACK_SIZE (8 * 1024)
-
-/**
  * Lock semaphore attributes. This is used for locking type mutexes.
  *
  * @warning Priority inheritance is on.
@@ -1287,6 +1280,33 @@ rtems_bdbuf_get_buffer_from_lru_list (const rtems_disk_device *dd,
   return NULL;
 }
 
+static rtems_status_code
+rtems_bdbuf_create_task(
+  rtems_name name,
+  rtems_task_entry entry,
+  rtems_task_argument arg,
+  rtems_id *id
+)
+{
+  rtems_status_code sc;
+  rtems_task_priority priority = bdbuf_config.swapout_priority ?
+    bdbuf_config.swapout_priority : RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT;
+  size_t stack_size = bdbuf_config.task_stack_size ?
+    bdbuf_config.task_stack_size : RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT;
+
+  sc = rtems_task_create (name,
+                          priority,
+                          stack_size,
+                          RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
+                          RTEMS_LOCAL | RTEMS_NO_FLOATING_POINT,
+                          id);
+
+  if (sc == RTEMS_SUCCESSFUL)
+    sc = rtems_task_start (*id, entry, arg);
+
+  return sc;
+}
+
 /**
  * Initialise the cache.
  *
@@ -1456,20 +1476,10 @@ rtems_bdbuf_init (void)
    */
   bdbuf_cache.swapout_enabled = true;
 
-  sc = rtems_task_create (rtems_build_name('B', 'S', 'W', 'P'),
-                          bdbuf_config.swapout_priority ?
-                            bdbuf_config.swapout_priority :
-                            RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT,
-                          SWAPOUT_TASK_STACK_SIZE,
-                          RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
-                          RTEMS_LOCAL | RTEMS_NO_FLOATING_POINT,
-                          &bdbuf_cache.swapout);
-  if (sc != RTEMS_SUCCESSFUL)
-    goto error;
-
-  sc = rtems_task_start (bdbuf_cache.swapout,
-                         rtems_bdbuf_swapout_task,
-                         (rtems_task_argument) &bdbuf_cache);
+  sc = rtems_bdbuf_create_task (rtems_build_name('B', 'S', 'W', 'P'),
+                                rtems_bdbuf_swapout_task,
+                                (rtems_task_argument) &bdbuf_cache,
+                                &bdbuf_cache.swapout);
   if (sc != RTEMS_SUCCESSFUL)
     goto error;
 
@@ -2639,22 +2649,12 @@ rtems_bdbuf_swapout_workers_open (void)
     rtems_chain_initialize_empty (&worker->transfer.bds);
     worker->transfer.dd = BDBUF_INVALID_DEV;
 
-    sc = rtems_task_create (rtems_build_name('B', 'D', 'o', 'a' + w),
-                            (bdbuf_config.swapout_priority ?
-                             bdbuf_config.swapout_priority :
-                             RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT),
-                            SWAPOUT_TASK_STACK_SIZE,
-                            RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
-                            RTEMS_LOCAL | RTEMS_NO_FLOATING_POINT,
-                            &worker->id);
+    sc = rtems_bdbuf_create_task (rtems_build_name('B', 'D', 'o', 'a' + w),
+                                  rtems_bdbuf_swapout_worker_task,
+                                  (rtems_task_argument) worker,
+                                  &worker->id);
     if (sc != RTEMS_SUCCESSFUL)
       rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE);
-
-    sc = rtems_task_start (worker->id,
-                           rtems_bdbuf_swapout_worker_task,
-                           (rtems_task_argument) worker);
-    if (sc != RTEMS_SUCCESSFUL)
-      rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START);
   }
 
   rtems_bdbuf_unlock_cache ();
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index bb18be4..5f6f063 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -1225,6 +1225,10 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
     #define CONFIGURE_SWAPOUT_WORKER_TASK_PRIORITY \
                               RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT
   #endif
+  #ifndef CONFIGURE_BDBUF_TASK_STACK_SIZE
+    #define CONFIGURE_BDBUF_TASK_STACK_SIZE \
+                              RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT
+  #endif
   #ifndef CONFIGURE_BDBUF_CACHE_MEMORY_SIZE
     #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE \
                               RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT
@@ -1246,12 +1250,20 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
       CONFIGURE_SWAPOUT_BLOCK_HOLD,
       CONFIGURE_SWAPOUT_WORKER_TASKS,
       CONFIGURE_SWAPOUT_WORKER_TASK_PRIORITY,
+      CONFIGURE_BDBUF_TASK_STACK_SIZE,
       CONFIGURE_BDBUF_CACHE_MEMORY_SIZE,
       CONFIGURE_BDBUF_BUFFER_MIN_SIZE,
       CONFIGURE_BDBUF_BUFFER_MAX_SIZE
     };
   #endif
 
+  #define CONFIGURE_LIBBLOCK_TASKS (1 + CONFIGURE_SWAPOUT_WORKER_TASKS)
+
+  #define CONFIGURE_LIBBLOCK_TASK_EXTRA_STACKS \
+    (CONFIGURE_LIBBLOCK_TASKS * \
+    (CONFIGURE_MINIMUM_TASK_STACK_SIZE < CONFIGURE_BDBUF_TASK_STACK_SIZE ? \
+    0 : CONFIGURE_BDBUF_TASK_STACK_SIZE - CONFIGURE_MINIMUM_TASK_STACK_SIZE))
+
   /*
    *  Semaphores:
    *    o disk lock
@@ -1269,6 +1281,8 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
     #error BDBUF Cache does not use a buffer configuration table. Please remove.
   #endif
 #else
+  #define CONFIGURE_LIBBLOCK_TASKS 0
+  #define CONFIGURE_LIBBLOCK_TASK_EXTRA_STACKS 0
   #define CONFIGURE_LIBBLOCK_SEMAPHORES 0
 #endif /* CONFIGURE_APPLICATION_NEEDS_LIBBLOCK */
 
@@ -1456,6 +1470,9 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
     #define CONFIGURE_MAXIMUM_TASKS               0
   #endif
 
+  #define CONFIGURE_TASKS \
+    (CONFIGURE_MAXIMUM_TASKS + CONFIGURE_LIBBLOCK_TASKS)
+
   #ifndef CONFIGURE_DISABLE_CLASSIC_API_NOTEPADS
     #define CONFIGURE_NOTEPADS_ENABLED           TRUE
   #else
@@ -2073,7 +2090,7 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
  *  requirements.
  */
 #define CONFIGURE_TOTAL_TASKS_AND_THREADS \
-   (CONFIGURE_MAXIMUM_TASKS + \
+   (CONFIGURE_TASKS + \
     CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_ADA_TASKS + \
     CONFIGURE_MAXIMUM_GOROUTINES)
 
@@ -2176,7 +2193,7 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
     _Configure_From_stackspace( CONFIGURE_IDLE_TASK_STACK_SIZE ) )
 
 #define CONFIGURE_TASKS_STACK \
-  (_Configure_Max_Objects( CONFIGURE_MAXIMUM_TASKS ) * \
+  (_Configure_Max_Objects( CONFIGURE_TASKS ) * \
     _Configure_From_stackspace( CONFIGURE_MINIMUM_TASK_STACK_SIZE ) )
 
 #define CONFIGURE_POSIX_THREADS_STACK \
@@ -2219,6 +2236,7 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
     CONFIGURE_GOROUTINES_STACK + \
     CONFIGURE_ADA_TASKS_STACK + \
     CONFIGURE_EXTRA_MPCI_RECEIVE_SERVER_STACK + \
+    CONFIGURE_LIBBLOCK_TASK_EXTRA_STACKS + \
     CONFIGURE_EXTRA_TASK_STACKS \
   )
 
@@ -2227,7 +2245,7 @@ rtems_fs_init_functions_t    rtems_fs_init_helper =
    *  This is the Classic API Configuration Table.
    */
   rtems_api_configuration_table Configuration_RTEMS_API = {
-    CONFIGURE_MAXIMUM_TASKS,
+    CONFIGURE_TASKS,
     CONFIGURE_NOTEPADS_ENABLED,
     CONFIGURE_MAXIMUM_TIMERS + CONFIGURE_TIMER_FOR_SHARED_MEMORY_DRIVER,
     CONFIGURE_SEMAPHORES,
diff --git a/testsuites/libtests/block01/init.c b/testsuites/libtests/block01/init.c
index 76f345c..43d612e 100644
--- a/testsuites/libtests/block01/init.c
+++ b/testsuites/libtests/block01/init.c
@@ -253,9 +253,8 @@ static rtems_task Init(rtems_task_argument argument)
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
 
-#define CONFIGURE_MAXIMUM_TASKS 2
+#define CONFIGURE_MAXIMUM_TASKS 1
 #define CONFIGURE_MAXIMUM_DRIVERS 2
-#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
 
diff --git a/testsuites/libtests/block02/init.c b/testsuites/libtests/block02/init.c
index 5f89700..7c6c5d6 100644
--- a/testsuites/libtests/block02/init.c
+++ b/testsuites/libtests/block02/init.c
@@ -199,7 +199,7 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 5
+#define CONFIGURE_MAXIMUM_TASKS 3
 #define CONFIGURE_MAXIMUM_DRIVERS 3
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block03/init.c b/testsuites/libtests/block03/init.c
index 802d8d0..1c4c993 100644
--- a/testsuites/libtests/block03/init.c
+++ b/testsuites/libtests/block03/init.c
@@ -186,7 +186,7 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 5
+#define CONFIGURE_MAXIMUM_TASKS 3
 #define CONFIGURE_MAXIMUM_DRIVERS 2
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block04/init.c b/testsuites/libtests/block04/init.c
index 98d49c0..eed81fa 100644
--- a/testsuites/libtests/block04/init.c
+++ b/testsuites/libtests/block04/init.c
@@ -158,7 +158,7 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 5
+#define CONFIGURE_MAXIMUM_TASKS 3
 #define CONFIGURE_MAXIMUM_DRIVERS 2
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block05/init.c b/testsuites/libtests/block05/init.c
index 38c7d6d..e68e53d 100644
--- a/testsuites/libtests/block05/init.c
+++ b/testsuites/libtests/block05/init.c
@@ -516,7 +516,7 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 6
+#define CONFIGURE_MAXIMUM_TASKS 4
 #define CONFIGURE_MAXIMUM_DRIVERS 4
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block06/init.c b/testsuites/libtests/block06/init.c
index b6e6bce..838f371 100644
--- a/testsuites/libtests/block06/init.c
+++ b/testsuites/libtests/block06/init.c
@@ -113,6 +113,8 @@ typedef struct bdbuf_task_control
 
 #define BDBUF_TEST_TASKS (3)
 
+#define BDBUF_TEST_STACK_SIZE (2 * RTEMS_MINIMUM_STACK_SIZE)
+
 /**
  * Seconds as milli-seconds.
  */
@@ -649,7 +651,7 @@ bdbuf_tests_create_task (bdbuf_task_control* tc,
   sc = rtems_task_create (rtems_build_name (tc->name[0], tc->name[1],
                                             tc->name[2], tc->name[3]),
                           priority,
-                          8 * 1024,
+                          BDBUF_TEST_STACK_SIZE,
                           RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
                           RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR,
                           &tc->task);
@@ -1842,12 +1844,14 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 8
+#define CONFIGURE_MAXIMUM_TASKS (1 + BDBUF_TEST_TASKS)
 #define CONFIGURE_MAXIMUM_DRIVERS 3
 #define CONFIGURE_MAXIMUM_SEMAPHORES 2
 
-#define CONFIGURE_INIT_TASK_STACK_SIZE (2 * RTEMS_MINIMUM_STACK_SIZE)
+#define CONFIGURE_EXTRA_TASK_STACKS \
+  (BDBUF_TEST_TASKS * BDBUF_TEST_STACK_SIZE)
 
+#define CONFIGURE_INIT_TASK_STACK_SIZE BDBUF_TEST_STACK_SIZE
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
 
 #include <rtems/confdefs.h>
diff --git a/testsuites/libtests/block07/init.c b/testsuites/libtests/block07/init.c
index 9ae38ad..43ff1e6 100644
--- a/testsuites/libtests/block07/init.c
+++ b/testsuites/libtests/block07/init.c
@@ -262,7 +262,7 @@ static rtems_task Init(rtems_task_argument argument)
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
 
-#define CONFIGURE_MAXIMUM_TASKS 6
+#define CONFIGURE_MAXIMUM_TASKS 4
 #define CONFIGURE_MAXIMUM_DRIVERS 2
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block09/init.c b/testsuites/libtests/block09/init.c
index 04b8878..36479fe 100644
--- a/testsuites/libtests/block09/init.c
+++ b/testsuites/libtests/block09/init.c
@@ -228,7 +228,7 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 3
+#define CONFIGURE_MAXIMUM_TASKS 1
 #define CONFIGURE_MAXIMUM_DRIVERS 4
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block10/init.c b/testsuites/libtests/block10/init.c
index 1fcc1a9..186d745 100644
--- a/testsuites/libtests/block10/init.c
+++ b/testsuites/libtests/block10/init.c
@@ -473,7 +473,7 @@ static rtems_task Init(rtems_task_argument argument)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 5
+#define CONFIGURE_MAXIMUM_TASKS 3
 #define CONFIGURE_MAXIMUM_DRIVERS 4
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
diff --git a/testsuites/libtests/block11/init.c b/testsuites/libtests/block11/init.c
index d29e8ab..2458edc 100644
--- a/testsuites/libtests/block11/init.c
+++ b/testsuites/libtests/block11/init.c
@@ -396,9 +396,8 @@ static rtems_task Init(rtems_task_argument argument)
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
 
-#define CONFIGURE_MAXIMUM_TASKS 2
+#define CONFIGURE_MAXIMUM_TASKS 1
 #define CONFIGURE_MAXIMUM_DRIVERS 2
-#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
 
diff --git a/testsuites/libtests/block12/init.c b/testsuites/libtests/block12/init.c
index 27bf631..8182cd6 100644
--- a/testsuites/libtests/block12/init.c
+++ b/testsuites/libtests/block12/init.c
@@ -142,9 +142,7 @@ static void Init(rtems_task_argument arg)
 
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
 
-#define CONFIGURE_MAXIMUM_TASKS 2
-
-#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
+#define CONFIGURE_MAXIMUM_TASKS 1
 
 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
 
-- 
1.6.4.2




More information about the devel mailing list