Skip to content

Commit c7784b1

Browse files
Maor GottliebSaeed Mahameed
authored andcommitted
net/mlx5: Replace fs_node mutex with reader/writer semaphore
Currently, steering object is protected by mutex lock, replace the mutex lock with reader/writer semaphore . In this patch we still use only write semaphore. In downstream patches we will switch part of the write locks to read locks. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 19f100f commit c7784b1

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ static struct init_tree_node {
145145
}
146146
};
147147

148-
enum fs_i_mutex_lock_class {
149-
FS_MUTEX_GRANDPARENT,
150-
FS_MUTEX_PARENT,
151-
FS_MUTEX_CHILD
148+
enum fs_i_lock_class {
149+
FS_LOCK_GRANDPARENT,
150+
FS_LOCK_PARENT,
151+
FS_LOCK_CHILD
152152
};
153153

154154
static const struct rhashtable_params rhash_fte = {
@@ -184,7 +184,7 @@ static void tree_init_node(struct fs_node *node,
184184
atomic_set(&node->refcount, 1);
185185
INIT_LIST_HEAD(&node->list);
186186
INIT_LIST_HEAD(&node->children);
187-
mutex_init(&node->lock);
187+
init_rwsem(&node->lock);
188188
node->remove_func = remove_func;
189189
node->active = false;
190190
}
@@ -208,18 +208,18 @@ static void tree_get_node(struct fs_node *node)
208208
}
209209

210210
static void nested_lock_ref_node(struct fs_node *node,
211-
enum fs_i_mutex_lock_class class)
211+
enum fs_i_lock_class class)
212212
{
213213
if (node) {
214-
mutex_lock_nested(&node->lock, class);
214+
down_write_nested(&node->lock, class);
215215
atomic_inc(&node->refcount);
216216
}
217217
}
218218

219219
static void lock_ref_node(struct fs_node *node)
220220
{
221221
if (node) {
222-
mutex_lock(&node->lock);
222+
down_write(&node->lock);
223223
atomic_inc(&node->refcount);
224224
}
225225
}
@@ -228,7 +228,7 @@ static void unlock_ref_node(struct fs_node *node)
228228
{
229229
if (node) {
230230
atomic_dec(&node->refcount);
231-
mutex_unlock(&node->lock);
231+
up_write(&node->lock);
232232
}
233233
}
234234

@@ -1376,7 +1376,7 @@ static struct mlx5_flow_handle *add_rule_fg(struct mlx5_flow_group *fg,
13761376
int old_action;
13771377
int ret;
13781378

1379-
nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD);
1379+
nested_lock_ref_node(&fte->node, FS_LOCK_CHILD);
13801380
ret = check_conflicting_ftes(fte, flow_act);
13811381
if (ret) {
13821382
handle = ERR_PTR(ret);
@@ -1400,7 +1400,7 @@ static struct mlx5_flow_handle *add_rule_fg(struct mlx5_flow_group *fg,
14001400
fte = alloc_insert_fte(fg, match_value, flow_act);
14011401
if (IS_ERR(fte))
14021402
return (void *)fte;
1403-
nested_lock_ref_node(&fte->node, FS_MUTEX_CHILD);
1403+
nested_lock_ref_node(&fte->node, FS_LOCK_CHILD);
14041404
handle = add_rule_fte(fte, fg, dest, dest_num, false);
14051405
if (IS_ERR(handle)) {
14061406
unlock_ref_node(&fte->node);
@@ -1548,7 +1548,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15481548
struct fs_fte *fte;
15491549

15501550
g = iter->g;
1551-
nested_lock_ref_node(&g->node, FS_MUTEX_PARENT);
1551+
nested_lock_ref_node(&g->node, FS_LOCK_PARENT);
15521552
fte = rhashtable_lookup_fast(&g->ftes_hash, spec->match_value,
15531553
rhash_fte);
15541554
if (fte) {
@@ -1566,7 +1566,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15661566
list_for_each_entry(iter, &match_head.list, list) {
15671567
g = iter->g;
15681568

1569-
nested_lock_ref_node(&g->node, FS_MUTEX_PARENT);
1569+
nested_lock_ref_node(&g->node, FS_LOCK_PARENT);
15701570
rule = add_rule_fg(g, spec->match_value,
15711571
flow_act, dest, dest_num, NULL);
15721572
if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOSPC) {
@@ -1605,7 +1605,7 @@ _mlx5_add_flow_rules(struct mlx5_flow_table *ft,
16051605
return ERR_PTR(-EINVAL);
16061606
}
16071607

1608-
nested_lock_ref_node(&ft->node, FS_MUTEX_GRANDPARENT);
1608+
nested_lock_ref_node(&ft->node, FS_LOCK_GRANDPARENT);
16091609
rule = try_add_to_existing_fg(ft, spec, flow_act, dest, dest_num);
16101610
if (!IS_ERR(rule) || PTR_ERR(rule) != -ENOENT)
16111611
goto unlock;

drivers/net/ethernet/mellanox/mlx5/core/fs_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct fs_node {
8080
struct fs_node *parent;
8181
struct fs_node *root;
8282
/* lock the node for writing and traversing */
83-
struct mutex lock;
83+
struct rw_semaphore lock;
8484
atomic_t refcount;
8585
bool active;
8686
void (*remove_func)(struct fs_node *);

0 commit comments

Comments
 (0)