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

Add the Barefoot Tofino Assembler to the Tofino back end. #5121

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Feb 7, 2025

The Tofino compiler is not really useful without the assembler. Hence we add it directly. Now the assembler is always active when we use bf-p4c.

The problem is that the assembler code is a little rough and does not pass many of the linting checks P4C has. This required a couple fixes and workarounds. I commented the remaining TODOs in the CMake files. Ideally, we gradually fix all the warnings that are thrown over time.

@fruffy fruffy added the tofino Topics related to the Tofino switch and back end. label Feb 7, 2025
@fruffy fruffy force-pushed the fruffy/assembler branch 5 times, most recently from 625c981 to e9b53ca Compare February 7, 2025 04:19
Signed-off-by: fruffy <[email protected]>
Signed-off-by: fruffy <[email protected]>
@fruffy fruffy force-pushed the fruffy/assembler branch 2 times, most recently from a870fbf to e534899 Compare February 8, 2025 16:55
@fruffy fruffy force-pushed the fruffy/assembler branch 3 times, most recently from 312dcaf to b9b092b Compare February 8, 2025 20:45
Signed-off-by: fruffy <[email protected]>
Signed-off-by: fruffy <[email protected]>
Signed-off-by: fruffy <[email protected]>
@fruffy fruffy marked this pull request as ready for review February 15, 2025 22:59
@fruffy fruffy requested a review from vgurevich February 15, 2025 23:01
Copy link
Contributor

@jafingerhut jafingerhut left a comment

Choose a reason for hiding this comment

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

@vlstill Feel free to give an actual detailed review (unlike this one, which is based on CI tests passing, the fact that these changes should affect ONLY the Tofino back end, and wanting to get the other parts of this working in the open-p4studio repo so we can leave it in a mostly-working state for others). However, as far as I can see right now, Fabian is the only one with the knowledge and interest to make these changes, and I'm the only other one interested in seeing that work move forward.

I have probably over-shared my qualifications on this approval :-)

@fruffy fruffy requested a review from ChrisDodd February 16, 2025 20:49
@ChrisDodd
Copy link
Contributor

Well, I guess as I originally wrote much of this code, I'm qualified to comment on it, if not review it.

The stuff in bf-asm/test is an old broken (non-functional) test suite that is based on running the even older python-based P4_14 compiler, and should probably just be deleted (nothing in it is used, and I don't think any of it is useful)

It looks like it does build fine (with just -DENABLE_TOFINO), but there aren't any tofino test cases? It seems like it should be possible to run some of the code in testdata through p4c --target tofino and then the assembler, but there's nothing set up to try to do that. When run manually, it looks ok, though. Currently ctest does run gtestasm, which runs some assembler internal unit tests, so there is that much.

It does have additional dependencies to build (I noticed at least pyyaml -- needed pip3 install pyyaml to get it to build), but the README.md is very out of date overall with respect to dependencies.

@fruffy
Copy link
Collaborator Author

fruffy commented Feb 18, 2025

The stuff in bf-asm/test is an old broken (non-functional) test suite that is based on running the even older python-based P4_14 compiler, and should probably just be deleted (nothing in it is used, and I don't think any of it is useful)

Okay, I will remove that code.

It looks like it does build fine (with just -DENABLE_TOFINO), but there aren't any tofino test cases? It seems like it should be possible to run some of the code in testdata through p4c --target tofino and then the assembler, but there's nothing set up to try to do that. When run manually, it looks ok, though. Currently ctest does run gtestasm, which runs some assembler internal unit tests, so there is that much.

Currently, compilation should be covered by the P4Testgen tests which runs the compiler with the following arguments: https://github.com/p4lang/p4c/blob/main/backends/p4tools/modules/testgen/targets/tofino/test/TestTemplate.cmake#L94

But it is not running packet-tests yet because the model isn't integrated.

One problem is the amount of warnings being thrown: https://productionresultssa18.blob.core.windows.net/actions-results/2f425077-cf0d-43ba-b2d1-299f3e6c0924/workflow-job-run-db3cdbd7-db2f-5c6d-ea50-8a2acf176300/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-02-18T13%3A36%3A26Z&sig=znJVJB1RLVnjLjLQb3KD732dHNwMwxMpYLNV7gyj%2FKg%3D&ske=2025-02-19T00%3A43%3A35Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-02-18T12%3A43%3A35Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-01-05&sp=r&spr=https&sr=b&st=2025-02-18T13%3A26%3A21Z&sv=2025-01-05

Most of them seem related to particular macro usage in the tables file. The expansion causes additional ; being added.

@ChrisDodd
Copy link
Contributor

One problem is the amount of warnings being thrown:

Most of the warning seem to come from base class virtual methods that have unused arguments -- these arguments are named for documentation/clarity (basically noting what the derived classes will do with them) even though they are not used in the base class method. Fixing the warnings by removing the arguments will make the code less self-documenting and harder to read/understand. I guess the arg names should be replaced by comments to both keep the info and silence the warnings.

Signed-off-by: fruffy <[email protected]>
@fruffy fruffy force-pushed the fruffy/assembler branch 2 times, most recently from 097b730 to 7229ed3 Compare February 20, 2025 19:06
@fruffy
Copy link
Collaborator Author

fruffy commented Feb 20, 2025

One problem is the amount of warnings being thrown:

Most of the warning seem to come from base class virtual methods that have unused arguments -- these arguments are named for documentation/clarity (basically noting what the derived classes will do with them) even though they are not used in the base class method. Fixing the warnings by removing the arguments will make the code less self-documenting and harder to read/understand. I guess the arg names should be replaced by comments to both keep the info and silence the warnings.

Slowly working my way through the warnings. There are a lot of warnings I can not fix because they are generated using chip.schema. Is there any way we can influence the generation of that code?

@fruffy fruffy force-pushed the fruffy/assembler branch 3 times, most recently from d200785 to 909a3fc Compare February 20, 2025 21:19
@ChrisDodd
Copy link
Contributor

Slowly working my way through the warnings. There are a lot of warnings I can not fix because they are generated using chip.schema. Is there any way we can influence the generation of that code?

That code is all generated by the python code in bf-asm/walle/csr.py -- I'll try to take a look at it this weekend.

Signed-off-by: fruffy <[email protected]>
@fruffy
Copy link
Collaborator Author

fruffy commented Feb 21, 2025

That code is all generated by the python code in bf-asm/walle/csr.py -- I'll try to take a look at it this weekend.

Currently disable these warnings using -Wno-unused-parameter -Wno-unused-variable -Wno-type-limits -Wno-sign-compare. I think a lot of them are trivially fixable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tofino Topics related to the Tofino switch and back end.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants