added comments and @author

This commit is contained in:
Steffen Vogel 2014-05-14 15:11:02 +02:00
parent 1d70e0781e
commit d358a78e56
6 changed files with 137 additions and 39 deletions

View file

@ -16,8 +16,10 @@
* *
* This file is part of MetalSVM. * This file is part of MetalSVM.
*/ */
/* /**
* Based on: * @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
*
* Based on:
* www.cs.berkeley.edu/~richie/bebop/notes/matmul/files/membench/ * www.cs.berkeley.edu/~richie/bebop/notes/matmul/files/membench/
*/ */
@ -28,67 +30,146 @@
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/pmc.h> #include <asm/pmc.h>
#define SAMPLES 40 #define SAMPLES 1000
#define CLKS 1e9 #define CLKS 1000000000L
#define RANGE_MIN 1024 /* 1 KiB */
#define RANGE_MAX (16*1024*1024) /* 16 MiB */ #define STRIDE_MIN 1
#define RANGE_MIN (32) /* 32 Byte */
#define RANGE_MAX (32*1024*1024) /* 32 MiB */
#define FLUSH 1
static inline void warmup(char* memory)
{
#ifdef FLUSH
tlb_flush();
flush_cache();
#else
int index;
for (index = 0; index < RANGE_MAX; index++) {
memory[index] = 0;
}
#endif
}
int membench(void* arg) int membench(void* arg)
{ {
kprintf("======= Starting membench\n"); kprintf("======= Starting membench\n");
/* Init PMCs */
struct pmc_caps* cap = pmc_init();
kprintf("PMC architecural version: %u\n", cap->version);
kprintf("There are %u general purpose PMCs (%u bit wide) available\n", cap->gp_count, cap->gp_width);
kprintf("There are %u fixed function PMCs (%u bit wide) available\n", cap->ff_count, cap->ff_width);
int i;
uint16_t tests[][2] = {
#if 0
{PMC_EVT_MEM_LOAD_RETIRED_DTLB_MISS, 0}
{PMC_EVT_MEM_LOAD_RETIRED_L1D_MISS, 0}
{PMC_EVT_MEM_LOAD_RETIRED_L2_MISS, 0}
#elif 0
{PMC_EVT_PAGE_WALK_CLKS, PMC_EVT_PAGE_WALK_COUNT}
#else
{PMC_EVT_DTLB_MISS_ANY, PMC_EVT_DTLB_MISS_LD},
{PMC_EVT_DTLB_MISS_ANY, PMC_EVT_DTLB_MISS_L0_LD},
{PMC_EVT_DTLB_MISS_ANY, PMC_EVT_DTLB_MISS_ST},
#endif
};
char *memory = palloc(RANGE_MAX, 0); char *memory = palloc(RANGE_MAX, 0);
kprintf("Allocated test memory: %#lx bytes at %p\n", RANGE_MAX, memory); kprintf("Allocated test memory: %#lx bytes at %p\n", RANGE_MAX, memory);
kprintf("%12s%12s%12s%12s\n", "reads", "range", "stride", "clks"); kprintf("#%12s%12s%12s%12s%12s%12s\n", "range", "stride", "steps", "runs", "reads", "results");
irq_disable();
/* Setup PMCs */
pmc_stop_all();
pmc_ff_config(1, PMC_FIXED_OS); // CPU_CLK_UNHALTED.CORE
/* Variables for PMC values */
uint64_t gp[2], ff[3];
uint64_t gp_ovh[2], ff_ovh[3];
int64_t gp_real[2], ff_real[3];
uint64_t run, steps, tsteps, index, runs, reads;
uint64_t range, stride;
volatile char temp;
/* Run the timing experiments */ /* Run the timing experiments */
register uint64_t range, stride;
for (range = RANGE_MIN; range <= RANGE_MAX; range *= 2) { for (range = RANGE_MIN; range <= RANGE_MAX; range *= 2) {
for (stride = 1; stride < range/2; stride *= 2) { for (stride = STRIDE_MIN; stride < range; stride *= 2) {
register uint64_t t0, t1, t2; runs = SAMPLES * stride / range + 1;
register uint64_t run, steps, tsteps, temp, index;
/* Time the loop with strided access + loop overhead */ for (i = 0; i < sizeof(tests) / 4; i++) {
steps = 0; pmc_gp_config(0, tests[i][0], PMC_EVTSEL_OS | PMC_EVTSEL_EN, 0, 0);
tsteps = 0; pmc_gp_config(1, tests[i][1], PMC_EVTSEL_OS | PMC_EVTSEL_EN, 0, 0);
// TODO: setup and start PMCs steps = 0;
tsteps = 0;
t0 = rdtsc(); /* Time the loop with strided access + loop overhead */
do { warmup(memory);
for (run = 0; run < SAMPLES; run++) { pmc_reset_all();
for (index = 0; index < range; index += stride) { pmc_start_all();
memory[index]++; do {
for (run = 0; run < runs; run++) {
for (index = 0; index < range; index += stride) {
temp = memory[index];
}
} }
}
steps++; steps++;
t1 = rdtsc() - t0; } while (pmc_ff_read(1) < CLKS);
} while (t1 < CLKS);
// TODO: read and stop PMCs pmc_stop_all();
/* Try to time just the overheads */ gp[0] = pmc_gp_read(0);
t0 = rdtsc(); gp[1] = pmc_gp_read(1);
do { ff[1] = pmc_ff_read(1);
for (run = 0; run < SAMPLES; run++) {
for (index = 0; index < range; index += stride) { /* Try to time just the overheads */
temp++; warmup(memory);
pmc_reset_all();
pmc_start_all();
do {
for (run = 0; run < runs; run++) {
for (index = 0; index < range; index += stride) {
temp++;
}
} }
}
tsteps++; tsteps++;
t2 = rdtsc() - t0; } while (tsteps < steps);
} while (tsteps < steps); pmc_stop_all();
/* Report on the average time per read/write */ gp_ovh[0] = pmc_gp_read(0);
int64_t clks = t1 - t2; gp_ovh[1] = pmc_gp_read(1);
uint64_t reads = SAMPLES * steps * range / stride; ff_ovh[1] = pmc_ff_read(1);
kprintf("%12d%12d%12d%12llu\n", reads, range, stride, 1000 * clks / reads); gp_real[0] = gp[0] - gp_ovh[0];
gp_real[1] = gp[1] - gp_ovh[1];
ff_real[1] = ff[1] - ff_ovh[1];
reads = runs * steps * range / stride;
if (i == 0)
kprintf("%12llu%12llu%12llu%12llu%12llu%12llu", range, stride, steps, runs, reads, ff_real[1]);
kprintf("%12llu", gp[0]);
kprintf("%12llu", gp[1]);
kprintf("\t");
}
kprintf("\n");
} }
kprintf("\n");
} }
irq_enable();
return 0; return 0;
} }

View file

@ -17,6 +17,10 @@
* This file is part of MetalSVM. * This file is part of MetalSVM.
*/ */
/**
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
*/
#include <metalsvm/stdlib.h> #include <metalsvm/stdlib.h>
#include <metalsvm/stdio.h> #include <metalsvm/stdio.h>
#include <metalsvm/stdarg.h> #include <metalsvm/stdarg.h>

View file

@ -20,6 +20,10 @@
#include <asm/uart.h> #include <asm/uart.h>
#include <asm/io.h> #include <asm/io.h>
/**
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
*/
static inline int is_transmit_empty() static inline int is_transmit_empty()
{ {
return inportb(UART_PORT + 5) & 0x20; return inportb(UART_PORT + 5) & 0x20;

View file

@ -33,6 +33,10 @@
#include <asm/multiboot.h> #include <asm/multiboot.h>
#include <asm/apic.h> #include <asm/apic.h>
/**
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
*/
/* /*
* Virtual Memory Layout of the standard configuration * Virtual Memory Layout of the standard configuration
* (1 GB kernel space) * (1 GB kernel space)

View file

@ -17,6 +17,10 @@
* This file is part of MetalSVM. * This file is part of MetalSVM.
*/ */
/**
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
*/
#ifndef __MALLOC_H__ #ifndef __MALLOC_H__
#define __MALLOC_H__ #define __MALLOC_H__

View file

@ -19,6 +19,7 @@
/** /**
* @author Stefan Lankes * @author Stefan Lankes
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
* @file include/metalsvm/vma.h * @file include/metalsvm/vma.h
* @brief VMA related sructure and functions * @brief VMA related sructure and functions
*/ */