From 77eda6f760c19331a459910c61904edb689583a9 Mon Sep 17 00:00:00 2001 From: M Mithilesh Date: Fri, 6 Mar 2026 13:50:33 +0530 Subject: [PATCH] cpukit/confdefs: Add CAN stack resource calculation The CAN/CAN FD stack requires a worker task per configured queue. Empirical profiling confirms the CAN worker task utilizes ~404 bytes of stack space on 32-bit architectures. This patch introduces CONFIGURE_MAXIMUM_CAN_QUEUES to dynamically inject the required CAN worker tasks into the master _CONFIGURE_TASKS pool. Because the 404-byte usage falls below RTEMS_MINIMUM_STACK_SIZE, provisioning them as standard system tasks automatically guarantees sufficient stack space overhead. Additionally, this patch removes the hardcoded +0x1000 stack padding in rtems_task_create to prevent workspace exhaustion, and adds the spcan01 test to verify the CONFIGURE_MAXIMUM_CAN_QUEUES macro behavior. Closes #5193 --- cpukit/dev/can/can-quekern.c | 2 +- cpukit/include/rtems/confdefs/threads.h | 11 +++- spec/build/testsuites/sptests/grp.yml | 2 + spec/build/testsuites/sptests/spcan01.yml | 19 +++++++ testsuites/sptests/spcan01/init.c | 67 +++++++++++++++++++++++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 spec/build/testsuites/sptests/spcan01.yml create mode 100644 testsuites/sptests/spcan01/init.c diff --git a/cpukit/dev/can/can-quekern.c b/cpukit/dev/can/can-quekern.c index 329290dec2..71321ed3a5 100644 --- a/cpukit/dev/can/can-quekern.c +++ b/cpukit/dev/can/can-quekern.c @@ -465,7 +465,7 @@ int rtems_can_queue_kern_initialize( void ) sc = rtems_task_create( rtems_build_name( 'C', 'A', 'N', 'D' ), CAN_DEAD_FUNC_PRIORITY, - RTEMS_MINIMUM_STACK_SIZE + 0x1000, + RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &dead_func_id diff --git a/cpukit/include/rtems/confdefs/threads.h b/cpukit/include/rtems/confdefs/threads.h index 8f1a59f985..78a2ac3470 100644 --- a/cpukit/include/rtems/confdefs/threads.h +++ b/cpukit/include/rtems/confdefs/threads.h @@ -59,8 +59,15 @@ #define CONFIGURE_MAXIMUM_TASKS 0 #endif -#define _CONFIGURE_TASKS \ - ( CONFIGURE_MAXIMUM_TASKS + _CONFIGURE_LIBBLOCK_TASKS ) +#ifdef CONFIGURE_MAXIMUM_CAN_CHIPS + #define _CONFIGURE_CAN_TASKS ( CONFIGURE_MAXIMUM_CAN_CHIPS + 1 ) +#else + #define _CONFIGURE_CAN_TASKS 0 +#endif + +#define _CONFIGURE_TASKS \ + ( CONFIGURE_MAXIMUM_TASKS + _CONFIGURE_LIBBLOCK_TASKS + \ + _CONFIGURE_CAN_TASKS ) #ifndef CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE #define CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE 0 diff --git a/spec/build/testsuites/sptests/grp.yml b/spec/build/testsuites/sptests/grp.yml index 3b55c68013..c5f3020bf2 100644 --- a/spec/build/testsuites/sptests/grp.yml +++ b/spec/build/testsuites/sptests/grp.yml @@ -168,6 +168,8 @@ links: uid: spatomic01 - role: build-dependency uid: spcache01 + - role: build-dependency + uid: spcan01 - role: build-dependency uid: spcbssched01 - role: build-dependency diff --git a/spec/build/testsuites/sptests/spcan01.yml b/spec/build/testsuites/sptests/spcan01.yml new file mode 100644 index 0000000000..09da20167d --- /dev/null +++ b/spec/build/testsuites/sptests/spcan01.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: test-program +cflags: [] +copyrights: +- Copyright (C) 2026 Mithilesh Mattapalli +cppflags: [] +cxxflags: [] +enabled-by: true +features: c cprogram +includes: [] +ldflags: [] +links: [] +source: +- testsuites/sptests/spcan01/init.c +stlib: [] +target: testsuites/sptests/spcan01.exe +type: build +use-after: [] +use-before: [] diff --git a/testsuites/sptests/spcan01/init.c b/testsuites/sptests/spcan01/init.c new file mode 100644 index 0000000000..88296f769c --- /dev/null +++ b/testsuites/sptests/spcan01/init.c @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/* + * Copyright (C) 2026 Mithilesh Mattapalli + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +const char rtems_test_name[] = "SPCAN 1"; + +static rtems_task Init( rtems_task_argument ignored ) +{ + struct rtems_can_chip *chip; + + (void) ignored; + rtems_print_printer_fprintf_putc( &rtems_test_printer ); + TEST_BEGIN(); + + chip = rtems_can_virtual_initialize(); + rtems_test_assert( chip != NULL ); + + TEST_END(); + rtems_test_exit( 0 ); +} + +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_MAXIMUM_SEMAPHORES 10 +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 10 +#define CONFIGURE_MAXIMUM_CAN_CHIPS 1 + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_INIT +#include