qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luca Tettamanti <kronos.it@gmail.com>
To: qemu-devel@nongnu.org
Cc: kvm-devel@lists.sf.net, Luca Tettamanti <kronos.it@gmail.com>
Subject: [Qemu-devel] [PATCH 3/4] Add support for HPET periodic timer.
Date: Sat, 18 Aug 2007 01:11:52 +0200	[thread overview]
Message-ID: <20070817231406.493008599@gmail.com> (raw)
In-Reply-To: 20070817231149.544849769@gmail.com

[-- Attachment #1: clock-hpet --]
[-- Type: text/plain, Size: 2741 bytes --]

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>

---
 vl.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-08-17 17:39:21.000000000 +0200
+++ qemu/vl.c	2007-08-18 00:40:16.000000000 +0200
@@ -56,6 +56,7 @@
 #include <pty.h>
 #include <malloc.h>
 #include <linux/rtc.h>
+#include <linux/hpet.h>
 #include <linux/ppdev.h>
 #include <linux/parport.h>
 #else
@@ -809,6 +810,9 @@
 
 #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);
 
@@ -818,7 +822,9 @@
 
 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
@@ -1153,6 +1159,55 @@
     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;

-- 

  parent reply	other threads:[~2007-08-17 23:14 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-17 23:11 [Qemu-devel] [PATCH 0/4] Rework alarm timer infrastrucure - take 2 Luca Tettamanti
2007-08-17 23:11 ` [Qemu-devel] [PATCH 1/4] Rework alarm timer infrastrucure Luca Tettamanti
2007-08-17 23:11 ` [Qemu-devel] [PATCH 2/4] Add -clock option Luca Tettamanti
2007-08-17 23:11 ` Luca Tettamanti [this message]
2007-08-21 19:24   ` [Qemu-devel] [PATCH 3/4] Add support for HPET periodic timer Matthew Kent
2007-08-21 19:40     ` Luca
2007-08-21 20:15       ` Matthew Kent
2007-08-22  6:48         ` [kvm-devel] " Dan Kenigsberg
2007-08-22  7:03           ` Avi Kivity
2007-08-22 12:34             ` Andi Kleen
2007-08-22 21:11               ` Dan Kenigsberg
2007-08-22 22:09                 ` Andi Kleen
2007-08-23  7:02                   ` Dan Kenigsberg
2007-08-24 20:18                     ` Luca
2007-08-25  8:24                       ` Dan Kenigsberg
2007-09-03  8:40       ` GUERRAZ Francois
2007-08-17 23:11 ` [Qemu-devel] [PATCH 4/4] Add support for dynamic ticks Luca Tettamanti
2007-08-17 23:48 ` [Qemu-devel] [PATCH 0/4] Rework alarm timer infrastrucure - take 2 Christian MICHON
2007-08-18  0:10   ` [kvm-devel] " Luca
2007-08-18 15:17 ` [Qemu-devel] Re: [kvm-devel] " Anthony Liguori
2007-08-18 16:53   ` [Qemu-devel] RE: [kvm-devel] [PATCH 0/4] Rework alarm timer infrastrucure - take2 Dor Laor
2007-08-18 22:02     ` [Qemu-devel] " Luca Tettamanti
2007-08-18 23:58       ` Anthony Liguori
2007-08-19  7:36         ` [Qemu-devel] RE: [kvm-devel] [PATCH 0/4] Rework alarm timer infrastrucure -take2 Dor Laor
2007-08-19  8:24         ` [Qemu-devel] Re: [kvm-devel] [PATCH 0/4] Rework alarm timer infrastrucure - take2 Avi Kivity
2007-08-19 13:10           ` Jamie Lokier
2007-08-19 13:48             ` [kvm-devel] [Qemu-devel] " Avi Kivity
2007-08-19 13:57               ` Paul Brook
2007-08-19 14:07                 ` Avi Kivity
2007-08-19 14:27                   ` Dor Laor
2007-08-20  9:25                   ` Avi Kivity
2007-08-19 17:15                 ` Jamie Lokier
2007-08-19 19:29                   ` [kvm-devel] [Qemu-devel] Re: [PATCH 0/4] Rework alarmtimer " Dor Laor
2007-08-19 19:30                   ` [kvm-devel] [Qemu-devel] Re: [PATCH 0/4] Rework alarm timer " Avi Kivity
2007-08-19 16:52       ` [Qemu-devel] Re: [kvm-devel] " Luca
2007-08-19 19:31         ` Avi Kivity
2007-08-20 21:20           ` Luca Tettamanti
2007-08-20 21:55             ` malc
2007-08-20 22:49               ` [kvm-devel] [Qemu-devel] " Luca
2007-08-21 12:09             ` [Qemu-devel] Re: [kvm-devel] " Avi Kivity
2007-08-21 19:38               ` Luca Tettamanti
2007-08-21 19:44                 ` malc
2007-08-22  5:02                 ` Avi Kivity
2007-08-22 16:12                   ` Luca Tettamanti
2007-08-22 16:21                     ` Avi Kivity
2007-08-22 16:38                       ` Luca
2007-08-22 16:45                         ` Avi Kivity
2007-08-22 17:23                           ` Luca
2007-08-22 17:39                             ` Luca
2007-08-22 19:21                             ` Luca
2007-08-22 21:35                               ` [Qemu-devel] " Dor Laor
2007-08-22 22:07                                 ` [Qemu-devel] " Luca
2007-08-22 20:42                         ` Dan Kenigsberg

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=20070817231406.493008599@gmail.com \
    --to=kronos.it@gmail.com \
    --cc=kvm-devel@lists.sf.net \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).