-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bluetooth: shell: refactor shell print for Bluetooth-specific context #74652
base: main
Are you sure you want to change the base?
Conversation
1f6268c
to
204e867
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right direction (but please do convince me if you believe so).
Some of the changes are welcome, but the idea of a bt_shell
is IMO not.
In your commit message you mention that you want to remove the code footprint, but you also mention an increase cost of this new bt_shell. Aren't those two sentences conflicting?
The BT shell definitely needs improvement. I created a issue #70945 related to this, that requests the removed of the ctx_shell
. The removal of the ctx_shell
would directly conflict with the majority of this PR, as all the bt_shell
functions you've defined will simply call the shell functions directly (as they would need the shell pointer again).
Could you provide some data on the codesize that you've increase/decreased?
@Thalley Thank you for your feedback. It's good to hear that you're addressing
At first glance, this might seem controversial.
By picking up
|
To stretch further, I think the functions that should be improved are
Since in reality the same message printed out inside the shell is always fixed to a specific color, and if we prioritize the code size, this should make sense. Otherwise, every time, for example in Cortex-M, |
Just tried your PR with the BT shell test application for the With PR
Without PR
So while I do not agree with the direction of this PR, as we really need to get rid of I'm not at a point where I'll approve, but I'm also not going to reject this change. I'd like to get input from the other BT collaborators on this. |
@Thalley, thank you for the additional information. It seems we should start by getting rid of |
@Thalley Just a reminder that this stretch was merged in this PR: #75340. 👀 |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
204e867
to
45075db
Compare
45075db
to
d3dffb7
Compare
@Thalley I just added another commit that introduces While exploring ways to eliminate |
|
||
#include "bt_shell_private.h" | ||
|
||
extern const struct shell *ctx_shell; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't bt_shell
be more appropriate, since this is now basically an internal API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also fine!
FWIW, I borrowed the name from #include "net_shell_private.h"
, so I was following that pattern. 😄
I'm not an expert in the shells, but the current If you have 2 or more shells that each may call the BT shell command handler, then currently the |
Yeah, that's why I'm bringing up the real use case. Even if we have two or more shells, do we really need to support BT shell responses for every situation? It feels like we're trying to cover cases that might not happen often. 😃
As you mentioned as an alternative in #70945. A kind of
I'm OK if that's the way we can move forward. WDYT? |
It's hard to tell how people use these APIs, but the API does allow for such behavior, and thus any solution to our "problems" should consider what's possible, even if it will only happen with madmen :D
I think the |
The BTW, I think in the future, we should make the shell commands more like CLI programs on a TTY, where the program exits before the shell returns to a prompt. For that, we could block and wait in command functions. For that duration, we have a tread and its stack as working memory. |
@alwa-nordic Thanks for the comment. |
550a985
to
0bf9681
Compare
Here we go! Finally, this PR is re-opened for review. 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Since BT is pretty much the only shell to do this, I think it makes sense to keep it in BT. One comment/question
Found one other place where "ctx_shell" was used outside of BT, but that was easy to just remove: #81395 |
Introduced `bt_shell_private.c` and `bt_shell_private.h` to provide common functions for the Bluetooth `shell_wall_print`. These functions are equivalent to `shell_fprintf`, `shell_info`, `shell_print`, `shell_warn`, `shell_error` and `shell_hexdump` but without requiring the `sh` parameter. The cost of the newly added `bt_shell_fprintf_info` ... `_error` functions will be negligible when there are many individual calls that need to pass both the `sh` and `color` parameters each time. Signed-off-by: Pisit Sawangvonganan <[email protected]>
Limit the usage of `ctx_shell` to cases where printing requires it and `sh` is not available. Signed-off-by: Pisit Sawangvonganan <[email protected]>
0bf9681
to
5243ac9
Compare
This change aims to eliminate the dependency on `ctx_shell` in the Bluetooth `host/shell/*`, making the code more maintainable. Replaced `shell_*` functions that depended on `ctx_shell` with the appropriate `bt_shell_*` functions. The shell-less functions `bt_do_scan_filter_clear_name`, `bt_do_scan_off`, and `bt_do_connect_le` were added so they can be called without `sh`. Signed-off-by: Pisit Sawangvonganan <[email protected]>
5243ac9
to
90f439f
Compare
Changes made as requested—hope this looks good! |
Excellent job and great that you updated it so fast :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything really Bluetooth specific in this c-file? Wouldn't other modules benefit from having a "wall" API? Seems to me like this should just be a generic API instead of a Bluetooth specific one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that this C-file isn't Bluetooth-specific, but since it's designed to address a Bluetooth-shell problem, keeping it focused on Bluetooth is fine for now. If similar needs arise elsewhere, it can be refactored into a generic API later.
🤞 Once this is merged, I'll open another PR for audio/shell
, mesh/shell
, and classic/shell
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakub-uC @carlescufi any comments on this? How easily could this generic API be accepted as part of the shell subsystem?
This PR aims to eliminate the dependency on
ctx_shell
in the Bluetoothhost/shell/*
, making the code more maintainable.bt_shell_private.c
andbt_shell_private.h
to provide common functions for the Bluetooth shell.ctx_shell
to cases where printing requires it andsh
is not available.(Interim commit before switch to
bt_shell_*
)ctx_shell
usage in the Bluetoothhost/shell/*
.