mempool: sort the rte_mempool_ops by name
PATCH 1/1 mempool: sort the rte_mempool_ops by name
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the rte_mempool_ops_table. For example, when building APPs with:
$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...
The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the mk/rte.app.mk to build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue (access null and crash) rte_mempool_get_ops (should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burst
To avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority in RTE_INIT, but it's not easy to maintain.
* change mk/rte.app.mk: Change the order in mk/rte.app.mk to be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
lib/librte_mempool/rte_mempool_ops.c +16 -2
@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);
@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ + ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;
@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; + rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;
Signature · 1 line
1.8.3.1
Quoted 62 lines · On Mon, Mar 2, 2020 at 7:27 AM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)lib/librte_mempool/rte_mempool_ops.c +1
-1@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 54
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */
+1 for the fix.
For the implementation, why not use qsort_r() for sorting?
Quoted 26 lines
lib/librte_mempool/rte_mempool_ops.c +13
-1+ ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; + rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index; --1.8.3.1
Quoted 67 lines · Jerin Jacob
Quoted 65 lines · On Mon, Mar 2, 2020 at 7:27 AM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)lib/librte_mempool/rte_mempool_ops.c +1
-1@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; }
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 54
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1- ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ +1 for the fix.
For the implementation, why not useqsort_r()for sorting?
The implementation is easy, and the number of mempool driver is not too large. But we can use the qsort_r to implement it.
Quoted 27 lines
Quoted 27 lines
lib/librte_mempool/rte_mempool_ops.c +13
-1+ ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; + rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index; --1.8.3.1
Signature · 2 lines
Thanks, Tonghao
Quoted 69 lines · Tonghao Zhang
Quoted 67 lines · Jerin Jacob
Quoted 65 lines · On Mon, Mar 2, 2020 at 7:27 AM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)lib/librte_mempool/rte_mempool_ops.c +1
-1@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; }
Quoted 8 lines
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 54
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1- ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ +1 for the fix.
For the implementation, why not useqsort_r()for sorting?The implementation is easy, and the number of mempool driver is not too large. But we can use the
qsort_rto implement it.
Since it is in a slow path, IMO, better to use standard sort functions for better readability.
Quoted 33 lines
Quoted 19 lines
Quoted 19 lines
lib/librte_mempool/rte_mempool_ops.c +11
-0+ ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks;Quoted 8 lines
Quoted 8 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1+ rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index; --1.8.3.1
--
Thanks,
Tonghao
Quoted 77 lines · Jerin Jacob
Quoted 75 lines · Tonghao Zhang
Quoted 73 lines · Jerin Jacob
Quoted 62 lines · On Mon, Mar 2, 2020 at 7:27 AM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)lib/librte_mempool/rte_mempool_ops.c +1
-1@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 54
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ +1 for the fix.
For the implementation, why not useqsort_r()for sorting?
Quoted 5 lines
Quoted 2 lines
The implementation is easy, and the number of mempool driver is not too large. But we can use the
qsort_rto implement it.Since it is in a slow path, IMO, better to use standard sort functions for better readability.
Agree, can you help me review the patch:
(quoted diff) +0 -0
b/lib/librte_mempool/rte_mempool_ops.c
index 22c5251..1acee58 100644
lib/librte_mempool/rte_mempool_ops.c +12 -0
@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)
@@ -63,6 +72,9 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; +qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops); +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
lib/librte_mempool/rte_mempool_ops.c +13
-0+ ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; + rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c +0
-1return ops_index; --1.8.3.1
--
Thanks,
Tonghao
--
Thanks,
Tonghao
Quoted 108 lines · Tonghao Zhang
Quoted 77 lines · Jerin Jacob
Quoted 75 lines · Tonghao Zhang
Quoted 73 lines · Jerin Jacob
Quoted 62 lines · On Mon, Mar 2, 2020 at 7:27 AM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)lib/librte_mempool/rte_mempool_ops.c +1
-1@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 54
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ +1 for the fix.
For the implementation, why not useqsort_r()for sorting?Quoted 5 lines
Quoted 2 lines
The implementation is easy, and the number of mempool driver is not too large. But we can use the
qsort_rto implement it.Since it is in a slow path, IMO, better to use standard sort functions for better readability.
Agree, can you help me review the patch:
lib/librte_mempool/rte_mempool_ops.c +9
-0@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 76
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c +2
-0@@ -63,6 +72,9 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; +qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops);
Looks good.
Not tested. Please check qsort behavior when
rte_mempool_ops_table.num_ops == 0 case.
Quoted 46 lines
lib/librte_mempool/rte_mempool_ops.c +1
-0+rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
lib/librte_mempool/rte_mempool_ops.c +13
-0+ ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; + rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c +0
-1return ops_index; --1.8.3.1
--
Thanks,
Tonghao--
Thanks,
Tonghao
Quoted 113 lines · Jerin Jacob
Quoted 111 lines · Tonghao Zhang
Quoted 77 lines · Jerin Jacob
Quoted 75 lines · Tonghao Zhang
Quoted 73 lines · Jerin Jacob
Quoted 62 lines · On Mon, Mar 2, 2020 at 7:27 AM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_mempool/rte_mempool_ops.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)lib/librte_mempool/rte_mempool_ops.c +1
-1@@ -22,7 +22,7 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { rte_mempool_register_ops(const struct rte_mempool_ops *h) {struct rte_mempool_ops *ops; -int16_t ops_index; +unsigned ops_index, i;rte_spinlock_lock (&rte_mempool_ops_table.sl);lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 54
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c +2
-1@@ -50,7 +50,19 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ +1 for the fix.
For the implementation, why not useqsort_r()for sorting?Quoted 5 lines
Quoted 2 lines
The implementation is easy, and the number of mempool driver is not too large. But we can use the
qsort_rto implement it.Since it is in a slow path, IMO, better to use standard sort functions for better readability.
Agree, can you help me review the patch:
lib/librte_mempool/rte_mempool_ops.c +9
-0@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)@@ -63,6 +72,9 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks;
Quoted 7 lines
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 76
Quoted 2 lines
lib/librte_mempool/rte_mempool_ops.c +2
-0+qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops);Looks good.
Not tested. Please check qsort behavior when
rte_mempool_ops_table.num_ops == 0 case.
If nmemb (qsort arg) == 0, qsort will do nothing.
Quoted 48 lines
Quoted 48 lines
lib/librte_mempool/rte_mempool_ops.c +1
-0+rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
lib/librte_mempool/rte_mempool_ops.c +13
-0+ ops_index = rte_mempool_ops_table.num_ops; +for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { +if (strcmp (h->name, rte_mempool_ops_table.ops[i].name) <0 ) { +do { + rte_mempool_ops_table.ops[ops_index] = + rte_mempool_ops_table.ops[ops_index -1 ]; + }while (--ops_index > i); +break ; + } + } + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -63,6 +75,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; + rte_mempool_ops_table.num_ops++; +rte_spinlock_unlock (&rte_mempool_ops_table.sl);Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c +0
-1return ops_index; --1.8.3.1
--
Thanks,
Tonghao--
Thanks,
Tonghao
Signature · 2 lines
Thanks, Tonghao
PATCH v2 1/1 mempool: sort the rte_mempool_ops by name
In reply to [email protected]From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the rte_mempool_ops_table. For example, when building APPs with:
$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...
The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the mk/rte.app.mk to build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue (access null and crash) rte_mempool_get_ops (should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burst
To avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority in RTE_INIT, but it's not easy to maintain.
* change mk/rte.app.mk: Change the order in mk/rte.app.mk to be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
---
v2:
1. use the qsort to sort the mempool_ops.
2. tested: https://travis-ci.com/ovn-open-virtual-networks/dpdk-next-net/builds/151894026
--- lib/librte_mempool/rte_mempool_ops.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
lib/librte_mempool/rte_mempool_ops.c +14 -0
@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)
@@ -63,6 +72,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */ +qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops); +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;
Signature · 1 line
1.8.3.1
Hi,
Quoted 35 lines · On Thu, Mar 05, 2020 at 04:20:40PM +0800, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.
Quoted 8 lines
* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>
Sorting the pool drivers certainly make things better than they are today. However, there is still an issue as soon as the mempool list is not the same on both sides.
I don't see any better solution anyway. Storing the ops pointers in the shared memory won't work, since function addresses won't be the same in the 2 processes.
Just one minor comment below.
Quoted 29 lines
---
v2:
1. use the qsort to sort themempool_ops.
2. tested: https://travis-ci.com/ovn-open-virtual-networks/dpdk-next-net/builds/151894026--- lib/librte_mempool/rte_mempool_ops.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)lib/librte_mempool/rte_mempool_ops.c +9
-0@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 76
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c +2
-0@@ -63,6 +72,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; +/* sort the rte_mempool_ops by name. the order of the mempool +* lib initiation will not affect rte_mempool_ops index. */
initiation -> initialization
there is also a checkpatch comment:
WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #153: FILE: lib/librte_mempool/rte_mempool_ops.c:76:
+ * lib initiation will not affect rte_mempool_ops index. */
Quoted 9 lines
lib/librte_mempool/rte_mempool_ops.c +3
-0+qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops); +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;Signature · 1 line
1.8.3.1
Then,
Thanks!
PATCH v3 1/1 mempool: sort the rte_mempool_ops by name
In reply to [email protected]From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the rte_mempool_ops_table. For example, when building APPs with:
$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...
The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the mk/rte.app.mk to build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue (access null and crash) rte_mempool_get_ops (should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burst
To avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority in RTE_INIT, but it's not easy to maintain.
* change mk/rte.app.mk: Change the order in mk/rte.app.mk to be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
---
v3:
* fix checkpatches.sh WARNING
* change "initiation -> initialization"
v2:
* use the qsort to sort the mempool_ops.
* tested: https://travis-ci.com/ovn-open-virtual-networks/dpdk-next-net/builds/151894026
--- lib/librte_mempool/rte_mempool_ops.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
lib/librte_mempool/rte_mempool_ops.c +16 -0
@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)
@@ -63,6 +72,13 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; +/* +* sort the rte_mempool_ops by name. the order of the mempool +* lib initialization will not affect rte_mempool_ops index. +*/ +qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops); +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index;
Signature · 1 line
1.8.3.1
Quoted 40 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
Quoted 5 lines
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>
Quoted 49 lines
---
v3:
* fixcheckpatches.shWARNING
* change "initiation -> initialization"v2:
* use the qsort to sort themempool_ops.
* tested: https://travis-ci.com/ovn-open-virtual-networks/dpdk-next-net/builds/151894026--- lib/librte_mempool/rte_mempool_ops.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)lib/librte_mempool/rte_mempool_ops.c +16
-1@@ -17,6 +17,15 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { .num_ops = 0 }; +static int +compare_mempool_ops (const void *a,const void *b) +{ +const struct rte_mempool_ops *m_a = a; +const struct rte_mempool_ops *m_b = b; + +return strcmp (m_a->name, m_b->name); +} +/* add a new ops struct in rte_mempool_ops_table, return its index. */ int rte_mempool_register_ops (const struct rte_mempool_ops *h)@@ -63,6 +72,13 @@ struct rte_mempool_ops_table rte_mempool_ops_table = { ops->get_info = h->get_info; ops->dequeue_contig_blocks = h->dequeue_contig_blocks; +/* +* sort the rte_mempool_ops by name. the order of the mempool +* lib initialization will not affect rte_mempool_ops index. +*/ +qsort (rte_mempool_ops_table.ops, rte_mempool_ops_table.num_ops, +sizeof (rte_mempool_ops_table.ops[0 ]), compare_mempool_ops); +rte_spinlock_unlock (&rte_mempool_ops_table.sl);return ops_index; --1.8.3.1
Quoted 40 lines · Jerin Jacob
Quoted 39 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
Quoted 6 lines
Quoted 5 lines
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>Acked-by Jerin Jacob <[email protected]>
The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks rte_mempool_register_ops() return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.
Also I remember patches which warn about above behaviour in documentation. If behaviour changes, corresponding documentation must be updated.
Quoted 55 lines · Andrew Rybchenko
Quoted 40 lines · Jerin Jacob
Quoted 39 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc", but get "bucket" mempool)rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.Quoted 6 lines
Quoted 5 lines
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.
Quoted 3 lines
Also I remember patches which warn about above behaviour in documentation. If behaviour changes, corresponding documentation must be updated.
One more point. If the patch is finally accepted it definitely deserves few lines in release notes.
Quoted 48 lines · Andrew Rybchenko
Quoted 46 lines · Andrew Rybchenko
Quoted 45 lines · Jerin Jacob
Quoted 44 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.
Yes, should update the doc: how about this:
lib/librte_mempool/rte_mempool.h +3 -1
@@ -904,7 +904,9 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,* @param ops * Pointer to an ops structure to register. * @return -* - >=0: Success; return the index of the ops struct in the table. +* - >=0: Success; return the index of the last ops struct in the table. +* The number of the ops struct registered is equal to index +* returned + 1. * - -EINVAL - some missing callbacks while registering ops struct. * - -ENOSPC - the maximum number of ops structs has been reached. */
(quoted diff) +0 -0
b/lib/librte_mempool/rte_mempool_ops.c
index b0da096..053f340 100644
lib/librte_mempool/rte_mempool_ops.c +5 -1
@@ -26,7 +26,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return strcmp (m_a->name, m_b->name); } -/* add a new ops struct in rte_mempool_ops_table, return its index. */ +/* +* add a new ops struct in rte_mempool_ops_table. +* on success, return the index of the last ops +* struct in the table. +*/ int rte_mempool_register_ops (const struct rte_mempool_ops *h) {
Quoted 6 lines
Quoted 3 lines
Also I remember patches which warn about above behaviour in documentation. If behaviour changes, corresponding documentation must be updated.
One more point. If the patch is finally accepted it definitely deserves few lines in release notes.
OK, a separate patch should be sent before DPDK 20.05 release ?
Quoted 1 line
Signature · 2 lines
Thanks, Tonghao
Hi,
Quoted 50 lines · Tonghao Zhang
Quoted 48 lines · Andrew Rybchenko
Quoted 46 lines · Andrew Rybchenko
Quoted 45 lines · Jerin Jacob
Quoted 44 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.
Good points.
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):
struct rte_mempool_shared_ops {
size_t num_mempool_ops;
struct {
char name[RTE_MEMPOOL_OPS_NAMESIZE];
} mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX];
char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX];
rte_spinlock_t mempool;
}2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
3/ Then do as before (in the per-process global table), except that we
reuse the registered id.
We can remove the num_ops field from rte_mempool_ops_table.
Thoughts?
Quoted 48 lines
Yes, should update the doc: how about this:
lib/librte_mempool/rte_mempool.h +3
-1@@ -904,7 +904,9 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,* @param ops * Pointer to an ops structure to register. * @return -* - >=0: Success; return the index of the ops struct in the table. +* - >=0: Success; return the index of the last ops struct in the table. +* The number of the ops struct registered is equal to index +* returned + 1. * - -EINVAL - some missing callbacks while registering ops struct. * - -ENOSPC - the maximum number of ops structs has been reached. */ lib/librte_mempool/rte_mempool_ops.c +5
-1@@ -26,7 +26,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return strcmp (m_a->name, m_b->name); } -/* add a new ops struct in rte_mempool_ops_table, return its index. */ +/* +* add a new ops struct in rte_mempool_ops_table. +* on success, return the index of the last ops +* struct in the table. +*/ int rte_mempool_register_ops (const struct rte_mempool_ops *h) {Quoted 6 lines
Quoted 3 lines
Also I remember patches which warn about above behaviour in documentation. If behaviour changes, corresponding documentation must be updated.
One more point. If the patch is finally accepted it definitely deserves few lines in release notes.
OK, a separate patch should be sent before DPDK 20.05 release ?
Quoted 1 line
Signature · 2 lines
Thanks, Tonghao
Quoted 63 lines · Olivier Matz
Hi,
Quoted 50 lines · Tonghao Zhang
Quoted 48 lines · Andrew Rybchenko
Quoted 46 lines · Andrew Rybchenko
Quoted 45 lines · Jerin Jacob
Quoted 44 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.
Quoted 6 lines
Good points.
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
That solution is better.
Quoted 18 lines
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX]; char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX]; rte_spinlock_t mempool; }2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Quoted 56 lines
3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.Thoughts?
Quoted 48 lines
Yes, should update the doc: how about this:
lib/librte_mempool/rte_mempool.h +3
-1@@ -904,7 +904,9 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,* @param ops * Pointer to an ops structure to register. * @return -* - >=0: Success; return the index of the ops struct in the table. +* - >=0: Success; return the index of the last ops struct in the table. +* The number of the ops struct registered is equal to index +* returned + 1. * - -EINVAL - some missing callbacks while registering ops struct. * - -ENOSPC - the maximum number of ops structs has been reached. */ lib/librte_mempool/rte_mempool_ops.c +5
-1@@ -26,7 +26,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return strcmp (m_a->name, m_b->name); } -/* add a new ops struct in rte_mempool_ops_table, return its index. */ +/* +* add a new ops struct in rte_mempool_ops_table. +* on success, return the index of the last ops +* struct in the table. +*/ int rte_mempool_register_ops (const struct rte_mempool_ops *h) {Quoted 6 lines
Quoted 3 lines
Also I remember patches which warn about above behaviour in documentation. If behaviour changes, corresponding documentation must be updated.
One more point. If the patch is finally accepted it definitely deserves few lines in release notes.
OK, a separate patch should be sent before DPDK 20.05 release ?
Quoted 1 line
--
Thanks,
Tonghao
--
Thanks,
Tonghao
Quoted 64 lines · Tonghao Zhang
Quoted 63 lines · Olivier Matz
Hi,
Quoted 58 lines · Tonghao Zhang
Quoted 56 lines · Andrew Rybchenko
Quoted 54 lines · Andrew Rybchenko
Quoted 40 lines · Jerin Jacob
Quoted 39 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.Quoted 6 lines
Quoted 5 lines
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.
Quoted 21 lines
Quoted 6 lines
Good points.
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
That solution is better.
Quoted 13 lines
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX];char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX];
oops I forgot to remove this line (replaced by mini-struct just above).
Quoted 69 lines
Quoted 7 lines
rte_spinlock_t mempool;}
2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.Quoted 56 lines
3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.Thoughts?
Quoted 48 lines
Yes, should update the doc: how about this:
lib/librte_mempool/rte_mempool.h +3
-1@@ -904,7 +904,9 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,* @param ops * Pointer to an ops structure to register. * @return -* - >=0: Success; return the index of the ops struct in the table. +* - >=0: Success; return the index of the last ops struct in the table. +* The number of the ops struct registered is equal to index +* returned + 1. * - -EINVAL - some missing callbacks while registering ops struct. * - -ENOSPC - the maximum number of ops structs has been reached. */ lib/librte_mempool/rte_mempool_ops.c +5
-1@@ -26,7 +26,11 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {return strcmp (m_a->name, m_b->name); } -/* add a new ops struct in rte_mempool_ops_table, return its index. */ +/* +* add a new ops struct in rte_mempool_ops_table. +* on success, return the index of the last ops +* struct in the table. +*/ int rte_mempool_register_ops (const struct rte_mempool_ops *h) {Quoted 6 lines
Quoted 3 lines
Also I remember patches which warn about above behaviour in documentation. If behaviour changes, corresponding documentation must be updated.
One more point. If the patch is finally accepted it definitely deserves few lines in release notes.
OK, a separate patch should be sent before DPDK 20.05 release ?
Quoted 1 line
--
Thanks,
Tonghao--
Thanks,
Tonghao
Quoted 31 lines · Tonghao Zhang
Quoted 4 lines · Olivier Matz
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
That solution is better.
Quoted 24 lines
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX]; char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX]; rte_spinlock_t mempool; }2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.Thoughts?
It seems better, just adding Anatoly and Bruce who know more about multiprocess.
Tonghao, could you add a unit test to exhibit the issue as part of this work?
Thanks.
Signature · 1 line
David Marchand
Quoted 32 lines · David Marchand
Quoted 30 lines · Tonghao Zhang
Quoted 4 lines · Olivier Matz
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
That solution is better.
Quoted 23 lines
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX]; char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX]; rte_spinlock_t mempool; }2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Thoughts?
It seems better, just adding Anatoly and Bruce who know more about multiprocess.
Tonghao, could you add a unit test to exhibit the issue as part of this work?
Thanks.
Hi Olivier
any progress?will apply this patch or wait your patch?
Quoted 4 lines
--
David Marchand
Signature · 2 lines
Thanks, Tonghao
Hi Tonghao,
Quoted 35 lines · Tonghao Zhang
Quoted 34 lines · David Marchand
Quoted 31 lines · Tonghao Zhang
Quoted 4 lines · Olivier Matz
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
That solution is better.
Quoted 24 lines
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX]; char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX]; rte_spinlock_t mempool; }2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.Thoughts?
Quoted 7 lines
Quoted 5 lines
It seems better, just adding Anatoly and Bruce who know more about multiprocess.
Tonghao, could you add a unit test to exhibit the issue as part of this work?
Thanks.
Hi Olivier
any progress?will apply this patch or wait your patch?
Sorry if it wasn't clear, but my proposition was just an idea, I have no time yet to work on it. Feel free to implement it by yourself, and I'll help to review the patches.
Thanks,
Olivier
Quoted 87 lines · Olivier Matz
Hi,
Quoted 50 lines · Tonghao Zhang
Quoted 48 lines · Andrew Rybchenko
Quoted 46 lines · Andrew Rybchenko
Quoted 45 lines · Jerin Jacob
Quoted 44 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.Good points.
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX]; char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX]; rte_spinlock_t mempool; }2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Quoted 6 lines
3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.Thoughts?
I like the solution.
Quoted 89 lines · Andrew Rybchenko
Quoted 87 lines · Olivier Matz
Hi,
Quoted 50 lines · Tonghao Zhang
Quoted 48 lines · Andrew Rybchenko
Quoted 46 lines · Andrew Rybchenko
Quoted 45 lines · Jerin Jacob
Quoted 44 lines · On Fri, Mar 6, 2020 at 7:06 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table.
Signed-off-by Tonghao Zhang <[email protected]>Acked-by Olivier Matz <[email protected]>Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Acked-by Jerin Jacob <[email protected]>The patch is OK, but the fact that ops index changes during mempool driver lifetime is frightening. In fact it breaks
rte_mempool_register_ops()return value semantics (read as API break). The return value is not used in DPDK, but it is a public function. If I'm not mistaken it should be taken into account.Good points.
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application. Also, breaking the ABI is not desirable.
Let me try to propose something else to solve your issue:
1/ At init, the primary process allocates a struct in shared memory
(named memzone):struct rte_mempool_shared_ops { size_t num_mempool_ops; struct { char name[RTE_MEMPOOL_OPS_NAMESIZE]; } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX]; char *mempool_ops_name[RTE_MEMPOOL_MAX_OPS_IDX]; rte_spinlock_t mempool; }2/ When we register a mempool ops, we first get a name and id from the
shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Quoted 8 lines
Quoted 6 lines
3/ Then do as before (in the per-process global table), except that we
reuse the registered id.We can remove the
num_opsfield fromrte_mempool_ops_table.Thoughts?
I like the solution.
The patch will be sent, thanks.
Signature · 1 line
Best regards, Tonghao
PATCH 1/2 eal: introduce last-init queue for libraries initialization
In reply to [email protected]From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running rte_last_init_run(), the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
--- lib/librte_eal/common/eal_common_last_init.c | 43 ++++++++++++++++++++++++++++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/freebsd/eal.c | 7 +++++ lib/librte_eal/include/rte_last_init.h | 36 +++++++++++++++++++++++ lib/librte_eal/linux/Makefile | 1 + lib/librte_eal/linux/eal.c | 8 ++++++ 7 files changed, 97 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_last_init.c create mode 100644 lib/librte_eal/include/rte_last_init.h
lib/librte_eal/common/eal_common_last_init.c new file +43 -0
@@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#include <sys/queue.h> + +#include <rte_last_init.h> +#include <rte_debug.h> + +static struct rte_last_init_list rte_last_init_list = +TAILQ_HEAD_INITIALIZER (rte_last_init_list); + +void +rte_last_init_register (rte_last_init_cb cb,const void *arg) +{ +struct rte_last_init *last; + +RTE_VERIFY (cb); + + last =malloc (sizeof (*last)); +if (last ==NULL ) +rte_panic ("Alloc memory for rte_last_init node failed\n" ); + + last->cb = cb; + last->arg = arg; + +TAILQ_INSERT_TAIL (&rte_last_init_list, last, next); +} + +int +rte_last_init_run (void ) +{ +struct rte_last_init *init; +int ret; + + TAILQ_FOREACH(init, &rte_last_init_list, next) { + ret = init->cb (init->arg); +if (ret) +return ret; + } + +return 0 ; +}
lib/librte_eal/common/meson.build +1 -0
@@ -43,6 +43,7 @@ sources += files( 'eal_common_thread.c', 'eal_common_timer.c', 'eal_common_uuid.c', + 'eal_common_last_init.c', 'hotplug_mp.c', 'malloc_elem.c', 'malloc_heap.c',
lib/librte_eal/freebsd/Makefile +1 -0
@@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_uuid.c +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_last_init.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += malloc_elem.c
lib/librte_eal/freebsd/eal.c +7 -0
@@ -44,6 +44,7 @@#include <rte_option.h> #include <rte_atomic.h> #include <malloc_heap.h> +#include <rte_last_init.h> #include "eal_private.h" #include "eal_thread.h"
@@ -874,6 +875,12 @@ static void rte_eal_init_alert(const char *msg)eal_check_mem_on_local_socket (); +if (rte_last_init_run () <0 ) { +rte_eal_init_alert ("Cannot init objects in last-init queue" ); + rte_errno =EFAULT ; +return -1 ; + } +eal_thread_init_master (rte_config.master_lcore); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
lib/librte_eal/include/rte_last_init.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#ifndef _RTE_LAST_INIT_H_ +#define _RTE_LAST_INIT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> +#include <sys/queue.h> + +typedef int (*rte_last_init_cb )(const void *arg); + +/** +* A structure describing a generic initialization. +*/ +struct rte_last_init { +TAILQ_ENTRY (rte_last_init) next;/**< Next bus object in linked list */ +const void *arg; +rte_last_init_cb cb; +}; + +/** Double linked list of buses */ +TAILQ_HEAD (rte_last_init_list, rte_last_init); + +void rte_last_init_register (rte_last_init_cb cb,const void *arg); +int rte_last_init_run (void ); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LAST_INIT_H_ */
lib/librte_eal/linux/Makefile +1 -0
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_uuid.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_last_init.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += malloc_elem.c
lib/librte_eal/linux/eal.c +8 -0
@@ -51,6 +51,7 @@#include <malloc_heap.h> #include <rte_vfio.h> #include <rte_option.h> +#include <rte_last_init.h> #include "eal_private.h" #include "eal_thread.h"
@@ -1203,6 +1204,13 @@ static void rte_eal_init_alert(const char *msg)eal_check_mem_on_local_socket (); + +if (rte_last_init_run () <0 ) { +rte_eal_init_alert ("Cannot init objects in last-init queue" ); + rte_errno =EFAULT ; +return -1 ; + } +eal_thread_init_master (rte_config.master_lcore); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
Signature · 1 line
1.8.3.1
PATCH 2/2 mempool: use shared memzone for rte_mempool_ops
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the rte_mempool_ops_table. For example, when building APPs with:
$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...
The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the mk/rte.app.mk to build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue (access null and crash) rte_mempool_get_ops (should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burst
To avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority in RTE_INIT, but it's not easy to maintain.
* change mk/rte.app.mk: Change the order in mk/rte.app.mk to be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table. but the number of mempool libraries may be different.
* shared memzone: The primary process allocates a struct in shared memory named memzone, When we register a mempool ops, we first get a name and id from the shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
previous discussion:
https://mails.dpdk.org/archives/dev/2020-March/159354.html
--- lib/librte_mempool/rte_mempool.h | 22 ++++++++- lib/librte_mempool/rte_mempool_ops.c | 89 ++++++++++++++++++++++++++++-------- 2 files changed, 90 insertions(+), 21 deletions(-)
lib/librte_mempool/rte_mempool.h +20 -2
@@ -50,6 +50,7 @@#include <rte_ring.h> #include <rte_memcpy.h> #include <rte_common.h> +#include <rte_last_init.h> #ifdef __cplusplusextern "C" {
@@ -678,7 +679,6 @@ struct rte_mempool_ops {*/ struct rte_mempool_ops_table {rte_spinlock_t sl;/**< Spinlock for add/delete. */ -uint32_t num_ops;/**< Number of used ops structs in the table. */ /** * Storage for all possible ops structs. */
@@ -910,6 +910,23 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,*/ int rte_mempool_register_ops (const struct rte_mempool_ops *ops); +struct rte_mempool_shared_ops { +size_t num_mempool_ops; +struct { +char name[RTE_MEMPOOL_OPS_NAMESIZE ]; + } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX ]; + +rte_spinlock_t mempool; +}; + +static inline int +rte_mempool_register_ops_cb (const void *arg) +{ +const struct rte_mempool_ops *h = (const struct rte_mempool_ops *)arg; + +return rte_mempool_register_ops (h); +} +/** * Macro to statically register the ops of a mempool handler. * Note that the rte_mempool_register_ops fails silently here when
@@ -918,7 +935,8 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,#define MEMPOOL_REGISTER_OPS (ops) \ RTE_INIT(mp_hdlr_init_##ops) \ { \ - rte_mempool_register_ops(&ops); \ + rte_last_init_register(rte_mempool_register_ops_cb, \ + (const void *)&ops); \ }/**
lib/librte_mempool/rte_mempool_ops.c +70 -19
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH dpdk-dev 1/2] eal: introduce last-init queue for libraries initialization
In reply to [email protected]Quoted 10 lines · On Thu, Apr 9, 2020 at 4:24 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running
rte_last_init_run(), the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.[This patch will be used for next patch.]
Quoted 7 lines
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_eal/common/eal_common_last_init.c | 43 ++++++++++++++++++++++++++++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/freebsd/eal.c | 7 +++++ lib/librte_eal/include/rte_last_init.h | 36 +++++++++++++++++++++++
Update doc/api/doxy-api-index.md and hook to documenion.
lib/librte_eal/common/eal_common_last_init.c line 20
Quoted 8 lines
lib/librte_eal/common/eal_common_last_init.c new file +8
-0+void +rte_last_init_register (rte_last_init_cb cb,const void *arg) +{ +struct rte_last_init *last; + +RTE_VERIFY (cb); + + last =malloc (sizeof (*last));
Does not look like this memory is NOT freed anywhere.
Quoted 25 lines
lib/librte_eal/common/eal_common_last_init.c new file +23
-0+if (last ==NULL ) +rte_panic ("Alloc memory for rte_last_init node failed\n" ); + + last->cb = cb; + last->arg = arg; + +TAILQ_INSERT_TAIL (&rte_last_init_list, last, next); +} + +int +rte_last_init_run (void ) +{ +struct rte_last_init *init; +int ret; + + TAILQ_FOREACH(init, &rte_last_init_list, next) { + ret = init->cb (init->arg); +if (ret) +return ret; + } + +return 0 ; +}lib/librte_eal/common/meson.build +0
-0
lib/librte_eal/common/meson.build
Quoted 10 lines
lib/librte_eal/common/meson.build +10
-0+typedef int (*rte_last_init_cb)(const void *arg); + +/** + * A structure describing a generic initialization. + */ +struct rte_last_init { + TAILQ_ENTRY(rte_last_init) next; /**< Next bus object in linked list */ + const void *arg; + rte_last_init_cb cb; +};
No need to expose this structure. Move to eal_private.h
lib/librte_eal/common/meson.build
Quoted 3 lines
lib/librte_eal/common/meson.build +3
-0+ +/** Double linked list of buses */ +TAILQ_HEAD(rte_last_init_list, rte_last_init);
No need to expose this structure. Move to eal_private.h
lib/librte_eal/common/meson.build
Quoted 2 lines
lib/librte_eal/common/meson.build +2
-0+ +void rte_last_init_register(rte_last_init_cb cb, const void *arg);
Add Doxygen comment.
Should we change to rte_init_register()? add an enum to specify where to call this RTE_INIT_PRE, RTE_INIT_POST to take care of the future needs. Just thought of bringing this point to make sure we can use this scheme for another use case IF ANY.
Quoted 1 line
+int
rte_last_init_run(void);
No need to expose this function in public API. Move to eal_private.h. Please start the internal functions with eal_(dont use rte_ for internal functions)
Re: [dpdk-dev] [PATCH dpdk-dev 1/2] eal: introduce last-init queue for libraries initialization
Quoted 89 lines · Jerin Jacob
Quoted 10 lines · On Thu, Apr 9, 2020 at 4:24 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running
rte_last_init_run(), the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.[This patch will be used for next patch.]
Quoted 7 lines
Signed-off-by Tonghao Zhang <[email protected]>--- lib/librte_eal/common/eal_common_last_init.c | 43 ++++++++++++++++++++++++++++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/freebsd/eal.c | 7 +++++ lib/librte_eal/include/rte_last_init.h | 36 +++++++++++++++++++++++Update
doc/api/doxy-api-index.mdand hook to documenion.lib/librte_eal/common/eal_common_last_init.c line 20
Quoted 8 lines
lib/librte_eal/common/eal_common_last_init.c new file +8
-0+void +rte_last_init_register (rte_last_init_cb cb,const void *arg) +{ +struct rte_last_init *last; + +RTE_VERIFY (cb); + + last =malloc (sizeof (*last));Does not look like this memory is NOT freed anywhere.
Quoted 25 lines
lib/librte_eal/common/eal_common_last_init.c new file +23
-0+if (last ==NULL ) +rte_panic ("Alloc memory for rte_last_init node failed\n" ); + + last->cb = cb; + last->arg = arg; + +TAILQ_INSERT_TAIL (&rte_last_init_list, last, next); +} + +int +rte_last_init_run (void ) +{ +struct rte_last_init *init; +int ret; + + TAILQ_FOREACH(init, &rte_last_init_list, next) { + ret = init->cb (init->arg); +if (ret) +return ret; + } + +return 0 ; +}lib/librte_eal/common/meson.build +0
-0lib/librte_eal/common/meson.build
Quoted 10 lines
lib/librte_eal/common/meson.build +10
-0+typedef int (*rte_last_init_cb)(const void *arg); + +/** + * A structure describing a generic initialization. + */ +struct rte_last_init { + TAILQ_ENTRY(rte_last_init) next; /**< Next bus object in linked list */ + const void *arg; + rte_last_init_cb cb; +};No need to expose this structure. Move to
eal_private.hlib/librte_eal/common/meson.build
Quoted 3 lines
lib/librte_eal/common/meson.build +3
-0+ +/** Double linked list of buses */ +TAILQ_HEAD(rte_last_init_list, rte_last_init);No need to expose this structure. Move to
eal_private.hlib/librte_eal/common/meson.build
Quoted 2 lines
lib/librte_eal/common/meson.build +2
-0+ +void rte_last_init_register(rte_last_init_cb cb, const void *arg);Add Doxygen comment.
Should we change to
rte_init_register()? add an enum to specify where to call thisRTE_INIT_PRE,RTE_INIT_POSTto take care of the future needs. Just thought of bringing this point to make sure we can use this scheme for another use case IF ANY.
Quoted 5 lines
Quoted 1 line
+int
rte_last_init_run(void);No need to expose this function in public API. Move to
eal_private.h. Please start the internal functions witheal_(dont use rte_ for internal functions)
Thanks for your review, v2 is sent. thanks.
Signature · 1 line
Best regards, Tonghao
PATCH v2 1/2 eal: introduce rte-init queue for libraries initialization
In reply to [email protected]From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running rte_last_init_run(), the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
---
v2:
* rename rte_last_init_register ->rte_init_register
* rename rte_last_init struct ->rte_init
* rename rte_init_cb ->rte_init_cb_t
* free the rte_init node when not used.
* remove rte_init and others to eal_private.h
* add comments
* fix checkpatch warning
--- lib/librte_eal/common/eal_common_init.c | 74 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 23 ++++++++++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/freebsd/eal.c | 6 +++ lib/librte_eal/include/rte_init.h | 59 ++++++++++++++++++++++++++ lib/librte_eal/linux/Makefile | 1 + lib/librte_eal/linux/eal.c | 6 +++ 8 files changed, 171 insertions(+) create mode 100644 lib/librte_eal/common/eal_common_init.c create mode 100644 lib/librte_eal/include/rte_init.h
lib/librte_eal/common/eal_common_init.c new file +74 -0
@@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#include <sys/queue.h> + +#include <rte_init.h> +#include <rte_debug.h> +#include <rte_tailq.h> + +#include "eal_private.h" + +static struct rte_init_list rte_init_list = +TAILQ_HEAD_INITIALIZER (rte_init_list); + +void +rte_init_register (rte_init_cb_t cb,const void *arg,enum rte_init_type type) +{ +struct rte_init *last; + +RTE_VERIFY (cb); + + last =malloc (sizeof (*last)); +if (last ==NULL ) +rte_panic ("Alloc memory for rte_init node failed\n" ); + + last->type = type; + last->arg = arg; + last->cb = cb; + +TAILQ_INSERT_TAIL (&rte_init_list, last, next); +} + +static int +eal_rte_init_run_type (enum rte_init_type type) +{ +struct rte_init *last; +int ret; + + TAILQ_FOREACH(last, &rte_init_list, next) { +if (last->type != type) +continue ; + + ret = last->cb (last->arg); +if (ret <0 ) +return ret; + } + +return 0 ; +} + +int +eal_rte_init_run (void ) +{ +struct rte_init *last; +struct rte_init *tmp; +int ret; + + ret =eal_rte_init_run_type (RTE_INIT_PRE ); +if (ret <0 ) +return ret; + + ret =eal_rte_init_run_type (RTE_INIT_POST ); +if (ret <0 ) +return ret; + +/* Free rte_init node, not used anymore. */ + TAILQ_FOREACH_SAFE(last, &rte_init_list, next, tmp) { +TAILQ_REMOVE (&rte_init_list, last, next); +free (last); + } + +return 0 ; +}
lib/librte_eal/common/eal_private.h +23 -0
@@ -11,6 +11,7 @@#include <rte_dev.h> #include <rte_lcore.h> +#include <rte_init.h> /** * Structure storing internal configuration (per-lcore)
@@ -60,6 +61,28 @@ struct rte_config { } __attribute__((__packed__));/** +* A structure describing a generic initialization. +*/ +struct rte_init { +TAILQ_ENTRY (rte_init) next; +enum rte_init_type type; +rte_init_cb_t cb; +const void *arg; +}; + +/** Double linked list of rte_init. */ +TAILQ_HEAD (rte_init_list, rte_init); + +/** +* Run the callback registered in the global double linked list. +* +* @return +* - 0 on success +* - Negative on error +*/ +int eal_rte_init_run (void ); + +/** * Get the global configuration structure. * * @return
lib/librte_eal/common/meson.build +1 -0
@@ -43,6 +43,7 @@ sources += files( 'eal_common_thread.c', 'eal_common_timer.c', 'eal_common_uuid.c', + 'eal_common_init.c', 'hotplug_mp.c', 'malloc_elem.c', 'malloc_heap.c',
lib/librte_eal/freebsd/Makefile +1 -0
@@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_uuid.c +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_init.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += malloc_elem.c
lib/librte_eal/freebsd/eal.c +6 -0
@@ -874,6 +874,12 @@ static void rte_eal_init_alert(const char *msg)eal_check_mem_on_local_socket (); +if (eal_rte_init_run () <0 ) { +rte_eal_init_alert ("Cannot init objects in rte-init queue" ); + rte_errno =EFAULT ; +return -1 ; + } +eal_thread_init_master (rte_config.master_lcore); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
lib/librte_eal/include/rte_init.h new file +59 -0
59 lines not on this page · raw message
lib/librte_eal/linux/Makefile +1 -0
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_uuid.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_init.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += malloc_elem.c
lib/librte_eal/linux/eal.c +6 -0
@@ -1203,6 +1203,12 @@ static void rte_eal_init_alert(const char *msg)eal_check_mem_on_local_socket (); +if (eal_rte_init_run () <0 ) { +rte_eal_init_alert ("Cannot init objects in rte-init queue" ); + rte_errno =EFAULT ; +return -1 ; + } +eal_thread_init_master (rte_config.master_lcore); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
Signature · 1 line
1.8.3.1
PATCH v2 2/2 mempool: use shared memzone for rte_mempool_ops
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the rte_mempool_ops_table. For example, when building APPs with:
$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...
The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the mk/rte.app.mk to build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue (access null and crash) rte_mempool_get_ops (should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burst
To avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority in RTE_INIT, but it's not easy to maintain.
* change mk/rte.app.mk: Change the order in mk/rte.app.mk to be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table. but the number of mempool libraries may be different.
* shared memzone: The primary process allocates a struct in shared memory named memzone, When we register a mempool ops, we first get a name and id from the shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Previous discussion: https://mails.dpdk.org/archives/dev/2020-March/159354.html
---
v2:
* fix checkpatch warning
--- lib/librte_mempool/rte_mempool.h | 28 +++++++++++- lib/librte_mempool/rte_mempool_ops.c | 89 ++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 21 deletions(-)
lib/librte_mempool/rte_mempool.h +26 -2
@@ -50,6 +50,7 @@#include <rte_ring.h> #include <rte_memcpy.h> #include <rte_common.h> +#include <rte_init.h> #ifdef __cplusplusextern "C" {
@@ -678,7 +679,6 @@ struct rte_mempool_ops {*/ struct rte_mempool_ops_table {rte_spinlock_t sl;/**< Spinlock for add/delete. */ -uint32_t num_ops;/**< Number of used ops structs in the table. */ /** * Storage for all possible ops structs. */
@@ -910,6 +910,30 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,*/ int rte_mempool_register_ops (const struct rte_mempool_ops *ops); +struct rte_mempool_shared_ops { +size_t num_mempool_ops; +struct { +char name[RTE_MEMPOOL_OPS_NAMESIZE ]; + } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX ]; + +rte_spinlock_t mempool; +}; + +static inline int +mempool_ops_register_cb (const void *arg) +{ +const struct rte_mempool_ops *h = (const struct rte_mempool_ops *)arg; + +return rte_mempool_register_ops (h); +} + +static inline void +mempool_ops_register (const struct rte_mempool_ops *ops) +{ +rte_init_register (mempool_ops_register_cb, (const void *)ops, +RTE_INIT_PRE ); +} +/** * Macro to statically register the ops of a mempool handler. * Note that the rte_mempool_register_ops fails silently here when
@@ -918,7 +942,7 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,#define MEMPOOL_REGISTER_OPS (ops) \ RTE_INIT(mp_hdlr_init_##ops) \ { \ - rte_mempool_register_ops(&ops); \ + mempool_ops_register(&ops); \ }/**
lib/librte_mempool/rte_mempool_ops.c +70 -19
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH dpdk-dev v2 1/2] eal: introduce rte-init queue for libraries initialization
In reply to [email protected]Quoted 5 lines · On Thu, Apr 9, 2020 at 8:33 PM <[email protected]> wrote:
From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running
rte_last_init_run(),
The above section needs to be rewritten wrt v2 changes.
Quoted 4 lines
the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
See below
Quoted 3 lines
Signed-off-by Tonghao Zhang <[email protected]>---
See above
Move [This patch will be used for next patch.] here to avoid unnecessary information in the git commit.
Quoted 15 lines
v2:
* renamerte_last_init_register->rte_init_register
* renamerte_last_initstruct ->rte_init
* renamerte_init_cb->rte_init_cb_t
* free therte_initnode when not used.
* removerte_initand others toeal_private.h
* add comments
* fix checkpatch warning
---lib/librte_eal/include/rte_init.h new file +0
-0
lib/librte_eal/include/rte_init.h line 6
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#ifndef _RTE_INIT_H_ +#define _RTE_INIT_H_
@file section is missing. See lib/librte_eal/common/include/rte_errno.h as example.
lib/librte_eal/include/rte_init.h line 13
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0+#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> +#include <sys/queue.h>
<sys/queue.h> is not required in public API header file.
Quoted 11 lines
lib/librte_eal/include/rte_init.h new file +11
-0+ +/** +* Implementation specific callback function which is +* responsible for specificed initialization. +* +* This is called when almost resources are available. +* +* @return +* 0 for successful callback +* Negative for unsuccessful callback with error value +*/
lib/librte_eal/include/rte_init.h line 34
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +10
-0+typedef int (*rte_init_cb_t )(const void *arg); + +/** +* rte_init type. +* +* The rte_init of RTE_INIT_PRE are called firstly, +* and then RTE_INIT_POST. +*/ +enum rte_init_type { +RTE_INIT_PRE ,
Type specific comment is missing.
Example as reference for formatting.
/**
* Enumerate trace mode operation.
*/
enum rte_trace_mode_e {
/**
* In this mode, When no space left in trace buffer, the subsequent
* events overwrite the old events in the trace buffer. */
RTE_TRACE_MODE_OVERWRITE,
/**
* In this mode, When no space left on trace buffer, the subsequent
* events shall not be recorded in the trace buffer.
*/
RTE_TRACE_MODE_DISCARD,
};
lib/librte_eal/include/rte_init.h line 42
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +8
-0+ RTE_INIT_POST +}; + +/** +* Register a rte_init callback. +* +* @param cb +* A pointer to a rte_init_cb structure, which will be used
s/used/invoked?
Quoted 17 lines
+ * in
rte_eal_init().
+ *
+ * @param arg
+ * The cb will use that as param.
+ *
+ * @param type
+ * The type ofrte_initregistered.
+ */lib/librte_eal/include/rte_init.h new file +9
-0+ +void rte_init_register (rte_init_cb_t cb,const void *arg, +enum rte_init_type type); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_INIT_H_ */
Re: [dpdk-dev] [PATCH dpdk-dev v2 1/2] eal: introduce rte-init queue for libraries initialization
Quoted 1 line · Jerin Jacob
Three more items are missing in this patch
1) Unit test case for new API
2) Make the new API __rte_experimal
3) Update the .map file
Quoted 132 lines · On Thu, Apr 9, 2020 at 8:33 PM <[email protected]> wrote:
Quoted 5 lines
From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running
rte_last_init_run(),The above section needs to be rewritten wrt v2 changes.
Quoted 4 lines
the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
See below
Quoted 3 lines
Signed-off-by Tonghao Zhang <[email protected]>---
See above
Move [This patch will be used for next patch.] here to avoid unnecessary information in the git commit.
Quoted 15 lines
v2:
* renamerte_last_init_register->rte_init_register
* renamerte_last_initstruct ->rte_init
* renamerte_init_cb->rte_init_cb_t
* free therte_initnode when not used.
* removerte_initand others toeal_private.h
* add comments
* fix checkpatch warning
---lib/librte_eal/include/rte_init.h new file +0
-0lib/librte_eal/include/rte_init.h line 6
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#ifndef _RTE_INIT_H_ +#define _RTE_INIT_H_@file section is missing. See
lib/librte_eal/common/include/rte_errno.has example.lib/librte_eal/include/rte_init.h line 13
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0+#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> +#include <sys/queue.h> <
sys/queue.h> is not required in public API header file.Quoted 11 lines
lib/librte_eal/include/rte_init.h new file +11
-0+ +/** +* Implementation specific callback function which is +* responsible for specificed initialization. +* +* This is called when almost resources are available. +* +* @return +* 0 for successful callback +* Negative for unsuccessful callback with error value +*/ lib/librte_eal/include/rte_init.h line 34
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +10
-0+typedef int (*rte_init_cb_t )(const void *arg); + +/** +* rte_init type. +* +* The rte_init of RTE_INIT_PRE are called firstly, +* and then RTE_INIT_POST. +*/ +enum rte_init_type { +RTE_INIT_PRE ,Type specific comment is missing.
Example as reference for formatting.
/**
* Enumerate trace mode operation.
*/
enumrte_trace_mode_e{
/**
* In this mode, When no space left in trace buffer, the subsequent
* events overwrite the old events in the trace buffer. */
RTE_TRACE_MODE_OVERWRITE,
/**
* In this mode, When no space left on trace buffer, the subsequent
* events shall not be recorded in the trace buffer.
*/
RTE_TRACE_MODE_DISCARD,
};lib/librte_eal/include/rte_init.h line 42
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +8
-0+ RTE_INIT_POST +}; + +/** +* Register a rte_init callback. +* +* @param cb +* A pointer to a rte_init_cb structure, which will be used s/used/invoked?
Quoted 17 lines
+ * in
rte_eal_init().
+ *
+ * @param arg
+ * The cb will use that as param.
+ *
+ * @param type
+ * The type ofrte_initregistered.
+ */lib/librte_eal/include/rte_init.h new file +9
-0+ +void rte_init_register (rte_init_cb_t cb,const void *arg, +enum rte_init_type type); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_INIT_H_ */
Re: [dpdk-dev] [PATCH dpdk-dev v2 1/2] eal: introduce rte-init queue for libraries initialization
Quoted 8 lines · Jerin Jacob
Quoted 1 line · Jerin Jacob
Three more items are missing in this patch
1) Unit test case for new API
2) Make the new API__rte_experimal
Hi Jerin
This API will be invoked in mempool, if use that prefix, there is a compile warning:include/rte_mempool.h:933:2: error: ‘rte_init_register’ is deprecated (declared at x86_64-native-linuxapp-gcc/include/rte_init.h:61): Symbol is not yet part of stable ABI [-Werror=deprecated-declarations]
remove the __rte_experimal in the patch 2?
Quoted 135 lines
3) Update the .map file
Quoted 132 lines · On Thu, Apr 9, 2020 at 8:33 PM <[email protected]> wrote:
Quoted 5 lines
From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running
rte_last_init_run(),The above section needs to be rewritten wrt v2 changes.
Quoted 4 lines
the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
See below
Quoted 3 lines
Signed-off-by Tonghao Zhang <[email protected]>---
See above
Move [This patch will be used for next patch.] here to avoid unnecessary information in the git commit.
Quoted 15 lines
v2:
* renamerte_last_init_register->rte_init_register
* renamerte_last_initstruct ->rte_init
* renamerte_init_cb->rte_init_cb_t
* free therte_initnode when not used.
* removerte_initand others toeal_private.h
* add comments
* fix checkpatch warning
---lib/librte_eal/include/rte_init.h new file +0
-0lib/librte_eal/include/rte_init.h line 6
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#ifndef _RTE_INIT_H_ +#define _RTE_INIT_H_@file section is missing. See
lib/librte_eal/common/include/rte_errno.has example.lib/librte_eal/include/rte_init.h line 13
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0+#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> +#include <sys/queue.h> <
sys/queue.h> is not required in public API header file.Quoted 11 lines
lib/librte_eal/include/rte_init.h new file +11
-0+ +/** +* Implementation specific callback function which is +* responsible for specificed initialization. +* +* This is called when almost resources are available. +* +* @return +* 0 for successful callback +* Negative for unsuccessful callback with error value +*/ lib/librte_eal/include/rte_init.h line 34
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +10
-0+typedef int (*rte_init_cb_t )(const void *arg); + +/** +* rte_init type. +* +* The rte_init of RTE_INIT_PRE are called firstly, +* and then RTE_INIT_POST. +*/ +enum rte_init_type { +RTE_INIT_PRE ,Type specific comment is missing.
Example as reference for formatting.
/**
* Enumerate trace mode operation.
*/
enumrte_trace_mode_e{
/**
* In this mode, When no space left in trace buffer, the subsequent
* events overwrite the old events in the trace buffer. */
RTE_TRACE_MODE_OVERWRITE,
/**
* In this mode, When no space left on trace buffer, the subsequent
* events shall not be recorded in the trace buffer.
*/
RTE_TRACE_MODE_DISCARD,
};lib/librte_eal/include/rte_init.h line 42
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +8
-0+ RTE_INIT_POST +}; + +/** +* Register a rte_init callback. +* +* @param cb +* A pointer to a rte_init_cb structure, which will be used s/used/invoked?
Quoted 17 lines
+ * in
rte_eal_init().
+ *
+ * @param arg
+ * The cb will use that as param.
+ *
+ * @param type
+ * The type ofrte_initregistered.
+ */lib/librte_eal/include/rte_init.h new file +9
-0+ +void rte_init_register (rte_init_cb_t cb,const void *arg, +enum rte_init_type type); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_INIT_H_ */
Signature · 1 line
Best regards, Tonghao
Re: [dpdk-dev] [PATCH dpdk-dev v2 1/2] eal: introduce rte-init queue for libraries initialization
Quoted 7 lines · Tonghao Zhang
Quoted 5 lines · Jerin Jacob
Quoted 1 line · Jerin Jacob
Three more items are missing in this patch
Can I add "Co-authored-by" for you ?
Quoted 151 lines
Quoted 2 lines
1) Unit test case for new API
2) Make the new API__rte_experimalHi Jerin
This API will be invoked in mempool, if use that prefix, there is a compile warning:include/rte_mempool.h:933:2: error: ‘rte_init_register’ is deprecated (declared atx86_64-native-linuxapp-gcc/include/rte_init.h:61): Symbol is not yet part of stable ABI [-Werror=deprecated-declarations]remove the
__rte_experimalin the patch 2?Quoted 127 lines
3) Update the .map file
Quoted 124 lines · On Thu, Apr 9, 2020 at 8:33 PM <[email protected]> wrote:
Quoted 5 lines
From: Tonghao Zhang <[email protected]>
This patch introduces last-init queue, user can register a callback for theirs initialization. Running
rte_last_init_run(),The above section needs to be rewritten wrt v2 changes.
Quoted 4 lines
the almost resource of DPDK are available, such as memzone, ring. With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
See below
Quoted 3 lines
Signed-off-by Tonghao Zhang <[email protected]>---
See above
Move [This patch will be used for next patch.] here to avoid unnecessary information in the git commit.
Quoted 15 lines
v2:
* renamerte_last_init_register->rte_init_register
* renamerte_last_initstruct ->rte_init
* renamerte_init_cb->rte_init_cb_t
* free therte_initnode when not used.
* removerte_initand others toeal_private.h
* add comments
* fix checkpatch warning
---lib/librte_eal/include/rte_init.h new file +0
-0lib/librte_eal/include/rte_init.h line 6
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 DPDK Community +*/ + +#ifndef _RTE_INIT_H_ +#define _RTE_INIT_H_@file section is missing. See
lib/librte_eal/common/include/rte_errno.has example.lib/librte_eal/include/rte_init.h line 13
Quoted 6 lines
lib/librte_eal/include/rte_init.h new file +6
-0+#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> +#include <sys/queue.h> <
sys/queue.h> is not required in public API header file.Quoted 11 lines
lib/librte_eal/include/rte_init.h new file +11
-0+ +/** +* Implementation specific callback function which is +* responsible for specificed initialization. +* +* This is called when almost resources are available. +* +* @return +* 0 for successful callback +* Negative for unsuccessful callback with error value +*/ lib/librte_eal/include/rte_init.h line 34
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +10
-0+typedef int (*rte_init_cb_t )(const void *arg); + +/** +* rte_init type. +* +* The rte_init of RTE_INIT_PRE are called firstly, +* and then RTE_INIT_POST. +*/ +enum rte_init_type { +RTE_INIT_PRE ,Type specific comment is missing.
Example as reference for formatting.
/**
* Enumerate trace mode operation.
*/
enumrte_trace_mode_e{
/**
* In this mode, When no space left in trace buffer, the subsequent
* events overwrite the old events in the trace buffer. */
RTE_TRACE_MODE_OVERWRITE,
/**
* In this mode, When no space left on trace buffer, the subsequent
* events shall not be recorded in the trace buffer.
*/
RTE_TRACE_MODE_DISCARD,
};lib/librte_eal/include/rte_init.h line 42
Quoted 10 lines
lib/librte_eal/include/rte_init.h new file +8
-0+ RTE_INIT_POST +}; + +/** +* Register a rte_init callback. +* +* @param cb +* A pointer to a rte_init_cb structure, which will be used s/used/invoked?
Quoted 9 lines
+ * in
rte_eal_init().
+ *
+ * @param arg
+ * The cb will use that as param.
+ *
+ * @param type
+ * The type ofrte_initregistered.
+ */
+Quoted 8 lines
Quoted 8 lines
lib/librte_eal/include/rte_init.h line 59
Quoted 8 lines
lib/librte_eal/include/rte_init.h new file +8
-0+void rte_init_register (rte_init_cb_t cb,const void *arg, +enum rte_init_type type); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_INIT_H_ */ --
Best regards, Tonghao
Signature · 1 line
Best regards, Tonghao
Re: [dpdk-dev] [PATCH dpdk-dev v2 1/2] eal: introduce rte-init queue for libraries initialization
Quoted 10 lines · Tonghao Zhang
Quoted 7 lines · Tonghao Zhang
Quoted 5 lines · Jerin Jacob
Quoted 1 line · Jerin Jacob
Three more items are missing in this patch
Can I add "Co-authored-by" for you ?
We are not using that tag in DPDK. Feel free to add, Suggested-by:
Jerin Jacob <[email protected]>
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
1) Unit test case for new API
2) Make the new API__rte_experimalHi Jerin
This API will be invoked in mempool, if use that prefix, there is a compile warning:include/rte_mempool.h:933:2: error: ‘rte_init_register’ is deprecated (declared atx86_64-native-linuxapp-gcc/include/rte_init.h:61): Symbol is not yet part of stable ABI [-Werror=deprecated-declarations]
http://patches.dpdk.org/patch/68119/ will be applied soon. So it will not a problem,
PATCH v3 1/2 eal: introduce rte-init queue for libraries initialization
In reply to [email protected]From: Tonghao Zhang <[email protected]>
This patch introduces rte-init queue, users can register a callback for theirs initialization. After the almost resource of DPDK are available (e.g. memzone, ring), invoke eal_rte_init_run(). With this way, users don't introduce additional codes in the eal layer.
---
This patch will be used for next patch.
and should be applied after http://patches.dpdk.org/patch/68119/
because of __rte_experimal
v3:
* add rte-init autotest
* add __rte_experimal prefix
* change return type of rte_init_register to int
* update doc/api/doxy-api-index.md
* update rte_eal_version.map
* update comments
* remove unused *.h in rte_init.h
v2:
* rename rte_last_init_register ->rte_init_register
* rename rte_last_init struct ->rte_init
* rename rte_init_cb ->rte_init_cb_t
* free the rte_init node when not used
* remove rte_init and others to eal_private.h
* add comments
* fix checkpatch warning
--- app/test/Makefile | 1 + app/test/autotest_data.py | 6 +++ app/test/meson.build | 1 + app/test/test_rte_init.c | 35 +++++++++++++ doc/api/doxy-api-index.md | 1 + lib/librte_eal/common/eal_common_init.c | 87 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 23 +++++++++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/freebsd/eal.c | 6 +++ lib/librte_eal/include/rte_init.h | 68 ++++++++++++++++++++++++++ lib/librte_eal/linux/Makefile | 1 + lib/librte_eal/linux/eal.c | 6 +++ lib/librte_eal/rte_eal_version.map | 1 + 14 files changed, 238 insertions(+) create mode 100644 app/test/test_rte_init.c create mode 100644 lib/librte_eal/common/eal_common_init.c create mode 100644 lib/librte_eal/include/rte_init.h
app/test/Makefile +1 -0
@@ -148,6 +148,7 @@ SRCS-y += test_alarm.c SRCS-y += test_interrupts.c SRCS-y += test_version.c SRCS-y += test_func_reentrancy.c +SRCS-y += test_rte_init.c SRCS-y += test_service_cores.c
app/test/autotest_data.py +6 -0
@@ -267,6 +267,12 @@ "Report": None, }, { + "Name": "RTE INIT autotest", + "Command": "rte_init_autotest", + "Func": default_autotest, + "Report": None, + }, + { "Name": "Atomics autotest", "Command": "atomic_autotest", "Func": default_autotest,
app/test/meson.build +1 -0
@@ -79,6 +79,7 @@ test_sources = files('commands.c', 'test_mempool.c', 'test_mempool_perf.c', 'test_memzone.c', + 'test_rte_init.c', 'test_meter.c', 'test_metrics.c', 'test_mcslock.c',
app/test/test_rte_init.c new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2020 DPDK Community +*/ + +#include <stdio.h> + +#include <rte_init.h> + +#include "test.h" + +static int +rte_init_cb(__rte_unused const void *arg) +{ +return 0 ; +} + +static int +test_rte_init (void ) +{ +printf ("test rte-init register API\n" ); +if (rte_init_register (rte_init_cb,NULL ,RTE_INIT_PRE ) !=0 ) +return -1 ; + +printf ("test rte-init cb\n" ); +if (rte_init_register (NULL ,NULL ,RTE_INIT_PRE ) != -EINVAL ) +return -1 ; + +printf ("test rte-init type\n" ); +if (rte_init_register (NULL ,NULL ,10 ) != -EINVAL ) +return -1 ; + +return 0 ; +} + +REGISTER_TEST_COMMAND (rte_init_autotest, test_rte_init);
doc/api/doxy-api-index.md +1 -0
@@ -178,6 +178,7 @@ The public API headers are grouped by topics: - **misc**: [EAL config] (@ref rte_eal.h), + [RTE INIT] (@ref rte_init.h), [common] (@ref rte_common.h), [experimental APIs] (@ref rte_compat.h), [ABI versioning] (@ref rte_function_versioning.h),
lib/librte_eal/common/eal_common_init.c new file +87 -0
87 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +23 -0
@@ -11,6 +11,7 @@#include <rte_dev.h> #include <rte_lcore.h> +#include <rte_init.h> /** * Structure storing internal configuration (per-lcore)
@@ -60,6 +61,28 @@ struct rte_config { } __attribute__((__packed__));/** +* A structure describing a generic initialization. +*/ +struct rte_init { +TAILQ_ENTRY (rte_init) next; +enum rte_init_type type; +rte_init_cb_t cb; +const void *arg; +}; + +/** Double linked list of rte_init. */ +TAILQ_HEAD (rte_init_list, rte_init); + +/** +* Run the callback registered in the global double linked list. +* +* @return +* - 0 on success +* - Negative on error +*/ +int eal_rte_init_run (void ); + +/** * Get the global configuration structure. * * @return
lib/librte_eal/common/meson.build +1 -0
@@ -43,6 +43,7 @@ sources += files( 'eal_common_thread.c', 'eal_common_timer.c', 'eal_common_uuid.c', + 'eal_common_init.c', 'hotplug_mp.c', 'malloc_elem.c', 'malloc_heap.c',
lib/librte_eal/freebsd/Makefile +1 -0
@@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_uuid.c +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_init.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += malloc_elem.c
lib/librte_eal/freebsd/eal.c +6 -0
@@ -874,6 +874,12 @@ static void rte_eal_init_alert(const char *msg)eal_check_mem_on_local_socket (); +if (eal_rte_init_run () <0 ) { +rte_eal_init_alert ("Cannot init objects in rte-init queue" ); + rte_errno =EFAULT ; +return -1 ; + } +eal_thread_init_master (rte_config.master_lcore); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
lib/librte_eal/include/rte_init.h new file +68 -0
68 lines not on this page · raw message
lib/librte_eal/linux/Makefile +1 -0
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_uuid.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_init.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += hotplug_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += malloc_elem.c
lib/librte_eal/linux/eal.c +6 -0
@@ -1203,6 +1203,12 @@ static void rte_eal_init_alert(const char *msg)eal_check_mem_on_local_socket (); +if (eal_rte_init_run () <0 ) { +rte_eal_init_alert ("Cannot init objects in rte-init queue" ); + rte_errno =EFAULT ; +return -1 ; + } +eal_thread_init_master (rte_config.master_lcore); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
lib/librte_eal/rte_eal_version.map +1 -0
@@ -338,4 +338,5 @@ EXPERIMENTAL { # added in 20.05 rte_log_can_log; + rte_init_register; };
Signature · 1 line
1.8.3.1
PATCH v3 2/2 mempool: use shared memzone for rte_mempool_ops
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the rte_mempool_ops_table. For example, when building APPs with:
$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...
The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the mk/rte.app.mk to build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue (access null and crash) rte_mempool_get_ops (should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burst
To avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority in RTE_INIT, but it's not easy to maintain.
* change mk/rte.app.mk: Change the order in mk/rte.app.mk to be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.
* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table. but the number of mempool libraries may be different.
* shared memzone: The primary process allocates a struct in shared memory named memzone, When we register a mempool ops, we first get a name and id from the shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Previous discussion: https://mails.dpdk.org/archives/dev/2020-March/159354.html
---
v2:
* fix checkpatch warning
--- lib/librte_mempool/rte_mempool.h | 28 +++++++++++- lib/librte_mempool/rte_mempool_ops.c | 89 ++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 21 deletions(-)
lib/librte_mempool/rte_mempool.h +26 -2
@@ -50,6 +50,7 @@#include <rte_ring.h> #include <rte_memcpy.h> #include <rte_common.h> +#include <rte_init.h> #ifdef __cplusplusextern "C" {
@@ -678,7 +679,6 @@ struct rte_mempool_ops {*/ struct rte_mempool_ops_table {rte_spinlock_t sl;/**< Spinlock for add/delete. */ -uint32_t num_ops;/**< Number of used ops structs in the table. */ /** * Storage for all possible ops structs. */
@@ -910,6 +910,30 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,*/ int rte_mempool_register_ops (const struct rte_mempool_ops *ops); +struct rte_mempool_shared_ops { +size_t num_mempool_ops; +struct { +char name[RTE_MEMPOOL_OPS_NAMESIZE ]; + } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX ]; + +rte_spinlock_t mempool; +}; + +static inline int +mempool_ops_register_cb (const void *arg) +{ +const struct rte_mempool_ops *h = (const struct rte_mempool_ops *)arg; + +return rte_mempool_register_ops (h); +} + +static inline void +mempool_ops_register (const struct rte_mempool_ops *ops) +{ +rte_init_register (mempool_ops_register_cb, (const void *)ops, +RTE_INIT_PRE ); +} +/** * Macro to statically register the ops of a mempool handler. * Note that the rte_mempool_register_ops fails silently here when
@@ -918,7 +942,7 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,#define MEMPOOL_REGISTER_OPS (ops) \ RTE_INIT(mp_hdlr_init_##ops) \ { \ - rte_mempool_register_ops(&ops); \ + mempool_ops_register(&ops); \ }/**
lib/librte_mempool/rte_mempool_ops.c +70 -19
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
Quoted 13 lines · Thomas Monjalon
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.
Quoted 7 lines
We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.
will I stop update the patches or when the patch is ready and then decide applied or not?
Quoted 2 lines
Signature · 1 line
Best regards, Tonghao
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
27/04/2020 10:03, Tonghao Zhang:
Quoted 18 lines · Thomas Monjalon
Quoted 17 lines
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
Quoted 6 lines
Quoted 3 lines
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.will I stop update the patches or when the patch is ready and then decide applied or not?
As I said, it requires more discussion.
Please start by answering my question above.
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
Quoted 19 lines · Thomas Monjalon
27/04/2020 10:03, Tonghao Zhang:
Quoted 17 lines · Thomas Monjalon
Quoted 16 lines
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
Hi Thomas,
The library mempool linked order can trigger that problem. but when the library is loaded
dynamically, trigger that problem too.
as Olivier Matz said:
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application.
the message in https://mails.dpdk.org/archives/dev/2020-March/159354.html
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.will I stop update the patches or when the patch is ready and then decide applied or not?
As I said, it requires more discussion.
Please start by answering my question above.
I got it, Thanks.
Quoted 1 line
Signature · 1 line
Best regards, Tonghao
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
Quoted 31 lines · Tonghao Zhang
Quoted 19 lines · Thomas Monjalon
27/04/2020 10:03, Tonghao Zhang:
Quoted 17 lines · Thomas Monjalon
Quoted 16 lines
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
Hi Thomas,
The library mempool linked order can trigger that problem. but when the library is loaded
dynamically, trigger that problem too.
as Olivier Matz said:
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application.
Quoted 1 line
the message in https://mails.dpdk.org/archives/dev/2020-March/159354.html
Hi Thomas,
For first patch, I guess we support a callback for other library, it make the codes much cleaner
at eal layer. Otherwise, if we init for library, we may include their header file.
There is a better solution ?
Quoted 15 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.will I stop update the patches or when the patch is ready and then decide applied or not?
As I said, it requires more discussion.
Please start by answering my question above.I got it, Thanks.
Quoted 1 line
--
Best regards, Tonghao
Signature · 1 line
Best regards, Tonghao
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
Hi,
Quoted 32 lines · Tonghao Zhang
Quoted 31 lines · Tonghao Zhang
Quoted 19 lines · Thomas Monjalon
27/04/2020 10:03, Tonghao Zhang:
Quoted 17 lines · Thomas Monjalon
Quoted 16 lines
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
Hi Thomas,
The library mempool linked order can trigger that problem. but when the library is loaded
dynamically, trigger that problem too.
as Olivier Matz said:
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application.
Quoted 7 lines
Quoted 1 line
the message in https://mails.dpdk.org/archives/dev/2020-March/159354.html
Hi Thomas,
For first patch, I guess we support a callback for other library, it make the codes much cleaner
at eal layer. Otherwise, if we init for library, we may include their header file.
There is a better solution ?
To summarize my understanding of the issu encountered by Tonghao:
Currently, it is not possible to call memzone_register() from an init function (registered with RTE_INIT()). This is needed if we want to store the list of registered mempool ops in a shared memory, available from multiprocess.
Tonghao's patch 1/2 solves this issue. I tried to find alternatives to this approach, but none of them seems satisfying:
- use RTE_PMD_REGISTER_VDEV() and rte_vdev_add_custom_scan() instead of RTE_INIT() in the MEMPOOL_REGISTER_OPS() macro to delay the initialization after eal_init(). This looks too complex (I made a POC of it, it someone is interested).
- synchronize mempool ops in shared memory when mempool_create() is called in the primary: this would probably works most of the time, but it is not a perfect solution as we cannot ensure that the primary application will create a mempool before the secondary comes up.
- introduce a mandatory call to rte_mempool_lib_init(): despite it's the usual way to initialize libs, this will break compatibility.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.
OK, let's discuss it once 20.05 is out.
Regards,
Olivier
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
Quoted 67 lines · Olivier Matz
Hi,
Quoted 32 lines · Tonghao Zhang
Quoted 31 lines · Tonghao Zhang
Quoted 19 lines · Thomas Monjalon
27/04/2020 10:03, Tonghao Zhang:
Quoted 17 lines · Thomas Monjalon
Quoted 16 lines
13/04/2020 16:21, [email protected]:
Quoted 10 lines
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.We are supposed to use pkg-config to link DPDK. Does the problem appear between a DPDK compiled with meson and an application linked with pkg-config information?
Hi Thomas,
The library mempool linked order can trigger that problem. but when the library is loaded
dynamically, trigger that problem too.
as Olivier Matz said:
The fact that the ops index changes during mempool driver lifetime is indeed frightening, especially knowning that this is a dynamic registration that could happen at any moment in the life of the application.Quoted 7 lines
Quoted 1 line
the message in https://mails.dpdk.org/archives/dev/2020-March/159354.html
Hi Thomas,
For first patch, I guess we support a callback for other library, it make the codes much cleaner
at eal layer. Otherwise, if we init for library, we may include their header file.
There is a better solution ?To summarize my understanding of the issu encountered by Tonghao:
Currently, it is not possible to call
memzone_register()from an init function (registered withRTE_INIT()). This is needed if we want to store the list of registered mempool ops in a shared memory, available from multiprocess.Tonghao's patch 1/2 solves this issue. I tried to find alternatives to this approach, but none of them seems satisfying:
- use
RTE_PMD_REGISTER_VDEV()andrte_vdev_add_custom_scan()instead ofRTE_INIT()in theMEMPOOL_REGISTER_OPS()macro to delay the initialization aftereal_init(). This looks too complex (I made a POC of it, it someone is interested).- synchronize mempool ops in shared memory when
mempool_create()is called in the primary: this would probably works most of the time, but it is not a perfect solution as we cannot ensure that the primary application will create a mempool before the secondary comes up.- introduce a mandatory call to
rte_mempool_lib_init(): despite it's the usual way to initialize libs, this will break compatibility.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
If the problem really needs to be solved,
the EAL patch (first of this series) needs to be discussed and reviewed carefully. I don't imagine it being done in 20.05.OK, let's discuss it once 20.05 is out.
Any news on this topic?
Is this issue still a problem?
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
In reply to [email protected]Quoted 83 lines · On 4/13/20 5:21 PM, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table. but the number of mempool libraries may be different.
* shared memzone: The primary process allocates a struct in shared memory named memzone, When we register a mempool ops, we first get a name and id from the shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Previous discussion: https://mails.dpdk.org/archives/dev/2020-March/159354.html
Suggested-by Olivier Matz <[email protected]>Suggested-by Jerin Jacob <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>---
v2:
* fix checkpatch warning--- lib/librte_mempool/rte_mempool.h | 28 +++++++++++- lib/librte_mempool/rte_mempool_ops.c | 89 ++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 21 deletions(-)lib/librte_mempool/rte_mempool.h +1
-1@@ -50,6 +50,7 @@#include <rte_ring.h> #include <rte_memcpy.h> #include <rte_common.h> +#include <rte_init.h> #ifdef __cplusplusextern "C" {@@ -678,7 +679,6 @@ struct rte_mempool_ops {*/ struct rte_mempool_ops_table {rte_spinlock_t sl;/**< Spinlock for add/delete. */ -uint32_t num_ops;/**< Number of used ops structs in the table. */ /** * Storage for all possible ops structs. */
lib/librte_mempool/rte_mempool.h int rte_mempool_ops_get_info(const struct rte_mempool *mp, · line 914
Quoted 5 lines
lib/librte_mempool/rte_mempool.h +2
-0@@ -910,6 +910,30 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,*/ int rte_mempool_register_ops (const struct rte_mempool_ops *ops); +struct rte_mempool_shared_ops { +size_t num_mempool_ops;
Is there any specific reason to change type from uint32_t used above to size_t? I think that uint32_t is better here since it is just a number, not a size of memory or related value.
Quoted 48 lines
lib/librte_mempool/rte_mempool.h +23
-1+struct { +char name[RTE_MEMPOOL_OPS_NAMESIZE ]; + } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX ]; + +rte_spinlock_t mempool; +}; + +static inline int +mempool_ops_register_cb (const void *arg) +{ +const struct rte_mempool_ops *h = (const struct rte_mempool_ops *)arg; + +return rte_mempool_register_ops (h); +} + +static inline void +mempool_ops_register (const struct rte_mempool_ops *ops) +{ +rte_init_register (mempool_ops_register_cb, (const void *)ops, +RTE_INIT_PRE ); +} +/** * Macro to statically register the ops of a mempool handler. * Note that the rte_mempool_register_ops fails silently here when @@ -918,7 +942,7 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,#define MEMPOOL_REGISTER_OPS (ops) \ RTE_INIT(mp_hdlr_init_##ops) \ { \ - rte_mempool_register_ops(&ops); \ + mempool_ops_register(&ops); \ }/** lib/librte_mempool/rte_mempool_ops.c +0
-4@@ -14,43 +14,95 @@/* indirect jump table to support external memory pools. */ struct rte_mempool_ops_table rte_mempool_ops_table = { .sl =RTE_SPINLOCK_INITIALIZER , - .num_ops =0 }; -/* add a new ops struct in rte_mempool_ops_table, return its index. */ -int -rte_mempool_register_ops (const struct rte_mempool_ops *h)
lib/librte_mempool/rte_mempool_ops.c line 26
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +7
-2+static int +rte_mempool_register_shared_ops (const char *name) { -struct rte_mempool_ops *ops; -int16_t ops_index; +static bool mempool_shared_ops_inited; +struct rte_mempool_shared_ops *shared_ops; +const struct rte_memzone *mz; +uint32_t ops_index =0 ; +
I think we should sanity check 'name' here to be not empty string (see review notes below).
Quoted 25 lines
lib/librte_mempool/rte_mempool_ops.c +21
-2+if (rte_eal_process_type () ==RTE_PROC_PRIMARY && + !mempool_shared_ops_inited) { + + mz =rte_memzone_reserve ("mempool_ops_shared" , +sizeof (*shared_ops),0 ,0 ); +if (mz ==NULL ) +return -ENOMEM ; + + shared_ops = mz->addr; + shared_ops->num_mempool_ops =0 ; +rte_spinlock_init (&shared_ops->mempool); + + mempool_shared_ops_inited = true; + }else { + mz =rte_memzone_lookup ("mempool_ops_shared" ); +if (mz ==NULL ) +return -ENOMEM ; + + shared_ops = mz->addr; + } -rte_spinlock_lock (&rte_mempool_ops_table.sl); +rte_spinlock_lock (&shared_ops->mempool); - if (rte_mempool_ops_table.num_ops >=
lib/librte_mempool/rte_mempool_ops.c line 57
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +3
-2- RTE_MEMPOOL_MAX_OPS_IDX) { -rte_spinlock_unlock (&rte_mempool_ops_table.sl); +if (shared_ops->num_mempool_ops >=RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&shared_ops->mempool);RTE_LOG (ERR ,MEMPOOL ,"Maximum number of mempool ops structs exceeded\n" );return -ENOSPC ; } +while (shared_ops->mempool_ops[ops_index].name[0 ]) {
Please, compare with '\0' as DPDK style guide says.
Quoted 18 lines
lib/librte_mempool/rte_mempool_ops.c +18
-0+if (!strcmp (name, shared_ops->mempool_ops[ops_index].name)) { +rte_spinlock_unlock (&shared_ops->mempool); +return ops_index; + } + + ops_index++; + } + +strlcpy (shared_ops->mempool_ops[ops_index].name, name, +sizeof (shared_ops->mempool_ops[0 ].name)); + + shared_ops->num_mempool_ops++; + +rte_spinlock_unlock (&shared_ops->mempool); +return ops_index; +} + +/* add a new ops struct in rte_mempool_ops_table, return its index. */
lib/librte_mempool/rte_mempool_ops.c line 83
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +7
-2+int +rte_mempool_register_ops (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; +if (h->alloc ==NULL || h->enqueue ==NULL || - h->dequeue ==NULL || h->get_count ==NULL ) { -rte_spinlock_unlock (&rte_mempool_ops_table.sl); + h->dequeue ==NULL || h->get_count ==NULL ) {
Changing formatting just makes review a bit more harder.
lib/librte_mempool/rte_mempool_ops.c line 86
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c +1
-0RTE_LOG (ERR ,MEMPOOL ,"Missing callback while registering mempool ops\n" ); + rte_errno =EINVAL ;
Why is it done in the patch? For me it looks like logically different change if it is really required (properly motivated).
lib/librte_mempool/rte_mempool_ops.c line 93
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +3
-3return -EINVAL ; }if (strlen (h->name) >=sizeof (ops->name) -1 ) { -rte_spinlock_unlock (&rte_mempool_ops_table.sl); -RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , - __func__, h->name); +RTE_LOG (ERR ,MEMPOOL , +"The registering mempool_ops <%s>: name too long\n" , + h->name);
Why do you change from DEBUG to ERR here? It it not directly related to the purpose of the patch.
Quoted 17 lines
lib/librte_mempool/rte_mempool_ops.c +8
-1rte_errno =EEXIST ;return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; + ops_index =rte_mempool_register_shared_ops (h->name); +if (ops_index <0 ) { + rte_errno = -ops_index; +return ops_index; + } + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 221
Quoted 8 lines
lib/librte_mempool/rte_mempool_ops.c +2
-3@@ -165,9 +217,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {if (mp->flags &MEMPOOL_F_POOL_CREATED )return -EEXIST ; -for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { -if (!strcmp (name, - rte_mempool_ops_table.ops[i].name)) { +for (i =0 ; i <RTE_MEMPOOL_MAX_OPS_IDX ; i++) { +if (!strcmp (name, rte_mempool_ops_table.ops[i].name)) {
Since rte_mempool_ops_table is filled in which zeros, name string is empty by default. So, request with empty name will match the first unused entry. I guess it is not what we want here. I think we should handle empty string before the loop and return -EINVAL.
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c +0
-0ops = &rte_mempool_ops_table.ops[i];break ; }
Re: [dpdk-dev] [PATCH dpdk-dev v3 2/2] mempool: use shared memzone for rte_mempool_ops
Quoted 88 lines · Andrew Rybchenko
Quoted 86 lines · On 4/13/20 5:21 PM, [email protected] wrote:
From: Tonghao Zhang <[email protected]>
The order of mempool initiation affects mempool index in the
rte_mempool_ops_table. For example, when building APPs with:$ gcc -lrte_mempool_bucket -lrte_mempool_ring ...The "bucket" mempool will be registered firstly, and its index in table is 0 while the index of "ring" mempool is 1. DPDK uses the
mk/rte.app.mkto build APPs, and others, for example, Open vSwitch, use the libdpdk.a or libdpdk.so to build it. The mempool lib linked in dpdk and Open vSwitch is different.The mempool can be used between primary and secondary process, such as dpdk-pdump and pdump-pmd/Open vSwitch(pdump enabled). There will be a crash because dpdk-pdump creates the "
ring_mp_mc" ring which index in table is 0, but the index of "bucket" ring is 0 in Open vSwitch. If Open vSwitch use the index 0 to get mempool ops and malloc memory from mempool. The crash will occur:
bucket_dequeue(access null and crash)rte_mempool_get_ops(should get "ring_mp_mc",
but get "bucket" mempool)
rte_mempool_ops_dequeue_bulk
...
rte_pktmbuf_alloc
rte_pktmbuf_copy
pdump_copy
pdump_rx
rte_eth_rx_burstTo avoid the crash, there are some solution:
* constructor priority: Different mempool uses different priority inRTE_INIT, but it's not easy to maintain.* change
mk/rte.app.mk: Change the order inmk/rte.app.mkto be same as libdpdk.a/libdpdk.so, but when adding a new mempool driver in future, we must make sure the order.* register mempool orderly: Sort the mempool when registering, so the lib linked will not affect the index in mempool table. but the number of mempool libraries may be different.
* shared memzone: The primary process allocates a struct in shared memory named memzone, When we register a mempool ops, we first get a name and id from the shared struct: with the lock held, lookup for the registered name and return its index, else get the last id and copy the name in the struct.
Previous discussion: https://mails.dpdk.org/archives/dev/2020-March/159354.html
Suggested-by Olivier Matz <[email protected]>Suggested-by Jerin Jacob <[email protected]>Signed-off-by Tonghao Zhang <[email protected]>---
v2:
* fix checkpatch warning--- lib/librte_mempool/rte_mempool.h | 28 +++++++++++- lib/librte_mempool/rte_mempool_ops.c | 89 ++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 21 deletions(-)lib/librte_mempool/rte_mempool.h +1
-1@@ -50,6 +50,7 @@#include <rte_ring.h> #include <rte_memcpy.h> #include <rte_common.h> +#include <rte_init.h> #ifdef __cplusplusextern "C" {@@ -678,7 +679,6 @@ struct rte_mempool_ops {*/ struct rte_mempool_ops_table {rte_spinlock_t sl;/**< Spinlock for add/delete. */ -uint32_t num_ops;/**< Number of used ops structs in the table. */ /** * Storage for all possible ops structs. */ @@ -910,6 +910,30 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,*/ int rte_mempool_register_ops (const struct rte_mempool_ops *ops);
Quoted 6 lines
lib/librte_mempool/rte_mempool.h int rte_mempool_ops_get_info(const struct rte_mempool *mp, · line 914
Quoted 2 lines
lib/librte_mempool/rte_mempool.h +2
-0+struct rte_mempool_shared_ops { +size_t num_mempool_ops;Is there any specific reason to change type from
uint32_tused above tosize_t? I think thatuint32_tis better here since it is just a number, not a size of memory or related value.
Thanks for you review. busy to commit other patch, so that be delayed. I will change that in next version.
Quoted 45 lines
Quoted 45 lines
lib/librte_mempool/rte_mempool.h +23
-1+struct { +char name[RTE_MEMPOOL_OPS_NAMESIZE ]; + } mempool_ops[RTE_MEMPOOL_MAX_OPS_IDX ]; + +rte_spinlock_t mempool; +}; + +static inline int +mempool_ops_register_cb (const void *arg) +{ +const struct rte_mempool_ops *h = (const struct rte_mempool_ops *)arg; + +return rte_mempool_register_ops (h); +} + +static inline void +mempool_ops_register (const struct rte_mempool_ops *ops) +{ +rte_init_register (mempool_ops_register_cb, (const void *)ops, +RTE_INIT_PRE ); +} +/** * Macro to statically register the ops of a mempool handler. * Note that the rte_mempool_register_ops fails silently here when @@ -918,7 +942,7 @@ int rte_mempool_ops_get_info(const struct rte_mempool *mp,#define MEMPOOL_REGISTER_OPS (ops) \ RTE_INIT(mp_hdlr_init_##ops) \ { \ - rte_mempool_register_ops(&ops); \ + mempool_ops_register(&ops); \ }/** lib/librte_mempool/rte_mempool_ops.c +0
-1@@ -14,43 +14,95 @@/* indirect jump table to support external memory pools. */ struct rte_mempool_ops_table rte_mempool_ops_table = { .sl =RTE_SPINLOCK_INITIALIZER , - .num_ops =0 };
Quoted 16 lines
lib/librte_mempool/rte_mempool_ops.c line 26
Quoted 13 lines
lib/librte_mempool/rte_mempool_ops.c +7
-5-/* add a new ops struct in rte_mempool_ops_table, return its index. */ -int -rte_mempool_register_ops (const struct rte_mempool_ops *h) +static int +rte_mempool_register_shared_ops (const char *name) { -struct rte_mempool_ops *ops; -int16_t ops_index; +static bool mempool_shared_ops_inited; +struct rte_mempool_shared_ops *shared_ops; +const struct rte_memzone *mz; +uint32_t ops_index =0 ; +I think we should sanity check 'name' here to be not empty string (see review notes below).
OK
Quoted 69 lines
Quoted 25 lines
lib/librte_mempool/rte_mempool_ops.c +21
-2+if (rte_eal_process_type () ==RTE_PROC_PRIMARY && + !mempool_shared_ops_inited) { + + mz =rte_memzone_reserve ("mempool_ops_shared" , +sizeof (*shared_ops),0 ,0 ); +if (mz ==NULL ) +return -ENOMEM ; + + shared_ops = mz->addr; + shared_ops->num_mempool_ops =0 ; +rte_spinlock_init (&shared_ops->mempool); + + mempool_shared_ops_inited = true; + }else { + mz =rte_memzone_lookup ("mempool_ops_shared" ); +if (mz ==NULL ) +return -ENOMEM ; + + shared_ops = mz->addr; + } -rte_spinlock_lock (&rte_mempool_ops_table.sl); +rte_spinlock_lock (&shared_ops->mempool); - if (rte_mempool_ops_table.num_ops >=lib/librte_mempool/rte_mempool_ops.c line 57
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +3
-2- RTE_MEMPOOL_MAX_OPS_IDX) { -rte_spinlock_unlock (&rte_mempool_ops_table.sl); +if (shared_ops->num_mempool_ops >=RTE_MEMPOOL_MAX_OPS_IDX ) { +rte_spinlock_unlock (&shared_ops->mempool);RTE_LOG (ERR ,MEMPOOL ,"Maximum number of mempool ops structs exceeded\n" );return -ENOSPC ; } +while (shared_ops->mempool_ops[ops_index].name[0 ]) {Please, compare with '\0' as DPDK style guide says.
Quoted 18 lines
lib/librte_mempool/rte_mempool_ops.c +18
-0+if (!strcmp (name, shared_ops->mempool_ops[ops_index].name)) { +rte_spinlock_unlock (&shared_ops->mempool); +return ops_index; + } + + ops_index++; + } + +strlcpy (shared_ops->mempool_ops[ops_index].name, name, +sizeof (shared_ops->mempool_ops[0 ].name)); + + shared_ops->num_mempool_ops++; + +rte_spinlock_unlock (&shared_ops->mempool); +return ops_index; +} + +/* add a new ops struct in rte_mempool_ops_table, return its index. */ lib/librte_mempool/rte_mempool_ops.c line 83
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +7
-2+int +rte_mempool_register_ops (const struct rte_mempool_ops *h) +{ +struct rte_mempool_ops *ops; +int16_t ops_index; +if (h->alloc ==NULL || h->enqueue ==NULL || - h->dequeue ==NULL || h->get_count ==NULL ) { -rte_spinlock_unlock (&rte_mempool_ops_table.sl); + h->dequeue ==NULL || h->get_count ==NULL ) {Changing formatting just makes review a bit more harder.
Quoted 6 lines
lib/librte_mempool/rte_mempool_ops.c line 86
Quoted 3 lines
lib/librte_mempool/rte_mempool_ops.c +1
-0RTE_LOG (ERR ,MEMPOOL ,"Missing callback while registering mempool ops\n" ); + rte_errno =EINVAL ;Why is it done in the patch? For me it looks like logically different change if it is really required (properly motivated).
I guess that should add the err code to rte_rrno ? but I am fine, not to do that.
Quoted 11 lines
lib/librte_mempool/rte_mempool_ops.c line 93
Quoted 10 lines
lib/librte_mempool/rte_mempool_ops.c +3
-3return -EINVAL ; }if (strlen (h->name) >=sizeof (ops->name) -1 ) { -rte_spinlock_unlock (&rte_mempool_ops_table.sl); -RTE_LOG (DEBUG ,EAL ,"%s(): mempool_ops <%s>: name too long\n" , - __func__, h->name); +RTE_LOG (ERR ,MEMPOOL , +"The registering mempool_ops <%s>: name too long\n" , + h->name);
Quoted 2 lines
Why do you change from DEBUG to ERR here? It it not directly related to the purpose of the patch.
Yes, because it is an error, so change that type. I change it in separate patch ?
Quoted 20 lines
Quoted 20 lines
lib/librte_mempool/rte_mempool_ops.c +8
-1rte_errno =EEXIST ;return -EEXIST ; } - ops_index = rte_mempool_ops_table.num_ops++; + ops_index =rte_mempool_register_shared_ops (h->name); +if (ops_index <0 ) { + rte_errno = -ops_index; +return ops_index; + } + +rte_spinlock_lock (&rte_mempool_ops_table.sl); + ops = &rte_mempool_ops_table.ops[ops_index];strlcpy (ops->name, h->name,sizeof (ops->name)); ops->alloc = h->alloc;@@ -165,9 +217,8 @@ struct rte_mempool_ops_table rte_mempool_ops_table = {if (mp->flags &MEMPOOL_F_POOL_CREATED )return -EEXIST ;
Quoted 11 lines
lib/librte_mempool/rte_mempool_ops.c struct rte_mempool_ops_table rte_mempool_ops_table = { · line 221
Quoted 5 lines
lib/librte_mempool/rte_mempool_ops.c +2
-3-for (i =0 ; i < rte_mempool_ops_table.num_ops; i++) { -if (!strcmp (name, - rte_mempool_ops_table.ops[i].name)) { +for (i =0 ; i <RTE_MEMPOOL_MAX_OPS_IDX ; i++) { +if (!strcmp (name, rte_mempool_ops_table.ops[i].name)) {Since
rte_mempool_ops_tableis filled in which zeros, name string is empty by default. So, request with empty name will match the first unused entry. I guess it is not what we want here. I think we should handle empty string before the loop and return-EINVAL.
OK, thanks.
Quoted 5 lines
Quoted 4 lines
lib/librte_mempool/rte_mempool_ops.c +0
-0ops = &rte_mempool_ops_table.ops[i];break ; }
Signature · 1 line
Best regards, Tonghao