have the core spinor routines automatically retry on failure

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.
This commit is contained in:
bunnie 2022-10-28 02:55:42 +08:00
parent d63c452fb6
commit 0c7c90fb78

View file

@ -174,17 +174,25 @@ impl Spinor {
// acquire a write lock on the unit // acquire a write lock on the unit
#[cfg(not(test))] #[cfg(not(test))]
{ {
let response = send_message(self.conn, const RETRY_LIMIT: usize = 5;
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(), for i in 0..RETRY_LIMIT {
self.token[0] as usize, let response = send_message(self.conn,
self.token[1] as usize, Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[2] as usize, self.token[0] as usize,
self.token[3] as usize, self.token[1] as usize,
) self.token[2] as usize,
).expect("couldn't send AcquireExclusive message to Spinor hardware!"); self.token[3] as usize,
if let xous::Result::Scalar1(result) = response { )
if result == 0 { ).expect("couldn't send AcquireExclusive message to Spinor hardware!");
return Err(SpinorError::BusyTryAgain) if let xous::Result::Scalar1(result) = response {
if result == 0 {
if i == RETRY_LIMIT - 1 {
return Err(SpinorError::BusyTryAgain)
}
xous::yield_slice();
} else {
break;
}
} }
} }
} }
@ -235,17 +243,25 @@ impl Spinor {
// acquire a write lock on the unit // acquire a write lock on the unit
#[cfg(not(test))] #[cfg(not(test))]
{ {
let response = send_message(self.conn, const RETRY_LIMIT: usize = 5;
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(), for i in 0..RETRY_LIMIT {
self.token[0] as usize, let response = send_message(self.conn,
self.token[1] as usize, Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[2] as usize, self.token[0] as usize,
self.token[3] as usize, self.token[1] as usize,
) self.token[2] as usize,
).expect("couldn't send AcquireExclusive message to Spinor hardware!"); self.token[3] as usize,
if let xous::Result::Scalar1(result) = response { )
if result == 0 { ).expect("couldn't send AcquireExclusive message to Spinor hardware!");
return Err(SpinorError::BusyTryAgain) if let xous::Result::Scalar1(result) = response {
if result == 0 {
if i == RETRY_LIMIT - 1 {
return Err(SpinorError::BusyTryAgain)
}
xous::yield_slice();
} else {
break;
}
} }
} }
} }