um: external time travel
Subsystems (2)
Johannes Berg
maintainercover um: external time travel
Hi,
Here's a respin of this - I've been testing this for a few weeks (and some of it months) now and things are working really well, so I think it's *almost* ready to go.
The only problem is patch 3 - the vhost-user spec changes *still* haven't gotten merged :-(
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerPATCH 1/6 um: move timer-internal.h to non-shared
From: Johannes Berg <[email protected]>
This file isn't really shared, it's only used on the kernel side, not on the user side. Remove the include from the user-side and move the file to a better place.
While at it, rename it to time-internal.h, it's not really just timers but all kinds of things related to timekeeping.
Reviewed-on: https://git-ger-8.devtools.intel.com/gerrit/96864
---
.../include/{shared/timer-internal.h => linux/time-internal.h} | 0
arch/um/kernel/process.c | 2 +-
arch/um/kernel/skas/syscall.c | 2 +-
arch/um/kernel/time.c | 2 +-
arch/um/os-Linux/time.c | 1 -
5 files changed, 3 insertions(+), 4 deletions(-)
rename arch/um/include/{shared/timer-internal.h => linux/time-internal.h} (100%)arch/um/include/linux/time-internal.h renamed from arch/um/include/shared/timer-internal.h +0 -0
arch/um/kernel/process.c +1 -1
@@ -32,7 +32,7 @@#include <kern_util.h> #include <os.h> #include <skas.h> -#include <timer-internal.h> +#include <linux/time-internal.h> /* * This is a per-cpu array. A processor only modifies its entry and it only
arch/um/kernel/skas/syscall.c +1 -1
@@ -10,7 +10,7 @@#include <sysdep/ptrace.h> #include <sysdep/ptrace_user.h> #include <sysdep/syscalls.h> -#include <shared/timer-internal.h> +#include <linux/time-internal.h> void handle_syscall (struct uml_pt_regs *r) {
arch/um/kernel/time.c +1 -1
@@ -18,7 +18,7 @@#include <asm/param.h> #include <kern_util.h> #include <os.h> -#include <timer-internal.h> +#include <linux/time-internal.h> #include <shared/init.h> #ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT
arch/um/os-Linux/time.c +0 -1
@@ -14,7 +14,6 @@#include <kern_util.h> #include <os.h> #include <string.h> -#include <timer-internal.h> static timer_t event_high_res_timer =0 ;
Signature · 7 lines
2.24.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerPATCH 2/6 um: time-travel: rewrite as an event scheduler
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Instead of tracking all the various timer configurations, modify the time-travel mode to have an event scheduler and use a timer event on the scheduler to handle the different timer configurations.
This doesn't change the function right now, but it prepares the code for having different kinds of events in the future (i.e. interrupts coming from other devices that are part of co-simulation.)
While at it, also move time_travel_sleep() to time.c to reduce the externally visible API surface.
Also, we really should mark time-travel as incompatible with SMP, even if UML doesn't support SMP yet.
Finally, I noticed a bug while developing this - if we move time forward due to consuming time while reading the clock, we might move across the next event and that would cause us to go backward in time when we then handle that event. Fix that by invoking the whole event machine in this case, but in order to simplify this, make reading the clock only cost something when interrupts are not disabled. Otherwise, we'd have to hook into the interrupt delivery machinery etc. and that's somewhat intrusive.
Reviewed-on: https://git-ger-8.devtools.intel.com/gerrit/96865
--- arch/um/Kconfig | 1 + arch/um/include/linux/time-internal.h | 65 +++----- arch/um/kernel/process.c | 37 ----- arch/um/kernel/time.c | 221 ++++++++++++++++++++++++-- 4 files changed, 229 insertions(+), 95 deletions(-)
arch/um/Kconfig +1 -0
@@ -191,6 +191,7 @@ config UML_TIME_TRAVEL_SUPPORT prompt "Support time-travel mode (e.g. for test execution)" # inf-cpu mode is incompatible with the benchmarking depends on !RAID6_PQ_BENCHMARK + depends on !SMP help Enable this option to support time travel inside the UML instance.
arch/um/include/linux/time-internal.h +20 -45
87 lines not on this page · raw message
arch/um/kernel/process.c +0 -37
@@ -203,43 +203,6 @@ void initial_thread_cb(void (*proc)(void *), void *arg) kmalloc_ok = save_kmalloc_ok; } -static void time_travel_sleep (unsigned long long duration) -{ -unsigned long long next = time_travel_time + duration; - -if (time_travel_mode !=TT_MODE_INFCPU ) -os_timer_disable (); - -while (time_travel_timer_mode ==TT_TMR_PERIODIC && - time_travel_timer_expiry < time_travel_time) -time_travel_set_timer_expiry (time_travel_timer_expiry + - time_travel_timer_interval); - -if (time_travel_timer_mode !=TT_TMR_DISABLED && - time_travel_timer_expiry < next) { -if (time_travel_timer_mode ==TT_TMR_ONESHOT ) -time_travel_set_timer_mode (TT_TMR_DISABLED ); -/* -* In basic mode, time_travel_time will be adjusted in -* the timer IRQ handler so it works even when the signal -* comes from the OS timer, see there. -*/ -if (time_travel_mode !=TT_MODE_BASIC ) -time_travel_set_time (time_travel_timer_expiry); - -deliver_alarm (); - }else { -time_travel_set_time (next); - } - -if (time_travel_mode !=TT_MODE_INFCPU ) { -if (time_travel_timer_mode ==TT_TMR_PERIODIC ) -os_timer_set_interval (time_travel_timer_interval); -else if (time_travel_timer_mode ==TT_TMR_ONESHOT ) -os_timer_one_shot (time_travel_timer_expiry - next); - } -} -static void um_idle_sleep (void ) {unsigned long long duration =UM_NSEC_PER_SEC ;
arch/um/kernel/time.c +208 -13
268 lines not on this page · raw message
Signature · 7 lines
2.24.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerPATCH 3/6 um: virtio: implement VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Implement in-band notifications that are necessary for running vhost-user devices under externally synchronized time-travel mode (which is in a follow-up patch). This feature makes what usually should be eventfd notifications in-band messages.
We'll prefer this feature, under the assumption that only a few (simulation) devices will ever support it, since it's not very efficient.
Reviewed-on: https://git-ger-8.devtools.intel.com/gerrit/96454
--- 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 14/* 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 = 35, };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.24.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerPATCH 4/6 um: implement time-travel=ext
In reply to Johannes BergFrom: 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 | 68 +++++- arch/um/include/linux/time-internal.h | 27 +++ arch/um/include/shared/os.h | 1 + arch/um/kernel/skas/syscall.c | 3 +- arch/um/kernel/time.c | 323 +++++++++++++++++++++++++- arch/um/os-Linux/file.c | 30 +++ include/uapi/linux/um_timetravel.h | 128 ++++++++++ 7 files changed, 563 insertions(+), 17 deletions(-) create mode 100644 include/uapi/linux/um_timetravel.h
arch/um/drivers/virtio_uml.c +64 -4
@@ -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>
@@ -64,6 +65,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;
@@ -118,10 +124,27 @@ static int vhost_user_recv_header(int fd, struct vhost_user_msg *msg)static int vhost_user_recv (struct virtio_uml_device *vu_dev,int fd,struct vhost_user_msg *msg, -size_t max_payload_size) +size_t max_payload_size,bool wait) {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. +*/ +if (wait) +time_travel_wait_readable (fd); + + rc =vhost_user_recv_header (fd, msg);if (rc == -ECONNRESET && vu_dev->registered) {struct virtio_uml_platform_data *pdata;
@@ -143,7 +166,8 @@ static int vhost_user_recv_resp(struct virtio_uml_device *vu_dev,struct vhost_user_msg *msg, size_t max_payload_size) { - int rc = vhost_user_recv(vu_dev, vu_dev->sock, msg, max_payload_size); + int rc = vhost_user_recv(vu_dev, vu_dev->sock, msg, + max_payload_size, true);if (rc)return rc;
@@ -173,7 +197,8 @@ static int vhost_user_recv_req(struct virtio_uml_device *vu_dev,struct vhost_user_msg *msg, size_t max_payload_size) { - int rc = vhost_user_recv(vu_dev, vu_dev->req_fd, msg, max_payload_size); + int rc = vhost_user_recv(vu_dev, vu_dev->req_fd, msg, + max_payload_size, false);if (rc)return rc;
@@ -700,6 +725,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;
@@ -847,6 +874,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)
@@ -866,6 +910,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 && callback) { + 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) {
@@ -874,6 +931,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 +27 -0
@@ -15,6 +15,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 +36,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 +66,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 +311 -12
445 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 +128 -0
128 lines not on this page · raw message
Signature · 7 lines
2.24.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH 4/6] um: implement time-travel=ext
Hello,
Quoted 6 lines · Johannes Berg
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.
I was wondering if the source code of the special application (central scheduler?) is public (or not) so that we can test on a local machine.
thanks,
-- Hajime
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH 4/6] um: implement time-travel=ext
Hi,
Quoted 5 lines
Quoted 2 lines
The protocol for the unix domain socket is defined in the new file
include/uapi/linux/um_timetravel.h.I was wondering if the source code of the special application (central scheduler?) is public (or not) so that we can test on a local machine.
So ... sadly, it's a bit of a sad story right now.
I have one, but it's part of a bigger testing framework that we wrote (and uses the infrastructure from it), that I haven't been able to release so far.
On this tool, conceptually, the code is very simple, just keep a sorted "next event" list, and tell the next one that it's their turn.
For a vhost-user device implementation, it's a bit more complex, as it needs to be able to handle scheduler messages while waiting for a vhost- user ACK message, similar to what you can see in the UML vhost-user code.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH 4/6] um: implement time-travel=ext
Hello,
Quoted 11 lines · Johannes Berg
Quoted 5 lines
Quoted 2 lines
The protocol for the unix domain socket is defined in the new file
include/uapi/linux/um_timetravel.h.I was wondering if the source code of the special application (central scheduler?) is public (or not) so that we can test on a local machine.
So ... sadly, it's a bit of a sad story right now.
I have one, but it's part of a bigger testing framework that we wrote (and uses the infrastructure from it), that I haven't been able to release so far.
I understand. Thanks for telling this.
Quoted 2 lines
On this tool, conceptually, the code is very simple, just keep a sorted "next event" list, and tell the next one that it's their turn.
I can imagine how it looks like, as I was doing a similar integration with kernel code and ns-3 network simulator (which isn't LKL).
This is just my 2 cents (and may be out of topic for the patch review); it would be nice to have an example code of this external program. Since the program is independent from arch/um, this is a great opportunity to extend in future.
One might wish to implement his/her own scheduler for particular purpose; for instance, a randomized error injection into time progress to exercise or fuzzing the Linux implementation, or alternate external program that can handle multiple UML instances across different nodes (it this already possible?).
In such case, having a reference implementation would be helpful.
Quoted 4 lines
For a vhost-user device implementation, it's a bit more complex, as it needs to be able to handle scheduler messages while waiting for a vhost- user ACK message, similar to what you can see in the UML vhost-user code.
Let me try to look at the code.
-- Hajime
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH 4/6] um: implement time-travel=ext
Quoted 11 lines
Quoted 3 lines
On this tool, conceptually, the code is very simple, just keep a sorted "next event" list, and tell the next one that it's their turn.
I can imagine how it looks like, as I was doing a similar integration with kernel code and ns-3 network simulator (which isn't LKL).
This is just my 2 cents (and may be out of topic for the patch review); it would be nice to have an example code of this external program. Since the program is independent from
arch/um, this is a great opportunity to extend in future.
Right.
Quoted 5 lines
One might wish to implement his/her own scheduler for particular purpose; for instance, a randomized error injection into time progress to exercise or fuzzing the Linux implementation, or alternate external program that can handle multiple UML instances across different nodes (it this already possible?).
It's all unix domain sockets now, so no network transparency. Wouldn't really be hard to make it speak the same protocol over a TCP socket though, but for UML it seemed a bit beside the point.
Quoted 1 line
In such case, having a reference implementation would be helpful.
Agree, I'm trying to see how I can get something released.
Perhaps it could be acceptable in the kernel itself, under the tools folder?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerPATCH 5/6 um: implement ndelay/udelay in time-travel mode
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
In external or inf-cpu time-travel mode, ndelay/udelay currently just waste CPU time since the simulation time doesn't advance. Implement them properly in this case.
Note that the "if (time_travel_mode == ...)" parts compile out if CONFIG_UML_TIME_TRAVEL_SUPPORT isn't set, time_travel_mode is defined to TT_MODE_OFF in that case.
--- arch/um/include/asm/Kbuild | 1 - arch/um/include/asm/delay.h | 30 +++++++++++++++++++++++++++ arch/um/include/linux/time-internal.h | 6 ++++++ arch/um/kernel/time.c | 6 ++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 arch/um/include/asm/delay.h
arch/um/include/asm/Kbuild +0 -1
@@ -3,7 +3,6 @@ generic-y += bpf_perf_event.h generic-y += bug.h generic-y += compat.h generic-y += current.h -generic-y += delay.h generic-y += device.h generic-y += emergency-restart.h generic-y += exec.h
arch/um/include/asm/delay.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_DELAY_H +#define __UM_DELAY_H +#include <asm-generic/delay.h> +#include <linux/time-internal.h> + +static inline void um_ndelay (unsigned long nsecs) +{ +if (time_travel_mode ==TT_MODE_INFCPU || + time_travel_mode ==TT_MODE_EXTERNAL ) { +time_travel_ndelay (nsecs); +return ; + } +ndelay (nsecs); +} +#undef ndelay +#define ndelay um_ndelay + +static inline void um_udelay (unsigned long usecs) +{ +if (time_travel_mode ==TT_MODE_INFCPU || + time_travel_mode ==TT_MODE_EXTERNAL ) { +time_travel_ndelay (1000 * usecs); +return ; + } +udelay (usecs); +} +#undef udelay +#define udelay um_udelay +#endif /* __UM_DELAY_H */
arch/um/include/linux/time-internal.h +6 -0
@@ -75,4 +75,10 @@ static inline void time_travel_wait_readable(int fd) { }#endif /* CONFIG_UML_TIME_TRAVEL_SUPPORT */ + +/* +* Without CONFIG_UML_TIME_TRAVEL_SUPPORT this is a linker error if used, +* which is intentional since we really shouldn't link it in that case. +*/ +void time_travel_ndelay (unsigned long nsec);#endif /* __TIMER_INTERNAL_H__ */
arch/um/kernel/time.c +6 -0
@@ -374,6 +374,12 @@ static void time_travel_update_time(unsigned long long next, bool idle)time_travel_del_event (&ne); } +void time_travel_ndelay (unsigned long nsec) +{ +time_travel_update_time (time_travel_time + nsec, false); +} +EXPORT_SYMBOL (time_travel_ndelay); +void time_travel_add_irq_event (struct time_travel_event *e) {BUG_ON (time_travel_mode !=TT_MODE_EXTERNAL );
Signature · 7 lines
2.24.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerPATCH 6/6 um: implement cpu_relax() as ndelay(1) for time-travel
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
In time-travel mode, cpu_relax() currently does actual CPU relax, but that doesn't affect the simulation. Ideally, we wouldn't run anything that uses it in simulation, but if we actually have virtio devices combined with the same simulation it's possible. Implement cpu_relax() as ndelay(1) in this case, using time_travel_ndelay(1) directly to catch errors if this is used erroneously in builds that don't set CONFIG_UML_TIME_TRAVEL_SUPPORT.
While at it, convert it to an __always_inline and also add that to rep_nop() like the original does now.
--- arch/x86/um/asm/processor.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/x86/um/asm/processor.h +10 -2
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __UM_PROCESSOR_H#define __UM_PROCESSOR_H +#include <linux/time-internal.h> /* include faultinfo structure */ #include <sysdep/faultinfo.h>
@@ -21,12 +22,19 @@#include <asm/user.h> /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ -static inline void rep_nop (void ) +static __always_inline void rep_nop(void) { __asm__ __volatile__("rep;nop" : : :"memory" ); } -#define cpu_relax () rep_nop() +static __always_inline void cpu_relax(void) +{ +if (time_travel_mode ==TT_MODE_INFCPU || + time_travel_mode ==TT_MODE_EXTERNAL ) +time_travel_ndelay (1 ); +else +rep_nop (); +}#define task_pt_regs (t) (&(t)->thread.regs)
Signature · 7 lines
2.24.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Quoted 9 lines · Johannes Berg
Hi,
Here's a respin of this - I've been testing this for a few weeks (and some of it months) now and things are working really well, so I think it's *almost* ready to go.
The only problem is patch 3 - the vhost-user spec changes *still* haven't gotten merged :-(
Since the vhost-user spec is now merged in qemu we can also merge this. :-) I removed all internal commit tags.
Signature · 7 lines
Thanks, //richard _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um