um: synchronized time-travel
Johannes Berg
maintainerRFC v3 1/2 um: virtio: implement VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
We'll prefer this feature, under the assumption that only a few (simulation) devices will ever support it, since it's not very efficient.
--- arch/um/drivers/vhost_user.h | 12 +++-- arch/um/drivers/virtio_uml.c | 85 ++++++++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 22 deletions(-)
arch/um/drivers/vhost_user.h +8 -4
@@ -10,9 +10,10 @@/* Feature bits */ #define VHOST_USER_F_PROTOCOL_FEATURES 30/* Protocol feature bits */ -#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 -#define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 -#define VHOST_USER_PROTOCOL_F_CONFIG 9 +#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 +#define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 +#define VHOST_USER_PROTOCOL_F_CONFIG 9 +#define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 13/* Vring state index masks */ #define VHOST_USER_VRING_INDEX_MASK 0xff#define VHOST_USER_VRING_POLL_MASK BIT(8)
@@ -24,7 +25,8 @@/* Supported protocol features */ #define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \ BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \ - BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG)) + BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) | \ + BIT_ULL(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS))enum vhost_user_request {VHOST_USER_GET_FEATURES =1 ,
@@ -52,12 +54,14 @@ enum vhost_user_request {VHOST_USER_SET_VRING_ENDIAN =23 ,VHOST_USER_GET_CONFIG =24 ,VHOST_USER_SET_CONFIG =25 , + VHOST_USER_VRING_KICK = 34, };enum vhost_user_slave_request {VHOST_USER_SLAVE_IOTLB_MSG =1 ,VHOST_USER_SLAVE_CONFIG_CHANGE_MSG =2 ,VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3 , +VHOST_USER_SLAVE_VRING_CALL =4 , }; struct vhost_user_header {
arch/um/drivers/virtio_uml.c +67 -18
173 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerv3 cover um: synchronized time-travel
This seems to work now. On top of qemu, I have the following patches:
https://lore.kernel.org/qemu-devel/[email protected]/
https://lore.kernel.org/qemu-devel/[email protected]/
https://lore.kernel.org/qemu-devel/[email protected]/
https://lore.kernel.org/qemu-devel/[email protected]/
https://lore.kernel.org/qemu-devel/[email protected]/
https://lore.kernel.org/qemu-devel/[email protected]/
https://lore.kernel.org/qemu-devel/[email protected]/
And 'make vhost-user-sim' builds a program there that speaks the UML simulation time protocol and implements a virtual ethernet network.
With all the patches I sent to UML, I have a start script like this:
-------------
#!/bin/sh
~/hwsim/qemu/vhost-user-sim -s /tmp/clock -n /tmp/net 2>&1 | tee /tmp/sim.log &
(sleep 0.5 ; /path/to/linux mem=128M init=$(pwd)/test.sh root=none \
hostfs=/ rootfstype=hostfs rootflags=/ \
time-travel=ext:/tmp/clock \
virtio_uml.device=/tmp/net:1 >/tmp/log1) &
(sleep 1.5 ; /path/to/linux mem=128M init=$(pwd)/test2.sh root=none \
hostfs=/ rootfstype=hostfs rootflags=/ \
time-travel=ext:/tmp/clock \
virtio_uml.device=/tmp/net:1 >/tmp/log1) &wait
wait
wait
-------------
where test.sh contains
-------------
#!/bin/bash
start=$(date +%s)
ip link set eth0 up
ip addr add 10.0.0.1/24 dev eth0
ping -D -n -i 10 -c 61 10.0.0.2
end=$(date +%s)
duration=$(($end - $start))
min=$(($duration / 60))
sec=$(($duration % 60))
echo "================= runtime observed inside VM ${min}m ${sec}s =================" poweroff -f
-------------
and test2.sh contains
-------------
#!/bin/sh
ip link set eth0 up
ip addr add 10.0.0.2/24 dev eth0
tcpdump -n -e -i eth0 &
sleep 660
poweroff -f
-------------
This then results in a network of two machines where one pings the other, and the virtual network currently implements exactly 50ms delay.
There are some bugs in the userspace side, it doesn't handle nested requests correctly and can lock up, that's why I have the different sleeps in there. However, I'll need to pivot a bit and write integration to the simulation that I really need this to work with, so I still wanted to get this out. I may not fix those userspace bugs, but it's still a sample program for this.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRFC v3 2/2 um: implement time-travel=ext
From: Johannes Berg <[email protected]>
This implements synchronized time-travel mode which - using a special application on a unix socket - lets multiple machines take part in a time-travelling simulation together.
The protocol for the unix domain socket is defined in the new file include/uapi/linux/um_timetravel.h.
--- arch/um/drivers/virtio_uml.c | 59 +++++- arch/um/include/linux/time-internal.h | 28 +++ arch/um/include/shared/os.h | 1 + arch/um/kernel/skas/syscall.c | 3 +- arch/um/kernel/time.c | 256 +++++++++++++++++++++++++- arch/um/os-Linux/file.c | 30 +++ include/uapi/linux/um_timetravel.h | 107 +++++++++++ 7 files changed, 472 insertions(+), 12 deletions(-) create mode 100644 include/uapi/linux/um_timetravel.h
arch/um/drivers/virtio_uml.c +58 -1
@@ -26,6 +26,7 @@#include <linux/virtio.h> #include <linux/virtio_config.h> #include <linux/virtio_ring.h> +#include <linux/time-internal.h> #include <shared/as-layout.h> #include <irq_kern.h> #include <init.h>
@@ -67,6 +68,11 @@ struct virtio_uml_device {struct virtio_uml_vq_info {int kick_fd, call_fd;char name[32 ]; +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +struct virtqueue *vq; +vq_callback_t *callback; +struct time_travel_event defer; +#endif };extern unsigned long long physmem_size, highmem;
@@ -124,7 +130,23 @@ static int vhost_user_recv(struct virtio_uml_device *vu_dev, size_t max_payload_size) {size_t size; -int rc =vhost_user_recv_header (fd, msg); +int rc; + +/* +* In virtio time-travel mode, we're handling all the vhost-user +* FDs by polling them whenever appropriate. However, we may get +* into a situation where we're sending out an interrupt message +* to a device (e.g. a net device) and need to handle a simulation +* time message while doing so, e.g. one that tells us to update +* our idea of how long we can run without scheduling. +* +* Thus, we need to not just read() from the given fd, but need +* to also handle messages for the simulation time - this function +* does that for us while waiting for the given fd to be readable. +*/ +time_travel_wait_readable (fd); + + rc =vhost_user_recv_header (fd, msg);if (rc == -ECONNRESET ) {struct virtio_uml_platform_data *pdata;
@@ -708,6 +730,8 @@ static bool vu_notify(struct virtqueue *vq)const uint64_t n =1 ;int rc; +time_travel_propagate_time (); +if (info->kick_fd <0 ) {struct virtio_uml_device *vu_dev;
@@ -855,6 +879,23 @@ static int vu_setup_vq_call_fd(struct virtio_uml_device *vu_dev,return rc; } +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +static void vu_defer_irq_handle (struct time_travel_event *d) +{ +struct virtio_uml_vq_info *info; + + info = container_of(d, struct virtio_uml_vq_info, defer); + info->callback (info->vq); +} + +static void vu_defer_irq_callback (struct virtqueue *vq) +{ +struct virtio_uml_vq_info *info = vq->priv; + +time_travel_add_irq_event (&info->defer); +} +#endif +static struct virtqueue *vu_setup_vq (struct virtio_device *vdev,unsigned index,vq_callback_t *callback,const char *name,bool ctx)
@@ -874,6 +915,19 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev,snprintf (info->name,sizeof (info->name),"%s.%d-%s" , pdev->name, pdev->id, name); +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +/* +* When we get an interrupt, we must bounce it through the simulation +* calendar (the simtime device), except for the simtime device itself +* since that's part of the simulation control. +*/ +if (time_travel_mode ==TT_MODE_EXTERNAL ) { + info->callback = callback; + callback = vu_defer_irq_callback; +time_travel_set_event_fn (&info->defer, vu_defer_irq_handle); + } +#endif + vq =vring_create_virtqueue (index, num,PAGE_SIZE , vdev, true, true, ctx, vu_notify, callback, info->name);if (!vq) {
@@ -882,6 +936,9 @@ static struct virtqueue *vu_setup_vq(struct virtio_device *vdev, } vq->priv = info; num =virtqueue_get_vring_size (vq); +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT + info->vq = vq; +#endif if (vu_dev->protocol_features &BIT_ULL (VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS )) {
arch/um/include/linux/time-internal.h +28 -0
@@ -7,6 +7,7 @@#ifndef __TIMER_INTERNAL_H__#define __TIMER_INTERNAL_H__#include <linux/list.h> +#include <linux/interrupt.h> #define TIMER_MULTIPLIER 256#define TIMER_MIN_DELTA 500
@@ -15,6 +16,7 @@ enum time_travel_mode {TT_MODE_OFF ,TT_MODE_BASIC ,TT_MODE_INFCPU , + TT_MODE_EXTERNAL, };#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT
@@ -35,6 +37,24 @@ time_travel_set_event_fn(struct time_travel_event *e, { e->fn = fn; } + +void __time_travel_propagate_time (void ); + +static inline void time_travel_propagate_time (void ) +{ +if (time_travel_mode ==TT_MODE_EXTERNAL ) +__time_travel_propagate_time (); +} + +void __time_travel_wait_readable (int fd); + +static inline void time_travel_wait_readable (int fd) +{ +if (time_travel_mode ==TT_MODE_EXTERNAL ) +__time_travel_wait_readable (fd); +} + +void time_travel_add_irq_event (struct time_travel_event *e);#else struct time_travel_event { };
@@ -47,5 +67,13 @@ static inline void time_travel_sleep(unsigned long long duration)/* this is a macro so the event/function need not exist */ #define time_travel_set_event_fn (e, fn) do {} while (0) + +static inline void time_travel_propagate_time (void ) +{ +} + +static inline void time_travel_wait_readable (int fd) +{ +}#endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */ #endif /* __TIMER_INTERNAL_H__ */
arch/um/include/shared/os.h +1 -0
@@ -181,6 +181,7 @@ extern int os_falloc_punch(int fd, unsigned long long offset, int count);extern int os_eventfd (unsigned int initval,int flags);extern int os_sendmsg_fds (int fd,const void *buf,unsigned int len,const int *fds,unsigned int fds_num); +int os_poll (unsigned int n,const int *fds);/* start_up.c */ extern void os_early_checks (void );
arch/um/kernel/skas/syscall.c +2 -1
@@ -24,7 +24,8 @@ void handle_syscall(struct uml_pt_regs *r)* went to sleep, even if said userspace interacts with the kernel in * various ways. */ -if (time_travel_mode ==TT_MODE_INFCPU ) +if (time_travel_mode ==TT_MODE_INFCPU || + time_travel_mode ==TT_MODE_EXTERNAL )schedule ();/* Initialize the syscall number and default return value. */
arch/um/kernel/time.c +246 -10
361 lines not on this page · raw message
arch/um/os-Linux/file.c +30 -0
@@ -5,6 +5,7 @@#include <stdio.h> #include <unistd.h> +#include <stdlib.h> #include <errno.h> #include <fcntl.h> #include <signal.h>
@@ -16,6 +17,7 @@#include <sys/un.h> #include <sys/types.h> #include <sys/eventfd.h> +#include <poll.h> #include <os.h> static void copy_stat (struct uml_stat *dst,const struct stat64 *src)
@@ -664,3 +666,31 @@ int os_sendmsg_fds(int fd, const void *buf, unsigned int len, const int *fds,return -errno;return err; } + +int os_poll (unsigned int n,const int *fds) +{ +/* currently need 2 FDs at most so avoid dynamic allocation */ +struct pollfd pollfds[2 ] = {}; +unsigned int i; +int ret; + +if (n >ARRAY_SIZE (pollfds)) +return -EINVAL ; + +for (i =0 ; i < n; i++) { + pollfds[i].fd = fds[i]; + pollfds[i].events =POLLIN ; + } + + ret =poll (pollfds, n,-1 ); +if (ret <0 ) +return -errno; + +/* Return the index of the available FD */ +for (i =0 ; i < n; i++) { +if (pollfds[i].revents) +return i; + } + +return -EIO ; +}
include/uapi/linux/um_timetravel.h new file +107 -0
107 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v3 1/2] um: virtio: implement VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS
In reply to Johannes BergQuoted 5 lines · Johannes Berg
From: Johannes Berg <[email protected]>
We'll prefer this feature, under the assumption that only a few (simulation) devices will ever support it, since it's not very efficient.
This is mostly RFC because the spec changes to vhost-user haven't really been accepted. I reposted them earlier and hopefully addressed all the concerns there, but who knows ...
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v3 2/2] um: implement time-travel=ext
In reply to Johannes Bergarch/um/drivers/virtio_uml.c struct virtio_uml_device { · line 75
Quoted 9 lines · Johannes Berg
struct
virtio_uml_vq_info{arch/um/drivers/virtio_uml.c +5
-0int kick_fd, call_fd;char name[32 ]; +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +struct virtqueue *vq; +vq_callback_t *callback; +struct time_travel_event defer; +#endif
There's a bit of a question here - should I put all these ifdefs?
It *should* compile fine without them, and throw away the unused functions, but this structure will still be bigger, and the vq initialization will still be done. Everything else should go away since time_travel_mode is tested (and is defined to NONE) / empty inlines are called if CONFIG_UML_TIME_TRAVEL_SUPPORT isn't set.
Though, come to think of it, I probably broke modular builds again here.
Anyway, I won't send a new version soon I think, comments welcome and I'll see how the qemu changes progress.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v3 2/2] um: implement time-travel=ext
In reply to Johannes BergForgot to say though - overall I'm MUCH happier with this than with the virtio-based device. It's about 30% faster (as I said before), and both sides of the communication channel are significantly less complex.
In particular, also, we need much less changes to virtio_uml.c since we can still rely on getting signals and -EINTR in poll() even while we talk over the timing channel but get a virtio message.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Re: [RFC v3 2/2] um: implement time-travel=ext
In reply to Johannes BergQuoted 11 lines · Johannes Berg
arch/um/drivers/virtio_uml.c struct virtio_uml_device { · line 75
Quoted 8 lines · Johannes Berg
struct virtio_uml_vq_info { int kick_fd, call_fd; char name[32];arch/um/drivers/virtio_uml.c +5
-0+#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +struct virtqueue *vq; +vq_callback_t *callback; +struct time_travel_event defer; +#endif There's a bit of a question here - should I put all these ifdefs?
Quoted 7 lines
It *should* compile fine without them, and throw away the unused functions, but this structure will still be bigger, and the vq initialization will still be done. Everything else should go away since
time_travel_modeis tested (and is defined to NONE) / empty inlines are called ifCONFIG_UML_TIME_TRAVEL_SUPPORTisn't set.Though, come to think of it, I probably broke modular builds again here.
:)
Quoted 3 lines
Anyway, I won't send a new version soon I think, comments welcome and I'll see how the qemu changes progress.
As I said - I am going to wait for Richard's next PR so I have a settled tree and I will get on with testing. I should have a bit more time then as well as ONS Europe will be out of the way. At the moment all of my time is being eaten by various k8 related stuff for that.
Quoted 9 lines
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 8 lines
Anton R. Ivanov https://www.kot-begemot.co.uk/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [RFC v3 2/2] um: implement time-travel=ext
Quoted 3 lines · Anton Ivanov
Quoted 1 line
Though, come to think of it, I probably broke modular builds again here.
:)
I'll fix it later, or maybe I'll just prohibit it, though there isn't really a strict reason to other than not having to sprinkle EXPORT_SYMBOL all over.
Quoted 7 lines
Quoted 2 lines
Anyway, I won't send a new version soon I think, comments welcome and I'll see how the qemu changes progress.
As I said - I am going to wait for Richard's next PR so I have a settled tree and I will get on with testing. I should have a bit more time then as well as ONS Europe will be out of the way. At the moment all of my time is being eaten by various k8 related stuff for that.
Sure, thanks. I'll keep rebasing this as that happens too, maybe I should publish a git tree on kernel.org for it?
Not that I really expect you to (want to) test all the time-travel stuff, it seems like a fairly niche feature :-)
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um