Skip to content

Commit 3804070

Browse files
amirvdavem330
authored andcommitted
net/sched: Enable netdev drivers to update statistics of offloaded actions
Introduce stats_update callback. netdev driver could call it for offloaded actions to update the basic statistics (packets, bytes and last use). Since bstats_update() and bstats_cpu_update() use skb as an argument to get the counters, _bstats_update() and _bstats_cpu_update(), that get bytes and packets as arguments, were added. Signed-off-by: Amir Vadai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 388665a commit 3804070

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

include/net/act_api.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct tc_action_ops {
106106
int bind);
107107
int (*walk)(struct net *, struct sk_buff *,
108108
struct netlink_callback *, int, struct tc_action *);
109+
void (*stats_update)(struct tc_action *, u64, u32, u64);
109110
};
110111

111112
struct tc_action_net {
@@ -178,10 +179,21 @@ int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
178179

179180
#define tc_for_each_action(_a, _exts) \
180181
list_for_each_entry(a, &(_exts)->actions, list)
182+
183+
static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
184+
u64 packets, u64 lastuse)
185+
{
186+
if (!a->ops->stats_update)
187+
return;
188+
189+
a->ops->stats_update(a, bytes, packets, lastuse);
190+
}
191+
181192
#else /* CONFIG_NET_CLS_ACT */
182193

183194
#define tc_no_actions(_exts) true
184195
#define tc_for_each_action(_a, _exts) while (0)
196+
#define tcf_action_stats_update(a, bytes, packets, lastuse)
185197

186198
#endif /* CONFIG_NET_CLS_ACT */
187199
#endif

include/net/sch_generic.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,27 @@ static inline bool qdisc_is_percpu_stats(const struct Qdisc *q)
527527
return q->flags & TCQ_F_CPUSTATS;
528528
}
529529

530+
static inline void _bstats_update(struct gnet_stats_basic_packed *bstats,
531+
__u64 bytes, __u32 packets)
532+
{
533+
bstats->bytes += bytes;
534+
bstats->packets += packets;
535+
}
536+
530537
static inline void bstats_update(struct gnet_stats_basic_packed *bstats,
531538
const struct sk_buff *skb)
532539
{
533-
bstats->bytes += qdisc_pkt_len(skb);
534-
bstats->packets += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1;
540+
_bstats_update(bstats,
541+
qdisc_pkt_len(skb),
542+
skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1);
543+
}
544+
545+
static inline void _bstats_cpu_update(struct gnet_stats_basic_cpu *bstats,
546+
__u64 bytes, __u32 packets)
547+
{
548+
u64_stats_update_begin(&bstats->syncp);
549+
_bstats_update(&bstats->bstats, bytes, packets);
550+
u64_stats_update_end(&bstats->syncp);
535551
}
536552

537553
static inline void bstats_cpu_update(struct gnet_stats_basic_cpu *bstats,

0 commit comments

Comments
 (0)