Skip to content

devices: make device name field optional #49352

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

Closed
wants to merge 6 commits into from

Conversation

gmarull
Copy link
Member

@gmarull gmarull commented Aug 22, 2022

With the adoption of DEVICE_DT_GET() device names are in many cases
optional and used only for stuff like debugging or in shells. This patch
makes struct device name field optional so that ROM can be saved in case
user can afford it. This means that the name field in struct device
should no longer be accessed directly but using a new function:
device_name_get().

Note that the option controlling such feature is
CONFIG_DEVICE_STORE_NAME, enabled by default.

Some quick numbers using hello_world:

nrf52840dk_nrf52840: $\Delta_{\textrm{FLASH}} = -100~\textrm{bytes}$
nucleo_h743zi: $\Delta_{\textrm{FLASH}} = -272~\textrm{bytes}$

Signed-off-by: Gerard Marull-Paretas [email protected]

@gmarull gmarull force-pushed the device-name-optional branch from 751b784 to 9f10be7 Compare August 24, 2022 13:48
Copy link
Contributor

@galak galak left a comment

Choose a reason for hiding this comment

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

I'd suggest maybe splitting this PR as the device_name_get cleanup could get merged now, and than we can hash out the testcase and details on CONFIG_DEVICE_STORE_NAME

@MaureenHelm
Copy link
Member

Sensor drivers and samples look good.
We need a test that builds with CONFIG_DEVICE_STORE_NAME=n

any suggestion? not sure where to test this

Maybe start with samples/basic/minimal? It's not exactly thorough, but it would be better than nothing.

@gmarull
Copy link
Member Author

gmarull commented Aug 24, 2022

I'd suggest maybe splitting this PR as the device_name_get cleanup could get merged now, and than we can hash out the testcase and details on CONFIG_DEVICE_STORE_NAME

you mean adding the API without the optional name field changes?

@galak
Copy link
Contributor

galak commented Aug 24, 2022

you mean adding the API without the optional name field changes?

yes. Since the 95% of this PR is the API and changes to use it. I think its reasonable to encapsulate the access to name.

@gmarull gmarull added the dev-review To be discussed in dev-review meeting label Aug 25, 2022
#ifdef CONFIG_DEVICE_STORE_NAME
return dev->name;
#else
return "";
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to allocate a global string in rom with value "<device>" or something like that, and return a pointer to it here. Otherwise log messages that print device names will be kind of busted with CONFIG_DEVICE_STORE_NAME=n in my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

adjusted to return "<device>"

{
ARG_UNUSED(name);

return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like a footgun implementation.

I believe we should not provide a device_get_binding implementation at all, at least by default, if CONFIG_DEVICE_STORE_NAME=n.

But I get why you would want this, so perhaps it should be configurable? Something like...

choice
	prompt "device_get_binding() behavior"
	depends on !DEVICE_STORE_NAME

config NO_DEVICE_GET_BINDING
	bool "No implementation"
	help
	  No device_get_binding() implementation will be provided.
	  Use of this function will cause build errors.

config NULL_DEVICE_GET_BINDING
	bool "NULL implementation"
	help
	  A stub device_get_binding() implementation will be provided
	  that returns NULL.

endchoice

with NO_DEVICE_GET_BINDING being the default behavior

Copy link
Member Author

Choose a reason for hiding this comment

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

We discussed this yesterday in dev-review, agreement was to disable device_get_binding completely, so you'll get a build failure if you can't really use this option.

@@ -951,6 +951,14 @@ config HAS_DYNAMIC_DEVICE_HANDLES
Hidden option that makes possible to manipulate device handles at
runtime.

config DEVICE_STORE_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems my above concern is already discussed here; I agree with @galak on this one, at least for the default.

@gmarull gmarull force-pushed the device-name-optional branch from 9f10be7 to de2cc84 Compare September 2, 2022 07:56
@gmarull
Copy link
Member Author

gmarull commented Sep 2, 2022

Sensor drivers and samples look good.
We need a test that builds with CONFIG_DEVICE_STORE_NAME=n

any suggestion? not sure where to test this

Maybe start with samples/basic/minimal? It's not exactly thorough, but it would be better than nothing.

disabled the option in this sample

@gmarull gmarull requested a review from galak September 2, 2022 08:21
@MaureenHelm MaureenHelm removed the dev-review To be discussed in dev-review meeting label Sep 7, 2022
Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

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

I'm all for the dev-review solution. One suggested doc improvement, but this looks good for v3.3 to me.

@gmarull gmarull force-pushed the device-name-optional branch from de2cc84 to ac83ac3 Compare September 19, 2022 08:53
@gmarull gmarull removed the request for review from mateusz-holenko September 19, 2022 08:54
@gmarull gmarull added this to the v3.3.0 milestone Sep 19, 2022
Rename the function to avoid clashed with the upcoming device_name_get.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
sd_gpio was checked for NULL using its name, so the condition was always
true. Check if the port (device) itself is NULL instead.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
@gmarull gmarull force-pushed the device-name-optional branch from ac83ac3 to 1fecfd6 Compare September 21, 2022 09:25
With the adoption of DEVICE_DT_GET() device names are in many cases
optional and used only for stuff like debugging or in shells. This patch
makes struct device name field optional so that ROM can be saved in case
user can afford it. This means that the name field in struct device
should no longer be accessed directly but using a new function:
device_name_get().

Note that the option controlling such feature is
CONFIG_DEVICE_STORE_NAME, enabled by default.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Since struct device name field is now optional, use device_name_get.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
CONFIG_DEVICE_STORE_NAME has the potential to reduce ROM usage in case
application images do not make use of device_get_binding(), so mention
it in the footprint documentation.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
Minimal sample is meant to show the minimum Zephyr ROM footprint.
Disable CONFIG_DEVICE_STORE_NAME since the option targets ROM footprint
reduction as well.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
@gmarull gmarull force-pushed the device-name-optional branch from 1fecfd6 to f5a2033 Compare September 21, 2022 10:04
@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Nov 21, 2022
@github-actions github-actions bot closed this Dec 5, 2022
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.

10 participants