Skip to content

Fix power consumption calculation with type-C sinks#751

Open
RobertZ2011 wants to merge 1 commit intoOpenDevicePartnership:mainfrom
RobertZ2011:type-c-fix-implicit-source
Open

Fix power consumption calculation with type-C sinks#751
RobertZ2011 wants to merge 1 commit intoOpenDevicePartnership:mainfrom
RobertZ2011:type-c-fix-implicit-source

Conversation

@RobertZ2011
Copy link
Contributor

Implicit source contracts were not being included in the power policy's calculations. Also fix provider disconnected events not being broadcast in some cases.

@RobertZ2011 RobertZ2011 self-assigned this Mar 16, 2026
Copilot AI review requested due to automatic review settings March 16, 2026 22:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_contract changes.
  • 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(...).await is called while the state mutex 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 using drop(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.

@RobertZ2011 RobertZ2011 force-pushed the type-c-fix-implicit-source branch from 7e0c2ad to 6535738 Compare March 16, 2026 22:17
Copilot AI review requested due to automatic review settings March 16, 2026 22:29
@RobertZ2011 RobertZ2011 force-pushed the type-c-fix-implicit-source branch from 6535738 to 408e7d2 Compare March 16, 2026 22:29
Implicit source contracts were not being included in the power policy's
calculations. Also fix provider disconnected events not being broadcast
in some cases.
@RobertZ2011 RobertZ2011 force-pushed the type-c-fix-implicit-source branch from 408e7d2 to 92d41de Compare March 16, 2026 22:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PortStatus vs 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.state for 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(...).await is executed while the self.state mutex guard is still held. This extends the critical section across I/O/broadcast awaits and risks deadlocks/latency spikes. Drop the mutex guard before calling comms_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants