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

virtio_mmio: Remove unneeded use of libmetal device #598

Merged
merged 2 commits into from
Jul 5, 2024

Conversation

glneo
Copy link
Contributor

@glneo glneo commented Jun 18, 2024

A virtual metal_device is created, then the needed IO regions are created and added to this device. Immediately we extract these same regions back out and make use of them. There is no reason to do this, instead simply use the created IO regions.

This also removes the need to have struct metal_device defined to have more than one IO region (METAL_MAX_DEVICE_REGIONS), which is not the default and can change per-platform. If the libmetal library was built with the default value for METAL_MAX_DEVICE_REGIONS, then this would have led to runtime failures.

A virtual metal_device is created, then the needed IO regions are created
and added to this device. Immediately we extract these same regions back
out and make use of them. There is no reason to do this, instead simply
use the created IO regions.

This also removes the need to have struct metal_device defined to have
more than one IO region (METAL_MAX_DEVICE_REGIONS), which is not the
default and can change per-platform. If the libmetal library was built
with the default value for METAL_MAX_DEVICE_REGIONS, then this would
have led to runtime failures.

Signed-off-by: Andrew Davis <[email protected]>
@tnmysh tnmysh requested review from xiaoxiang781216 and arnopo June 18, 2024 16:58
@arnopo arnopo requested review from edmooring, tnmysh and danmilea June 19, 2024 07:34
Copy link
Collaborator

@danmilea danmilea left a comment

Choose a reason for hiding this comment

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

Looks good to merge.

vmdev->cfg_io = metal_allocate_memory(sizeof(*vmdev->cfg_io));
metal_io_init(vmdev->cfg_io, (void *)cfg_mem_ptr,
(metal_phys_addr_t *)&vmdev->cfg_mem.base,
vmdev->cfg_mem.size, -1, 0, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm quite puzzled by this. One of the key principles of the OpenAMP library is to support static allocation s wherever possible. If we want to extend the virtio MMIO for AMP systems, we should also support "safe" allocation.

I can see two strategies:

  • Implement dynamic allocation with metal_allocate_memory() to have a robust memory allocator.
  • Declare allocations statically where possible.

The OpenAMP library uses static allocation for the virtio and rpmsg layers. For the virtio transport layer (remoteproc virtio), we have dynamic allocation.

I would be in favor here of implementing static allocation as proposed by @danmilea in danmilea/open-amp@ba16118.

I notice that there is another allocation in the virtio_mmio_register_device() function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, seems reasonable, adding a follow up patch to switch to static allocations here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And for the more general issue of dynamic allocations, I've been looking at the same as it would be a blocker for "safety".

I'd like to drop out those last couple dynamic allocations (move them to the application side, not hide them in the library as done today) but it would take a slight modification to the API. Specifically the allocations in rproc_virtio_create_vdev(). So to do any work on that we would want to make it an internal-only API which it should have been from the start.

Unfortunately as we don't separate internal from external APIs yet, someone used it in a Zephyr project sample. I've got a patch to fix that[0]. After that is in, we should mark that API internal-only so we can clean it up without breaking anyone.

glneo/zephyr@4acc5fc

Copy link
Collaborator

Choose a reason for hiding this comment

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

And for the more general issue of dynamic allocations, I've been looking at the same as it would be a blocker for "safety".

I'd like to drop out those last couple dynamic allocations (move them to the application side, not hide them in the library as done today) but it would take a slight modification to the API. Specifically the allocations in rproc_virtio_create_vdev(). So to do any work on that we would want to make it an internal-only API which it should have been from the start.

Unfortunately as we don't separate internal from external APIs yet, someone used it in a Zephyr project sample. I've got a patch to fix that[0]. After that is in, we should mark that API internal-only so we can clean it up without breaking anyone.

glneo/zephyr@4acc5fc

rproc_virtio_create_vdev() has been used to avoid to embed the remoteproc part of the library.
The use of the remoteproc add around 2kB of code and 200 bytes of data.

Another objective was to separate the remotproc layers from the remoteproc_virtio layer.

That said yes this part need to be reworked to support the resource table in safety context with static allocation.
What about a new API that would replace this one?

Make the metal_io_region for cfg_io and shm_io into full member structs
instead of just pointers. This means they will be allocated along with
the parent virtio_mmio_device struct and not need dynamically allocated
later.

Signed-off-by: Andrew Davis <[email protected]>
Copy link
Collaborator

@arnopo arnopo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@edmooring edmooring left a comment

Choose a reason for hiding this comment

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

Looks good to go.

@arnopo
Copy link
Collaborator

arnopo commented Jul 2, 2024

@danmilea : ok for you with the static allocation?

Copy link
Collaborator

@danmilea danmilea left a comment

Choose a reason for hiding this comment

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

Looks good to merge.

@arnopo arnopo merged commit fdb8bf3 into OpenAMP:main Jul 5, 2024
3 checks passed
@arnopo arnopo added this to the Release V2024.10 milestone Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants