Skip to content

Commit 3df2bf2

Browse files
committed
Merge: CNB96: net: Support for nexthop group statistics
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5198 JIRA: https://issues.redhat.com/browse/RHEL-59118 Tested: Using fib_nexthops.sh, router_mpath_nh.sh and router_mpath_nh_res.sh self-tests ``` eedd47a ("nexthop: Factor out hash threshold fdb nexthop selection") 4bb5239 ("nexthop: Factor out neighbor validity check") 75f5f04 ("nexthop: Do not return invalid nexthop object during multipath selection") c7e95bb ("selftests: net: Add test cases for nexthop groups with invalid neighbors") 3e584e3 ("nexthop: Annotate struct nh_notifier_res_table_info with __counted_by") cf9ecad ("nexthop: Annotate struct nh_notifier_grp_info with __counted_by") 2118f93 ("net: nexthop: Adjust netlink policy parsing for a new attribute") a207eab ("net: nexthop: Add NHA_OP_FLAGS") f4676ea ("net: nexthop: Add nexthop group entry stats") 95fedd7 ("net: nexthop: Expose nexthop group stats to user space") 5877786 ("net: nexthop: Add hardware statistics notifications") 746c19a ("net: nexthop: Add ability to enable / disable hardware statistics") 5072ae0 ("net: nexthop: Expose nexthop group HW stats to user space") 2d32c49 ("net: nexthop: Initialize NH group ID in resilient NH group notifiers") e99eb57 ("net: nexthop: Have all NH notifiers carry NH ID") a22b042 ("selftests: forwarding: Add a test for NH group stats") dc5e014 ("nexthop: Only parse NHA_OP_FLAGS for get messages that require it") 262a68a ("nexthop: Only parse NHA_OP_FLAGS for dump messages that require it") d8a2107 ("nexthop: Fix out-of-bounds access during attribute validation") e006858 ("nexthop: Fix splat with CONFIG_DEBUG_PREEMPT=y") 9145e22 ("nexthop: fix uninitialized variable in nla_put_nh_group_stats()") ``` Signed-off-by: Ivan Vecera <ivecera@redhat.com> Approved-by: Ivan Vecera <ivecera@redhat.com> Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents d3df786 + 7c3ae3e commit 3df2bf2

File tree

9 files changed

+731
-51
lines changed

9 files changed

+731
-51
lines changed

include/net/nexthop.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct nh_config {
4949
bool nh_grp_res_has_idle_timer;
5050
bool nh_grp_res_has_unbalanced_timer;
5151

52+
bool nh_hw_stats;
53+
5254
struct nlattr *nh_encap;
5355
u16 nh_encap_type;
5456

@@ -97,8 +99,14 @@ struct nh_res_table {
9799
struct nh_res_bucket nh_buckets[];
98100
};
99101

102+
struct nh_grp_entry_stats {
103+
u64_stats_t packets;
104+
struct u64_stats_sync syncp;
105+
};
106+
100107
struct nh_grp_entry {
101108
struct nexthop *nh;
109+
struct nh_grp_entry_stats __percpu *stats;
102110
u8 weight;
103111

104112
union {
@@ -116,6 +124,7 @@ struct nh_grp_entry {
116124

117125
struct list_head nh_list;
118126
struct nexthop *nh_parent; /* nexthop of group with this entry */
127+
u64 packets_hw;
119128
};
120129

121130
struct nh_group {
@@ -126,6 +135,7 @@ struct nh_group {
126135
bool resilient;
127136
bool fdb_nh;
128137
bool has_v4;
138+
bool hw_stats;
129139

130140
RH_KABI_RESERVE(1)
131141
RH_KABI_RESERVE(2)
@@ -162,13 +172,15 @@ enum nexthop_event_type {
162172
NEXTHOP_EVENT_REPLACE,
163173
NEXTHOP_EVENT_RES_TABLE_PRE_REPLACE,
164174
NEXTHOP_EVENT_BUCKET_REPLACE,
175+
NEXTHOP_EVENT_HW_STATS_REPORT_DELTA,
165176
};
166177

167178
enum nh_notifier_info_type {
168179
NH_NOTIFIER_INFO_TYPE_SINGLE,
169180
NH_NOTIFIER_INFO_TYPE_GRP,
170181
NH_NOTIFIER_INFO_TYPE_RES_TABLE,
171182
NH_NOTIFIER_INFO_TYPE_RES_BUCKET,
183+
NH_NOTIFIER_INFO_TYPE_GRP_HW_STATS,
172184
};
173185

174186
struct nh_notifier_single_info {
@@ -178,21 +190,22 @@ struct nh_notifier_single_info {
178190
__be32 ipv4;
179191
struct in6_addr ipv6;
180192
};
193+
u32 id;
181194
u8 is_reject:1,
182195
is_fdb:1,
183196
has_encap:1;
184197
};
185198

186199
struct nh_notifier_grp_entry_info {
187200
u8 weight;
188-
u32 id;
189201
struct nh_notifier_single_info nh;
190202
};
191203

192204
struct nh_notifier_grp_info {
193205
u16 num_nh;
194206
bool is_fdb;
195-
struct nh_notifier_grp_entry_info nh_entries[];
207+
bool hw_stats;
208+
struct nh_notifier_grp_entry_info nh_entries[] __counted_by(num_nh);
196209
};
197210

198211
struct nh_notifier_res_bucket_info {
@@ -205,7 +218,19 @@ struct nh_notifier_res_bucket_info {
205218

206219
struct nh_notifier_res_table_info {
207220
u16 num_nh_buckets;
208-
struct nh_notifier_single_info nhs[];
221+
bool hw_stats;
222+
struct nh_notifier_single_info nhs[] __counted_by(num_nh_buckets);
223+
};
224+
225+
struct nh_notifier_grp_hw_stats_entry_info {
226+
u32 id;
227+
u64 packets;
228+
};
229+
230+
struct nh_notifier_grp_hw_stats_info {
231+
u16 num_nh;
232+
bool hw_stats_used;
233+
struct nh_notifier_grp_hw_stats_entry_info stats[] __counted_by(num_nh);
209234
};
210235

211236
struct nh_notifier_info {
@@ -218,6 +243,7 @@ struct nh_notifier_info {
218243
struct nh_notifier_grp_info *nh_grp;
219244
struct nh_notifier_res_table_info *nh_res_table;
220245
struct nh_notifier_res_bucket_info *nh_res_bucket;
246+
struct nh_notifier_grp_hw_stats_info *nh_grp_hw_stats;
221247
};
222248
};
223249

@@ -230,6 +256,9 @@ void nexthop_bucket_set_hw_flags(struct net *net, u32 id, u16 bucket_index,
230256
bool offload, bool trap);
231257
void nexthop_res_grp_activity_update(struct net *net, u32 id, u16 num_buckets,
232258
unsigned long *activity);
259+
void nh_grp_hw_stats_report_delta(struct nh_notifier_grp_hw_stats_info *info,
260+
unsigned int nh_idx,
261+
u64 delta_packets);
233262

234263
/* caller is holding rcu or rtnl; no reference taken to nexthop */
235264
struct nexthop *nexthop_find_by_id(struct net *net, u32 id);

include/uapi/linux/nexthop.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ enum {
3030

3131
#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
3232

33+
#define NHA_OP_FLAG_DUMP_STATS BIT(0)
34+
#define NHA_OP_FLAG_DUMP_HW_STATS BIT(1)
35+
3336
enum {
3437
NHA_UNSPEC,
3538
NHA_ID, /* u32; id for nexthop. id == 0 means auto-assign */
@@ -60,6 +63,18 @@ enum {
6063
/* nested; nexthop bucket attributes */
6164
NHA_RES_BUCKET,
6265

66+
/* u32; operation-specific flags */
67+
NHA_OP_FLAGS,
68+
69+
/* nested; nexthop group stats */
70+
NHA_GROUP_STATS,
71+
72+
/* u32; nexthop hardware stats enable */
73+
NHA_HW_STATS_ENABLE,
74+
75+
/* u32; read-only; whether any driver collects HW stats */
76+
NHA_HW_STATS_USED,
77+
6378
__NHA_MAX,
6479
};
6580

@@ -101,4 +116,34 @@ enum {
101116

102117
#define NHA_RES_BUCKET_MAX (__NHA_RES_BUCKET_MAX - 1)
103118

119+
enum {
120+
NHA_GROUP_STATS_UNSPEC,
121+
122+
/* nested; nexthop group entry stats */
123+
NHA_GROUP_STATS_ENTRY,
124+
125+
__NHA_GROUP_STATS_MAX,
126+
};
127+
128+
#define NHA_GROUP_STATS_MAX (__NHA_GROUP_STATS_MAX - 1)
129+
130+
enum {
131+
NHA_GROUP_STATS_ENTRY_UNSPEC,
132+
133+
/* u32; nexthop id of the nexthop group entry */
134+
NHA_GROUP_STATS_ENTRY_ID,
135+
136+
/* uint; number of packets forwarded via the nexthop group entry */
137+
NHA_GROUP_STATS_ENTRY_PACKETS,
138+
139+
/* uint; number of packets forwarded via the nexthop group entry in
140+
* hardware
141+
*/
142+
NHA_GROUP_STATS_ENTRY_PACKETS_HW,
143+
144+
__NHA_GROUP_STATS_ENTRY_MAX,
145+
};
146+
147+
#define NHA_GROUP_STATS_ENTRY_MAX (__NHA_GROUP_STATS_ENTRY_MAX - 1)
148+
104149
#endif

0 commit comments

Comments
 (0)