1/**
2 * \file
3 * \brief library for benchmarking the network related code
4 *
5 */
6
7/*
8 * Copyright (c) 2007, 2008, 2009, 2010, 2011 ETH Zurich.
9 * All rights reserved.
10 *
11 * This file is distributed under the terms in the attached LICENSE file.
12 * If you do not find this file, copies can be found by writing to:
13 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
14 */
15
16#ifndef NETBENCH_H_
17#define NETBENCH_H_
18
19#include <barrelfish/barrelfish.h>
20#include <stdio.h>
21#include <sys/cdefs.h>
22
23__BEGIN_DECLS
24
25#if 0
26#define CONVERT_TO_SEC
27
28#ifdef CONVERT_TO_SEC
29float in_seconds(uint64_t cycles);
30float in_seconds(uint64_t cycles)
31{
32    float ans;
33    ans = cycles / MACHINE_CLOCK_SPEED;
34    ans = ans / MACHINE_CLK_UNIT;
35    return ans;
36}
37#else
38#define PU PRIu64
39uint64_t in_seconds(uint64_t cycles);
40uint64_t in_seconds(uint64_t cycles)
41{
42    return cycles;
43}
44
45#endif // CONVERT_TO_SEC
46
47#endif // 0
48
49// To print the seconds
50#define PU "f"
51
52#define NAME_SIZE               64
53
54enum Benchmark_states {
55    BMS_INACTIVE = 0,
56    BMS_START_REQUEST = 1,
57    BMS_RUNNING = 2,
58    BMS_STOP_REQUEST = 3,
59    BMS_STOPPED = 4,
60};
61
62
63enum Recorded_DataTypes {
64    RDT_COUNT,
65    RDT_SUM,
66    RDT_MAX,
67    RDT_MIN,
68    EVENT_ELEMENTS  // MUST BE THE LAST ELEMENT!!
69};
70
71struct netbench_details {
72    uint8_t status;
73    uint32_t event_elements;
74    uint32_t total_events;
75    uint64_t *stats;
76    char name[NAME_SIZE];
77};
78
79// Utility functions
80uint64_t my_avg(uint64_t sum, uint64_t n);
81
82#ifndef LIBRARY
83
84float in_seconds(uint64_t cycles);
85void netbench_reset(struct netbench_details *nbp);
86struct netbench_details *netbench_alloc(char *name, uint32_t total_events);
87
88void netbench_record_event(struct netbench_details *nbp,
89        uint32_t event_type, uint64_t value);
90void netbench_record_event_no_ts(struct netbench_details *nbp,
91        uint8_t event_type);
92void netbench_record_event_simple(struct netbench_details *nbp,
93        uint8_t event_type, uint64_t ts);
94
95void netbench_print_event_stat(struct netbench_details *nbp,
96        uint8_t event_type, char *event_name, int type);
97void netbench_print_all_stats(struct netbench_details *nbp);
98
99#else
100
101#define netbench_reset(a)
102#define netbench_alloc(a, b)
103#define netbench_record_event(a, b, c)
104#define netbench_record_event_no_ts(a, b)
105#define netbench_record_event_simple(a, b, c)   while(0) { (void)c; }
106#define netbench_print_event_stat(a, b, c, d)
107#define netbench_print_all_stats(a)
108
109static inline float in_seconds(uint64_t cycles)
110{
111    return cycles;
112}
113
114#endif
115
116__END_DECLS
117
118#endif // NETBENCH_H_
119