Skip to content

Commit

Permalink
RR Upgrade (#1267)
Browse files Browse the repository at this point in the history
* added replay check to loadvm

* changed the PANDA_IS_IN_REPLAY flag to be a global var

* made it so that loadvm ALWAYS excludes non-essential devices

* exclude unnecessary devices from snapshots while recording

* cpu_common is not important for replays

* minor tweaks and cleanup

* more minor cleanup

* forgot to commit the header sooner oops

* reset the rr debugging code

* removed section ID checks on snapshot load

* reset rr debug code

* setting panda_is_in_record inside of scissors

* wrapped global flag setting/unsetting in shim functions
  • Loading branch information
off-by-1-error committed Mar 2, 2023
1 parent a7cebe0 commit 5472db2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/migration/savevm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extern int panda_is_in_record;

void set_rr_snapshot(void);
void unset_rr_snapshot(void);
31 changes: 31 additions & 0 deletions migration/savevm.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "io/channel-buffer.h"
#include "io/channel-file.h"
#include "panda/callbacks/cb-support.h"
#include "migration/savevm.h"

#ifndef ETH_P_RARP
#define ETH_P_RARP 0x8035
Expand Down Expand Up @@ -83,6 +84,30 @@ static struct mig_cmd_args {
[MIG_CMD_MAX] = { .len = -1, .name = "MAX" },
};

const char* important_idstrs[] = {
"ram",
"cpu",
NULL
};

int idstr_is_important(char* idstr);


int idstr_is_important(char* idstr) {

int i = 0;
while (important_idstrs[i]) {
if (strcmp(idstr, important_idstrs[i]) == 0) {
return 1;
}

i++;
}

return 0;
}


static int announce_self_create(uint8_t *buf,
uint8_t *mac_addr)
{
Expand Down Expand Up @@ -1153,6 +1178,10 @@ void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only)
json_start_array(vmdesc, "devices");
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {

if (panda_is_in_record && !idstr_is_important(se->idstr)) {
continue;
}

if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
continue;
}
Expand Down Expand Up @@ -1838,6 +1867,7 @@ void loadvm_free_handlers(MigrationIncomingState *mis)
}
}


static int
qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
{
Expand All @@ -1859,6 +1889,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)

trace_qemu_loadvm_state_section_startfull(section_id, idstr,
instance_id, version_id);

/* Find savevm section */
se = find_se(idstr, instance_id);
if (se == NULL) {
Expand Down
6 changes: 6 additions & 0 deletions panda/plugins/scissors/scissors.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "panda/include/panda/rr/panda_rr2.h"

#include "migration/migration.h"
#include "migration/savevm.h"
#include "include/exec/address-spaces.h"
#include "migration/qemu-file.h"
#include "io/channel-file.h"
Expand Down Expand Up @@ -256,8 +257,13 @@ static inline void save_snp_shot(void) {
QIOChannelFile* ioc =
qio_channel_file_new_path(snp_name, O_WRONLY | O_CREAT, 0660, NULL);
QEMUFile* snp = qemu_fopen_channel_output(QIO_CHANNEL(ioc));

set_rr_snapshot();

qemu_savevm_state(snp, NULL);
qemu_fclose(snp);

unset_rr_snapshot();
}

static void create_command_file(void) {
Expand Down
16 changes: 16 additions & 0 deletions panda/src/rr/rr_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "panda/callbacks/cb-support.h"
#include "exec/gdbstub.h"
#include "sysemu/cpus.h"
#include "migration/savevm.h"

//#define RR_DEBUG

Expand Down Expand Up @@ -89,6 +90,16 @@ struct rr_file_info* recording_info = NULL;

bool rr_replay_complete = false;

int panda_is_in_record = 0;

void set_rr_snapshot(void) {
panda_is_in_record = 1;
}

void unset_rr_snapshot(void) {
panda_is_in_record = 0;
}

// our own assertion mechanism
#define rr_assert(exp) \
if (!(exp)) { \
Expand Down Expand Up @@ -1583,6 +1594,9 @@ int rr_do_begin_record(const char* file_name_full, CPUState* cpu_state)
QIOChannelFile* ioc =
qio_channel_file_new_path(name_buf, O_WRONLY | O_CREAT, 0660, NULL);
QEMUFile* snp = qemu_fopen_channel_output(QIO_CHANNEL(ioc));

set_rr_snapshot();

snapshot_ret = qemu_savevm_state(snp, &err);
qemu_fclose(snp);
// log_all_cpu_states();
Expand Down Expand Up @@ -1643,6 +1657,8 @@ void rr_do_end_record(void)

printf("...complete!\n");

unset_rr_snapshot();

// log_all_cpu_states();

rr_destroy_log();
Expand Down

0 comments on commit 5472db2

Please sign in to comment.