vmware-archive/p4c-xdp

Compiler support for registers and hash functions

mcnevesinf opened this issue · 3 comments

I'm trying to port some P4 programs originally written for BMv2 to the XDP target, but I'm struggling to describe an equivalent behavior for registers and hash functions. Is there any workaround I could use at the P4 level?

Also, I understand that adding support to the compiler for whatever function in the form of externs would not scale, but it could be interesting to try to make both models (v1 and ebpf/xdp, or psa and ebpf/xdp) more compatible. Any thoughts on that?

The bmv2 back-end solves this problem in the same way: it has a calling convention which allows people to extend the language with extern constructs as long as they supply implementations in the runtime (bmv2 in this case). We can do the same thing here as well: agree that all functions and externs which are not defined in the model can be supplied by the user as C functions. But we do need to define some calling conventions - how are the functions named, how are the parameters passed, etc.

This is not particularly difficult, but it does need some developer time.

I want to see if I can work on adding registers myself, by starting from "CounterArray". To me it seems like a RegisterArray are just a fancier version of CounterArray with read()/write() instead of increments, so I plan to add some implementation of RegisterArray alongside all the places that implements CounterArray.

However, I'm not sure if I located everything about implementing CounterArray (I searched within this repo but didn't find much). Could you please point me to the places in here or the p4c backend that implements CounterArray?

p4c_xdp is built on top of the p4c compiler from http://github.com/p4-lang/p4c. The support for CounterArray is in that repository, in backends/ebpf. You are right that Registers are just a bit more complex than counters.