[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/7] timer: move general utility functions together
From: |
Xuebing Wang |
Subject: |
[Qemu-devel] [PULL 6/7] timer: move general utility functions together |
Date: |
Mon, 3 Mar 2014 09:43:39 +0800 |
Signed-off-by: Xuebing Wang <address@hidden>
Reviewed-By: Alex Bligh <address@hidden>
---
qemu-timer.c | 97 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 50 insertions(+), 47 deletions(-)
diff --git a/qemu-timer.c b/qemu-timer.c
index c9801da..e592c14 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -501,53 +501,6 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg)
return deadline;
}
-/* Transition function to convert a nanosecond timeout to ms
- * This is used where a system does not support ppoll
- */
-int qemu_timeout_ns_to_ms(int64_t ns)
-{
- int64_t ms;
- if (ns < 0) {
- return -1;
- }
-
- if (!ns) {
- return 0;
- }
-
- /* Always round up, because it's better to wait too long than to wait too
- * little and effectively busy-wait
- */
- ms = (ns + SCALE_MS - 1) / SCALE_MS;
-
- /* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */
- if (ms > (int64_t) INT32_MAX) {
- ms = INT32_MAX;
- }
-
- return (int) ms;
-}
-
-
-/* qemu implementation of g_poll which uses a nanosecond timeout but is
- * otherwise identical to g_poll
- */
-int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout)
-{
-#ifdef CONFIG_PPOLL
- if (timeout < 0) {
- return ppoll((struct pollfd *)fds, nfds, NULL, NULL);
- } else {
- struct timespec ts;
- ts.tv_sec = timeout / 1000000000LL;
- ts.tv_nsec = timeout % 1000000000LL;
- return ppoll((struct pollfd *)fds, nfds, &ts, NULL);
- }
-#else
- return g_poll(fds, nfds, qemu_timeout_ns_to_ms(timeout));
-#endif
-}
-
/*
* QEMUTimer
*/
@@ -683,6 +636,56 @@ uint64_t timer_expire_time_ns(QEMUTimer *ts)
return timer_pending(ts) ? ts->expire_time : -1;
}
+/*
+ * General utility functions
+ */
+
+/* Transition function to convert a nanosecond timeout to ms
+ * This is used where a system does not support ppoll
+ */
+int qemu_timeout_ns_to_ms(int64_t ns)
+{
+ int64_t ms;
+ if (ns < 0) {
+ return -1;
+ }
+
+ if (!ns) {
+ return 0;
+ }
+
+ /* Always round up, because it's better to wait too long than to wait too
+ * little and effectively busy-wait
+ */
+ ms = (ns + SCALE_MS - 1) / SCALE_MS;
+
+ /* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */
+ if (ms > (int64_t) INT32_MAX) {
+ ms = INT32_MAX;
+ }
+
+ return (int) ms;
+}
+
+/* qemu implementation of g_poll which uses a nanosecond timeout but is
+ * otherwise identical to g_poll
+ */
+int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout)
+{
+#ifdef CONFIG_PPOLL
+ if (timeout < 0) {
+ return ppoll((struct pollfd *)fds, nfds, NULL, NULL);
+ } else {
+ struct timespec ts;
+ ts.tv_sec = timeout / 1000000000LL;
+ ts.tv_nsec = timeout % 1000000000LL;
+ return ppoll((struct pollfd *)fds, nfds, &ts, NULL);
+ }
+#else
+ return g_poll(fds, nfds, qemu_timeout_ns_to_ms(timeout));
+#endif
+}
+
void init_clocks(void)
{
QEMUClockType type;
--
1.7.9.5
- [Qemu-devel] [PULL 0/7] refactor timer, Xuebing Wang, 2014/03/02
- [Qemu-devel] [PULL 1/7] timer: move QEMUTimerList functions together, Xuebing Wang, 2014/03/02
- [Qemu-devel] [PULL 2/7] timer: make QEMUTimerLis t functions private (remove from APIs), Xuebing Wang, 2014/03/02
- [Qemu-devel] [PULL 3/7] timer: move QEMUClockType related functions together, Xuebing Wang, 2014/03/02
- [Qemu-devel] [PULL 4/7] timer: move QEMUTimerListGroup function to be below QEMUClockType, Xuebing Wang, 2014/03/02
- [Qemu-devel] [PULL 5/7] timer: move QEMUTimer related functions together, Xuebing Wang, 2014/03/02
- [Qemu-devel] [PULL 6/7] timer: move general utility functions together,
Xuebing Wang <=
- [Qemu-devel] [PULL 7/7] timer: clean unnecessary #include and use minimal required #include, Xuebing Wang, 2014/03/02
- Re: [Qemu-devel] [PULL 0/7] refactor timer, Peter Maydell, 2014/03/07