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, Universitaetstrasse 6, 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#include <dist/barrier.h>
28
29#include "memtest_trace.h"
30
31
32#define MEM_BITS 20
33
34static void run_benchmark_0(coreid_t core)
35{
36    assert(core == 0);
37
38    errval_t err;
39    struct capref ramcap;
40
41    debug_printf("starting benchmark. allocating mem of size: %d\n", MEM_BITS);
42
43    int i = -1;
44
45    do {
46        i++;
47        err = ram_alloc(&ramcap, MEM_BITS);
48    } while (err_is_ok(err) && (i < 10));
49
50    debug_printf("done benchmark. allocated %d caps (%lu bytes)\n",
51                 i, i * (1UL << MEM_BITS));
52}
53
54
55static void run_benchmark(coreid_t core)
56{
57    errval_t err;
58    struct capref ramcap;
59
60    debug_printf("starting benchmark. allocating mem of size: %d\n", MEM_BITS);
61
62    int i = -1;
63
64    do {
65        i++;
66        err = ram_alloc(&ramcap, MEM_BITS);
67    } while (err_is_ok(err));
68
69    debug_printf("done benchmark. allocated %d caps (%lu bytes)\n",
70                 i, i * (1UL << MEM_BITS));
71
72    nsb_register_n(core, "mem_bench");
73}
74
75
76int main(int argc, char *argv[])
77{
78    errval_t err;
79
80    coreid_t mycore = disp_get_core_id();
81
82    debug_printf("This is mem_bench\n");
83
84    if (argc >= 2) {
85        assert(mycore == 0);
86
87        int num_cores = strtol(argv[1], NULL, 10);
88
89        debug_printf("spawning on %d cores\n", num_cores);
90
91        err = init_tracing();
92        if (err_is_fail(err)) {
93            DEBUG_ERR(err, "initialising tracing");
94            return EXIT_FAILURE;
95        }
96        prepare_dump();
97
98        start_tracing();
99
100        char *path = argv[0];
101        argv[1] = NULL;
102
103        for (int i = 1; i <= num_cores; i++) {
104            err = spawn_program(i, path, argv, NULL, 0, NULL);
105            if (err_is_fail(err)) {
106                DEBUG_ERR(err, "failed spawn %d", i);
107                return EXIT_FAILURE;
108            }
109            debug_printf("spawned on core %d\n", i);
110        }
111
112        //start_tracing();
113
114        run_benchmark_0(mycore);
115
116        nsb_master(1, num_cores, "mem_bench");
117
118        debug_printf("all benchmarks completed\n");
119
120        stop_tracing();
121        // dump_trace();
122    } else {
123        run_benchmark(mycore);
124    }
125
126    return EXIT_SUCCESS;
127}
128