Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 extra checks on next tables #1287
base: main
Are you sure you want to change the base?
Add extra checks on next tables #1287
Changes from all commits
5ff35b2
e5c617e
545580d
2834e72
c660463
8672f5e
47ce102
ecca451
722bb68
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
@jafingerhut do you think this is a good opportunity to mention this attribute (
base_default_next
) in the bmv2 JSON format document? Not sure if p4c uses it.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.
I would be happy to document it, if I could tell what it was for :-)
I see it in the JSON files generated by p4c in table definitions, pretty much most of the tables, but I also see in most tables [1] that the
next_tables
key defines a next node for every action name of the table. It isn't clear to me when the value ofbase_default_next
is ever used by BMv2 code. Even if it is sometimes used, it seems to me that it might be for a feature that P4 the language does not need.[1] the ones that don't use
table.apply().hit
ortable.apply().miss
features, which are most tables in the test suite (and typical P4 programs in general only use that feature occasionally).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.
So this is the original PR: #78
I think this attribute was necessary at the time to implement the
reset_default_entry
API.Because in P4_16, there is always a default action with arguments (as the compiler will use
NoAction
if the programmer didn't provide one), I do think that this attribute is actually never used [1], unless I am missing something.Maybe we could try to stop generating it in the p4c bmv2 backend, assuming nothing breaks (if tests break as a result, we need to come back and check what it's actually used for...). It's always good to simplify the emitted JSON. If we stop using it in p4c, we should not include it in the documentation here (discarding my initial comment), but we should keep it in the code for backwards compatibility. Maybe with a comment in P4Objects.cpp that it is no longer used by p4c.
[1] This is based on the assumption that this code is always executed for all tables when the JSON is generated by p4c:
behavioral-model/src/bm_sim/P4Objects.cpp
Line 1889 in 2f82eaf
This assumption is only true if the
default_entry
attribute is set for all tables, and always includes theaction_data
attribute (see my other comment). Could you confirm that it is indeed true?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.
default_entry
is not present for tables with typeindirect
(corresponding to implementation=action_profile) andindirect_ws
(corresponding to implementation=action_selector).default_entry
seems to always be present for tables with typesimple
.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.
Note that I am not aware of any strong reason, other than similarity to Tofino perhaps, that we could not go ahead and implement full support for default_action in tables that have action profiles or action selectors.
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 seems to me that the code is actually able to handle "regular" default actions with action data, even for indirect tables. It is actually mentioned in the PR description here: #551. It is possible that p4c was never updated in response to that to generate the proper
default_entry
in the JSON for such tables.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.
Here is the code in the p4c BMv2 back end that specifically checks for, and omits, any default_action definition in the P4_16 source code for tables with action profiles or action selectors: p4lang/p4c@96ec4d5#diff-e1b9c4c9f99e44821b652694b5a72f9a58784dd8e05572850c0a08b7f7c1c87fR1215-R1221
(search for the string "Target does not support default_action" in that commit's diff)
The commit comment by Mihai was "bmv2 does not support default_action for all tables", so apparently he believed that was true at that time. For all I know, perhaps it was true for bmv2 in May 2016.
I am happy to try experimenting with a modification to p4c that removes that restriction, and test bmv2 to see if it seems to behave correctly with default_action definitions on tables with action profiles and action selectors. I agree that if bmv2 does not support them as it is written today, I suspect it would be a very small change to enable it to work for default_action's on such tables.
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 would have been true then given that #551 is from 2018
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.
If you are OK reviewing this PR as it is right now, I am happy to make a new issue to track the following things, perhaps modified in later PRs:
(a) consider modifying p4c bmv2 back end so that it supports default_action in P4 source code for tables with action profiles or action selectors.
(b) Document the key
base_default_next
, including mentioning what it was for originally, and any known cases where its value affects the behavior of bmv2.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.
p4c issue to track idea (a) above: p4lang/p4c#5101
behavioral-model issue to track idea (b) above: #1289
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.
see comment above. I am not sure we need to enforce this new restriction. But I don't feel very strongly about it, so if you think this is more meaningful this way, we can add it. I assume it won't break the test JSON files included in this repo?
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.
All behavioral-model CI tests are passing, as you can see on Github page for this PR.
I have also run all p4c tests with behavioral-model with the changes on this PR, and this exception never occurs.
I am OK removing the check if you prefer. The main reason I even include it is that it makes it more clear what behavioral-model can rely on going forward, and reduce the number of cases that we need to think about when modifying code related to this.
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.
Updated docs in commit 9 to make it clearer that
action_data
key is required inside ofdefault_entry
.