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

rpmsg_virtio: configuration option to set buffer sizes per instance #328

Merged

Conversation

hubertmis
Copy link
Contributor

Fixes #322

Enable user of rpmsg_virtio to set sizes of TX and RX buffers per
created rpmsg_virtio instance. Each instance can use other buffer sizes.

Signed-off-by: Hubert Miś hubert.mis@nordicsemi.no

@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch 2 times, most recently from 807d53b to 30fc4ff Compare December 13, 2021 11:16
@hubertmis
Copy link
Contributor Author

I've tested this implementation with a Zephyr sample. Looks to work as expected

@@ -145,6 +157,36 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
struct metal_io_region *shm_io,
struct rpmsg_virtio_shm_pool *shpool);

/**
* rpmsg_init_vdev_with_config - initialize rpmsg virtio device
Copy link
Collaborator

Choose a reason for hiding this comment

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

initialize rpmsg virtio device with config ?

Comment on lines 163 to 178
* Initialize RPMsg virtio queues and shared buffers, the address of shm can be
* ANY. In this case, function will get shared memory from system shared memory
* pools. If the vdev has RPMsg name service feature, this API will create an
* name service endpoint.
*
* Slave side:
* This API will not return until the driver ready is set by the master side.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add here what config is?

Comment on lines 648 to 649
rvdev->config.txbuf_size = RPMSG_BUFFER_SIZE;
rvdev->config.rxbuf_size = RPMSG_BUFFER_SIZE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not but should we think about adding RPMSG_BUFFER_RX_SIZE and RPMSG_BUFFER_TX_SIZE as compile-time defines since we are now decoupling TX and RX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if anyone needs it, it could be implemented in other patch

@arnopo arnopo requested review from arnopo and edmooring December 14, 2021 10:08
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.

few minor remarks but LGTM

lib/rpmsg/rpmsg_virtio.c Outdated Show resolved Hide resolved
lib/rpmsg/rpmsg_virtio.c Outdated Show resolved Hide resolved
* @param shpool - pointer to shared memory pool. rpmsg_virtio_init_shm_pool has
* to be called first to fill this structure.
* @param config - pointer to configuration structure, if NULL default
* configuration is used like in @ref rpmsg_init_vdev
Copy link
Collaborator

Choose a reason for hiding this comment

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

confusing, proposal:
pointer to configuration structure, if NULL (like in @ref rpmsg_init_vdev) default configuration is used

@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch from 30fc4ff to 55e9a34 Compare December 14, 2021 11:31
if (config) {
rvdev->config = *config;
} else {
rvdev->config = RPMSG_VIRTIO_DEFAULT_CONFIG;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about just past RPMSG_VIRTIO_DEFAULT_CONFIG as argument in rpmsg_init_vdev function and suppress this condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would need some code to handle config == NULL. What do you suggest? Return RPMSG_ERR_PARAM?

@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch from 55e9a34 to 56f38cf Compare December 14, 2021 14:11
Copy link
Collaborator

@carlocaione carlocaione 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.

The substance of this looks good to go. Regarding the terminology changes, if they don't go in, I can pick them up in a subsequent push to #323, since I think this will probably go in first.

This pull request could serve as a model of how to do them right.

lib/include/openamp/rpmsg_virtio.h Show resolved Hide resolved
@@ -145,6 +164,39 @@ int rpmsg_init_vdev(struct rpmsg_virtio_device *rvdev,
struct metal_io_region *shm_io,
struct rpmsg_virtio_shm_pool *shpool);

/**
* rpmsg_init_vdev_with_config - initialize rpmsg virtio device with config
* Master side:
Copy link
Contributor

Choose a reason for hiding this comment

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

In keeping with the effort to remove potentially objectionable terminology, I suggest replacing "Master" and "Slave" with "Driver" and "Device" as in PR #323.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm changing Master and Slave here to Host and Remote. It seems this header should use RPMsg terminology (host/remote), not virtio (driver/device), because it operates on rpmsg instances.

* Sizes of virtio data buffers used by initialized RPMsg instance are set to
* values read from the passed configuration structure.
*
* Slave side:
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, replace "Slave" with "Device". Check throughout the PR.

* Master side:
* Initialize RPMsg virtio queues and shared buffers, the address of shm can be
* ANY. In this case, function will get shared memory from system shared memory
* pools. If the vdev has RPMsg name service feature, this API will create an
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor English fixups:
s/has RPMsg name service/has the RPMsg name service/
s/an$/a/

* ANY. In this case, function will get shared memory from system shared memory
* pools. If the vdev has RPMsg name service feature, this API will create an
* name service endpoint.
* Sizes of virtio data buffers used by initialized RPMsg instance are set to
Copy link
Contributor

Choose a reason for hiding this comment

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

s/initialized/the initialized/

@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch from 56f38cf to 19782c5 Compare December 20, 2021 08:50
@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch from 19782c5 to 935ab1c Compare December 20, 2021 08:51
lib/rpmsg/rpmsg_virtio.c Show resolved Hide resolved
/**
* struct rpmsg_virtio_config - configuration of rpmsg device based on virtio
* @txbuf_size: the tx buffer size, used to send data from host to remote
* @rxbuf_size: the rx buffer size, used to send data from remote to host
Copy link
Collaborator

Choose a reason for hiding this comment

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

Deeply reviewing your patch, look to me that, for an unfamiliar user, it is not easy to understand this structure.
My apologize for that because I should see it before... only the host use the config structure.
Another point is the notion of RX TX which is ambiguous. If only the host defines it, the remote gets the corresponding values from the vrings.

Here is a proposal to rework the structure

 * struct rpmsg_virtio_config - configuration of rpmsg device based on virtio
 *
 * This structure is use by the rpmsg virtio host to configure the virtiio layer.
 * 
 * @h2r_buf_size: the buffer size, used to send data from host to remote
 * @r2h_buf_size: the uffer size, used to send data from remote to host
 struct rpmsg_virtio_config {
	uint32_t h2r_buf_size;
	uint32_t r2h_buf_size;
}

/**
* struct rpmsg_virtio_device - representation of a rpmsg device based on virtio
* @rdev: rpmsg device, first property in the struct
* @config: structure containing device configuration
Copy link
Collaborator

Choose a reason for hiding this comment

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

@config: structure containing virtio configuration

@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch 2 times, most recently from 5e3c365 to 92a1aac Compare December 20, 2021 12:05
@hubertmis hubertmis requested a review from arnopo December 20, 2021 12:32
{
struct rpmsg_device *rdev;
const char *vq_names[RPMSG_NUM_VRINGS];
vq_callback callback[RPMSG_NUM_VRINGS];
int status;
unsigned int i, role;

role = rpmsg_virtio_get_role(rvdev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Segmentation fault during my non-reg tests because the rvdev->vdev->role is not yet set.
The block should be move after rdev = &rvdev->rdev;

@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch from 92a1aac to 73f61d0 Compare December 20, 2021 13:25
Enable user of rpmsg_virtio to set sizes of TX and RX buffers per
created rpmsg_virtio instance. Each instance can use other buffer sizes.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
Replacing potentially objectionable terms from the function description.
Language fixes.

Signed-off-by: Hubert Miś <hubert.mis@nordicsemi.no>
@hubertmis hubertmis force-pushed the pr/configurable-rpmsg-virio-buffer-size branch from 73f61d0 to 409ab20 Compare December 20, 2021 13:31
@hubertmis
Copy link
Contributor Author

One more update: I've silenced "unused config parameter" warning when building SLAVE_ONLY configuration.

@arnopo arnopo added this to the Release V2022.04 milestone Dec 22, 2021
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 arnopo merged commit a12d03c into OpenAMP:main Jan 4, 2022
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.

Make rpmsg buffer size customizable per rpmsg instance
5 participants