b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Remi Pommarel <repk@triplefau.lt>
To: Sven Eckelmann <sven@narfation.org>
Cc: b.a.t.m.a.n@lists.open-mesh.org,
	Marek Lindner <mareklindner@neomailbox.ch>,
	Simon Wunderlich <sw@simonwunderlich.de>,
	Antonio Quartulli <a@unstable.cc>
Subject: Re: [PATCH v3 4/5] batman-adv: Remove atomic usage for tt.local_changes
Date: Thu, 21 Nov 2024 10:28:06 +0100	[thread overview]
Message-ID: <Zz79Jqaf3ee4ZxMT@pilgrim> (raw)
In-Reply-To: <9417646.rMLUfLXkoz@ripper>

On Thu, Nov 21, 2024 at 10:04:15AM +0100, Sven Eckelmann wrote:
> On Wednesday, 20 November 2024 18:47:17 CET Remi Pommarel wrote:
> > 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.
> 
> The overall change assumes that the compiler never splits writes (store 
> tearing) [1]. Of course, writes are protected against each other using locks. 
> But the reader is no longer protected from partial writes. I haven't checked 
> whether store fusing might be a problem.
> 
> Kind regards,
> 	Sven
> 
> [1] https://www.kernel.org/doc/html/latest/core-api/wrappers/memory-barriers.html

Good catch thanks.

> 
> [...]
> > @@ -783,13 +783,13 @@ static int batadv_softif_init_late(struct net_device *dev)
> >  	atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
> >  	atomic_set(&bat_priv->bcast_seqno, 1);
> >  	atomic_set(&bat_priv->tt.vn, 0);
> > -	atomic_set(&bat_priv->tt.local_changes, 0);
> >  	atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
> >  #ifdef CONFIG_BATMAN_ADV_BLA
> >  	atomic_set(&bat_priv->bla.num_requests, 0);
> >  #endif
> >  	atomic_set(&bat_priv->tp_num, 0);
> >  
> > +	bat_priv->tt.local_changes = 0;
> 
> Would need WRITE_ONCE (just to be consistent)
> 
> [...]
> > @@ -508,21 +507,17 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,
> >  del:
> >  		list_del(&entry->list);
> >  		kmem_cache_free(batadv_tt_change_cache, entry);
> > +		bat_priv->tt.local_changes--;
> >  		kmem_cache_free(batadv_tt_change_cache, tt_change_node);
> > -		event_removed = true;
> >  		goto unlock;
> >  	}
> >  
> >  	/* track the change in the OGMinterval list */
> >  	list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
> > +	bat_priv->tt.local_changes++;
> 
> Needs more complex constructs with WRITE_ONCE or 
> __sync_add_and_fetch/__sync_sub_and_fetch (which were handled before inside 
> atomic_inc). The latter are not used that often in the kernel, so I wouldn't
> want to introduce them in the batman-adv module.

What about using something in the line:
	WRITE_ONCE(&bat_priv->tt.local_changes,
		   READ_ONCE(&bat_priv->tt.local_changes) + 1);

> 
> > @@ -1022,7 +1017,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
> >  	tt_data->flags = BATADV_TT_OGM_DIFF;
> >  
> >  	spin_lock_bh(&bat_priv->tt.changes_list_lock);
> > -	atomic_set(&bat_priv->tt.local_changes, 0);
> > +	bat_priv->tt.local_changes = 0;
> >  
> >  	list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
> >  				 list) {
> 
> Would need WRITE_ONCE
> 
> > @@ -1438,7 +1433,7 @@ static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
> >  		kmem_cache_free(batadv_tt_change_cache, entry);
> >  	}
> >  
> > -	atomic_set(&bat_priv->tt.local_changes, 0);
> > +	bat_priv->tt.local_changes = 0;
> >  	spin_unlock_bh(&bat_priv->tt.changes_list_lock);
> >  }
> 
> Would need WRITE_ONCE 

Yes.

Thanks for the review.

-- 
Remi

  reply	other threads:[~2024-11-21  9:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 17:47 [PATCH v3 0/5] batman-adv: TT change events fixes and improvements Remi Pommarel
2024-11-20 17:47 ` [PATCH v3 1/5] batman-adv: Do not send uninitialized TT changes Remi Pommarel
2024-11-21 13:05   ` Antonio Quartulli
2024-11-21 13:56     ` Remi Pommarel
2024-11-21 15:07       ` Remi Pommarel
2024-11-21 18:02         ` Sven Eckelmann
2024-11-21 20:24           ` Remi Pommarel
2024-11-21 21:07             ` Antonio Quartulli
2024-11-22  8:16             ` Sven Eckelmann
2024-11-20 17:47 ` [PATCH v3 2/5] batman-adv: Remove uninitialized data in full table TT response Remi Pommarel
2024-11-21 13:14   ` Antonio Quartulli
2024-11-21 18:20     ` Sven Eckelmann
2024-11-21 20:55       ` Antonio Quartulli
2024-11-20 17:47 ` [PATCH v3 3/5] batman-adv: Do not let TT changes list grows indefinitely Remi Pommarel
2024-11-21 13:50   ` Antonio Quartulli
2024-11-21 14:18     ` Remi Pommarel
2024-11-20 17:47 ` [PATCH v3 4/5] batman-adv: Remove atomic usage for tt.local_changes Remi Pommarel
2024-11-21  9:04   ` Sven Eckelmann
2024-11-21  9:28     ` Remi Pommarel [this message]
2024-11-21  9:34       ` Sven Eckelmann
2024-11-20 17:47 ` [PATCH v3 5/5] batman-adv: Don't keep redundant TT change events Remi Pommarel
2024-11-21  8:43   ` Sven Eckelmann
2024-11-21  9:13     ` Remi Pommarel
2024-11-21  9:23       ` Sven Eckelmann
2024-11-21  9:30         ` Sven Eckelmann
2024-11-21  9:35           ` Remi Pommarel
2024-11-20 19:46 ` [PATCH v3 0/5] batman-adv: TT change events fixes and improvements Sven Eckelmann
2024-11-20 19:54   ` Remi Pommarel
2024-11-20 20:29     ` Antonio Quartulli
2024-11-20 21:04     ` Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zz79Jqaf3ee4ZxMT@pilgrim \
    --to=repk@triplefau.lt \
    --cc=a@unstable.cc \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=mareklindner@neomailbox.ch \
    --cc=sven@narfation.org \
    --cc=sw@simonwunderlich.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).