Skip to content

riscv_openocd_poll(): fix premature termination of algorithms under SMP #1259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: riscv
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4057,6 +4057,7 @@ int riscv_openocd_poll(struct target *target)
unsigned int should_resume = 0;
unsigned int halted = 0;
unsigned int running = 0;
unsigned int running_under_debug = 0;
unsigned int cause_groups = 0;
struct target_list *entry;
foreach_smp_target(entry, targets) {
Expand All @@ -4081,6 +4082,8 @@ int riscv_openocd_poll(struct target *target)
if (t->state == TARGET_RUNNING ||
t->state == TARGET_DEBUG_RUNNING)
running++;
if (t->state == TARGET_DEBUG_RUNNING)
running_under_debug++;
break;
case RPH_REMAIN_HALTED:
should_remain_halted++;
Expand All @@ -4104,6 +4107,12 @@ int riscv_openocd_poll(struct target *target)
} else if (should_resume) {
LOG_TARGET_DEBUG(target, "resume all");
riscv_resume(target, true, 0, 0, 0, false);
} else if (halted && running && (running_under_debug == running)) {
/* We don't consider the state inconsistent when all running harts are running under debug
control (state == TARGET_DEBUG_RUNNING), to avoid causing early abort of long-running
algorithms run on a single core under SMP. */
LOG_TARGET_DEBUG(target, "SMP group is running under debug control: %u halted, %u running",
halted, running);
} else if (halted && running) {
LOG_TARGET_DEBUG(target, "SMP group is in inconsistent state: %u halted, %u running",
halted, running);
Expand Down
Loading