-
Notifications
You must be signed in to change notification settings - Fork 446
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
Control-plane name clash introduced by LocalizeAllActions and RemoveActionParameters #2749
Comments
I do not know if this is exactly the same, or different, but there are at least similarities with this behavior and the behavior described in this issue: #1936 I have the vague impression that there is something subtly wrong here, but not sure how to make it more precise other than "two actions with the same names seem likely to cause problems in at least rare situations, if not common situations". Maybe Nate's example is a more common situation that makes the kinds of questions in the other issue more relevant to a typical P4 program? |
Indeed, the algorithm for creating |
True, but I think |
The P4 spec has a section on how names are generated. I don't exactly know how this should be modified. |
Why are spec changes needed? When the compiler duplicates |
There are other possibilities, like an action being used in two tables and optimized differently for each of them. This would lead to two actions with different names but the same |
I see, I see. So |
It depends on how the P4Runtime API is designed. If you can create an action and then insert in a table in separate operations, then the first operation does not have enough context to decide. |
There is no way to "create an action" in the P4Runtime API. There are ways to associate actions with newly added table entries, or to modify the action for an existing table entry, and to read table entries to see what their (key, action, action parameters are). In P4Runtime API, it only knows about actions that are in the P4Info file as generated by the compiler, and cannot refer to actions in any other way than how they are described there. |
My biggest question in this area is this. Let us take it for granted that there are good reasons to take action definitions in a P4_16 source program, and create duplicates of those that can be optimized independently, e.g. perhaps for different tables where the same action can be invoked on a match, or as a default action. It seems to me that this kind of activity is appropriate for a back end of a compiler, not as something that ever affects the control plane API. If the control plane sees that there are two tables with the same action name, it should be able to request adding that same action to either of the two tables, and it is up to the driver level target-specific code to determine which of several possible optimized versions of that action to invoke. The control plane API shouldn't ever see that detail. Right now, p4c does action duplication per-table before the P4Info file is generated, in the front end. Why? |
Pass ordering is not always an easy decision. |
I understand it is not an easy decision. I am simply trying to point out that generating extra actions that are not in the user's program before P4Info generation seems counterproductive, and leads to difficult to fix and reason about corner cases. |
Note: I am not saying "don't inline". I am referring specifically to whatever part of the front end passes is duplication actions from the user's original program. |
Even if we generate new actions after generating the API, the runtime still needs a way to identify which actions we are talking about. There could still be multiple actions with the same original name in different tables. |
"There could still be multiple actions with the same original name in different tables." Can you give an example of this? EDIT: Sorry, scratch that request. I know what you mean, but was having a brain fade there for a moment. New response: So what if there can still be multiple actions with the same original name in different tables, after you generate the API? That is a perfectly fine and reasonable back-end optimization to perform. It is the the back end compiler's job, and driver's / runtime's job, to keep them straight. |
If it is possible for this to happen if inlining is done API generation, it should also be possible to happen correctly if API generation is done after inlining. |
It is either impossible, or very hard, to prove that it would be impossible to have a correct compiler that does duplication of actions before API generation, and I will not attempt it. Is there a practical advantage that you know of to duplicating actions before API generation? |
Only that some optimizations may take advantage of this fact. |
We can optimize after API generation, yes? |
In principle yes. Today some passes are only run once. We will have to check whether any other passes require action duplication in the frontend. I suspect not. |
Take a look at the test programs for issue #2755, which generate incorrect P4Info files with latest p4c as of 2021-Apr-30. Think about how one might develop a fix for that bug, such that the compiler gave a compile-time error for both of those input programs, and at the same time p4c still generated duplicate actions before API generation. It seems way easier to fix that bug by delaying the creation of duplicate actions until after API generation. |
This is an experiment we should try. |
The following program compiles incorrectly:
Note that action
a
is invoked via tablet
and directly inMyIngress
.However, the
LocalizeAllActions
andRemoveActionParameters
passes generate this program:Note that there are two actions named
MyIngress.a
, but they take different numbers of parameters.This may break the control plane when trying to insert an entry into
t
with actiona
.I can provide more detail if helpful, but hopefully the issue is clear...
The text was updated successfully, but these errors were encountered: