Repository navigation
soc: apple: vote GPU activity to the PMP on T6001 — packaged default #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joshuaswarren
wants to merge
22
commits into
omacom:integration/aurora
Choose a base branch
from
joshuaswarren:w72/t600x-agx-vote
base: integration/aurora
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
689f2f9
soc: apple: vote GPU activity to the PMP so memory leaves idle DVFS o…
joshuaswarren f7ad8cf
pmdomain: apple: pmp-report: export a locked, acknowledged update of …
joshuaswarren e033631
pmdomain: apple: pmp-report: keep the AGX bit out of the export, docu…
joshuaswarren 5b54de3
pmdomain: apple: pmp-report: hold the AGX request 250 ms after the la…
joshuaswarren 6ece082
pmdomain: apple: pmp-report: close the races in the AGX vote and stop…
joshuaswarren e8ddbd9
tools: asahi: give the T6030 graph harness the two names the extracte…
joshuaswarren 1142df9
tools: asahi: host suite for the T6001 AGX vote policy, with mutant c…
joshuaswarren db48e98
tools: asahi: pin the vote clock wrap and require a passing base in t…
joshuaswarren 825e9ac
tools: asahi: vote suite cases for the end-during-SET race, the backo…
joshuaswarren a7330a5
pmdomain: apple: pmp-agx-vote: drain the SET-write race, bound the re…
joshuaswarren 2ec389c
pmdomain: apple: pmp-agx-vote: give begin the clock so a backoff cann…
joshuaswarren efff25c
tools: asahi: drop the dead second begin-ignores-retry control entry
joshuaswarren fb8cba3
tools: asahi: vote suite case for the SET-timeout race (red at this c…
joshuaswarren a594075
pmdomain: apple: pmp-agx-vote: arm the retry from begin when the writ…
joshuaswarren 4574c14
tools: asahi: vote suite case for the idle retry (red at this commit)
joshuaswarren 85a68bf
pmdomain: apple: pmp-agx-vote: arm the retry when the write outlasts …
joshuaswarren c3487a5
pmdomain: apple: handle half-range vote retry wrap
joshuaswarren bfb4186
pmdomain: apple: pmp-agx-vote: leave the retry arming to next()
joshuaswarren b36d019
ci: retrigger the device trees job
joshuaswarren b666d1d
tools: asahi: per-owner stop cases, the timer overwrite and a setarch…
joshuaswarren 772b1a7
pmdomain: apple: pmp-agx-vote: stop-reason mask, earlier-only kick, T…
joshuaswarren 4c76d62
drm/asahi: take the AGX activity guard where the job reaches the firm…
joshuaswarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
|
|
||
| //! Submission queue management | ||
|
|
@@ -697,12 +697,6 @@ | |
| return Err(ENODEV); | ||
| } | ||
|
|
||
| let op_guard = if in_sync_count > 0 { | ||
| Some(gpu.start_op()?) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let mut events: [KVec<Option<workqueue::QueueEventInfo::ver>>; SQ_COUNT] = | ||
| Default::default(); | ||
|
|
||
|
|
@@ -791,7 +785,10 @@ | |
| QueueJob::ver { | ||
| dev: self.dev.clone(), | ||
| vm_bind, | ||
| op_guard, | ||
| // The AGX activity guard is taken where the job reaches the firmware | ||
| // (the deferred start_op in run_job), not at ioctl time: a job blocked on | ||
| // input syncs would otherwise hold bit 9 while the GPU is idle. | ||
| op_guard: None, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This drops the base's early — Marcelo's agent |
||
| sj_vtx: self | ||
| .q_vtx | ||
| .as_mut() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ | ||
| /* | ||
| * When the T6001 AGX request (PS-REQ bit 9 of the PMP report) is set and cleared. | ||
| * | ||
| * The GPU driver counts operations in flight (begin/end). The request is set when the first operation starts and cleared | ||
| * idle_ms after the last one ends, so a decode stream (a burst every ~10 ms) holds one vote and an idle GPU drops it. All state | ||
| * changes are in these functions; the caller serializes them with one spinlock and does the register write between | ||
| * agx_vote_decide() and agx_vote_applied(). Times are milliseconds from any wrapping clock. | ||
| */ | ||
| #ifndef PMP_AGX_VOTE_H | ||
| #define PMP_AGX_VOTE_H | ||
|
|
||
| #ifdef __KERNEL__ | ||
| #include <linux/types.h> | ||
| /* jiffies_to_msecs() returns u32: the clock wraps every 49.7 days, and every compare below is done in 32 bits. */ | ||
| typedef u32 agx_ms_t; | ||
| typedef s32 agx_sms_t; | ||
| #else | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| typedef uint32_t agx_ms_t; | ||
| typedef int32_t agx_sms_t; | ||
| #endif | ||
|
|
||
| /* Stop reasons. Each owner sets and clears only its own bit: a resume from one (PM_POST_SUSPEND after a sleep) | ||
| * must not re-enable votes another still refuses (a GPU unbind), and the reverse. */ | ||
| #define AGX_STOP_GPU (1u << 0) /* the GPU driver released (unbind) */ | ||
| #define AGX_STOP_REPORT (1u << 1) /* this report is being removed */ | ||
| #define AGX_STOP_SLEEP (1u << 2) /* the system is suspending or hibernating */ | ||
|
|
||
| /* How long the request is held after the last operation ends. w7X measured idle gaps of up to 111.5 ms inside one 9B generation, so 100 ms | ||
| * was not enough; 250 ms is about 2.2 times the largest gap seen. The parameter pmp_report.agx_vote_idle_ms overrides it at run time. */ | ||
| #define AGX_VOTE_IDLE_MS_DEFAULT 250 | ||
|
|
||
| /* After a set that was not acknowledged (or a PMP that is not running), wait this long before trying again. */ | ||
| #define AGX_VOTE_RETRY_MS 1000 | ||
|
|
||
| struct agx_vote { | ||
| bool enabled; /* the module parameter */ | ||
| bool voted; /* bit 9 is set and was acknowledged */ | ||
| unsigned int stopped; /* AGX_STOP_* bits set by release/refuse: no new vote until every reason's resume() */ | ||
| unsigned int users; /* GPU operations in flight */ | ||
| agx_ms_t idle_ms; /* keep the vote this long after the last operation ends */ | ||
| agx_ms_t idle_at; /* when users last fell to 0 */ | ||
| unsigned int failures; /* consecutive failed sets; the backoff applies only while this is nonzero */ | ||
| agx_ms_t retry_at; /* with failures: no new set before this */ | ||
| }; | ||
|
|
||
| enum agx_vote_action { | ||
| AGX_VOTE_NONE, | ||
| AGX_VOTE_SET, | ||
| AGX_VOTE_CLEAR, | ||
| }; | ||
|
|
||
| static inline bool agx_vote_reached(agx_ms_t now, agx_ms_t t) | ||
| { | ||
| return (agx_sms_t)(now - t) >= 0; | ||
| } | ||
|
|
||
| /* A retry deadline more than one backoff window in the future cannot be real: an idle gap beyond half the | ||
| * 32-bit millisecond range makes the wrapped arithmetic read an expired deadline as future. Treat it as expired. */ | ||
| static inline bool agx_vote_retry_reached(const struct agx_vote *v, agx_ms_t now) | ||
| { | ||
| return agx_vote_reached(now, v->retry_at) | ||
| || (agx_ms_t)(v->retry_at - now) > AGX_VOTE_RETRY_MS; | ||
| } | ||
|
|
||
| /* An operation starts. now is the operation's start time in ms (any wrapping clock; the caller reads it | ||
| * under its lock). Returns the delay in ms until the reconcile step must run, in the same terms as | ||
| * agx_vote_end(): 1 runs it now, 0 means nothing is pending. A begin during a failed-set backoff returns the | ||
| * remaining backoff (retry_at - now): the reconcile is already armed for the retry, so a later begin shortens | ||
| * the wait but never postpones it. It returns 1 once the deadline has passed. */ | ||
| static inline agx_ms_t agx_vote_begin(struct agx_vote *v, agx_ms_t now) | ||
| { | ||
| v->users++; | ||
| if (!v->enabled || v->stopped) | ||
| return 0; | ||
| if (v->voted) | ||
| return 0; | ||
| return (!v->failures || agx_vote_retry_reached(v, now)) ? 1 : v->retry_at - now; | ||
| } | ||
|
|
||
| /* An operation ends. Returns the delay in ms after which the reconcile step must run, 0 when none is needed. */ | ||
| static inline agx_ms_t agx_vote_end(struct agx_vote *v, agx_ms_t now) | ||
| { | ||
| if (!v->users) /* unbalanced end: ignored */ | ||
| return 0; | ||
| if (--v->users) | ||
| return 0; | ||
| v->idle_at = now; | ||
| if (!v->enabled || !v->voted) | ||
| return 0; | ||
| return v->idle_ms ? v->idle_ms : 1; | ||
| } | ||
|
|
||
| /* What the reconcile step must do now. */ | ||
| static inline enum agx_vote_action agx_vote_decide(const struct agx_vote *v, agx_ms_t now) | ||
| { | ||
| if (!v->enabled || v->stopped) | ||
| return v->voted ? AGX_VOTE_CLEAR : AGX_VOTE_NONE; | ||
| if (v->users) | ||
| return !v->voted && (!v->failures || agx_vote_retry_reached(v, now)) ? AGX_VOTE_SET : AGX_VOTE_NONE; | ||
| if (v->voted && agx_vote_reached(now, v->idle_at + v->idle_ms)) | ||
| return AGX_VOTE_CLEAR; | ||
| return AGX_VOTE_NONE; | ||
| } | ||
|
|
||
| /* | ||
| * Delay in ms until the reconcile step must run again, 0 when no timer is needed. 1 when work is due now: an | ||
| * operation began while a clear was being written (begin saw voted still true and did not kick), or an end | ||
| * landed inside the SET write so the vote is set with an already-reached idle deadline. The caller must run the | ||
| * reconcile those cases would otherwise skip; it cannot read 1 as "nothing pending". | ||
| */ | ||
| static inline agx_ms_t agx_vote_next(const struct agx_vote *v, agx_ms_t now) | ||
| { | ||
| agx_ms_t at; | ||
|
|
||
| if (!v->enabled || v->stopped) | ||
| return 0; | ||
| if (v->users && !v->voted && !v->failures) | ||
| return 1; | ||
| if (v->users && !v->voted && v->failures) | ||
| at = agx_vote_retry_reached(v, now) ? now : v->retry_at; | ||
| else if (!v->users && v->voted) | ||
| at = v->idle_at + v->idle_ms; | ||
| else if (!v->users && !v->voted && v->failures) | ||
| /* The write outlasted the operation: arm the retry from the failure state | ||
| * itself. The caller clears failures when this reconcile finds nobody waiting | ||
| * (decide returns NONE), so it fires once. */ | ||
| at = agx_vote_retry_reached(v, now) ? now : v->retry_at; | ||
| else | ||
| return 0; | ||
| /* An already-reached deadline returns 1: there is work, due now. The SET-write race leaves exactly | ||
| * this state (voted, no user, deadline passed), and 0 here would strand the vote set forever. */ | ||
| return agx_vote_reached(now, at) ? 1 : at - now; | ||
| } | ||
|
|
||
| /* Record the outcome of the register write for `action` (ret 0: acknowledged). */ | ||
| static inline void agx_vote_applied(struct agx_vote *v, enum agx_vote_action action, int ret, agx_ms_t now) | ||
| { | ||
| if (action == AGX_VOTE_SET) { | ||
| if (ret) { | ||
| v->failures++; | ||
| v->retry_at = now + AGX_VOTE_RETRY_MS; | ||
| } else { | ||
| v->voted = true; | ||
| v->failures = 0; | ||
| } | ||
| } else if (action == AGX_VOTE_CLEAR) { | ||
| v->voted = false; /* the write was made; the caller logs an unacknowledged clear */ | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * The GPU driver unbinds, the report goes away, or the system sleeps: drop the vote now and refuse new ones. True when bit 9 is set and the caller must | ||
| * write the clear. An operation that begins afterwards (an ioctl already past the unplug check) counts as a user but does not vote. | ||
| */ | ||
| static inline bool agx_vote_release(struct agx_vote *v, unsigned int reason) | ||
| { | ||
| bool was_voted = v->voted; | ||
|
|
||
| v->voted = false; | ||
| v->stopped |= reason; | ||
| return was_voted; | ||
| } | ||
|
|
||
| /* Refuse new votes without touching the one that is set (the first step of a release, before the work item is waited out). */ | ||
| static inline void agx_vote_refuse(struct agx_vote *v, unsigned int reason) | ||
| { | ||
| v->stopped |= reason; | ||
| } | ||
|
|
||
| /* The GPU probes (or the report comes back, or the system resumes): votes are allowed again. True when work is already in flight and the caller must run the reconcile step. */ | ||
| static inline bool agx_vote_resume(struct agx_vote *v, unsigned int reason) | ||
| { | ||
| v->stopped &= ~reason; | ||
| return v->enabled && v->users && !v->voted && !v->stopped; | ||
| } | ||
|
|
||
| #endif /* PMP_AGX_VOTE_H */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For submissions with input syncs,
start_op()runs at ioctl time, before the fence dependencies are added (queue/mod.rs:700-704,:826-830). So a blocked job holds bit 9 on an idle GPU. Could the PMP activity be counted where the job reaches the firmware instead?— Marcelo's agent