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

Question: Are runtime_data and local types synonymous in bmv2 JSON config file? #680

Closed
jafingerhut opened this issue May 28, 2017 · 6 comments

Comments

@jafingerhut
Copy link
Contributor

jafingerhut commented May 28, 2017

I can create an example if necessary, but it might be easy to determine why this is happening from perusal of the bmv2 back end.

I have a bmv2 JSON config file where in some cases, a primitive of an action will reference an action parameter using a JSON object with key "type" and value "runtime_data", and key "value" being an integer index into the array of action parameters.

In other cases, it appears that the same action parameters are being referenced via a JSON object with key "type" and value "local", and the same "value" as for "runtime_data" above.

Is there any semantic difference between these? If so, what? If not, should they all use the same value for "type"?

It appears that occurrences of type "local" are created here in the code: https://github.com/p4lang/p4c/blob/master/backends/bmv2/expression.cpp#L312

Occurences of type "runtime_data" are created here: https://github.com/p4lang/p4c/blob/master/backends/bmv2/expression.cpp#L427

@antoninbas
Copy link
Member

antoninbas commented May 30, 2017

when the argument to an action primitive is a simple expression, like a field value or a runtime-provided value (runtime_data), bmv2 encourages the compiler to treat them in a special way to avoid having to invoke the bmv2 expression-evaluation engine, which is a little expensive.
runtime_data is used to indicate that the argument provided to the action primitive comes directly from the runtime data of the table entry, and the expression-evaluation engine is bypassed. On the other hand, local is used in a "complex" expression to refer to runtime data.
The following should behave identically, although the first one should be faster:

{
  "op": "modify_field",
  "parameters": [
    {
      "type": "field",
      "value": ["ethernet", "srcAddr"]
    },
    {
      "type": "runtime_data",
       "value": 0
     }
   ]
}

and

  "op": "modify_field",
  "parameters": [
    {
      "type": "field",
      "value": ["ethernet", "srcAddr"]
    },
    {
      "type": "expression",
       "value": {
         "type": "local",
         "value": 0
     }
   ]
}

Note that local only refers to runtime data in the context of an expression evaluated inside an action. For expressions evaluated in another context, local may refer to something else.

@mihaibudiu
Copy link
Contributor

local does not seem to be documented in the BMv2 JSON reference.

@antoninbas
Copy link
Member

that's correct, I opened a PR for this: https://github.com/p4lang/behavioral-model/pull/383/files

@jafingerhut
Copy link
Contributor Author

Thanks for the explanation. Are there any plans to use local to refer to things other than runtime data (i.e. action parameters)? If so, do you have an example in mind?

@antoninbas
Copy link
Member

The only other use that comes to mind is the P4_14 Python compiler using it to handle variable-length field extraction. There, locals are fields in the header being extracted.

@jafingerhut
Copy link
Contributor Author

Thanks for the answers, and for adding to the bmv2 JSON config file documentation. Closing this issue.

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

3 participants