freebsd: Add support for multiple dpdk instances on FreeBSD
PATCH 1/1 freebsd: Add support for multiple dpdk instances on FreeBSD
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the nic_uio driver.
Add relevant parts in dpdk to support this.
--- config/rte_config.h | 2 + kernel/freebsd/contigmem/contigmem.c | 227 ++++++++++++++++++--------- lib/eal/common/eal_common_options.c | 2 + lib/eal/freebsd/eal.c | 12 ++ lib/eal/freebsd/eal_hugepage_info.c | 12 +- lib/eal/freebsd/eal_memory.c | 3 +- 6 files changed, 182 insertions(+), 76 deletions(-)
config/rte_config.h +2 -0
@@ -51,6 +51,8 @@#define RTE_MAX_VFIO_CONTAINERS 64/* bsd module defines */ +#define RTE_CONTIGMEM_DEFAULT_NUM_DEVS 1 +#define RTE_CONTIGMEM_MAX_NUM_DEVS 64#define RTE_CONTIGMEM_MAX_NUM_BUFS 64#define RTE_CONTIGMEM_DEFAULT_NUM_BUFS 1#define RTE_CONTIGMEM_DEFAULT_BUF_SIZE (512*1024*1024)
kernel/freebsd/contigmem/contigmem.c +157 -70
354 lines not on this page · raw message
lib/eal/common/eal_common_options.c +2 -0
@@ -313,11 +313,13 @@ eal_option_device_parse(void)const char *eal_get_hugefile_prefix (void ) { +#ifndef RTE_EXEC_ENV_FREEBSD const struct internal_config *internal_conf =eal_get_internal_configuration ();if (internal_conf->hugefile_prefix !=NULL )return internal_conf->hugefile_prefix; +#endif return HUGEFILE_PREFIX_DEFAULT ; }
lib/eal/freebsd/eal.c +12 -0
@@ -464,6 +464,18 @@ eal_parse_args(int argc, char **argv) }break ; } +case OPT_FILE_PREFIX_NUM : + { +char *prefix =strdup (optarg); +if (prefix ==NULL ) +EAL_LOG (ERR ,"Could not store file prefix" ); +else { +/* free old prefix */ +free (internal_conf->hugefile_prefix); + internal_conf->hugefile_prefix = prefix; + } +break ; + }case OPT_HELP_NUM :eal_usage (prgname);exit (EXIT_SUCCESS );
lib/eal/freebsd/eal_hugepage_info.c +7 -5
@@ -14,8 +14,6 @@#include "eal_internal_cfg.h" #include "eal_filesystem.h" -#define CONTIGMEM_DEV "/dev/contigmem" -/* * Uses mmap to create a shared memory area for storage of data * Used in this file to store the hugepage file map on disk
@@ -85,9 +83,13 @@ eal_hugepage_info_init(void)return -1 ; } - fd =open (CONTIGMEM_DEV ,O_RDWR ); +char contigmemdev[64 ]; +snprintf (contigmemdev,sizeof (contigmemdev),"/dev/%s" , + internal_conf->hugefile_prefix); + + fd =open (contigmemdev,O_RDWR );if (fd <0 ) { -EAL_LOG (ERR ,"could not open " CONTIGMEM_DEV ); +EAL_LOG (ERR ,"could not open %s" , contigmemdev);return -1 ; }if (flock (fd,LOCK_EX |LOCK_NB ) <0 ) {
@@ -105,7 +107,7 @@ eal_hugepage_info_init(void)EAL_LOG (INFO ,"Contigmem driver has %d buffers, each of size %dKB" , num_buffers, (int )(buffer_size>>10 )); -strlcpy (hpi->hugedir,CONTIGMEM_DEV ,sizeof (hpi->hugedir)); +strlcpy (hpi->hugedir, contigmemdev,sizeof (hpi->hugedir)); hpi->hugepage_sz = buffer_size; hpi->num_pages[0 ] = num_buffers; hpi->lock_descriptor = fd;
lib/eal/freebsd/eal_memory.c +2 -1
@@ -128,7 +128,8 @@ rte_eal_hugepage_init(void)* the previous one. */ snprintf (physaddr_str,sizeof (physaddr_str), -"hw.contigmem.physaddr.%d" , j); +"hw.contigmem.%s.%d" , + internal_conf->hugefile_prefix, j); error =sysctlbyname (physaddr_str, &physaddr, &sysctl_size,NULL ,0 );if (error <0 ) {
Signature · 1 line
2.44.0
PATCH 1/1 freebsd: Add support for multiple dpdk instances on FreeBSD
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the nic_uio driver.
Add relevant parts in dpdk to support this.
--- config/rte_config.h | 2 + kernel/freebsd/contigmem/contigmem.c | 225 ++++++++++++++++++--------- lib/eal/common/eal_common_options.c | 2 + lib/eal/freebsd/eal.c | 12 ++ lib/eal/freebsd/eal_hugepage_info.c | 12 +- lib/eal/freebsd/eal_memory.c | 3 +- 6 files changed, 180 insertions(+), 76 deletions(-)
config/rte_config.h +2 -0
@@ -51,6 +51,8 @@#define RTE_MAX_VFIO_CONTAINERS 64/* bsd module defines */ +#define RTE_CONTIGMEM_DEFAULT_NUM_DEVS 1 +#define RTE_CONTIGMEM_MAX_NUM_DEVS 64#define RTE_CONTIGMEM_MAX_NUM_BUFS 64#define RTE_CONTIGMEM_DEFAULT_NUM_BUFS 1#define RTE_CONTIGMEM_DEFAULT_BUF_SIZE (512*1024*1024)
kernel/freebsd/contigmem/contigmem.c +155 -70
352 lines not on this page · raw message
lib/eal/common/eal_common_options.c +2 -0
@@ -313,11 +313,13 @@ eal_option_device_parse(void)const char *eal_get_hugefile_prefix (void ) { +#ifndef RTE_EXEC_ENV_FREEBSD const struct internal_config *internal_conf =eal_get_internal_configuration ();if (internal_conf->hugefile_prefix !=NULL )return internal_conf->hugefile_prefix; +#endif return HUGEFILE_PREFIX_DEFAULT ; }
lib/eal/freebsd/eal.c +12 -0
@@ -464,6 +464,18 @@ eal_parse_args(int argc, char **argv) }break ; } +case OPT_FILE_PREFIX_NUM : + { +char *prefix =strdup (optarg); +if (prefix ==NULL ) +EAL_LOG (ERR ,"Could not store file prefix" ); +else { +/* free old prefix */ +free (internal_conf->hugefile_prefix); + internal_conf->hugefile_prefix = prefix; + } +break ; + }case OPT_HELP_NUM :eal_usage (prgname);exit (EXIT_SUCCESS );
lib/eal/freebsd/eal_hugepage_info.c +7 -5
@@ -14,8 +14,6 @@#include "eal_internal_cfg.h" #include "eal_filesystem.h" -#define CONTIGMEM_DEV "/dev/contigmem" -/* * Uses mmap to create a shared memory area for storage of data * Used in this file to store the hugepage file map on disk
@@ -85,9 +83,13 @@ eal_hugepage_info_init(void)return -1 ; } - fd =open (CONTIGMEM_DEV ,O_RDWR ); +char contigmemdev[64 ]; +snprintf (contigmemdev,sizeof (contigmemdev),"/dev/%s" , + internal_conf->hugefile_prefix); + + fd =open (contigmemdev,O_RDWR );if (fd <0 ) { -EAL_LOG (ERR ,"could not open " CONTIGMEM_DEV ); +EAL_LOG (ERR ,"could not open %s" , contigmemdev);return -1 ; }if (flock (fd,LOCK_EX |LOCK_NB ) <0 ) {
@@ -105,7 +107,7 @@ eal_hugepage_info_init(void)EAL_LOG (INFO ,"Contigmem driver has %d buffers, each of size %dKB" , num_buffers, (int )(buffer_size>>10 )); -strlcpy (hpi->hugedir,CONTIGMEM_DEV ,sizeof (hpi->hugedir)); +strlcpy (hpi->hugedir, contigmemdev,sizeof (hpi->hugedir)); hpi->hugepage_sz = buffer_size; hpi->num_pages[0 ] = num_buffers; hpi->lock_descriptor = fd;
lib/eal/freebsd/eal_memory.c +2 -1
@@ -128,7 +128,8 @@ rte_eal_hugepage_init(void)* the previous one. */ snprintf (physaddr_str,sizeof (physaddr_str), -"hw.contigmem.physaddr.%d" , j); +"hw.contigmem.%s.%d" , + internal_conf->hugefile_prefix, j); error =sysctlbyname (physaddr_str, &physaddr, &sysctl_size,NULL ,0 );if (error <0 ) {
Signature · 1 line
2.44.0
Quoted 7 lines · Tom Jones
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the
nic_uiodriver.Add relevant parts in dpdk to support this.
Signed-off-by Tom Jones <[email protected]> ---
Thanks for these patches, I hope to review and test them soon. From an initial quick scan through, I think the changes may be easier reviewed if split up into more than one patch. For example, could the changes to move the "SYSCTL_INT" declarations from being in global to local scope be separated out into one patch? Also, if the kernel module changes are backward compatible, they could be in a separate patch to the userspace changes to take advantage of the kernel module enhancements.
Is such a split possible or are all the changes tightly tied together?
/Bruce
PS: For sending new versions of this patch, or as a patchset, please add a version number so we can track what version is the latest one in patchwork and on the mailing list. [Use -v<N> flag to git format-patch] Thanks.
Hi Bruce,
thanks for letting me know
I'm not tied to anything particularly. This change isn't compatible with the previous API, but I'm not against making it so if that is really the best thing to do. As is, the dpdk changes and the contigmem changes need to come together because the API changes for getting the physical addresses.
It is just the sysctl paths that differ. I'm not sure what the compatibility needs to be for DPDK, for all of my usage I have built the kernel module with the package - making API changes easy.
I'm happy to follow which ever path you think is best.
Sorry for the patch confusion, I'll try to keep the sequence obvious going forward.
Tom
Quoted 24 lines · Bruce Richardson
Quoted 7 lines · Tom Jones
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the
nic_uiodriver.Add relevant parts in dpdk to support this.
Signed-off-by Tom Jones <[email protected]> ---Thanks for these patches, I hope to review and test them soon. From an initial quick scan through, I think the changes may be easier reviewed if split up into more than one patch. For example, could the changes to move the "
SYSCTL_INT" declarations from being in global to local scope be separated out into one patch? Also, if the kernel module changes are backward compatible, they could be in a separate patch to the userspace changes to take advantage of the kernel module enhancements.Is such a split possible or are all the changes tightly tied together?
/Bruce
PS: For sending new versions of this patch, or as a patchset, please add a version number so we can track what version is the latest one in patchwork and on the mailing list. [Use -v<N> flag to git format-patch] Thanks.
Signature · 1 line
- Tom
Quoted 6 lines · Tom Jones
Hi Bruce,
thanks for letting me know
I'm not tied to anything particularly. This change isn't compatible with the previous API, but I'm not against making it so if that is really the best thing to do. As is, the dpdk changes and the contigmem changes need to come together because the API changes for getting the physical addresses.
I don't think it's a major problem if the new kernel code doesn't work with the older DPDK userspace code, we can apply both together in one patch. However, it would count as an API/ABI change so would need to be deferred for merge to 24.11 release, I think.
Quoted 4 lines
It is just the sysctl paths that differ. I'm not sure what the compatibility needs to be for DPDK, for all of my usage I have built the kernel module with the package - making API changes easy.
I'm happy to follow which ever path you think is best.
I'll maybe give more thoughts on this once I try the patch out. Hopefully I'll get to test it out this afternoon. Don't bother trying to rework anything until then! :-)
Quoted 2 lines
Sorry for the patch confusion, I'll try to keep the sequence obvious going forward.
No problem. Thanks for the contribution here. FreeBSD support has sadly been lacking a number of features for some time now, so all changes to close the feature gap vs linux are very welcome!
/Bruce
Quoted 16 lines · Tom Jones
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the
nic_uiodriver.Add relevant parts in dpdk to support this.
Signed-off-by Tom Jones <[email protected]>--- config/rte_config.h | 2 + kernel/freebsd/contigmem/contigmem.c | 225 ++++++++++++++++++--------- lib/eal/common/eal_common_options.c | 2 + lib/eal/freebsd/eal.c | 12 ++ lib/eal/freebsd/eal_hugepage_info.c | 12 +- lib/eal/freebsd/eal_memory.c | 3 +- 6 files changed, 180 insertions(+), 76 deletions(-)
<snip>
kernel/freebsd/contigmem/contigmem.c contigmem_cdev_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot, · line 320
Quoted 11 lines
kernel/freebsd/contigmem/contigmem.c +4
-1@@ -238,10 +312,14 @@ contigmem_cdev_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot, {struct contigmem_vm_handle *vmh = handle;struct contigmem_buffer *buf; +struct contigmem_device *cd; - buf = &contigmem_buffers[vmh->buffer_index]; + cd = &contigmem_device_list[vmh->device_index]; + buf = &cd->cm_buffers[vmh->buffer_index]; + vmh, vmh->buffer_index, vmh->device_index, cd, buf, buf->refcnt);
The CI reports build failures with this patch, and the above is the offending line. Looking and comparing with the previous version, you've deleted a printf, but I think you missed the line continuation of it.
/Bruce
Quoted 7 lines · Tom Jones
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the
nic_uiodriver.Add relevant parts in dpdk to support this.
Signed-off-by Tom Jones <[email protected]>
Quoted 9 lines
--- config/rte_config.h | 2 + kernel/freebsd/contigmem/contigmem.c | 225 ++++++++++++++++++--------- lib/eal/common/eal_common_options.c | 2 + lib/eal/freebsd/eal.c | 12 ++ lib/eal/freebsd/eal_hugepage_info.c | 12 +- lib/eal/freebsd/eal_memory.c | 3 +- 6 files changed, 180 insertions(+), 76 deletions(-)
Hi Tom,
on testing this out the biggest gap I see is that we need a documentation update for it. In V3 can you please update the FreeBSD GSG doc with some details about how to use this feature.
Also, on first run using testpmd, the application failed to start, as I was missing a file-prefix option. At minimum I think the code needs to default the file-prefix on BSD to "contigmem0", so that when running a standalone app as before, it "just works". An idea for backward compatibility here that may help us, is to omit the "0" for contigmem0 device. That would mean that an older DPDK app will work with a newer kernel driver, and vice versa.
Beyond that, I'm not sure how to get multiple processes working right now (hence the doc update request!). When I run a second instance of DPDK on my system with "--file-prefix=contigmem1", I get errors about the shared config file in "/var/run/dpdk/rte/config".
/Bruce
Quoted 31 lines · Bruce Richardson
Quoted 7 lines · Tom Jones
Add support to the contigmem module on FreeBSD for multiple concurrent files, this enables running multiple dpdk instances with the
nic_uiodriver.Add relevant parts in dpdk to support this.
Signed-off-by Tom Jones <[email protected]>Quoted 9 lines
--- config/rte_config.h | 2 + kernel/freebsd/contigmem/contigmem.c | 225 ++++++++++++++++++--------- lib/eal/common/eal_common_options.c | 2 + lib/eal/freebsd/eal.c | 12 ++ lib/eal/freebsd/eal_hugepage_info.c | 12 +- lib/eal/freebsd/eal_memory.c | 3 +- 6 files changed, 180 insertions(+), 76 deletions(-)Hi Tom,
on testing this out the biggest gap I see is that we need a documentation update for it. In V3 can you please update the FreeBSD GSG doc with some details about how to use this feature.
Also, on first run using testpmd, the application failed to start, as I was missing a file-prefix option. At minimum I think the code needs to default the file-prefix on BSD to "contigmem0", so that when running a standalone app as before, it "just works". An idea for backward compatibility here that may help us, is to omit the "0" for contigmem0 device. That would mean that an older DPDK app will work with a newer kernel driver, and vice versa.
Quoted 5 lines
Beyond that, I'm not sure how to get multiple processes working right now (hence the doc update request!). When I run a second instance of DPDK on my system with "--file-prefix=contigmem1", I get errors about the shared config file in "
/var/run/dpdk/rte/config".
Inspiration struck me just after I hit send on this email. Removing the #ifdefs in eal_common_options.c allows me to run two processes in parallel just fine.
I think we need to consider how to rework this to avoid using the file-prefix argument for the contigmem files. Not sure what a better scheme is, though. Do you have any ideas or suggestions on this from your experience doing up this patch?
Thanks,
/Bruce
Quoted 20 lines
Quoted 15 lines
on testing this out the biggest gap I see is that we need a documentation update for it. In V3 can you please update the FreeBSD GSG doc with some details about how to use this feature.
Also, on first run using testpmd, the application failed to start, as I was missing a file-prefix option. At minimum I think the code needs to default the file-prefix on BSD to "contigmem0", so that when running a standalone app as before, it "just works". An idea for backward compatibility here that may help us, is to omit the "0" for contigmem0 device. That would mean that an older DPDK app will work with a newer kernel driver, and vice versa.
Quoted 5 lines
Beyond that, I'm not sure how to get multiple processes working right now (hence the doc update request!). When I run a second instance of DPDK on my system with "--file-prefix=contigmem1", I get errors about the shared config file in "
/var/run/dpdk/rte/config".
Quoted 8 lines
Inspiration struck me just after I hit send on this email. Removing the #ifdefs in
eal_common_options.callows me to run two processes in parallel just fine.I think we need to consider how to rework this to avoid using the file-prefix argument for the contigmem files. Not sure what a better scheme is, though. Do you have any ideas or suggestions on this from your experience doing up this patch?
Thanks for testing I'll fix these pieces up. I'll add a default to /dev/contigmem0, it'll fail to get the lock in normal use so it shouldn't be a problem.
I have done basically all of my testing through vpp, I can't say I've ever had much luck getting testpmd to do more than just start up. I resused the exist file-prefix interface as it allowed the smallest change to vpp[1]. I'm not normally a fan of such overloading, but it isn't so bad in this case.
I tried adding a compatible patch with the old /dev/contigmem and sysctl API, but it added a lot to the driver to handle a case I'm not sure we need.
I think my next steps should be:
- add a default for the file prefix
- documentation for the new option
with those I'll try to post a v3 patch this week.
- Tom
[1]: https://github.com/adventureloop/vpp/commit/d49be6e1958016c2d680c2e06e23c42988911aa7