BT_LW_WQ stack overflows with debug options

The `BT_LW_WQ` stack may overflow with the build with debug options selected.

Without build with debug options selected, the thread analyzer shows nearly all of the stack space used:
[00:00:31.310,882] <inf> thread_analyzer: BT_LW_WQ : STACK: unused 80 usage 1160 / 1240 (93 %); CPU: 0 %

The configuration option for the stack size is not prompted, so it cannot be overridden to fix the issue without editing the NCS SDK.

config BT_LONG_WQ_STACK_SIZE
  # Hidden: Long workqueue stack size. Should be derived from system
  # requirements.
  int
  # should have `prompt "Long workqueue stack size"`
  default 1300 if BT_GATT_CACHING
  default 1140 if BT_TINYCRYPT_ECC
  default 1024

I manually edited /opt/nordic/ncs/v2.1.3/zephyr/subsys/bluetooth/host/Kconfig to allow BT_LONG_WQ_STACK_SIZE to be assigned (to 4096) and I no longer experience the stack overflow with the "Enable debug options" flag.

[00:01:01.317,840] <inf> thread_analyzer:  BT_LW_WQ            : STACK: unused 2776 usage 1256 / 4032 (31 %); CPU: 0 %

Parents Reply
  • Hi again

    No news on an update from our side yet, but one of the developers alerted me to a better workaround than having to alter the SDK files. 

    In order to make the BT_LONG_WQ_STACK_SIZE parameter user configurable you can simply add it to your local Kconfig file (just create a file called Kconfig in the project root folder). 

    Then you can redefine the parameter with any default value you want:

    config BT_LONG_WQ_STACK_SIZE
        int "Long workqueue stack size"
        default 2000
        
    source "Kconfig.zephyr"

    Best regards
    Torbjørn

Children
  • Hi Torbjørn,

    Thanks for the workaround option. I will use that for hacks as it is useful in development.

    For a non-debug build, the workaround sounds like a bug to me since nothing associates the intended override with the actual SDK version's Kconfig parameter or value.

    I am concerned that the workaround adds a manual item to check with each release change that won't be caught at compile time. In my experience, BT_LONG_WQ_STACK_SIZE will probably be renamed to BT_LW_WQ_STACK_SIZE or something and cause stack overflows again on a later release.

     

  • Hi 

    For a non-debug build you shouldn't have to use the workaround at all. 

    Any issue with the default configuration should be picked up by our own release testing. 

    Best regards
    Torbjørn

Related