app/test: fix mempool test failure on FreeBSD
PATCH 1/1 app/test: fix mempool test failure on FreeBSD
FreeBSD EAL does not implement rte_mem_virt2iova() that was used in mempool_autotest, causing it to fail:
EAL: Test assert test_mempool_flag_non_io_unset_when_populated_with_valid_iova line 781 failed: Cannot get IOVA
test failed at test_mempool():1030
Test Failed
Change unit test to use rte_memzone_reserve() to allocate memory, which allows to obtain IOVA directly.
Bugzilla ID: 863
--- app/test/test_mempool.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
app/test/test_mempool.c +15 -13
@@ -740,16 +740,17 @@ test_mempool_events_safety(void)static int test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) { -void *virt =NULL ; +const struct rte_memzone *mz =NULL ; +void *virt;rte_iova_t iova;size_t size =MEMPOOL_ELT_SIZE *16 ;struct rte_mempool *mp =NULL ;int ret; - virt =rte_malloc ("test_mempool" , size,rte_mem_page_size ()); -RTE_TEST_ASSERT_NOT_NULL (virt,"Cannot allocate memory" ); - iova =rte_mem_virt2iova (virt); -RTE_TEST_ASSERT_NOT_EQUAL (iova,RTE_BAD_IOVA ,"Cannot get IOVA" ); + mz =rte_memzone_reserve ("test_mempool" , size,SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mz,"Cannot allocate memory" ); + virt = mz->addr; + iova = mz->iova; mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE ,0 ,0 ,SOCKET_ID_ANY ,RTE_MEMPOOL_F_NO_IOVA_CONTIG );
@@ -772,14 +773,15 @@ test_mempool_flag_non_io_set_when_no_iova_contig_set(void) ret =TEST_SUCCESS ; exit:rte_mempool_free (mp); -rte_free (virt); +rte_memzone_free (mz);return ret; }static int test_mempool_flag_non_io_unset_when_populated_with_valid_iova (void ) { -void *virt =NULL ; +const struct rte_memzone *mz =NULL ; +void *virt;rte_iova_t iova;size_t total_size =MEMPOOL_ELT_SIZE *MEMPOOL_SIZE ;size_t block_size = total_size /3 ;
@@ -789,12 +791,12 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)/* * Since objects from the pool are never used in the test, * we don't care for contiguous IOVA, on the other hand, -* reiuring it could cause spurious test failures. +* reqiuring it could cause spurious test failures. */ - virt =rte_malloc ("test_mempool" , total_size,rte_mem_page_size ()); -RTE_TEST_ASSERT_NOT_NULL (virt,"Cannot allocate memory" ); - iova =rte_mem_virt2iova (virt); -RTE_TEST_ASSERT_NOT_EQUAL (iova,RTE_BAD_IOVA ,"Cannot get IOVA" ); + mz =rte_memzone_reserve ("test_mempool" , total_size,SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mz,"Cannot allocate memory" ); + virt = mz->addr; + iova = mz->iova; mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE ,0 ,0 ,SOCKET_ID_ANY ,0 );
@@ -827,7 +829,7 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) exit:rte_mempool_free (mp); -rte_free (virt); +rte_memzone_free (mz);return ret; }
Signature · 1 line
2.25.1
Hi Dmitry,
Quoted 8 lines · Dmitry Kozlyuk
FreeBSD EAL does not implement
rte_mem_virt2iova()that was used inmempool_autotest, causing it to fail:EAL: Test assert
test_mempool_flag_non_io_unset_when_populated_with_valid_iovaline 781 failed: Cannot get IOVA
test failed at test_mempool():1030
Test Failed
Quoted 8 lines
Change unit test to use
rte_memzone_reserve()to allocate memory, which allows to obtain IOVA directly.Bugzilla ID: 863
Fixes 11541c5c81dd ("mempool: add non-IO flag")Reported-by YuX Jiang <[email protected]>Signed-off-by Dmitry Kozlyuk <[email protected]>
However, I launched the test like this and it failed:
$ ./build/app/test/dpdk-test --no-huge -m 512 EAL: Detected CPU lcores: 12 EAL: Detected NUMA nodes: 1 EAL: Detected shared linkage of DPDK EAL: Multi-process socket /run/user/12489/dpdk/rte/mp_socket EAL: Selected IOVA mode 'VA' APP: HPET is not enabled, using TSC as default timer RTE>>mempool_autotest (...) EAL: Test assert test_mempool_events line 585 failed: Failed to populate mempool empty1: Success test failed at test_mempool():1019 Test Failed
It appears that the failure comes from:
intrte_mempool_populate_anon(struct rte_mempool *mp)
{
(...)
/* can't use MMAP_LOCKED, it does not exist on BSD */
if (rte_mem_lock(addr, size) < 0) {
=> rte_mem_unmap(addr, size);
return 0;
}The errno here is 12 (ENOMEM). This is because of the default ulimit for max locked memory: (kbytes, -l) 65536
If I increase it to 128000, it works.
Would it make sense to decrease the size of the pools so that we don't reach this limit?
(...)
app/test/test_mempool.c test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) · line 794
Quoted 6 lines
app/test/test_mempool.c +1
-1@@ -789,12 +791,12 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)/* * Since objects from the pool are never used in the test, * we don't care for contiguous IOVA, on the other hand, -* reiuring it could cause spurious test failures. +* reqiuring it could cause spurious test failures.
nice try :D
Quoted 64 lines
-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: 29 октября 2021 г. 12:35
To: Dmitry Kozlyuk <[email protected]>
Cc: [email protected]; YuX Jiang <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH] app/test: fix mempool test failure on FreeBSDExternal email: Use caution opening links or attachments
Hi Dmitry,
Quoted 4 lines · Dmitry Kozlyuk
FreeBSD EAL does not implement
rte_mem_virt2iova()that was used inmempool_autotest, causing it to fail:EAL: Test assert
test_mempool_flag_non_io_unset_when_populated_with_valid_iovaQuoted 4 lines
line 781 failed: Cannot get IOVA
test failed at test_mempool():1030
Test FailedQuoted 8 lines
Change unit test to use
rte_memzone_reserve()to allocate memory, which allows to obtain IOVA directly.Bugzilla ID: 863
Fixes 11541c5c81dd ("mempool: add non-IO flag")Reported-by YuX Jiang <[email protected]>Signed-off-by Dmitry Kozlyuk <[email protected]>Reviewed-by Olivier Matz <[email protected]>However, I launched the test like this and it failed:
$ ./build/app/test/dpdk-test --no-huge -m 512 EAL: Detected CPU lcores: 12 EAL: Detected NUMA nodes: 1 EAL: Detected shared linkage of DPDK EAL: Multi-process socket /run/user/12489/dpdk/rte/mp_socket EAL: Selected IOVA mode 'VA' APP: HPET is not enabled, using TSC as default timer RTE>>mempool_autotest (...) EAL: Test assert test_mempool_events line 585 failed: Failed to populate mempool empty1: Success test failed at test_mempool():1019 Test FailedIt appears that the failure comes from:
int
rte_mempool_populate_anon(struct rte_mempool *mp)
{
(...)/* can't use MMAP_LOCKED, it does not exist on BSD */ if (rte_mem_lock(addr, size) < 0) { => rte_mem_unmap(addr, size); return 0; }
Quoted 7 lines
The errno here is 12 (ENOMEM). This is because of the default ulimit for max locked memory: (kbytes, -l) 65536
If I increase it to 128000, it works.
Would it make sense to decrease the size of the pools so that we don't reach this limit?
Good catch, will send a v2.
Quoted 10 lines
(...)
Review
Quoted 1 line
(quoted diff) +0
-0@@ -789,12 +791,12 @@
test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)app/test/test_mempool.c test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) · line 794
Quoted 5 lines
app/test/test_mempool.c +1
-1/* * Since objects from the pool are never used in the test, * we don't care for contiguous IOVA, on the other hand, -* reiuring it could cause spurious test failures. +* reqiuring it could cause spurious test failures. nice try :D
v2 cover Mempool fixes for FreeBSD
In reply to Dmitry Kozlyukmempool_autotest was failing on FreeBSD,
because rte_virt2iova() is not implemented.
After the test started using memzones,
it appeared that in --no-huge memzones have iova=RTE_BAD_IOVA, which is unexpected and contradicts with selected IOVA-as-PA. Intead of working around this in the unit test,
fix FreeBSD EAL to select IOVA-as-VA in --no-huge mode.
v2:
* Add the EAL changes.
* Fix a failure with --no-huge (Olivier).
Dmitry Kozlyuk (3):
eal/freebsd: fix IOVA mode selection
app/test: fix mempool test on FreeBSD
app/test: fix mempool test in no-huge mode
app/test/test_mempool.c | 62 ++++++++++++++++++++++------------------- lib/eal/freebsd/eal.c | 37 ++++++++++++++++-------- 2 files changed, 58 insertions(+), 41 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 eal/freebsd: fix IOVA mode selection
FreeBSD EAL selected IOVA mode PA even in --no-huge mode where PA are not available. Memory zones were created with IOVA equal to RTE_BAD_IOVA with no indication this field is not usable.
Change IOVA mode detection:
1. Always allow to force --iova-mode=va.
2. In --no-huge mode, disallow forcing --iova-mode=pa, and select VA.
3. Otherwise select IOVA mode according to bus requests, default to PA. In case contigmem is inaccessible, memory initialization will fail with a message indicating the cause.
--- lib/eal/freebsd/eal.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
lib/eal/freebsd/eal.c +25 -12
@@ -677,6 +677,8 @@ rte_eal_init(int argc, char **argv)const struct rte_config *config =rte_eal_get_configuration ();struct internal_config *internal_conf =eal_get_internal_configuration (); +bool has_phys_addr; +enum rte_iova_mode iova_mode;/* checks if the machine is adequate */ if (!rte_cpu_is_supported ()) {
@@ -777,21 +779,32 @@ rte_eal_init(int argc, char **argv)return -1 ; } -/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ -if (internal_conf->iova_mode ==RTE_IOVA_DC ) { -/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); - -if (iova_mode ==RTE_IOVA_DC ) - iova_mode =RTE_IOVA_PA ; -rte_eal_get_configuration ()->iova_mode = iova_mode; - }else { -rte_eal_get_configuration ()->iova_mode = - internal_conf->iova_mode; +/* +* PA are only available for hugepages via contigmem. +* If contigmem is inaccessible, rte_eal_hugepage_init() will fail +* with a message describing the cause. +*/ + has_phys_addr = internal_conf->no_hugetlbfs ==0 ; + iova_mode = internal_conf->iova_mode; +if (iova_mode ==RTE_IOVA_PA && !has_phys_addr) { +rte_eal_init_alert ("Cannot use IOVA as 'PA' since physical addresses are not available" ); + rte_errno =EINVAL ; +return -1 ; + } +if (iova_mode ==RTE_IOVA_DC ) { +RTE_LOG (DEBUG ,EAL ,"Specific IOVA mode is not requested, autodetecting\n" ); +if (has_phys_addr) { +RTE_LOG (DEBUG ,EAL ,"Selecting IOVA mode according to bus requests\n" ); + iova_mode =rte_bus_get_iommu_class (); +if (iova_mode ==RTE_IOVA_DC ) + iova_mode =RTE_IOVA_PA ; + }else { + iova_mode =RTE_IOVA_VA ; + } } -RTE_LOG (INFO ,EAL ,"Selected IOVA mode '%s'\n" ,rte_eal_iova_mode () ==RTE_IOVA_PA ?"PA" :"VA" ); +rte_eal_get_configuration ()->iova_mode = iova_mode;if (internal_conf->no_hugetlbfs ==0 ) {/* rte_config isn't initialized yet */
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v2 1/3] eal/freebsd: fix IOVA mode selection
Quoted 66 lines · Dmitry Kozlyuk
FreeBSD EAL selected IOVA mode PA even in --no-huge mode where PA are not available. Memory zones were created with IOVA equal to
RTE_BAD_IOVAwith no indication this field is not usable.Change IOVA mode detection:
1. Always allow to force --iova-mode=va.
2. In --no-huge mode, disallow forcing --iova-mode=pa, and select VA.
3. Otherwise select IOVA mode according to bus requests, default to PA. In case contigmem is inaccessible, memory initialization will fail with a message indicating the cause.Fixes c2361bab70c5 ("eal: compute IOVA mode based on PA availability")Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/eal/freebsd/eal.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)lib/eal/freebsd/eal.c +20
-11@@ -677,6 +677,8 @@ rte_eal_init(int argc, char **argv)const struct rte_config *config =rte_eal_get_configuration ();struct internal_config *internal_conf =eal_get_internal_configuration (); +bool has_phys_addr; +enum rte_iova_mode iova_mode;/* checks if the machine is adequate */ if (!rte_cpu_is_supported ()) {@@ -777,21 +779,32 @@ rte_eal_init(int argc, char **argv)return -1 ; } -/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ -if (internal_conf->iova_mode ==RTE_IOVA_DC ) { -/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); - -if (iova_mode ==RTE_IOVA_DC ) - iova_mode =RTE_IOVA_PA ; -rte_eal_get_configuration ()->iova_mode = iova_mode; - }else { -rte_eal_get_configuration ()->iova_mode = - internal_conf->iova_mode; +/* +* PA are only available for hugepages via contigmem. +* If contigmem is inaccessible, rte_eal_hugepage_init() will fail +* with a message describing the cause. +*/ + has_phys_addr = internal_conf->no_hugetlbfs ==0 ; + iova_mode = internal_conf->iova_mode; +if (iova_mode ==RTE_IOVA_PA && !has_phys_addr) { +rte_eal_init_alert ("Cannot use IOVA as 'PA' since physical addresses are not available" ); + rte_errno =EINVAL ; +return -1 ; + } +if (iova_mode ==RTE_IOVA_DC ) { +RTE_LOG (DEBUG ,EAL ,"Specific IOVA mode is not requested, autodetecting\n" ); +if (has_phys_addr) { +RTE_LOG (DEBUG ,EAL ,"Selecting IOVA mode according to bus requests\n" ); + iova_mode =rte_bus_get_iommu_class (); +if (iova_mode ==RTE_IOVA_DC )
lib/eal/freebsd/eal.c rte_eal_init(int argc, char **argv) · line 808
Quoted 10 lines
lib/eal/freebsd/eal.c +5
-1+ iova_mode =RTE_IOVA_PA ; + }else { + iova_mode =RTE_IOVA_VA ; + } } -RTE_LOG (INFO ,EAL ,"Selected IOVA mode '%s'\n" ,rte_eal_iova_mode () ==RTE_IOVA_PA ?"PA" :"VA" ); +rte_eal_get_configuration ()->iova_mode = iova_mode;
This line needs to come before the log, or else the log statement needs to be changed to use iova_mode rather than rte_eal_iova_mode(). I'd suggest the former option.
With that change, you can add my ack to v2:
PATCH v2 2/3 app/test: fix mempool test on FreeBSD
In reply to Dmitry KozlyukFreeBSD EAL does not implement rte_mem_virt2iova() causing an error:
EAL: Test assert test_mempool_flag_non_io_unset_when_populated_with_valid_iova line 781 failed: Cannot get IOVA
test failed at test_mempool():1030
Test Failed
Change unit test to use rte_memzone_reserve() to allocate memory, which allows to obtain IOVA directly.
Bugzilla ID: 863
--- app/test/test_mempool.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
app/test/test_mempool.c +15 -13
@@ -740,16 +740,17 @@ test_mempool_events_safety(void)static int test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) { -void *virt =NULL ; +const struct rte_memzone *mz =NULL ; +void *virt;rte_iova_t iova;size_t size =MEMPOOL_ELT_SIZE *16 ;struct rte_mempool *mp =NULL ;int ret; - virt =rte_malloc ("test_mempool" , size,rte_mem_page_size ()); -RTE_TEST_ASSERT_NOT_NULL (virt,"Cannot allocate memory" ); - iova =rte_mem_virt2iova (virt); -RTE_TEST_ASSERT_NOT_EQUAL (iova,RTE_BAD_IOVA ,"Cannot get IOVA" ); + mz =rte_memzone_reserve ("test_mempool" , size,SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mz,"Cannot allocate memory" ); + virt = mz->addr; + iova = mz->iova; mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE ,0 ,0 ,SOCKET_ID_ANY ,RTE_MEMPOOL_F_NO_IOVA_CONTIG );
@@ -772,14 +773,15 @@ test_mempool_flag_non_io_set_when_no_iova_contig_set(void) ret =TEST_SUCCESS ; exit:rte_mempool_free (mp); -rte_free (virt); +rte_memzone_free (mz);return ret; }static int test_mempool_flag_non_io_unset_when_populated_with_valid_iova (void ) { -void *virt =NULL ; +const struct rte_memzone *mz =NULL ; +void *virt;rte_iova_t iova;size_t total_size =MEMPOOL_ELT_SIZE *MEMPOOL_SIZE ;size_t block_size = total_size /3 ;
@@ -789,12 +791,12 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)/* * Since objects from the pool are never used in the test, * we don't care for contiguous IOVA, on the other hand, -* reiuring it could cause spurious test failures. +* requiring it could cause spurious test failures. */ - virt =rte_malloc ("test_mempool" , total_size,rte_mem_page_size ()); -RTE_TEST_ASSERT_NOT_NULL (virt,"Cannot allocate memory" ); - iova =rte_mem_virt2iova (virt); -RTE_TEST_ASSERT_NOT_EQUAL (iova,RTE_BAD_IOVA ,"Cannot get IOVA" ); + mz =rte_memzone_reserve ("test_mempool" , total_size,SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mz,"Cannot allocate memory" ); + virt = mz->addr; + iova = mz->iova; mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE ,0 ,0 ,SOCKET_ID_ANY ,0 );
@@ -827,7 +829,7 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) exit:rte_mempool_free (mp); -rte_free (virt); +rte_memzone_free (mz);return ret; }
Signature · 1 line
2.25.1
PATCH v2 3/3 app/test: fix mempool test in no-huge mode
In reply to Dmitry KozlyukAmount of locked memory for regular users is limited, it is usually 64 KB by default.
Hitting this limit in rte_mempool_populate_anon() resulted in not populating the mempool, and a test case failure:
EAL: Test assert test_mempool_events line 585 failed: Failed to populate mempool empty1: Success test failed at test_mempool():1019
Test Failed
Decrease the amount of mapped anonymous memory to fit the limit. While there, make all function-local constants lowercase.
--- app/test/test_mempool.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
app/test/test_mempool.c +18 -16
@@ -515,17 +515,19 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))#undef RTE_TEST_TRACE_FAILURE#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) -static const size_t CB_NUM =3 ; -static const size_t MP_NUM =2 ; +static const size_t callback_num =3 ; +static const size_t mempool_num =2 ; +static const unsigned int mempool_elt_size =64 ; +static const unsigned int mempool_size =64 ; -struct test_mempool_events_data data[CB_NUM ]; -struct rte_mempool *mp[MP_NUM ], *freed; +struct test_mempool_events_data data[callback_num]; +struct rte_mempool *mp[mempool_num], *freed;char name[RTE_MEMPOOL_NAMESIZE ];size_t i, j;int ret;memset (mp,0 ,sizeof (mp)); -for (i =0 ; i <CB_NUM ; i++) { +for (i =0 ; i < callback_num; i++) { ret =rte_mempool_event_callback_register (test_mempool_events_cb, &data[i]); RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to register the callback %zu: %s",
@@ -541,12 +543,12 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))/* Create mempool 0 that will be observed by all callbacks. */ memset (&data,0 ,sizeof (data));strcpy (name,"empty0" ); - mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , -MEMPOOL_ELT_SIZE ,0 ,0 , + mp[0 ] =rte_mempool_create_empty (name, mempool_size, + mempool_elt_size,0 ,0 ,SOCKET_ID_ANY ,0 );RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , name,rte_strerror (rte_errno)); -for (j =0 ; j <CB_NUM ; j++) +for (j =0 ; j < callback_num; j++)RTE_TEST_ASSERT_EQUAL (data[j].invoked, false,"Callback %zu invoked on %s mempool creation" , j, name);
@@ -555,7 +557,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp)) ret =populate (mp[0 ]);RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , name,rte_strerror (-ret)); -for (j =0 ; j <CB_NUM ; j++) { +for (j =0 ; j < callback_num; j++) {RTE_TEST_ASSERT_EQUAL (data[j].invoked, true,"Callback %zu not invoked on mempool %s population" , j, name);
@@ -574,8 +576,8 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp)) rte_strerror(rte_errno));memset (&data,0 ,sizeof (data));strcpy (name,"empty1" ); - mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , -MEMPOOL_ELT_SIZE ,0 ,0 , + mp[1 ] =rte_mempool_create_empty (name, mempool_size, + mempool_elt_size,0 ,0 ,SOCKET_ID_ANY ,0 );RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , name,rte_strerror (rte_errno));
@@ -587,7 +589,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))"Unregistered callback 0 invoked on %s mempool populaton" , name); -for (i =0 ; i <MP_NUM ; i++) { +for (i =0 ; i < mempool_num; i++) {memset (&data,0 ,sizeof (data));sprintf (name,"empty%zu" , i);rte_mempool_free (mp[i]);
@@ -597,7 +599,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))*/ freed = mp[i]; mp[i] =NULL ; -for (j =1 ; j <CB_NUM ; j++) { +for (j =1 ; j < callback_num; j++) {RTE_TEST_ASSERT_EQUAL (data[j].invoked, true,"Callback %zu not invoked on mempool %s destruction" , j, name);
@@ -613,7 +615,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp)) name); } -for (j =1 ; j <CB_NUM ; j++) { +for (j =1 ; j < callback_num; j++) { ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, &data[j]); RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to unregister the callback %zu: %s",
@@ -622,10 +624,10 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))return TEST_SUCCESS ; fail: -for (j =0 ; j <CB_NUM ; j++) +for (j =0 ; j < callback_num; j++)rte_mempool_event_callback_unregister (test_mempool_events_cb, &data[j]); -for (i =0 ; i <MP_NUM ; i++) +for (i =0 ; i < mempool_num; i++)rte_mempool_free (mp[i]);return TEST_FAILED ;
Signature · 1 line
2.25.1
v3 cover Mempool fixes for FreeBSD
In reply to Dmitry Kozlyukmempool_autotest was failing on FreeBSD,
because rte_virt2iova() is not implemented.
After the test started using memzones,
it appeared that in --no-huge memzones have iova=RTE_BAD_IOVA, which is unexpected and contradicts with selected IOVA-as-PA. Intead of working around this in the unit test,
fix FreeBSD EAL to select IOVA-as-VA in --no-huge mode.
v3:
* Fix IOVA mode logging (Bruce).
v2:
* Add the EAL changes.
* Fix a failure with --no-huge (Olivier).
Dmitry Kozlyuk (3):
eal/freebsd: fix IOVA mode selection
app/test: fix mempool test on FreeBSD
app/test: fix mempool test in no-huge mode
app/test/test_mempool.c | 62 ++++++++++++++++++++++------------------- lib/eal/freebsd/eal.c | 37 ++++++++++++++++-------- 2 files changed, 58 insertions(+), 41 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/3 eal/freebsd: fix IOVA mode selection
FreeBSD EAL selected IOVA mode PA even in --no-huge mode where PA are not available. Memory zones were created with IOVA equal to RTE_BAD_IOVA with no indication this field is not usable.
Change IOVA mode detection:
1. Always allow to force --iova-mode=va.
2. In --no-huge mode, disallow forcing --iova-mode=pa, and select VA.
3. Otherwise select IOVA mode according to bus requests, default to PA. In case contigmem is inaccessible, memory initialization will fail with a message indicating the cause.
--- lib/eal/freebsd/eal.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
lib/eal/freebsd/eal.c +25 -12
@@ -677,6 +677,8 @@ rte_eal_init(int argc, char **argv)const struct rte_config *config =rte_eal_get_configuration ();struct internal_config *internal_conf =eal_get_internal_configuration (); +bool has_phys_addr; +enum rte_iova_mode iova_mode;/* checks if the machine is adequate */ if (!rte_cpu_is_supported ()) {
@@ -777,19 +779,30 @@ rte_eal_init(int argc, char **argv)return -1 ; } -/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ -if (internal_conf->iova_mode ==RTE_IOVA_DC ) { -/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); - -if (iova_mode ==RTE_IOVA_DC ) - iova_mode =RTE_IOVA_PA ; -rte_eal_get_configuration ()->iova_mode = iova_mode; - }else { -rte_eal_get_configuration ()->iova_mode = - internal_conf->iova_mode; +/* +* PA are only available for hugepages via contigmem. +* If contigmem is inaccessible, rte_eal_hugepage_init() will fail +* with a message describing the cause. +*/ + has_phys_addr = internal_conf->no_hugetlbfs ==0 ; + iova_mode = internal_conf->iova_mode; +if (iova_mode ==RTE_IOVA_PA && !has_phys_addr) { +rte_eal_init_alert ("Cannot use IOVA as 'PA' since physical addresses are not available" ); + rte_errno =EINVAL ; +return -1 ; } - +if (iova_mode ==RTE_IOVA_DC ) { +RTE_LOG (DEBUG ,EAL ,"Specific IOVA mode is not requested, autodetecting\n" ); +if (has_phys_addr) { +RTE_LOG (DEBUG ,EAL ,"Selecting IOVA mode according to bus requests\n" ); + iova_mode =rte_bus_get_iommu_class (); +if (iova_mode ==RTE_IOVA_DC ) + iova_mode =RTE_IOVA_PA ; + }else { + iova_mode =RTE_IOVA_VA ; + } + } +rte_eal_get_configuration ()->iova_mode = iova_mode;RTE_LOG (INFO ,EAL ,"Selected IOVA mode '%s'\n" ,rte_eal_iova_mode () ==RTE_IOVA_PA ?"PA" :"VA" );
Signature · 1 line
2.25.1
PATCH v3 2/3 app/test: fix mempool test on FreeBSD
In reply to Dmitry KozlyukFreeBSD EAL does not implement rte_mem_virt2iova() causing an error:
EAL: Test assert test_mempool_flag_non_io_unset_when_populated_with_valid_iova line 781 failed: Cannot get IOVA
test failed at test_mempool():1030
Test Failed
Change unit test to use rte_memzone_reserve() to allocate memory, which allows to obtain IOVA directly.
Bugzilla ID: 863
--- app/test/test_mempool.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
app/test/test_mempool.c +15 -13
@@ -740,16 +740,17 @@ test_mempool_events_safety(void)static int test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) { -void *virt =NULL ; +const struct rte_memzone *mz =NULL ; +void *virt;rte_iova_t iova;size_t size =MEMPOOL_ELT_SIZE *16 ;struct rte_mempool *mp =NULL ;int ret; - virt =rte_malloc ("test_mempool" , size,rte_mem_page_size ()); -RTE_TEST_ASSERT_NOT_NULL (virt,"Cannot allocate memory" ); - iova =rte_mem_virt2iova (virt); -RTE_TEST_ASSERT_NOT_EQUAL (iova,RTE_BAD_IOVA ,"Cannot get IOVA" ); + mz =rte_memzone_reserve ("test_mempool" , size,SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mz,"Cannot allocate memory" ); + virt = mz->addr; + iova = mz->iova; mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE ,0 ,0 ,SOCKET_ID_ANY ,RTE_MEMPOOL_F_NO_IOVA_CONTIG );
@@ -772,14 +773,15 @@ test_mempool_flag_non_io_set_when_no_iova_contig_set(void) ret =TEST_SUCCESS ; exit:rte_mempool_free (mp); -rte_free (virt); +rte_memzone_free (mz);return ret; }static int test_mempool_flag_non_io_unset_when_populated_with_valid_iova (void ) { -void *virt =NULL ; +const struct rte_memzone *mz =NULL ; +void *virt;rte_iova_t iova;size_t total_size =MEMPOOL_ELT_SIZE *MEMPOOL_SIZE ;size_t block_size = total_size /3 ;
@@ -789,12 +791,12 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)/* * Since objects from the pool are never used in the test, * we don't care for contiguous IOVA, on the other hand, -* reiuring it could cause spurious test failures. +* requiring it could cause spurious test failures. */ - virt =rte_malloc ("test_mempool" , total_size,rte_mem_page_size ()); -RTE_TEST_ASSERT_NOT_NULL (virt,"Cannot allocate memory" ); - iova =rte_mem_virt2iova (virt); -RTE_TEST_ASSERT_NOT_EQUAL (iova,RTE_BAD_IOVA ,"Cannot get IOVA" ); + mz =rte_memzone_reserve ("test_mempool" , total_size,SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mz,"Cannot allocate memory" ); + virt = mz->addr; + iova = mz->iova; mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE ,0 ,0 ,SOCKET_ID_ANY ,0 );
@@ -827,7 +829,7 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) exit:rte_mempool_free (mp); -rte_free (virt); +rte_memzone_free (mz);return ret; }
Signature · 1 line
2.25.1
PATCH v3 3/3 app/test: fix mempool test in no-huge mode
In reply to Dmitry KozlyukAmount of locked memory for regular users is limited, it is usually 64 KB by default.
Hitting this limit in rte_mempool_populate_anon() resulted in not populating the mempool, and a test case failure:
EAL: Test assert test_mempool_events line 585 failed: Failed to populate mempool empty1: Success test failed at test_mempool():1019
Test Failed
Decrease the amount of mapped anonymous memory to fit the limit. While there, make all function-local constants lowercase.
--- app/test/test_mempool.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
app/test/test_mempool.c +18 -16
@@ -515,17 +515,19 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))#undef RTE_TEST_TRACE_FAILURE#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) -static const size_t CB_NUM =3 ; -static const size_t MP_NUM =2 ; +static const size_t callback_num =3 ; +static const size_t mempool_num =2 ; +static const unsigned int mempool_elt_size =64 ; +static const unsigned int mempool_size =64 ; -struct test_mempool_events_data data[CB_NUM ]; -struct rte_mempool *mp[MP_NUM ], *freed; +struct test_mempool_events_data data[callback_num]; +struct rte_mempool *mp[mempool_num], *freed;char name[RTE_MEMPOOL_NAMESIZE ];size_t i, j;int ret;memset (mp,0 ,sizeof (mp)); -for (i =0 ; i <CB_NUM ; i++) { +for (i =0 ; i < callback_num; i++) { ret =rte_mempool_event_callback_register (test_mempool_events_cb, &data[i]); RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to register the callback %zu: %s",
@@ -541,12 +543,12 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))/* Create mempool 0 that will be observed by all callbacks. */ memset (&data,0 ,sizeof (data));strcpy (name,"empty0" ); - mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , -MEMPOOL_ELT_SIZE ,0 ,0 , + mp[0 ] =rte_mempool_create_empty (name, mempool_size, + mempool_elt_size,0 ,0 ,SOCKET_ID_ANY ,0 );RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , name,rte_strerror (rte_errno)); -for (j =0 ; j <CB_NUM ; j++) +for (j =0 ; j < callback_num; j++)RTE_TEST_ASSERT_EQUAL (data[j].invoked, false,"Callback %zu invoked on %s mempool creation" , j, name);
@@ -555,7 +557,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp)) ret =populate (mp[0 ]);RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , name,rte_strerror (-ret)); -for (j =0 ; j <CB_NUM ; j++) { +for (j =0 ; j < callback_num; j++) {RTE_TEST_ASSERT_EQUAL (data[j].invoked, true,"Callback %zu not invoked on mempool %s population" , j, name);
@@ -574,8 +576,8 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp)) rte_strerror(rte_errno));memset (&data,0 ,sizeof (data));strcpy (name,"empty1" ); - mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , -MEMPOOL_ELT_SIZE ,0 ,0 , + mp[1 ] =rte_mempool_create_empty (name, mempool_size, + mempool_elt_size,0 ,0 ,SOCKET_ID_ANY ,0 );RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , name,rte_strerror (rte_errno));
@@ -587,7 +589,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))"Unregistered callback 0 invoked on %s mempool populaton" , name); -for (i =0 ; i <MP_NUM ; i++) { +for (i =0 ; i < mempool_num; i++) {memset (&data,0 ,sizeof (data));sprintf (name,"empty%zu" , i);rte_mempool_free (mp[i]);
@@ -597,7 +599,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))*/ freed = mp[i]; mp[i] =NULL ; -for (j =1 ; j <CB_NUM ; j++) { +for (j =1 ; j < callback_num; j++) {RTE_TEST_ASSERT_EQUAL (data[j].invoked, true,"Callback %zu not invoked on mempool %s destruction" , j, name);
@@ -613,7 +615,7 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp)) name); } -for (j =1 ; j <CB_NUM ; j++) { +for (j =1 ; j < callback_num; j++) { ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, &data[j]); RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to unregister the callback %zu: %s",
@@ -622,10 +624,10 @@ test_mempool_events(int (*populate)(struct rte_mempool *mp))return TEST_SUCCESS ; fail: -for (j =0 ; j <CB_NUM ; j++) +for (j =0 ; j < callback_num; j++)rte_mempool_event_callback_unregister (test_mempool_events_cb, &data[j]); -for (i =0 ; i <MP_NUM ; i++) +for (i =0 ; i < mempool_num; i++)rte_mempool_free (mp[i]);return TEST_FAILED ;
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v3 0/3] Mempool fixes for FreeBSD
In reply to Dmitry Kozlyuk02/11/2021 11:08, Dmitry Kozlyuk:
Quoted 14 lines
mempool_autotestwas failing on FreeBSD,
becauserte_virt2iova()is not implemented.
After the test started using memzones,
it appeared that in --no-huge memzones have iova=RTE_BAD_IOVA, which is unexpected and contradicts with selected IOVA-as-PA. Intead of working around this in the unit test,
fix FreeBSD EAL to select IOVA-as-VA in --no-huge mode.v3:
* Fix IOVA mode logging (Bruce).
v2:
* Add the EAL changes.
* Fix a failure with --no-huge (Olivier).
Quoted 4 lines
Dmitry Kozlyuk (3):
eal/freebsd: fix IOVA mode selection
app/test: fix mempool test on FreeBSD
app/test: fix mempool test in no-huge mode
Series applied, thanks.