Re: [PATCH v5 32/54] common/clock: Move delay and timeout functions to lib/

2018-06-13 Thread Andrey Smirnov
On Wed, Jun 13, 2018 at 1:19 AM Sascha Hauer  wrote:
>
> On Tue, Jun 12, 2018 at 01:52:48PM -0700, Andrey Smirnov wrote:
> > Move delay and timeout functions to lib/ in order to share them with
> > PBL. Currently only the most trivial implementation of get_time_ns()
> > usefull to implement never-expiring timeouts is provided. More work is
> > needed to allow board specific overrides.
> >
> > Signed-off-by: Andrey Smirnov 
> > ---
> >  common/clock.c | 52 
> >  lib/Makefile   |  1 +
> >  lib/clock.c| 72 ++
> >  3 files changed, 73 insertions(+), 52 deletions(-)
> >  create mode 100644 lib/clock.c
> >
> > +#if defined(__PBL__)
> > +/*
> > + * Poller infrastructure is not available in PBL, so we just define
> > + * is_timeout to be a synonym for is_timeout_non_interruptible
> > + */
> > +int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
> > + __alias(is_timeout_non_interruptible);
> > +#else
> > +#include 
> > +
> > +int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
> > +{
> > +
> > + if (time_offset_ns >= 100 * USECOND)
> > + poller_call();
> > +
> > + return is_timeout_non_interruptible(start_ns, time_offset_ns);
> > +}
> > +#endif
> > +EXPORT_SYMBOL(is_timeout);
> > +
> > +void ndelay(unsigned long nsecs)
> > +{
> > + uint64_t start = get_time_ns();
> > +
> > + while(!is_timeout_non_interruptible(start, nsecs));
> > +}
> > +EXPORT_SYMBOL(ndelay);
> > +
> > +void udelay(unsigned long usecs)
> > +{
> > + uint64_t start = get_time_ns();
> > +
> > + while(!is_timeout(start, usecs * USECOND));
> > +}
> > +EXPORT_SYMBOL(udelay);
> > +
> > +void mdelay(unsigned long msecs)
> > +{
> > + uint64_t start = get_time_ns();
> > +
> > + while(!is_timeout(start, msecs * MSECOND));
> > +}
> > +EXPORT_SYMBOL(mdelay);
> > +
> > +void mdelay_non_interruptible(unsigned long msecs)
> > +{
> > + uint64_t start = get_time_ns();
> > +
> > + while (!is_timeout_non_interruptible(start, msecs * MSECOND))
> > + ;
> > +}
> > +EXPORT_SYMBOL(mdelay_non_interruptible);
> > +
> > +__weak uint64_t get_time_ns(void)
> > +{
> > + return 0;
> > +}
>
> So in PBL we now have [num]delay functions which will lockup the system
> forever when called. This is not good.
>
> Given that you only need is_timeout() to implement the iopoll.h functions
> and this patch is only a complicated way to shortcircuit the timeout, I
> think it would be better to just put a #ifndef __PBL__ around the call
> to is_timeout() in readx_poll_timeout(). This would at least make it
> clearer to the reader that there actually is no timeout in the PBL
> case.
>

OK, sure, will do in v6.

Thanks,
Andrey Smirnov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v5 32/54] common/clock: Move delay and timeout functions to lib/

2018-06-13 Thread Sascha Hauer
On Tue, Jun 12, 2018 at 01:52:48PM -0700, Andrey Smirnov wrote:
> Move delay and timeout functions to lib/ in order to share them with
> PBL. Currently only the most trivial implementation of get_time_ns()
> usefull to implement never-expiring timeouts is provided. More work is
> needed to allow board specific overrides.
> 
> Signed-off-by: Andrey Smirnov 
> ---
>  common/clock.c | 52 
>  lib/Makefile   |  1 +
>  lib/clock.c| 72 ++
>  3 files changed, 73 insertions(+), 52 deletions(-)
>  create mode 100644 lib/clock.c
> 
> +#if defined(__PBL__)
> +/*
> + * Poller infrastructure is not available in PBL, so we just define
> + * is_timeout to be a synonym for is_timeout_non_interruptible
> + */
> +int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
> + __alias(is_timeout_non_interruptible);
> +#else
> +#include 
> +
> +int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
> +{
> +
> + if (time_offset_ns >= 100 * USECOND)
> + poller_call();
> +
> + return is_timeout_non_interruptible(start_ns, time_offset_ns);
> +}
> +#endif
> +EXPORT_SYMBOL(is_timeout);
> +
> +void ndelay(unsigned long nsecs)
> +{
> + uint64_t start = get_time_ns();
> +
> + while(!is_timeout_non_interruptible(start, nsecs));
> +}
> +EXPORT_SYMBOL(ndelay);
> +
> +void udelay(unsigned long usecs)
> +{
> + uint64_t start = get_time_ns();
> +
> + while(!is_timeout(start, usecs * USECOND));
> +}
> +EXPORT_SYMBOL(udelay);
> +
> +void mdelay(unsigned long msecs)
> +{
> + uint64_t start = get_time_ns();
> +
> + while(!is_timeout(start, msecs * MSECOND));
> +}
> +EXPORT_SYMBOL(mdelay);
> +
> +void mdelay_non_interruptible(unsigned long msecs)
> +{
> + uint64_t start = get_time_ns();
> +
> + while (!is_timeout_non_interruptible(start, msecs * MSECOND))
> + ;
> +}
> +EXPORT_SYMBOL(mdelay_non_interruptible);
> +
> +__weak uint64_t get_time_ns(void)
> +{
> + return 0;
> +}

So in PBL we now have [num]delay functions which will lockup the system
forever when called. This is not good.

Given that you only need is_timeout() to implement the iopoll.h functions
and this patch is only a complicated way to shortcircuit the timeout, I
think it would be better to just put a #ifndef __PBL__ around the call
to is_timeout() in readx_poll_timeout(). This would at least make it
clearer to the reader that there actually is no timeout in the PBL
case.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v5 32/54] common/clock: Move delay and timeout functions to lib/

2018-06-12 Thread Andrey Smirnov
Move delay and timeout functions to lib/ in order to share them with
PBL. Currently only the most trivial implementation of get_time_ns()
usefull to implement never-expiring timeouts is provided. More work is
needed to allow board specific overrides.

Signed-off-by: Andrey Smirnov 
---
 common/clock.c | 52 
 lib/Makefile   |  1 +
 lib/clock.c| 72 ++
 3 files changed, 73 insertions(+), 52 deletions(-)
 create mode 100644 lib/clock.c

diff --git a/common/clock.c b/common/clock.c
index f98176dd5..c356a88b5 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -25,7 +25,6 @@
 #include 
 #include 
 #include 
-#include 
 
 static uint64_t time_ns;
 
@@ -170,57 +169,6 @@ uint32_t clocksource_hz2mult(uint32_t hz, uint32_t 
shift_constant)
return (uint32_t)tmp;
 }
 
-int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns)
-{
-   if ((int64_t)(start_ns + time_offset_ns - get_time_ns()) < 0)
-   return 1;
-   else
-   return 0;
-}
-EXPORT_SYMBOL(is_timeout_non_interruptible);
-
-int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
-{
-   if (time_offset_ns >= 100 * USECOND)
-   poller_call();
-
-   return is_timeout_non_interruptible(start_ns, time_offset_ns);
-}
-EXPORT_SYMBOL(is_timeout);
-
-void ndelay(unsigned long nsecs)
-{
-   uint64_t start = get_time_ns();
-
-   while(!is_timeout_non_interruptible(start, nsecs));
-}
-EXPORT_SYMBOL(ndelay);
-
-void udelay(unsigned long usecs)
-{
-   uint64_t start = get_time_ns();
-
-   while(!is_timeout(start, usecs * USECOND));
-}
-EXPORT_SYMBOL(udelay);
-
-void mdelay(unsigned long msecs)
-{
-   uint64_t start = get_time_ns();
-
-   while(!is_timeout(start, msecs * MSECOND));
-}
-EXPORT_SYMBOL(mdelay);
-
-void mdelay_non_interruptible(unsigned long msecs)
-{
-   uint64_t start = get_time_ns();
-
-   while (!is_timeout_non_interruptible(start, msecs * MSECOND))
-   ;
-}
-EXPORT_SYMBOL(mdelay_non_interruptible);
-
 int init_clock(struct clocksource *cs)
 {
if (current_clock && cs->priority <= current_clock->priority)
diff --git a/lib/Makefile b/lib/Makefile
index a7498288a..09c250a1c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -65,3 +65,4 @@ obj-y += int_sqrt.o
 obj-y  += parseopt.o
 obj-y  += clz_ctz.o
 obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
+obj-pbl-y  += clock.o
\ No newline at end of file
diff --git a/lib/clock.c b/lib/clock.c
new file mode 100644
index 0..b7cc49fa6
--- /dev/null
+++ b/lib/clock.c
@@ -0,0 +1,72 @@
+#include 
+#include 
+#include 
+
+int is_timeout_non_interruptible(uint64_t start_ns, uint64_t time_offset_ns)
+{
+   if ((int64_t)(start_ns + time_offset_ns - get_time_ns()) < 0)
+   return 1;
+   else
+   return 0;
+}
+EXPORT_SYMBOL(is_timeout_non_interruptible);
+
+#if defined(__PBL__)
+/*
+ * Poller infrastructure is not available in PBL, so we just define
+ * is_timeout to be a synonym for is_timeout_non_interruptible
+ */
+int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
+   __alias(is_timeout_non_interruptible);
+#else
+#include 
+
+int is_timeout(uint64_t start_ns, uint64_t time_offset_ns)
+{
+
+   if (time_offset_ns >= 100 * USECOND)
+   poller_call();
+
+   return is_timeout_non_interruptible(start_ns, time_offset_ns);
+}
+#endif
+EXPORT_SYMBOL(is_timeout);
+
+void ndelay(unsigned long nsecs)
+{
+   uint64_t start = get_time_ns();
+
+   while(!is_timeout_non_interruptible(start, nsecs));
+}
+EXPORT_SYMBOL(ndelay);
+
+void udelay(unsigned long usecs)
+{
+   uint64_t start = get_time_ns();
+
+   while(!is_timeout(start, usecs * USECOND));
+}
+EXPORT_SYMBOL(udelay);
+
+void mdelay(unsigned long msecs)
+{
+   uint64_t start = get_time_ns();
+
+   while(!is_timeout(start, msecs * MSECOND));
+}
+EXPORT_SYMBOL(mdelay);
+
+void mdelay_non_interruptible(unsigned long msecs)
+{
+   uint64_t start = get_time_ns();
+
+   while (!is_timeout_non_interruptible(start, msecs * MSECOND))
+   ;
+}
+EXPORT_SYMBOL(mdelay_non_interruptible);
+
+__weak uint64_t get_time_ns(void)
+{
+   return 0;
+}
+EXPORT_SYMBOL(get_time_ns);
\ No newline at end of file
-- 
2.17.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox