Skip to content

Commit 8587e0e

Browse files
repksimonwunderlich
authored andcommitted
batman-adv: Remove atomic usage for tt.local_changes
The tt.local_changes atomic is either written with tt.changes_list_lock or close to it (see batadv_tt_local_event()). Thus the performance gain using an atomic was limited (or because of atomic_read() impact even negative). Using atomic also comes with the need to be wary of potential negative tt.local_changes value. Simplify the tt.local_changes usage by removing the atomic property and modifying it only with tt.changes_list_lock held. Signed-off-by: Remi Pommarel <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent a7d5100 commit 8587e0e

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

net/batman-adv/soft-interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,13 @@ static int batadv_softif_init_late(struct net_device *dev)
783783
atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
784784
atomic_set(&bat_priv->bcast_seqno, 1);
785785
atomic_set(&bat_priv->tt.vn, 0);
786-
atomic_set(&bat_priv->tt.local_changes, 0);
787786
atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
788787
#ifdef CONFIG_BATMAN_ADV_BLA
789788
atomic_set(&bat_priv->bla.num_requests, 0);
790789
#endif
791790
atomic_set(&bat_priv->tp_num, 0);
792791

792+
WRITE_ONCE(bat_priv->tt.local_changes, 0);
793793
bat_priv->tt.last_changeset = NULL;
794794
bat_priv->tt.last_changeset_len = 0;
795795
bat_priv->isolation_mark = 0;

net/batman-adv/translation-table.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,
423423
struct batadv_tt_change_node *tt_change_node, *entry, *safe;
424424
struct batadv_tt_common_entry *common = &tt_local_entry->common;
425425
u8 flags = common->flags | event_flags;
426-
bool event_removed = false;
427426
bool del_op_requested, del_op_entry;
427+
size_t changes;
428428

429429
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
430430
if (!tt_change_node)
@@ -440,6 +440,7 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,
440440

441441
/* check for ADD+DEL or DEL+ADD events */
442442
spin_lock_bh(&bat_priv->tt.changes_list_lock);
443+
changes = READ_ONCE(bat_priv->tt.local_changes);
443444
list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
444445
list) {
445446
if (!batadv_compare_eth(entry->change.addr, common->addr))
@@ -468,21 +469,18 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,
468469
del:
469470
list_del(&entry->list);
470471
kmem_cache_free(batadv_tt_change_cache, entry);
472+
changes--;
471473
kmem_cache_free(batadv_tt_change_cache, tt_change_node);
472-
event_removed = true;
473-
goto unlock;
474+
goto update_changes;
474475
}
475476

476477
/* track the change in the OGMinterval list */
477478
list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
479+
changes++;
478480

479-
unlock:
481+
update_changes:
482+
WRITE_ONCE(bat_priv->tt.local_changes, changes);
480483
spin_unlock_bh(&bat_priv->tt.changes_list_lock);
481-
482-
if (event_removed)
483-
atomic_dec(&bat_priv->tt.local_changes);
484-
else
485-
atomic_inc(&bat_priv->tt.local_changes);
486484
}
487485

488486
/**
@@ -950,7 +948,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
950948
int tt_diff_entries_count = 0;
951949
u16 tvlv_len;
952950

953-
tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes);
951+
tt_diff_entries_num = READ_ONCE(bat_priv->tt.local_changes);
954952
tt_diff_len = batadv_tt_len(tt_diff_entries_num);
955953

956954
/* if we have too many changes for one packet don't send any
@@ -970,7 +968,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
970968
goto container_register;
971969

972970
spin_lock_bh(&bat_priv->tt.changes_list_lock);
973-
atomic_set(&bat_priv->tt.local_changes, 0);
971+
WRITE_ONCE(bat_priv->tt.local_changes, 0);
974972

975973
list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
976974
list) {
@@ -1380,7 +1378,7 @@ static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
13801378
kmem_cache_free(batadv_tt_change_cache, entry);
13811379
}
13821380

1383-
atomic_set(&bat_priv->tt.local_changes, 0);
1381+
WRITE_ONCE(bat_priv->tt.local_changes, 0);
13841382
spin_unlock_bh(&bat_priv->tt.changes_list_lock);
13851383
}
13861384

@@ -3634,7 +3632,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)
36343632
{
36353633
lockdep_assert_held(&bat_priv->tt.commit_lock);
36363634

3637-
if (atomic_read(&bat_priv->tt.local_changes) < 1) {
3635+
if (READ_ONCE(bat_priv->tt.local_changes) == 0) {
36383636
if (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt))
36393637
batadv_tt_tvlv_container_update(bat_priv);
36403638
return;

net/batman-adv/types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ struct batadv_priv_tt {
10221022
atomic_t ogm_append_cnt;
10231023

10241024
/** @local_changes: changes registered in an originator interval */
1025-
atomic_t local_changes;
1025+
size_t local_changes;
10261026

10271027
/**
10281028
* @changes_list: tracks tt local changes within an originator interval
@@ -1044,7 +1044,7 @@ struct batadv_priv_tt {
10441044
*/
10451045
struct list_head roam_list;
10461046

1047-
/** @changes_list_lock: lock protecting changes_list */
1047+
/** @changes_list_lock: lock protecting changes_list & local_changes */
10481048
spinlock_t changes_list_lock;
10491049

10501050
/** @req_list_lock: lock protecting req_list */

0 commit comments

Comments
 (0)