From 27a2a6e016be6887e3571ab3bb3f9b5400e6b2e5 Mon Sep 17 00:00:00 2001 From: Luca Valente Date: Wed, 17 Jan 2024 18:30:47 +0100 Subject: [PATCH 1/5] WIP: add wce test. --- carfield.mk | 2 + sw/sw.mk | 5 +- sw/tests/bare-metal/hostd/pulp-offload-intf.c | 112 ++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 sw/tests/bare-metal/hostd/pulp-offload-intf.c diff --git a/carfield.mk b/carfield.mk index 7d7be6ab..15e2804f 100644 --- a/carfield.mk +++ b/carfield.mk @@ -317,6 +317,8 @@ $(PULPD_ROOT)/pulp-runtime: $(PULPD_ROOT) $(MAKE) -C $(PULPD_ROOT) pulp-runtime $(PULPD_ROOT)/regression-tests: $(PULPD_ROOT) $(MAKE) -C $(PULPD_ROOT) regression-tests + cd $(PULPD_ROOT)/regression-tests + git checkout 0bd8077565153178d0449ec23bb25811630634dc # For independent boot of an island, we allow to compile the binary standalone. .PHONY: safed-sw-build diff --git a/sw/sw.mk b/sw/sw.mk index 40a3d9e2..97743e6c 100644 --- a/sw/sw.mk +++ b/sw/sw.mk @@ -61,9 +61,11 @@ CAR_ELFLOAD_BLOCKING_SAFED_SRC_C := $(CAR_SW_DIR)/tests/bare-metal/hostd/safed_o CAR_ELFLOAD_BLOCKING_SAFED_PATH := $(basename $(CAR_ELFLOAD_BLOCKING_SAFED_SRC_C)) CAR_ELFLOAD_PULPD_SRC_C := $(CAR_SW_DIR)/tests/bare-metal/hostd/pulp-offload.c CAR_ELFLOAD_PULPD_PATH := $(basename $(CAR_ELFLOAD_PULPD_SRC_C)) +CAR_ELFLOAD_PULPD_INTF_SRC_C := $(CAR_SW_DIR)/tests/bare-metal/hostd/pulp-offload-intf.c +CAR_ELFLOAD_PULPD_INTF_PATH := $(basename $(CAR_ELFLOAD_PULPD_INTF_SRC_C)) CAR_SW_TEST_SRCS_S = $(wildcard $(CAR_SW_DIR)/tests/bare-metal/hostd/*.S) -CAR_SW_TEST_SRCS_C = $(filter-out $(CAR_ELFLOAD_BLOCKING_SAFED_SRC_C) $(CAR_ELFLOAD_PULPD_SRC_C), $(wildcard $(CAR_SW_DIR)/tests/bare-metal/hostd/*.c)) +CAR_SW_TEST_SRCS_C = $(filter-out $(CAR_ELFLOAD_BLOCKING_SAFED_SRC_C) $(CAR_ELFLOAD_PULPD_SRC_C) $(CAR_ELFLOAD_PULPD_INTF_PATH), $(wildcard $(CAR_SW_DIR)/tests/bare-metal/hostd/*.c)) CAR_SW_TEST_DRAM_DUMP = $(CAR_SW_TEST_SRCS_S:.S=.car.dram.dump) $(CAR_SW_TEST_SRCS_C:.c=.car.dram.dump) CAR_SW_TEST_DRAM_SLM = $(CAR_SW_TEST_SRCS_S:.S=.car.dram.slm) $(CAR_SW_TEST_SRCS_C:.c=.car.dram.slm) @@ -104,6 +106,7 @@ include $(CAR_SW_DIR)/tests/bare-metal/pulpd/sw.mk car-pulpd-sw-offload-tests: $(call offload_tests_template,$(PULPD_HEADER_TARGETS),pulpd,$(CAR_ELFLOAD_PULPD_SRC_C),$(CAR_ELFLOAD_PULPD_PATH)) + $(call offload_tests_template,$(PULPD_HEADER_TARGETS),pulpd,$(CAR_ELFLOAD_PULPD_INTF_SRC_C),$(CAR_ELFLOAD_PULPD_INTF_PATH)) # Litmus tests LITMUS_REPO := https://github.com/pulp-platform/CHERI-Litmus.git diff --git a/sw/tests/bare-metal/hostd/pulp-offload-intf.c b/sw/tests/bare-metal/hostd/pulp-offload-intf.c new file mode 100644 index 00000000..81c9287a --- /dev/null +++ b/sw/tests/bare-metal/hostd/pulp-offload-intf.c @@ -0,0 +1,112 @@ +// Copyright 2023 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Yvan Tortorella +// +// Bare-metal offload test for the PULP cluster + +#include +#include + +#include "car_memory_map.h" +#include "car_util.h" +#include "dif/clint.h" +#include "dif/uart.h" +#include "params.h" +#include "regs/cheshire.h" +#include "csr.h" +#include "util.h" +#include "payload.h" +#include "printf.h" + +long int * buffer; // 8 bytes * 256 * 1024 byte = 2 MB + +void read_from_cache(int l1_way_size, int stride) { + asm volatile("": : :"memory"); + for(int j = 0; j < l1_way_size; j++) + { + * ( ( volatile long int * ) &buffer[j] ); + } + asm volatile("": : :"memory"); + for(int j = 0; j < l1_way_size; j++) + { + * ( ( volatile long int * ) &buffer[(j+0)*stride]); + } + asm volatile("": : :"memory"); +} + +int sweep(int stride) +{ + + int l1_way_size = 4 * 1024 / 8; + int working_set = l1_way_size * stride * 8; + + long unsigned cycle_start; + + for(int i = 0; i < 10; i++) + { + if(i==1) + { + cycle_start = get_mcycle(); + } + read_from_cache(l1_way_size, stride); + } + + long unsigned cycles = get_mcycle() - cycle_start; + + #ifdef VERBOSE + printf("%3dKB , %6d \r\n", + working_set / 1024, (int)cycles); + #endif + + return (int)cycles; +} + +int main(void) +{ + // Set the LLC as LLC + axi_llc_reg32_all_cache(&__base_llc); + int pulp_ret_val = 0; + // Init the HW + // PULP Island + #ifdef LCL + car_enable_domain(CAR_PULP_RST); + char str[] = "Cluster boot.\r\n"; + uint32_t rtc_freq = *reg32(&__base_regs, CHESHIRE_RTC_FREQ_REG_OFFSET); + uint64_t reset_freq = clint_get_core_freq(rtc_freq, 2500); + + load_binary(); + + volatile uint32_t pulp_boot_default = 0x78008080; + volatile uint32_t pulp_ret_val = 0; + + pulp_cluster_set_bootaddress(pulp_boot_default); + + uart_init(&__base_uart, reset_freq, 115200); + uart_write_str(&__base_uart, str, sizeof(str)); + uart_write_flush(&__base_uart); + + pulp_cluster_start(); + #endif + + long unsigned cycles[5]; + int j=0; + for( int i = 4; i<128; i=i*2){ + cycles[j] = sweep(i); + j++; + } + + #ifdef LCL + pulp_cluster_wait_eoc(); + + pulp_ret_val = pulp_cluster_get_return(); + #endif + + + for(int i=0;i<5;i++) + printf("%d\r\n",cycles[i]); + + return pulp_ret_val; + +} From 23030de979e4ad72f5cc14a4ec60e0c764dab01b Mon Sep 17 00:00:00 2001 From: Luca Valente Date: Thu, 18 Jan 2024 12:09:57 +0100 Subject: [PATCH 2/5] Fix `buffer` accesses in `pulp-offload-intf.c` --- carfield.mk | 4 +-- sw/sw.mk | 2 +- sw/tests/bare-metal/hostd/pulp-offload-intf.c | 34 ++++++++++++------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/carfield.mk b/carfield.mk index 15e2804f..af9edcac 100644 --- a/carfield.mk +++ b/carfield.mk @@ -316,9 +316,7 @@ pulpd-sw-init: $(PULPD_ROOT) $(PULPD_ROOT)/pulp-runtime $(PULPD_ROOT)/regression $(PULPD_ROOT)/pulp-runtime: $(PULPD_ROOT) $(MAKE) -C $(PULPD_ROOT) pulp-runtime $(PULPD_ROOT)/regression-tests: $(PULPD_ROOT) - $(MAKE) -C $(PULPD_ROOT) regression-tests - cd $(PULPD_ROOT)/regression-tests - git checkout 0bd8077565153178d0449ec23bb25811630634dc + git clone git@github.com:pulp-platform/regression_tests.git -b lv/car-wce $@ # For independent boot of an island, we allow to compile the binary standalone. .PHONY: safed-sw-build diff --git a/sw/sw.mk b/sw/sw.mk index 97743e6c..c2be5820 100644 --- a/sw/sw.mk +++ b/sw/sw.mk @@ -65,7 +65,7 @@ CAR_ELFLOAD_PULPD_INTF_SRC_C := $(CAR_SW_DIR)/tests/bare-metal/hostd/pulp-offloa CAR_ELFLOAD_PULPD_INTF_PATH := $(basename $(CAR_ELFLOAD_PULPD_INTF_SRC_C)) CAR_SW_TEST_SRCS_S = $(wildcard $(CAR_SW_DIR)/tests/bare-metal/hostd/*.S) -CAR_SW_TEST_SRCS_C = $(filter-out $(CAR_ELFLOAD_BLOCKING_SAFED_SRC_C) $(CAR_ELFLOAD_PULPD_SRC_C) $(CAR_ELFLOAD_PULPD_INTF_PATH), $(wildcard $(CAR_SW_DIR)/tests/bare-metal/hostd/*.c)) +CAR_SW_TEST_SRCS_C = $(filter-out $(CAR_ELFLOAD_BLOCKING_SAFED_SRC_C) $(CAR_ELFLOAD_PULPD_SRC_C) $(CAR_ELFLOAD_PULPD_INTF_SRC_C), $(wildcard $(CAR_SW_DIR)/tests/bare-metal/hostd/*.c)) CAR_SW_TEST_DRAM_DUMP = $(CAR_SW_TEST_SRCS_S:.S=.car.dram.dump) $(CAR_SW_TEST_SRCS_C:.c=.car.dram.dump) CAR_SW_TEST_DRAM_SLM = $(CAR_SW_TEST_SRCS_S:.S=.car.dram.slm) $(CAR_SW_TEST_SRCS_C:.c=.car.dram.slm) diff --git a/sw/tests/bare-metal/hostd/pulp-offload-intf.c b/sw/tests/bare-metal/hostd/pulp-offload-intf.c index 81c9287a..7b53e2ea 100644 --- a/sw/tests/bare-metal/hostd/pulp-offload-intf.c +++ b/sw/tests/bare-metal/hostd/pulp-offload-intf.c @@ -2,9 +2,9 @@ // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 // -// Yvan Tortorella +// Luca Valente // -// Bare-metal offload test for the PULP cluster +// Bare-metal offload test for the PULP cluster with interference #include #include @@ -20,29 +20,31 @@ #include "payload.h" #include "printf.h" -long int * buffer; // 8 bytes * 256 * 1024 byte = 2 MB +#define LCL + +long int buffer[128]; void read_from_cache(int l1_way_size, int stride) { asm volatile("": : :"memory"); - for(int j = 0; j < l1_way_size; j++) + for(volatile int j = 0; j < l1_way_size; j++) { * ( ( volatile long int * ) &buffer[j] ); } asm volatile("": : :"memory"); - for(int j = 0; j < l1_way_size; j++) + for(volatile int j = 0; j < l1_way_size; j++) { - * ( ( volatile long int * ) &buffer[(j+0)*stride]); + * ( ( volatile long int * ) &buffer[j*stride]); } asm volatile("": : :"memory"); } -int sweep(int stride) +long unsigned sweep(int stride) { int l1_way_size = 4 * 1024 / 8; int working_set = l1_way_size * stride * 8; - long unsigned cycle_start; + volatile long unsigned cycle_start; for(int i = 0; i < 10; i++) { @@ -53,21 +55,22 @@ int sweep(int stride) read_from_cache(l1_way_size, stride); } - long unsigned cycles = get_mcycle() - cycle_start; + volatile long unsigned cycles = get_mcycle() - cycle_start; #ifdef VERBOSE printf("%3dKB , %6d \r\n", working_set / 1024, (int)cycles); #endif - return (int)cycles; + return cycles; } int main(void) { // Set the LLC as LLC axi_llc_reg32_all_cache(&__base_llc); - int pulp_ret_val = 0; + writew(0x18,CAR_HYPERBUS_CFG_BASE_ADDR+0x18); + volatile uint32_t pulp_ret_val = 0; // Init the HW // PULP Island #ifdef LCL @@ -79,7 +82,6 @@ int main(void) load_binary(); volatile uint32_t pulp_boot_default = 0x78008080; - volatile uint32_t pulp_ret_val = 0; pulp_cluster_set_bootaddress(pulp_boot_default); @@ -90,7 +92,11 @@ int main(void) pulp_cluster_start(); #endif - long unsigned cycles[5]; + #ifdef VERBOSE + printf("Buffer: %x\n", buffer); + #endif + + volatile long unsigned cycles[5]; int j=0; for( int i = 4; i<128; i=i*2){ cycles[j] = sweep(i); @@ -107,6 +113,8 @@ int main(void) for(int i=0;i<5;i++) printf("%d\r\n",cycles[i]); + printf("Done\n"); + return pulp_ret_val; } From 94171ef78011a9f2ff30d31535c9bee1af360d63 Mon Sep 17 00:00:00 2001 From: Luca Valente Date: Wed, 20 Mar 2024 14:31:43 +0100 Subject: [PATCH 3/5] Let `pulp_boot_default` be defined by `elf2header.py` --- scripts/elf2header.py | 19 +++++++++++++++++++ sw/tests/bare-metal/hostd/pulp-offload-intf.c | 2 +- sw/tests/bare-metal/hostd/pulp-offload.c | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/elf2header.py b/scripts/elf2header.py index 9b116fbd..99ddd6d2 100644 --- a/scripts/elf2header.py +++ b/scripts/elf2header.py @@ -17,6 +17,7 @@ # from elftools.elf.elffile import ELFFile +from elftools.elf.sections import SymbolTableSection import os import os.path import struct @@ -62,6 +63,7 @@ def __init__(self, verbose=False): self.mem = {} self.verbose = verbose self.areas = [] + self.start_addr = 0 self.dump('Created stimuli generator') @@ -142,6 +144,8 @@ def __gen_stim_header(self, filename, width): with open(filename, 'w') as file: file.write(c_header) + if(self.start_addr!=0): + file.write('#define ELF_BOOT_ADDR %s \n' %(hex(self.start_addr))) file.write('int load_binary() {\n' ) file.write(c_function) for key in sorted(self.mem.keys()): @@ -150,6 +154,19 @@ def __gen_stim_header(self, filename, width): file.write('return 0; \n }\n') + def __get_start_addr(self,filename,width): + + for binary in self.binaries: + + with open(binary, 'rb') as file: + elffile = ELFFile(file) + for section in elffile.iter_sections(): + if isinstance(section, SymbolTableSection): + for symbol in section.iter_symbols(): + if symbol.name == "_start": + self.start_addr = symbol.entry['st_value'] + break + def __parse_binaries(self, width): self.mem = {} @@ -196,6 +213,8 @@ def gen_stim_header_32(self, stim_file): self.__parse_binaries(4) + self.__get_start_addr(stim_file, 4) + self.__gen_stim_header(stim_file, 4) def gen_stim_slm_64(self, stim_file): diff --git a/sw/tests/bare-metal/hostd/pulp-offload-intf.c b/sw/tests/bare-metal/hostd/pulp-offload-intf.c index 7b53e2ea..a720a248 100644 --- a/sw/tests/bare-metal/hostd/pulp-offload-intf.c +++ b/sw/tests/bare-metal/hostd/pulp-offload-intf.c @@ -81,7 +81,7 @@ int main(void) load_binary(); - volatile uint32_t pulp_boot_default = 0x78008080; + volatile uint32_t pulp_boot_default = ELF_BOOT_ADDR; pulp_cluster_set_bootaddress(pulp_boot_default); diff --git a/sw/tests/bare-metal/hostd/pulp-offload.c b/sw/tests/bare-metal/hostd/pulp-offload.c index a54d4db1..ae8a06a2 100644 --- a/sw/tests/bare-metal/hostd/pulp-offload.c +++ b/sw/tests/bare-metal/hostd/pulp-offload.c @@ -30,7 +30,7 @@ int main(void) load_binary(); - volatile uint32_t pulp_boot_default = 0x78008080; + volatile uint32_t pulp_boot_default = ELF_BOOT_ADDR; volatile uint32_t pulp_ret_val = 0; pulp_cluster_set_bootaddress(pulp_boot_default); From d1b246585f72f6cce4576db0ce074486c99563c0 Mon Sep 17 00:00:00 2001 From: Luca Valente Date: Wed, 20 Mar 2024 14:32:20 +0100 Subject: [PATCH 4/5] Point to yt/carfield branch for the `regression_tests` --- carfield.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carfield.mk b/carfield.mk index af9edcac..620cb878 100644 --- a/carfield.mk +++ b/carfield.mk @@ -316,7 +316,7 @@ pulpd-sw-init: $(PULPD_ROOT) $(PULPD_ROOT)/pulp-runtime $(PULPD_ROOT)/regression $(PULPD_ROOT)/pulp-runtime: $(PULPD_ROOT) $(MAKE) -C $(PULPD_ROOT) pulp-runtime $(PULPD_ROOT)/regression-tests: $(PULPD_ROOT) - git clone git@github.com:pulp-platform/regression_tests.git -b lv/car-wce $@ + $(MAKE) -C $(PULPD_ROOT) regression-tests # For independent boot of an island, we allow to compile the binary standalone. .PHONY: safed-sw-build From ddc9c04733461f8edae334be8022cd80d934c3d8 Mon Sep 17 00:00:00 2001 From: Luca Valente Date: Wed, 20 Mar 2024 15:00:08 +0100 Subject: [PATCH 5/5] Fix `carfield.mk` indentation --- carfield.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carfield.mk b/carfield.mk index 620cb878..7d7be6ab 100644 --- a/carfield.mk +++ b/carfield.mk @@ -316,7 +316,7 @@ pulpd-sw-init: $(PULPD_ROOT) $(PULPD_ROOT)/pulp-runtime $(PULPD_ROOT)/regression $(PULPD_ROOT)/pulp-runtime: $(PULPD_ROOT) $(MAKE) -C $(PULPD_ROOT) pulp-runtime $(PULPD_ROOT)/regression-tests: $(PULPD_ROOT) - $(MAKE) -C $(PULPD_ROOT) regression-tests + $(MAKE) -C $(PULPD_ROOT) regression-tests # For independent boot of an island, we allow to compile the binary standalone. .PHONY: safed-sw-build