Skip to content

Commit 753524d

Browse files
committed
Print TSC timestamp during kerf exec
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 6439f84 commit 753524d

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pylibfdt = "^1.7.0"
1919
click = "^8.0.0"
2020
pyyaml = "^6.0"
2121
pyudev = "^0.24.0"
22+
rdtsc = "^0.2.1"
2223

2324
[tool.poetry.group.dev.dependencies]
2425
pytest = "^7.0.0"

src/init/init.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <errno.h>
2222
#include <fcntl.h>
2323
#include <signal.h>
24+
#include <stdint.h>
2425
#include <stdio.h>
2526
#include <stdlib.h>
2627
#include <string.h>
@@ -29,7 +30,6 @@
2930
#include <sys/stat.h>
3031
#include <sys/wait.h>
3132
#include <termios.h>
32-
#include <time.h>
3333
#include <unistd.h>
3434

3535
#define CMDLINE_PATH "/proc/cmdline"
@@ -63,22 +63,19 @@ static void log_error(const char *msg)
6363
log_msg(buf);
6464
}
6565

66-
static void log_starting(void)
66+
static inline uint64_t rdtsc(void)
6767
{
68-
struct timespec ts;
69-
struct tm tm;
70-
char buf[80];
68+
uint32_t lo, hi;
69+
asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
70+
return ((uint64_t)hi << 32) | lo;
71+
}
7172

72-
if (clock_gettime(CLOCK_REALTIME, &ts) < 0 ||
73-
gmtime_r(&ts.tv_sec, &tm) == NULL) {
74-
log_msg("starting");
75-
return;
76-
}
73+
static void log_starting(void)
74+
{
75+
char buf[64];
76+
uint64_t tsc = rdtsc();
7777

78-
snprintf(buf, sizeof(buf), "starting at %04d-%02d-%02d %02d:%02d:%02d.%03ld UTC",
79-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
80-
tm.tm_hour, tm.tm_min, tm.tm_sec,
81-
ts.tv_nsec / 1000000);
78+
snprintf(buf, sizeof(buf), "starting at TSC %lu", tsc);
8279
log_msg(buf);
8380
}
8481

src/kerf/exec/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import Optional
2525

2626
import click
27+
import rdtsc
2728

2829
from ..models import InstanceState
2930
from ..utils import get_instance_id_from_name
@@ -38,7 +39,6 @@
3839
SYS_REBOOT_ARM = 88
3940
SYS_REBOOT_X86 = 88
4041

41-
4242
def get_reboot_syscall():
4343
"""Get the reboot syscall number for current architecture."""
4444
arch = platform.machine().lower()
@@ -211,7 +211,8 @@ def exec_cmd(name: Optional[str], id: Optional[int], attach_console: bool, verbo
211211
click.echo(f"✓ Kernel image found for instance '{instance_name}'")
212212
click.echo(f"Instance ID to boot: {instance_id}")
213213
click.echo(f"Using reboot syscall with command: 0x{LINUX_REBOOT_CMD_MULTIKERNEL:x}")
214-
click.echo("Calling reboot syscall...")
214+
tsc = rdtsc.get_cycles()
215+
click.echo(f"Calling reboot syscall at TSC {tsc}")
215216
else:
216217
click.echo(f"Booting instance '{instance_name}' (ID: {instance_id})...")
217218

0 commit comments

Comments
 (0)