Skip to content

kernel: S8003 firmware interrupt, PM work gating and pool growth - #153

Merged
henrikklee merged 25 commits into
OrchardLinux:mainfrom
brkosebay:a9-gpu-firmware-perf
Nov 17, 2026
Merged

henrikklee merged 25 commits into
OrchardLinux:mainfrom
brkosebay:a9-gpu-firmware-perf

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

Depends on #150, #151. Only the last 6 commits are new in this PR.

Summary

Use the firmware interrupt to drive completion checks, restrict cache-line
reads to PM sets the firmware can write, skip redundant PM records, and grow
idle PM pools from firmware feedback. Keep runtime-PM and wait counters in
debugfs. The behavior is fixed; no performance-comparison module parameters
are added.

This series uses #151's terminal-shutdown/fault lifetime guards, gate-off
interval tracking and initial PM-pool diagnostics. It does not carry the
eviction series. Feedback growth uses the existing process-context pool
allocator before the geometry job is written.

Commits

  • Let a chip's firmware interrupt drive job completion
  • Take the S8003 firmware's interrupt
  • Touch only the S8003 PM sets the firmware may write
  • Send the S8003 PM record only for a set that is not clean
  • Grow an S8003 PM pool from firmware feedback
  • Report runtime PM cycles and job waits in debugfs

Hardware

On the iPad 5, host in-flight time per fragment job fell by 8%, with zero
GPU faults. These measurements cover the series together; they do not
isolate an individual commit. Fullscreen glmark2 went from 386 to 418, but
those were separate boots, not repeated, and glmark2 drifts about 16% run to
run on this device, so the score is not the claim.

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. The shared parts run on the T8010 too: its
RTKit receive callback now goes through the same firmware-event helper,
with the same lifetime guard, and it gets the common apple_jobs lines
(per-engine submitted/done/pending, busy time, runtime PM, poll and wait
counters). The T8010 keeps polling for completion (fw_irq none), because
none of its firmware messages is known to mean "job done".

The PM-set touch mask, PM-record gating and feedback pool growth stay
S8003-only because the hardware path differs: they operate on the host-
managed PM sets and command records of the S8003 firmware. The T8010
firmware manages its own PM through an RTKit work ring with StartTA
free-list descriptors; it has no host PM sets or records for these to act
on.

A10 testers: please post apple_jobs before and after a fullscreen GPU run,
and any new firmware crash, GPU fault or hang in dmesg.

How to test

sudo find /sys/kernel/debug/dri -name apple_jobs -exec cat {} +
glmark2-es2-wayland --fullscreen
sudo find /sys/kernel/debug/dri -name apple_jobs -exec cat {} +
sudo dmesg | grep -i powervr
  • A9: fw_irq is on or off (not none) and its irqs count rises;
    done catches up with submitted, pending is 0 once idle; pm_record
    shows far more clean than full; fault 0.
  • A10: fw_irq none is expected (still polled). submitted/done must
    advance and there are no S8003 lines (touch, pm_record, pm_pool). A
    fault or hang here is a regression in the shared path.
  • A/B: boot the base branch kernel. 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
@henrikklee
henrikklee merged commit 886bd8b into OrchardLinux:main Nov 17, 2026
11 checks passed
shaynelegault pushed a commit to shaynelegault/hardware that referenced this pull request Nov 19, 2026
OrchardLinux#151, OrchardLinux#152, OrchardLinux#153 and OrchardLinux#157 were each written on OrchardLinux#150 alone. Combined:

- gpu/0051: the BO memory cap charges a native BO at creation, also when
  its pages come later.
- gpu/0053: one record of the last two PM scenes, shared by the cache-line
  touch mask and the eviction veto.
- gpu/0054: the restore path and VM_MAP size their page tables from the
  device address, as gpu/0042 made VM_MAP do.
- gpu/0055: pools are prepared in the submit ioctl and sized for the
  firmware's feedback too; the job worker only switches to a prepared
  pool, between scenes, and never allocates.
- gpu/0058: completions are signalled before the S8003 rings are
  touched, in the poll worker of gpu/0041 and gpu/0043.

Two fixes on top: one submission order lock per device instead of one
for every PowerVR device (gpu/0059), and the job worker allocates as
before on chips that cannot evict (gpu/0060), so the A10 is unchanged.

Left out: GPU time in debugfs (OrchardLinux#156; belongs in per-client fdinfo
accounting) and the default-off scene overlap switch (OrchardLinux#157's second
patch). The s8003 display DART patch becomes devices/s8000/0017; main
took 0016 meanwhile.

Assisted-by: LLM
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