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

[sai-gen] Add support of generating hit count counters #531

Merged
merged 2 commits into from
Mar 6, 2024
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
8 changes: 6 additions & 2 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def __init__(self):
self.isreadonly: str = "true"
self.counter_type: str = "bytes"
self.attr_type: str = "stats"
self.no_suffix: bool = ""
self.param_actions: List[str] = []

def parse_p4rt(self, p4rt_counter: Dict[str, Any], var_ref_graph: P4VarRefGraph) -> None:
Expand Down Expand Up @@ -597,6 +598,8 @@ def __parse_sai_counter_annotation(self, p4rt_counter: Dict[str, Any]) -> None:
self.attr_type = str(kv['value']['stringValue'])
if self.attr_type not in ["counter_attr", "counter_id", "stats"]:
raise ValueError(f'Unknown counter attribute type: attr_type={self.attr_type}')
elif kv['key'] == 'no_suffix':
self.no_suffix = str(kv['value']['stringValue']) == "true"
else:
raise ValueError("Unknown attr annotation " + kv['key'])

Expand All @@ -613,10 +616,11 @@ def generate_counter_sai_attributes(self) -> 'Iterator[SAICounter]':
counter = copy.deepcopy(self)

counter.counter_type = counter_type

if counter.attr_type == "counter_attr":
counter.name = f"{counter.name}_{counter.counter_type}_counter"
counter.name = f"{counter.name}_{counter.counter_type}_counter" if not self.no_suffix else f"{counter.name}_counter"
else:
counter.name = f"{counter.name}_{counter.counter_type}"
counter.name = f"{counter.name}_{counter.counter_type}" if not self.no_suffix else counter.name

yield counter

Expand Down
5 changes: 5 additions & 0 deletions dash-pipeline/bmv2/dash_arch_specific.p4
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
@SaiCounter[__VA_ARGS__] \
counter(count, CounterType.bytes) name;

#define DEFINE_HIT_COUNTER(name, count, ...) \
@SaiCounter[__VA_ARGS__, no_suffix="true"] \
counter(count, CounterType.packets) name;

#define UPDATE_COUNTER(name, index) \
name.count((bit<32>)index)

Expand All @@ -40,6 +44,7 @@
#define DEFINE_COUNTER(name, count, ...)
#define DEFINE_PACKET_COUNTER(name, count, ...)
#define DEFINE_BYTE_COUNTER(name, count, ...)
#define DEFINE_HIT_COUNTER(name, count, ...)
#define UPDATE_COUNTER(name, index)

#ifdef DPDK_SUPPORTS_DIRECT_COUNTER_ON_WILDCARD_KEY_TABLE
Expand Down
Loading