From 88b83dd0ef7cfec2927dc55a3ab308f6b675b080 Mon Sep 17 00:00:00 2001 From: rpone Date: Sat, 31 Oct 2026 19:43:24 +0800 Subject: [PATCH] feat(timeline): owner pid and retire time per GPU job Each timeline entry records the submitting process and when the driver saw the job retired, so a frame's wait for the ring and for completion can be split. --- NativeAdrenoSubmit.cpp | 11 +++++++---- NativeAdrenoSubmit.h | 6 ++++++ NativeAdrenoUserClient.cpp | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/NativeAdrenoSubmit.cpp b/NativeAdrenoSubmit.cpp index 25576cf..ee7a4e5 100644 --- a/NativeAdrenoSubmit.cpp +++ b/NativeAdrenoSubmit.cpp @@ -60,9 +60,9 @@ extern "C" {volatile uint32_t native_adreno_ib_log[4][4+28];volatile uint32_t na extern "C" volatile uint32_t native_adreno_table_switches[8]; /* Where the last recover() stopped: [0] the step (1 fence read, 2 restart hook, 3 table write, 4 nop encode, 5 replay vm, 6 replay submit), [1] the IOReturn or value there, [2] fence, [3] last submitted. */ extern "C" {volatile uint32_t native_adreno_recover_trace[4];} -/* The jobs' timeline (the newest native_adreno_tl_cap retired, allocated at attach): [0] fence | indirect buffers << 32, [1] submit time (us), [2] the CP's always-on counter before the - * job's buffers, [3] after them (19.2 MHz ticks; 0 when not stamped), [4] GPU level at submit | observed retire time << 8 (us, low 56 bits), - * [5] jobs retired before it that are still counted (the sequence number). native_adreno_tl_count is the total. */ +/* The jobs' timeline (the newest native_adreno_tl_cap retired, allocated at attach): [0] fence | indirect buffers << 32 | ring status << 58, [1] submit + * time (us), [2] the CP's always-on counter before the job's buffers, [3] after them (19.2 MHz ticks; 0 when not stamped), [4] GPU level at submit | + * the submitting pid << 32, [5] when the driver saw the job retired (us, the submission clock). native_adreno_tl_count is the total. */ extern "C" {volatile uint64_t (*native_adreno_tl)[6]=nullptr;volatile uint32_t native_adreno_tl_cap=0;volatile uint32_t native_adreno_tl_count;} /* The stall handler's actions (the newest 32): [0] time (us), [1] fence, [2] event (1 write pointer given again and translations dropped, 3 bus drain, * 4 snapshot, 0 the stall ended) | timed-out waits << 8, [3] time the fence had been pending (us), [4] read and write pointer before | after << 32 for @@ -155,7 +155,8 @@ IOReturn NativeAdrenoSubmit::release(Job &job) if(native_adreno_tl_cap) { const uint32_t n=native_adreno_tl_count;volatile uint64_t *slot=native_adreno_tl[n&(native_adreno_tl_cap-1)]; slot[0]=(uint64_t)job.fence|(uint64_t)job.count<<32|(uint64_t)stamped<<58;slot[1]=job.submit_us; - slot[2]=start;slot[3]=end;slot[4]=(uint64_t)job.level;slot[5]=n; + slot[2]=start;slot[3]=end;slot[4]=(uint64_t)job.level|(uint64_t)(uint32_t)job.owner<<32; + slot[5]=clock_now_?clock_now_(clock_cookie_):0; native_adreno_tl_count=n+1; } } @@ -328,7 +329,9 @@ IOReturn NativeAdrenoSubmit::submit(NativeAdrenoVm *vm,const NativeAdrenoSubmitB job->count=handle_count;job->fence=value;job->queue=queue;job->active=true;job->vm_next=vm_->nextHandle();job->vm=vm; job->context=ring_->context();job->word_count=word_count; job->submit_us=clock && clock->now_us?clock->now_us(clock->cookie):0; + if(clock && clock->now_us) {clock_now_=clock->now_us;clock_cookie_=clock->cookie;} job->level=&native_gpu_dcvs?native_gpu_dcvs[1]:0; + job->owner=next_owner_;next_owner_=0; for(size_t i=0;iwords[i]=words[i]; ++stats_.submissions; if(outstanding()>stats_.peak_jobs)stats_.peak_jobs=outstanding(); diff --git a/NativeAdrenoSubmit.h b/NativeAdrenoSubmit.h index c80cf60..00fb088 100644 --- a/NativeAdrenoSubmit.h +++ b/NativeAdrenoSubmit.h @@ -55,6 +55,7 @@ class NativeAdrenoSubmit final { uint32_t context=0; /* the ring context it ran in (NativeAdrenoRing::useContext) */ uint64_t submit_us=0; /* the clock when the write pointer moved (0: no clock), and the GPU level then (native_gpu_dcvs) */ uint32_t level=0; + int32_t owner=0; /* the process that submitted it (nextOwner) */ size_t word_count=0; /* its ring words (the IB packets), kept to replay it after a GPU restart */ uint32_t words[NativeAdrenoSubmitMaxBuffers*4]{}; }; @@ -88,7 +89,12 @@ class NativeAdrenoSubmit final { Job *free(); IOReturn release(Job &); IOReturn poison(); + int32_t next_owner_=0; + /* The clock of the last submission, for the time a job is seen retired (release has no clock of its own). */ + uint64_t (*clock_now_)(void *)=nullptr;void *clock_cookie_=nullptr; public: + /* The process the next submission comes from, for the timeline (the user client sets it before each submit). */ + void nextOwner(int32_t pid) {next_owner_=pid;} NativeAdrenoSubmit()=default; ~NativeAdrenoSubmit()=default; NativeAdrenoSubmit(const NativeAdrenoSubmit &)=delete; diff --git a/NativeAdrenoUserClient.cpp b/NativeAdrenoUserClient.cpp index a2bfb13..5f7d71a 100644 --- a/NativeAdrenoUserClient.cpp +++ b/NativeAdrenoUserClient.cpp @@ -400,6 +400,7 @@ IOReturn NativeAdrenoUserClient::submit(const NativeAdrenoAbiSubmit *request, uint32_t fence=0; used_=true; ring_->useContext(context_); + submit_->nextOwner(proc_selfpid()); const IOReturn status=submit_->submit(vm_,buffers,request->buffer_count, queue_base_+request->queue,&fence,clock); if(status)return status;