-
Notifications
You must be signed in to change notification settings - Fork 82
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
Design syntax and semantics to indicate persistent storage of per-table-entry data across packets, modifiable in data plane #1177
Comments
I'm not wedded to defining a new direction for action parameters, but it seemed to me like a semi-natural way to express this. This explanation will explain the syntax in that way, but if you have another syntax that achieves the same goal that you believe has advantages, please propose it. As a very short example, suppose there was a new direction other than the existing The new When an action
When This would require some definition of what happens in concurrent execution scenarios, but the intent is that effectively all or as much of the action body as required would effectively "lock the table entry E1" during its execution, and any changes made to Example of syntax with new direction
Example of a different syntax mentioned by Nate Foster and/or Mihai Budiu, with NO new direction
|
@mariobaldi Created this issue for the P4 language work group, to see if I can get the ball rolling. For the background of others, this feature request originates in the architecture work group, and seems to me to be a natural way to express data plane modification of per-table-entry state. |
Note: TNA defines a way to do this using DirectRegister and RegisterAction externs, plus abstract methods. I will check with Tofino compiler developers whether this proposal is "just another syntax" for this behavior, easy to support, or if there are any differences in expressive power that I am not yet aware of. The syntax of this proposal definitely seems noticeably easier to read and understand, to me personally. I believe that one noticeable difference between this proposal and using a |
Directions were originally intended to indicate calling conventions -- a defensible language design choice. (Ab)using directionless parameters to indicate the control-plane parameters was always controversial. Experience has shown that it is confusing to new P4 developers -- not ridiculously so, but it's not natural. In my opinion, it was a mistake. (At the time P4_16 was being developed, we considered having two sets of braces, which would have been arguably more natural, but some on the LDWG had parenthephobia.) Anyway, I really like the idea of having syntax for initializing per-table-entry state for direct mapped objects. But I wonder if further abusing direction parameters is the best way to go, or if we are continuing down a bad syntactic path. |
I am certainly open to other syntactic ideas, certainly. I know there is a preference/guidance against using annotations for things that significantly change the meaning of the program if they are removed, so this seems like a poor use case for them. If you or others have thoughts on syntax besides a new direction besides in/out/inout, please do describe them. |
@jnfoster I recall you mentioning something like this about directionless parameters for actions being a choice you wish had been made differently. Perhaps I misunderstood, but I thought you meant something like "I wish instead of action parameters having no direction keyword meant 'comes from the control plane', instead we had an explicit direction keyword that meant 'comes from the control plane'". But perhaps you had something else in mind? |
Here are my thoughts and even how I would have done the original control plane based arguments. The grammar becomes Note I am ok with not adding a specific direction and leaving directionless because it is almost water on the bridge now. |
What would be a difference between such an action and a control or a function? |
@vgurevich asks: "What would be a difference between such an action and a control or a function?" It would be in an action, and thus could be an action of a table. Controls and functions cannot be actions of a table. Controls cannot be invoked from within actions in the current language definition. |
@apinski-cavium I agree that if we want to preserve backwards compatibility with very very commonly written P4 code, we should not make a change where we mandate that directionless parameters to actions must have a new direction keyword in front of them. I do think something like your |
The reason directionless has two meanings is historical, to support p4-14, where there were no functions, and an action could be used both as a function and as an action. The same action could be called from two different contexts: other actions or tables. |
I would actually use a declaration and not a parameter:
|
I have generalized the name of this issue to be closer to the problem statement, and the title no longer mentions the specific implementation approach of adding a new kind of action parameter direction. I have created a more explicit example in the style of this comment: #1177 (comment) and added it this comment above: #1177 (comment) @mariobaldi Please take a look at the two syntax examples at the end of this comment, particularly the last one, to see what you think: #1177 (comment) |
Upon thinking about it a bit more, perhaps it's better to make it look like a new kind of parameter that looks behaves like an inout parameter, but which is provided by the dataplane and not by the program.
The semantics is special in that the initial_value is a default_value, but the value that the state starts with when the action is installed. The initial_value is optional, if missing the control-plane has to specify it. |
Maybe I do not understand well what @jnfoster and @mbudiu-vmw have proposed, but I have the impression that the parallel with inout has brought us away from the initial intent. In the case of max_seq_seen how does the compiler know in which position in the table entry the value should be stored? Does it infer it from the fact that max_seq_seen was initialized with initial_seq_seen, which was the third action parameter? In the case of token (Mihai's proposal), when initial_value is not present, what do we mean that the control plane must specify the value? If we mean that the control plane will have written the value in the second action parameter in the table entry associated to the action execution, then isn't this the same as the initial proposal with rmw (now called "state")? |
@mbudiu-vmw In this comment #1177 (comment) you say: "but which is provided by the dataplane and not by the program". I don't think there is a desire for the initial value to be supplied by the data plane here. And if we remove that part of your proposal, it appears that the only difference that remains is whether the keyword is my initial placeholder Maybe I am missing something, though. |
The initial value is actually supplied through add_entry extern when an entry is created by the data plane, and through the API (TDI/P4Runtime) when an entry is created by the control plane. |
This topic has been discussed again recently in the 2023-Jan-30 Architecture work group meeting. If anyone has ideas for syntax that do not involve using a new direction name (perhaps abusing a new direction name, agreed), those ideas are very welcome. One thought: What if 'rmw' was not a direction like in/out/inout, but instead a separate category of qualifier that can be used in defining the parameters of an action, e.g. like Perhaps that is what Mihai was intending with his |
Here are some notes I took on this topic during the 2023-Feb-27 P4.org architecture work group meeting, discussing PNA, where this issue originated from. We talked about the idea of having a per-table-entry lock on action data that was writable, that would be held for the duration of the execution of the action. Andy: More precisely, I would say that the P4 language spec should not mandate that an implementation must have a per-table-entry exclusive lock held for the entire duration of the action's execution. Instead, perhaps it could be stated as "an implementation should behave as if this were the implementation", leaving open to the target how it actually achieves this behavior. Mario: What about an annotation that disables the per-entry-lock for that table? Example action, written assuming that the keyword
With such an annotation that disables the per-entry-lock that lasts for the duration of the entire action body, the following order of events would be possible:
Perhaps add extern functions like these?
Note: It doesn't seem like a P4 compiler would need to be very sophisticated to notice that the first 17 statements of an ation like the example above do not write to action parameters, and thus need not have lock-like protection around them, i.e. those statements can be done outside the critical section. |
Agreed, furthermore it's important to note that reads should be considered too (only writes are mentioned).
I can't see the user's motivation for this - performance optimisation? |
@thomascalvert-xlnx The only motivation that makes sense to me is giving the developer knobs that can help increase performance, without sacrificing correct behavior. As a perhaps weird example, that I don't know if anyone would want to implement or use, one could imagine an action that looked like this:
Of course such an action definition would only be correct if the P4 developer had done their own independent reasoning about the possible behaviors that could result, and judged that it was suitable for their use case. If action definition like a7 above are of any interest, and motivate the suggestion to provide explicit acquire/release lock primitives, then it seems to me unlikely that a P4 compiler would ever be "smart enough" to figure out that a7 should be the result of an action written without those acquire/release primitives written as shown. |
Notes from a P4.org meeting of 2023-Mar-17 on this topic alone available here: https://docs.google.com/presentation/d/15vZJETWr0Cyht-dcQFnat28A3c9FoY7Z/edit?usp=share_link&ouid=113165450274035133953&rtpof=true&sd=true |
Action: we will wait until there is an implementation of this feature, and some experience writing programs with it. But the LDWG endorses the direction and looks forward to seeing an implementation and full proposal. |
One other thought... We can also add a backwards compatible |
@vgurevich I am not sure why you say "Without it, read-only fields will always have to precede read-modify-write fields." If you look at the proposed PR with changes to the language spec for this new feature here: #1239 you can see that it says: "All parameters that are either directionless or declared Do you see any issues with that proposed text? |
Oh, I see! In that case we are good! |
Does ir make sense to use the existing |
My main concern with using |
@ChrisDodd -- the main problem with reusing |
Personnel
Design
Implementation
p4-spec
: A draft of a PR to the language spec that is currently only intended to help define this feature for a proposed experimental implementation in p4c: Data plane writable per table entry state v1 #1239p4c
:Process
p4-spec
:p4c
:=======================================
The text was updated successfully, but these errors were encountered: