Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Compiler support for registers and hash functions #119

Open
mcnevesinf opened this issue Aug 13, 2019 · 3 comments
Open

Compiler support for registers and hash functions #119

mcnevesinf opened this issue Aug 13, 2019 · 3 comments
Labels

Comments

@mcnevesinf
Copy link

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?

@mihaibudiu
Copy link
Contributor

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.

@chenxiaoqino
Copy link

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?

@mihaibudiu
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants