Skip to content
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

API Change: IPM - callback improvement #26780

Merged
merged 7 commits into from Jul 30, 2020

Conversation

tbursztyka
Copy link
Collaborator

@tbursztyka tbursztyka commented Jul 9, 2020

  • Problem Description:

ipm_callback_t do not provide the IPM device's callback caller as parameter, forcing users to use the context parameter instead for this purpose, which in turn limits its usage (they cannot provide some private data, or have to mangle thing together storing the IPM dev pointer into the private data).

  • Proposed Change (detailed):

All other API provide the callback's caller device pointer, and thus adding it as first parameter to ipm_callback_t

  • Dependencies:

All users of ipm_register_callback() function need to adapt their callbacks accordingly.

@github-actions github-actions bot added area: API Changes to public APIs area: Samples Samples platform: NXP NXP platform: STM32 ST Micro STM32 labels Jul 9, 2020
@github-actions github-actions bot added the area: Tests Issues related to a particular existing or missing test label Jul 10, 2020
@tbursztyka tbursztyka removed area: Samples Samples area: Tests Issues related to a particular existing or missing test platform: NXP NXP platform: STM32 ST Micro STM32 labels Jul 10, 2020
@github-actions github-actions bot added area: Samples Samples area: Tests Issues related to a particular existing or missing test platform: NXP NXP platform: STM32 ST Micro STM32 labels Jul 10, 2020
@tbursztyka
Copy link
Collaborator Author

@carlescufi let's bring that one up at the next API meeting as well

@tbursztyka tbursztyka changed the title [RFC] IPM callback fix [RFC] API Change: IPM - callback improvement Jul 14, 2020
@tbursztyka tbursztyka added area: IPC Inter-Process Communication and removed area: Documentation area: Samples Samples area: Tests Issues related to a particular existing or missing test platform: NXP NXP platform: STM32 ST Micro STM32 labels Jul 14, 2020
@github-actions github-actions bot added area: Documentation area: Samples Samples area: Tests Issues related to a particular existing or missing test platform: NXP NXP platform: STM32 ST Micro STM32 labels Jul 14, 2020
@carlescufi
Copy link
Member

@nordic-krch and @anangl could you please take a look?

@@ -36,7 +37,8 @@ static void nrfx_ipc_handler(uint32_t event_mask, void *p_context)
__ASSERT(event_idx < NRFX_IPC_ID_MAX_VALUE,
"Illegal event_idx: %d", event_idx);
event_mask &= ~BIT(event_idx);
nrfx_ipm_data.callback(nrfx_ipm_data.callback_ctx,
nrfx_ipm_data.callback(nrfx_ipm_data.dev,
Copy link
Member

Choose a reason for hiding this comment

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

This is a single instance part of the driver, so you could use DEVICE_GET(ipm_nrf) here and avoid adding the dev field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

@@ -133,7 +135,8 @@ static void vipm_dispatcher(uint32_t event_mask, void *p_context)
event_mask &= ~BIT(event_idx);
if (nrfx_vipm_data.callback[event_idx] != NULL) {
nrfx_vipm_data.callback[event_idx]
(nrfx_vipm_data.callback_ctx[event_idx],
(nrfx_vipm_data.ipm_device,
Copy link
Member

Choose a reason for hiding this comment

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

The ipm_device field is currently not initialized. It is actually not used at all (looks like it's some remnant of an earlier version of the driver). You'll need to initialize it in vipm_nrf_init() to use it this way (and perhaps rename it to dev, to avoid confusion).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed, done

Copy link
Member

@anangl anangl Jul 27, 2020

Choose a reason for hiding this comment

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

I'm sorry, now I see I was wrong in my previous comment. This field should be changed to an array of struct device * and its entries should be initialized in vipm_nrf_##_idx##_register_callback() (like callback[_idx] and callback_ctx[_idx] are), not in vipm_nrf_init().

@tbursztyka tbursztyka force-pushed the ipm_callback_fix branch 2 times, most recently from 77b729a to 7e09b81 Compare July 27, 2020 11:12
@@ -36,7 +36,8 @@ static void nrfx_ipc_handler(uint32_t event_mask, void *p_context)
__ASSERT(event_idx < NRFX_IPC_ID_MAX_VALUE,
"Illegal event_idx: %d", event_idx);
event_mask &= ~BIT(event_idx);
nrfx_ipm_data.callback(nrfx_ipm_data.callback_ctx,
nrfx_ipm_data.callback(DEVICE_GET(ipm_nrf),
Copy link
Member

Choose a reason for hiding this comment

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

This requires also DEVICE_DECLARE(ipm_nrf); to be added above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh yes

@@ -133,7 +135,8 @@ static void vipm_dispatcher(uint32_t event_mask, void *p_context)
event_mask &= ~BIT(event_idx);
if (nrfx_vipm_data.callback[event_idx] != NULL) {
nrfx_vipm_data.callback[event_idx]
(nrfx_vipm_data.callback_ctx[event_idx],
(nrfx_vipm_data.ipm_device,
Copy link
Member

@anangl anangl Jul 27, 2020

Choose a reason for hiding this comment

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

I'm sorry, now I see I was wrong in my previous comment. This field should be changed to an array of struct device * and its entries should be initialized in vipm_nrf_##_idx##_register_callback() (like callback[_idx] and callback_ctx[_idx] are), not in vipm_nrf_init().

@tbursztyka
Copy link
Collaborator Author

@anangl For vipm: which device should it be? tDEVICE_GET(ipm_nrf) or the actual vipm? If it's the later, current change is fine. If it should be the first, then let's just use it as is, without .dev attribute.

@anangl
Copy link
Member

anangl commented Jul 27, 2020

@anangl For vipm: which device should it be? tDEVICE_GET(ipm_nrf) or the actual vipm? If it's the later, current change is fine. If it should be the first, then let's just use it as is, without .dev attribute.

@tbursztyka When CONFIG_IPM_NRF_SINGLE_INSTANCE is not enabled, there is no ipm_nrf device, but instead there are multiple devices (in count of NRFX_IPC_ID_MAX_VALUE) created here by UTIL_LISTIFY. Thus, dev pointer needs to be stored for each of them, and that needs to be done in vipm_nrf_##_idx##_register_callback(), as in vipm_nrf_init() you don't have _idx to access the corresponding array entry.

@tbursztyka
Copy link
Collaborator Author

Wait, that driver seems to be doing things upside down... why having one static struct vipm_nrf_data nrfx_vipm_data; when each and every vipm device could have its own static struct vipm_nrf_data nrfx_vipm_##idx##_data; (and the attributes there would not be arrays)?

That seems to add complexity for no reason.

@tbursztyka tbursztyka changed the title [RFC] API Change: IPM - callback improvement API Change: IPM - callback improvement Jul 28, 2020
@tbursztyka
Copy link
Collaborator Author

@anangl I have followed the change you advised. However, this vipm driver would definitely gain in simplicity by using device's private data instead of those arrays (it would require only an external static sturct device *ipc_device[NRFX_IPC_ID_MAX_VALUE]). That would save rom a bit, since the code would be shared for all instances, and ram usage would be the same.

@anangl
Copy link
Member

anangl commented Jul 28, 2020

However, this vipm driver would definitely gain in simplicity by using device's private data instead of those arrays.

I agree. I have no idea why the driver has been done this way. It's quite confusing, too. This unusual approach used here was the cause I was wrong in my initial comment. I just misunderstood it.

@tbursztyka tbursztyka force-pushed the ipm_callback_fix branch 2 times, most recently from 4fc927b to 813cf7a Compare July 29, 2020 07:21
@carlescufi carlescufi removed the DNM This PR should not be merged (Do Not Merge) label Jul 30, 2020
Tomasz Bursztyka added 7 commits July 30, 2020 09:49
Let's normalize the callback like it is done in other APIs.
This will avoid the need to do not so nice code (storing the ipm device
pointer as global, or else) and more importantly will help to move all
device instance to constant.

Fixes zephyrproject-rtos#26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Of course IPM drivers now provide their device instance. There are 2
drivers using IPM callbacks as well, so they get the imp device instance
pointer now through the callback.

Fixes zephyrproject-rtos#26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Applications using IPM callbacks get the imp device instance pointer
now through the callback. Which help to clarify a bit the code here and
there as well.

Fixes zephyrproject-rtos#26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Provide the IPM device pointer to the callback.

Fixes zephyrproject-rtos#26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
s/context/user_data

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
s/context/user_data

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Documenting the change.

Fixes zephyrproject-rtos#26923

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
@carlescufi carlescufi merged commit f0743df into zephyrproject-rtos:master Jul 30, 2020
Architecture Project automation moved this from In Progress to Done Jul 30, 2020
@tbursztyka tbursztyka deleted the ipm_callback_fix branch July 31, 2020 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Documentation area: IPC Inter-Process Communication area: Samples Samples area: Tests Issues related to a particular existing or missing test Breaking API Change Breaking changes to stable, public APIs platform: NXP NXP platform: STM32 ST Micro STM32
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants