Skip to content

[PATCH v10] api: packet: redefine packet data sharing with packet references#2287

Open
JannePeltonen wants to merge 14 commits intoOpenDataPlane:masterfrom
JannePeltonen:api-pkt-ref
Open

[PATCH v10] api: packet: redefine packet data sharing with packet references#2287
JannePeltonen wants to merge 14 commits intoOpenDataPlane:masterfrom
JannePeltonen:api-pkt-ref

Conversation

@JannePeltonen
Copy link
Copy Markdown
Collaborator

Current API regarding dynamic packet references is not easy to efficiently support in some ODP implementations with HW accelerated packet output due to the need to update reference counts after TX completion and based on that conditionally free packet buffers. odp_packet_ref() has been implemented only as a full packet copy in all ODP implementation.

Redefine the semantics of odp_packet_ref() and the packets involved in packet data sharing in a way that hopefully makes it simpler to support packet data sharing with restrictions in packet output and with per-packet reference counting instead of per-segment reference counting. The new semantics also enable use cases that were not previously possible.

Specify better the rules regarding packet data layout manipulation operations, allowing private packet data also in the tail of the packets that reference other packets. Pull and truncate operations may involve shared packet data, in which case they just remove that data from the packet, not affecting the packet owning the data. All extend and truncate operations always produce non-shared packet data.

Change odp_packet_has_ref() to indicate whether a packet is referenced by another packet, not whether the packet shares data with another packet. In partivular, odp_packet_ref() returns a packet that shares data with the given packet but is not itself referenced by other packets. Specify that packet data and layout of packets referenced by other packets can not be modified at all.

Introduce pktio capability bits to indicate whether a pktio supports sending packets with shared data without using the dont_free flag. Sending with the dont_free flag is supported with all types of packets.

@odpbuild odpbuild changed the title api: packet: redefine packet data sharing [PATCH v1] api: packet: redefine packet data sharing Nov 11, 2025
@MatiasElo MatiasElo added this to the v1.49.0 milestone Nov 19, 2025
* Packets returned by this function can be used normally in ODP API functions
* unless otherwise noted. There are restrictions in packet output.
*
* Referenced packets can be used in ODP API functions that treat packet data
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use one word to refer. Either base packet or referenced packet.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in v2 so that we talk about referenced packets, not base packets.

* of a static reference it also shares metadata. Packet data and data layout
* of packet that have references must be treated as read only.
*
* Packets created through odp_packet_ref() or odp_packet_ref_hdr() share data
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odp_packet_ref_hdr() --> odp_packet_ref_pkt()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in v2

@odpbuild odpbuild changed the title [PATCH v1] api: packet: redefine packet data sharing [PATCH v2] api: packet: redefine packet data sharing Dec 2, 2025
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v2: Many text clarifications and typo fixes. Removed base packet from terminology. Made the packet I/O capabilities more granular. Added reference related text in odp_packet_concat() specification. Added a new function to test whether a packet is a referencing packet. Mentioned that the functions that create referencing packets and static references can be called simultaneously in multiple threads for the same packet.

@odpbuild odpbuild changed the title [PATCH v2] api: packet: redefine packet data sharing [PATCH v3] api: packet: redefine packet data sharing Dec 9, 2025
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v3: Specified that sending shared packets to TM must obey the restrictions of the egress pktio (but currently TM does not support the dont_free flag, which maybe needs to change).

@odpbuild odpbuild changed the title [PATCH v3] api: packet: redefine packet data sharing [PATCH v4] api: packet: redefine packet data sharing Dec 10, 2025
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

JannePeltonen commented Dec 10, 2025

v4:

  • Renamed odp_pktout_shared_packet_capability_t to odp_pktout_packet_ref_capability_t and rewrote the description for better clarity.
  • Renamed odp_pktio_capability_t::shared_pkt_consume to odp_pktio_capability_t::packet_ref
  • Added text to odp_packet_free() to describe handling of packet references
  • Removed the restriction that the ODP_PACKET_FREE_CTRL_DONT_FREE may not be set in packets with multiple references.
  • Added TM capability bits that tell whether different types of packet references may be enqueued to TM. Since TM capabilities are separate for different egresses or TM systems, the capability to handle packet references can depend on the underlying pktio. The don't_free packet option continues to not have an effect in odp_tm_enqueue().
  • fixed a couple of typos

@JannePeltonen JannePeltonen marked this pull request as ready for review December 12, 2025 12:05
@odpbuild odpbuild changed the title [PATCH v4] api: packet: redefine packet data sharing [PATCH v5] api: packet: redefine packet data sharing Dec 23, 2025
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v5: Updated based on review comments. Text clarifications only, no semantic changes.

@MatiasElo MatiasElo removed this from the v1.49.0 milestone Dec 29, 2025
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v6: cosmetic changes based on review comments, rebased

@odpbuild odpbuild changed the title [PATCH v5] api: packet: redefine packet data sharing [PATCH v6] api: packet: redefine packet data sharing Dec 31, 2025
@JannePeltonen JannePeltonen changed the title [PATCH v6] api: packet: redefine packet data sharing [PATCH v6] api: packet: redefine packet data sharing with packet references Dec 31, 2025
@ashwinyes
Copy link
Copy Markdown
Contributor

Acked-by: Ashwin Sekhar T K asekhar@marvell.com

@MatiasElo MatiasElo added this to the v1.50.0 milestone Mar 12, 2026
/** Referencing packets can be consumed */
uint8_t referencing :1;

} odp_pktout_packet_ref_capability_t;
Copy link
Copy Markdown
Collaborator

@psavol psavol Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the same type for both pktout and TM capas? In both cases the flag tells if packet output can consume the packet, and that common part of the documentation could remain here (the first paragraph). The differing part could be documented in the capa documentation using the type (second paragraph about dont_free moved into pktio capa).

Type name could be shortened to odp_pktout_ref_capability_t.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in v8

@odpbuild odpbuild changed the title [PATCH v7] api: packet: redefine packet data sharing with packet references [PATCH v8] api: packet: redefine packet data sharing with packet references Mar 20, 2026
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v8:

  • Changed odp_packet_is_referencing() to return 1 only for referencing packets. Now it returns 0 for static references. This clarifies the API and makes things easier in the implementation since referencing packets and static references are quite different from each other. Now it will not be easy to distinguish between a static reference and referenced packet, but a future API revision can introduce a new function for that purpose if it turns out necessary.
  • Changed pktio and TM capabilities to use a common odp_packet_ref_types_t struct when describing what types of packet are supported.
  • removed some unnecessary and redundant spec text as suggested by Petri
  • fixed a couple of typos and grammar issues

@odpbuild odpbuild changed the title [PATCH v8] api: packet: redefine packet data sharing with packet references [PATCH v9] api: packet: redefine packet data sharing with packet references Mar 23, 2026
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v9:

  • removed stale references to a capability typedef removed in v8
  • added short descriptions for Doxygen in a couple of places

Copy link
Copy Markdown
Collaborator

@psavol psavol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed API commits.

Make packet reference tests forward compatible with the following changes
that are coming in the API version by removing or changing the conflicting
code.
- odp_packet_has_ref() returns 0 for packets created using odp_packet_ref()
  and odp_packet_ref_pkt().
- Referenced packets may not be modified
- Creating references of references is not allowed

Also fix a couple of asserts that checked the wrong packet handles.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Specification text of odp_packet_head() says that odp_packet_data() and
odp_packet_l2_ptr() can be used to return packet data start address. The
latter is incorrect as there is packet data before the l2_ptr if l2 offset
is nonzero. Remove the incorrect reference to odp_packet_l2_ptr().

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Current API regarding dynamic packet references is not easy to
efficiently support in some ODP implementations with HW accelerated
packet output due to the need to update reference counts after TX
completion and based on that conditionally free packet buffers.
odp_packet_ref() has been implemented only as a full packet copy in
all ODP implementations.

Redefine the semantics of odp_packet_ref() and the packets involved
in packet data sharing in a way that hopefully makes it simpler to
support packet data sharing with restrictions in packet output and
with per-packet reference counting instead of per-segment reference
counting. The new semantics also enable use cases that were not
previously possible.

Specify better the rules regarding packet data layout manipulation
operations, allowing private packet data also in the tail of the
packets that reference other packets. Pull and truncate operations may
involve shared packet data, in which case they just remove that data
from the packet, not affecting the packet owning the data. All push
and extend operations always produce non-shared packet data.

Change odp_packet_has_ref() to indicate whether a packet is referenced
by another packet, not whether the packet shares data with another
packet. In particular, odp_packet_ref() returns a packet that shares
data with the given packet but is not itself referenced by other
packets. Specify that packet data and layout of packets referenced by
other packets cannot be modified at all.

Add new odp_packet_is_referencing() to test whether a packet
references another packet but is not a static reference.

Introduce pktio capability bits to indicate whether a pktio supports
sending packets with shared data without using the dont_free flag.
Sending with the dont_free flag is supported with all types of packets.

Introduce TM capability bits that indicate if referencing and
referenced packets and static packet references can be enqueued to TM.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Maximum CoS index is 63 but the field for it in packet header is of type
uint16_t. Change the field to uint8_t to make room for other things
without a need to change the memory layout of the header.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Introduce the concept of indirect segments whose data pointers point to
data areas of other segments. Use the existing per-segment reference counts
to keep track of the usage of shared segments.

Implement dynamic packet references, or referencing packets, using indirect
segments. A referencing packet has a chain of segments so that some of
the segments may be indirect. Add special handling for indirect segments in
packet manipulation functions wherever necessary.

This commit tries to keep the implementation simple and leaves optimization
opportunities for the future.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Add support for packet references to all pktios. Many pktios copy packets
before output processing already. Check for referencing packets and make
a copy if needed in loop, ipc and xdp pktio and in the dpdk pktio in the
zero copy case.

Set the relevant pktio capabilities in the common packet i/o code.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
If a referencing packet is passed to crypto, copy it before processing to
avoid writing to the read-only parts of the packet.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
If a referencing packet is passed to TM, copy it before processing to
avoid writing to the read-only parts of the packet. Unconditional copying
at TM enqueue time could be avoided by making the copy only when needed
in various marking functions but this commit keeps things simple and
does the copy always. Copying for referenced packets and static packet
references was already in place.

Add capability bits to indicate support for packet references.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
If a referencing packet is passed to ipsec, copy it before processing to
avoid writing to the read-only parts of the packet.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Add testing with referencing and referenced packets in addition to normal
packets and static references. Add checking of the related new pktio
capabilities.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Add testing with referencing and referenced packets in addition to normal
packets and static references.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Add testing of odp_packet_is_referencing().

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Check that odp_pktio_capability_t::packet_ref.static_ref capability is
present in the used pktios when static reference TX mode is requested.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Print the odp_pktout_packet_ref_capability_t flags for pktios.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
@odpbuild odpbuild changed the title [PATCH v9] api: packet: redefine packet data sharing with packet references [PATCH v10] api: packet: redefine packet data sharing with packet references Mar 27, 2026
@JannePeltonen
Copy link
Copy Markdown
Collaborator Author

v10:

  • added implementation
  • added packet refs to pktio and crypto validation tests
  • added capa printing to sysinfo and other small changes

I will add new packet API validation tests later as those need still some work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants