2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-05 08:45:49 +00:00

compel/std/uapi: Provide setter for gettimeofday()

Provide a way to set gettimeofday() function for an infected task.
CRIU's parasite & restorer are very voluble as more logs are better
than lesser in terms of bug investigations.
In all modern kernels there is a way to get time without entering
kernel: vdso. So, add a way to reduce the cost of logging without making
it less valuable.

[I'm not particularly fond of std_log_set_gettimeofday() name, so
 if someone can come with a better naming - I'm up for a change]

Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
This commit is contained in:
Dmitry Safonov
2019-07-25 23:01:08 +01:00
committed by Andrei Vagin
parent d2d6e3f537
commit 28949d5fb8
2 changed files with 27 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ struct simple_buf {
static int logfd = -1;
static int cur_loglevel = COMPEL_DEFAULT_LOGLEVEL;
static struct timeval start;
static gettimeofday_t __std_gettimeofday;
static void sbuf_log_flush(struct simple_buf *b);
@@ -54,7 +55,7 @@ static void sbuf_log_init(struct simple_buf *b)
if (start.tv_sec != 0) {
struct timeval now;
sys_gettimeofday(&now, NULL);
std_gettimeofday(&now, NULL);
timediff(&start, &now);
/* Seconds */
@@ -130,6 +131,19 @@ void std_log_set_start(struct timeval *s)
start = *s;
}
void std_log_set_gettimeofday(gettimeofday_t gtod)
{
__std_gettimeofday = gtod;
}
int std_gettimeofday(struct timeval *tv, struct timezone *tz)
{
if (__std_gettimeofday != NULL)
return __std_gettimeofday(tv, tz);
return sys_gettimeofday(tv, tz);
}
static void print_string(const char *msg, struct simple_buf *b)
{
while (*msg) {