Fix serial interface vmstate
PATCH 1/1 Fix serial interface vmstate
This patch fixes save/restore of serial interface's state. It includes changing of fcr setter function (it now does not invoke
an interrupt while loading vmstate), and saving/restoring all fields that describe the state of serial interface (including timers).
--- hw/serial.c | 133 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 87 insertions(+), 46 deletions(-)
hw/serial.c +87 -46
@@ -362,6 +362,62 @@ static void serial_xmit(void *opaque) } +/* Setter for FCR. +is_load flag means, that value is set while loading VM state +and interrupt should not be invoked */ +static void serial_write_fcr (void *opaque,uint32_t val,int is_load) +{ +SerialState *s = opaque; + + val = val &0xFF ; + +if (s->fcr == val) +return ; + +/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ +if ((val ^ s->fcr) &UART_FCR_FE ) + val |=UART_FCR_XFR |UART_FCR_RFR ; + +/* FIFO clear */ + +if (val &UART_FCR_RFR ) { +qemu_del_timer (s->fifo_timeout_timer); + s->timeout_ipending=0 ; +fifo_clear (s,RECV_FIFO ); + } + +if (val &UART_FCR_XFR ) { +fifo_clear (s,XMIT_FIFO ); + } + +if (val &UART_FCR_FE ) { + s->iir |=UART_IIR_FE ; +/* Set RECV_FIFO trigger Level */ +switch (val &0xC0 ) { +case UART_FCR_ITL_1 : + s->recv_fifo.itl =1 ; +break ; +case UART_FCR_ITL_2 : + s->recv_fifo.itl =4 ; +break ; +case UART_FCR_ITL_3 : + s->recv_fifo.itl =8 ; +break ; +case UART_FCR_ITL_4 : + s->recv_fifo.itl =14 ; +break ; + } + }else + s->iir &= ~UART_IIR_FE ; + +/* Set fcr - or at least the bits in it that are supposed to "stick" */ + s->fcr = val &0xC9 ; +if (!is_load) { +serial_update_irq (s); + } +} + +static void serial_ioport_write (void *opaque,uint32_t addr,uint32_t val) {SerialState *s = opaque;
@@ -414,50 +470,7 @@ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val) }break ;case 2 : - val = val &0xFF ; - -if (s->fcr == val) -break ; - -/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ -if ((val ^ s->fcr) &UART_FCR_FE ) - val |=UART_FCR_XFR |UART_FCR_RFR ; - -/* FIFO clear */ - -if (val &UART_FCR_RFR ) { -qemu_del_timer (s->fifo_timeout_timer); - s->timeout_ipending=0 ; -fifo_clear (s,RECV_FIFO ); - } - -if (val &UART_FCR_XFR ) { -fifo_clear (s,XMIT_FIFO ); - } - -if (val &UART_FCR_FE ) { - s->iir |=UART_IIR_FE ; -/* Set RECV_FIFO trigger Level */ -switch (val &0xC0 ) { -case UART_FCR_ITL_1 : - s->recv_fifo.itl =1 ; -break ; -case UART_FCR_ITL_2 : - s->recv_fifo.itl =4 ; -break ; -case UART_FCR_ITL_3 : - s->recv_fifo.itl =8 ; -break ; -case UART_FCR_ITL_4 : - s->recv_fifo.itl =14 ; -break ; - } - }else - s->iir &= ~UART_IIR_FE ; - -/* Set fcr - or at least the bits in it that are supposed to "stick" */ - s->fcr = val &0xC9 ; -serial_update_irq (s); +serial_write_fcr (s, val,0 );break ;case 3 : {
@@ -673,20 +686,38 @@ static int serial_post_load(void *opaque, int version_id) s->fcr_vmstate =0 ; }/* Initialize fcr via setter to perform essential side-effects */ -serial_ioport_write (s,0x02 , s->fcr_vmstate); +serial_write_fcr (s, s->fcr_vmstate,1 );serial_update_parameters (s);return 0 ; } + +static const VMStateDescription vmstate_fifo = { + .name ="serial FIFO" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BUFFER (data, SerialFIFO), +VMSTATE_UINT8 (count, SerialFIFO), +VMSTATE_UINT8 (itl, SerialFIFO), +VMSTATE_UINT8 (tail, SerialFIFO), +VMSTATE_UINT8 (head, SerialFIFO), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_serial = { .name ="serial" , - .version_id =3 , + .version_id =4 , .minimum_version_id =2 , .pre_save = serial_pre_save, .post_load = serial_post_load, .fields = (VMStateField []) {VMSTATE_UINT16_V (divider, SerialState,2 ),VMSTATE_UINT8 (rbr, SerialState), +VMSTATE_UINT8_V (thr, SerialState,4 ), +VMSTATE_UINT8_V (tsr, SerialState,4 ),VMSTATE_UINT8 (ier, SerialState),VMSTATE_UINT8 (iir, SerialState),VMSTATE_UINT8 (lcr, SerialState),
@@ -695,6 +726,16 @@ static const VMStateDescription vmstate_serial = { VMSTATE_UINT8(msr, SerialState), VMSTATE_UINT8(scr, SerialState), VMSTATE_UINT8_V(fcr_vmstate, SerialState, 3), + VMSTATE_INT32_V(thr_ipending, SerialState, 4), + VMSTATE_INT32_V(last_break_enable, SerialState, 4), + VMSTATE_INT32_V(tsr_retry, SerialState, 4), + VMSTATE_STRUCT(recv_fifo, SerialState, 4, vmstate_fifo, SerialFIFO), + VMSTATE_STRUCT(xmit_fifo, SerialState, 4, vmstate_fifo, SerialFIFO), + VMSTATE_TIMER_V(fifo_timeout_timer, SerialState, 4), + VMSTATE_INT32_V(timeout_ipending, SerialState, 4), + VMSTATE_TIMER_V(transmit_timer, SerialState, 4), + VMSTATE_INT32_V(poll_msl, SerialState, 4), + VMSTATE_TIMER_V(modem_status_poll, SerialState, 4),VMSTATE_END_OF_LIST () } };
Quoted 6 lines · Pavel Dovgaluk
This patch fixes save/restore of serial interface's state. It includes changing of fcr setter function (it now does not invoke
an interrupt while loading vmstate), and saving/restoring all fields that describe the state of serial interface (including timers).Signed-off-by Pavel Dovgalyuk <[email protected]>
I think we can do this with a new subsection.
Quoted 13 lines
--- hw/serial.c | 133 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 87 insertions(+), 46 deletions(-)hw/serial.c +1
-0@@ -362,6 +362,62 @@ static void serial_xmit(void *opaque) } +/* Setter for FCR.
hw/serial.c static void serial_xmit(void *opaque) · line 375
Quoted 10 lines
hw/serial.c +10
-0+is_load flag means, that value is set while loading VM state +and interrupt should not be invoked */ +static void serial_write_fcr (void *opaque,uint32_t val,int is_load) +{ +SerialState *s = opaque; + + val = val &0xFF ; + +if (s->fcr == val) +return ;
This looks like a test. if this is true, we don't need to restore the other values, so we shouldbe safe, right?
Quoted 31 lines
hw/serial.c +31
-0+/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ +if ((val ^ s->fcr) &UART_FCR_FE ) + val |=UART_FCR_XFR |UART_FCR_RFR ; + +/* FIFO clear */ + +if (val &UART_FCR_RFR ) { +qemu_del_timer (s->fifo_timeout_timer); + s->timeout_ipending=0 ; +fifo_clear (s,RECV_FIFO ); + } + +if (val &UART_FCR_XFR ) { +fifo_clear (s,XMIT_FIFO ); + } + +if (val &UART_FCR_FE ) { + s->iir |=UART_IIR_FE ; +/* Set RECV_FIFO trigger Level */ +switch (val &0xC0 ) { +case UART_FCR_ITL_1 : + s->recv_fifo.itl =1 ; +break ; +case UART_FCR_ITL_2 : + s->recv_fifo.itl =4 ; +break ; +case UART_FCR_ITL_3 : + s->recv_fifo.itl =8 ; +break ; +case UART_FCR_ITL_4 : + s->recv_fifo.itl =14 ;
hw/serial.c static void serial_xmit(void *opaque) · line 417
Quoted 10 lines
hw/serial.c +10
-0+break ; + } + }else + s->iir &= ~UART_IIR_FE ; + +/* Set fcr - or at least the bits in it that are supposed to "stick" */ + s->fcr = val &0xC9 ; +if (!is_load) { +serial_update_irq (s); + }
we can put the serial_update_irq() at caller site. Function is only called twice, on place need to call serial_update_irq() and the other not.
Quoted 106 lines
hw/serial.c +27
-46+} + +static void serial_ioport_write (void *opaque,uint32_t addr,uint32_t val) {SerialState *s = opaque;@@ -414,50 +470,7 @@ static void serial_ioport_write(void *opaque, uint32_t addr, uint32_t val) }break ;case 2 : - val = val &0xFF ; - -if (s->fcr == val) -break ; - -/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ -if ((val ^ s->fcr) &UART_FCR_FE ) - val |=UART_FCR_XFR |UART_FCR_RFR ; - -/* FIFO clear */ - -if (val &UART_FCR_RFR ) { -qemu_del_timer (s->fifo_timeout_timer); - s->timeout_ipending=0 ; -fifo_clear (s,RECV_FIFO ); - } - -if (val &UART_FCR_XFR ) { -fifo_clear (s,XMIT_FIFO ); - } - -if (val &UART_FCR_FE ) { - s->iir |=UART_IIR_FE ; -/* Set RECV_FIFO trigger Level */ -switch (val &0xC0 ) { -case UART_FCR_ITL_1 : - s->recv_fifo.itl =1 ; -break ; -case UART_FCR_ITL_2 : - s->recv_fifo.itl =4 ; -break ; -case UART_FCR_ITL_3 : - s->recv_fifo.itl =8 ; -break ; -case UART_FCR_ITL_4 : - s->recv_fifo.itl =14 ; -break ; - } - }else - s->iir &= ~UART_IIR_FE ; - -/* Set fcr - or at least the bits in it that are supposed to "stick" */ - s->fcr = val &0xC9 ; -serial_update_irq (s); +serial_write_fcr (s, val,0 );break ;case 3 : {@@ -673,20 +686,38 @@ static int serial_post_load(void *opaque, int version_id) s->fcr_vmstate =0 ; }/* Initialize fcr via setter to perform essential side-effects */ -serial_ioport_write (s,0x02 , s->fcr_vmstate); +serial_write_fcr (s, s->fcr_vmstate,1 );serial_update_parameters (s);return 0 ; } + +static const VMStateDescription vmstate_fifo = { + .name ="serial FIFO" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BUFFER (data, SerialFIFO), +VMSTATE_UINT8 (count, SerialFIFO), +VMSTATE_UINT8 (itl, SerialFIFO), +VMSTATE_UINT8 (tail, SerialFIFO), +VMSTATE_UINT8 (head, SerialFIFO), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_serial = { .name ="serial" , - .version_id =3 , + .version_id =4 , .minimum_version_id =2 , .pre_save = serial_pre_save, .post_load = serial_post_load, .fields = (VMStateField []) {VMSTATE_UINT16_V (divider, SerialState,2 ),VMSTATE_UINT8 (rbr, SerialState), +VMSTATE_UINT8_V (thr, SerialState,4 ), +VMSTATE_UINT8_V (tsr, SerialState,4 ),VMSTATE_UINT8 (ier, SerialState),VMSTATE_UINT8 (iir, SerialState),VMSTATE_UINT8 (lcr, SerialState),@@ -695,6 +726,16 @@ static const VMStateDescription vmstate_serial = {VMSTATE_UINT8 (msr, SerialState),VMSTATE_UINT8 (scr, SerialState),VMSTATE_UINT8_V (fcr_vmstate, SerialState,3 ), +VMSTATE_INT32_V (thr_ipending, SerialState,4 ), +VMSTATE_INT32_V (last_break_enable, SerialState,4 ), + VMSTATE_INT32_V(tsr_retry, SerialState, 4),
hw/serial.c static const VMStateDescription vmstate_serial = { · line 741
Quoted 10 lines
hw/serial.c +7
-0+VMSTATE_STRUCT (recv_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_STRUCT (xmit_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_TIMER_V (fifo_timeout_timer, SerialState,4 ), +VMSTATE_INT32_V (timeout_ipending, SerialState,4 ), +VMSTATE_TIMER_V (transmit_timer, SerialState,4 ), +VMSTATE_INT32_V (poll_msl, SerialState,4 ), +VMSTATE_TIMER_V (modem_status_poll, SerialState,4 ), VMSTATE_END_OF_LIST() } };
Anyways, I think that it is better to split the change in two patches. One that refactor the common code in another function. And the other that adds the VMSTATE bits, I can add the subsection part if you want.
Later, Juan.
Quoted 22 lines
Quoted 6 lines · Pavel Dovgaluk
This patch fixes save/restore of serial interface's state. It includes changing of fcr setter function (it now does not invoke
an interrupt while loading vmstate), and saving/restoring all fields that describe the state of serial interface (including timers).Signed-off-by Pavel Dovgalyuk <[email protected]>I think we can do this with a new subsection.
Quoted 12 lines
--- hw/serial.c | 133 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 87 insertions(+), 46 deletions(-)hw/serial.c +0
-0@@ -362,6 +362,62 @@ static void serial_xmit(void *opaque) }
Quoted 14 lines
hw/serial.c static void serial_xmit(void *opaque) · line 375
Quoted 11 lines
hw/serial.c +11
-0+/* Setter for FCR. +is_load flag means, that value is set while loading VM state +and interrupt should not be invoked */ +static void serial_write_fcr (void *opaque,uint32_t val,int is_load) +{ +SerialState *s = opaque; + + val = val &0xFF ; + +if (s->fcr == val) +return ;This looks like a test. if this is true, we don't need to restore the other values, so we shouldbe safe, right?
Yes, that's right.
Actually, this code is moved from serial_ioport_write into separate
function. All checks and branches were not changed, only irq invocation was made conditional.
Quoted 36 lines
Quoted 36 lines
hw/serial.c +36
-0+/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ +if ((val ^ s->fcr) &UART_FCR_FE ) + val |=UART_FCR_XFR |UART_FCR_RFR ; + +/* FIFO clear */ + +if (val &UART_FCR_RFR ) { +qemu_del_timer (s->fifo_timeout_timer); + s->timeout_ipending=0 ; +fifo_clear (s,RECV_FIFO ); + } + +if (val &UART_FCR_XFR ) { +fifo_clear (s,XMIT_FIFO ); + } + +if (val &UART_FCR_FE ) { + s->iir |=UART_IIR_FE ; +/* Set RECV_FIFO trigger Level */ +switch (val &0xC0 ) { +case UART_FCR_ITL_1 : + s->recv_fifo.itl =1 ; +break ; +case UART_FCR_ITL_2 : + s->recv_fifo.itl =4 ; +break ; +case UART_FCR_ITL_3 : + s->recv_fifo.itl =8 ; +break ; +case UART_FCR_ITL_4 : + s->recv_fifo.itl =14 ; +break ; + } + }else + s->iir &= ~UART_IIR_FE ; +
Quoted 8 lines
hw/serial.c static void serial_xmit(void *opaque) · line 417
Quoted 5 lines
hw/serial.c +5
-0+/* Set fcr - or at least the bits in it that are supposed to "stick" */ + s->fcr = val &0xC9 ; +if (!is_load) { +serial_update_irq (s); + }we can put the
serial_update_irq()at caller site. Function is only called twice, on place need to callserial_update_irq()and the other not.
Yes, you right. I didn't think about it.
Quoted 43 lines
Quoted 43 lines
hw/serial.c +27
-1+static const VMStateDescription vmstate_fifo = { + .name ="serial FIFO" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BUFFER (data, SerialFIFO), +VMSTATE_UINT8 (count, SerialFIFO), +VMSTATE_UINT8 (itl, SerialFIFO), +VMSTATE_UINT8 (tail, SerialFIFO), +VMSTATE_UINT8 (head, SerialFIFO), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_serial = { .name ="serial" , - .version_id =3 , + .version_id =4 , .minimum_version_id =2 , .pre_save = serial_pre_save, .post_load = serial_post_load, .fields = (VMStateField []) {VMSTATE_UINT16_V (divider, SerialState,2 ),VMSTATE_UINT8 (rbr, SerialState), +VMSTATE_UINT8_V (thr, SerialState,4 ), +VMSTATE_UINT8_V (tsr, SerialState,4 ),VMSTATE_UINT8 (ier, SerialState),VMSTATE_UINT8 (iir, SerialState),VMSTATE_UINT8 (lcr, SerialState),@@ -695,6 +726,16 @@ static const VMStateDescription vmstate_serial = {VMSTATE_UINT8 (msr, SerialState),VMSTATE_UINT8 (scr, SerialState),VMSTATE_UINT8_V (fcr_vmstate, SerialState,3 ), +VMSTATE_INT32_V (thr_ipending, SerialState,4 ), +VMSTATE_INT32_V (last_break_enable, SerialState,4 ), +VMSTATE_INT32_V (tsr_retry, SerialState,4 ), +VMSTATE_STRUCT (recv_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_STRUCT (xmit_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_TIMER_V (fifo_timeout_timer, SerialState,4 ), +VMSTATE_INT32_V (timeout_ipending, SerialState,4 ), +VMSTATE_TIMER_V (transmit_timer, SerialState,4 ), + VMSTATE_INT32_V(poll_msl, SerialState, 4),
Quoted 8 lines
hw/serial.c static const VMStateDescription vmstate_serial = { · line 741
Quoted 4 lines
hw/serial.c +1
-0+VMSTATE_TIMER_V (modem_status_poll, SerialState,4 ), VMSTATE_END_OF_LIST() } };Anyways, I think that it is better to split the change in two patches. One that refactor the common code in another function. And the other that adds the VMSTATE bits, I can add the subsection part if you want.
What is the purpose of subsections?
And how to create them?
Pavel Dovgaluk
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 141 lines · Pavel Dovgaluk
Quoted 22 lines
Quoted 6 lines · Pavel Dovgaluk
This patch fixes save/restore of serial interface's state. It includes changing of fcr setter function (it now does not invoke
an interrupt while loading vmstate), and saving/restoring all fields that describe the state of serial interface (including timers).Signed-off-by Pavel Dovgalyuk <[email protected]>I think we can do this with a new subsection.
Quoted 12 lines
--- hw/serial.c | 133 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 87 insertions(+), 46 deletions(-)hw/serial.c +0
-0@@ -362,6 +362,62 @@ static void serial_xmit(void *opaque) }Quoted 14 lines
hw/serial.c static void serial_xmit(void *opaque) · line 375
Quoted 11 lines
hw/serial.c +11
-0+/* Setter for FCR. +is_load flag means, that value is set while loading VM state +and interrupt should not be invoked */ +static void serial_write_fcr (void *opaque,uint32_t val,int is_load) +{ +SerialState *s = opaque; + + val = val &0xFF ; + +if (s->fcr == val) +return ;This looks like a test. if this is true, we don't need to restore the other values, so we shouldbe safe, right?
Yes, that's right.
Actually, this code is moved fromserial_ioport_writeinto separate
function. All checks and branches were not changed, only irq invocation was made conditional.Quoted 36 lines
Quoted 36 lines
hw/serial.c +36
-0+/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ +if ((val ^ s->fcr) &UART_FCR_FE ) + val |=UART_FCR_XFR |UART_FCR_RFR ; + +/* FIFO clear */ + +if (val &UART_FCR_RFR ) { +qemu_del_timer (s->fifo_timeout_timer); + s->timeout_ipending=0 ; +fifo_clear (s,RECV_FIFO ); + } + +if (val &UART_FCR_XFR ) { +fifo_clear (s,XMIT_FIFO ); + } + +if (val &UART_FCR_FE ) { + s->iir |=UART_IIR_FE ; +/* Set RECV_FIFO trigger Level */ +switch (val &0xC0 ) { +case UART_FCR_ITL_1 : + s->recv_fifo.itl =1 ; +break ; +case UART_FCR_ITL_2 : + s->recv_fifo.itl =4 ; +break ; +case UART_FCR_ITL_3 : + s->recv_fifo.itl =8 ; +break ; +case UART_FCR_ITL_4 : + s->recv_fifo.itl =14 ; +break ; + } + }else + s->iir &= ~UART_IIR_FE ; +Quoted 8 lines
hw/serial.c static void serial_xmit(void *opaque) · line 417
Quoted 5 lines
hw/serial.c +5
-0+/* Set fcr - or at least the bits in it that are supposed to "stick" */ + s->fcr = val &0xC9 ; +if (!is_load) { +serial_update_irq (s); + }we can put the
serial_update_irq()at caller site. Function is only called twice, on place need to callserial_update_irq()and the other not.Yes, you right. I didn't think about it.
Quoted 43 lines
Quoted 43 lines
hw/serial.c +27
-1+static const VMStateDescription vmstate_fifo = { + .name ="serial FIFO" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BUFFER (data, SerialFIFO), +VMSTATE_UINT8 (count, SerialFIFO), +VMSTATE_UINT8 (itl, SerialFIFO), +VMSTATE_UINT8 (tail, SerialFIFO), +VMSTATE_UINT8 (head, SerialFIFO), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_serial = { .name ="serial" , - .version_id =3 , + .version_id =4 , .minimum_version_id =2 , .pre_save = serial_pre_save, .post_load = serial_post_load, .fields = (VMStateField []) {VMSTATE_UINT16_V (divider, SerialState,2 ),VMSTATE_UINT8 (rbr, SerialState), +VMSTATE_UINT8_V (thr, SerialState,4 ), +VMSTATE_UINT8_V (tsr, SerialState,4 ),VMSTATE_UINT8 (ier, SerialState),VMSTATE_UINT8 (iir, SerialState),VMSTATE_UINT8 (lcr, SerialState),@@ -695,6 +726,16 @@ static const VMStateDescription vmstate_serial = {VMSTATE_UINT8 (msr, SerialState),VMSTATE_UINT8 (scr, SerialState),VMSTATE_UINT8_V (fcr_vmstate, SerialState,3 ), +VMSTATE_INT32_V (thr_ipending, SerialState,4 ), +VMSTATE_INT32_V (last_break_enable, SerialState,4 ), +VMSTATE_INT32_V (tsr_retry, SerialState,4 ), +VMSTATE_STRUCT (recv_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_STRUCT (xmit_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_TIMER_V (fifo_timeout_timer, SerialState,4 ), +VMSTATE_INT32_V (timeout_ipending, SerialState,4 ), +VMSTATE_TIMER_V (transmit_timer, SerialState,4 ), + VMSTATE_INT32_V(poll_msl, SerialState, 4),Quoted 8 lines
hw/serial.c static const VMStateDescription vmstate_serial = { · line 741
Quoted 4 lines
hw/serial.c +1
-0+VMSTATE_TIMER_V (modem_status_poll, SerialState,4 ), VMSTATE_END_OF_LIST() } };Anyways, I think that it is better to split the change in two patches. One that refactor the common code in another function. And the other that adds the VMSTATE bits, I can add the subsection part if you want.
Quoted 1 line
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
So you have to implement a handler that checks the serial state on savevm whether any of the new fields contains a state that requires to be saved. Of any of them do, we have to throw that time-traveling over board and create the subsection. If not, we can continue to write the old state. That might be the case here if the guest does not use the serial port or if the port is idle at the time of saving.
Quoted 1 line
And how to create them?
See e.g. [1] with [2] (to fix my copy&paste mistake).
Jan
[1] http://thread.gmane.org/gmane.comp.emulators.kvm.devel/74679
[2] http://thread.gmane.org/gmane.comp.emulators.kvm.devel/74685
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 130 lines
Quoted 130 lines
Quoted 21 lines
Quoted 6 lines
This patch fixes save/restore of serial interface's state. It includes changing of fcr setter function (it now does not invoke
an interrupt while loading vmstate), and saving/restoring all fields that describe the state of serial interface (including timers).Signed-off-by Pavel Dovgalyuk <[email protected]>I think we can do this with a new subsection.
Quoted 12 lines
--- hw/serial.c | 133 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 87 insertions(+), 46 deletions(-)hw/serial.c +0
-0@@ -362,6 +362,62 @@ static void serial_xmit(void *opaque) }Quoted 14 lines
hw/serial.c static void serial_xmit(void *opaque) · line 375
Quoted 11 lines
hw/serial.c +11
-0+/* Setter for FCR. +is_load flag means, that value is set while loading VM state +and interrupt should not be invoked */ +static void serial_write_fcr (void *opaque,uint32_t val,int is_load) +{ +SerialState *s = opaque; + + val = val &0xFF ; + +if (s->fcr == val) +return ;This looks like a test. if this is true, we don't need to restore the other values, so we shouldbe safe, right?
Yes, that's right.
Actually, this code is moved fromserial_ioport_writeinto separate
function. All checks and branches were not changed, only irq invocation was made conditional.Quoted 36 lines
Quoted 36 lines
hw/serial.c +36
-0+/* Did the enable/disable flag change? If so, make sure FIFOs get flushed */ +if ((val ^ s->fcr) &UART_FCR_FE ) + val |=UART_FCR_XFR |UART_FCR_RFR ; + +/* FIFO clear */ + +if (val &UART_FCR_RFR ) { +qemu_del_timer (s->fifo_timeout_timer); + s->timeout_ipending=0 ; +fifo_clear (s,RECV_FIFO ); + } + +if (val &UART_FCR_XFR ) { +fifo_clear (s,XMIT_FIFO ); + } + +if (val &UART_FCR_FE ) { + s->iir |=UART_IIR_FE ; +/* Set RECV_FIFO trigger Level */ +switch (val &0xC0 ) { +case UART_FCR_ITL_1 : + s->recv_fifo.itl =1 ; +break ; +case UART_FCR_ITL_2 : + s->recv_fifo.itl =4 ; +break ; +case UART_FCR_ITL_3 : + s->recv_fifo.itl =8 ; +break ; +case UART_FCR_ITL_4 : + s->recv_fifo.itl =14 ; +break ; + } + }else + s->iir &= ~UART_IIR_FE ; +Quoted 8 lines
hw/serial.c static void serial_xmit(void *opaque) · line 417
Quoted 5 lines
hw/serial.c +5
-0+/* Set fcr - or at least the bits in it that are supposed to "stick" */ + s->fcr = val &0xC9 ; +if (!is_load) { +serial_update_irq (s); + }we can put the
serial_update_irq()at caller site. Function is only called twice, on place need to callserial_update_irq()and the other not.Yes, you right. I didn't think about it.
Quoted 42 lines
Quoted 42 lines
hw/serial.c +26
-1+static const VMStateDescription vmstate_fifo = { + .name ="serial FIFO" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_BUFFER (data, SerialFIFO), +VMSTATE_UINT8 (count, SerialFIFO), +VMSTATE_UINT8 (itl, SerialFIFO), +VMSTATE_UINT8 (tail, SerialFIFO), +VMSTATE_UINT8 (head, SerialFIFO), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_serial = { .name ="serial" , - .version_id =3 , + .version_id =4 , .minimum_version_id =2 , .pre_save = serial_pre_save, .post_load = serial_post_load, .fields = (VMStateField []) {VMSTATE_UINT16_V (divider, SerialState,2 ),VMSTATE_UINT8 (rbr, SerialState), +VMSTATE_UINT8_V (thr, SerialState,4 ), +VMSTATE_UINT8_V (tsr, SerialState,4 ),VMSTATE_UINT8 (ier, SerialState),VMSTATE_UINT8 (iir, SerialState),VMSTATE_UINT8 (lcr, SerialState),@@ -695,6 +726,16 @@ static const VMStateDescription vmstate_serial = {VMSTATE_UINT8 (msr, SerialState),VMSTATE_UINT8 (scr, SerialState),VMSTATE_UINT8_V (fcr_vmstate, SerialState,3 ), +VMSTATE_INT32_V (thr_ipending, SerialState,4 ), +VMSTATE_INT32_V (last_break_enable, SerialState,4 ), +VMSTATE_INT32_V (tsr_retry, SerialState,4 ), +VMSTATE_STRUCT (recv_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_STRUCT (xmit_fifo, SerialState,4 , vmstate_fifo, SerialFIFO), +VMSTATE_TIMER_V (fifo_timeout_timer, SerialState,4 ), +VMSTATE_INT32_V (timeout_ipending, SerialState,4 ), + VMSTATE_TIMER_V(transmit_timer, SerialState, 4),
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/serial.c static const VMStateDescription vmstate_serial = { · line 741
Quoted 5 lines
hw/serial.c +2
-0+VMSTATE_INT32_V (poll_msl, SerialState,4 ), +VMSTATE_TIMER_V (modem_status_poll, SerialState,4 ), VMSTATE_END_OF_LIST() } };Anyways, I think that it is better to split the change in two patches. One that refactor the common code in another function. And the other
I thought about splitting. First change is not for refactoring,
it is also a bugfix of non-deterministic loading of serial interface state. Both part of my patch relate to the same problem - non-deterministic load.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
that adds the VMSTATE bits, I can add the subsection part if you want.
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
Do you have an idea how to implement "needed" function for my case?
Because I think, these fields should always be saved and loaded, because they are related to the main state of the interface, not the kind of optional substate.
Quoted 6 lines
So you have to implement a handler that checks the serial state on savevm whether any of the new fields contains a state that requires to be saved. Of any of them do, we have to throw that time-traveling over board and create the subsection. If not, we can continue to write the old state. That might be the case here if the guest does not use the serial port or if the port is idle at the time of saving.
If the port is disabled, the state will not be saved, isn't it?
Pavel Dovgaluk
Quoted 10 lines · Pavel Dovgaluk
Quoted 5 lines
Quoted 1 line
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
Do you have an idea how to implement "needed" function for my case?
Because I think, these fields should always be saved and loaded, because they are related to the main state of the interface, not the kind of optional substate.
E.g., if the fifo is empty, you do not need to save its content. That would be one part of the condition. Go through all fields and check if they have states that could be ignored or if they could be ignored if other already saved fields have specific values. If you find any new field that must always be restored, let us discuss it. It may turn out that a substate is unrealistic, then we need to go with a new version.
Quoted 9 lines
Quoted 7 lines
So you have to implement a handler that checks the serial state on savevm whether any of the new fields contains a state that requires to be saved. Of any of them do, we have to throw that time-traveling over board and create the subsection. If not, we can continue to write the old state. That might be the case here if the guest does not use the serial port or if the port is idle at the time of saving.
If the port is disabled, the state will not be saved, isn't it?
Default PC configurations contain this port. But that doesn't mean guests actively use.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
Do you have an idea how to implement "needed" function for my case?
Because I think, these fields should always be saved and loaded, because they are related to the main state of the interface, not the kind of optional substate.
Quoted 6 lines
E.g., if the fifo is empty, you do not need to save its content. That would be one part of the condition. Go through all fields and check if they have states that could be ignored or if they could be ignored if other already saved fields have specific values. If you find any new field that must always be restored, let us discuss it. It may turn out that a substate is unrealistic, then we need to go with a new version.
You mean, if FIFO is empty an will not be saved, we will have to clear
it before loading every time?
So there should be multiple subsections for every possible field? E.g. timers are saved only if they are pending, thr_ipending is saved
only when it is nonzero, and so on. Do you mean that?
Pavel Dovgaluk
Quoted 18 lines · Pavel Dovgaluk
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
Do you have an idea how to implement "needed" function for my case?
Because I think, these fields should always be saved and loaded, because they are related to the main state of the interface, not the kind of optional substate.Quoted 6 lines
E.g., if the fifo is empty, you do not need to save its content. That would be one part of the condition. Go through all fields and check if they have states that could be ignored or if they could be ignored if other already saved fields have specific values. If you find any new field that must always be restored, let us discuss it. It may turn out that a substate is unrealistic, then we need to go with a new version.
Quoted 2 lines
You mean, if FIFO is empty an will not be saved, we will have to clear
it before loading every time?
We (soon, patches posted) do a reset before every loadvm. We already do this when starting a new machine. That sets all states that aren't restored to defaults. In case of the fifo, they are all emptied.
Quoted 3 lines
So there should be multiple subsections for every possible field? E.g. timers are saved only if they are pending,
thr_ipendingis saved
only when it is nonzero, and so on. Do you mean that?
Nope, only a single subsection. Either we are able to avoid any new field under certain circumstances or we have to break the legacy format anyway.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 26 lines · Pavel Dovgaluk
Quoted 18 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
Do you have an idea how to implement "needed" function for my case?
Because I think, these fields should always be saved and loaded, because they are related to the main state of the interface, not the kind of optional substate.Quoted 6 lines
E.g., if the fifo is empty, you do not need to save its content. That would be one part of the condition. Go through all fields and check if they have states that could be ignored or if they could be ignored if other already saved fields have specific values. If you find any new field that must always be restored, let us discuss it. It may turn out that a substate is unrealistic, then we need to go with a new version.
Quoted 2 lines
You mean, if FIFO is empty an will not be saved, we will have to clear
it before loading every time?We (soon, patches posted) do a reset before every loadvm. We already do this when starting a new machine. That sets all states that aren't restored to defaults. In case of the fifo, they are all emptied.
Quoted 7 lines
Quoted 3 lines
So there should be multiple subsections for every possible field? E.g. timers are saved only if they are pending,
thr_ipendingis saved
only when it is nonzero, and so on. Do you mean that?Nope, only a single subsection. Either we are able to avoid any new field under certain circumstances or we have to break the legacy format anyway.
Fields added by my patch are not belong to single subsection. Consider THR and TSR registers:
THR:
Bit 5 in the LSR, line status register can be used to check if new information must be written to THR. The value 1 indicates that the register is empty.
TSR:
Contains data, that should be shifted out. This register is Interconnected with transmit_timer - when timer event occurs, the data is shifted out.
There are also other fields, that describe the state of the serial
interface, but cannot be directly derived from THR and TSR state.
So, there are the following ways, as I see it:
1. Make several subsections - one for every substate.
2. Make one subsection with very complex "needed" condition, which will be true, when any part of the subsection should be written. I think, that such complex condition will be too hard for testing.
3. Change version of the format.
Pavel Dovgaluk
Quoted 34 lines · Pavel Dovgaluk
Quoted 26 lines · Pavel Dovgaluk
Quoted 18 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
What is the purpose of subsections?
To skip the new fields whenever possible. That would allow to continue saving a vmstate on a new version of qemu and then restoring it on an older one.
Do you have an idea how to implement "needed" function for my case?
Because I think, these fields should always be saved and loaded, because they are related to the main state of the interface, not the kind of optional substate.Quoted 6 lines
E.g., if the fifo is empty, you do not need to save its content. That would be one part of the condition. Go through all fields and check if they have states that could be ignored or if they could be ignored if other already saved fields have specific values. If you find any new field that must always be restored, let us discuss it. It may turn out that a substate is unrealistic, then we need to go with a new version.
Quoted 2 lines
You mean, if FIFO is empty an will not be saved, we will have to clear
it before loading every time?We (soon, patches posted) do a reset before every loadvm. We already do this when starting a new machine. That sets all states that aren't restored to defaults. In case of the fifo, they are all emptied.
Quoted 7 lines
Quoted 3 lines
So there should be multiple subsections for every possible field? E.g. timers are saved only if they are pending,
thr_ipendingis saved
only when it is nonzero, and so on. Do you mean that?Nope, only a single subsection. Either we are able to avoid any new field under certain circumstances or we have to break the legacy format anyway.
Quoted 12 lines
Fields added by my patch are not belong to single subsection. Consider THR and TSR registers:
THR:
Bit 5 in the LSR, line status register can be used to check if new information must be written to THR. The value 1 indicates that the register is empty.
TSR:
Contains data, that should be shifted out. This register is Interconnected withtransmit_timer- when timer event occurs, the data is shifted out.
There are also other fields, that describe the state of the serial
interface, but cannot be directly derived from THR and TSR state.
Neither thr nor tsr are set to a specific value on reset. That indicates that both depend on other states to be valid. Looks like tsr_retry > 0 would be the condition for a tsr worth saving e.g.
Quoted 3 lines
So, there are the following ways, as I see it:
1. Make several subsections - one for every substate.
Again, that comes with no benefits.
Quoted 5 lines
2. Make one subsection with very complex "needed" condition, which will be true, when any part of the subsection should be written. I think, that such complex condition will be too hard for testing.
3. Change version of the format.
I still don't think we have found the case that requires a version change.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am 22.06.2011 um 10:58 schrieb Pavel Dovgaluk:
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
This patch fixes save/restore of serial interface's state. It includes changing of fcr setter function (it now does not
invoke
an interrupt while loading vmstate), and saving/restoring all fields that describe the state of serial interface (including timers).Signed-off-by Pavel Dovgalyuk <[email protected]>If the port is disabled, the state will not be saved, isn't it?
See the ISA reconfigurability / PReP series for a counter-example [1]. Whether the state is saved depends on whether the isa-serial qdev device is instantiated, not on whether the port is active. Therefore a subsection will be even more useful here.
Andreas