提交 9b63f57d 编写于 作者: I Ido Schimmel 提交者: David S. Miller

drop_monitor: Move per-CPU data init/fini to separate functions

Currently drop monitor only reports software drops to user space, but
subsequent patches are going to add support for hardware drops.

Like software drops, the per-CPU data of hardware drops needs to be
initialized and de-initialized upon module initialization and exit. To
avoid code duplication, break this code into separate functions, so that
these could be re-used for hardware drops.

No functional changes intended.
Signed-off-by: NIdo Schimmel <idosch@mellanox.com>
Acked-by: NJiri Pirko <jiri@mellanox.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 f7750830
...@@ -934,9 +934,40 @@ static struct notifier_block dropmon_net_notifier = { ...@@ -934,9 +934,40 @@ static struct notifier_block dropmon_net_notifier = {
.notifier_call = dropmon_net_event .notifier_call = dropmon_net_event
}; };
static int __init init_net_drop_monitor(void) static void __net_dm_cpu_data_init(struct per_cpu_dm_data *data)
{
spin_lock_init(&data->lock);
skb_queue_head_init(&data->drop_queue);
u64_stats_init(&data->stats.syncp);
}
static void __net_dm_cpu_data_fini(struct per_cpu_dm_data *data)
{
WARN_ON(!skb_queue_empty(&data->drop_queue));
}
static void net_dm_cpu_data_init(int cpu)
{ {
struct per_cpu_dm_data *data; struct per_cpu_dm_data *data;
data = &per_cpu(dm_cpu_data, cpu);
__net_dm_cpu_data_init(data);
}
static void net_dm_cpu_data_fini(int cpu)
{
struct per_cpu_dm_data *data;
data = &per_cpu(dm_cpu_data, cpu);
/* At this point, we should have exclusive access
* to this struct and can free the skb inside it.
*/
consume_skb(data->skb);
__net_dm_cpu_data_fini(data);
}
static int __init init_net_drop_monitor(void)
{
int cpu, rc; int cpu, rc;
pr_info("Initializing network drop monitor service\n"); pr_info("Initializing network drop monitor service\n");
...@@ -961,12 +992,8 @@ static int __init init_net_drop_monitor(void) ...@@ -961,12 +992,8 @@ static int __init init_net_drop_monitor(void)
rc = 0; rc = 0;
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu)
data = &per_cpu(dm_cpu_data, cpu); net_dm_cpu_data_init(cpu);
spin_lock_init(&data->lock);
skb_queue_head_init(&data->drop_queue);
u64_stats_init(&data->stats.syncp);
}
goto out; goto out;
...@@ -978,7 +1005,6 @@ static int __init init_net_drop_monitor(void) ...@@ -978,7 +1005,6 @@ static int __init init_net_drop_monitor(void)
static void exit_net_drop_monitor(void) static void exit_net_drop_monitor(void)
{ {
struct per_cpu_dm_data *data;
int cpu; int cpu;
BUG_ON(unregister_netdevice_notifier(&dropmon_net_notifier)); BUG_ON(unregister_netdevice_notifier(&dropmon_net_notifier));
...@@ -988,15 +1014,8 @@ static void exit_net_drop_monitor(void) ...@@ -988,15 +1014,8 @@ static void exit_net_drop_monitor(void)
* we are guarnateed not to have any current users when we get here * we are guarnateed not to have any current users when we get here
*/ */
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu)
data = &per_cpu(dm_cpu_data, cpu); net_dm_cpu_data_fini(cpu);
/*
* At this point, we should have exclusive access
* to this struct and can free the skb inside it
*/
kfree_skb(data->skb);
WARN_ON(!skb_queue_empty(&data->drop_queue));
}
BUG_ON(genl_unregister_family(&net_drop_monitor_family)); BUG_ON(genl_unregister_family(&net_drop_monitor_family));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册