-
Notifications
You must be signed in to change notification settings - Fork 449
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
[P4TC] Align key components to the nearest 8-bit size #5024
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small compilation issues
Will do another round after running more complex tests
As we discussed on the meeting, here's an example that shows the sum bug sum_example.tar.gz |
cb20ec1
to
e5a365e
Compare
e5a365e
to
889848e
Compare
The PR looks ok, but can you rebase on top of main when you have some time? |
998f749
to
ffca7b6
Compare
Hi @vbnogueira , @fruffy , Can you review the PR once? |
Sorry, we got a bit overwhelmed, but will do today |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from these small issues, the PR seems ok
ffca7b6
to
3f9f128
Compare
3f9f128
to
1234582
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @jafingerhut / @fruffy Could you review and approve the PR? |
1234582
to
6395a85
Compare
I have no objections to merging these changes, as long as whoever is a stakeholder in the EBPF and P4TC backends is OK with them. I am currently so unfamiliar with the EBPF and P4TC back ends that I don't think I can review C++ code changes effectively. I took a quick look at the changes in the P4TC expected output files, and it appears the changes described in the initial comment of this PR have been made there. Is there currently any automated testing of the P4TC back end, e.g. tests that compile a P4 program, load it into the kernel, add some table entries, send some packets in, and check that the expected packets come out (and no others)? If not, is anyone considering developing such automated tests as a way to test changes like this? I see that this PR makes some changes to some ebpf p4c files, but does not make any changes to any expected EBPF output files. Is that because there are no EBPF expected output files in the p4c repo? Or because this PR should have no effect on the output of the p4c-ebpf compiler? |
Yes, there is a PR we are currently finishing for that: #5011 |
So I don't have a lot of stake in personally using the P4TC back end at this time, and I am not the best person to review C++ code in p4c's internals. You have one approving review from someone who is more knowledgeable of, and invested in, P4TC, and I personally think that is enough for merging (assuming all of the CI tests pass, the PR is up to date with the main branch code, etc.) I am glad you are working towards adding more automated CI tests for the P4TC back end! |
That's fair, but from what Komal told us she needs either your approval or Fabian's to be able to merge this PR |
OK. @komajai I'm pretty good for reviewing changes to test cases, but not really for a thorough review of C++ code changes, except in very localized parts of the p4c repo, and not at all for ebpf or tc back ends. If Fabian is willing to review and approve, then great. If not, we could ask if @thomascalvert-xlnx might be willing to do so? I see he has done at least some work on the EBPF and TC back ends, which is more than I can say for me. |
Hi @jafingerhut , This PR doesnt affect any ebpf testcases. And for the changes made in C++ code, there are testcases added along with the expected compiler output files. (The diff in output files reflect compiler changes due to current PR). |
auto tcTarget = dynamic_cast<const P4TCTarget *>(builder->target); | ||
auto ebpfType = EBPFTypeFactory::instance->create(ftype); | ||
EBPFScalarType *scalar = nullptr; | ||
if (ebpfType->is<EBPFScalarType>()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend an return-based flow here instead of if else chains.
Or just a single visit(expression) call and a return in the !isPrimitive
case.
return; | ||
bool CodeGenInspector::storeBitAlignment(const IR::Type *ltype, const IR::Expression *lexpr, | ||
cstring lpath) { | ||
auto tcTarget = dynamic_cast<const P4TCTarget *>(builder->target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use dynamic cast, use P4C's handlers in lib/castable.h
. The target should already be castable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this code should be in eBPFCodeGen for TC, if it needs to be casted to a P4TCTarget.
return; | ||
bool CodeGenInspector::storeBitAlignment(const IR::Type *ltype, const IR::Expression *lexpr, | ||
cstring lpath) { | ||
auto tcTarget = dynamic_cast<const P4TCTarget *>(builder->target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this code should be in eBPFCodeGen for TC, if it needs to be casted to a P4TCTarget.
@@ -568,8 +567,19 @@ void CodeGenInspector::emitTCBinaryOperation(const IR::Operation_Binary *b, bool | |||
return; | |||
} | |||
|
|||
void CodeGenInspector::emitTCAssignmentEndianessConversion(const IR::Expression *lexpr, | |||
const IR::Expression *rexpr) { | |||
void CodeGenInspector::emitTCAssignmentEndianessConversion(const IR::Type *ltype, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, these functions should ideally be in the TC back end not here. Makes it much harder refactor this back end later on. I guess the problem is that there is no TC-specific codegen derived from the CodeGenInspector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't easy change as codeGenInspector is the base class for many classes in EBPF code, so we took this path to update in-place. But you pointed it correctly that refactoring of code would be difficult.
One solution @syogender suggested is that we treat CodeGenInspector as a base class for new class VendorCodeGenInspector. This new class will be define by each target in a separate file, which gets included depends on the target it is built for, that way we can have clean code with minimum intrusion.
Please suggest your inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that sounds great. I can approve this PR to unblock things and since there are already TC-specific functions in this class. But the next PRs should introduce such a refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fruffy Could you approve the PR? I will create next PR with separate CodeGenInspector for TC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you addressed the other comments?
Signed-off-by: Komal, Jain <[email protected]>
6395a85
to
7f7134f
Compare
As of now, whenever there is a key component that is a bit-type which doesn't correspond to primitive C type (u8, u16, u32, ...),
the compiler generates it as using the closest primitive C type that is larger then X in bit
For example -
dest_op here is converted into u32 like below -
This won't work, because the P4TC side is expecting the bit<24> (
dest_op
) to be contained in3 bytes
and not 4. All key components are expected to be 8-bit aligned. The new declaration for 'dest_op' would be -For all operations, compiler will call function 'getPrimitiveXX()' which will convert u8[] into primitive type (u32 or u64).
For reverse assignment operations compiler calls 'storePrimitiveXX()' which converts primitive types to u8 [ ] array.
@vbnogueira @jhsmt