gem5.cpp 6.07 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

25
26
#include <iostream>

Antoine Kaufmann's avatar
Antoine Kaufmann committed
27
28
29
#include "trace/events.h"
#include "trace/parser.h"
#include "trace/process.h"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

namespace bio = boost::iostreams;

gem5_parser::gem5_parser(sym_map &syms_)
    : syms(syms_)
{
}

gem5_parser::~gem5_parser()
{
}

void gem5_parser::process_msg(uint64_t ts, char *comp_name,
        size_t comp_name_len, char *msg, size_t msg_len)
{
    parser p(msg, msg_len, 0);

    /*if (ts < ts_first)
        return;*/

    if (comp_name_len == 18 && !memcmp(comp_name, "system.switch_cpus", 18)) {
Antoine Kaufmann's avatar
Antoine Kaufmann committed
51
        // cpu_lines++;
52
53
54
55
56
57
58
59
60
61
        if (!p.consume_str("T0 : 0x"))
            return;

        uint64_t addr;
        if (!p.consume_hex(addr) || p.consume_char('.'))
            return;

        if (const std::string *s = syms.lookup(addr)) {
            cur_event = new EHostCall(ts, *s);
        }
Antoine Kaufmann's avatar
Antoine Kaufmann committed
62
63
64
    } else if (comp_name_len == 18 &&
            !memcmp(comp_name, "system.pc.ethernet", 18)) {
        // eth_lines++;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

        /*std::cout.write(msg, msg_len);
        std::cout << std::endl;*/

        if (!p.consume_str("cosim: "))
            return;

        uint64_t id = 0;
        uint64_t addr = 0;
        uint64_t size = 0;
        if (p.consume_str("received ")) {
            if (p.consume_str("MSI-X intr vec ") && p.consume_dec(id)) {
                cur_event = new EHostMsiX(ts, id);
            } else if (p.consume_str("DMA read id ") && p.consume_dec(id) &&
                    p.consume_str(" addr ") && p.consume_hex(addr) &&
Antoine Kaufmann's avatar
Antoine Kaufmann committed
80
81
82
                    p.consume_str(" size ") && p.consume_dec(size)) {
                // cosim: received DMA read id 94113551511792 addr 23697ad60
                //          size 20
83
84
85
                cur_event = new EHostDmaR(ts, id, addr, size);
            } else if (p.consume_str("DMA write id ") && p.consume_dec(id) &&
                    p.consume_str(" addr ") && p.consume_hex(addr) &&
Antoine Kaufmann's avatar
Antoine Kaufmann committed
86
87
88
                    p.consume_str(" size ") && p.consume_dec(size)) {
                // cosim: received DMA write id 94113551528032 addr 236972000
                //          size 4
89
90
                cur_event = new EHostDmaW(ts, id, addr, size);
            } else if (p.consume_str("read completion id ") &&
Antoine Kaufmann's avatar
Antoine Kaufmann committed
91
                    p.consume_dec(id)) {
92
93
94
                // cosim: received read completion id 94583743418112
                cur_event = new EHostMmioC(ts, id);
            } else if (p.consume_str("write completion id ") &&
Antoine Kaufmann's avatar
Antoine Kaufmann committed
95
                    p.consume_dec(id)) {
96
97
98
99
100
101
                // cosim: received write completion id 94583743418736
                cur_event = new EHostMmioC(ts, id);
            }
        } else if (p.consume_str("sending ")) {
            if (p.consume_str("read addr ") && p.consume_hex(addr) &&
                    p.consume_str(" size ") && p.consume_dec(size) &&
Antoine Kaufmann's avatar
Antoine Kaufmann committed
102
                    p.consume_str(" id ") && p.consume_dec(id)) {
103
104
105
106
                // cosim: sending read addr c012a500 size 4 id 94583743418112
                cur_event = new EHostMmioR(ts, id, addr, size);
            } else if (p.consume_str("write addr ") && p.consume_hex(addr) &&
                    p.consume_str(" size ") && p.consume_dec(size) &&
Antoine Kaufmann's avatar
Antoine Kaufmann committed
107
                    p.consume_str(" id ") && p.consume_dec(id)) {
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
                // cosim: sending write addr c0108000 size 4 id 94584005188256
                cur_event = new EHostMmioW(ts, id, addr, size);
            }
        } else if (p.consume_str("completed DMA id ") && p.consume_dec(id)) {
            cur_event = new EHostDmaC(ts, id);
        }
    }

    /*if (!cur_event) {
        std::cout.write(msg, msg_len);
        std::cout << std::endl;
    }*/
}


void gem5_parser::process_line(char *line, size_t line_len)
{
    size_t pos = 0;

    size_t line_start = pos;
    size_t comp_name_start = 0;
    size_t comp_name_len = 0;
    bool valid = true;

    // eat spaces
Antoine Kaufmann's avatar
Antoine Kaufmann committed
133
    for (; pos < line_len && line[pos] == ' '; pos++) {}
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

    // parse ts
    uint64_t ts = 0;
    size_t ts_len = 0;
    for (; pos < line_len && line[pos] >= '0' && line[pos] <= '9'; pos++) {
        ts = ts * 10 + line[pos] - '0';
        ts_len++;
    }
    if (ts_len == 0) {
        valid = false;
        goto out;
    }

    // skip colon
    if (line[pos] != ':') {
        valid = false;
        goto out;
    }
    pos++;

    // skip space
    if (line[pos] != ' ') {
        valid = false;
        goto out;
    }
    pos++;

    comp_name_start = pos;
    for (; pos < line_len && line[pos] != ' ' && line[pos] != '\n'; pos++,
Antoine Kaufmann's avatar
Antoine Kaufmann committed
163
            comp_name_len++) {}
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    // skip space
    if (line[pos] != ' ') {
        valid = false;
        goto out;
    }
    if (line[pos - 1] != ':') {
        valid = false;
        goto out;
    }
    comp_name_len--;
    pos++;

out:
    size_t msg_start = pos;
    size_t msg_len = line_len - msg_start;
    line[line_len - 1] = 0;
    if (valid) {
        process_msg(ts, line + comp_name_start, comp_name_len, line + msg_start,
                msg_len);
    } else {
        std::cout << line + line_start << std::endl;
        std::cout << pos << std::endl;
    }

    return;
}