Skip to content

Commit 6555acd

Browse files
gomordjmberg-intel
authored andcommitted
um: time-travel: support time-travel protocol broadcast messages
Add a message type to the time-travel protocol to broadcast a small (64-bit) value to all participants in a simulation. The main use case is to have an identical message come to all participants in a simulation, e.g. to separate out logs for different tests running in a single simulation. Down in the guts of time_travel_handle_message() we can't use printk() and not even printk_deferred(), so just store the message and print it at the start of the userspace() function. Unfortunately this means that other prints in the kernel can actually bypass the message, but in most cases where this is used, for example to separate test logs, userspace will be involved. Also, even if we could use printk_deferred(), we'd still need to flush it out in the userspace() function since otherwise userspace messages might cross it. As a result, this is a reasonable compromise, there's no need to have any core changes and it solves the main use case we have for it. Signed-off-by: Mordechay Goodstein <[email protected]> Link: https://patch.msgid.link/20240702192118.c4093bc5b15e.I2ca8d006b67feeb866ac2017af7b741c9e06445a@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent 267ed02 commit 6555acd

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

arch/um/include/shared/timetravel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@ enum time_travel_mode {
1515
#if defined(UML_CONFIG_UML_TIME_TRAVEL_SUPPORT) || \
1616
defined(CONFIG_UML_TIME_TRAVEL_SUPPORT)
1717
extern enum time_travel_mode time_travel_mode;
18+
extern int time_travel_should_print_bc_msg;
1819
#else
1920
#define time_travel_mode TT_MODE_OFF
21+
#define time_travel_should_print_bc_msg 0
2022
#endif /* (UML_)CONFIG_UML_TIME_TRAVEL_SUPPORT */
2123

24+
void _time_travel_print_bc_msg(void);
25+
static inline void time_travel_print_bc_msg(void)
26+
{
27+
if (time_travel_should_print_bc_msg)
28+
_time_travel_print_bc_msg();
29+
}
30+
2231
#endif /* _UM_TIME_TRAVEL_H_ */

arch/um/kernel/time.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ enum time_travel_message_handling {
6060
TTMH_READ,
6161
};
6262

63+
static u64 bc_message;
64+
int time_travel_should_print_bc_msg;
65+
66+
void _time_travel_print_bc_msg(void)
67+
{
68+
time_travel_should_print_bc_msg = 0;
69+
printk(KERN_INFO "time-travel: received broadcast 0x%llx\n", bc_message);
70+
}
71+
6372
static void time_travel_handle_message(struct um_timetravel_msg *msg,
6473
enum time_travel_message_handling mode)
6574
{
@@ -101,6 +110,10 @@ static void time_travel_handle_message(struct um_timetravel_msg *msg,
101110
time_travel_ext_free_until_valid = true;
102111
time_travel_ext_free_until = msg->time;
103112
break;
113+
case UM_TIMETRAVEL_BROADCAST:
114+
bc_message = msg->time;
115+
time_travel_should_print_bc_msg = 1;
116+
break;
104117
}
105118

106119
resp.seq = msg->seq;
@@ -880,4 +893,50 @@ __uml_help(setup_time_travel_start,
880893
"time-travel-start=<nanoseconds>\n"
881894
"Configure the UML instance's wall clock to start at this value rather than\n"
882895
"the host's wall clock at the time of UML boot.\n");
896+
static struct kobject *bc_time_kobject;
897+
898+
static ssize_t bc_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
899+
{
900+
return sprintf(buf, "0x%llx", bc_message);
901+
}
902+
903+
static ssize_t bc_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count)
904+
{
905+
int ret;
906+
u64 user_bc_message;
907+
908+
ret = kstrtou64(buf, 0, &user_bc_message);
909+
if (ret)
910+
return ret;
911+
912+
bc_message = user_bc_message;
913+
914+
time_travel_ext_req(UM_TIMETRAVEL_BROADCAST, bc_message);
915+
pr_info("um: time: sent broadcast message: 0x%llx\n", bc_message);
916+
return count;
917+
}
918+
919+
static struct kobj_attribute bc_attribute = __ATTR(bc-message, 0660, bc_show, bc_store);
920+
921+
static int __init um_bc_start(void)
922+
{
923+
if (time_travel_mode != TT_MODE_EXTERNAL)
924+
return 0;
925+
926+
bc_time_kobject = kobject_create_and_add("um-ext-time", kernel_kobj);
927+
if (!bc_time_kobject)
928+
return 0;
929+
930+
if (sysfs_create_file(bc_time_kobject, &bc_attribute.attr))
931+
pr_debug("failed to create the bc file in /sys/kernel/um_time");
932+
933+
return 0;
934+
}
935+
936+
void __exit time_exit(void)
937+
{
938+
kobject_put(bc_time_kobject);
939+
}
940+
941+
late_initcall(um_bc_start);
883942
#endif

arch/um/os-Linux/skas/process.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <skas.h>
2424
#include <sysdep/stub.h>
2525
#include <linux/threads.h>
26+
#include <timetravel.h>
2627
#include "../internal.h"
2728

2829
int is_skas_winch(int pid, int fd, void *data)
@@ -345,6 +346,8 @@ void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
345346
interrupt_end();
346347

347348
while (1) {
349+
time_travel_print_bc_msg();
350+
348351
if (kill_userspace_mm[0])
349352
fatal_sigsegv();
350353

include/uapi/linux/um_timetravel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ enum um_timetravel_ops {
123123
* the simulation.
124124
*/
125125
UM_TIMETRAVEL_GET_TOD = 8,
126+
127+
/**
128+
* @UM_TIMETRAVEL_BROADCAST: Send/Receive a broadcast message.
129+
* This message can be used to sync all components in the system
130+
* with a single message, if the calender gets the message, the
131+
* calender broadcast the message to all components, and if a
132+
* component receives it it should act based on it e.g print a
133+
* message to it's log system.
134+
* (calendar <-> host)
135+
*/
136+
UM_TIMETRAVEL_BROADCAST = 9,
126137
};
127138

128139
#endif /* _UAPI_LINUX_UM_TIMETRAVEL_H */

0 commit comments

Comments
 (0)