mirror of
https://github.com/UniXNU/NativeAdreno.git
synced 2026-11-17 04:51:59 +03:00
feat(adreno): report BO pool pressure in Query flags
NativeAdrenoParamsPoolPressure tells clients to give cached BOs back.
This commit is contained in:
+2
-1
@@ -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 */
|
||||
|
||||
@@ -5,6 +5,7 @@ extern "C" {volatile uint32_t native_adreno_trace_stage;}
|
||||
#include <IOKit/IOBufferMemoryDescriptor.h>
|
||||
#include <IOKit/IOLib.h>
|
||||
#include <kern/task.h>
|
||||
#include <kern/clock.h>
|
||||
|
||||
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<window;
|
||||
}
|
||||
uint64_t NativeAdrenoMemory::poolPhysical() {return pool.descriptor?pool.physical:0;}
|
||||
/* int-152: a user BO's pages changed attribute one pmap_set_cache_attributes call at a time (each walks the page's mappings, flushes the
|
||||
* TLB and cleans the page), on allocation and again on release, under the connection lock: 3 ms a BO on average and 90-130 ms for a
|
||||
@@ -125,6 +136,7 @@ IOReturn NativeAdrenoMemory::allocate(size_t bytes,unsigned bits,bool contiguous
|
||||
}
|
||||
}
|
||||
native_adreno_pool_stats[2]=native_adreno_pool_stats[2]+1;
|
||||
gPoolMissAt=mach_absolute_time();
|
||||
}
|
||||
IOOptionBits options=static_cast<IOOptionBits>(kIODirectionInOut)|static_cast<IOOptionBits>(kIOMemoryMapperNone);
|
||||
if(contiguous)options|=kIOMemoryPhysicallyContiguous;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)<<NativeAdrenoAbiMaxBoBytesShift;
|
||||
params->flags=NativeAdrenoParamsHostImport|(ownedCoherent()?NativeAdrenoParamsOwnedCoherent:0u)|
|
||||
(NativeAdrenoMemory::poolPressure()?NativeAdrenoParamsPoolPressure:0u);params->max_bo_bytes=UINT64_C(1)<<NativeAdrenoAbiMaxBoBytesShift;
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
/* Per client slot (4, the kernel's own client last): [0] live objects now, [1] their peak, [2] refused BoAllocs, [3] last refusal status,
|
||||
|
||||
Reference in New Issue
Block a user