-
Notifications
You must be signed in to change notification settings - Fork 296
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
Use new VIRTIO_{DRIVER,DEVICE}_SUPPORT compiler define to improve code readability #560
Conversation
Hello @glneo Your proposal seems making code more readable. Nevertheless I have few concerns
|
c17bba3
to
e8d3a7e
Compare
Hi @arnopo,
Unless what you are saying is that you have changes in a downstream fork of this project that makes use of this flag. In which case I'd like to know the policy on that. For instance the Linux kernel is very clear that downstream forks need not be considered when making changes to internal code. Otherwise how could one make any change without risking breaking some fork that they have no visibility into?
|
Having more optimized code for device mode is required for device role as coprocessor can be limited in term of memories.
That true for project based on cmake but not for project that use the code without cmake pre-build step.
You can refer to https://www.openampproject.org/governance/ for the rule we expect to apply on OpenAMP. In this PR following the deprecated rule seems quite simple, so I don't see a a reason to make an exception. |
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.
VIRTIO_DEVICE_ONLY
andVIRTIO_DRIVER_ONLY
have to be marked as deprecatedVIRTIO_MASTER_ONLY
andVIRTIO_MASTER_ONLY
can be removed (in a separate commit) as now deprecated since 2 years (Replace potentially objectionable terms in OpenAMP variable names. #323)
lib/remoteproc/remoteproc.c
Outdated
#ifdef VIRTIO_DRIVER_ONLY | ||
role = (role != VIRTIO_DEV_DRIVER) ? 0xFFFFFFFFUL : role; | ||
#endif | ||
if (role == VIRTIO_DEV_DRIVER && !VIRTIO_DRIVER_SUPPORT) { |
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.
would prefer to keep #if
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.
Sure, no problem.
lib/remoteproc/remoteproc.c
Outdated
role = (role != VIRTIO_DEV_DRIVER) ? 0xFFFFFFFFUL : role; | ||
#endif | ||
if (role == VIRTIO_DEV_DRIVER && !VIRTIO_DRIVER_SUPPORT) { | ||
metal_log(METAL_LOG_ERROR, "VirtIO role is set to Driver, but Driver support is not enabled\n"); |
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.
Do we really need this debug message? It adds extra footprint for a prebuild configuration issue.
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.
Not sure what you mean by a prebuild configuration issue? The variable role
is passed in by the user of this API function remoteproc_create_virtio()
at runtime. If the library was built without VIRTIO_DRIVER_SUPPORT
and later the user wants the created virtio to have the "driver" role, then it will fail at runtime.
There is another check that both driver
and device
support have been disabled (which would be a build configuration issue), that is a different check.
Either way, I can remove this message and keep the old behavior of just quietly returning NULL here.
What projects? This project is cmake based. It builds a library that can be used by other projects that may not be cmake based, but that doesn't change this project. Unless you are saying you are directly building/copy/pasting the source from this repo into the build of another project. The API must be defined as the function prototypes in
I'll make the change to keep this PR moving along, but as stated above, I do not agree with the reasoning. Might be worth chatting out what constitutes the "API" in the next meeting. |
If the issue is that the define is not obvious or masks that the optimization is intended, we could use that
Which I think makes it very clear now that this is a preprocessor level check. It also matches what U-Boot is now doing to remove its #ifdef messiness. |
7f4cda0
to
e4842e6
Compare
CMake can be used to configure a project, but it does not necessarily impose building a library. The objective here is to not break compatibility with some existing legacy projects, when possible. We don't know all the users. In such an environment, the work you are doing to rationalize the APIs is very important because it will help with maintainability. We just need to move forward step by step.
That's a good Idea, let's put this on the agenda for next meeting. |
9574620
to
3b609d4
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.
Need to fix zephyr issue else as discussed in meeting ok to go in this way . If we detect that this generate extra footprint we some compiler we will come back to #if
solution
lib/include/openamp/virtio.h
Outdated
@@ -101,6 +101,8 @@ __deprecated static inline int deprecated_virtio_dev_slave(void) | |||
#warning "VIRTIO_DEVICE_ONLY is deprecated, please use VIRTIO_DRIVER_SUPPORT=0" | |||
#endif | |||
|
|||
#define IS_ENABLED(option) (option == 1) |
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.
Seems that this creates a redefinition issue in Zephyr context.
Perhaps this define should be in a separate include that only been includes by open_amp source file.
What about adding a include/internal/utilities.h file for that?
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.
Seems that doesn't work either, if any source file includes the new utilities.h but also is built in the Zephyr context which also has IS_ENABLED() defined due to inclusions from libmetal
, we get the same issue.
Simple solution is to change this to a unique name, since this is for checking if virtio
options are enabled, I'll just rename it to VIRTIO_ENABLED
.
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.
Fair enough, if we need a more generic macro for some other config we will address that later.
3b609d4
to
c7c8f23
Compare
Also, the long line checkpatch warnings will be fixed in the next PR. |
Please fix that is in this PR, checkpatch success is requested before we merge the PR |
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.
LGTM after fixing checkpatch report
Currently compiler defines are defined when support for driver or device is the only support being built. This is a negative define, it surrounds the code to not be built and we use ifndef. This is confusing. It also leaves ifndefs all throughout the code-base. Instead, define a macro that is set to 1 if support is enabled. Use this inline in if statements where possible. Any sane compiler will optimize away the code in the branch when support is not enabled just the same as when using the preprocessor so we keep the same binary size. Signed-off-by: Andrew Davis <[email protected]>
Checks if this symbol is defined and set to equal 1. Used to make it more clear that a preprocessor level check is intended. Signed-off-by: Andrew Davis <[email protected]>
There is a common pattern of checking the virtio role while also checking that this role is supported in this build, which can help optimize away unusable code. Add a couple macros for this. This has two main benefits, first being shorter and easier to read if statements, and also makes it easier to not forget to always do both checks. Use these everywhere except rpmsg_virtio.c which needs one more refactor before we can switch it over. Signed-off-by: Andrew Davis <[email protected]>
c7c8f23
to
e969802
Compare
Fair enough, I've added one extra patch to this series which I was going to send as part of a different PR, but it fixes the long line warnings and hopefully is trivial enough. |
Currently compiler defines are defined when support for driver or device is the only support being built. This is a negative define, it surrounds the code to not be built and we use ifndef. This is confusing. It also leaves ifndefs all throughout the code-base. Instead, define a macro that is set to 1 if support is enabled. Use this inline in if statements where possible. Any sane compiler will optimize away the code in the branch when support is not enabled just the same as when using the preprocessor so we keep the same binary size.