-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
ipc: icmsg & icbmsg: Add support for the nrf5340bsim #78390
Conversation
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
d266165
to
878a2a1
Compare
@maje-emb , please have a look. |
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 am against doing it the way proposed. This is quite intrusive into ipc service with next to no value in itself. We will now need to track if the new posix related macros don't break compatibility and security of the ipc.
@aescolar, isn't it enough to remap buffers defined on dts level (i.e., entire memory passed to ipc service)? I expect you already tried this but I wonder why every pointer needs to be mapped separately.
blocking until we understand the impact
If I understand correctly the problem comes from the fact that addresses passed in dts are from HW world and do not exist in virtual space mapping. If this is a problem then fixing address on configuration of buffers should be enough as all addresses used in ipc are calculated from it (offset from start). I wonder if you could not simply mmap some memory into this specific range for the process running the simulation. If it is not used it should work. You could try to mmap a (ram based) file there. This could be done at this fake sim board initialization time and so nothing in the system would be aware that any mapping actually took place. |
something like that
|
Yes, the problem is that addresses are indeed the HW addresses which come from DT.
A proof of concept of this can be seen here #78295. But unfortunately this direction is not tenable. It became immediately evident that ASan breaks with this approach. And it is likely that other libraries or tooling may also, if not now, some time in the future. Another option which was tried was to change (at preprocessor time) the addresses when building for these simulated targets. So instead of using the DT provided address, we'd refer to a constant pointer known at link time. This is how it is done today for static vrings. Unfortunately given the amount of macrology around the initialization of icbmsg, this proved much worse than one could hope. Specially as the Tx and Rx buffers are crossed in each side of the channel. A quick trial can be seen here: #78109. Generalizing this to N MCUs with the current design would lead to way too many macros too difficult to maintain. (If instead of defining 2 buffers in DT, we'd define just one buffer, and a direction (so the buffer is used as two halves by the code at init), it would be easier). I also considered offsetting the DT address (also at preprocessor time), offsetting 0x2000_0000 to a buffer whose address is known at link time, where that buffer represent the whole global memory. That solution would be ok for the nrf5340, but would easily became quite cumbersome if we have different processors using different common memories. That's why I leaned for a solution which changes the configured addresses at runtime for simulated targets. Note there is no penalty for the embedded targets. Neither in executed code or memory layout (what is const remains const).
We are just remapping the pointers set from DT macros. The macros that initialize the config structure are already pre-initializing all those pointers. Unfortunately there is not just 1 pointer set from DT, there is all of those to which the DT address propagates thru several layers of macros. |
include/zephyr/ipc/pbuf.h
Outdated
* Remap the pbuf memory pointers into something which can be used in the native simulated | ||
* targets | ||
*/ | ||
void pbuf_native_addr_remap(struct pbuf *pb); |
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.
Maybe make this function more consistent, because right now calling it depends on few conditions. It is automatically called in init
function, but if you not calling init
then you have to call it directly. If CONFIG_ARCH_POSIX
is enabled, you have to call it. Otherwise, you don't.
I suggest calling this function always before using pb
. Even before pbuf_init
. if CONFIG_ARCH_POSIX
it can be empty static inline function. This will make it clearer when to use it and we avoid additional #if
s when calling it.
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.
Also, please update the comment to be doxygen-compatible and add statement when it must be called.
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.
Thank you very much for the review. I updated the PR content with what we just discussed on the phone.
ssize_t is not part of the C library ISO standard subset, and as such one cannot expect a C library to expose the type by default. Some libraries like glibc do not expose this type in general, and trying to build using them results in build errors. There is 3 possible options: 1. Continue using ssize_t and: 1.a define _POSIX_C_SOURCE before including any header 1.b include sys/types.h directly (A bit uglier) 3. Not use ssize_t, and instead rely on ISO standard types Let's just go with 1.a assuming we want to keep using this type, as that is the correct way of getting this type defined. Signed-off-by: Alberto Escolar Piedras <[email protected]>
Update the HW models module to: 85944c64f224406e4d781aa382c5f1f71ed307fd Including the following: * 5340: Allocate a buffer for the APP core RAM (2nd version) * 82ca90c Add NCS test-spec.yml to trigger downstream CI job * a05d7a6 docs: top README: Mention nrf54l15 support and minor fixes * cd64524 54 ECB/CCM tests: Remove comment which does not apply Signed-off-by: Alberto Escolar Piedras <[email protected]>
Add a function which can be used to remap embedded device address, into addresses which can be used in the simulated native boards. For the nrf_bsim boards we provide an actual implementation. For other boards, we provide an optional dummy version which does nothing. It is up to each board implementation to decide if they want to provide one or use the dummy. Signed-off-by: Alberto Escolar Piedras <[email protected]>
326a3fa
to
30208ca
Compare
Provide a new function for initializing the Rx side, so users do not need to initialize the pointers by hand if they did not use PBUF_DEFINE(). Let's also rename pbuf_init() to pbuf_tx_init() to clearly signify the previous function was only meant to be used by the Tx side. Signed-off-by: Alberto Escolar Piedras <[email protected]>
Add support in this IPC backends for POSIX arch targets in general, and ensure the nrf5340bsim defines the buffer which will be used. Signed-off-by: Alberto Escolar Piedras <[email protected]>
Enable this sample for the nrf5340bsim Signed-off-by: Alberto Escolar Piedras <[email protected]>
Enable this sample for the nrf5340bsim Signed-off-by: Alberto Escolar Piedras <[email protected]>
Enable this sample for the nrf5340bsim Signed-off-by: Alberto Escolar Piedras <[email protected]>
30208ca
to
549e755
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.
Considering the situation I see we will have to accept this changes. I think it would be best to find a long term solution hiding the simulator quirks into some porting layer. I understand however this cannot be done at this point and we need to go on.
Since Dominik is ok, I don't see a reason to nack it.
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.
a minor comment else LGTM
/* Initialize local copies of rx_pb. */ | ||
dev_data->rx_pb->data.wr_idx = 0; | ||
dev_data->rx_pb->data.rd_idx = 0; | ||
(void)pbuf_rx_init(dev_data->rx_pb); |
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.
if you don't treat the error returned would be nice to have a comment explaining why
Add support in these IPC backends for the nrf5340bsim.
And enable these backends samples/tests for this board so they are also runtime tested in CI.
Fixes #78099
The driver of this PR is that these IPC backends are configured from Device Tree at build time, with whatever hardcoded address is given on it.
But in the "native" (POSIX arch) targets (when we built for workstation testing) we cannot write to some hardcoded address. All addresses are determined at link time.
In this PR, we ifdef calls during the backend init to replace the hardcoded address with something which can be used in workstation testing. (And together with it, we need to conditionally remove the
const
in the structures which hold those pointers we modify at runtime).The change does not have any effect for embedded targets.
This PR supersedes #78109. Unlike that PR, this replaces the pointers during init. As trying to replace them in the macros was not really possible in a generic way.
The PR contains: