[PATCH] vmx: support HPET timers configuration

João Sena Ribeiro via Devel posted 1 patch 2 weeks, 3 days ago
src/vmx/vmx.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
[PATCH] vmx: support HPET timers configuration
Posted by João Sena Ribeiro via Devel 2 weeks, 3 days ago
All VMs are being created with no hpet timer defined. Check if the
VM definition XML file enables HPET and reflect that on the VMX
file.

Signed-off-by: João Sena Ribeiro <joao.ribeiro@identity.pt>
---
 src/vmx/vmx.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index de16c1f634..d7e116dd07 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -65,7 +65,7 @@ def->maxvcpus = <value>           <=>   numvcpus = "<value>"
 def->cpumask = <uint list>        <=>   sched.cpu.affinity = "<uint list>"
 def->cputune.shares = <value>     <=>   sched.cpu.shares = "<value>"            # with handling for special values
                                                                                 # "high", "normal", "low"
-
+def->ntimers                      <=>   hpet.present = "<value>"                # "true", "false"
 
 
 ################################################################################
@@ -3496,6 +3496,35 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
         }
     }
 
+    /* def:clock.ntimers */
+    for (i = 0; i < def->clock.ntimers; i++) {
+        switch ((virDomainTimerNameType)def->clock.timers[i]->name) {
+        case VIR_DOMAIN_TIMER_NAME_HPET:
+            if (def->clock.timers[i]->present == VIR_TRISTATE_BOOL_YES) {
+                virBufferAddLit(&buffer, "hpet0.present = \"true\"\n");
+            } else if (def->clock.timers[i]->present == VIR_TRISTATE_BOOL_NO) {
+                virBufferAddLit(&buffer, "hpet0.present = \"false\"\n");
+            }
+            break;
+
+        case VIR_DOMAIN_TIMER_NAME_TSC:
+        case VIR_DOMAIN_TIMER_NAME_PLATFORM:
+        case VIR_DOMAIN_TIMER_NAME_KVMCLOCK:
+        case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK:
+        case VIR_DOMAIN_TIMER_NAME_RTC:
+        case VIR_DOMAIN_TIMER_NAME_PIT:
+        case VIR_DOMAIN_TIMER_NAME_ARMVTIMER:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unsupported timer type (name) '%1$s'"),
+                           virDomainTimerNameTypeToString(def->clock.timers[i]->name));
+            goto cleanup;
+
+        case VIR_DOMAIN_TIMER_NAME_LAST:
+            break;
+
+        }
+    }
+
     /* def:graphics */
     for (i = 0; i < def->ngraphics; ++i) {
         switch (def->graphics[i]->type) {
-- 
2.34.1
Re: [PATCH] vmx: support HPET timers configuration
Posted by Martin Kletzander 3 days, 13 hours ago
On Wed, Sep 18, 2024 at 12:03:57PM +0100, João Sena Ribeiro via Devel wrote:
>All VMs are being created with no hpet timer defined. Check if the
>VM definition XML file enables HPET and reflect that on the VMX
>file.
>

Hi, this is great.  But to actually report that properly it would be
nice if you could also add the reverse operation into
virVMXParseConfig() so that we report it in the XML when someone dumps
it.

Otherwise the patch looks fine.

>Signed-off-by: João Sena Ribeiro <joao.ribeiro@identity.pt>
>---
> src/vmx/vmx.c | 31 ++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
>diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
>index de16c1f634..d7e116dd07 100644
>--- a/src/vmx/vmx.c
>+++ b/src/vmx/vmx.c
>@@ -65,7 +65,7 @@ def->maxvcpus = <value>           <=>   numvcpus = "<value>"
> def->cpumask = <uint list>        <=>   sched.cpu.affinity = "<uint list>"
> def->cputune.shares = <value>     <=>   sched.cpu.shares = "<value>"            # with handling for special values
>                                                                                 # "high", "normal", "low"
>-
>+def->ntimers                      <=>   hpet.present = "<value>"                # "true", "false"
>
>
> ################################################################################
>@@ -3496,6 +3496,35 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
>         }
>     }
>
>+    /* def:clock.ntimers */
>+    for (i = 0; i < def->clock.ntimers; i++) {
>+        switch ((virDomainTimerNameType)def->clock.timers[i]->name) {
>+        case VIR_DOMAIN_TIMER_NAME_HPET:
>+            if (def->clock.timers[i]->present == VIR_TRISTATE_BOOL_YES) {
>+                virBufferAddLit(&buffer, "hpet0.present = \"true\"\n");
>+            } else if (def->clock.timers[i]->present == VIR_TRISTATE_BOOL_NO) {
>+                virBufferAddLit(&buffer, "hpet0.present = \"false\"\n");
>+            }
>+            break;
>+
>+        case VIR_DOMAIN_TIMER_NAME_TSC:
>+        case VIR_DOMAIN_TIMER_NAME_PLATFORM:
>+        case VIR_DOMAIN_TIMER_NAME_KVMCLOCK:
>+        case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK:
>+        case VIR_DOMAIN_TIMER_NAME_RTC:
>+        case VIR_DOMAIN_TIMER_NAME_PIT:
>+        case VIR_DOMAIN_TIMER_NAME_ARMVTIMER:
>+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>+                           _("unsupported timer type (name) '%1$s'"),
>+                           virDomainTimerNameTypeToString(def->clock.timers[i]->name));
>+            goto cleanup;
>+
>+        case VIR_DOMAIN_TIMER_NAME_LAST:
>+            break;
>+
>+        }
>+    }
>+
>     /* def:graphics */
>     for (i = 0; i < def->ngraphics; ++i) {
>         switch (def->graphics[i]->type) {
>-- 
>2.34.1
>