Skip to contentSkip to conversation

backwards busy wait using "time_before()"??

DISCUSSION Robert P. J. Day 2 participants 3 messages Dec 31, 2009 – Jan 1, 2010

lore
Share & tools
lore
#0 lore raw

if this is an idiotic question, i'll blame it on the fact that
there's only decaf left in the house.

from drivers/spi/spi_stmp.c:

   #define busy_wait(cond)                                              \
        ({                                                              \
        unsigned long end_jiffies = jiffies + STMP_SPI_TIMEOUT;         \
        bool succeeded = false;                                         \
        do {                                                            \
                if (cond) {                                             \
                        succeeded = true;                               \
                        break;                                          \
                }                                                       \
                cpu_relax();                                            \
        } while (time_before(end_jiffies, jiffies));                    \
        succeeded;                                                      \
        })

is it just me, or do those arguments to time_before() look
backwards?

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday

========================================================================

#1 lore raw
Quoted 21 lines · Robert P. J. Day

if this is an idiotic question, i'll blame it on the fact that
there's only decaf left in the house.

from drivers/spi/spi_stmp.c:

   #define busy_wait(cond)                                              \
        ({                                                              \
        unsigned long end_jiffies = jiffies + STMP_SPI_TIMEOUT;         \
        bool succeeded = false;                                         \
        do {                                                            \
                if (cond) {                                             \
                        succeeded = true;                               \
                        break;                                          \
                }                                                       \
                cpu_relax();                                            \
        } while (time_before(end_jiffies, jiffies));                    \
        succeeded;                                                      \
        })
Quoted 2 lines

is it just me, or do those arguments to time_before() look
backwards?

with a quick grep, i found one other example that looks reversed.
from drivers/char/hvsi.c:

static void hvsi_drain_input(struct hvsi_struct *hp)

{
        uint8_t buf[HVSI_MAX_READ] __ALIGNED__;
        unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;

        while (time_before(end_jiffies, jiffies))
                if (0 == hvsi_read(hp, buf, HVSI_MAX_READ))
                        break;
}

surely that's backwards as well, no?

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday

========================================================================

#2 lore raw
In reply to Robert P. J. Day
Quoted 8 lines · Robert P. J. Day
                cpu_relax();                                            \
        } while (time_before(end_jiffies, jiffies));                    \
        succeeded;                                                      \
        })

is it just me, or do those arguments to time_before() look
backwards?

Yes it looks backwards. The timeout path probably has been never tested.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.