Skip to content

Commit

Permalink
Stop yields when yield is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Nehab committed Jun 30, 2020
1 parent 59ce76b commit ed52397
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/machine-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,23 @@ struct machine_state {
return brk;
}

/// \brief Decide if brk should be set due to yield.
bool brk_from_iflags_Y(void) const {
if (iflags.Y) {
// uint64_t dev = HTIF_DEV_FIELD(htif.tohost);
uint64_t dev = htif.tohost >> 56;
// uint64_t cmd = HTIF_CMD_FIELD(htif.tohost)
uint64_t cmd = htif.tohost << 8 >> 48;
// brk |= (dev == HTIF_DEVICE_YIELD && (htif.iyield >> cmd));
return (dev == 2 && ((htif.iyield >> cmd) & 1));
}
return false;
}

/// \brief Checks that false brk is consistent with rest of state
void assert_no_brk(void) const {
assert((mie & mip) == 0);
assert(!iflags.Y);
assert(!brk_from_iflags_Y());
assert(!iflags.H);
}

Expand All @@ -202,7 +215,7 @@ struct machine_state {

/// \brief Updates the brk flag from changes in the iflags_Y flag.
void or_brk_with_iflags_Y(void) {
brk |= iflags.Y;
brk |= brk_from_iflags_Y();
}

/// \brief Rebuild brk from all.
Expand Down
8 changes: 6 additions & 2 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ void machine::interact(void) {
m_h.interact();
}

bool machine::should_yield(void) const {
return m_s.brk_from_iflags_Y();
}

machine::machine(const machine_config &c):
m_s{},
m_t{},
Expand Down Expand Up @@ -1200,7 +1204,7 @@ access_log machine::step(const access_log::type &log_type, bool one_based) {
hash_type root_hash_after;
update_merkle_tree();
get_root_hash(root_hash_after);
verify_state_transition(root_hash_before, *a.get_log(),
verify_state_transition(root_hash_before, *a.get_log(),
root_hash_after, one_based);
} else {
verify_access_log(*a.get_log(), one_based);
Expand Down Expand Up @@ -1249,7 +1253,7 @@ void machine::run(uint64_t mcycle_end) {
}

// If we yielded, we are done
if (read_iflags_Y()) {
if (should_yield()) {
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class machine final {
/// instruction. Another example is when the machine halts.
void run_inner_loop(uint64_t mcycle_end);

/// \brief Decides if machine should yield
bool should_yield(void) const;

public:

/// \brief Type of hash
Expand Down

0 comments on commit ed52397

Please sign in to comment.