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

compiler bug? global action #99

Closed
smolkaj opened this issue Oct 12, 2016 · 3 comments
Closed

compiler bug? global action #99

smolkaj opened this issue Oct 12, 2016 · 3 comments

Comments

@smolkaj
Copy link
Member

smolkaj commented Oct 12, 2016

I have a program that compiles fine with the p4c-bm2-ss backend, but crashes at run-time with the small_switch bmv2. I compile with

p4c-bm2-ss --p4-16 switch.p4 -o switch.json

and run with

simple_switch switch.json

Compilation succeeds without complaints, but when I invoke simple_switch it crashes with the following error:

Calling target program-options parser
terminate called after throwing an instance of 'std::runtime_error'
  what():  in Json::Value::operator[](char const*)const: requires objectValue
Aborted (core dumped)

Here is a minimized version of the program:

#include <core.p4>
#include <v1model.p4>

struct H { };
struct M { };

parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t smeta) {
    state start { transition accept; }
}

action drop(out standard_metadata_t smeta) { smeta.drop = 1; } // this global action seems to cause the problem

control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) {

    table forward {
        key = { }
        actions = { drop(smeta); }
        const default_action = drop;
    }

    apply {
        forward.apply();
    }

};

control EgressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) {
    apply { }
};

control DeparserI(packet_out pk, in H hdr) {
    apply { }
}

control VerifyChecksumI(in H hdr, inout M meta) {
    apply { }
}

control ComputeChecksumI(inout H hdr, inout M meta) {
    apply { }
}

V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(),
         ComputeChecksumI(), DeparserI()) main;

The problem seems to be caused by the global drop action. It disappears when I define a (parameter-free) version of drop inside the IngressI scope instead.

@mihaibudiu
Copy link
Contributor

mihaibudiu commented Oct 12, 2016

I have created a new test case for this example. The problem is not the global action, but the copy-in copy-out of the fat structure. It looks like we generate incorrect code for assignment between structures. Ideally the compiler should figure out that it does not need to do structure copying at all, but we have some work to do to achieve that. Here is the generated code:

control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) {
    standard_metadata_t smeta_0;
    action drop_0() {
        smeta_0.drop = 1w1;
        smeta = smeta_0;
    }
    ...
}

The bmv2 back-end is not very robust yet.

@mihaibudiu
Copy link
Contributor

I have submitted a fix which makes this compile. I have not checked that it runs correctly. It's still inefficient.

ChrisDodd pushed a commit that referenced this issue Oct 24, 2016
@smolkaj
Copy link
Member Author

smolkaj commented Nov 3, 2016

I can confirm that this compiles now.

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

No branches or pull requests

2 participants