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 support for Checksum extern and CRC16/32 algorithms to eBPF backend #3167

Merged
merged 3 commits into from
Apr 6, 2022

Conversation

kmateuszssak
Copy link
Contributor

This PR adds Checksum extern and adds support for CRC16 and CRC32 algorithms.

Co-authored-by: Tomasz Osiński [email protected]
Co-authored-by: Jan Palimąka [email protected]

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

This is good, but could use a little more documentation.

@@ -33,8 +33,35 @@ void DeparserBodyTranslatorPSA::processFunction(const P4::ExternFunction *functi
}
}

void DeparserBodyTranslatorPSA::processMethod(const P4::ExternMethod *method) {
auto dprs = dynamic_cast<const EBPFDeparserPSA*>(deparser);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to CHECK_NULL?
Maybe you want to implement the to<> method for these classes?

@@ -108,6 +116,25 @@ EBPFPsaParser::EBPFPsaParser(const EBPFProgram* program, const IR::ParserBlock*
visitor = new PsaStateTranslationVisitor(program->refMap, program->typeMap, this);
}

void EBPFPsaParser::emitDeclaration(CodeBuilder* builder, const IR::Declaration* decl) {
if (decl->is<IR::Declaration_Instance>()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this pattern a lot, perhaps you can factor it out into a convenience function getSpecializedTypeArgument()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added EBPFObject::getSpecializedTypeName() function.

auto typeSpec = di->type->to<IR::Type_Specialized>();
cstring name = di->name.name;

if (typeSpec != nullptr &&
Copy link
Contributor

Choose a reason for hiding this comment

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

this may be a utility function too.
you may want to review the code committed previously for these patterns too.

@@ -0,0 +1,133 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also add symlinks from testdata/p4_16_samples to these files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we shouldn't. What would be the value of adding PTF testfiles to testdata/p4_16_samples ?

Copy link
Contributor

Choose a reason for hiding this comment

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

These programs would be used to test the p4test compiler. More tests are always good.

::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", block);
return;
}
int type = di->arguments->at(0)->expression->to<IR::Constant>()->asInt();
Copy link
Contributor

Choose a reason for hiding this comment

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

can it not be a constant?
maybe you should check

Copy link
Contributor

Choose a reason for hiding this comment

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

or you can at least use checkedTo


cstring CRCChecksumAlgorithm::reflect(cstring str) {
BUG_CHECK(crcWidth <= 64, "CRC checksum width up to 64 bits is supported");
unsigned long long poly = std::stoull(str.c_str(), nullptr, 16);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this enough validation?


void CRCChecksumAlgorithm::emitUpdateMethod(CodeBuilder* builder, int crcWidth) {
// Note that this update method is optimized for our CRC16 and CRC32, custom
// version may require other method of update. To deal with byte order data
Copy link
Contributor

Choose a reason for hiding this comment

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

comma after order?

concatenateBits = true;
if (width > remainingBits) {
::error(ErrorType::ERR_UNSUPPORTED,
"Sub-byte fields have to be aligned to bytes %1%", field);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I would understand this error message as a user of the compiler.

@kmateuszssak
Copy link
Contributor Author

@mbudiu-vmw I think I've addressed all of the comments.

@mihaibudiu
Copy link
Contributor

Unfortunately this branch now has conflicts, which you will have to resolve before we can merge.

@mihaibudiu mihaibudiu merged commit 77ddb3e into p4lang:main Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants