| 130 | } |
| 131 | |
| 132 | fn persist_state(&self) { |
| 133 | let bindings: Vec<GpuBinding> = self |
| 134 | .slots |
| 135 | .iter() |
| 136 | .filter_map(|s| { |
| 137 | s.assigned_to.as_ref().map(|id| GpuBinding { |
| 138 | bdf: s.info.bdf.clone(), |
| 139 | sandbox_id: id.clone(), |
| 140 | bound_at_ms: std::time::SystemTime::now() |
| 141 | .duration_since(std::time::UNIX_EPOCH) |
| 142 | .map_or(0, |d| i64::try_from(d.as_millis()).unwrap_or(i64::MAX)), |
| 143 | }) |
| 144 | }) |
| 145 | .collect(); |
| 146 | let state = GpuBindState { bindings }; |
| 147 | if let Err(err) = state.save(&self.state_path) { |
| 148 | tracing::warn!(error = %err, "failed to persist GPU bind state"); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | pub struct GpuAssignment { |