Skip to content

Commit 50f8f2f

Browse files
Edward Creedavem330
Edward Cree
authored andcommitted
sfc: implement counters readout to TC stats
On FLOW_CLS_STATS, look up the MAE counter by TC cookie, and report the change in packet and byte count since the last time FLOW_CLS_STATS read them. Signed-off-by: Edward Cree <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 83a187a commit 50f8f2f

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

drivers/net/ethernet/sfc/tc.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,42 @@ static int efx_tc_flower_destroy(struct efx_nic *efx,
595595
return 0;
596596
}
597597

598+
static int efx_tc_flower_stats(struct efx_nic *efx, struct net_device *net_dev,
599+
struct flow_cls_offload *tc)
600+
{
601+
struct netlink_ext_ack *extack = tc->common.extack;
602+
struct efx_tc_counter_index *ctr;
603+
struct efx_tc_counter *cnt;
604+
u64 packets, bytes;
605+
606+
ctr = efx_tc_flower_find_counter_index(efx, tc->cookie);
607+
if (!ctr) {
608+
/* See comment in efx_tc_flower_destroy() */
609+
if (!IS_ERR(efx_tc_flower_lookup_efv(efx, net_dev)))
610+
if (net_ratelimit())
611+
netif_warn(efx, drv, efx->net_dev,
612+
"Filter %lx not found for stats\n",
613+
tc->cookie);
614+
NL_SET_ERR_MSG_MOD(extack, "Flow cookie not found in offloaded rules");
615+
return -ENOENT;
616+
}
617+
if (WARN_ON(!ctr->cnt)) /* can't happen */
618+
return -EIO;
619+
cnt = ctr->cnt;
620+
621+
spin_lock_bh(&cnt->lock);
622+
/* Report only new pkts/bytes since last time TC asked */
623+
packets = cnt->packets;
624+
bytes = cnt->bytes;
625+
flow_stats_update(&tc->stats, bytes - cnt->old_bytes,
626+
packets - cnt->old_packets, 0, cnt->touched,
627+
FLOW_ACTION_HW_STATS_DELAYED);
628+
cnt->old_packets = packets;
629+
cnt->old_bytes = bytes;
630+
spin_unlock_bh(&cnt->lock);
631+
return 0;
632+
}
633+
598634
int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev,
599635
struct flow_cls_offload *tc, struct efx_rep *efv)
600636
{
@@ -611,6 +647,9 @@ int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev,
611647
case FLOW_CLS_DESTROY:
612648
rc = efx_tc_flower_destroy(efx, net_dev, tc);
613649
break;
650+
case FLOW_CLS_STATS:
651+
rc = efx_tc_flower_stats(efx, net_dev, tc);
652+
break;
614653
default:
615654
rc = -EOPNOTSUPP;
616655
break;

drivers/net/ethernet/sfc/tc_counters.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
198198
return ctr;
199199
}
200200

201+
struct efx_tc_counter_index *efx_tc_flower_find_counter_index(
202+
struct efx_nic *efx, unsigned long cookie)
203+
{
204+
struct efx_tc_counter_index key = {};
205+
206+
key.cookie = cookie;
207+
return rhashtable_lookup_fast(&efx->tc->counter_id_ht, &key,
208+
efx_tc_counter_id_ht_params);
209+
}
210+
201211
/* TC Channel. Counter updates are delivered on this channel's RXQ. */
202212

203213
static void efx_tc_handle_no_channel(struct efx_nic *efx)

drivers/net/ethernet/sfc/tc_counters.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct efx_tc_counter {
2929
spinlock_t lock; /* Serialises updates to counter values */
3030
u32 gen; /* Generation count at which this counter is current */
3131
u64 packets, bytes;
32+
u64 old_packets, old_bytes; /* Values last time passed to userspace */
3233
/* jiffies of the last time we saw packets increase */
3334
unsigned long touched;
3435
};
@@ -50,6 +51,8 @@ struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
5051
enum efx_tc_counter_type type);
5152
void efx_tc_flower_put_counter_index(struct efx_nic *efx,
5253
struct efx_tc_counter_index *ctr);
54+
struct efx_tc_counter_index *efx_tc_flower_find_counter_index(
55+
struct efx_nic *efx, unsigned long cookie);
5356

5457
extern const struct efx_channel_type efx_tc_channel_type;
5558

0 commit comments

Comments
 (0)