Commit 4572ef52 authored by andy zhou's avatar andy zhou Committed by David S. Miller

openvswitch: Refactor recirc key allocation.

The logic of allocating and copy key for each 'exec_actions_level'
was specific to execute_recirc(). However, future patches will reuse
as well.  Refactor the logic into its own function clone_key().
Signed-off-by: default avatarAndy Zhou <azhou@ovn.org>
Acked-by: default avatarPravin B Shelar <pshelar@ovn.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 47c697aa
/* /*
* Copyright (c) 2007-2014 Nicira, Inc. * Copyright (c) 2007-2017 Nicira, Inc.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public * modify it under the terms of version 2 of the GNU General Public
...@@ -83,14 +83,31 @@ struct action_fifo { ...@@ -83,14 +83,31 @@ struct action_fifo {
struct deferred_action fifo[DEFERRED_ACTION_FIFO_SIZE]; struct deferred_action fifo[DEFERRED_ACTION_FIFO_SIZE];
}; };
struct recirc_keys { struct action_flow_keys {
struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD]; struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD];
}; };
static struct action_fifo __percpu *action_fifos; static struct action_fifo __percpu *action_fifos;
static struct recirc_keys __percpu *recirc_keys; static struct action_flow_keys __percpu *flow_keys;
static DEFINE_PER_CPU(int, exec_actions_level); static DEFINE_PER_CPU(int, exec_actions_level);
/* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
* space. Return NULL if out of key spaces.
*/
static struct sw_flow_key *clone_key(const struct sw_flow_key *key_)
{
struct action_flow_keys *keys = this_cpu_ptr(flow_keys);
int level = this_cpu_read(exec_actions_level);
struct sw_flow_key *key = NULL;
if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
key = &keys->key[level - 1];
*key = *key_;
}
return key;
}
static void action_fifo_init(struct action_fifo *fifo) static void action_fifo_init(struct action_fifo *fifo)
{ {
fifo->head = 0; fifo->head = 0;
...@@ -1090,8 +1107,8 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb, ...@@ -1090,8 +1107,8 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_key *key, struct sw_flow_key *key,
const struct nlattr *a, int rem) const struct nlattr *a, int rem)
{ {
struct sw_flow_key *recirc_key;
struct deferred_action *da; struct deferred_action *da;
int level;
if (!is_flow_key_valid(key)) { if (!is_flow_key_valid(key)) {
int err; int err;
...@@ -1115,29 +1132,26 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb, ...@@ -1115,29 +1132,26 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
return 0; return 0;
} }
level = this_cpu_read(exec_actions_level); /* If within the limit of 'OVS_DEFERRED_ACTION_THRESHOLD',
if (level <= OVS_DEFERRED_ACTION_THRESHOLD) { * recirc immediately, otherwise, defer it for later execution.
struct recirc_keys *rks = this_cpu_ptr(recirc_keys); */
struct sw_flow_key *recirc_key = &rks->key[level - 1]; recirc_key = clone_key(key);
if (recirc_key) {
*recirc_key = *key;
recirc_key->recirc_id = nla_get_u32(a); recirc_key->recirc_id = nla_get_u32(a);
ovs_dp_process_packet(skb, recirc_key); ovs_dp_process_packet(skb, recirc_key);
return 0;
}
da = add_deferred_actions(skb, key, NULL, 0);
if (da) {
da->pkt_key.recirc_id = nla_get_u32(a);
} else { } else {
kfree_skb(skb); da = add_deferred_actions(skb, key, NULL, 0);
if (da) {
if (net_ratelimit()) recirc_key = &da->pkt_key;
pr_warn("%s: deferred action limit reached, drop recirc action\n", recirc_key->recirc_id = nla_get_u32(a);
ovs_dp_name(dp)); } else {
/* Log an error in case action fifo is full. */
kfree_skb(skb);
if (net_ratelimit())
pr_warn("%s: deferred action limit reached, drop recirc action\n",
ovs_dp_name(dp));
}
} }
return 0; return 0;
} }
...@@ -1327,8 +1341,8 @@ int action_fifos_init(void) ...@@ -1327,8 +1341,8 @@ int action_fifos_init(void)
if (!action_fifos) if (!action_fifos)
return -ENOMEM; return -ENOMEM;
recirc_keys = alloc_percpu(struct recirc_keys); flow_keys = alloc_percpu(struct action_flow_keys);
if (!recirc_keys) { if (!flow_keys) {
free_percpu(action_fifos); free_percpu(action_fifos);
return -ENOMEM; return -ENOMEM;
} }
...@@ -1339,5 +1353,5 @@ int action_fifos_init(void) ...@@ -1339,5 +1353,5 @@ int action_fifos_init(void)
void action_fifos_exit(void) void action_fifos_exit(void)
{ {
free_percpu(action_fifos); free_percpu(action_fifos);
free_percpu(recirc_keys); free_percpu(flow_keys);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment