diff --git a/NativeAdrenoGpuContext.cpp b/NativeAdrenoGpuContext.cpp index 1d7f607..27f0fe6 100644 --- a/NativeAdrenoGpuContext.cpp +++ b/NativeAdrenoGpuContext.cpp @@ -193,11 +193,20 @@ IOReturn NativeAdrenoGpuContext::clearFault(uint32_t fsr,uint32_t far[3]) if(io->write32(io->cookie,(size_t)offset+0x58,fsr) || io->barrier(io->cookie))return kIOReturnIOError; return kIOReturnSuccess; } +extern "C" {extern volatile uint32_t native_adreno_global_fault[4];} IOReturn NativeAdrenoGpuContext::endFault(uint32_t out[4]) { if(!out || !ready_)return kIOReturnBadArgument; out[0]=out[1]=out[2]=out[3]=0; const ArmSmmu4KIo *io=smmu_.ioHandle(); + { /* The global fault status the GPU's faulting access left (sGFSR, write one to clear): cleared with the context's, or every + * later look at the SMMU reads it. Its last value is kept. */ + uint32_t global=0; + if(!io->read32(io->cookie,0x48,&global) && global) { + native_adreno_global_fault[2]=native_adreno_global_fault[2]+1;native_adreno_global_fault[3]=global; + (void)io->write32(io->cookie,0x48,global); + } + } const uint64_t offset=smmu_.stateHandle()->context_offset; if(!offset)return kIOReturnNotReady; if(io->read32(io->cookie,(size_t)offset+0x58,&out[0]))return kIOReturnIOError; diff --git a/NativeAdrenoSubmit.cpp b/NativeAdrenoSubmit.cpp index f06ef18..475955d 100644 --- a/NativeAdrenoSubmit.cpp +++ b/NativeAdrenoSubmit.cpp @@ -75,6 +75,43 @@ static void peekFetch(const NativeAdrenoVm *vm,uint64_t fetch,volatile uint32_t slot[0]=0xffff0000u+before; for(unsigned i=0;i<16;++i)slot[1+i]=words[i]; } +/* Where the stalled job's command buffers name the IB2 the thread stopped in: every IB1 of the job (the CP_INDIRECT_BUFFER packets + * of its ring words) is read for a CP_INDIRECT_BUFFER whose low address word is the IB2 base register's. [0] how many were found, + * [1] the IB1's place in the job, [2..3] its address, [4] the packet's dword offset in it, [5..10] the packet's four words and the + * two before it, [11] IB1s read, [12] dwords read, [13] IB1s that could not be read. Nothing found with every IB1 read means the + * address did not come from the job's commands. */ +extern "C" {volatile uint32_t native_adreno_stall_find[14];} +static bool indirectBuffer(uint32_t header) {return (header>>28)==7u && ((header>>16)&0x7fu)==0x3fu && (header&0x3fffu)==3;} +static void findIb2(const NativeAdrenoVm *vm,const uint32_t *ring_words,size_t ring_count,uint32_t ib2_low) +{ + uint32_t out[14]={}; + static uint32_t chunk[1024]; + uint32_t index=0; + for(size_t i=0;i+3peekWordsUncached(ib1+4ull*at,chunk,take)) {++out[13];break;} + out[12]+=take; + for(uint32_t k=0;k+3>32);out[4]=at+k; + out[5]=k>=2?chunk[k-2]:carry[0];out[6]=k>=1?chunk[k-1]:carry[1]; + for(unsigned w=0;w<4;++w)out[7+w]=chunk[k+w]; + } + ++out[0]; + } + carry[0]=chunk[take>=2?take-2:0];carry[1]=chunk[take-1]; + } + ++index; + } + for(unsigned i=0;i<14;++i)native_adreno_stall_find[i]=out[i]; +} static uint32_t stall_fence,stall_timeouts,stall_stage; /* stage: 0 none yet, 1 write pointer given again, 2 translations dropped, 3 bus drained */ static uint64_t stall_began_us,stall_last_us; /* the fence's first and latest timed-out wait */ /* How long fences stayed pending from their first timed-out wait to their last: [i] under 1 << i ms for i < 7, [7] 64 ms or more. */ @@ -841,6 +878,7 @@ void NativeAdrenoSubmit::snapshot(uint32_t next,uint32_t waited,uint64_t now,uin if(!stalled->ibBefore(words[16],&ib,&size))peekIb(space,ib,size,words[18],&native_adreno_stall_mem[4+17]); else peekFetch(space,(uint64_t)words[11]<<32|words[17],&native_adreno_stall_mem[4+17]); /* BV IB1 base: the low word only */ peekFetch(space,(uint64_t)words[21]<<32|words[20],&native_adreno_stall_mem[4+34]); + if(job && job->word_count)findIb2(space,job->words,job->word_count,words[13]); { uint64_t brIb=(uint64_t)words[11]<<32|words[10],bvIb=(uint64_t)words[11]<<32|words[17]; if(!stalled->ibBefore(words[8],&ib,&size))brIb=ib; diff --git a/NativeAdrenoVm.cpp b/NativeAdrenoVm.cpp index 586e814..e67fb99 100644 --- a/NativeAdrenoVm.cpp +++ b/NativeAdrenoVm.cpp @@ -87,14 +87,25 @@ struct PhaseClock { } }; } +/* The SMMU's global fault status set while the routes and the global configuration read as they should: the GPU's own access + * faulted (a job's bad address), which the hang check ends and clears (NativeAdrenoGpuContext::endFault). It says nothing about + * this address space's tables, so the operation goes on; taking the address space out of use here failed whichever process + * mapped or attached next (seven of them in one run, the render server among them). Counted with the status word. */ +extern "C" {volatile uint32_t native_adreno_global_fault[4];} +ArmSmmu4KStatus NativeAdrenoVm::notOurFault(ArmSmmu4KStatus status,uint32_t word) +{ + if(status!=ArmSmmu4KFault)return status; + native_adreno_global_fault[0]=native_adreno_global_fault[0]+1;native_adreno_global_fault[1]=word; + return ArmSmmu4KSuccess; +} ArmSmmu4KStatus NativeAdrenoVm::observe() const { ArmSmmu4KStreamResult routes; - ArmSmmu4KStatus status=ArmSmmu4KObserveStreams(&io_,streams_,context_,&routes);if(status)return status; + ArmSmmu4KStatus status=notOurFault(ArmSmmu4KObserveStreams(&io_,streams_,context_,&routes),routes.global_fault);if(status)return status; ArmSmmu4KLiveRegion lower=region(0),upper=region(1);ArmSmmu4KLiveResult audit; status=ArmSmmu4KLiveAuditContext(context_,lower.arena?&lower:nullptr,upper.arena?&upper:nullptr,&audit); if(status)return status; - return ArmSmmu4KObserveStreams(&io_,streams_,context_,&routes); + return notOurFault(ArmSmmu4KObserveStreams(&io_,streams_,context_,&routes),routes.global_fault); } /* Global policy, the context image and the owned routes only. The scan of every other slot for a conflicting route read each * SMR/S2CR of the SMMU twice per map and unmap (int-152: 0.75 ms a pass, 1.3 s of the 3.2 s of 807 maps); observe(), which @@ -113,7 +124,7 @@ ArmSmmu4KStatus NativeAdrenoVm::observeCheap() if(++since_audit_>=64) { since_audit_=0; ArmSmmu4KStreamResult routes; - return ArmSmmu4KObserveStreams(&io_,streams_,context_,&routes); + return notOurFault(ArmSmmu4KObserveStreams(&io_,streams_,context_,&routes),routes.global_fault); } return ArmSmmu4KSuccess; } diff --git a/NativeAdrenoVm.h b/NativeAdrenoVm.h index b154e2d..085fbfc 100644 --- a/NativeAdrenoVm.h +++ b/NativeAdrenoVm.h @@ -130,6 +130,7 @@ class NativeAdrenoVm final { * map/unmap pay a full extra audit only every 64th operation (int-139: 4 full walks of the 2 GiB aperture made every map 70 ms). */ ArmSmmu4KStatus observeStreamsOnly() const; ArmSmmu4KStatus observeCheap(); + static ArmSmmu4KStatus notOurFault(ArmSmmu4KStatus,uint32_t word); unsigned since_audit_=0; IOReturn failAt(ArmSmmu4KStatus,unsigned line); Mapping *find(uint64_t);