Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p4c-dpdk back end does not support 128-bit arithmetic #4174

Open
jafingerhut opened this issue Sep 23, 2023 · 5 comments
Open

p4c-dpdk back end does not support 128-bit arithmetic #4174

jafingerhut opened this issue Sep 23, 2023 · 5 comments
Assignees
Labels
dpdk Topics related to the DPDK back end enhancement This topic discusses an improvement to existing compiler code.

Comments

@jafingerhut
Copy link
Contributor

jafingerhut commented Sep 23, 2023

With commit #4952, p4c-dpdk supports many operations on 128-bit values.

The one known remaining omission is that it does not support 128-bit constant literal values, which are used by the current DASH program, and seem likely to be desirable to use in many P4 programs that manipulate 128-bit values.

The text of the original issue from 2023-Sep-23 is given below, for historical reference:

With this p4c commit #4171 the p4c-dpdk back end at least usually correctly reports when it does not support a P4 program that uses arithmetic operations on operands larger than 64 bits in size.

This issue is meant to track one possible enhancement that would enable a larger class of useful P4 programs to compile and run on P4-DPDK, which is: implement arithmetic on operands up to 128 bits in size in the P4-DPDK software switch, and then modify the p4c-dpdk back end compiler to take advantage of these operations.

Motivation: IPv6 addresses are commonly manipulated data values in P4 programs, and often arithmetic operations are performed on these values, especially these operations:

  • bitwise AND, OR, XOR
  • bit slice extraction from 128-bit values into smaller values
  • equality comparisons, e.g. (my_ipv6_addr == some_128_bit_constant)
  • assignment of smaller values into a bit slice of a 128-bit destination field, e.g. my_ipv6_addr[31:0] = some_bit_32_expression

I believe that implementing at least the operations above would enable the DASH P4 code to compile without changes. For example, see the commands in issue #4156

I have attempted to modify the P4 code mentioned there to work with the current p4c-dpdk back end and P4-DPDK software switch as of 2023-Sep-23, but I do not think this is feasible. It is necessary to at least be able to do an lpm match kind in a table key on a full 128-bit IPv6 address, and also to compare a 128-bit value to 0, and to do bit-wise AND, OR, and XOR. There is no practical way in P4 to do an lpm match on two 64-bit fields that works the same way as a 128-bit lpm match.

I would recommend that the P4-DPDK back end be enhanced to support all of the following operations, too, on any values up to 128 bits wide:

  • addition and subtraction. These are the same bit-wise results in P4_16 for both unsigned and signed operations, because P4_16 mandates 2's complement representation for signed bit strings. There are fairly straightforward ways to implement these using 64-bit addition and subtraction, e.g. https://stackoverflow.com/questions/5288915/128-bit-arithmetic-on-x64-in-c
  • all comparison operations, i.e. !=, <, <=, >, >= at least on unsigned bit strings, but ideally also for signed bit strings.
  • shift left and right
@Sosutha
Copy link
Contributor

Sosutha commented Oct 9, 2024

PR for supporting 128 bitwise operations on dpdk compiler backend. #4952

@KrisNey-MSFT
Copy link

Looks like 4952 in p4lang/p4c is Merged. Can this one be updated?

@fruffy
Copy link
Collaborator

fruffy commented Nov 5, 2024

The failures are not completely resolved yet and the program is still marked XFail:
https://github.com/p4lang/p4c/blob/main/backends/dpdk/DpdkXfail.cmake#L29

#4952 (comment) describes the remaining work to do.

@jafingerhut
Copy link
Contributor Author

jafingerhut commented Nov 5, 2024

For anyone looking for the gory details, basically the PR #4952 did add a lot of support for 128-bit operations in p4lang/p4c DPDK back end. However, even with that PR it still does not support 128-bit constant values in the P4 source program, which the DASH program does use some of. The bad news is that there are still 2 error messages (shown below) with a 2024-Oct-31 version of p4c source code. The good news is that the number of error messages is down from something-over-20 down to 2 with the changes in PR #4952

$ git clone https://github.com/sonic-net/DASH
$ cd DASH
$ git log -n 1 | head -n 3
commit ee1fa2350a444409e20ad825b13fafdf67010e41
Author: Shaofeng Wu <[email protected]>
Date:   Tue Nov 5 17:24:32 2024 +0800

$ cd dash-pipeline/bmv2
$ mkdir -p output
$ $HOME/forks/p4c/build/p4c-dpdk \
    -DTARGET_DPDK_PNA -DPNA_CONNTRACK \
    --arch pna \
    --p4runtime-files output/dash_pipeline.p4info.txtpb \
    --bf-rt-schema output/dash_pipeline.bfrt.json \
    -o output/dash_pipeline.spec \
    --pp output/dash_pipeline.pp.p4 \
    dash_pipeline.p4

[ ... many warning messages omitted ... ]

[--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit
[--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit
stages/../dash_routing_types.p4(173): [--Werror=overlimit] error: DPDK target supports up-to 64-bit immediate values, 128w0xffffffffffffffffffffffff exceeds the limit
    inout metadata_t meta,
                     ^^^^

@KrisNey-MSFT
Copy link

KrisNey-MSFT commented Nov 5, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dpdk Topics related to the DPDK back end enhancement This topic discusses an improvement to existing compiler code.
Projects
None yet
Development

No branches or pull requests

4 participants