Fix power consumption calculation with type-C sinks#751
Fix power consumption calculation with type-C sinks#751RobertZ2011 wants to merge 1 commit intoOpenDevicePartnership:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes power-policy accounting for Type‑C implicit source contracts and improves provider disconnect notification behavior so policy state reflects actual sourcing/consumption.
Changes:
- Track implicit Type‑C source contracts in the TPS6699x controller status logic.
- Adjust wrapper logic to trigger provider-contract processing based on
available_source_contractchanges. - Recompute provider global power state when a provider disconnects.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| type-c-service/src/wrapper/mod.rs | Updates provider contract change detection during port status processing. |
| type-c-service/src/driver/tps6699x.rs | Uses port role to infer implicit source contracts for Type‑C. |
| power-policy-service/src/provider.rs | Exposes provider State.state for updates from the crate root logic. |
| power-policy-service/src/lib.rs | Recalculates global provider power state and broadcasts ProviderDisconnected. |
Comments suppressed due to low confidence (1)
power-policy-service/src/lib.rs:132
self.comms_notify(...).awaitis called while thestatemutex guard is still in scope. This keeps the lock held across an await point and can block other policy operations (and potentially deadlock if notification paths call back into code that takes the same lock). Drop the guard before awaiting the notification (e.g., by limiting the guard scope or usingdrop(state)before the await).
self.comms_notify(CommsMessage {
data: CommsData::ProviderDisconnected(device_id),
})
.await;
true
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
7e0c2ad to
6535738
Compare
6535738 to
408e7d2
Compare
Implicit source contracts were not being included in the power policy's calculations. Also fix provider disconnected events not being broadcast in some cases.
408e7d2 to
92d41de
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes power policy accounting for implicit (non-PD) Type‑C contracts and improves provider disconnect handling so policy/comms updates occur when contracts change or providers drop.
Changes:
- Type‑C wrapper now triggers provider-contract processing based on a cached previous
PortStatusvs current status (instead of relying solely on status-event flags). - TPS6699x driver detects implicit source contracts using the port-role bit, enabling implicit source contracts to be surfaced to policy.
- Power policy updates provider power-state recalculation on provider removal and exposes
provider::State.statefor cross-module updates.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| type-c-service/src/wrapper/mod.rs | Uses previous cached status to detect source-contract changes and invoke provider-contract processing. |
| type-c-service/src/driver/tps6699x.rs | Fixes implicit source-contract detection using status.port_role() for non-PD cases. |
| power-policy-service/src/provider.rs | Makes State.state accessible to the parent module for provider-state updates. |
| power-policy-service/src/lib.rs | Recalculates global provider power-state on provider removal and broadcasts disconnect notifications. |
Comments suppressed due to low confidence (1)
power-policy-service/src/lib.rs:132
self.comms_notify(...).awaitis executed while theself.statemutex guard is still held. This extends the critical section across I/O/broadcast awaits and risks deadlocks/latency spikes. Drop the mutex guard before callingcomms_notify(e.g., compute new state, update it under the lock, then release and notify).
if total_power_mw > self.config.limited_power_threshold_mw {
state.current_provider_state.state = PowerState::Limited;
} else {
state.current_provider_state.state = PowerState::Unlimited;
}
self.comms_notify(CommsMessage {
data: CommsData::ProviderDisconnected(device_id),
})
.await;
true
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Implicit source contracts were not being included in the power policy's calculations. Also fix provider disconnected events not being broadcast in some cases.