diff --git a/NativeAdrenoABI.h b/NativeAdrenoABI.h index c2c4333..5259024 100644 --- a/NativeAdrenoABI.h +++ b/NativeAdrenoABI.h @@ -42,7 +42,8 @@ struct NativeAdrenoAbiParams { }; enum { NativeAdrenoParamsHostImport = 1, /* BoImport pins the caller's own pages (an IOSurface's) as a BO */ - NativeAdrenoParamsOwnedCoherent = 2 /* BOs are cacheable for the CPU and mapped write-back inner-shareable for the GPU (IO coherence): map them with the default cache mode, not write-combined */ + NativeAdrenoParamsOwnedCoherent = 2, /* BOs are cacheable for the CPU and mapped write-back inner-shareable for the GPU (IO coherence): map them with the default cache mode, not write-combined */ + NativeAdrenoParamsPoolPressure = 4 /* now: the shared BO pool is nearly full or could not serve an allocation lately; give cached BOs back */ }; struct NativeAdrenoAbiBoAlloc { uint64_t bytes; /* 4KiB multiple, <= max_bo_bytes */ diff --git a/NativeAdrenoMemory.cpp b/NativeAdrenoMemory.cpp index aa6f194..002d8d3 100644 --- a/NativeAdrenoMemory.cpp +++ b/NativeAdrenoMemory.cpp @@ -5,6 +5,7 @@ extern "C" {volatile uint32_t native_adreno_trace_stage;} #include #include #include +#include static bool outputWidth(unsigned bits) {return bits==32 || bits==36 || bits==40 || bits==42 || bits==44 || bits==48;} @@ -53,6 +54,16 @@ void poolGive(size_t offset,size_t bytes) { } } size_t NativeAdrenoMemory::poolBytes() {return pool.bytes;} +static uint64_t gPoolMissAt; /* mach_absolute_time of the last allocation the pool could not serve, 0 none */ +bool NativeAdrenoMemory::poolPressure() +{ + if(!pool.descriptor || !pool.bytes)return false; + if(pool.used>pool.bytes-pool.bytes/8)return true; + const uint64_t miss=gPoolMissAt; + if(!miss)return false; + uint64_t window=0;nanoseconds_to_absolutetime(2000000000ull,&window); + return mach_absolute_time()-miss(kIODirectionInOut)|static_cast(kIOMemoryMapperNone); if(contiguous)options|=kIOMemoryPhysicallyContiguous; diff --git a/NativeAdrenoMemory.h b/NativeAdrenoMemory.h index d0b1261..381bb76 100644 --- a/NativeAdrenoMemory.h +++ b/NativeAdrenoMemory.h @@ -72,6 +72,9 @@ public: * allocate(..., pooled=true) uses the pool when one is reserved and has room, else the scattered path. Only the board calls this. */ static IOReturn reservePool(unsigned output_bits,size_t bytes); static size_t poolBytes(); + /* Pressure on the pool every client allocates from: more than seven eighths in use, or an allocation it could not serve in the last + * two seconds (that one fell back to scattered pages). Clients poll it (Query) and empty their BO caches. */ + static bool poolPressure(); /* The pool's first physical byte (0 without a pool): its pages belong to pooled BOs alone. */ static uint64_t poolPhysical(); /* The whole pool write-combined once, for good: a pooled BO then takes no page-attribute change on allocation or release. diff --git a/NativeAdrenoUserClient.cpp b/NativeAdrenoUserClient.cpp index 101b6c2..32f9ce5 100644 --- a/NativeAdrenoUserClient.cpp +++ b/NativeAdrenoUserClient.cpp @@ -173,7 +173,8 @@ IOReturn NativeAdrenoUserClient::query(NativeAdrenoAbiParams *params) if(!open_)return kIOReturnNotReady; params->abi_version=NativeAdrenoAbiVersion; params->input_bits=input_bits_;params->output_bits=output_bits_; - params->flags=NativeAdrenoParamsHostImport|(ownedCoherent()?NativeAdrenoParamsOwnedCoherent:0u);params->max_bo_bytes=UINT64_C(1)<flags=NativeAdrenoParamsHostImport|(ownedCoherent()?NativeAdrenoParamsOwnedCoherent:0u)| + (NativeAdrenoMemory::poolPressure()?NativeAdrenoParamsPoolPressure:0u);params->max_bo_bytes=UINT64_C(1)<