Skip to contentSkip to conversation

Save/load PC speaker internal state (v2)

PATCH Jan Kiszka 2 participants 3 messages Aug 28, 2012 – Aug 29, 2012 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Jan Kiszka

author
#1 lore raw
Quoted 28 lines · Pavel Dovgaluk

Save PC speaker state to remove differences between system states after saving the snapshot and after loading it again. This patch is needed for deterministic replay of the execution.

v2: Do not save the data that cannot affect the guest code behavior.

---
 hw/pcspk.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
hw/pcspk.c +2 -2
index e430324..07a3de0 100644
@@ -46,8 +46,8 @@ typedef struct {
     unsigned int pit_count;
     unsigned int samples;
     unsigned int play_pos;
-    int data_on;
-    int dummy_refresh_clock;
+    uint8_t data_on;
+    uint8_t dummy_refresh_clock;
 } PCSpkState;
 
 static const char *s_spk = "pcspk";
@@ -159,6 +159,18 @@ static const MemoryRegionOps pcspk_io_ops = {
     },

hw/pcspk.c static const MemoryRegionOps pcspk_io_ops = { · line 169

Quoted 10 lines
hw/pcspk.c +8 -0
 };
 
+static const VMStateDescription vmstate_spk = {
+    .name = "pcspk",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT8(data_on, PCSpkState),
+        VMSTATE_UINT8(dummy_refresh_clock, PCSpkState),

Just to understand the plan: The intention is to leave the audio disabled after resume, just saving those bits that can be read back via IO port, correct? Then please document this in a comment, otherwise fix it.

Jan

#2 lore raw
Quoted 38 lines

-----Original Message-----
From: Jan Kiszka [mailto:[email protected]]
Sent: Tuesday, August 28, 2012 11:13 AM
To: Pavel Dovgaluk
Cc: 'qemu-devel'
Subject: Re: [PATCH] Save/load PC speaker internal state (v2)

Quoted 30 lines · Pavel Dovgaluk

Save PC speaker state to remove differences between system states after saving the snapshot and after loading it again. This patch is needed for deterministic replay of the execution.

v2: Do not save the data that cannot affect the guest code behavior.

---
 hw/pcspk.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
hw/pcspk.c +2 -2
index e430324..07a3de0 100644
@@ -46,8 +46,8 @@ typedef struct {
     unsigned int pit_count;
     unsigned int samples;
     unsigned int play_pos;
-    int data_on;
-    int dummy_refresh_clock;
+    uint8_t data_on;
+    uint8_t dummy_refresh_clock;
 } PCSpkState;
 
 static const char *s_spk = "pcspk";
@@ -159,6 +159,18 @@ static const MemoryRegionOps pcspk_io_ops = {
     },
 };
 
Quoted 12 lines

hw/pcspk.c static const MemoryRegionOps pcspk_io_ops = { · line 169

Quoted 8 lines
hw/pcspk.c +8 -0
+static const VMStateDescription vmstate_spk = {
+    .name = "pcspk",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT8(data_on, PCSpkState),
+        VMSTATE_UINT8(dummy_refresh_clock, PCSpkState),

Just to understand the plan: The intention is to leave the audio disabled after resume, just saving those bits that can be read back via IO port, correct? Then please document this in a comment, otherwise fix it.

The plan is to make guest system behavior deterministic.
Resuming the audio is not needed for this but could be a useful side effect. I thought about solutions of this problem and got the following:
we cannot reinitialize the buffer in post_load function, because pit used for samples generation could be not reloaded yet at that moment and the buffer's state will be invalid in this case.
So the only solution is saving and loading the complete state of the audio buffer.

Pavel Dovgaluk

author
#3 lore raw
Quoted 51 lines · Pavel Dovgaluk
Quoted 38 lines

-----Original Message-----
From: Jan Kiszka [mailto:[email protected]]
Sent: Tuesday, August 28, 2012 11:13 AM
To: Pavel Dovgaluk
Cc: 'qemu-devel'
Subject: Re: [PATCH] Save/load PC speaker internal state (v2)

Quoted 30 lines · Pavel Dovgaluk

Save PC speaker state to remove differences between system states after saving the snapshot and after loading it again. This patch is needed for deterministic replay of the execution.

v2: Do not save the data that cannot affect the guest code behavior.

---
 hw/pcspk.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
hw/pcspk.c +2 -2
index e430324..07a3de0 100644
@@ -46,8 +46,8 @@ typedef struct {
     unsigned int pit_count;
     unsigned int samples;
     unsigned int play_pos;
-    int data_on;
-    int dummy_refresh_clock;
+    uint8_t data_on;
+    uint8_t dummy_refresh_clock;
 } PCSpkState;
 
 static const char *s_spk = "pcspk";
@@ -159,6 +159,18 @@ static const MemoryRegionOps pcspk_io_ops = {
     },
 };
 
Quoted 12 lines

hw/pcspk.c static const MemoryRegionOps pcspk_io_ops = { · line 169

Quoted 8 lines
hw/pcspk.c +8 -0
+static const VMStateDescription vmstate_spk = {
+    .name = "pcspk",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT8(data_on, PCSpkState),
+        VMSTATE_UINT8(dummy_refresh_clock, PCSpkState),

Just to understand the plan: The intention is to leave the audio disabled after resume, just saving those bits that can be read back via IO port, correct? Then please document this in a comment, otherwise fix it.

Quoted 7 lines

The plan is to make guest system behavior deterministic.
Resuming the audio is not needed for this but could be a useful side effect. I thought about solutions of this problem and got the following:
we cannot reinitialize the buffer in post_load function, because pit used for samples generation could be not reloaded yet at that moment and the buffer's state will be invalid in this case.
So the only solution is saving and loading the complete state of the audio buffer.

Theoretically, you could save the required PIT state inside the pcspk VMSD to solve this (still less bytes than saving the buffer). However, I see no relevant loss in leaving audio off until the guest fiddles with the controls again. I'm just asking for documenting this.

Jan