tc: m_action: introduce support for hw stats type
Subsystems (3)
Jiri Pirko
maintainerPATCH v2 1/1 tc: m_action: introduce support for hw stats type
From: Jiri Pirko <[email protected]>
Introduce support for per-action hw stats type config.
This patch allows user to specify one of the following types of HW stats for added action:
immediate - queried during dump time
delayed - polled from HW periodically or sent by HW in async manner disabled - no stats needed
Note that if "hw_stats" option is not passed, user does not care about the type, just expects any type of stats.
Examples:
$ tc filter add dev enp0s16np28 ingress proto ip handle 1 pref 1 flower skip_sw dst_ip 192.168.1.1 action drop hw_stats disabled
$ tc -s filter show dev enp0s16np28 ingress
filter protocol ip pref 1 flower chain 0
filter protocol ip pref 1 flower chain 0 handle 0x1
eth_type ipv4
dst_ip 192.168.1.1
skip_sw
in_hw in_hw_count 2
action order 1: gact action drop
random type none pass val 0
index 1 ref 1 bind 1 installed 7 sec used 2 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
hw_stats disabled$ tc filter add dev enp0s16np28 ingress proto ip handle 1 pref 1 flower skip_sw dst_ip 192.168.1.1 action drop hw_stats immediate
$ tc -s filter show dev enp0s16np28 ingress
filter protocol ip pref 1 flower chain 0
filter protocol ip pref 1 flower chain 0 handle 0x1
eth_type ipv4
dst_ip 192.168.1.1
skip_sw
in_hw in_hw_count 2
action order 1: gact action drop
random type none pass val 0
index 1 ref 1 bind 1 installed 11 sec used 4 sec
Action statistics:
Sent 102 bytes 1 pkt (dropped 1, overlimits 0 requeues 0)
Sent software 0 bytes 0 pkt
Sent hardware 102 bytes 1 pkt
backlog 0b 0p requeues 0
hw_stats immediate---v1->v2:
- added more description and examples
--- include/uapi/linux/pkt_cls.h | 22 +++++++++++++ man/man8/tc-actions.8 | 31 ++++++++++++++++++ tc/m_action.c | 61 ++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+)
include/uapi/linux/pkt_cls.h +22 -0
@@ -17,6 +17,7 @@ enum {TCA_ACT_PAD ,TCA_ACT_COOKIE ,TCA_ACT_FLAGS , +TCA_ACT_HW_STATS_TYPE , __TCA_ACT_MAX };
@@ -24,6 +25,27 @@ enum {* actions stats. */ +/* tca HW stats type +* When user does not pass the attribute, he does not care. +* It is the same as if he would pass the attribute with +* all supported bits set. +* In case no bits are set, user is not interested in getting any HW statistics. +*/ +#define TCA_ACT_HW_STATS_TYPE_IMMEDIATE (1 << 0)/* Means that in dump, user +* gets the current HW stats +* state from the device +* queried at the dump time. +*/ +#define TCA_ACT_HW_STATS_TYPE_DELAYED (1 << 1)/* Means that in dump, user gets +* HW stats that might be out +* of date for some time, maybe +* couple of seconds. This is +* the case when driver polls +* stats updates periodically +* or when it gets async stats update +* from the device. +*/ +#define TCA_ACT_MAX __TCA_ACT_MAX#define TCA_OLD_COMPAT (TCA_ACT_MAX+1)#define TCA_ACT_MAX_PRIO 32
man/man8/tc-actions.8 +31 -0
@@ -49,6 +49,8 @@ actions \- independently defined actions in tc ] [ .I FLAGS ] [ +.I HWSTATSSPEC +] [ .I CONTROL ]
@@ -77,6 +79,12 @@ ACTNAME := .I no_percpu +.I HWSTATSSPEC +:= +.BR hw_stats " {" +.IR immediate " | " delayed " | " disabled +.R } + .I ACTDETAIL := .I ACTNAME ACTPARAMS
@@ -200,6 +208,29 @@ which indicates that action is expected to have minimal software data-path traffic and doesn't need to allocate stat counters with percpu allocator. This option is intended to be used by hardware-offloaded actions. +.TP +.BI hw_stats " HW_STATS" +Speficies the type of HW stats of new action. If omitted, any stats counter type +is going to be used, according to driver and its resources. +The +.I HW_STATS +indicates the type. Any of the following are valid: +.RS +.TP +.B immediate +Means that in dump, user gets the current HW stats state from the device +queried at the dump time. +.TP +.B delayed +Means that in dump, user gets HW stats that might be out of date for +some time, maybe couple of seconds. This is the case when driver polls +stats updates periodically or when it gets async stats update +from the device. +.TP +.B disabled +No HW stats are going to be available in dump. +.RE + .TP .BI since " MSTIME" When dumping large number of actions, a millisecond time-filter can be
tc/m_action.c +61 -0
79 lines not on this page · raw message
Signature · 1 line
2.21.1
Quoted 6 lines · Jiri Pirko
include/uapi/linux/pkt_cls.h +2
-0@@ -24,6 +25,27 @@ enum {* actions stats. */ +/* tca HW stats type +* When user does not pass the attribute, he does not care.
include/uapi/linux/pkt_cls.h enum { · line 39
Quoted 10 lines
include/uapi/linux/pkt_cls.h +10
-0+* It is the same as if he would pass the attribute with +* all supported bits set. +* In case no bits are set, user is not interested in getting any HW statistics. +*/ +#define TCA_ACT_HW_STATS_TYPE_IMMEDIATE (1 << 0)/* Means that in dump, user +* gets the current HW stats +* state from the device +* queried at the dump time. +*/ +#define TCA_ACT_HW_STATS_TYPE_DELAYED (1 << 1)/* Means that in dump, user gets
really long names for attributes.
Quoted 7 lines
tc/m_action.c +7
-0+static void print_hw_stats (const struct rtattr *arg) +{ +struct nla_bitfield32 *hw_stats_type_bf =RTA_DATA (arg); +__u8 hw_stats_type; +int i; + + hw_stats_type = hw_stats_type_bf->value & hw_stats_type_bf->selector;
tc/m_action.c new_cmd(char **argv) · line 177
Quoted 10 lines
tc/m_action.c +10
-0+print_string (PRINT_FP ,NULL ,"\t" ,NULL ); +open_json_array (PRINT_ANY ,"hw_stats" ); + +for (i =0 ; i <ARRAY_SIZE (hw_stats_type_items); i++) { +const struct hw_stats_type_item *item; + + item = &hw_stats_type_items[i]; +if ((!hw_stats_type && !item->type) || + hw_stats_type & item->type) +print_string (PRINT_ANY ,NULL ," %s" , item->str);
the stats type can be both delayed and immediate?
Quoted 8 lines
tc/m_action.c +8
-0+ } +close_json_array (PRINT_JSON ,NULL ); +} + +static int parse_hw_stats (const char *str,struct nlmsghdr *n) +{ +int i; +
tc/m_action.c new_cmd(char **argv) · line 195
Quoted 10 lines
tc/m_action.c +10
-0+for (i =0 ; i <ARRAY_SIZE (hw_stats_type_items); i++) { +const struct hw_stats_type_item *item; + + item = &hw_stats_type_items[i]; +if (matches (str, item->str) ==0 ) { +struct nla_bitfield32 hw_stats_type_bf = + { item->type, + item->type }; +addattr_l (n,MAX_MSG ,TCA_ACT_HW_STATS_TYPE , + &hw_stats_type_bf,sizeof (hw_stats_type_bf));
that is not human friendly. how about something like:
struct nla_bitfield32 hw_stats_type_bf = {
.value = item->type,
.selector = item->type
};with a line between the declaration and code.
and "disabled" corresponds to 0 which does not align with a TCA_ACT_HW_STATS_TYPE_ so why send it
Jiri Pirko
maintainerQuoted 32 lines · Wed, Mar 11, 2020 at 12:44:42AM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
include/uapi/linux/pkt_cls.h +2
-0@@ -24,6 +25,27 @@ enum {* actions stats. */ +/* tca HW stats type +* When user does not pass the attribute, he does not care. include/uapi/linux/pkt_cls.h enum { · line 39
Quoted 10 lines
include/uapi/linux/pkt_cls.h +10
-0+* It is the same as if he would pass the attribute with +* all supported bits set. +* In case no bits are set, user is not interested in getting any HW statistics. +*/ +#define TCA_ACT_HW_STATS_TYPE_IMMEDIATE (1 << 0)/* Means that in dump, user +* gets the current HW stats +* state from the device +* queried at the dump time. +*/ +#define TCA_ACT_HW_STATS_TYPE_DELAYED (1 << 1)/* Means that in dump, user gets really long names for attributes.
Quoted 11 lines
tc/m_action.c +11
-0+static void print_hw_stats (const struct rtattr *arg) +{ +struct nla_bitfield32 *hw_stats_type_bf =RTA_DATA (arg); +__u8 hw_stats_type; +int i; + + hw_stats_type = hw_stats_type_bf->value & hw_stats_type_bf->selector; +print_string (PRINT_FP ,NULL ,"\t" ,NULL ); +open_json_array (PRINT_ANY ,"hw_stats" ); + +for (i =0 ; i <ARRAY_SIZE (hw_stats_type_items); i++) {
Quoted 8 lines
tc/m_action.c new_cmd(char **argv) · line 177
Quoted 6 lines
tc/m_action.c +6
-0+const struct hw_stats_type_item *item; + + item = &hw_stats_type_items[i]; +if ((!hw_stats_type && !item->type) || + hw_stats_type & item->type) +print_string (PRINT_ANY ,NULL ," %s" , item->str);the stats type can be both delayed and immediate?
Yes, if offloaded to 2 drivers, each supporting different stats.
Quoted 22 lines
Quoted 9 lines
tc/m_action.c +8
-0+ } +close_json_array (PRINT_JSON ,NULL ); +} + +static int parse_hw_stats (const char *str,struct nlmsghdr *n) +{ +int i; +tc/m_action.c new_cmd(char **argv) · line 195
Quoted 10 lines
tc/m_action.c +10
-0+for (i =0 ; i <ARRAY_SIZE (hw_stats_type_items); i++) { +const struct hw_stats_type_item *item; + + item = &hw_stats_type_items[i]; +if (matches (str, item->str) ==0 ) { +struct nla_bitfield32 hw_stats_type_bf = + { item->type, + item->type }; +addattr_l (n,MAX_MSG ,TCA_ACT_HW_STATS_TYPE , + &hw_stats_type_bf,sizeof (hw_stats_type_bf));that is not human friendly. how about something like:
Quoted 4 lines
struct nla_bitfield32 hw_stats_type_bf = {
.value = item->type,
.selector = item->type
};Okay.
Quoted 5 lines
with a line between the declaration and code.
and "disabled" corresponds to 0 which does not align with a
TCA_ACT_HW_STATS_TYPE_so why send it
It is a bitfield. So 0 means no bit is set, therefore disabled.