All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH 08/17] linux/compat.h: Add wait_event_timeout macro
Date: Thu, 2 Jul 2020 06:08:16 +0200	[thread overview]
Message-ID: <7590866b-59dc-d96a-5780-8581f3a98de8@gmx.de> (raw)
In-Reply-To: <20200701162959.9814-9-vicooodin@gmail.com>

On 7/1/20 6:29 PM, Anastasiia Lukianenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>
> Add  wait_event_timeout - sleep until a condition gets true or a
> timeout elapses.
>
> This is a stripped version of the same from Linux kernel with the
> following u-boot specific modifications:
> - no wait queues supported
> - use u-boot timer to detect timeouts
> - check for Ctrl-C pressed during wait
>
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Signed-off-by: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com>
> ---
>  include/linux/compat.h | 45 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>
> diff --git a/include/linux/compat.h b/include/linux/compat.h
> index 712eeaef4e..5375b7d3b8 100644
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -1,12 +1,20 @@
>  #ifndef _LINUX_COMPAT_H_
>  #define _LINUX_COMPAT_H_
>
> +#include <console.h>
>  #include <log.h>
>  #include <malloc.h>
> +
> +#include <asm/processor.h>
> +
>  #include <linux/types.h>
>  #include <linux/err.h>
>  #include <linux/kernel.h>
>
> +#ifdef CONFIG_XEN
> +#include <xen/events.h>
> +#endif
> +
>  struct unused {};
>  typedef struct unused unused_t;
>
> @@ -122,6 +130,43 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep)
>  #define add_wait_queue(...)	do { } while (0)
>  #define remove_wait_queue(...)	do { } while (0)
>
> +#ifndef CONFIG_XEN
> +#define eventchn_poll()
> +#endif
> +
> +#define __wait_event_timeout(condition, timeout, ret)		\
> +({								\
> +	ulong __ret = ret; /* explicit shadow */		\
> +	ulong start = get_timer(0);				\
> +	for (;;) {						\
> +		eventchn_poll();				\
> +		if (condition) {				\
> +			__ret = 1;				\
> +			break;					\
> +	}							\
> +	if ((get_timer(start) > timeout) || ctrlc()) {		\
> +		__ret = 0;					\
> +		break;						\
> +	}							\
> +	cpu_relax();						\
> +	}							\
> +	__ret;							\
> +})
> +
> +/*
> + * 0 if the @condition evaluated to %false after the @timeout elapsed,
> + * 1 if the @condition evaluated to %true
> + */

Please, document all arguments. Use Sphinx style as in

https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation.

Best regards

Heinrich.

> +#define wait_event_timeout(wq_head, condition, timeout)			\
> +({									\
> +	ulong __ret;							\
> +	if (condition)							\
> +		__ret = 1;						\
> +	else								\
> +		__ret = __wait_event_timeout(condition, timeout, __ret);\
> +	__ret;								\
> +})
> +
>  #define KERNEL_VERSION(a,b,c)	(((a) << 16) + ((b) << 8) + (c))
>
>  /* This is also defined in ARMv8's mmu.h */
>

  reply	other threads:[~2020-07-02  4:08 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 16:29 [PATCH 00/17] Add new board: Xen guest for ARM64 Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 01/17] armv8: Fix SMCC and ARM_PSCI_FW dependencies Anastasiia Lukianenko
2020-07-02  1:14   ` Peng Fan
2020-07-03  9:57     ` Nastya Vicodin
2020-07-01 16:29 ` [PATCH 02/17] Kconfig: Introduce CONFIG_XEN Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-03 12:42     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 03/17] board: Introduce xenguest_arm64 board Anastasiia Lukianenko
2020-07-02  1:28   ` Peng Fan
2020-07-02  7:18     ` Oleksandr Andrushchenko
2020-07-02  7:26       ` Heinrich Schuchardt
2020-07-02  7:57         ` Oleksandr Andrushchenko
2020-07-01 16:29 ` [PATCH 04/17] xen: Add essential and required interface headers Anastasiia Lukianenko
2020-07-02  1:30   ` Peng Fan
2020-07-03 12:46     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 05/17] xen: Port Xen hypervizor related code from mini-os Anastasiia Lukianenko
2020-07-01 17:46   ` Julien Grall
2020-07-03 12:21     ` Anastasiia Lukianenko
2020-07-03 13:38       ` Julien Grall
2020-07-08  8:55         ` Anastasiia Lukianenko
2020-07-16 13:16     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 06/17] xen: Port Xen event channel driver " Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-03 12:34     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 07/17] serial: serial_xen: Add Xen PV serial driver Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-03 12:59     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 08/17] linux/compat.h: Add wait_event_timeout macro Anastasiia Lukianenko
2020-07-02  4:08   ` Heinrich Schuchardt [this message]
2020-07-03 13:02     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 09/17] lib: sscanf: add sscanf implementation Anastasiia Lukianenko
2020-07-02  4:04   ` Heinrich Schuchardt
2020-07-01 16:29 ` [PATCH 10/17] xen: Port Xen bus driver from mini-os Anastasiia Lukianenko
2020-07-02  4:43   ` Heinrich Schuchardt
2020-07-01 16:29 ` [PATCH 11/17] xen: Port Xen grant table " Anastasiia Lukianenko
2020-07-01 16:59   ` Julien Grall
2020-07-03 13:09     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 12/17] xen: pvblock: Add initial support for para-virtualized block driver Anastasiia Lukianenko
2020-07-02  4:17   ` Heinrich Schuchardt
2020-07-03 13:25     ` Anastasiia Lukianenko
2020-07-02  4:29   ` Heinrich Schuchardt
2020-07-02  5:30     ` Peng Fan
2020-07-03 14:14     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 13/17] xen: pvblock: Enumerate virtual block devices Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-01 16:29 ` [PATCH 14/17] xen: pvblock: Read XenStore configuration and initialize Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-06  9:08     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 15/17] xen: pvblock: Implement front-back protocol and do IO Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-06  9:10     ` Anastasiia Lukianenko
2020-07-01 16:29 ` [PATCH 16/17] xen: pvblock: Print found devices indices Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-01 16:29 ` [PATCH 17/17] board: xen: De-initialize before jumping to Linux Anastasiia Lukianenko
2020-07-03  3:50   ` Simon Glass
2020-07-06  9:13     ` Anastasiia Lukianenko
2020-07-01 16:51 ` [PATCH 00/17] Add new board: Xen guest for ARM64 Anastasiia Lukianenko

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=7590866b-59dc-d96a-5780-8581f3a98de8@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.