mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
perf: network tables Android refuses are served from the synthesized copy without retrying the open
Wine's nsiproxy reads /proc/net/dev and /sys/class/net/*/carrier for every interface on each adapter query, and the route tables for gateways. Android refuses those opens, and each refused open costs 60-150 us under proot before the synthesized table is returned. A refusal is now remembered for a second per table, so repeat reads go straight to the synthesized copy. Mortal Kombat XL asks for its adapters from the game thread about 30 times a second: GetAdaptersAddresses 2.92 -> 2.53 ms, GetIfTable 1.79 -> 1.35 ms, winedevice 9.0 -> 7.6% CPU.
This commit is contained in:
1 parent
dafe5f13b5
commit
8d0b1a42b9
1 file changed
+20
-11
@@ -504,19 +504,23 @@ static void write_table(FILE *out, const char *table, const struct link *link) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char *denied_table(const char *path) {
|
||||
static const char *const tables[] = { "route", "ipv6_route", "if_inet6", "dev", "arp" };
|
||||
#define CARRIER_TABLE 5
|
||||
|
||||
static const char *const net_tables[] = { "route", "ipv6_route", "if_inet6", "dev", "arp", "carrier" };
|
||||
static long long net_denied_at[sizeof(net_tables) / sizeof(net_tables[0])];
|
||||
|
||||
static int denied_table(const char *path) {
|
||||
if (strncmp(path, "/proc/net/", 10) == 0) {
|
||||
for (size_t i = 0; i < sizeof(tables) / sizeof(tables[0]); i++) {
|
||||
if (strcmp(path + 10, tables[i]) == 0) return tables[i];
|
||||
for (int i = 0; i < CARRIER_TABLE; i++) {
|
||||
if (strcmp(path + 10, net_tables[i]) == 0) return i;
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
size_t len = strlen(path);
|
||||
if (strncmp(path, "/sys/class/net/", 15) == 0 && len > 8 && strcmp(path + len - 8, "/carrier") == 0) {
|
||||
return "carrier";
|
||||
return CARRIER_TABLE;
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static FILE *synthesize(const char *table) {
|
||||
@@ -548,11 +552,16 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode, cons
|
||||
if (copy == NULL) close(status);
|
||||
return copy;
|
||||
}
|
||||
FILE *f = real(path, mode);
|
||||
if (f || path == NULL || mode == NULL || mode[0] != 'r') return f;
|
||||
int table = path && mode && mode[0] == 'r' ? denied_table(path) : -1;
|
||||
FILE *f;
|
||||
if (table >= 0 && fresh(&net_denied_at[table]) && (f = synthesize(net_tables[table])) != NULL) return f;
|
||||
f = real(path, mode);
|
||||
if (f || table < 0) return f;
|
||||
int saved = errno;
|
||||
const char *table = denied_table(path);
|
||||
if (table && (f = synthesize(table)) != NULL) return f;
|
||||
if ((f = synthesize(net_tables[table])) != NULL) {
|
||||
if (saved == EACCES) __atomic_store_n(&net_denied_at[table], now_ns(), __ATOMIC_RELAXED);
|
||||
return f;
|
||||
}
|
||||
errno = saved;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user