P4 parallelism while processing one packet

Hi,

I’m wondering if p4 supports parallelism while processing one packet. For a native example, if we wanna update fields A and B (such as the src and dest address in the ethernet header), can we update them parallelly? Thank you.

Best,
Sven

Hi @svenchen ,

In hardware switch some “functions” are parallelized at the hardware level, In other word you can exploit it optimizing the code that you write, but for doing that you have to know in depth the architecture. But in the P4 language you haven’t thread data structure, that can run in parallel.
Overhall I think that you can achieve good service time for your pipeline balancing properly each stage of the pipe and exploit the parallelization made in the hardware architecture.

1 Like

I think @DavideS makes a good point here, there is little to add. I remember a good video, so I thought of leaving the link here: https://youtu.be/DptVDfxjoSk. Check it all, but particularly from minute 27.

This is a fairly nice video that explains parallelism in their ASIC by Barefoot in 2017. Many of the operations that you write are parallel by default as long as there is no hard dependency between them. Davide is right, you can indeed try to optimize your code to try to achieve higher parallelization. But this might require a fairly deep understanding of the target and ASIC. The courses taught by Barefoot in the past are quite useful but not sure the current status. You might want to check INTEL’s website. Any specific questions about the ASIC need to be asked at the ICRP forum.

I would summarize the point of parallelism first determining if the target can run parallel operations and then it is up to the compiler to determine which operations can run in parallel and how to achieve it. You should absolutely watch the video :slight_smile: Consider that the statements in the video do not necessarily apply to software switches or other hardware targets, but the general concepts are still probably generalizable and valid for similar targets.

Cheers,

1 Like

I am not sure if the link is correct. Here is the one I have: P4 mapping to Barefoot Tofino(tm) - YouTube

1 Like