50 volatile bool _is_done_with_init;
58 size(size),data(
new char[size]){}
59 void* get_data() {
return (
void*)data; }
60 int get_size() {
return size; }
61 void reset_size(
int size) { this->size = size; }
70 virtual void write(
void* data,
int num_bytes) = 0;
72 virtual void initialize_io_structures() = 0;
79 pthread_t read_thread;
80 pthread_mutex_t read_lock;
81 std::list<io_buffer*> read_q;
87 pthread_t write_thread;
88 pthread_mutex_t write_lock;
89 pthread_cond_t write_cond;
90 std::list<io_buffer*> write_q;
95 pthread_attr_t io_sched_attr[2];
96 struct sched_param fifo_param[2];
110 QemuNic(std::string mac_addr =
"");
114 void write(
void* data,
int num_bytes);
116 void initialize_io_structures(){}
119 std::string mac_addr;
135 void write(
void* data,
int num_bytes);
137 void initialize_io_structures();
139 char socket_file[100];
140 struct sockaddr_un address;
142 static const int buf_size;
158 void write(
void* data,
int num_bytes);
160 void initialize_io_structures();
163 char write_file[100];
164 int read_fd, write_fd;
165 volatile bool exit_read;
166 static const int buf_size;
179 virtual unsigned read_mem(
unsigned addr) = 0;
180 virtual void write_mem(
unsigned addr,
unsigned dat) = 0;
194 virtual int elapsed() = 0;
196 static CompSysEmulator* launch_qemu(
const char* exec_file, std::vector<std::string>& args);
203 virtual bool is_alive() = 0;
205 virtual void run(
int us) = 0;
207 virtual void join() = 0;
210 template <
typename X>
217 void delta_ext(
double e,
const Bag<X>& xb);
218 void delta_conf(
const Bag<X>& xb);
220 void output_func(
Bag<X>& yb);
223 double get_timing_error()
const {
return qemu_time-sim_time; }
224 double get_qemu_time()
const {
return qemu_time; }
225 double get_quantum_seconds()
const {
return quantum; }
226 double get_mean_timing_error()
const {
return acc_error/(double)(error_samples+1); }
227 double get_max_timing_error()
const {
return max_error; }
238 std::vector<std::string>& qemu_args,
239 std::string disk_img,
241 EmulatorMode emulator_mode = PRECISE);
243 std::vector<std::string>& qemu_args,
244 std::vector<std::string>& disks,
245 std::vector<std::string>& disk_formats,
249 EmulatorMode emulator_mode);
251 std::vector<std::string>& ucsim_args,
252 std::string flash_img,
256 const double quantum;
258 double ttg, qemu_time, sim_time, acc_error, max_error;
259 unsigned error_samples;
260 void inject_input(
void* buf,
unsigned size);
261 enum { CATCHUP, THREAD_RUNNING, IDLE } mode;
263 void internal_and_confluent();
266 template <
typename X>
269 quantum(quantum_seconds),
281 template <
typename X>
284 if (emulator != NULL)
286 if (mode == THREAD_RUNNING)
292 template <
typename X>
297 if (mode == THREAD_RUNNING)
302 qemu_time += (emulator->elapsed()/1E6);
306 template <
typename X>
316 if (mode != CATCHUP && qemu_time > sim_time)
320 acc_error += get_timing_error();
321 max_error = (max_error > get_timing_error()) ? max_error : get_timing_error();
322 ttg = qemu_time - sim_time;
325 else if (emulator->is_alive())
327 assert(mode != THREAD_RUNNING);
328 emulator->run(quantum*1E6);
329 mode = THREAD_RUNNING;
335 template <
typename X>
338 internal_and_confluent();
341 template <
typename X>
348 template <
typename X>
351 internal_and_confluent();
354 template <
typename X>
357 if (emulator->is_alive())
359 return adevs_inf<double>();
362 template <
typename X>
364 std::vector<std::string>& args,
365 std::vector<std::string>& disks,
366 std::vector<std::string>& disk_formats,
370 EmulatorMode emulator_mode)
373 args.push_back(
"-vga");
374 args.push_back(
"std");
375 args.push_back(
"-m");
376 sprintf(arg_buf,
"%d",mb_ram);
377 args.push_back(arg_buf);
379 args.push_back(
"-monitor");
380 args.push_back(
"none");
383 args.push_back(
"-rtc");
384 args.push_back(
"clock=vm");
386 if (emulator_mode == PRECISE)
388 sprintf(arg_buf,
"1,sleep=off");
389 args.push_back(
"-icount");
390 args.push_back(arg_buf);
392 else if (emulator_mode == FAST)
394 args.push_back(
"-cpu");
395 args.push_back(
"kvm64,-kvmclock,-tsc");
396 args.push_back(
"-machine");
397 args.push_back(
"smm=off");
398 args.push_back(
"-enable-kvm");
401 for (
unsigned idx = 0; idx < disks.size(); idx++)
403 sprintf(arg_buf,
"file=%s,index=%u,media=disk,format=%s",disks[idx].c_str(),idx,disk_formats[idx].c_str());
404 args.push_back(
"-drive");
405 args.push_back(arg_buf);
409 args.push_back(
"-cdrom");
410 args.push_back(cdrom);
413 args.push_back(
"-boot");
418 emulator = CompSysEmulator::launch_qemu(
"qemu-system-i386",args);
419 assert(emulator->is_alive());
422 template <
typename X>
424 std::vector<std::string>& args,
425 std::string disk_image,
427 QemuComputer<X>::EmulatorMode emulator_mode)
429 std::string cdrom =
"";
430 std::vector<std::string> disks, disk_formats;
431 disks.push_back(disk_image);
432 disk_formats.push_back(
"raw");
433 create_x86(args,disks,disk_formats,cdrom,
false,mb_ram,emulator_mode);
436 template <
typename X>
438 std::vector<std::string>& args,
439 std::string flash_image,
442 args.push_back(
"-t");
443 args.push_back(
"8052");
444 args.push_back(flash_image);
445 emulator = CompSysEmulator::launch_ucsim(
"s51",args,obj);
446 assert(emulator->is_alive());
double ta()
Definition: adevs_qemu.h:355
Definition: adevs_qemu.h:19
void output_func(Bag< X > &yb)
Definition: adevs_qemu.h:293
Definition: adevs_qemu.h:150
Definition: adevs_qemu.h:211
void read_bytes(void *buf)
Definition: adevs_qemu.h:187
Definition: adevs_qemu.h:106
void write_bytes(void *data, int num_bytes)
Definition: adevs_fmi.h:56
void delta_conf(const Bag< X > &xb)
Definition: adevs_qemu.h:349
Definition: adevs_qemu.h:54
Definition: adevs_qemu.h:175
void delta_int()
Internal transition function.
Definition: adevs_qemu.h:336
virtual void append_qemu_arguments(std::vector< std::string > &args)=0
void delta_ext(double e, const Bag< X > &xb)
Definition: adevs_qemu.h:342
Definition: adevs_qemu.h:127
Definition: adevs_models.h:47