diff mbox

[ovs-dev,4/5] lib/dp-packet: copy multi-segments data from DPDK mbuf

Message ID 1493705445-5774-5-git-send-email-qdy220091330@gmail.com
State Changes Requested
Headers show

Commit Message

Michael Qiu May 2, 2017, 6:10 a.m. UTC
From: Michael Qiu <qiudayu@chinac.com>

When doing packet clone, if packet source is from DPDK driver,
multi-segment must be considered, and copy the segment's
data one by one.

Signed-off-by: Michael Qiu <qiudayu@chinac.com>
---
 lib/dp-packet.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

Comments

Mark Kavanagh May 3, 2017, 3:37 p.m. UTC | #1
>
>From: Michael Qiu <qiudayu@chinac.com>
>
>When doing packet clone, if packet source is from DPDK driver,
>multi-segment must be considered, and copy the segment's
>data one by one.
>
>Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>---
> lib/dp-packet.c | 27 ++++++++++++++++++++++++---
> 1 file changed, 24 insertions(+), 3 deletions(-)
>
>diff --git a/lib/dp-packet.c b/lib/dp-packet.c
>index 79f6e7e..1093e4a 100644
>--- a/lib/dp-packet.c
>+++ b/lib/dp-packet.c
>@@ -165,9 +165,30 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t
>headroom)
> {
>     struct dp_packet *new_buffer;
>
>-    new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
>-                                                 dp_packet_size(buffer),
>-                                                 headroom);
>+    uint32_t size = dp_packet_size(buffer);
>+
>+    /* copy multi-seg data */
>+#ifdef DPDK_NETDEV
>+    if (buffer->source == DPBUF_DPDK && buffer->mbuf.nb_segs > 1) {
>+        uint32_t off_set = 0;
>+        void *dst = NULL;
>+        struct rte_mbuf *tmbuf = CONST_CAST(struct rte_mbuf *, &(buffer->mbuf));
>+
>+        new_buffer = dp_packet_new_with_headroom(size, headroom);
>+        dst = dp_packet_put_uninit(new_buffer, size);
>+
>+        while (tmbuf) {
>+            rte_memcpy((char *)dst + off_set,
>+                       rte_pktmbuf_mtod(tmbuf, void *), tmbuf->data_len);
>+            off_set += tmbuf->data_len;
>+            tmbuf = tmbuf->next;
>+        }
>+    }
>+    else
>+#endif
Shouldn't this be #else, since the buffer has already been cloned for DPDK case?

>+        new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
>+                                                        size, headroom);

Shouldn't this be #endif?
>+
>     new_buffer->l2_pad_size = buffer->l2_pad_size;
>     new_buffer->l2_5_ofs = buffer->l2_5_ofs;
>     new_buffer->l3_ofs = buffer->l3_ofs;
>--
>1.8.3.1
Michael Qiu May 3, 2017, 3:57 p.m. UTC | #2
在 2017年5月3日,下午11:37,Kavanagh, Mark B <mark.b.kavanagh@intel.com> 写道:

>> 
>> From: Michael Qiu <qiudayu@chinac.com>
>> 
>> When doing packet clone, if packet source is from DPDK driver,
>> multi-segment must be considered, and copy the segment's
>> data one by one.
>> 
>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>> ---
>> lib/dp-packet.c | 27 ++++++++++++++++++++++++---
>> 1 file changed, 24 insertions(+), 3 deletions(-)
>> 
>> diff --git a/lib/dp-packet.c b/lib/dp-packet.c
>> index 79f6e7e..1093e4a 100644
>> --- a/lib/dp-packet.c
>> +++ b/lib/dp-packet.c
>> @@ -165,9 +165,30 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t
>> headroom)
>> {
>>    struct dp_packet *new_buffer;
>> 
>> -    new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
>> -                                                 dp_packet_size(buffer),
>> -                                                 headroom);
>> +    uint32_t size = dp_packet_size(buffer);
>> +
>> +    /* copy multi-seg data */
>> +#ifdef DPDK_NETDEV
>> +    if (buffer->source == DPBUF_DPDK && buffer->mbuf.nb_segs > 1) {
>> +        uint32_t off_set = 0;
>> +        void *dst = NULL;
>> +        struct rte_mbuf *tmbuf = CONST_CAST(struct rte_mbuf *, &(buffer->mbuf));
>> +
>> +        new_buffer = dp_packet_new_with_headroom(size, headroom);
>> +        dst = dp_packet_put_uninit(new_buffer, size);
>> +
>> +        while (tmbuf) {
>> +            rte_memcpy((char *)dst + off_set,
>> +                       rte_pktmbuf_mtod(tmbuf, void *), tmbuf->data_len);
>> +            off_set += tmbuf->data_len;
>> +            tmbuf = tmbuf->next;
>> +        }
>> +    }
>> +    else
>> +#endif
> Shouldn't this be #else, since the buffer has already been cloned for DPDK case?

Because, if the nb_segs equal to 1, it will be the previous case.  so it doesn't care the buffer source.


> 
>> +        new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
>> +                                                        size, headroom);
> 
> Shouldn't this be #endif?
>> +
>>    new_buffer->l2_pad_size = buffer->l2_pad_size;
>>    new_buffer->l2_5_ofs = buffer->l2_5_ofs;
>>    new_buffer->l3_ofs = buffer->l3_ofs;
>> --
>> 1.8.3.1
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Mark Kavanagh May 4, 2017, 9:20 a.m. UTC | #3
>在 2017年5月3日,下午11:37,Kavanagh, Mark B <mark.b.kavanagh@intel.com> 写道:
>
>>>
>>> From: Michael Qiu <qiudayu@chinac.com>
>>>
>>> When doing packet clone, if packet source is from DPDK driver,
>>> multi-segment must be considered, and copy the segment's
>>> data one by one.
>>>
>>> Signed-off-by: Michael Qiu <qiudayu@chinac.com>
>>> ---
>>> lib/dp-packet.c | 27 ++++++++++++++++++++++++---
>>> 1 file changed, 24 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/lib/dp-packet.c b/lib/dp-packet.c
>>> index 79f6e7e..1093e4a 100644
>>> --- a/lib/dp-packet.c
>>> +++ b/lib/dp-packet.c
>>> @@ -165,9 +165,30 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t
>>> headroom)
>>> {
>>>    struct dp_packet *new_buffer;
>>>
>>> -    new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
>>> -                                                 dp_packet_size(buffer),
>>> -                                                 headroom);
>>> +    uint32_t size = dp_packet_size(buffer);
>>> +
>>> +    /* copy multi-seg data */
>>> +#ifdef DPDK_NETDEV
>>> +    if (buffer->source == DPBUF_DPDK && buffer->mbuf.nb_segs > 1) {
>>> +        uint32_t off_set = 0;
>>> +        void *dst = NULL;
>>> +        struct rte_mbuf *tmbuf = CONST_CAST(struct rte_mbuf *, &(buffer->mbuf));
>>> +
>>> +        new_buffer = dp_packet_new_with_headroom(size, headroom);
>>> +        dst = dp_packet_put_uninit(new_buffer, size);
>>> +
>>> +        while (tmbuf) {
>>> +            rte_memcpy((char *)dst + off_set,
>>> +                       rte_pktmbuf_mtod(tmbuf, void *), tmbuf->data_len);
>>> +            off_set += tmbuf->data_len;
>>> +            tmbuf = tmbuf->next;
>>> +        }
>>> +    }
>>> +    else
>>> +#endif
>> Shouldn't this be #else, since the buffer has already been cloned for DPDK case?
>
>Because, if the nb_segs equal to 1, it will be the previous case.  so it doesn't care the
>buffer source.

Yes, of course - please disregard that comment!

>
>
>>
>>> +        new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
>>> +                                                        size, headroom);
>>
>> Shouldn't this be #endif?
>>> +
>>>    new_buffer->l2_pad_size = buffer->l2_pad_size;
>>>    new_buffer->l2_5_ofs = buffer->l2_5_ofs;
>>>    new_buffer->l3_ofs = buffer->l3_ofs;
>>> --
>>> 1.8.3.1
>>
>> _______________________________________________
>> dev mailing list
>> dev@openvswitch.org
>> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox

Patch

diff --git a/lib/dp-packet.c b/lib/dp-packet.c
index 79f6e7e..1093e4a 100644
--- a/lib/dp-packet.c
+++ b/lib/dp-packet.c
@@ -165,9 +165,30 @@  dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom)
 {
     struct dp_packet *new_buffer;
 
-    new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
-                                                 dp_packet_size(buffer),
-                                                 headroom);
+    uint32_t size = dp_packet_size(buffer);
+
+    /* copy multi-seg data */
+#ifdef DPDK_NETDEV
+    if (buffer->source == DPBUF_DPDK && buffer->mbuf.nb_segs > 1) {
+        uint32_t off_set = 0;
+        void *dst = NULL;
+        struct rte_mbuf *tmbuf = CONST_CAST(struct rte_mbuf *, &(buffer->mbuf));
+
+        new_buffer = dp_packet_new_with_headroom(size, headroom);
+        dst = dp_packet_put_uninit(new_buffer, size);
+
+        while (tmbuf) {
+            rte_memcpy((char *)dst + off_set,
+                       rte_pktmbuf_mtod(tmbuf, void *), tmbuf->data_len);
+            off_set += tmbuf->data_len;
+            tmbuf = tmbuf->next;
+        }
+    }
+    else
+#endif
+        new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer),
+                                                        size, headroom);
+
     new_buffer->l2_pad_size = buffer->l2_pad_size;
     new_buffer->l2_5_ofs = buffer->l2_5_ofs;
     new_buffer->l3_ofs = buffer->l3_ofs;