Skip to content

Commit

Permalink
hypervisor: introduce GCOV support
Browse files Browse the repository at this point in the history
This introduces pretty minimal GCOV support. The hypervisor does not
need to understand much of that. It just needs to call the init
functions to gather the addresses of the gcov related data structures.
These are just linked together so something outside the hypervisor can
look at them later.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Tested-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>
[Jan: Remove .gcno clean-files rule - done by kbuild]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
henning-schild authored and jan-kiszka committed Apr 19, 2017
1 parent 1f9d184 commit 6bd02b7
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 2 deletions.
5 changes: 5 additions & 0 deletions hypervisor/Makefile
Expand Up @@ -37,6 +37,11 @@ GCOV_PROFILE := n
CORE_OBJECTS = setup.o printk.o paging.o control.o lib.o mmio.o pci.o ivshmem.o
CORE_OBJECTS += uart.o uart-8250.o

ifdef CONFIG_JAILHOUSE_GCOV
CORE_OBJECTS += gcov.o
endif
ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs -ftest-coverage

clean-dirs := arch/$(SRCARCH)/include/generated

define sed-y
Expand Down
1 change: 1 addition & 0 deletions hypervisor/arch/arm-common/Kbuild
Expand Up @@ -11,6 +11,7 @@
#

GCOV_PROFILE := n
ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs -ftest-coverage

OBJS-y += dbg-write.o lib.o psci.o control.o paging.o mmu_cell.o
OBJS-y += irqchip.o pci.o ivshmem.o uart-pl011.o uart-xuartps.o
Expand Down
6 changes: 6 additions & 0 deletions hypervisor/arch/arm/Kbuild
Expand Up @@ -20,5 +20,11 @@ obj-y := $(COMMON_OBJECTS)
obj-y += entry.o exception.o setup.o control.o traps.o mmio.o lib.o
obj-y += mmu_hyp.o caches.o mach-stubs.o

# in here we switch of the MMU and stuff, cant profile such code
# NOTE
# gcc7 will bring a new function attribute "no_profile_instrument_function"
# should switch to that for higher granularity, but gcc7 is not even there
CFLAGS_mmu_hyp.o += -fno-profile-arcs -fno-test-coverage

obj-$(CONFIG_ARM_GIC_V3) += gic-v3.o
obj-$(CONFIG_MACH_VEXPRESS) += mach-vexpress.o
3 changes: 2 additions & 1 deletion hypervisor/arch/x86/Kbuild
@@ -1,7 +1,7 @@
#
# Jailhouse, a Linux-based partitioning hypervisor
#
# Copyright (c) Siemens AG, 2013
# Copyright (c) Siemens AG, 2013-2017
# Copyright (c) Valentine Sinitsyn, 2014
#
# Authors:
Expand All @@ -13,6 +13,7 @@
#

GCOV_PROFILE := n
ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs -ftest-coverage

BUILT_IN_OBJECTS := built-in-amd.o built-in-intel.o
COMMON_OBJECTS := apic.o dbg-write.o entry.o setup.o control.o mmio.o iommu.o \
Expand Down
50 changes: 50 additions & 0 deletions hypervisor/gcov.c
@@ -0,0 +1,50 @@
/*
* Jailhouse, a Linux-based partitioning hypervisor
*
* Copyright (c) Siemens AG, 2017
*
* Authors:
* Henning Schild <henning.schild@siemens.com>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*/
#include <jailhouse/entry.h>
#include <jailhouse/gcov.h>

extern unsigned long __init_array_start[], __init_array_end[];

/* the actual data structure is bigger but we just need to know the version
* independent beginning to link the elements to a list */
struct gcov_min_info {
unsigned int version;
struct gcov_min_info *next;
};

void gcov_init(void) {
unsigned long *iarray = __init_array_start;
unsigned long *iarray_end = __init_array_end;
void (*__init_func)(void);

while (iarray < iarray_end) {
__init_func = (void(*)(void))iarray[0];
iarray++;
__init_func();
}
}

void __gcov_init(struct gcov_min_info *info);
void __gcov_merge_add(void *counters, unsigned int n_counters);

/* just link them all together and leave the head in the header
* where a processing tool can find it */
void __gcov_init(struct gcov_min_info *info)
{
info->next = (struct gcov_min_info *)hypervisor_header.gcov_info_head;
hypervisor_header.gcov_info_head = info;
}

/* Satisfy the linker, never called */
void __gcov_merge_add(void *counters, unsigned int n_counters)
{
}
5 changes: 5 additions & 0 deletions hypervisor/hypervisor.lds.S
Expand Up @@ -30,6 +30,11 @@ SECTIONS
. = ALIGN(16);
.data : { *(.data) }

. = ALIGN(8);
__init_array_start = .;
.init_array : { *(SORT(.init_array.*)) *(.init_array) }
__init_array_end = .;

ARCH_SECTIONS

. = ALIGN(16);
Expand Down
17 changes: 17 additions & 0 deletions hypervisor/include/jailhouse/gcov.h
@@ -0,0 +1,17 @@
/*
* Jailhouse, a Linux-based partitioning hypervisor
*
* Copyright (c) Siemens AG, 2017
*
* Authors:
* Henning Schild <henning.schild@siemens.com>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*/

#ifdef CONFIG_JAILHOUSE_GCOV
void gcov_init(void);
#else
static inline void gcov_init(void) {}
#endif
3 changes: 3 additions & 0 deletions hypervisor/include/jailhouse/header.h
Expand Up @@ -58,6 +58,9 @@ struct jailhouse_header {
/** Offset of the console page inside the hypervisor memory
* @note Filled at build time. */
unsigned long console_page;
/** Pointer to the first struct gcov_info
* @note Filled at build time */
void *gcov_info_head;

/** Configured maximum logical CPU ID + 1.
* @note Filled by Linux loader driver before entry. */
Expand Down
5 changes: 4 additions & 1 deletion hypervisor/setup.c
@@ -1,7 +1,7 @@
/*
* Jailhouse, a Linux-based partitioning hypervisor
*
* Copyright (c) Siemens AG, 2013-2016
* Copyright (c) Siemens AG, 2013-2017
*
* Authors:
* Jan Kiszka <jan.kiszka@siemens.com>
Expand All @@ -13,6 +13,7 @@
#include <jailhouse/processor.h>
#include <jailhouse/printk.h>
#include <jailhouse/entry.h>
#include <jailhouse/gcov.h>
#include <jailhouse/mmio.h>
#include <jailhouse/paging.h>
#include <jailhouse/control.h>
Expand Down Expand Up @@ -51,6 +52,8 @@ static void init_early(unsigned int cpu_id)
JAILHOUSE_VERSION, cpu_id);
printk("Code location: %p\n", __text_start);

gcov_init();

error = paging_init();
if (error)
return;
Expand Down

0 comments on commit 6bd02b7

Please sign in to comment.