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

Dpdk Backend: Enable header stack dynamic index elimination #3375

Merged
merged 4 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backends/dpdk/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ limitations under the License.
#include "midend/fillEnumMap.h"
#include "midend/flattenHeaders.h"
#include "midend/flattenInterfaceStructs.h"
#include "midend/hsIndexSimplify.h"
#include "midend/local_copyprop.h"
#include "midend/midEndLast.h"
#include "midend/nestedStructs.h"
Expand Down Expand Up @@ -205,10 +206,9 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options,
new P4::FlattenHeaders(&refMap, &typeMap),
new P4::FlattenInterfaceStructs(&refMap, &typeMap),
new P4::SimplifyControlFlow(&refMap, &typeMap),
new P4::HSIndexSimplifier(&refMap, &typeMap),
new P4::ParsersUnroll(true, &refMap, &typeMap),
new P4::ReplaceSelectRange(&refMap, &typeMap),
// DPDK architecture does not currently support predicated instructions
// new P4::Predication(&refMap),
new P4::MoveDeclarations(), // more may have been introduced
new P4::ConstantFolding(&refMap, &typeMap),
new P4::LocalCopyPropagation(&refMap, &typeMap, nullptr, policy),
Expand Down
140 changes: 140 additions & 0 deletions testdata/p4_16_samples/pna-example-varIndex-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
Copyright 2022 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <core.p4>
#include "pna.p4"

#define MAX_LAYERS 2
typedef bit<48> EthernetAddress;

enum bit<16> ether_type_t {
TPID = 0x8100,
IPV4 = 0x0800,
IPV6 = 0x86DD
}

header ethernet_t {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

header vlan_tag_h {
bit<3> pcp;
bit<1> cfi;
bit<12> vid;
ether_type_t ether_type;
}

struct headers_t {
ethernet_t ethernet;
vlan_tag_h[MAX_LAYERS] vlan_tag;
}

struct main_metadata_t {
bit<2> depth;
bit<16> ethType;
}

control PreControlImpl(
in headers_t hdrs,
inout main_metadata_t meta,
in pna_pre_input_metadata_t istd,
inout pna_pre_output_metadata_t ostd)
{
apply {
}
}

parser MainParserImpl(
packet_in pkt,
out headers_t hdrs,
inout main_metadata_t meta,
in pna_main_parser_input_metadata_t istd)
{
state start {
meta.depth = MAX_LAYERS - 1;
pkt.extract(hdrs.ethernet);
transition select(hdrs.ethernet.etherType) {
ether_type_t.TPID : parse_vlan_tag;
default: accept;
}
}
state parse_vlan_tag {
pkt.extract(hdrs.vlan_tag.next);
meta.depth = meta.depth - 1;
transition select(hdrs.vlan_tag.last.ether_type) {
ether_type_t.TPID : parse_vlan_tag;
default: accept;
}
}

}

control MainControlImpl(
inout headers_t hdrs, // from main parser
inout main_metadata_t meta, // from main parser, to "next block"
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd)
{
action execute() {
hdrs.vlan_tag[meta.depth].vid = hdrs.vlan_tag[meta.depth-1].vid;
}
action execute_1() {
drop_packet();
}

table stub {
key = {
hdrs.vlan_tag[meta.depth].vid : exact;
}

actions = {
execute;
}
const default_action = execute;
size=1000000;
}

apply {
stub.apply();
}
}

control MainDeparserImpl(
packet_out pkt,
in headers_t hdr, // from main control
in main_metadata_t user_meta, // from main control
in pna_main_output_metadata_t ostd)
{
apply {
pkt.emit(hdr.ethernet);
pkt.emit(hdr.vlan_tag[0]);
pkt.emit(hdr.vlan_tag[1]);
}
}

// BEGIN:Package_Instantiation_Example
PNA_NIC(
MainParserImpl(),
PreControlImpl(),
MainControlImpl(),
MainDeparserImpl()
// Hoping to make this optional parameter later, but not supported
// by p4c yet.
//, PreParserImpl()
) main;
// END:Package_Instantiation_Example
155 changes: 155 additions & 0 deletions testdata/p4_16_samples/pna-example-varIndex-2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
Copyright 2022 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <core.p4>
#include "pna.p4"

#define MAX_LAYERS 2
typedef bit<48> EthernetAddress;

enum bit<16> ether_type_t {
TPID = 0x8100,
IPV4 = 0x0800,
IPV6 = 0x86DD
}

header ethernet_t {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

header vlan_tag_h {
bit<3> pcp;
bit<1> cfi;
bit<12> vid;
ether_type_t ether_type;
}

struct headers_t {
ethernet_t ethernet;
vlan_tag_h[MAX_LAYERS] vlan_tag;
}

struct main_metadata_t {
bit<2> depth;
bit<16> ethType;
}

control PreControlImpl(
in headers_t hdrs,
inout main_metadata_t meta,
in pna_pre_input_metadata_t istd,
inout pna_pre_output_metadata_t ostd)
{
apply {
}
}

parser MainParserImpl(
packet_in pkt,
out headers_t hdrs,
inout main_metadata_t meta,
in pna_main_parser_input_metadata_t istd)
{
state start {
meta.depth = MAX_LAYERS - 1;
pkt.extract(hdrs.ethernet);
transition select(hdrs.ethernet.etherType) {
ether_type_t.TPID : parse_vlan_tag;
default: accept;
}
}
state parse_vlan_tag {
pkt.extract(hdrs.vlan_tag.next);
meta.depth = meta.depth - 1;
transition select(hdrs.vlan_tag.last.ether_type) {
ether_type_t.TPID : parse_vlan_tag;
default: accept;
}
}

}

control MainControlImpl(
inout headers_t hdrs, // from main parser
inout main_metadata_t meta, // from main parser, to "next block"
in pna_main_input_metadata_t istd,
inout pna_main_output_metadata_t ostd)
{
action execute() {
hdrs.vlan_tag[meta.depth].vid = hdrs.vlan_tag[0].vid;
}
action execute_1() {
drop_packet();
}

table stub {
key = {
hdrs.vlan_tag[meta.depth].vid : exact;
}

actions = {
execute;
}
const default_action = execute;
size=1000000;
}

table stub1 {
key = {
hdrs.ethernet.etherType : exact;
}

actions = {
execute_1;
}
const default_action = execute_1;
size=1000000;
}

apply {
switch (hdrs.vlan_tag[meta.depth].vid) {
12w1: { stub.apply();}
12w2: { stub1.apply();}
}
}
}

control MainDeparserImpl(
packet_out pkt,
in headers_t hdr, // from main control
in main_metadata_t user_meta, // from main control
in pna_main_output_metadata_t ostd)
{
apply {
pkt.emit(hdr.ethernet);
pkt.emit(hdr.vlan_tag[0]);
pkt.emit(hdr.vlan_tag[1]);
}
}

// BEGIN:Package_Instantiation_Example
PNA_NIC(
MainParserImpl(),
PreControlImpl(),
MainControlImpl(),
MainDeparserImpl()
// Hoping to make this optional parameter later, but not supported
// by p4c yet.
//, PreParserImpl()
) main;
// END:Package_Instantiation_Example
Loading