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 Register extern to PSA/eBPF backend #3202

Merged
merged 8 commits into from
Apr 14, 2022

Conversation

osinstom
Copy link
Contributor

No description provided.

} else if (method->method->type->name == "read") {
::warning(ErrorType::WARN_UNUSED, "This Register(%1%) read value is not used!", name);
reg->emitRegisterRead(builder, method, this, nullptr);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

could give an error for other methods


namespace EBPF {

EBPFRegisterPSA::EBPFRegisterPSA(const EBPFProgram *program,
Copy link
Contributor

Choose a reason for hiding this comment

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

This stuff could be useful even in the basic ebpf backend, but perhaps it's too late to move it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can think about moving it to EBPF model, but we would need to agree on the extern definition, which might be different from the one from PSA.

backends/ebpf/psa/externs/ebpfPsaRegister.cpp Show resolved Hide resolved

if (auto wt = dynamic_cast<IHasWidth *>(this->keyType)) {
unsigned keyWidth = wt->widthInBits();
// For keys <= 32 bit register is based on array map,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you should put this into a separate policy function; annotations could be used to generalize this later.

size = declaredSize->asUnsigned();

if (di->arguments->size() == 2) {
this->initialValue = di->arguments->at(1)->expression->to<IR::Constant>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you should document the fact that this can be nullptr.
But if the argument is present and not a constant you will also get a nullptr, which is probably wrong.

}

auto declaredSize = di->arguments->at(0)->expression->to<IR::Constant>();
if (!declaredSize->fitsUint()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

no CHECK_NULL?
Has this been validated someplace else?

void EBPFRegisterPSA::emitRegisterWrite(CodeBuilder* builder, const P4::ExternMethod* method,
ControlBodyTranslatorPSA* translator) {
auto indexArgExpr = method->expr->arguments->at(0)->expression->to<IR::PathExpression>();
cstring indexParamName = translator->getActionParamName(indexArgExpr);
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 implying that within an action the index must be an action parameter?
So it cannot be some expression that involves the action parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the function name is misleading, I'll change it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihaibudiu
Copy link
Contributor

The ptf tests are currently failing.

@osinstom
Copy link
Contributor Author

@mbudiu-vmw I've fixed PTF tests. They are passing now.

@mihaibudiu mihaibudiu merged commit 5ab6998 into p4lang:main Apr 14, 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.

2 participants