-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dash-p4] Add macro for defining and update regular counters. (#530)
- Loading branch information
Showing
4 changed files
with
75 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,80 @@ | ||
#ifndef __DASH_TARGET_SPECIFIC__ | ||
#define __DASH_TARGET_SPECIFIC__ | ||
|
||
#ifdef TARGET_BMV2_V1MODEL | ||
|
||
#include <v1model.p4> | ||
// | ||
// P4 arch/target includes | ||
// | ||
#if defined(TARGET_BMV2_V1MODEL) | ||
#include <v1model.p4> | ||
#elif defined(TARGET_DPDK_PNA) // TARGET_BMV2_V1MODEL | ||
#include <pna.p4> | ||
#endif // TARGET_DPDK_PNA | ||
|
||
// | ||
// Counters | ||
#define DEFINE_TABLE_COUNTER(counter_name) direct_counter(CounterType.packets_and_bytes) counter_name; | ||
#define ATTACH_TABLE_COUNTER(counter_name) counters = counter_name; | ||
#define DIRECT_COUNTER_TABLE_PROPERTY counters | ||
// - The counters are defined differently for different arch. | ||
// | ||
#if defined(TARGET_BMV2_V1MODEL) | ||
|
||
#define DEFINE_COUNTER(name, count, ...) \ | ||
@SaiCounter[__VA_ARGS__] \ | ||
counter(count, CounterType.packets_and_bytes) name; | ||
|
||
// DBC (Design By Contract) macros | ||
#define REQUIRES(cond) assert(cond) | ||
#define DEFINE_PACKET_COUNTER(name, count, ...) \ | ||
@SaiCounter[__VA_ARGS__] \ | ||
counter(count, CounterType.packets) name; | ||
|
||
#endif // TARGET_BMV2_V1MODEL | ||
#define DEFINE_BYTE_COUNTER(name, count, ...) \ | ||
@SaiCounter[__VA_ARGS__] \ | ||
counter(count, CounterType.bytes) name; | ||
|
||
#ifdef TARGET_DPDK_PNA | ||
#define UPDATE_COUNTER(name, index) \ | ||
name.count((bit<32>)index) | ||
|
||
#define DEFINE_TABLE_COUNTER(counter_name) direct_counter(CounterType.packets_and_bytes) counter_name; | ||
#define ATTACH_TABLE_COUNTER(counter_name) counters = counter_name; | ||
|
||
#elif defined(TARGET_DPDK_PNA) // TARGET_BMV2_V1MODEL | ||
|
||
// Counters are not supported yet for PNA arch in DASH | ||
#define DEFINE_COUNTER(name, count, ...) | ||
#define DEFINE_PACKET_COUNTER(name, count, ...) | ||
#define DEFINE_BYTE_COUNTER(name, count, ...) | ||
#define UPDATE_COUNTER(name, index) | ||
|
||
#include <pna.p4> | ||
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE | ||
// Omit all direct counters for tables with ternary match keys, | ||
// because the latest version of p4c-dpdk as of 2023-Jan-26 does | ||
// not support this combination of features. If you try to | ||
// compile it with this code enabled, the error message looks like | ||
// this: | ||
// | ||
// [--Werror=target-error] error: Direct counters and direct meters are unsupported for wildcard match table outbound_acl_stage1:dash_acl_rule|dash_acl | ||
// | ||
// This p4c issue is tracking this feature gap in p4c-dpdk: | ||
// https://github.com/p4lang/p4c/issues/3868 | ||
#define DEFINE_TABLE_COUNTER(counter_name) DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) counter_name; | ||
#define ATTACH_TABLE_COUNTER(counter_name) pna_direct_counter = counter_name; | ||
#else | ||
#define DEFINE_TABLE_COUNTER(counter_name) | ||
#define ATTACH_TABLE_COUNTER(counter_name) | ||
#endif | ||
|
||
// Counters | ||
#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE | ||
// Omit all direct counters for tables with ternary match keys, | ||
// because the latest version of p4c-dpdk as of 2023-Jan-26 does | ||
// not support this combination of features. If you try to | ||
// compile it with this code enabled, the error message looks like | ||
// this: | ||
// | ||
// [--Werror=target-error] error: Direct counters and direct meters are unsupported for wildcard match table outbound_acl_stage1:dash_acl_rule|dash_acl | ||
// | ||
// This p4c issue is tracking this feature gap in p4c-dpdk: | ||
// https://github.com/p4lang/p4c/issues/3868 | ||
#define DEFINE_TABLE_COUNTER(counter_name) DirectCounter<bit<64>>(PNA_CounterType_t.PACKETS_AND_BYTES) counter_name; | ||
#define ATTACH_TABLE_COUNTER(counter_name) pna_direct_counter = counter_name; | ||
#else | ||
#define DEFINE_TABLE_COUNTER(counter_name) | ||
#define ATTACH_TABLE_COUNTER(counter_name) | ||
#endif | ||
#endif // TARGET_DPDK_PNA | ||
|
||
// | ||
// DBC (Design By Contract) macros | ||
// NOTE: PNA doesn't support assert, hence all macros are defined as empty | ||
#define REQUIRES(cond) | ||
|
||
// - These macros will be used as a replacement for asserts, which makes the precondition and postcondition checks more explicit. | ||
// | ||
#if defined(TARGET_BMV2_V1MODEL) | ||
|
||
#define REQUIRES(cond) assert(cond) | ||
|
||
#elif defined(TARGET_DPDK_PNA) // TARGET_BMV2_V1MODEL | ||
|
||
// NOTE: PNA doesn't support assert, hence all macros are defined as empty | ||
#define REQUIRES(cond) | ||
|
||
#endif // TARGET_DPDK_PNA | ||
|
||
#endif // __DASH_TARGET_SPECIFIC__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters