Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
Surfaces around the window server's pictures (IOSurfaceWrapClientImage, ~4000 refused requests a second, 9% of its drawing thread); a still surface looked at every 8th frame, not every frame (adding them all up took half the thread); glprof=US: the drawing thread's profile; surf_wrap=0, glstill=0 to compare
shimoku74759b62052c5b
diff --git a/configs/boot-args.lst b/configs/boot-args.lstindex 6a3a0fb..3147932 100644--- a/configs/boot-args.lst+++ b/configs/boot-args.lst@@ -114,6 +114,7 @@ glno uglnumbers uglplain uglprecision u+glprof uglsb3 uglshaders uglshow u@@ -121,6 +122,7 @@ glshow_part uglshow_zoom uglskip uglslow u+glstill uglsync ugltrace ugltrace_at u@@ -242,6 +244,7 @@ sound_pause ksound_secs kspeaker_probe ksurf_clear k+surf_wrap ksurftrace ksurftrace_of kswitcher_wallpaper udiff --git a/configs/common_defconfig b/configs/common_defconfigindex e702006..08ae448 100644--- a/configs/common_defconfig+++ b/configs/common_defconfig@@ -2,7 +2,7 @@# HakiOS common defconfig: every setting there is, with what it does.# Made by tools/hakios-config.py listing common -o <this file>; the values are the ones that file sets, and tests/CI check that it names every symbol.#-# 347 symbols in 18 groups; 34 are set, 25 of them drivers built in.+# 350 symbols in 18 groups; 34 are set, 25 of them drivers built in.##@@ -335,7 +335,7 @@ CONFIG_TOUCHSCREEN=y# CONFIG_VIRTIO_INPUT is not set#-# GPU and display (71)+# GPU and display (74)## rendering on Adreno (an image built with GL=1; the GPU's firmware from your phone) [needs fw-gpu/ from the phone]@@ -449,6 +449,9 @@ CONFIG_GPU=y# as the shaders say.# CONFIG_GLPRECISION is not set+# read by eagl.c (user space)+# CONFIG_GLPROF is not set+# read by eagl.c (user space)# CONFIG_GLSHADERS is not set@@ -467,6 +470,9 @@ CONFIG_GPU=y# read by eagl.c (user space)# CONFIG_GLSLOW is not set+# read by eagl.c (user space)+# CONFIG_GLSTILL is not set+# read by eagl.c (user space)# CONFIG_GLSYNC is not set@@ -539,6 +545,9 @@ CONFIG_GPU=y# kept memory is given out as it is (to see what the clearing costs; a surface is then not all zeroes)# CONFIG_SURF_CLEAR is not set+# surfaces around the client's pictures refused, as before methodWrapClientImage (for comparing)+# CONFIG_SURF_WRAP is not set+# log the first N surfaces created (default 24)# CONFIG_SURFTRACE is not setdiff --git a/configs/symbols.tsv b/configs/symbols.tsvindex 548174c..3b981c3 100644--- a/configs/symbols.tsv+++ b/configs/symbols.tsv@@ -105,6 +105,7 @@ GLNO arg glno User space u inject.cGLNUMBERS arg glnumbers GPU and display u eagl.cGLPLAIN arg glplain GPU and display u eagl.c leave such draws as they are; 2: also those without a texture; 3: the two with a colour matrix drawn plainly tooGLPRECISION arg glprecision GPU and display u eagl.c as the shaders say.+GLPROF arg glprof GPU and display u eagl.cGLSB3 arg glsb3 User space u inject.cGLSHADERS arg glshaders GPU and display u eagl.cGLSHOW arg glshow GPU and display u eagl.c the first texture of that size there is (names are handed out afresh every run)@@ -112,6 +113,7 @@ GLSHOW_PART arg glshow_part GPU and display u eagl.cGLSHOW_ZOOM arg glshow_zoom GPU and display u eagl.cGLSKIP arg glskip GPU and display u eagl.c the draws of those programs are left out of the picture, which says what in it is their workGLSLOW arg glslow GPU and display u eagl.c+GLSTILL arg glstill GPU and display u eagl.cGLSYNC arg glsync GPU and display u eagl.cGLTRACE arg gltrace GPU and display u eagl.cGLTRACE_AT arg gltrace_at GPU and display u eagl.c@@ -218,6 +220,7 @@ SOUND_PAUSE arg sound_pause Audio and battery k hakios.sound.cSOUND_SECS arg sound_secs Audio and battery k hakios.sound.cSPEAKER_PROBE arg speaker_probe Audio and battery k hakios.speaker.c reads registers and nothing else: the pins, the power names (below)SURF_CLEAR arg surf_clear GPU and display k MiniIOSurface.cpp kept memory is given out as it is (to see what the clearing costs; a surface is then not all zeroes)+SURF_WRAP arg surf_wrap GPU and display k MiniIOSurface.cpp surfaces around the client's pictures refused, as before methodWrapClientImage (for comparing)SURFTRACE arg surftrace GPU and display k MiniIOSurface.cpp log the first N surfaces created (default 24)SURFTRACE_OF arg surftrace_of GPU and display k MiniIOSurface.cppSWITCHER_WALLPAPER arg switcher_wallpaper User space u inject_sb.cdiff --git a/docs/boot-args.md b/docs/boot-args.mdindex cb91133..ba4e1b6 100644--- a/docs/boot-args.md+++ b/docs/boot-args.md@@ -2,13 +2,13 @@Made by `tools/boot-args.py --markdown`; CI fails if it is out of date with the source (`tools/boot-args.py --check`).-Every argument that the kernel, the loader or user space of this port reads, and which file reads it. **325 arguments**: 275 read by the kernel, 14 by the loader, 46 by user space (one is read in more than one place).+Every argument that the kernel, the loader or user space of this port reads, and which file reads it. **328 arguments**: 276 read by the kernel, 14 by the loader, 48 by user space (one is read in more than one place).This is a catalogue of what exists and who reads it, not a manual. What an argument means is in the head of the file that reads it. The stable switches have a symbol in the configuration (`tools/hakios-config.py help SYMBOL`, `docs/configs.md`); the rest are the knobs of bring-up (a driver's steps, pauses, traces, test modes) and can change with the driver. Any of them can be given in a configuration with `CONFIG_BOOTARGS="name=value ..."`, which checks that each name is in this list.Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl kern.bootargs`).-## GPU and display (71)+## GPU and display (74)| Argument | Layer | Read by | Configuration | Set by ||---|---|---|---|---|@@ -48,12 +48,14 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `glnumbers` | U | `eagl.c` | `CONFIG_GLNUMBERS` | || `glplain` | U | `eagl.c` | `CONFIG_GLPLAIN` | || `glprecision` | U | `eagl.c` | `CONFIG_GLPRECISION` | |+| `glprof` | U | `eagl.c` | `CONFIG_GLPROF` | || `glshaders` | U | `eagl.c` | `CONFIG_GLSHADERS` | || `glshow` | U | `eagl.c` | `CONFIG_GLSHOW` | || `glshow_part` | U | `eagl.c` | `CONFIG_GLSHOW_PART` | || `glshow_zoom` | U | `eagl.c` | `CONFIG_GLSHOW_ZOOM` | || `glskip` | U | `eagl.c` | `CONFIG_GLSKIP` | || `glslow` | U | `eagl.c` | `CONFIG_GLSLOW` | |+| `glstill` | U | `eagl.c` | `CONFIG_GLSTILL` | || `glsync` | U | `eagl.c` | `CONFIG_GLSYNC` | || `gltrace` | U | `eagl.c` | `CONFIG_GLTRACE` | || `gltrace_at` | U | `eagl.c` | `CONFIG_GLTRACE_AT` | |@@ -79,6 +81,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `rec_start` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_REC_START` | || `rec_step` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_REC_STEP` | || `surf_clear` | K | `MiniIOSurface.cpp` | `CONFIG_SURF_CLEAR` | |+| `surf_wrap` | K | `MiniIOSurface.cpp` | `CONFIG_SURF_WRAP` | || `surftrace` | K | `MiniIOSurface.cpp` | `CONFIG_SURFTRACE` | || `surftrace_of` | K | `MiniIOSurface.cpp` | `CONFIG_SURFTRACE_OF` | || `touch_lat` | KU | `MiniIOMobileFramebuffer.cpp`, `eagl.c`, `hakios.goodix.c`, `hakios.gpu.cpp`, `hakios.input.c`, `inject.c`, `inject_sb.c` | `CONFIG_TOUCH_LAT` | |diff --git a/userland/src/eagl.c b/userland/src/eagl.cindex 12fd9e7..3c359ee 100644--- a/userland/src/eagl.c+++ b/userland/src/eagl.c@@ -60,6 +60,9 @@*/#include <CoreFoundation/CoreFoundation.h>#include <IOKit/IOKitLib.h>+#include <dlfcn.h>+#include <mach/mach.h>+#include <pthread.h>#include <IOSurface/IOSurfaceRef.h>#include <libkern/OSByteOrder.h>#include <mach/mach_time.h>@@ -235,6 +238,7 @@ struct image {bool painted; /* something has been drawn into it (it is a target in fact, not only in name) */unsigned looked; /* ... the frame in which that memory was last looked at, */uint64_t sum; /* ... and what it added up to */+ unsigned unchanged; /* ... and how many looks in a row found it the same (surface_changed()) */GLenum to, internal, format, type;uint32_t plane, seed;GLsizei width, height;@@ -657,7 +661,16 @@ surface_shared(struct eagl *e, struct image *image)* made again. A GPU that has the memory itself shows what is there. A copy has to notice: once* a frame, when the texture is about to be drawn with, the memory is added up, and copied again* if the sum has changed.+ * Most of them never change -- the wallpaper, the icons, the pictures CoreAnimation has made surfaces around+ * (MiniIOSurface's methodWrapClientImage) -- and adding all of them up every frame took more than half of the drawing+ * thread's time (glprof: the wallpaper alone is 11 MB). One that has been the same STILL_LOOKS looks in a row (about a+ * second) is looked at every STILL_EVERY frames only, each in a frame of its own (by its surface's number); the first+ * change seen makes it looked at every frame again. A still picture that does change is seen at most STILL_EVERY frames+ * late (67 ms); what keeps changing, a picture a program animates, is looked at every frame.*/+#define STILL_LOOKS 120+#define STILL_EVERY 8+static int still_seldom = 1; /* boot-arg glstill=0: every surface looked at every frame (for comparing) */static boolsurface_changed(struct eagl *e, struct image *image){@@ -670,6 +683,9 @@ surface_changed(struct eagl *e, struct image *image)if (image->looked == e->frames + 1 || base == NULL || IOSurfaceGetPlaneCount(surface) > 0) {return false;}+ if (still_seldom && image->unchanged >= STILL_LOOKS && (e->frames + IOSurfaceGetID(surface)) % STILL_EVERY != 0) {+ return false;+ }image->looked = e->frames + 1;for (size_t at = 0; at + 8 <= size; at += 8) {memcpy(&word, base + at, 8);@@ -677,9 +693,11 @@ surface_changed(struct eagl *e, struct image *image)sum ^= sum >> 29;}if (sum == image->sum) {+ image->unchanged += image->unchanged < STILL_LOOKS;return false;}image->sum = sum;+ image->unchanged = 0;return true;}@@ -979,6 +997,115 @@ show_texture(struct eagl *e, struct image *image)free(pixels);}+/*+ * Where the window server's drawing thread spends its processor time (boot-arg glprof=US): a thread of its own looks at+ * the drawing thread every US microseconds, and when that one is on a processor (not waiting) takes its program counter.+ * Every PROF_DUMP of them the most frequent go to the log as "hakios-prof: IMAGE+0xOFFSET N%", for symbolizing on the+ * build machine against the unstripped libraries (libOSMesa's is in xnu-deps/build/mesa/build-*). The frame took 6 to+ * 7 ms of the processor at 146 draws (tools/frames.py): this says in what.+ * While the drawing thread is held (thread_suspend) nothing here allocates or takes a lock: it may hold malloc's.+ */+#define PROF_SLOTS 8192+#define PROF_DUMP 4000+#define PROF_SHOWN 30+#define PROF_DEPTH 9 /* the program counter, the link register, seven callers from the frame chain */+static unsigned prof_us; /* 0: no profile */+static thread_t prof_thread; /* the drawing thread, the first that begins a frame */+static struct {+ uint64_t stack[PROF_DEPTH];+ unsigned count;+} prof_table[PROF_SLOTS];++static int+prof_by_count(const void *a, const void *b)+{+ const typeof(prof_table[0]) *x = a, *y = b;++ return (int)y->count - (int)x->count;+}++static void *+prof_main(__unused void *argument)+{+ unsigned taken = 0, looks = 0;++ for (;;) {+ thread_basic_info_data_t basic;+ mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;+ arm_thread_state64_t state;+ mach_msg_type_number_t state_count = ARM_THREAD_STATE64_COUNT;++ usleep(prof_us);+ looks++;+ if (thread_info(prof_thread, THREAD_BASIC_INFO, (thread_info_t)&basic, &count) != KERN_SUCCESS ||+ basic.run_state != TH_STATE_RUNNING) {+ continue;+ }+ if (thread_suspend(prof_thread) != KERN_SUCCESS) {+ continue;+ }+ kern_return_t got = thread_get_state(prof_thread, ARM_THREAD_STATE64, (thread_state_t)&state, &state_count);+ thread_resume(prof_thread);+ if (got != KERN_SUCCESS) {+ continue;+ }+ /*+ * The stack as far as PROF_DEPTH: the program counter, the link register (a leaf such as a system call's stub has+ * pushed no frame of its own) and the return addresses of the frame records the frame pointer leads through --+ * each checked to lie above the stack pointer and within a megabyte of it, and to go upwards, before it is read.+ */+ uint64_t stack[PROF_DEPTH] = { arm_thread_state64_get_pc(state), arm_thread_state64_get_lr(state) };+ uint64_t sp = arm_thread_state64_get_sp(state), fp = arm_thread_state64_get_fp(state), hash = 0;++ for (unsigned depth = 2; depth < PROF_DEPTH && fp >= sp && fp < sp + (1u << 20) && (fp & 15) == 0; depth++) {+ const uint64_t *record = (const uint64_t *)(uintptr_t)fp;++ stack[depth] = record[1];+ if (record[0] <= fp) {+ break;+ }+ fp = record[0];+ }+ for (unsigned depth = 0; depth < PROF_DEPTH; depth++) {+ hash = (hash ^ stack[depth]) * 0x9e3779b97f4a7c15ull;+ }+ for (unsigned i = (unsigned)(hash >> 32) % PROF_SLOTS, probes = 0; probes < PROF_SLOTS; i = (i + 1) % PROF_SLOTS, probes++) {+ if (prof_table[i].count == 0 || memcmp(prof_table[i].stack, stack, sizeof(stack)) == 0) {+ memcpy(prof_table[i].stack, stack, sizeof(stack));+ prof_table[i].count++;+ break;+ }+ }+ if (++taken < PROF_DUMP) {+ continue;+ }+ /* the most frequent first, each as its image and the offset in it (dladdr: not while the thread was held) */+ qsort(prof_table, PROF_SLOTS, sizeof(prof_table[0]), prof_by_count);+ say("hakios-prof: %u samples of the drawing thread on a processor, in %u looks:\n", taken, looks);+ for (unsigned i = 0; i < PROF_SHOWN && prof_table[i].count != 0; i++) {+ char line[1024];+ int at = snprintf(line, sizeof(line), "hakios-prof: %.1f%%", 100.0 * prof_table[i].count / taken);++ for (unsigned depth = 0; depth < PROF_DEPTH && prof_table[i].stack[depth] != 0 && at < (int)sizeof(line); depth++) {+ Dl_info where = { 0 };+ const char *image = "?", *slash;+ uint64_t offset = prof_table[i].stack[depth];++ if (dladdr((void *)(uintptr_t)offset, &where) != 0 && where.dli_fname != NULL) {+ image = (slash = strrchr(where.dli_fname, '/')) != NULL ? slash + 1 : where.dli_fname;+ offset -= (uint64_t)(uintptr_t)where.dli_fbase;+ }+ at += snprintf(line + at, sizeof(line) - (size_t)at, " %s%s+0x%llx(%s)", depth ? "<- " : "", image,+ (unsigned long long)offset, where.dli_sname != NULL ? where.dli_sname : "?");+ }+ say("%s\n", line);+ }+ memset(prof_table, 0, sizeof(prof_table));+ taken = looks = 0;+ }+ return NULL;+}+/* Before the first drawing of a frame: the textures whose IOSurfaces somebody has written to since. */static voidframe_begin(struct eagl *e)@@ -991,6 +1118,13 @@ frame_begin(struct eagl *e)}e->in_frame = true;e->began = now_us();+ if (prof_us != 0 && prof_thread == MACH_PORT_NULL) {+ pthread_t sampler;++ prof_thread = mach_thread_self();+ pthread_create(&sampler, NULL, prof_main, NULL);+ say("hakios-gl: the drawing thread's profile, a look every %u us (glprof)\n", prof_us);+ }eagl_tracing = e->frames + 1 >= trace_first && e->frames + 1 <= trace_last;if ((trace_at != 0 && e->began >= trace_at) || (trace_draws != 0 && e->last_draws == trace_draws) || trace_function_met) {trace_left = trace_frames; /* (once) */@@ -1089,8 +1223,15 @@ frame_end(struct eagl *e, bool finished)e->in_frame = false;e->frames++;if (latency_lines) {- /* "tl: g FRAME began US ended US DRAWS": microseconds of mach_absolute_time (tools/latency.py) */- say("tl: g %u began %llu ended %llu %u\n", e->frames, e->began, after, e->draws);+ uint64_t tpidr;++ /*+ * "tl: g FRAME began US ended US DRAWS cpu N": microseconds of mach_absolute_time (tools/latency.py), and the+ * core the frame ended on, which the kernel keeps in TPIDR_EL0's low bits as libsyscall's _os_cpu_number()+ * reads it (tools/frames.py: whether the slow frames were drawn on the small cores)+ */+ __asm__ volatile ("mrs %0, TPIDR_EL0" : "=r" (tpidr));+ say("tl: g %u began %llu ended %llu %u cpu %u\n", e->frames, e->began, after, e->draws, (unsigned)(tpidr & 0xfff));}if (frame_lines) {/*@@ -4129,6 +4270,10 @@ install(void)census_on = strstr(arguments, "glcensus=1") != NULL;frame_lines = strstr(arguments, "glframes=1") != NULL;latency_lines = strstr(arguments, "touch_lat=1") != NULL;+ still_seldom = strstr(arguments, "glstill=0") == NULL;+ if ((argument = strstr(arguments, "glprof=")) != NULL) {+ prof_us = (unsigned)strtoul(argument + 7, NULL, 10); /* (frame_begin() starts the profile: prof_main()) */+ }if ((argument = strstr(arguments, "glslow=")) != NULL) {slow_calls_us = strtoull(argument + 7, NULL, 10);}diff --git a/xnu/files/iokit/Kernel/MiniIOSurface.cpp b/xnu/files/iokit/Kernel/MiniIOSurface.cppindex a520658..5413c2b 100644--- a/xnu/files/iokit/Kernel/MiniIOSurface.cpp+++ b/xnu/files/iokit/Kernel/MiniIOSurface.cpp@@ -5,7 +5,7 @@* followed by the pixels. Every client that knows a surface has the whole of it mapped once.* Surfaces travel between processes as Mach send rights (IOSurfaceSendRight) or by number.*- * What is not here: child surfaces, wrapping of client memory, purgeability, compression,+ * What is not here: child surfaces, wrapping of client memory in pieces, purgeability, compression,* notifications. Calls that are not implemented are logged once and refused.*/@@ -151,6 +151,8 @@ static thread_call_t gSurfaceClearing;static uint32_t gSurfacesGivenAgain; /* for MiniIOSurfaceCost() *//* boot-arg surf_clear=0: kept memory is given out as it is (to see what the clearing costs; a surface is then not all zeroes) */static TUNABLE(uint32_t, gSurfaceClear, "surf_clear", 1);+/* boot-arg surf_wrap=0: surfaces around the client's pictures refused, as before methodWrapClientImage (for comparing) */+static TUNABLE(uint32_t, gSurfaceWrap, "surf_wrap", 1);voidMiniIOSurfaceClearKept(void)@@ -603,7 +605,8 @@ surfaceCreate(OSDictionary * props, IOReturn * error)needed += offset;alloc = dictNumber(props, "IOSurfaceAllocSize", 0);if (alloc < needed) {- if (alloc != 0) {+ /* (a surface around the owner's memory has the owner's size: a mask's last row is only as long as it is wide) */+ if (alloc != 0 && wrapped == NULL) {IOLog("MiniIOSurface: alloc size %u too small for %ux%u '%.4s', using %llu\n", alloc, width, height,(const char *) &format, needed);}@@ -904,6 +907,7 @@ class IOSurfaceRootUserClient : public IOUserClientIOReturn methodInit(IOExternalMethodArguments * args);IOReturn methodCreate(IOExternalMethodArguments * args);+ IOReturn methodWrapClientImage(IOExternalMethodArguments * args);IOReturn methodLookup(IOExternalMethodArguments * args);IOReturn methodLookupFromPort(IOExternalMethodArguments * args);IOReturn methodCreatePort(IOExternalMethodArguments * args);@@ -1259,6 +1263,74 @@ IOSurfaceRootUserClient::methodCreate(IOExternalMethodArguments * args)return ret;}+/*+ * A surface around a picture of the client's own (IOSurfaceWrapClientImage): what CoreAnimation's OpenGL ES renderer asks+ * for each image it is to draw from -- a picture, a glyph mask, a gradient. While it was refused the window server asked+ * about 4000 times a second, drew those images another way every frame, and 9% of its drawing thread's time went to the+ * refusals alone (eagl.c's glprof). The request is 32 bytes (as seen on the phone, see externalMethod's log of it):+ *+ * address (8), width, height, pixel format, bytes per element, bytes per row, size (4 each)+ *+ * with the size the owner's (a mask's last row only as long as it is wide). Made as a create with IOSurfaceAddress is:+ * the surface's pixels are that memory itself, and the reply is a create's.+ */+IOReturn+IOSurfaceRootUserClient::methodWrapClientImage(IOExternalMethodArguments * args)+{+ struct {+ uint64_t address;+ uint32_t width, height, format, bytesPerElement, bytesPerRow, size;+ } request;+ static const char * const keys[] = { "IOSurfaceWidth", "IOSurfaceHeight", "IOSurfacePixelFormat", "IOSurfaceBytesPerElement",+ "IOSurfaceBytesPerRow", "IOSurfaceAllocSize" };+ struct minisurf_client_ref * ref;+ OSDictionary * props;+ MiniIOSurface * s;+ IOReturn ret = kIOReturnSuccess;+ uint64_t began = mach_absolute_time();++ if (args->structureInput == NULL || args->structureInputSize < sizeof(request)) {+ return kIOReturnBadArgument;+ }+ memcpy(&request, args->structureInput, sizeof(request));+ if (request.address == 0 || request.size == 0) {+ return kIOReturnBadArgument;+ }+ props = OSDictionary::withCapacity(8);+ OSNumber * address = OSNumber::withNumber(request.address, 64);+ if (props == NULL || address == NULL) {+ OSSafeReleaseNULL(address);+ OSSafeReleaseNULL(props);+ return kIOReturnNoMemory;+ }+ props->setObject("IOSurfaceAddress", address);+ address->release();+ const uint32_t values[] = { request.width, request.height, request.format, request.bytesPerElement, request.bytesPerRow,+ request.size };+ for (unsigned i = 0; i < sizeof(keys) / sizeof(keys[0]) && ret == kIOReturnSuccess; i++) {+ OSNumber * n = OSNumber::withNumber(values[i], 32);++ ret = n != NULL && props->setObject(keys[i], n) ? kIOReturnSuccess : kIOReturnNoMemory;+ OSSafeReleaseNULL(n);+ }+ s = ret == kIOReturnSuccess ? surfaceCreate(props, &ret) : NULL;+ props->release();+ if (s == NULL) {+ return ret;+ }+ IOLockLock(gSurfaceLock);+ ref = addRef(s);+ ret = ref ? returnSurface(ref, false, args) : kIOReturnNoMemory;+ if (ref != NULL && ret != kIOReturnSuccess) {+ dropRef(ref);+ }+ surfaceUnhold(s); /* the maker's hold; the client's own is in the ref */+ IOLockUnlock(gSurfaceLock);+ OSAddAtomic64((SInt64) (mach_absolute_time() - began), (SInt64 *) &gSurfaceMaking);+ OSIncrementAtomic(&gSurfacesMade);+ return ret;+}+IOReturnIOSurfaceRootUserClient::methodLookup(IOExternalMethodArguments * args){@@ -1604,6 +1676,11 @@ IOSurfaceRootUserClient::externalMethod(uint32_t selector, IOExternalMethodArgumreturn methodInit(args);case kSurfaceMethodCreate:return methodCreate(args);+ case kSurfaceMethodWrapClientImage:+ if (gSurfaceWrap) {+ return methodWrapClientImage(args);+ }+ break;case kSurfaceMethodLookup:return methodLookup(args);case kSurfaceMethodLookupFromPort:@@ -1698,6 +1775,32 @@ IOSurfaceRootUserClient::externalMethod(uint32_t selector, IOExternalMethodArgumbreak;}+ /*+ * Surfaces around memory of the client's own (IOSurfaceWrapClientMemory; the image's are made: methodWrapClientImage):+ * what is asked, said for the first few and every thousandth, is the layout of the request for when they are made --+ * that is how the image's was learnt, at about 4000 refused requests a second from the window server.+ */+ if (selector == kSurfaceMethodWrapClientImage || selector == kSurfaceMethodWrapClientMemory) {+ static uint32_t wraps[2];+ uint32_t n = ++wraps[selector - kSurfaceMethodWrapClientImage];++ if (n <= 6 || n % 1000 == 0) {+ char hex[3 * 64 + 1] = "", procname[32] = "?";+ const uint8_t * in = (const uint8_t *)args->structureInput;+ uint32_t size = args->structureInputSize < 64 ? args->structureInputSize : 64;++ for (uint32_t i = 0; in != NULL && i < size; i++) {+ snprintf(hex + 3 * i, sizeof(hex) - 3 * i, "%02x ", in[i]);+ }+ proc_selfname(procname, sizeof(procname));+ IOLog("MiniIOSurface: wrap client %s #%u from %s[%d]: scalars %u (%#llx %#llx %#llx), structure %u in, %u out: %s\n",+ selector == kSurfaceMethodWrapClientImage ? "image" : "memory", n, procname, proc_selfpid(),+ args->scalarInputCount, args->scalarInputCount > 0 ? args->scalarInput[0] : 0ULL,+ args->scalarInputCount > 1 ? args->scalarInput[1] : 0ULL, args->scalarInputCount > 2 ? args->scalarInput[2] : 0ULL,+ args->structureInputSize, args->structureOutputSize, hex);+ }+ }+if (selector < 128 && !(gSurfaceLogged[selector / 64] & (1ULL << (selector % 64)))) {gSurfaceLogged[selector / 64] |= 1ULL << (selector % 64);IOLog("MiniIOSurface: selector %u not implemented (scalars %u in, %u out; structure %u in, %u out)\n", selector,