From: Luca Tettamanti <kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: Dan Kenigsberg <dank-atKUWr5tajBWk0Htik3J/w@public.gmane.org>,
Luca Tettamanti
<kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
qemu-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org
Subject: [PATCH/RFC 3/4] Add support for HPET periodic timer.
Date: Thu, 16 Aug 2007 22:41:16 +0200 [thread overview]
Message-ID: <11872968773524-git-send-email-kronos.it@gmail.com> (raw)
In-Reply-To: <11872968773155-git-send-email-kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Linux operates the HPET timer in legacy replacement mode, which means that
the periodic interrupt of the CMOS RTC is not delivered (qemu won't be able
to use /dev/rtc). Add support for HPET (/dev/hpet) as a replacement for the
RTC; the periodic interrupt is delivered via SIGIO and is handled in the
same way as the RTC timer.
Signed-off-by: Luca Tettamanti <kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
qemu/vl.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 56 insertions(+), 1 deletions(-)
diff --git a/qemu/vl.c b/qemu/vl.c
index f0b4896..0373beb 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -54,6 +54,7 @@
#include <pty.h>
#include <malloc.h>
#include <linux/rtc.h>
+#include <linux/hpet.h>
#include <linux/ppdev.h>
#endif
#endif
@@ -773,6 +774,9 @@ static void unix_stop_timer(struct qemu_alarm_timer *t);
#ifdef __linux__
+static int hpet_start_timer(struct qemu_alarm_timer *t);
+static void hpet_stop_timer(struct qemu_alarm_timer *t);
+
static int rtc_start_timer(struct qemu_alarm_timer *t);
static void rtc_stop_timer(struct qemu_alarm_timer *t);
@@ -782,7 +786,9 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t);
static struct qemu_alarm_timer alarm_timers[] = {
#ifdef __linux__
- /* RTC - if available - is preferred */
+ /* HPET - if available - is preferred */
+ {"hpet", hpet_start_timer, hpet_stop_timer, NULL},
+ /* ...otherwise try RTC */
{"rtc", rtc_start_timer, rtc_stop_timer, NULL},
#endif
#ifndef _WIN32
@@ -1117,6 +1123,55 @@ static void enable_sigio_timer(int fd)
fcntl(fd, F_SETOWN, getpid());
}
+static int hpet_start_timer(struct qemu_alarm_timer *t)
+{
+ struct hpet_info info;
+ int r, fd;
+
+ fd = open("/dev/hpet", O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ /* Set frequency */
+ r = ioctl(fd, HPET_IRQFREQ, RTC_FREQ);
+ if (r < 0) {
+ fprintf(stderr, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n"
+ "error, but for better emulation accuracy type:\n"
+ "'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n");
+ goto fail;
+ }
+
+ /* Check capabilities */
+ r = ioctl(fd, HPET_INFO, &info);
+ if (r < 0)
+ goto fail;
+
+ /* Enable periodic mode */
+ r = ioctl(fd, HPET_EPI, 0);
+ if (info.hi_flags && (r < 0))
+ goto fail;
+
+ /* Enable interrupt */
+ r = ioctl(fd, HPET_IE_ON, 0);
+ if (r < 0)
+ goto fail;
+
+ enable_sigio_timer(fd);
+ t->priv = (void *)fd;
+
+ return 0;
+fail:
+ close(fd);
+ return -1;
+}
+
+static void hpet_stop_timer(struct qemu_alarm_timer *t)
+{
+ int fd = (int)t->priv;
+
+ close(fd);
+}
+
static int rtc_start_timer(struct qemu_alarm_timer *t)
{
int rtc_fd;
--
1.5.2.4
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
WARNING: multiple messages have this Message-ID (diff)
From: Luca Tettamanti <kronos.it@gmail.com>
To: kvm-devel@lists.sourceforge.net
Cc: Dan Kenigsberg <dank@qumranet.com>,
Luca Tettamanti <kronos.it@gmail.com>,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH/RFC 3/4] Add support for HPET periodic timer.
Date: Thu, 16 Aug 2007 22:41:16 +0200 [thread overview]
Message-ID: <11872968773524-git-send-email-kronos.it@gmail.com> (raw)
In-Reply-To: <11872968773155-git-send-email-kronos.it@gmail.com>
Linux operates the HPET timer in legacy replacement mode, which means that
the periodic interrupt of the CMOS RTC is not delivered (qemu won't be able
to use /dev/rtc). Add support for HPET (/dev/hpet) as a replacement for the
RTC; the periodic interrupt is delivered via SIGIO and is handled in the
same way as the RTC timer.
Signed-off-by: Luca Tettamanti <kronos.it@gmail.com>
---
qemu/vl.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 56 insertions(+), 1 deletions(-)
diff --git a/qemu/vl.c b/qemu/vl.c
index f0b4896..0373beb 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -54,6 +54,7 @@
#include <pty.h>
#include <malloc.h>
#include <linux/rtc.h>
+#include <linux/hpet.h>
#include <linux/ppdev.h>
#endif
#endif
@@ -773,6 +774,9 @@ static void unix_stop_timer(struct qemu_alarm_timer *t);
#ifdef __linux__
+static int hpet_start_timer(struct qemu_alarm_timer *t);
+static void hpet_stop_timer(struct qemu_alarm_timer *t);
+
static int rtc_start_timer(struct qemu_alarm_timer *t);
static void rtc_stop_timer(struct qemu_alarm_timer *t);
@@ -782,7 +786,9 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t);
static struct qemu_alarm_timer alarm_timers[] = {
#ifdef __linux__
- /* RTC - if available - is preferred */
+ /* HPET - if available - is preferred */
+ {"hpet", hpet_start_timer, hpet_stop_timer, NULL},
+ /* ...otherwise try RTC */
{"rtc", rtc_start_timer, rtc_stop_timer, NULL},
#endif
#ifndef _WIN32
@@ -1117,6 +1123,55 @@ static void enable_sigio_timer(int fd)
fcntl(fd, F_SETOWN, getpid());
}
+static int hpet_start_timer(struct qemu_alarm_timer *t)
+{
+ struct hpet_info info;
+ int r, fd;
+
+ fd = open("/dev/hpet", O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ /* Set frequency */
+ r = ioctl(fd, HPET_IRQFREQ, RTC_FREQ);
+ if (r < 0) {
+ fprintf(stderr, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n"
+ "error, but for better emulation accuracy type:\n"
+ "'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n");
+ goto fail;
+ }
+
+ /* Check capabilities */
+ r = ioctl(fd, HPET_INFO, &info);
+ if (r < 0)
+ goto fail;
+
+ /* Enable periodic mode */
+ r = ioctl(fd, HPET_EPI, 0);
+ if (info.hi_flags && (r < 0))
+ goto fail;
+
+ /* Enable interrupt */
+ r = ioctl(fd, HPET_IE_ON, 0);
+ if (r < 0)
+ goto fail;
+
+ enable_sigio_timer(fd);
+ t->priv = (void *)fd;
+
+ return 0;
+fail:
+ close(fd);
+ return -1;
+}
+
+static void hpet_stop_timer(struct qemu_alarm_timer *t)
+{
+ int fd = (int)t->priv;
+
+ close(fd);
+}
+
static int rtc_start_timer(struct qemu_alarm_timer *t)
{
int rtc_fd;
--
1.5.2.4
next prev parent reply other threads:[~2007-08-16 20:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-16 20:41 [PATCH/RFC 0/4] Rework alarm timer infrastrucure Luca Tettamanti
2007-08-16 20:41 ` [Qemu-devel] " Luca Tettamanti
[not found] ` <11872968773449-git-send-email-kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2007-08-16 20:41 ` [PATCH/RFC 1/4] " Luca Tettamanti
2007-08-16 20:41 ` [Qemu-devel] " Luca Tettamanti
[not found] ` <11872968771257-git-send-email-kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2007-08-16 20:41 ` [PATCH/RFC 2/4] Add -clock option Luca Tettamanti
2007-08-16 20:41 ` [Qemu-devel] " Luca Tettamanti
[not found] ` <11872968773155-git-send-email-kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2007-08-16 20:41 ` Luca Tettamanti [this message]
2007-08-16 20:41 ` [Qemu-devel] [PATCH/RFC 3/4] Add support for HPET periodic timer Luca Tettamanti
[not found] ` <11872968773524-git-send-email-kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2007-08-16 20:41 ` [PATCH/RFC 4/4] Add support for dynamic ticks Luca Tettamanti
2007-08-16 20:41 ` [Qemu-devel] " Luca Tettamanti
[not found] ` <1187296877557-git-send-email-kronos.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2007-08-17 7:16 ` Matthew Kent
2007-08-17 7:16 ` [Qemu-devel] Re: [kvm-devel] " Matthew Kent
[not found] ` <42755.207.81.93.54.1187334969.squirrel-N19E6/cp6YFSV923RJcDwA@public.gmane.org>
2007-08-19 8:08 ` Avi Kivity
2007-08-19 8:08 ` [Qemu-devel] Re: [kvm-devel] " Avi Kivity
2007-08-17 12:44 ` [PATCH/RFC 0/4] Rework alarm timer infrastrucure Avi Kivity
2007-08-17 12:44 ` [Qemu-devel] Re: [kvm-devel] " Avi Kivity
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=11872968773524-git-send-email-kronos.it@gmail.com \
--to=kronos.it-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=dank-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=qemu-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org \
/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.