Skip to content

Commit 28315f7

Browse files
idoschdavem330
authored andcommitted
drop_monitor: Add alert mode operations
The next patch is going to add another alert mode in which the dropped packet is notified to user space, instead of only a summary of recent drops. Abstract the differences between the modes by adding alert mode operations. The operations are selected based on the currently configured mode and associated with the probes and the work item just before tracing starts. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c5ab9b1 commit 28315f7

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

‎include/uapi/linux/net_dropmon.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,13 @@ enum {
6262
* Our group identifiers
6363
*/
6464
#define NET_DM_GRP_ALERT 1
65+
66+
/**
67+
* enum net_dm_alert_mode - Alert mode.
68+
* @NET_DM_ALERT_MODE_SUMMARY: A summary of recent drops is sent to user space.
69+
*/
70+
enum net_dm_alert_mode {
71+
NET_DM_ALERT_MODE_SUMMARY,
72+
};
73+
6574
#endif

‎net/core/drop_monitor.c‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ static int dm_delay = 1;
7575
static unsigned long dm_hw_check_delta = 2*HZ;
7676
static LIST_HEAD(hw_stats_list);
7777

78+
static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
79+
80+
struct net_dm_alert_ops {
81+
void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
82+
void *location);
83+
void (*napi_poll_probe)(void *ignore, struct napi_struct *napi,
84+
int work, int budget);
85+
void (*work_item_func)(struct work_struct *work);
86+
};
87+
7888
static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
7989
{
8090
size_t al;
@@ -241,10 +251,23 @@ static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi,
241251
rcu_read_unlock();
242252
}
243253

254+
static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
255+
.kfree_skb_probe = trace_kfree_skb_hit,
256+
.napi_poll_probe = trace_napi_poll_hit,
257+
.work_item_func = send_dm_alert,
258+
};
259+
260+
static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
261+
[NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops,
262+
};
263+
244264
static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
245265
{
266+
const struct net_dm_alert_ops *ops;
246267
int cpu, rc;
247268

269+
ops = net_dm_alert_ops_arr[net_dm_alert_mode];
270+
248271
if (!try_module_get(THIS_MODULE)) {
249272
NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
250273
return -ENODEV;
@@ -254,7 +277,7 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
254277
struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
255278
struct sk_buff *skb;
256279

257-
INIT_WORK(&data->dm_alert_work, send_dm_alert);
280+
INIT_WORK(&data->dm_alert_work, ops->work_item_func);
258281
timer_setup(&data->send_timer, sched_send_work, 0);
259282
/* Allocate a new per-CPU skb for the summary alert message and
260283
* free the old one which might contain stale data from
@@ -264,13 +287,13 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
264287
consume_skb(skb);
265288
}
266289

267-
rc = register_trace_kfree_skb(trace_kfree_skb_hit, NULL);
290+
rc = register_trace_kfree_skb(ops->kfree_skb_probe, NULL);
268291
if (rc) {
269292
NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to kfree_skb() tracepoint");
270293
goto err_module_put;
271294
}
272295

273-
rc = register_trace_napi_poll(trace_napi_poll_hit, NULL);
296+
rc = register_trace_napi_poll(ops->napi_poll_probe, NULL);
274297
if (rc) {
275298
NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to napi_poll() tracepoint");
276299
goto err_unregister_trace;
@@ -279,7 +302,7 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
279302
return 0;
280303

281304
err_unregister_trace:
282-
unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL);
305+
unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
283306
err_module_put:
284307
module_put(THIS_MODULE);
285308
return rc;
@@ -288,10 +311,13 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
288311
static void net_dm_trace_off_set(void)
289312
{
290313
struct dm_hw_stat_delta *new_stat, *temp;
314+
const struct net_dm_alert_ops *ops;
291315
int cpu;
292316

293-
unregister_trace_napi_poll(trace_napi_poll_hit, NULL);
294-
unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL);
317+
ops = net_dm_alert_ops_arr[net_dm_alert_mode];
318+
319+
unregister_trace_napi_poll(ops->napi_poll_probe, NULL);
320+
unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
295321

296322
tracepoint_synchronize_unregister();
297323

0 commit comments

Comments
 (0)