From: Anastasiia Lukianenko <vicooodin@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 08/18] linux/compat.h: Add wait_event_timeout macro
Date: Mon, 20 Jul 2020 14:02:14 +0300 [thread overview]
Message-ID: <20200720110224.28851-9-vicooodin@gmail.com> (raw)
In-Reply-To: <20200720110224.28851-1-vicooodin@gmail.com>
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 | 54 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 712eeaef4e..363b2b9425 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,52 @@ 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; \
+})
+
+/**
+ * wait_event_timeout() - Wait until the event occurs before the timeout.
+ * @wr_head: The wait queue to wait on.
+ * @condition: Expression for the event to wait for.
+ * @timeout: Maximum waiting time.
+ *
+ * We wait until the @condition evaluates to %true (succeed) or
+ * %false (@timeout elapsed).
+ *
+ * Return:
+ * 0 - if the @condition evaluated to %false after the @timeout elapsed
+ * 1 - if the @condition evaluated to %true
+ */
+#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 */
--
2.17.1
next prev parent reply other threads:[~2020-07-20 11:02 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-20 11:02 [PATCH v2 00/18] Add new board: Xen guest for ARM64 Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 01/18] Add MIT License Anastasiia Lukianenko
2020-07-28 18:58 ` Simon Glass
2020-07-29 8:32 ` Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 02/18] Kconfig: Introduce CONFIG_XEN Anastasiia Lukianenko
2020-07-28 18:58 ` Simon Glass
2020-07-29 8:42 ` Anastasiia Lukianenko
2020-07-29 13:03 ` Simon Glass
2020-08-07 9:22 ` Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 03/18] xen: Add essential and required interface headers Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 04/18] board: Introduce xenguest_arm64 board Anastasiia Lukianenko
2020-07-31 5:00 ` AKASHI Takahiro
2020-08-03 9:07 ` Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 05/18] xen: Port Xen hypervizor related code from mini-os Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 06/18] xen: Port Xen event channel driver " Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 07/18] serial: serial_xen: Add Xen PV serial driver Anastasiia Lukianenko
2020-07-20 11:02 ` Anastasiia Lukianenko [this message]
2020-07-20 11:02 ` [PATCH v2 09/18] lib: sscanf: add sscanf implementation Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 10/18] xen: Port Xen bus driver from mini-os Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 11/18] xen: Port Xen grant table " Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 12/18] xen: pvblock: Add initial support for para-virtualized block driver Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 13/18] xen: pvblock: Enumerate virtual block devices Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 14/18] xen: pvblock: Read XenStore configuration and initialize Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 15/18] xen: pvblock: Implement front-back protocol and do IO Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 16/18] xen: pvblock: Print found devices indices Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 17/18] board: xen: De-initialize before jumping to Linux Anastasiia Lukianenko
2020-07-20 11:02 ` [PATCH v2 18/18] doc: xen: Add Xen guest ARM64 board documentation Anastasiia Lukianenko
2020-07-30 19:25 ` [PATCH v2 00/18] Add new board: Xen guest for ARM64 Julien Grall
2020-08-01 10:14 ` 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=20200720110224.28851-9-vicooodin@gmail.com \
--to=vicooodin@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox