1/** \file 2 * \brief Memory server benchmark application, repeatedly request memory 3 */ 4 5/* 6 * Copyright (c) 2010-2011, ETH Zurich. 7 * All rights reserved. 8 * 9 * This file is distributed under the terms in the attached LICENSE file. 10 * If you do not find this file, copies can be found by writing to: 11 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 12 */ 13 14/* 15 * Spawn benchmark on given # of cores. 16 * Request memory on each core until it runs out. 17 * This benchmark program does not wait on any barriers before starting. 18 */ 19 20#include <stdio.h> 21#include <stdlib.h> 22 23#include <barrelfish/barrelfish.h> 24#include <trace/trace.h> 25 26#include <barrelfish/spawn_client.h> 27 28#include "memtest_trace.h" 29 30 31#define MEM_BITS 20 32 33static void run_benchmark_0(coreid_t core) 34{ 35 assert(core == 0); 36 37 errval_t err; 38 struct capref ramcap; 39 40 debug_printf("starting benchmark. allocating mem of size: %d\n", MEM_BITS); 41 42 int i = -1; 43 44 do { 45 i++; 46 err = ram_alloc(&ramcap, MEM_BITS); 47 } while (err_is_ok(err) && (i < 10)); 48 49 debug_printf("done benchmark. allocated %d caps (%lu bytes)\n", 50 i, i * (1UL << MEM_BITS)); 51} 52 53 54static void run_benchmark(coreid_t core) 55{ 56 errval_t err; 57 struct capref ramcap; 58 59 debug_printf("starting benchmark. allocating mem of size: %d\n", MEM_BITS); 60 61 int i = -1; 62 63 do { 64 i++; 65 err = ram_alloc(&ramcap, MEM_BITS); 66 } while (err_is_ok(err)); 67 68 debug_printf("done benchmark. allocated %d caps (%lu bytes)\n", 69 i, i * (1UL << MEM_BITS)); 70 71 ns_barrier_register_n(core, "mem_bench"); 72} 73 74 75int main(int argc, char *argv[]) 76{ 77 errval_t err; 78 79 coreid_t mycore = disp_get_core_id(); 80 81 debug_printf("This is mem_bench\n"); 82 83 if (argc >= 2) { 84 assert(mycore == 0); 85 86 int num_cores = strtol(argv[1], NULL, 10); 87 88 debug_printf("spawning on %d cores\n", num_cores); 89 90 err = init_tracing(); 91 if (err_is_fail(err)) { 92 DEBUG_ERR(err, "initialising tracing"); 93 return EXIT_FAILURE; 94 } 95 prepare_dump(); 96 97 start_tracing(); 98 99 char *path = argv[0]; 100 argv[1] = NULL; 101 102 for (int i = 1; i <= num_cores; i++) { 103 err = spawn_program(i, path, argv, NULL, 0, NULL); 104 if (err_is_fail(err)) { 105 DEBUG_ERR(err, "failed spawn %d", i); 106 return EXIT_FAILURE; 107 } 108 debug_printf("spawned on core %d\n", i); 109 } 110 111 //start_tracing(); 112 113 run_benchmark_0(mycore); 114 115 ns_barrier_master(1, num_cores, "mem_bench"); 116 117 debug_printf("all benchmarks completed\n"); 118 119 stop_tracing(); 120 // dump_trace(); 121 } else { 122 run_benchmark(mycore); 123 } 124 125 return EXIT_SUCCESS; 126} 127