2021-07-28 11:56:35 +02:00
|
|
|
#ifndef OVNI_EMU_H
|
|
|
|
#define OVNI_EMU_H
|
|
|
|
|
|
|
|
#include "ovni.h"
|
2021-07-29 17:46:25 +02:00
|
|
|
#include "uthash.h"
|
2021-08-03 17:48:37 +02:00
|
|
|
#include "parson.h"
|
2021-07-28 11:56:35 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* Debug macros */
|
|
|
|
|
|
|
|
#define ENABLE_DEBUG
|
|
|
|
|
|
|
|
#ifdef ENABLE_DEBUG
|
|
|
|
# define dbg(...) fprintf(stderr, __VA_ARGS__);
|
|
|
|
#else
|
|
|
|
# define dbg(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define err(...) fprintf(stderr, __VA_ARGS__);
|
|
|
|
|
|
|
|
/* Emulated thread runtime status */
|
|
|
|
enum ethread_state {
|
|
|
|
TH_ST_UNKNOWN,
|
|
|
|
TH_ST_RUNNING,
|
|
|
|
TH_ST_PAUSED,
|
|
|
|
TH_ST_DEAD,
|
|
|
|
};
|
|
|
|
|
2021-07-29 17:46:25 +02:00
|
|
|
enum nosv_task_state {
|
|
|
|
TASK_ST_CREATED,
|
|
|
|
TASK_ST_RUNNING,
|
|
|
|
TASK_ST_PAUSED,
|
|
|
|
TASK_ST_DEAD,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ovni_ethread;
|
2021-08-02 10:08:58 +02:00
|
|
|
struct ovni_eproc;
|
2021-07-29 17:46:25 +02:00
|
|
|
|
|
|
|
struct nosv_task {
|
|
|
|
int id;
|
2021-07-29 18:13:41 +02:00
|
|
|
int type_id;
|
2021-07-29 17:46:25 +02:00
|
|
|
struct ovni_ethread *thread;
|
|
|
|
enum nosv_task_state state;
|
|
|
|
UT_hash_handle hh;
|
|
|
|
};
|
|
|
|
|
2021-07-29 18:13:41 +02:00
|
|
|
struct nosv_task_type {
|
|
|
|
int id;
|
2021-07-30 20:08:40 +02:00
|
|
|
const char *label;
|
2021-07-29 18:13:41 +02:00
|
|
|
UT_hash_handle hh;
|
|
|
|
};
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
/* State of each emulated thread */
|
|
|
|
struct ovni_ethread {
|
|
|
|
/* Emulated thread tid */
|
|
|
|
pid_t tid;
|
|
|
|
|
2021-08-02 10:08:58 +02:00
|
|
|
int index;
|
|
|
|
int gindex;
|
|
|
|
|
|
|
|
/* The process associated with this thread */
|
|
|
|
struct ovni_eproc *proc;
|
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
/* Stream fd */
|
|
|
|
int stream_fd;
|
2021-07-28 11:56:35 +02:00
|
|
|
|
|
|
|
enum ethread_state state;
|
|
|
|
|
|
|
|
/* Thread stream */
|
|
|
|
struct ovni_stream *stream;
|
|
|
|
|
|
|
|
/* Current cpu */
|
|
|
|
struct ovni_cpu *cpu;
|
2021-07-29 17:46:25 +02:00
|
|
|
|
|
|
|
/* FIXME: Use a table with registrable pointers to custom data
|
|
|
|
* structures */
|
|
|
|
|
|
|
|
/* nosv task */
|
|
|
|
struct nosv_task *task;
|
2021-07-28 11:56:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* State of each emulated process */
|
|
|
|
struct ovni_eproc {
|
2021-07-30 21:37:25 +02:00
|
|
|
int pid;
|
2021-08-02 10:08:58 +02:00
|
|
|
int index;
|
|
|
|
int gindex;
|
2021-08-03 18:42:56 +02:00
|
|
|
int appid;
|
2021-07-28 11:56:35 +02:00
|
|
|
|
|
|
|
/* Path of the process tracedir */
|
|
|
|
char dir[PATH_MAX];
|
|
|
|
|
|
|
|
/* Threads */
|
|
|
|
size_t nthreads;
|
|
|
|
struct ovni_ethread thread[OVNI_MAX_THR];
|
2021-07-30 21:37:25 +02:00
|
|
|
|
2021-08-03 17:48:37 +02:00
|
|
|
JSON_Value *meta;
|
|
|
|
|
2021-07-30 21:37:25 +02:00
|
|
|
/* ------ Subsystem specific data --------*/
|
|
|
|
/* TODO: Use dynamic allocation */
|
|
|
|
|
|
|
|
struct nosv_task_type *types;
|
|
|
|
struct nosv_task *tasks;
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------ emulation ---------------- */
|
|
|
|
|
|
|
|
enum ovni_cpu_type {
|
|
|
|
CPU_REAL,
|
|
|
|
CPU_VIRTUAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ovni_cpu_state {
|
|
|
|
CPU_ST_UNKNOWN,
|
|
|
|
CPU_ST_READY,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ovni_cpu {
|
2021-08-02 18:15:59 +02:00
|
|
|
/* Logical index: 0 to ncpus - 1 */
|
|
|
|
int i;
|
2021-07-28 11:56:35 +02:00
|
|
|
|
2021-08-02 18:15:59 +02:00
|
|
|
/* Physical id: as reported by lscpu(1) */
|
|
|
|
int phyid;
|
2021-07-28 11:56:35 +02:00
|
|
|
|
2021-08-02 21:13:03 +02:00
|
|
|
/* Global index for all CPUs */
|
|
|
|
int gindex;
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
enum ovni_cpu_state state;
|
|
|
|
|
2021-07-28 19:12:20 +02:00
|
|
|
size_t last_nthreads;
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
/* The threads the cpu is currently running */
|
|
|
|
size_t nthreads;
|
|
|
|
struct ovni_ethread *thread[OVNI_MAX_THR];
|
|
|
|
};
|
|
|
|
|
2021-08-02 21:13:03 +02:00
|
|
|
/* ----------------------- trace ------------------------ */
|
|
|
|
|
|
|
|
/* State of each loom on post-process */
|
|
|
|
struct ovni_loom {
|
|
|
|
size_t nprocs;
|
|
|
|
char name[HOST_NAME_MAX];
|
2021-07-28 11:56:35 +02:00
|
|
|
|
|
|
|
int max_ncpus;
|
2021-08-02 18:15:59 +02:00
|
|
|
int max_phyid;
|
2021-07-28 11:56:35 +02:00
|
|
|
int ncpus;
|
|
|
|
struct ovni_cpu cpu[OVNI_MAX_CPU];
|
|
|
|
|
|
|
|
/* Virtual CPU */
|
|
|
|
struct ovni_cpu vcpu;
|
|
|
|
|
2021-08-02 21:13:03 +02:00
|
|
|
struct ovni_eproc proc[OVNI_MAX_PROC];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ovni_trace {
|
|
|
|
int nlooms;
|
|
|
|
struct ovni_loom loom[OVNI_MAX_LOOM];
|
|
|
|
int nstreams;
|
|
|
|
struct ovni_stream *stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ovni_stream {
|
|
|
|
uint8_t *buf;
|
|
|
|
size_t size;
|
|
|
|
size_t offset;
|
|
|
|
|
|
|
|
int tid;
|
|
|
|
int thread;
|
|
|
|
int proc;
|
|
|
|
int loom;
|
|
|
|
int loaded;
|
|
|
|
int active;
|
|
|
|
struct ovni_ev *cur_ev;
|
|
|
|
uint64_t lastclock;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ovni_emu {
|
|
|
|
struct ovni_trace trace;
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
struct ovni_stream *cur_stream;
|
|
|
|
struct ovni_ev *cur_ev;
|
|
|
|
|
|
|
|
struct ovni_loom *cur_loom;
|
|
|
|
struct ovni_eproc *cur_proc;
|
|
|
|
struct ovni_ethread *cur_thread;
|
|
|
|
|
2021-08-02 21:13:03 +02:00
|
|
|
struct nosv_task *cur_task;
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
uint64_t lastclock;
|
2021-07-29 17:46:25 +02:00
|
|
|
int64_t delta_time;
|
|
|
|
|
2021-08-03 18:42:56 +02:00
|
|
|
FILE *prv_thread;
|
|
|
|
FILE *prv_cpu;
|
|
|
|
|
2021-08-02 10:08:58 +02:00
|
|
|
/* Total counters */
|
|
|
|
int total_thread;
|
|
|
|
int total_proc;
|
2021-08-03 17:48:37 +02:00
|
|
|
int total_cpus;
|
2021-07-28 11:56:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Emulator function declaration */
|
|
|
|
|
|
|
|
void emu_emit(struct ovni_emu *emu);
|
|
|
|
|
2021-07-28 19:12:20 +02:00
|
|
|
void hook_pre_ovni(struct ovni_emu *emu);
|
2021-07-30 21:37:25 +02:00
|
|
|
void hook_emit_ovni(struct ovni_emu *emu);
|
2021-07-28 19:12:20 +02:00
|
|
|
void hook_post_ovni(struct ovni_emu *emu);
|
2021-07-28 11:56:35 +02:00
|
|
|
|
2021-07-29 17:46:25 +02:00
|
|
|
void hook_pre_nosv(struct ovni_emu *emu);
|
2021-07-30 21:37:25 +02:00
|
|
|
void hook_emit_nosv(struct ovni_emu *emu);
|
2021-07-29 17:46:25 +02:00
|
|
|
void hook_post_nosv(struct ovni_emu *emu);
|
|
|
|
|
2021-08-02 21:13:03 +02:00
|
|
|
struct ovni_cpu *emu_get_cpu(struct ovni_loom *loom, int cpuid);
|
2021-07-28 11:56:35 +02:00
|
|
|
|
|
|
|
struct ovni_ethread *emu_get_thread(struct ovni_emu *emu, int tid);
|
|
|
|
|
2021-07-30 21:37:25 +02:00
|
|
|
void emu_emit_prv(struct ovni_emu *emu, int type, int val);
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
#endif /* OVNI_EMU_H */
|