I was using the send/dump feature and noticed that when restoring a
guest that the console connection would "stutter." (Wasn't printing
fully without hitting return.)

The following diff properly restores the vm_pipe structures for the
uart, pit, and rtc devices when using `vmctl receive`. The pipe readable
event is now removed during calls a device's *_stop() function since it
needs to be re-added in calls to *_start().

I also reordered the device restore logic for the emulated ns8250 so it
more closely resembles the initialization logic to make it easier to
debug in the future.

-Dave


Index: usr.sbin/vmd/i8253.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/i8253.c,v
retrieving revision 1.32
diff -u -p -r1.32 i8253.c
--- usr.sbin/vmd/i8253.c        28 Jun 2020 16:52:45 -0000      1.32
+++ usr.sbin/vmd/i8253.c        22 Mar 2021 02:41:58 -0000
@@ -412,6 +412,9 @@ i8253_restore(int fd, uint32_t vm_id)
                    &i8253_channel[i]);
                i8253_reset(i);
        }
+
+       vm_pipe_init(&dev_pipe, i8253_pipe_dispatch);
+
        return (0);
 }

@@ -421,6 +424,7 @@ i8253_stop()
        int i;
        for (i = 0; i < 3; i++)
                evtimer_del(&i8253_channel[i].timer);
+       event_del(&dev_pipe.read_ev);
 }

 void
@@ -430,4 +434,5 @@ i8253_start()
        for (i = 0; i < 3; i++)
                if (i8253_channel[i].in_use)
                        i8253_reset(i);
+       event_add(&dev_pipe.read_ev, NULL);
 }
Index: usr.sbin/vmd/mc146818.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/mc146818.c,v
retrieving revision 1.22
diff -u -p -r1.22 mc146818.c
--- usr.sbin/vmd/mc146818.c     28 Jun 2020 16:52:45 -0000      1.22
+++ usr.sbin/vmd/mc146818.c     22 Mar 2021 02:41:58 -0000
@@ -368,6 +368,9 @@ mc146818_restore(int fd, uint32_t vm_id)
        memset(&rtc.per, 0, sizeof(struct event));
        evtimer_set(&rtc.sec, rtc_fire1, NULL);
        evtimer_set(&rtc.per, rtc_fireper, (void *)(intptr_t)rtc.vm_id);
+
+       vm_pipe_init(&dev_pipe, mc146818_pipe_dispatch);
+
        return (0);
 }

@@ -376,11 +379,13 @@ mc146818_stop()
 {
        evtimer_del(&rtc.per);
        evtimer_del(&rtc.sec);
+       event_del(&dev_pipe.read_ev);
 }

 void
 mc146818_start()
 {
        evtimer_add(&rtc.sec, &rtc.sec_tv);
+       event_add(&dev_pipe.read_ev, NULL);
        rtc_reschedule_per();
 }
Index: usr.sbin/vmd/ns8250.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/ns8250.c,v
retrieving revision 1.29
diff -u -p -r1.29 ns8250.c
--- usr.sbin/vmd/ns8250.c       28 Jun 2020 16:52:45 -0000      1.29
+++ usr.sbin/vmd/ns8250.c       22 Mar 2021 02:41:58 -0000
@@ -694,9 +694,7 @@ ns8250_restore(int fd, int con_fd, uint3
        com1_dev.byte_out = 0;
        com1_dev.regs.divlo = 1;
        com1_dev.baudrate = 115200;
-       com1_dev.rate_tv.tv_usec = 10000;
        com1_dev.pause_ct = (com1_dev.baudrate / 8) / 1000 * 10;
-       evtimer_set(&com1_dev.rate, ratelimit, NULL);

        event_set(&com1_dev.event, com1_dev.fd, EV_READ | EV_PERSIST,
            com_rcv_event, (void *)(intptr_t)vmid);
@@ -704,6 +702,12 @@ ns8250_restore(int fd, int con_fd, uint3
        event_set(&com1_dev.wake, com1_dev.fd, EV_WRITE,
            com_rcv_event, (void *)(intptr_t)vmid);

+       timerclear(&com1_dev.rate_tv);
+       com1_dev.rate_tv.tv_usec = 10000;
+       evtimer_set(&com1_dev.rate, ratelimit, NULL);
+
+       vm_pipe_init(&dev_pipe, ns8250_pipe_dispatch);
+
        return (0);
 }

@@ -712,6 +716,7 @@ ns8250_stop()
 {
        if(event_del(&com1_dev.event))
                log_warn("could not delete ns8250 event handler");
+       event_del(&dev_pipe.read_ev);
        evtimer_del(&com1_dev.rate);
 }

@@ -720,5 +725,6 @@ ns8250_start()
 {
        event_add(&com1_dev.event, NULL);
        event_add(&com1_dev.wake, NULL);
+       event_add(&dev_pipe.read_ev, NULL);
        evtimer_add(&com1_dev.rate, &com1_dev.rate_tv);
 }

Reply via email to