On Tue, May 07, 2024 at 04:48:04PM +0200, Bartosz Golaszewski wrote: > On Tue, May 7, 2024 at 4:24 PM Paul E. McKenney <paulmck@xxxxxxxxxx> wrote: > > > > On Tue, May 07, 2024 at 02:13:46PM +0200, Bartosz Golaszewski wrote: > > > From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> > > > > > > Commit 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU") > > > caused a massive drop in performance of requesting GPIO lines due to the > > > call to synchronize_srcu() on each label change. Rework the code to not > > > wait until all read-only users are done with reading the label but > > > instead atomically replace the label pointer and schedule its release > > > after all read-only critical sections are done. > > > > > > To that end wrap the descriptor label in a struct that also contains the > > > rcu_head struct required for deferring tasks using call_srcu() and stop > > > using kstrdup_const() as we're required to allocate memory anyway. Just > > > allocate enough for the label string and rcu_head in one go. > > > > > > Reported-by: Neil Armstrong <neil.armstrong@xxxxxxxxxx> > > > Closes: https://lore.kernel.org/linux-gpio/CAMRc=Mfig2oooDQYTqo23W3PXSdzhVO4p=G4+P8y1ppBOrkrJQ@xxxxxxxxxxxxxx/ > > > Fixes: 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU") > > > Suggested-by: Paul E. McKenney <paulmck@xxxxxxxxxx> > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> > > > > Looks good to me! > > > > Acked-by: Paul E. McKenney <paulmck@xxxxxxxxxx> > > > > One semi-related question... Why the per-descriptor srcu_struct? > > > > If the srcu_struct was shared among all of these, you could just do one > > synchronize_srcu() and one cleanup_srcu_struct() instead of needing to > > do one per gdev->desc[] entry. > > > > You might be able to go further and have one srcu_struct for all the > > gpio devices. > > > > Or did you guys run tests and find some performance problem with sharing > > srcu_struct structures? (I wouldn't expect one, but sometimes the > > hardware has a better imagination than I do.) > > > > I guess my goal was not to make synchronize_srcu() for descriptor X > wait for read-only operations on descriptor Y. But with that gone, I > suppose you're right, we can improve this patch further by switching > to a single SRCU descriptor. > > I'll send a v2. My guess is that a separate patch for each of the two changes would be best, but I must defer to you guys on that. Thanx, Paul