History

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.

Ido Schimmel committed 7 years ago

Commit 28315f71 parent c5ab9b12 files · +41 −6Browse files

Unified · Split

2 files
  1. include/uapi/linux/net_dropmon.h +9 −0
  2. net/core/drop_monitor.c +32 −6
include/uapi/linux/net_dropmon.h+9−0
@@ -62,4 +62,13 @@ enum { · 61 unmodified lines
62 * Our group identifiers62 * Our group identifiers
63 */63 */
64#define NET_DM_GRP_ALERT 164#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 */
70enum net_dm_alert_mode {
71 NET_DM_ALERT_MODE_SUMMARY,
72};
73
65#endif74#endif
net/core/drop_monitor.c+32−6
@@ -75,6 +75,16 @@ static int dm_delay = 1; · 74 unmodified lines
75static unsigned long dm_hw_check_delta = 2*HZ;75static unsigned long dm_hw_check_delta = 2*HZ;
76static LIST_HEAD(hw_stats_list);76static LIST_HEAD(hw_stats_list);
77 77
78static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
79
80struct 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
78static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)88static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
79{89{
80 size_t al;90 size_t al;
@@ -241,10 +251,23 @@ static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi, · 160 unmodified lines
241 rcu_read_unlock();251 rcu_read_unlock();
242}252}
243 253
254static 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
260static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
261 [NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops,
262};
263
244static int net_dm_trace_on_set(struct netlink_ext_ack *extack)264static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
245{265{
266 const struct net_dm_alert_ops *ops;
246 int cpu, rc;267 int cpu, rc;
247 268
269 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
270
248 if (!try_module_get(THIS_MODULE)) {271 if (!try_module_get(THIS_MODULE)) {
249 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");272 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
250 return -ENODEV;273 return -ENODEV;
@@ -254,7 +277,7 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack) · 3 unmodified lines
254 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);277 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
255 struct sk_buff *skb;278 struct sk_buff *skb;
256 279
257 INIT_WORK(&data->dm_alert_work, send_dm_alert);280 INIT_WORK(&data->dm_alert_work, ops->work_item_func);
258 timer_setup(&data->send_timer, sched_send_work, 0);281 timer_setup(&data->send_timer, sched_send_work, 0);
259 /* Allocate a new per-CPU skb for the summary alert message and282 /* Allocate a new per-CPU skb for the summary alert message and
260 * free the old one which might contain stale data from283 * 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) · 3 unmodified lines
264 consume_skb(skb);287 consume_skb(skb);
265 }288 }
266 289
267 rc = register_trace_kfree_skb(trace_kfree_skb_hit, NULL);290 rc = register_trace_kfree_skb(ops->kfree_skb_probe, NULL);
268 if (rc) {291 if (rc) {
269 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to kfree_skb() tracepoint");292 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to kfree_skb() tracepoint");
270 goto err_module_put;293 goto err_module_put;
271 }294 }
272 295
273 rc = register_trace_napi_poll(trace_napi_poll_hit, NULL);296 rc = register_trace_napi_poll(ops->napi_poll_probe, NULL);
274 if (rc) {297 if (rc) {
275 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to napi_poll() tracepoint");298 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to napi_poll() tracepoint");
276 goto err_unregister_trace;299 goto err_unregister_trace;
@@ -279,7 +302,7 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack) · 2 unmodified lines
279 return 0;302 return 0;
280 303
281err_unregister_trace:304err_unregister_trace:
282 unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL);305 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
283err_module_put:306err_module_put:
284 module_put(THIS_MODULE);307 module_put(THIS_MODULE);
285 return rc;308 return rc;
@@ -288,10 +311,13 @@ err_module_put: · 2 unmodified lines
288static void net_dm_trace_off_set(void)311static void net_dm_trace_off_set(void)
289{312{
290 struct dm_hw_stat_delta *new_stat, *temp;313 struct dm_hw_stat_delta *new_stat, *temp;
314 const struct net_dm_alert_ops *ops;
291 int cpu;315 int cpu;
292 316
293 unregister_trace_napi_poll(trace_napi_poll_hit, NULL);317 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
294 unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL);318
319 unregister_trace_napi_poll(ops->napi_poll_probe, NULL);
320 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
295 321
296 tracepoint_synchronize_unregister();322 tracepoint_synchronize_unregister();
297 323

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t