Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Libpfm building with KTF #217

Merged
merged 7 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ cscope.*
Makeconf.local
.DS_Store
drivers/acpi/acpica/source/
third-party/libpfm/COPYING
third-party/libpfm/Makefile
third-party/libpfm/README
third-party/libpfm/config.mk
third-party/libpfm/include/
third-party/libpfm/lib/
third-party/libpfm/libpfm.a
third-party/libpfm/rules.mk
32 changes: 14 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ endif
PFMLIB_ARCHIVE :=
PFMLIB_LINKER_FLAGS :=
PFMLIB_INCLUDE :=
PFMLIB_NAME := libpfm
PFMLIB_VER := 4.10.1
PFMLIB_DIR := $(KTF_ROOT)/$(THIRD_PARTY)/$(PFMLIB_NAME)
PFMLIB_TARBALL := $(PFMLIB_DIR)/$(PFMLIB_NAME)-$(PFMLIB_VER).tar.gz
ifeq ($(CONFIG_LIBPFM),y)
KTF_PFMLIB_COMPILE := 1
export KTF_PFMLIB_COMPILE
TAR_CMD_PFMLIB := tar --exclude=.git --exclude=.gitignore --strip-components=1 -xvf
PFMLIB_VER := 4.10.1
PFMLIB_NAME := libpfm
PFMLIB_DIR := $(KTF_ROOT)/$(THIRD_PARTY)/$(PFMLIB_NAME)
TAR_CMD_PFMLIB := tar --exclude=.git --exclude=.gitignore --strip-components=1 -xf
PFMLIB_TOOLS_DIR := $(KTF_ROOT)/$(TOOLS_DIR)/$(PFMLIB_NAME)
PFMLIB_ARCHIVE := $(PFMLIB_DIR)/$(PFMLIB_NAME).a
PFMLIB_TARBALL := $(PFMLIB_DIR)/$(PFMLIB_NAME)-$(PFMLIB_VER).tar.gz
PFMLIB_UNTAR_FILES := $(PFMLIB_NAME)-$(PFMLIB_VER)/lib
PFMLIB_UNTAR_FILES += $(PFMLIB_NAME)-$(PFMLIB_VER)/include
PFMLIB_UNTAR_FILES += $(PFMLIB_NAME)-$(PFMLIB_VER)/rules.mk
Expand Down Expand Up @@ -159,7 +159,7 @@ endif
$(PREP_LINK_SCRIPT) : $(LINK_SCRIPT)
$(VERBOSE) $(CC) $(AFLAGS) -E -P -C -x c $< -o $@

$(TARGET): $(PFMLIB_ARCHIVE) $(OBJS) $(PREP_LINK_SCRIPT)
$(TARGET): $(OBJS) $(PREP_LINK_SCRIPT)
@echo "LD " $@
$(VERBOSE) $(LD) -T $(PREP_LINK_SCRIPT) -o $@ $(OBJS) $(PFMLIB_LINKER_FLAGS)
@echo "GEN " $(SYMBOLS_NAME).S
Expand All @@ -171,22 +171,21 @@ $(TARGET): $(PFMLIB_ARCHIVE) $(OBJS) $(PREP_LINK_SCRIPT)
$(VERBOSE) $(LD) -T $(PREP_LINK_SCRIPT) -o $@ $(OBJS) $(PFMLIB_LINKER_FLAGS) $(SYMBOLS_NAME).o

$(PFMLIB_ARCHIVE): $(PFMLIB_TARBALL)
@echo "UNTAR pfmlib"
# untar tarball and apply the patch
cd $(PFMLIB_DIR) &&\
@echo "UNTAR libpfm"
$(VERBOSE) cd $(PFMLIB_DIR) &&\
$(TAR_CMD_PFMLIB) $(PFMLIB_TARBALL) $(PFMLIB_UNTAR_FILES) -C ./ &&\
$(PATCH) -p1 < $(PFMLIB_PATCH_FILE) &&\
$(PATCH) -s -p1 < $(PFMLIB_PATCH_FILE) &&\
cd -
# invoke libpfm build
$(MAKE) -C $(PFMLIB_DIR) lib &&\
cp $(PFMLIB_DIR)/lib/$(PFMLIB_NAME).a $(PFMLIB_DIR)/
find $(PFMLIB_DIR) -name \*.c -delete
@echo "BUILD libpfm"
$(VERBOSE) $(MAKE) -C $(PFMLIB_DIR) lib
$(VERBOSE) cp $(PFMLIB_DIR)/lib/$(PFMLIB_NAME).a $(PFMLIB_DIR)/
$(VERBOSE) find $(PFMLIB_DIR) -name \*.c -delete

%.o: %.S
@echo "AS " $@
$(VERBOSE) $(CC) -c -o $@ $(AFLAGS) $<

%.o: %.c
%.o: %.c $(PFMLIB_ARCHIVE)
@echo "CC " $@
$(VERBOSE) $(CC) -c -o $@ $(CFLAGS) $<

Expand All @@ -202,10 +201,7 @@ clean:
$(VERBOSE) find $(KTF_ROOT) -name \*.iso -delete
$(VERBOSE) find $(KTF_ROOT) -name \*.img -delete
$(VERBOSE) find $(KTF_ROOT) -name cscope.\* -delete
ifeq ($(CONFIG_LIBPFM),y)
$(MAKE) -C $(PFMLIB_DIR) cleanlib
$(VERBOSE) find $(PFMLIB_DIR) -mindepth 1 ! -name $(PFMLIB_NAME)-$(PFMLIB_VER).tar.gz -delete
endif
$(VERBOSE) $(RM) -rf $(ACPICA_DEST_DIR)/source

# Check whether we can use kvm for qemu
Expand Down
3 changes: 3 additions & 0 deletions arch/x86/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ SECTIONS
. = ALIGN(4K);
__start_text = .;
*(.text)
*(.text.*)
. = ALIGN(4K);
__end_text = .;
} :kernel
Expand All @@ -163,6 +164,7 @@ SECTIONS
. = ALIGN(4K);
__start_data = .;
*(.data)
*(.data.*)
__start_cmdline = .;
*(.cmdline)
__end_cmdline = .;
Expand All @@ -184,6 +186,7 @@ SECTIONS
__start_bss = .;
*(COMMON)
*(.bss)
*(.bss.*)
. = ALIGN(4K);
__end_bss = .;
} :kernel
Expand Down
8 changes: 4 additions & 4 deletions common/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ void __naked kernel_main(void) {
display_memory_map();
display_multiboot_mmap();

#ifdef KTF_PMU
pfm_initialize();
#endif

test_main();

printk("All tasks done.\n");

#ifdef KTF_PMU
pfm_terminate();
#endif

#ifdef KTF_ACPICA
acpi_power_off();
#endif
Expand Down
12 changes: 12 additions & 0 deletions common/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
#include <drivers/serial.h>
#include <drivers/vga.h>

#ifdef KTF_PMU
#include <perfmon/pfmlib.h>
#endif

bool opt_debug = false;
bool_cmd("debug", opt_debug);

Expand Down Expand Up @@ -299,6 +303,14 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,
if (opt_keyboard)
init_keyboard(get_bsp_cpu_id());

#ifdef KTF_PMU
printk("Initializing PFM library\n");

int ret = pfm_initialize();
if (ret != PFM_SUCCESS)
printk("Warning: PFM library initialization failed: %d\n", ret);
#endif

/* Jump from .text.init section to .text */
asm volatile("jmp kernel_main");

Expand Down
Loading