Skip to content

Commit

Permalink
have the core spinor routines automatically retry on failure
Browse files Browse the repository at this point in the history
normally we never see these failures, but, as we are seeing
flash wear-out on the CI machine the writes can take
long enough that we get some concurrent requests. As a work-around,
just automatically retry a few times before throwing the error
back to the caller.
  • Loading branch information
bunnie committed Oct 27, 2022
1 parent d63c452 commit 0c7c90f
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions services/spinor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,25 @@ impl Spinor {
// acquire a write lock on the unit
#[cfg(not(test))]
{
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[0] as usize,
self.token[1] as usize,
self.token[2] as usize,
self.token[3] as usize,
)
).expect("couldn't send AcquireExclusive message to Spinor hardware!");
if let xous::Result::Scalar1(result) = response {
if result == 0 {
return Err(SpinorError::BusyTryAgain)
const RETRY_LIMIT: usize = 5;
for i in 0..RETRY_LIMIT {
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[0] as usize,
self.token[1] as usize,
self.token[2] as usize,
self.token[3] as usize,
)
).expect("couldn't send AcquireExclusive message to Spinor hardware!");
if let xous::Result::Scalar1(result) = response {
if result == 0 {
if i == RETRY_LIMIT - 1 {
return Err(SpinorError::BusyTryAgain)
}
xous::yield_slice();
} else {
break;
}
}
}
}
Expand Down Expand Up @@ -235,17 +243,25 @@ impl Spinor {
// acquire a write lock on the unit
#[cfg(not(test))]
{
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[0] as usize,
self.token[1] as usize,
self.token[2] as usize,
self.token[3] as usize,
)
).expect("couldn't send AcquireExclusive message to Spinor hardware!");
if let xous::Result::Scalar1(result) = response {
if result == 0 {
return Err(SpinorError::BusyTryAgain)
const RETRY_LIMIT: usize = 5;
for i in 0..RETRY_LIMIT {
let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[0] as usize,
self.token[1] as usize,
self.token[2] as usize,
self.token[3] as usize,
)
).expect("couldn't send AcquireExclusive message to Spinor hardware!");
if let xous::Result::Scalar1(result) = response {
if result == 0 {
if i == RETRY_LIMIT - 1 {
return Err(SpinorError::BusyTryAgain)
}
xous::yield_slice();
} else {
break;
}
}
}
}
Expand Down

0 comments on commit 0c7c90f

Please sign in to comment.