Skip to content

Commit

Permalink
restorer: Use gettimeofday() from rt-vdso for log timings
Browse files Browse the repository at this point in the history
Omit calling raw syscalls and use vdso for the purpose of logging.
That will eliminate as much as one-syscall-per-PIE-message.
Getting time without switching to kernel will speed up C/R,
keeping logs as informative as they were.

Fixes: checkpoint-restore#346

Signed-off-by: Dmitry Safonov <dima@arista.com>
  • Loading branch information
0x7f454c46 committed Jun 19, 2019
1 parent a1bb0af commit a551c51
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions criu/arch/aarch64/include/asm/vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* we should support at the moment.
*/
#define VDSO_SYMBOL_MAX 4
#define VDSO_SYMBOL_GTOD 2

/*
* Workaround for VDSO array symbol table's relocation.
Expand Down
1 change: 1 addition & 0 deletions criu/arch/arm/include/asm/vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Poke from kernel file arch/arm/vdso/vdso.lds.S
*/
#define VDSO_SYMBOL_MAX 2
#define VDSO_SYMBOL_GTOD 1
#define ARCH_VDSO_SYMBOLS \
"__vdso_clock_gettime", \
"__vdso_gettimeofday"
Expand Down
1 change: 1 addition & 0 deletions criu/arch/ppc64/include/asm/vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* inside the text page which should not be used as is from user space.
*/
#define VDSO_SYMBOL_MAX 10
#define VDSO_SYMBOL_GTOD 5
#define ARCH_VDSO_SYMBOLS \
"__kernel_clock_getres", \
"__kernel_clock_gettime", \
Expand Down
3 changes: 2 additions & 1 deletion criu/arch/s390/include/asm/vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* This is a minimal amount of symbols
* we should support at the moment.
*/
#define VDSO_SYMBOL_MAX 4
#define VDSO_SYMBOL_MAX 4
#define VDSO_SYMBOL_GTOD 0

/*
* This definition is used in pie/util-vdso.c to initialize the vdso symbol
Expand Down
3 changes: 2 additions & 1 deletion criu/arch/x86/include/asm/vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* This is a minimal amount of symbols
* we should support at the moment.
*/
#define VDSO_SYMBOL_MAX 6
#define VDSO_SYMBOL_MAX 6
#define VDSO_SYMBOL_GTOD 2

/*
* XXX: we don't patch __kernel_vsyscall as it's too small:
Expand Down
1 change: 1 addition & 0 deletions criu/include/parasite-vdso.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static inline bool is_vdso_mark(void *addr)
return false;
}

extern void vdso_update_gtod_addr(struct vdso_maps *rt);
extern int vdso_do_park(struct vdso_maps *rt, unsigned long park_at,
unsigned long park_size);
extern int vdso_map_compat(unsigned long map_at);
Expand Down
47 changes: 42 additions & 5 deletions criu/pie/parasite-vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "int.h"
#include "types.h"
#include "page.h"
#include <compel/plugins/std/syscall.h>
#include "compel/plugins/std/syscall.h"
#include "compel/plugins/std/log.h"
#include "image.h"
#include "parasite-vdso.h"
#include "vma.h"
Expand Down Expand Up @@ -43,14 +44,50 @@ static int remap_one(char *who, unsigned long *from, unsigned long to, size_t si

static int park_at(struct vdso_maps *rt, unsigned long vdso, unsigned long vvar)
{
unsigned long vvar_size = rt->sym.vvar_size;
unsigned long vdso_size = rt->sym.vdso_size;
int ret;

ret = remap_one("rt-vdso", &rt->vdso_start, vdso, rt->sym.vdso_size);

if (ret || !vvar)
ret = remap_one("rt-vdso", &rt->vdso_start, vdso, vdso_size);
if (ret)
return ret;

return remap_one("rt-vvar", &rt->vvar_start, vvar, rt->sym.vvar_size);
std_log_set_gettimeofday(NULL); /* stop using vdso for timings */

if (vvar)
ret = remap_one("rt-vvar", &rt->vvar_start, vvar, vvar_size);

if (!ret)
vdso_update_gtod_addr(rt);

return ret;
}

void vdso_update_gtod_addr(struct vdso_maps *rt)
{
struct vdso_symbol *gtod_sym;
void *gtod;

if (rt->vdso_start == VDSO_BAD_ADDR) {
pr_debug("No rt-vdso - no fast gettimeofday()\n");
return;
}

if (VDSO_SYMBOL_GTOD < 0) {
pr_debug("Arch doesn't support gettimeofday() from vdso\n");
return;
}

gtod_sym = &rt->sym.symbols[VDSO_SYMBOL_GTOD];
if (gtod_sym->offset == VDSO_BAD_ADDR) {
pr_debug("No gettimeofday() on rt-vdso\n");
return;
}

gtod = (void*)(rt->vdso_start + gtod_sym->offset);
pr_info("Using gettimeofday() on vdso at %p\n", gtod);

std_log_set_gettimeofday(gtod);
}

/*
Expand Down
1 change: 1 addition & 0 deletions criu/pie/restorer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ long __export_restore_task(struct task_restore_args *args)
/* Map vdso that wasn't parked */
if (args->can_map_vdso && (map_vdso(args) < 0))
goto core_restore_end;
vdso_update_gtod_addr(&args->vdso_maps_rt);

/* Shift private vma-s to the left */
for (i = 0; i < args->vmas_n; i++) {
Expand Down

0 comments on commit a551c51

Please sign in to comment.