gem5.cc 6.25 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

namespace bio = boost::iostreams;

33
gem5_parser::gem5_parser(sym_map &syms_) : syms(syms_) {
34
35
}

36
gem5_parser::~gem5_parser() {
37
38
39
}

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

43
44
  /*if (ts < ts_first)
      return;*/
45

46
47
48
49
  if (comp_name_len == 18 && !memcmp(comp_name, "system.switch_cpus", 18)) {
    // cpu_lines++;
    if (!p.consume_str("T0 : 0x"))
      return;
50

51
    uint64_t addr;
52
    if (!p.consume_hex(addr))
53
      return;
54

55
56
    if (!p.consume_char('.')) {
      // instructions don't have a .X
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
      /*if (prevInstr)
        yield(prevInstr)*/
      yield(std::make_shared<EHostInstr>(ts, addr));

      if (const std::string *s = syms.lookup(addr)) {
        yield(std::make_shared<EHostCall>(ts, *s));
      }
    } else {
      // micro-op
      if (!p.skip_until_after(" : ") || !p.skip_until_after(" : "))
        return;

      if (p.consume_str("halt")) {
        yield(std::make_shared<EHostHalt>(ts, addr));
      }
      /*if (p.consume_str("MemRead")) {
        if (prevInstr)
          prevInstr->fMemR = true;
      } else if (p.consume_str("MemWrite")) {
        if (prevInstr)
          prevInstr->fMemW = true;
      }*/
80
    }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  } else if (comp_name_len == 18 &&
             !memcmp(comp_name, "system.pc.ethernet", 18)) {
    // eth_lines++;

    /*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)) {
96
        yield(std::make_shared<EHostMsiX>(ts, id));
97
98
99
100
101
      } else if (p.consume_str("DMA read id ") && p.consume_dec(id) &&
                 p.consume_str(" addr ") && p.consume_hex(addr) &&
                 p.consume_str(" size ") && p.consume_dec(size)) {
        // cosim: received DMA read id 94113551511792 addr 23697ad60
        //          size 20
102
        yield(std::make_shared<EHostDmaR>(ts, id, addr, size));
103
104
105
106
107
      } else if (p.consume_str("DMA write id ") && p.consume_dec(id) &&
                 p.consume_str(" addr ") && p.consume_hex(addr) &&
                 p.consume_str(" size ") && p.consume_dec(size)) {
        // cosim: received DMA write id 94113551528032 addr 236972000
        //          size 4
108
        yield(std::make_shared<EHostDmaW>(ts, id, addr, size));
109
110
      } else if (p.consume_str("read completion id ") && p.consume_dec(id)) {
        // cosim: received read completion id 94583743418112
111
        yield(std::make_shared<EHostMmioC>(ts, id));
112
113
      } else if (p.consume_str("write completion id ") && p.consume_dec(id)) {
        // cosim: received write completion id 94583743418736
114
        yield(std::make_shared<EHostMmioC>(ts, id));
115
116
117
118
119
120
      }
    } else if (p.consume_str("sending ")) {
      if (p.consume_str("read addr ") && p.consume_hex(addr) &&
          p.consume_str(" size ") && p.consume_dec(size) &&
          p.consume_str(" id ") && p.consume_dec(id)) {
        // cosim: sending read addr c012a500 size 4 id 94583743418112
121
        yield(std::make_shared<EHostMmioR>(ts, id, addr, size));
122
123
124
125
      } else if (p.consume_str("write addr ") && p.consume_hex(addr) &&
                 p.consume_str(" size ") && p.consume_dec(size) &&
                 p.consume_str(" id ") && p.consume_dec(id)) {
        // cosim: sending write addr c0108000 size 4 id 94584005188256
126
        yield(std::make_shared<EHostMmioW>(ts, id, addr, size));
127
128
      }
    } else if (p.consume_str("completed DMA id ") && p.consume_dec(id)) {
129
      yield(std::make_shared<EHostDmaC>(ts, id));
130
    }
131
  }
132

133
134
135
136
137
  /*if (!cur_event) {
      std::cout.write(msg, msg_len);
      std::cout << std::endl;
  }*/
}
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
163
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
190
191
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
  for (; pos < line_len && line[pos] == ' '; pos++) {
  }

  // 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++, comp_name_len++) {
  }
  // skip space
  if (line[pos] != ' ') {
    valid = false;
    goto out;
  }
  if (line[pos - 1] != ':') {
    valid = false;
    goto out;
  }
  comp_name_len--;
  pos++;
192
193

out:
194
195
196
197
198
  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,
199
                msg_len);
200
201
202
203
  } else {
    std::cout << line + line_start << std::endl;
    std::cout << pos << std::endl;
  }
204

205
  return;
206
}