Skip to content

kernel: S8003 TA waits only on the last PM-rebuilding TA - #154

Merged
henrikklee merged 26 commits into
OrchardLinux:mainfrom
brkosebay:a9-gpu-pm-wait
Nov 17, 2026
Merged

henrikklee merged 26 commits into
OrchardLinux:mainfrom
brkosebay:a9-gpu-pm-wait

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

Depends on #150, #151, #153. Only the last commit is new in this PR.

#153 ("S8003 firmware interrupt, PM work gating and pool growth") goes
first; this branch is stacked on it.

Summary

A clean PM set currently falls back to a full PM record whenever the
immediately preceding TA is still running. Follow iOS
(AGXTACommandDescriptor_preparePMAndWork): remember the last TA that
rebuilt this set and wait only for its stamp. Reset the remembered stamp
when the set's backing or the firmware is rebuilt. Below, "W1" is this
last-rebuild wait.

There is one fixed behavior and no module parameter. The always-rebuild
and previous-TA comparison modes are not part of this PR.

Commits

  • Wait only on the last S8003 PM rebuild in steady state

Hardware

On the iPad 5, full PM records per glmark2 run fell from ~31–52k to 2, with zero GPU faults.

W1 ahead in both run orders on one boot: +2.8 % (W1 second) and +13.7 % (W1 first); full PM records ~31–52k → 2; fragment busy +1.9 to +3.3 pts.

Order Kernel glmark2 Fragment busy Geometry busy Fragment jobs Full PM records
W1 second previous-TA wait 469 75.2 % 17.1 % 188,594 52,549
W1 second W1 482 77.1 % 19.7 % 194,947 2
W1 first previous-TA wait 498 77.6 % 20.6 % 193,776 30,996
W1 first W1 566 80.9 % 24.9 % 199,159 2

Absolute glmark2 scores drift about 16% run to run on one boot on this
device, so the claim rests on W1 winning in both orders, not on the size of
either gain. Both comparisons ran composited fullscreen glmark2 with a
development-only switch between the two waits; this PR has no such switch.

Tested on Orchard main plus this series and our other pending patches (the J71t charging series and the rest of our iPad 5 development series), as one development kernel.

A10

Only the A9 was tested by us. This change is S8003-only because the
hardware path differs: it changes when the S8003 host sends a full PM
record, and the T8010 firmware manages its PM itself through RTKit
geometry/fragment descriptors, with no host PM record or rebuild stamp.
The T8010 runs no new code here.

A10 testers: please report any GPU fault or hang after a fullscreen run. No
pm_record line is expected on the T8010.

How to test

sudo find /sys/kernel/debug/dri -name apple_jobs -exec grep pm_record {} +
glmark2-es2-wayland --fullscreen
sudo find /sys/kernel/debug/dri -name apple_jobs -exec grep pm_record {} +
  • A9: the counters are cumulative, so compare the two lines. full rises
    by a handful over the whole run (2 in ours), clean by tens of
    thousands, and rec_unreached stays 0. On the base branch the same run
    adds tens of thousands of full records.
  • A10: no pm_record line; nothing to compare. A fault or hang is a
    regression to report.
  • A/B: boot the base branch kernel (kernel: S8003 firmware interrupt, PM work gating and pool growth #153). There is no off switch, by design.

Testing

  • A9 / apple-16k: PASS; image, modules and device trees built; no new warnings.
  • A10 / apple-4k: PASS; image, modules and device trees built; no new warnings.

The stock apple-4k CI config has CONFIG_DRM_POWERVR_APPLE disabled; that
checks the disabled-backend stubs. The apple-16k build enables the Apple
backend and compiles both the S8003 and T8010 implementations.

The branch's CI config is unchanged and the effective config after olddefconfig
matches it byte for byte. Compiler debug output is disabled only for the
local build to fit the host. Reapplying the patch series can emit the
existing PMGR blank-line-at-EOF application warning under either config.
No new compiler warnings are accepted.

…ial pages

On the iPad 5, vkCreateDevice() fails with VK_ERROR_INITIALIZATION_FAILED.
CREATE_HWRT_DATASET returns -EINVAL without a log line when Mesa creates
the dummy render target used during device creation.

The A9 allocates the parameter manager's pages itself. Its free list is
not grown by pvr_free_list_create(), so current_pages stays zero, but
hwrt_init_kernel_structure() still checks it against the minimum.

For chips with own_pm_pages, check initial_num_pages instead. This is
the limit used to size the S8003 parameter manager's render blocks.

Affects the Apple A9 (S8003). The A10 is unchanged.

Assisted-by: LLM
…rejected

After a rejected command stream on the iPad 5, the next exec in another
process oopses in free_bprm with a bad rss-counter. slub_debug reports
"Object already free" on kmalloc-512: the object was allocated and freed
in pvr_fw_cmd_init(), then freed again from pvr_job_put().

When stream parsing fails, pvr_job_process_stream() frees the command.
The caller then releases the job, whose release path frees it again.
Clear the command pointer and length after freeing the rejected command.

Upstream has the same code. Affects every PowerVR device.

Fixes: eaf01ee5ba28 ("drm/imagination: Implement job submission and scheduling")

Assisted-by: LLM
Every geometry and fragment job on the iPad 5 is refused with -EINVAL,
without a log line. The stream parser requires the A10's type-1 register
extension on every Apple chip, while the A9 supplies its registers in
extension type 2.

Put each chip's required extension type and mask beside its stream
definitions and obtain them through an Apple accessor. Keep the A10's
values and leave compute without an Apple must-have entry.

Affects the Apple A9 (S8003). The A10's validation values are unchanged.

Assisted-by: LLM
…ry job

Once rendering works on the iPad 5, every fragment job warns at
WARN_ON(job->paired_job) in pvr_job.c, thousands of times a minute.
Geometry jobs are never freed, and clients hang when destroying a
render target: glmark2 and vkcube run until killed.

Apple queues receive jobs linked by pvr_jobs_link_geom_frag(), but their
free path does not drop the fragment job's paired geometry reference.
That reference also keeps the geometry job's HWRT and context alive.

Follow pvr_queue_free_job(): drop the paired geometry reference and
clear paired_job before dropping the scheduler's reference.

Affects the shared Apple queue used by the A9 (S8003) and A10 (T8010).
The A10 has been build-tested only.

Assisted-by: LLM
A client's first render on the iPad 5 fails without a log line when
another client rendered last. Its geometry job returns -EBUSY, then
its fragment job is refused with "fragment job without a geometry job".

The call that takes a VM's PM sets is inside the dependency choice for
consecutive jobs of the same VM. A new VM can therefore reach submission
without a PM set when the previous fragment belonged to another VM.

Call vm_scenes for every geometry job before selecting its dependency.
Keep the existing prev_frag/last_frag choice and locking context.

Affects the Apple A9 (S8003). The A10 has no vm_scenes callback and is
unchanged.

Assisted-by: LLM
The iPad 5's rejected geometry and fragment streams return -EINVAL
without explaining which check failed. Applications fail to render,
and the kernel gives no values with which to diagnose the rejection.

Report malformed headers, invalid destination entries, short input,
unsupported extensions and missing must-have bits at the rejecting
check. Include the command type, entry or extension, and checked values.
Use one rate-limited warning per rejected stream; callers log short
reads so that propagated errors do not produce duplicate messages.

Keep successful parsing and error returns unchanged. Affects every
PowerVR device.

Assisted-by: LLM
Render failures on the iPad 5 can leave a fragment job without its
geometry job. S8003 submission errors otherwise return silently, so
the kernel does not say which engine or stage failed.

Add one rate-limited warning at each failing submission stage with the
engine, error, VM and reason. Separate the PM pool build and record
slot wait checks so that their errors can be distinguished.

Keep submission and recovery behaviour unchanged. A fragment without
its geometry scene is still refused.

Affects the Apple A9 (S8003). The A10 is unchanged.

Assisted-by: LLM
…e it loads

The iPad 5 loses Firefox's WebGL context under multiple GPU clients.
Firmware slot loads return -EIO, geometry jobs fail, and their fragment
jobs are refused. Single-client runs do not hit the failure.

VM map and unmap flushes take tag_lock but not submit_lock. They can
bump a slot's host tag while DC_SLOT loads its root. With two or more
bumps, firmware can copy an intermediate tag that matches neither the
loaded tag nor the current host tag, falsely failing the load check.

Mark each slot as loading under tag_lock while publishing its root and
tag. Defer flushes on those slots, verify the exact loaded tag, then
clear loading and apply any pending bump through the shared helper on
both success and failure. submit_lock keeps the VM's job behind the
pending bump, so firmware still invalidates stale translations before
using the slot. Report the slot, loaded, firmware and current tags on
a mismatch.

Affects: Apple A9 (S8003). The A10 is unchanged.

Assisted-by: LLM
Firmware stops processing jobs after a fault, but internal record and
PM waits spent five seconds polling an unreachable stamp. End waits on
the existing fault latch and return -EIO unless the requested stamp
actually arrived. Keep the latch until a new boot.

Affects: Apple A9 (S8003); A10 unchanged
Assisted-by: LLM
A texture read at VA 0xffffffc0 stopped rendering on the iPad 5. Share
the decoder and once-per-boot report so the VA, access, requester and
context are captured before reset. Read only e150/e158 after checking
Fender state, transition bits and an optional chip-supplied highest
state. Refuse capture without a licence. Both fault edges and internal
wait failures use this path.

Affects: Apple A9 (S8003); chips without a licence callback do not read RGX
Assisted-by: LLM
A quick idle suspend and resume can restart firmware before the chip's
minimum gate-off interval expires. Record successful power-off time and
wait only its remaining interval before powering up. Retain reset's
existing delay. Chips with no minimum are unaffected.

Affects: Apple A9 (S8003); A10 has no gate-off minimum
Assisted-by: LLM
A slot tag can wrap onto firmware's cached value, making a page-table
change invisible and retaining stale translations. Share the helper
that skips zero and the cached tag, retaining unsigned wrap and the
steps-past counter. Leave A10's generation bump unchanged until its
cached-generation offset is known.

Affects: Apple A9 (S8003); A10 unchanged
Assisted-by: LLM
Native creation pins all backing pages, so a client can exhaust memory
needed to recover. Charge before taking pages and refuse above device
and per-TGID budgets with -ENOMEM and a ratelimited diagnostic. Share
accounting across the creator's DRM files, uncharge at free and exclude
imports. Defaults are 50 percent of RAM and 75 percent of that device
budget per client. Create-time charging counts real backing here; it
can move to residency when eviction becomes available.

Affects: every PowerVR device
Assisted-by: LLM
Pool-limit failures cannot be attributed without the sizes real scenes
ask the PM to hold. Log VM, blocks, clamp, tiles and initial free-list
pages once per VM when its first pool is built. Reuse existing values
and add no register access.

Affects: Apple A9 (S8003); A10 unchanged
Assisted-by: LLM
A firmware fault stopped the iPad 5 GPU, but submitted jobs waited for
the five-second scheduler timeout. Fault the one scheduler owning the
oldest bound hardware fence; its reset cancels all pending engines.
Bind scheduler metadata under the fence lock and retain normal timeout
coverage for unbound fences. Mark the selected fence so the timeout
handler says the job was lost to a firmware fault. Keep context failure,
stop, reset and restart unchanged. A10 can opt in once its fault event
types are confirmed.

Affects: Apple A9 (S8003); A10 event policy unchanged
Assisted-by: LLM
Driver removal freed firmware storage while the DMA writer still ran.
Stop firmware and pollers before releasing pages, and defer an idle
firmware restart until a job needs it. A blocked submit ioctl also held
reboot in DRM unplug SRCU for minutes. Quiesce hardware in shutdown
without unplug or scheduler flush. Bound submit locking and engine waits,
cancel fences with -ESHUTDOWN, and use terminal-only non-joining work,
mailbox and runtime-PM operations. Preserve the existing power requests
and force-stop writes. Retain callback storage until CPUs stop; ordinary
teardown still joins workers.

Affects: Apple A9 and A10 firmware teardown and reboot
Assisted-by: LLM
Keep the native BO cap at S8003 50/75 defaults and off on other chips unless explicitly configured. Track one devfreq suspend reference across lazy runtime resumes, failed starts and system sleep on both Apple chips.

Assisted-by: LLM
Keep the branch based on the updated A9 render series.

Assisted-by: LLM
A 1 MiB buffer at BO offset zero can cross a 2 MiB device-VA boundary.
Sizing the table reserve from the BO offset leaves it one table short,
so mapping fails with ENOMEM on every retry despite available memory.
Masked indices can also wrap across a parent boundary and underflow the
allocation count. Count absolute regions through the inclusive last VA;
retain the BO offset only for the scatter-gather cursor.

Fixes: ff5f643de0bf ("drm/imagination: Add GEM and VM related code")
Affects: every PowerVR device
Assisted-by: LLM
…pletion

The poll work re-arms a 100 us timer for as long as any job is pending:
about 10,000 wakeups a second whenever the GPU is busy, and a finished
job is seen up to 100 us late.

Let a chip hand the backend its firmware's interrupt. The hard IRQ handler
acknowledges it at the source through the new irq_ack() op and kicks the
poll work, which drains the firmware's rings and signals fences as
before. The interrupt is requested with IRQF_NO_AUTOEN and enabled only
while fences are pending, because firmware that is up but idle raises it
as well. While it is enabled the poll work re-checks every irq_poll_us,
except for PVR_APPLE_FAST_US after a chip reported a finished job
(pvr_apple_firmware_progress()). The stamps and ring watermarks that
make a job done do not all reach memory at the same moment, so those
re-checks keep apple_poll_us.

pvr_apple_firmware_event() is the one place that kicks the poll work for
the firmware. The A10's RTKit receive callback now calls it as well,
with the same behaviour as before. The A10 takes no interrupt here and
keeps polling, because none of its firmware messages is known to mean
completion.

Affects: Apple A9 (S8003) and A10 (T8010); the A10 keeps polling, no behaviour change

Assisted-by: LLM
The A9's firmware raises AIC interrupt 174, the node's fifth, by writing
its bit to the AIC's software-set register (AIC+0x4014, bit 14). The
apple-aic driver never clears a software-set interrupt, so taking it
without help would fire again as soon as it is unmasked. That is why the
backend polled for finished jobs every 100 us.

Apple's kext clears the bit itself at the software-clear register
(AIC+0x4094 for interrupt 174) before it reads the rings, and so does
this. irq_ack() writes the bit to that word, which init() maps from the
AIC's address in the device tree, and the shared code then takes the
interrupt while jobs are pending. A stamp event read from the event ring
marks progress, so completion is checked again at 100 us steps for a
millisecond while the job's watermarks reach memory. Otherwise the
backstop period is 1 ms, the period of s8003_touch() that the firmware
needs to make progress at all.

If the interrupt or its register cannot be had, the backend logs a
warning and polls as before.

Affects: Apple A9 (S8003)

Assisted-by: LLM
… write

While a job runs, s8003_touch() reads every cache line of the
firmware's root and shared memory and of every PM set that some VM has
taken, at most once a millisecond: about 9,700 non-cached loads, or
0.2 ms of CPU each time, with two clients. The firmware needs those
reads to see its own progress. A set it is not writing gains nothing
from them.

Read only the sets the firmware may be writing: those with a geometry
or fragment job that is not done yet, and those of the VMs that
submitted the last two scenes, whose free lists the PM writes back when
a later job runs (the reason for the park VM). Each set's last geometry
and fragment job is kept for this, and the last two VMs' sets as a mask.
Both are written under submit_lock and read without it. A set read for
nothing costs time only. The root and shared memory are still read
whole.

On the iPad 5, restricting these reads was safe: the reads
took 25 to 33 % less time, with no slower phase, timeout or fault. Also
allow the 1 ms period an eighth of slack, so that a check made exactly
every millisecond does not skip every other read.

Affects: Apple A9 (S8003)

Assisted-by: LLM
…is not clean

Every geometry job starts with the PM record command {6, slot, PM id,
set}. It has the firmware take the PM state from the set and rebuild
the set's free list from its block list, which is per-job firmware
time. Earlier hardware measurements sent it only when the set was not known to be
clean, and otherwise {4, the geometry channel's stamp, seq - 1}, a wait
that is already satisfied. On the iPad 5 that cut a small render pass
by a third and raised glmark2 by 6 to 35 % per scene, with no fault,
timeout or free-list drift. It let the next geometry job run under the
previous fragment job, as on iOS.

Do the same. A set is clean for a geometry job when:
- it is not built anew for the job (same firmware start, pool large
  enough);
- its last scene ran to its end in this firmware start: geometry and
  fragment job both handed over, the fragment job done, no fault
  latched.

A scene without a fragment job gave no pages back and leaves the set
dirty. So does a job that failed before it reached the firmware. A
firmware start (every runtime resume, every reset) builds the sets anew.

Unlike in earlier hardware measurements, a geometry job here can be written while the
one before it still runs. The {4} form would then make the firmware
wait on its own stamp, which it sees late without the host's reads. So
the record is skipped only when job seq - 1 is already done.

Affects: Apple A9 (S8003)

Assisted-by: LLM
An S8003 scene that exhausts its PM pool stops the firmware. Dataset
sizing alone does not incorporate what previous scenes actually used.

Read the firmware high-water mark, margin and bounded growth request from
the completed set's list page, following its taken-flag protocol. At most
every 167 ms per VM, grow to three times high-water or one block plus the
margin, otherwise by the request (at most eight blocks). Ignore impossible
values and retain the existing pool cap.

Take feedback in the geometry submission's process context, under the
existing submit lock, just before the existing idle-set pool allocator.
No reclaim or prepared-pool infrastructure is needed by this change.

Affects: Apple A9 (S8003). The A10 is unchanged.

Assisted-by: LLM
…ugfs

Runtime suspend stops the firmware and the next job starts it again, but
host in-flight durations do not show that cycle's cost or the work spent
checking for completion.

Expose a read-only apple_jobs file and snapshot job progress without
powering up the GPU. Report firmware starts and failures, gate-off waits,
boot/resume/first-job latency, suspend duration, IRQs and poll iterations.
Let each chip add its own measurements; S8003 reports cache-line read time,
PM record use, pool feedback and its wait loops. Keep the existing power
policy, submission order and completion criteria unchanged.

Affects: Apple A9 (S8003) and A10 (T8010), debugfs measurements only.

Assisted-by: LLM
…ady state

The clean-set path waits on the immediately preceding geometry job. When
that job is still running it falls back to a full PM record, rebuilding
the free list even though this set has not changed.

Follow AGXTACommandDescriptor_preparePMAndWork: remember the geometry job
that last carried each set's PM record and wait only on that stamp for a
clean set. A newer ordinary geometry job does not force a rebuild. Reset
the remembered stamp when backing is rebuilt or firmware restarts, and
fall back to a record if the rebuild stamp has not been reached.

Make this the single behavior. No always-rebuild or legacy-wait mode and
no module parameter are added. Keep the existing clean-set bookkeeping
in the prerequisite series; report clean queued and unreached stamps.

Affects: Apple A9 (S8003). The A10 is unchanged.

Assisted-by: LLM
@henrikklee
henrikklee merged commit 9f16e13 into OrchardLinux:main Nov 17, 2026
11 checks passed
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.

2 participants