Skip to content

Commit 3643be7

Browse files
JannePeltonenMatiasElo
authored andcommitted
doc: userguide: update the chapter on packet references
Update the chapter on packet references to better match the updated API spec. Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com> Reviewed-by: Matias Elo <matias.elo@nokia.com>
1 parent a0196b7 commit 3643be7

1 file changed

Lines changed: 40 additions & 28 deletions

File tree

doc/users-guide/users-guide-packet.adoc

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ function like:
322322
int xmit_pkt(odp_pktout_queue_t queue, odp_packet_t pkt)
323323
{
324324
odp_packet_t ref = odp_packet_ref_static(pkt);
325+
/* send through a pktio that supports static packet references */
325326
return ref == ODP_PACKET_INVALID ? -1 : odp_pktout_send(queue, ref, 1);
326327
}
327328
-----
@@ -330,7 +331,8 @@ This transmits a reference to `pkt` so that `pkt` is retained by the caller,
330331
which means that the caller is free to retransmit it if needed at a later
331332
time. When a higher level protocol (_e.g.,_ receipt of a TCP ACK packet)
332333
confirms that the transmission was successful, `pkt` can then be discarded via
333-
an `odp_packet_free()` call.
334+
an `odp_packet_free()` call. The pktio through which the reference is
335+
sent must support sending static packet references.
334336

335337
The key characteristic of a static reference is that because there are
336338
multiple independent handles that refer to the same packet, the caller should
@@ -349,8 +351,9 @@ int odp_packet_has_ref(odp_packet_t pkt);
349351
-----
350352

351353
that indicates whether other packets exist that share bytes with this
352-
packet. If this routine returns 0 then the caller can be assured that it is
353-
safe to modify it as this handle is the only reference to the packet.
354+
packet. If this routine returns 0 and the packet is not a dynamic reference,
355+
then the caller can be assured that it is safe to modify the packet as this
356+
handle is the only reference to the packet.
354357

355358
==== Dynamic References
356359
While static references are convenient and efficient, they are limited by the
@@ -380,12 +383,19 @@ image::ref.svg[align="center"]
380383
Following a successful reference creation, the bytes of `pkt` beginning at
381384
offset `offset` are shared with the created reference. These bytes should be
382385
treated as read only since multiple references point to them. Each reference,
383-
however still retains its own individual headroom and metadata that is not
384-
shared with any other reference. This allows unique headers to be created by
385-
calling `odp_packet_push_head()` or `odp_packet_extend_head()` on either
386-
handle. This allows multiple references to the same packet to prefix unique
387-
headers onto common shared data it so that they can be properly multicast
388-
using code such as:
386+
however, has its own metadata that is not shared with any other packet.
387+
388+
Packet data and layout of the referenced packet `pkt` must not be
389+
modified as long as references to the packet exist. Packet layout of the
390+
referencing packet, `ref_pkt`, may be modified. The push and extend
391+
variants of packet manipulation functions always add non-shared data
392+
to a dynamic reference and pull and trunc functions remove any kind
393+
(shared or non-shared) data from the reference. Non-shared packet data
394+
of the referencing packet may be modified.
395+
396+
Prefixing dynamic references with non-shared packet data makes it possible to
397+
have multiple packets that prefix the same packet data with unique headers,
398+
which enables multicast without packet data copying using code such as:
389399

390400
[source,c]
391401
-----
@@ -401,6 +411,10 @@ int pkt_fanout(odp_packet_t payload, odp_queue_t fanout_queue[], int num_queues)
401411
Receiver worker threads can then operate on each reference to the packet in
402412
parallel to prefix a unique transmit header onto it and send it out.
403413

414+
Dynamic references and referencing packets can be sent to a pktio only
415+
if the pktio advertises the capability to send such packets or if the
416+
packets are sent with the `ODP_PACKET_FREE_CTRL_DONT_FREE` option.
417+
404418
==== Dynamic References with Headers
405419
The dynamic references discussed so far have one drawback in that the headers
406420
needed to make each reference unique must be constructed individually after
@@ -457,7 +471,7 @@ Here two separate header packets are prefixed onto the same shared packet, each
457471
at their own specified offset, which may or may not be the same. The result is
458472
three packets visible to the application:
459473

460-
* The original `pkt`, which can still be accessed and manipulated directly.
474+
* The original `pkt`, which can still be accessed as read only.
461475
* The first reference, which consists of `hdr_pkt1` followed by bytes
462476
contained in `pkt` starting at `offset1`.
463477
* The second reference, which consists of `hdr_pkt2` followed by bytes
@@ -468,10 +482,9 @@ references exist.
468482

469483
===== Data Sharing with References
470484
Because a `pkt` is a shared object when referenced, applications must observe
471-
certain disciplines when working with them. For best portability and
472-
reliability, the shared data contained in any packet referred to by references
473-
should be treated as read only once it has been successfully referenced until
474-
it is known that all references to it have been freed.
485+
certain disciplines when working with them. Shared data contained in any
486+
packet should be treated as read only and all packet data of packets referenced
487+
by other packets should be treaded as read only.
475488

476489
To assist applications in working with references, ODP provides the additional
477490
API:
@@ -481,24 +494,23 @@ API:
481494
int odp_packet_has_ref(odp_packet_t pkt);
482495
-----
483496
The `odp_packet_has_ref()` API says whether any other packets
484-
exist that share any bytes with this packet.
497+
exist that reference packet data of this packet.
485498

486-
===== Compound References
487-
Note that architecturally ODP does not limit referencing and so it is possible
488-
that a reference may be used as a basis for creating another reference. The
489-
result is a _compound reference_ that should still behave as any other
499+
[source,c]
500+
-----
501+
int odp_packet_is_referencing(odp_packet_t pkt);
502+
-----
503+
The `odp_packet_is_referencing()` API says whether this packet is a dynamic
490504
reference.
491505

492-
As noted earlier, the intent behind references is that they are lightweight
493-
objects that can be implemented without requiring data copies. The existence
494-
of compound references may complicate this goal for some implementations. As a
495-
result, implementations are always free to perform partial or full copies of
496-
packets as part of any reference creation call.
506+
===== Compound References
497507

498-
Note also that a packet may not reference itself, nor may circular reference
499-
relationships be formed, _e.g.,_ packet A is used as a header for a reference
500-
to packet B and B is used as a header for a reference to packet A. Results
501-
are undefined if such circular references are attempted.
508+
Static packet reference may be created to a packet it is already a static
509+
packet reference. Static packet reference may not be created to a packet
510+
that is a dynamic reference or a packet that is referenced by a dynamic
511+
reference. Dynamic references may not be created to packets that are
512+
static or dynamic references, but may be created to packets that are
513+
already referenced by another dynamic reference.
502514

503515
=== Packet Parsing, Checksum Processing, and Overrides
504516
Packet parsing is normally triggered automatically as part of packet RX

0 commit comments

Comments
 (0)