Skip to content

Commit

Permalink
cosim support
Browse files Browse the repository at this point in the history
  • Loading branch information
liaochengjie committed Mar 17, 2024
1 parent 7322824 commit d71d696
Show file tree
Hide file tree
Showing 10 changed files with 611 additions and 2 deletions.
34 changes: 34 additions & 0 deletions accel/tcg/cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "sysemu/cpus.h"
#include "sysemu/replay.h"

#include "acc/acc.h"

/* -icount align implementation. */

typedef struct SyncClocks {
Expand Down Expand Up @@ -135,6 +137,38 @@ static void init_delay_params(SyncClocks *sc, const CPUState *cpu)
}
#endif /* CONFIG USER ONLY */

//Instantiate HDL extern variables
zsock_t *ls_sock;
int hdl_lockstep = 1;
int hdl_step_size = ICOUNT_STEP;
int catchup_steps = 0;
int64_t hdl_step_count = 100000000000L; /* initial buffer for boot */
const int RCVHWM_VALUE = 1;

uintptr_t wrapper_tcg_qemu_tb_exec(void *env, void *tb_ptr) {

//VM-HDL lock-step
if (hdl_lockstep) {
hdl_step_count -= 1;
while (hdl_step_count <= 0) {
if (ls_sock == NULL) {
int port = atoi(getenv("COSIM_PORT"));
char buffer[50];
sprintf(buffer, SOCK_BASE, RECV_SOCK, port + 6);
ls_sock = zsock_new_pull(buffer);
zsock_set_rcvhwm(ls_sock, RCVHWM_VALUE);
}
zframe_t* frame = zframe_recv(ls_sock);
assert(frame);
zframe_destroy(&frame);
do {
hdl_step_count += hdl_step_size;
} while (catchup_steps-- > 0);
}
}
return ((uintptr_t (*)(void *, void *))tcg_ctx.code_gen_prologue)(env, tb_ptr);
}

/* Execute a TB, and fix up the CPU state afterwards if necessary */
static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
{
Expand Down
1 change: 1 addition & 0 deletions default-configs/pci.mak
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ CONFIG_VGA_PCI=y
CONFIG_IVSHMEM_DEVICE=$(CONFIG_IVSHMEM)
CONFIG_ROCKER=y
CONFIG_VHOST_USER_SCSI=$(and $(CONFIG_VHOST_USER),$(CONFIG_LINUX))
CONFIG_ACCELERATOR=y
29 changes: 29 additions & 0 deletions hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,35 @@ been deleted, the QEMU Block layer returns -EIO which results in IO
errors in the guest for applications that are reading/writing to the device.
These errors are always reported to the guest, regardless of the drive's error
actions (drive options rerror, werror).
ETEXI

{
.name = "hdl_lockstep",
.args_type = "option:s?",
.params = "[on|off]",
.help = "toggle lockstep with HDL in emulation",
.cmd = hmp_hdl_lockstep,
},

STEXI
@item hdl_lockstep [off]
@findex hdl_lockstep
Run the emulation in lock step mode with HDL simulation.
If called with option off, the emulation returns to normal mode.
ETEXI

{
.name = "hdl_stepsize",
.args_type = "step:i",
.params = "step",
.help = "adjust number of cycles qemu can step relative to hdl",
.cmd = hmp_hdl_stepsize,
},

STEXI
@item hdl_stepsize @var{count}
@findex hdl_stepsize
Adjust the number of cycles qemu can step relative to hdl.
ETEXI

{
Expand Down
22 changes: 22 additions & 0 deletions hmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#include <spice/enums.h>
#endif

#include "acc/acc.h"

static void hmp_handle_error(Monitor *mon, Error **errp)
{
assert(errp);
Expand Down Expand Up @@ -1044,6 +1046,26 @@ void hmp_stop(Monitor *mon, const QDict *qdict)
qmp_stop(NULL);
}

void hmp_hdl_lockstep(Monitor *mon, const QDict *qdict)
{
const char *option = qdict_get_try_str(qdict, "option");
if (!option || !strcmp(option, "on")) {
hdl_lockstep = 1;
hdl_step_count = 0;
} else if (!strcmp(option, "off")) {
hdl_lockstep = 0;
} else {
monitor_printf(mon, "unexpected option %s\n", option);
}
}

void hmp_hdl_stepsize(Monitor *mon, const QDict *qdict)
{
monitor_printf(mon,"old step_size %d\n", hdl_step_size);
hdl_step_size = qdict_get_try_int(qdict, "step", 8);
monitor_printf(mon,"new step_size %d\n", hdl_step_size);
}

void hmp_system_reset(Monitor *mon, const QDict *qdict)
{
qmp_system_reset(NULL);
Expand Down
2 changes: 2 additions & 0 deletions hmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
void hmp_netdev_add(Monitor *mon, const QDict *qdict);
void hmp_netdev_del(Monitor *mon, const QDict *qdict);
void hmp_getfd(Monitor *mon, const QDict *qdict);
void hmp_hdl_lockstep(Monitor *mon, const QDict *qdict);
void hmp_hdl_stepsize(Monitor *mon, const QDict *qdict);
void hmp_closefd(Monitor *mon, const QDict *qdict);
void hmp_sendkey(Monitor *mon, const QDict *qdict);
void hmp_screendump(Monitor *mon, const QDict *qdict);
Expand Down
2 changes: 2 additions & 0 deletions hw/misc/Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
obj-$(CONFIG_AUX) += auxbus.o
obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
obj-y += mmio_interface.o

obj-$(CONFIG_ACCELERATOR) += accelerator_pcie.o
Loading

0 comments on commit d71d696

Please sign in to comment.