Libexo

From Msim

Jump to: navigation, search

Libexo has been used in M-sim as a mechanism to handle simulation checkpoints - the writing and reading of.

Contents

Replacement

M-sim is moving towards the use of output/input operators to replace the necessity of the libexo files. Part of the motivation to do this was in order to use istreams for file I/O within the simulator. The replacement of libexo includes replacing the use of FILE* with C++ streams.

n== smt.h == We must include fstream to use C++ streams.

#include<fstream>

Change the eio file handle to a stream:
Old code:

FILE *eio_fd;

New code:

std::ifstream *eio_fd;

smt.c

eio_fd needs to be initialized to an input stream instead of NULL:
Old code:

eio_fd(NULL),

New code:

eio_fd(new std::ifstream),

At destruction, checking for NULL is not enough, we must also check if the file is actually open.
Old code:

if(eio_fd != NULL)
{
 fclose(eio_fd);
}

New code:

if(eio_fd && eio_fd->is_open())
{
 eio_fd->close();
 delete eio_fd;
}

As an additional fix, we now check that infile and argfile are open before closing them. Old code:

if(infile)
...
if(argfile)

New code:

if(infile != NULL)
...
if(argfile != NULL)

eio.h

Now includes iostream.

#include<iostream>

eio_open no longer returns a FILE*, instead, it takes in an std::ifstream& and modifies it. It also now uses string instead of char *. Old code:

FILE *eio_open(const char *fname);

New code:

void eio_open(std::string fname, std::ifstream & in);

eio_write_chkpt takes a filename (as a string) instead of a FILE* Old code:

FILE *fd,                               //stream to write to

New code:

std::string filename,                   //file name to write to

eio_read_chkpt takes a std::ifstream& instead of a FILE* Old code:

FILE *fd,                               //stream to read

New code:

std::ifstream & in,

eio_write_trace, eio_read_trace, eio_fast_forward are no longer provided. Traces are no longer supported (they didn't work properly in M-sim 2.0 anyway and syscalls could still be called normally in most cases). Fast forwarding should be done as part of the checkpoint creation.

eio.c

Now includes fstream.

#include<fstream>

No longer includes "libexo/libexo.h".
EIO instruction format no longer needed.
Significant code removal (class mem_rec_t and all successive code). Code now uses streams to read in checkpoints New code - Old code


loader.h

void ld_load_prog no longer takes a FILE*& to eio_fd. It takes an std::ifstream& to eio_fd. Old code:

FILE* &eio_fd);                         //reference to eio_fd handle for a context

New code:

std::ifstream & eio_fd);                //reference to eio_fd handle for a context

loader.c

void ld_load_prog no longer takes a FILE*& to eio_fd. It takes an std::ifstream& to eio_fd. Old code:

FILE* &eio_fd)          //reference to context's eio file descriptor

New code:

std::ifstream & eio_fd)                                 //reference to context's eio file descriptor


Within ld_load_prog:
eio_open no longer returns a FILE* and now takes a string as first parameter (std::ifstream& as second): Old code:

eio_fd = eio_open(fname.c_str());

New code:

eio_open(fname,eio_fd);

The following is no longer used as the checkpoints are provided by using .arg files to refer to .eio files. Therefore, sim_chkpt_fname can not be provided any longer (and may not have been properly supported in M-sim anyway).

/* load checkpoint? */
if (sim_chkpt_fname != NULL)
{
 counter_t restore_icnt;
 
 FILE *chkpt_fd;
 
 fprintf(stderr, "sim: loading checkpoint file: %s\n", sim_chkpt_fname);
 
 if (!eio_valid(sim_chkpt_fname))
  fatal("file `%s' does not appear to be a checkpoint file", sim_chkpt_fname);
 
 /* open the checkpoint file */
 chkpt_fd = eio_open(sim_chkpt_fname);
 
 /* load the state image */
 restore_icnt = eio_read_chkpt(regs, mem, chkpt_fd, sim_num_insn);
 
 /* fast forward the baseline EIO trace to checkpoint location */
 myfprintf(stderr, "sim: fast forwarding to instruction %n\n", restore_icnt);
 eio_fast_forward(eio_fd, restore_icnt);
}

sim-outorder.c

Changes in loader.h::ld_load_prog require sim-outorder.c to call this function differently.
Instead of:

//load program text and data, set up environment, memory, and regs
loader.ld_load_prog(fname, argc, argv, envp, regs, contexts[num_contexts].mem, TRUE, contexts[num_contexts].eio_fd);

We must use:

//load program text and data, set up environment, memory, and regs
loader.ld_load_prog(fname, argc, argv, envp, regs, contexts[num_contexts].mem, TRUE, (*contexts[num_contexts].eio_fd));

machine.h

Libexo related macros removed:

  • MD_MISC_REGS_TO_EXO
  • MD_IREG_TO_EXO
  • MD_FREG_TO_EXO
  • MD_EXO_TO_MISC_REGS
  • MD_EXO_TO_IREG
  • MD_EXO_TO_FREG
  • MD_EXO_CMP_IREG

Defines removed:

  • #define MD_FIRST_IN_REG 0
  • #define MD_LAST_IN_REG 21
  • #define MD_FIRST_OUT_REG 0
  • #define MD_LAST_OUT_REG 21

Typedefs removed:

  • typedef qword_t exo_address_t;
  • typedef qword_t exo_integer_t;
  • typedef double exo_float_t;

syscall.c

References to an EIO trace have been removed: (if(traceable....))

Makefile

Removed references to libexo

Libexo

Removed libexo files

Personal tools