2024-05-10 23:55:27

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 1/1] spi: Refactor spi_stop_queue()

The refactoring makes code less verbose and easier to read.
Besides that the binary size is also reduced, which sounds
like a win-win case:

add/remove: 0/1 grow/shrink: 2/2 up/down: 210/-226 (-16)
Function old new delta
spi_destroy_queue 42 156 +114
spi_controller_suspend 101 197 +96
spi_unregister_controller 346 319 -27
spi_register_controller 1834 1794 -40
spi_stop_queue 159 - -159
Total: Before=49230, After=49214, chg -0.03%

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/spi/spi.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 289feccca376..ef0027b9cae5 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2207,11 +2207,8 @@ static int spi_start_queue(struct spi_controller *ctlr)

static int spi_stop_queue(struct spi_controller *ctlr)
{
+ unsigned int limit = 500;
unsigned long flags;
- unsigned limit = 500;
- int ret = 0;
-
- spin_lock_irqsave(&ctlr->queue_lock, flags);

/*
* This is a bit lame, but is optimized for the common execution path.
@@ -2219,20 +2216,18 @@ static int spi_stop_queue(struct spi_controller *ctlr)
* execution path (pump_messages) would be required to call wake_up or
* friends on every SPI message. Do this instead.
*/
- while ((!list_empty(&ctlr->queue) || ctlr->busy) && limit--) {
+ do {
+ spin_lock_irqsave(&ctlr->queue_lock, flags);
+ if (list_empty(&ctlr->queue) && !ctlr->busy) {
+ ctlr->running = false;
+ spin_unlock_irqrestore(&ctlr->queue_lock, flags);
+ return 0;
+ }
spin_unlock_irqrestore(&ctlr->queue_lock, flags);
usleep_range(10000, 11000);
- spin_lock_irqsave(&ctlr->queue_lock, flags);
- }
+ } while (--limit);

- if (!list_empty(&ctlr->queue) || ctlr->busy)
- ret = -EBUSY;
- else
- ctlr->running = false;
-
- spin_unlock_irqrestore(&ctlr->queue_lock, flags);
-
- return ret;
+ return -EBUSY;
}

static int spi_destroy_queue(struct spi_controller *ctlr)
--
2.43.0.rc1.1336.g36b5255a03ac



2024-06-05 21:08:24

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] spi: Refactor spi_stop_queue()

On Fri, May 10, 2024 at 11:49:45PM +0300, Andy Shevchenko wrote:
> The refactoring makes code less verbose and easier to read.
> Besides that the binary size is also reduced, which sounds
> like a win-win case:
>
> add/remove: 0/1 grow/shrink: 2/2 up/down: 210/-226 (-16)
> Function old new delta
> spi_destroy_queue 42 156 +114
> spi_controller_suspend 101 197 +96
> spi_unregister_controller 346 319 -27
> spi_register_controller 1834 1794 -40
> spi_stop_queue 159 - -159
> Total: Before=49230, After=49214, chg -0.03%

Hmm... Other more recent patches went through, is this lost in cracks?

--
With Best Regards,
Andy Shevchenko



2024-06-05 21:22:11

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] spi: Refactor spi_stop_queue()

On Thu, Jun 06, 2024 at 12:08:10AM +0300, Andy Shevchenko wrote:
> On Fri, May 10, 2024 at 11:49:45PM +0300, Andy Shevchenko wrote:
> > The refactoring makes code less verbose and easier to read.
> > Besides that the binary size is also reduced, which sounds
> > like a win-win case:
> >
> > add/remove: 0/1 grow/shrink: 2/2 up/down: 210/-226 (-16)
> > Function old new delta
> > spi_destroy_queue 42 156 +114
> > spi_controller_suspend 101 197 +96
> > spi_unregister_controller 346 319 -27
> > spi_register_controller 1834 1794 -40
> > spi_stop_queue 159 - -159
> > Total: Before=49230, After=49214, chg -0.03%
>
> Hmm... Other more recent patches went through, is this lost in cracks?

Please don't send content free pings and please allow a reasonable time
for review. People get busy, go on holiday, attend conferences and so
on so unless there is some reason for urgency (like critical bug fixes)
please allow at least a couple of weeks for review. If there have been
review comments then people may be waiting for those to be addressed.

Sending content free pings adds to the mail volume (if they are seen at
all) which is often the problem and since they can't be reviewed
directly if something has gone wrong you'll have to resend the patches
anyway, so sending again is generally a better approach though there are
some other maintainers who like them - if in doubt look at how patches
for the subsystem are normally handled.


Attachments:
(No filename) (1.59 kB)
signature.asc (499.00 B)
Download all attachments

2024-06-06 12:49:21

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] spi: Refactor spi_stop_queue()

On Wed, Jun 05, 2024 at 10:21:55PM +0100, Mark Brown wrote:
> On Thu, Jun 06, 2024 at 12:08:10AM +0300, Andy Shevchenko wrote:
> > On Fri, May 10, 2024 at 11:49:45PM +0300, Andy Shevchenko wrote:
> > > The refactoring makes code less verbose and easier to read.
> > > Besides that the binary size is also reduced, which sounds
> > > like a win-win case:
> > >
> > > add/remove: 0/1 grow/shrink: 2/2 up/down: 210/-226 (-16)
> > > Function old new delta
> > > spi_destroy_queue 42 156 +114
> > > spi_controller_suspend 101 197 +96
> > > spi_unregister_controller 346 319 -27
> > > spi_register_controller 1834 1794 -40
> > > spi_stop_queue 159 - -159
> > > Total: Before=49230, After=49214, chg -0.03%
> >
> > Hmm... Other more recent patches went through, is this lost in cracks?

Found this, it is an announce that is missing.
Thanks!

--
With Best Regards,
Andy Shevchenko