From patchwork Tue Feb 25 13:36:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuebing Wang X-Patchwork-Id: 323971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3BC932C00CB for ; Wed, 26 Feb 2014 00:46:21 +1100 (EST) Received: from localhost ([::1]:35022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIIKw-0005TO-TP for incoming@patchwork.ozlabs.org; Tue, 25 Feb 2014 08:46:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIICy-0004Fi-KN for qemu-devel@nongnu.org; Tue, 25 Feb 2014 08:38:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIICl-0004jv-VG for qemu-devel@nongnu.org; Tue, 25 Feb 2014 08:38:04 -0500 Received: from mail-pa0-x236.google.com ([2607:f8b0:400e:c03::236]:36815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIICl-0004ji-P1 for qemu-devel@nongnu.org; Tue, 25 Feb 2014 08:37:51 -0500 Received: by mail-pa0-f54.google.com with SMTP id fa1so8081519pad.13 for ; Tue, 25 Feb 2014 05:37:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NE23YCAmshek9/q+O//SooEv0tarVCqMejh4Bc/rHrg=; b=VimlvDOP5yI7V6eYf8xgc/MLDhaESuREhBYzmtTTlMXvCnnsfCWMldQ5C5A81qLFk4 Ea9Ov5gbQBEY71mSsckPnQ9r5Xk4dq2dVBXwNrDAp7XlG56QZZPdeeD/K9r+fI8WaMXs DBEhNI2BhrLMXOlzVN/o/i7Ro9El9HK3vvkkrxGpdJZVRaMvmp37KudoIEWi/Hpm6sTq //IOcSmMMyZcJSY9n3tYF2NAQtf978T1sZ8SbEY3GkXSNIUG1r08+XBslFWcdcAKusvT AHj4eLNPg/thjytNUoN9nkhm6kpu3YDQxQp1tqdLBYwzwGag0k04c4WWoYm2XfMj4Yww ToZA== X-Received: by 10.68.143.72 with SMTP id sc8mr6509837pbb.101.1393335470786; Tue, 25 Feb 2014 05:37:50 -0800 (PST) Received: from localhost.localdomain ([216.131.71.88]) by mx.google.com with ESMTPSA id j3sm10781784pbh.38.2014.02.25.05.37.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 05:37:50 -0800 (PST) From: Xuebing Wang To: qemu-devel@nongnu.org Date: Tue, 25 Feb 2014 21:36:53 +0800 Message-Id: <1393335414-27589-7-git-send-email-xbing6@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393335414-27589-1-git-send-email-xbing6@gmail.com> References: <1393335414-27589-1-git-send-email-xbing6@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::236 Cc: pbonzini@redhat.com, xbing6@gmail.com, stefanha@redhat.com, alex@alex.org.uk Subject: [Qemu-devel] [PATCH 6/7] timer: move general utility functions together X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Xuebing Wang --- 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;