Add new emulator

This commit is contained in:
Rodrigo Arias 2023-01-17 19:28:52 +01:00 committed by Rodrigo Arias Mallo
parent bac907dba0
commit fb06a3ec32
2 changed files with 148 additions and 0 deletions

99
src/emu/emu.c Normal file
View File

@ -0,0 +1,99 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#define _POSIX_C_SOURCE 2
#include "emu.h"
#include <unistd.h>
static char progname[] = "ovniemu";
static void
usage(void)
{
err("Usage: %s [-c offsetfile] tracedir\n", progname);
err("\n");
err("Options:\n");
err(" -c offsetfile Use the given offset file to correct\n");
err(" the clocks among nodes. It can be\n");
err(" generated by the ovnisync program\n");
err("\n");
err(" tracedir The output trace dir generated by ovni.\n");
err("\n");
err("The output PRV files are placed in the tracedir directory.\n");
exit(EXIT_FAILURE);
}
static void
parse_args(struct emu *emu, int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "c:l")) != -1) {
switch (opt) {
case 'c':
emu->clock_offset_file = optarg;
break;
case 'l':
emu->enable_linter = 1;
break;
default: /* '?' */
usage();
}
}
if (optind >= argc) {
err("missing tracedir\n");
usage();
}
emu->tracedir = argv[optind];
}
int
emu_model_register(struct emu *emu, struct model_spec *spec, void *ctx)
{
emu->model_ctx[spec->model] = ctx;
emu->model[spec->model] = spec;
return 0;
}
void *
emu_model_get_context(struct emu *emu, struct model_spec *spec, int model)
{
for (int i = 0; spec->depends[i]; i++) {
if (spec->depends[i] == model)
return emu->model_ctx[model];
}
/* Not allowed */
return NULL;
}
int
emu_init(struct emu *emu, int argc, char *argv[])
{
memset(emu, 0, sizeof(*emu));
parse_args(emu, argc, argv);
/* Load the streams into the emu_trace */
if (emu_trace_load(&emu->trace, emu->tracedir) != 0) {
err("emu_init: cannot load trace '%s'\n",
emu->tracedir);
return -1;
}
/* Parse the streams and build the emu_system */
if (emu_system_load(&emu->system, &emu->trace) != 0) {
err("emu_init: cannot parse trace '%s'\n",
emu->tracedir);
return -1;
}
/* Register all the models */
//emu_model_register(emu, ovni_model_spec, ctx);
return 0;
}

49
src/emu/emu.h Normal file
View File

@ -0,0 +1,49 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef EMU_H
#define EMU_H
#include "bay.h"
#include "pvtrace.h"
#include "emu_trace.h"
#include "emu_system.h"
enum error_values {
ST_BAD = 666,
ST_TOO_MANY_TH = 777,
};
struct emu;
typedef int (emu_hook_t)(struct emu *emu);
struct model_spec {
char *name;
int model;
char *depends;
emu_hook_t *probe;
emu_hook_t *create;
emu_hook_t *connect;
emu_hook_t *event;
};
struct emu {
struct bay *bay;
struct pvman *pvman;
char *tracedir;
int enable_linter;
char *clock_offset_file;
struct emu_trace trace;
struct emu_system system;
struct model_spec *model[256];
void *model_ctx[256];
};
int emu_init(struct emu *emu, int argc, char *argv[]);
int emu_model_register(struct emu *emu, struct model_spec *spec, void *ctx);
void *emu_model_get_context(struct emu *emu, struct model_spec *spec, int model);
#endif /* EMU_H */