Skip to content

Conversation

joerchan
Copy link
Contributor

@joerchan joerchan commented Feb 26, 2020

For Nordic alternative HCI driver the main stack usage caused stack overflow issues.
Refactor conf files to recommended CONF_FILE usage as the current CONF_FILE mechanism does not work when providing extra CONF_FILE or CONF_OVERLAY. Configurations will be lost in this case.

@joerchan
Copy link
Contributor Author

CC: @rugeGerritsen

@zephyrbot zephyrbot added area: Bluetooth area: API Changes to public APIs area: Samples Samples labels Feb 26, 2020
@zephyrbot
Copy link

zephyrbot commented Feb 26, 2020

All checks passed.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

Comment on lines 421 to 448
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole branch seems unnecessary to me. The condition is identical to the branch above it and you're not doing any long-duration work in that branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, removed it.

@cvinayak
Copy link
Contributor

cvinayak commented Mar 1, 2020

We should address this at kernel level and not have these in individual samples. For some context, see: #15856 and #15848

@ceolin FYI.

static u32_t prio_ts;

if (k_uptime_get_32() - prio_ts > K_SECONDS(5)) {
STACK_ANALYZE("main thread stack",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STACK_ANALYZE is deprecated, please do not use it.
You want a k_thread_foreach() loop and call k_thread_stack_space_get() on each thread.

Copy link
Contributor Author

@joerchan joerchan Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will replace STACK_ANALYZE usage. But need a way to do it for main stack. k_thread_foreach will not give me main stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with suggestion.

#include <logging/log.h>
#include <stdbool.h>

extern K_THREAD_STACK_DEFINE(z_main_stack, CONFIG_MAIN_STACK_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not put these here, they are private to the kernel

Copy link
Contributor Author

@joerchan joerchan Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need an alternative so that I can debug the main stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@andrewboie
Copy link
Contributor

you should really separate out the patches which are strictly bug fixes into a separate PR to get them in faster.

Copy link
Contributor

@andrewboie andrewboie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs changes

@joerchan
Copy link
Contributor Author

joerchan commented Mar 2, 2020

@andrewboie Your suggestion does not give me the stack usage of the threads mentioned, with the k_thread_foreach(_unlocked) I only get "BT RX" and "BT RX pri" threads. Not the main stack or any of the others.
EDIT: This appears to be an issue with the logging system. Only the two first threads is printed. But all threads are iterated.

Another thing I noticed is that k_thread_foreach does not iterate over the static threads either, but adding code for that did not give me main stack usage.
EDIT: Created #23196

The application sets the stack size of these threads and performs a lot of the code that runs it them. But don't have a way to analyze the stack usage for these threads.

What about adding struct k_thread_t *k_thread_get(const char *name) function or something similar, maybe one per thread, that would allow us to analyze these threads?

@joerchan joerchan requested a review from andrewboie March 2, 2020 13:19
@joerchan
Copy link
Contributor Author

joerchan commented Mar 2, 2020

@andrewboie Sorry for the noise, it appears to be a logging issue. I only get some of the LOG_INF statements. Using printk I see it all.
EDIT:
Silly mistake, too low LOG_LEVEL for LOG_INF to appear in main.c.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update the sample's README.rst with info on how to use this debug.conf?

joerchan added 4 commits March 4, 2020 15:09
Update main stack size for nrf5 boards. This is to support an
alternative hci_driver that has a higher stack size usage in hci driver
open. Measured stack usage in this case to 808/1024.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Refactor conf files to use prj.conf + board/<board>.conf configuration.
This allows us to have put common configurations into the prj.conf and
have board specific configs in each board file.
This also respects adding additional prj.conf files such as
-DCONF_FILE='nrf5.conf debug.conf' to add debug configuration.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Remove BT_CTLR_DTM_HCI=y config which is not supported for this board.
This produced the following warning:

warning: BT_CTLR_DTM_HCI was assigned the value
'y' but got the value 'n'. Check these unsatisfied dependencies:
BT_CTLR_DTM_HCI_SUPPORT (=n).

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
Remove data length and phy update set to 'n' on board that does not
support these features anyway. BT_CTLR_DATA_LEN_SUPPORTED and
BT_CTLR_PHY_UPDATE_SUPPORTED are both set to 'n'.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
@joerchan joerchan changed the title Bluetooth: HCI_UART: Update stack sizes and provide stack usage debug Bluetooth: HCI_UART: Update main stack and refactor conf files Mar 4, 2020
@joerchan
Copy link
Contributor Author

joerchan commented Mar 4, 2020

Split the stack debug changes into a new PR.
This is now only the main stack usage update and refactor of the conf files.
The refactor of the conf files is needed to easily add additional configuration options from debug conf file.

Copy link
Member

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@joerchan
Copy link
Contributor Author

@andrewboie The things you objected to have been removed from the PR.

@andrewboie andrewboie merged commit 5726a26 into zephyrproject-rtos:master Mar 13, 2020
@joerchan joerchan deleted the main-stack-debug branch March 13, 2020 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants