From cde3357cada5649058959399ac5dc58d7e41aed6 Mon Sep 17 00:00:00 2001 From: Tinic Uro Date: Mon, 28 Sep 2026 04:05:26 +0000 Subject: [PATCH] sana2: one home for the device-name helpers (resident -152 B) #109 added ami_sana2_default_tcp_ack_max in sana2_policy.c with its own lower-case compare and basename walk, next to the identical static ami_str_iequal/ami_sana2_basename and WiFiPi name test in sana2_device.c. Both now live once in sana2_policy.c (pure, still host-linkable) and both WiFiPi defaults (128 posted reads, 11680 ACK ceiling) share one test. bsdsocket.library (preset default): 365,468 -> 365,316 bytes, text 338,636 -> 338,488; pre-#109 main was 364,956. The 366,000 budget stays. Host tests sana2_device and config_routes pass. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 2 +- include/aminetxduo/sana2.h | 5 +++ src/sana2/sana2_device.c | 59 ------------------------------------ src/sana2/sana2_internal.h | 1 - src/sana2/sana2_policy.c | 62 ++++++++++++++++++++++++++------------ tools/check-image-size.sh | 4 +-- 6 files changed, 50 insertions(+), 83 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c295ceae5..7e254dda2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ version at the top when it merges. to an 11,680-byte ceiling when the setting is absent; other devices retain the 50,176-byte port default. This changes ACK cadence, not the unresolved cause of missing outbound frames (#89). The per-interface policy brings the - resident `bsdsocket.library` image to 365,468 bytes in CI; its budget is + resident `bsdsocket.library` image to 365,316 bytes; its budget is 366,000 bytes. ## 1.0.0-beta7 diff --git a/include/aminetxduo/sana2.h b/include/aminetxduo/sana2.h index c57689e97..91716e013 100644 --- a/include/aminetxduo/sana2.h +++ b/include/aminetxduo/sana2.h @@ -77,6 +77,11 @@ ULONG ami_sana2_retained_holds(const char *device, ULONG unit); use that port default. Names are compared by basename, ignoring case. */ ULONG ami_sana2_default_tcp_ack_max(const char *device); +/* The pure device-name helpers behind those defaults (sana2_policy.c). */ +BOOL ami_str_iequal(const char *a, const char *b); +const char *ami_sana2_basename(const char *device); +UWORD ami_sana2_default_ip_reads(const char *device); + /* * Collect whatever the devices have given back since, without waiting, and * CloseDevice() and free every interface nothing holds any more. Under diff --git a/src/sana2/sana2_device.c b/src/sana2/sana2_device.c index 6c8dc595d..b455b26f5 100644 --- a/src/sana2/sana2_device.c +++ b/src/sana2/sana2_device.c @@ -83,24 +83,6 @@ static VOID ami_str_copy(char *dst, const char *src, ULONG size) dst[i] = '\0'; } -/* The same, ignoring case: a device name is a file name. */ -static BOOL ami_str_iequal(const char *a, const char *b) -{ - while (*a != '\0' && *b != '\0') - { - char x = *a++; - char y = *b++; - - if (x >= 'A' && x <= 'Z') - x = (char)(x + ('a' - 'A')); - if (y >= 'A' && y <= 'Z') - y = (char)(y + ('a' - 'A')); - if (x != y) - return FALSE; - } - return (BOOL)(*a == *b); -} - static BOOL ami_str_equal(const char *a, const char *b) { ULONG i = 0; @@ -1542,22 +1524,6 @@ UWORD ami_sana2_retained_count(VOID) return ami_sana2_retained_n; } -/* The file name without its path: DEVS:Networks/x.device and x.device are - one driver. */ -static const char *ami_sana2_basename(const char *device) -{ - const char *base = device; - const char *p; - - for (p = device; *p != '\0'; p++) - { - if (*p == '/' || *p == ':') - base = p + 1; - } - - return base; -} - ULONG ami_sana2_retained_holds(const char *device, ULONG unit) { const AmiSana2If *iface; @@ -1693,31 +1659,6 @@ ULONG ami_sana2_known_rx_bytes(const char *device) return 0; } -/* WiFiPi's receiver runs at Exec priority 5, above every ThreadX task, and - * delivers a whole wake's SDPCM frames (up to 64, each possibly a glom) - * before the reader can re-post one CMD_READ; a frame with no read queued is - * dropped into UnknownTypesReceived. Its fixed 100 Mbit/s device query lands - * on the 32-read LAN rung. Measured on the CM4 A1200 (#89): 128 reads, 59.0 - * Mbit/s inbound, UnknownTypes 82 of 53,483 packets; 128 is also - * AMI_SANA2_RX_MAX_DEPTH. Over the 32 it replaces it holds 96 more pool - * packets (156,672 B of the pool at the 1,632 B stride, none allocated) and - * 11,904 B more slot RAM; an explicit IPREQUESTS still wins, and rx_plan() - * still caps it at the pool budget. */ -UWORD ami_sana2_default_ip_reads(const char *device) -{ - const char *base; - - if (device == NULL) - return 0; - - base = ami_sana2_basename(device); - if (ami_str_iequal(base, "anxwifipi.device") || - ami_str_iequal(base, "wifipi.device")) - return 128; - - return 0; -} - BOOL ami_sana2_is_online(const AmiSana2If *iface) { return (iface != NULL) ? iface->online : FALSE; diff --git a/src/sana2/sana2_internal.h b/src/sana2/sana2_internal.h index ec94a3f92..e9ab1cd31 100644 --- a/src/sana2/sana2_internal.h +++ b/src/sana2/sana2_internal.h @@ -985,7 +985,6 @@ VOID ami_sana2_rx_filled(APTR ios2_data, ULONG len, ULONG sum, UBYTE summed); ULONG ami_sana2_known_rx_bytes(const char *device); /* Extra default IPv4 reads for a known burst-delivering driver, or 0 to use the ordinary BPS ladder; explicit IPREQUESTS always takes precedence. */ -UWORD ami_sana2_default_ip_reads(const char *device); /* The IPv4 read depth an interface asks for: IPREQUESTS, else the above (sana2_rx.c). */ UWORD ami_sana2_rx_ask_ip(const AmiSana2If *iface); diff --git a/src/sana2/sana2_policy.c b/src/sana2/sana2_policy.c index 0be350fd9..0aff15376 100644 --- a/src/sana2/sana2_policy.c +++ b/src/sana2/sana2_policy.c @@ -1,38 +1,60 @@ -/* Pure device-name defaults shared by the driver and host netstack tests. */ +/* Pure device-name policy shared by the driver and the host netstack tests. */ #include "aminetxduo/sana2.h" -static char lower_ascii(char c) -{ - if (c >= 'A' && c <= 'Z') - return (char)(c + ('a' - 'A')); - return c; -} - -static int name_equal(const char *a, const char *b) +/* Two strings the same, ignoring case: a device name is a file name. */ +BOOL ami_str_iequal(const char *a, const char *b) { while (*a != '\0' && *b != '\0') { - if (lower_ascii(*a++) != lower_ascii(*b++)) - return 0; + char x = *a++; + char y = *b++; + + if (x >= 'A' && x <= 'Z') + x = (char)(x + ('a' - 'A')); + if (y >= 'A' && y <= 'Z') + y = (char)(y + ('a' - 'A')); + if (x != y) + return FALSE; } - return *a == *b; + return (BOOL)(*a == *b); } -ULONG ami_sana2_default_tcp_ack_max(const char *device) +/* The file name without its path: DEVS:Networks/x.device and x.device are + one driver. */ +const char *ami_sana2_basename(const char *device) { const char *base = device; const char *p; - if (device == NULL) - return 0; - for (p = device; *p != '\0'; p++) + { if (*p == '/' || *p == ':') base = p + 1; + } - if (name_equal(base, "anxwifipi.device") || - name_equal(base, "wifipi.device")) - return 11680UL; + return base; +} - return 0; +static BOOL ami_sana2_is_wifipi(const char *device) +{ + const char *base; + + if (device == NULL) + return FALSE; + + base = ami_sana2_basename(device); + return (BOOL)(ami_str_iequal(base, "anxwifipi.device") || + ami_str_iequal(base, "wifipi.device")); +} + +/* WiFiPi wants 128 posted reads (#107); the pool budget still caps it. */ +UWORD ami_sana2_default_ip_reads(const char *device) +{ + return ami_sana2_is_wifipi(device) ? 128 : 0; +} + +/* WiFiPi acknowledges once per GRO run (#89, #109); 0 = the NetX default. */ +ULONG ami_sana2_default_tcp_ack_max(const char *device) +{ + return ami_sana2_is_wifipi(device) ? 11680UL : 0UL; } diff --git a/tools/check-image-size.sh b/tools/check-image-size.sh index 2ab303f83..b2f1ae9f2 100755 --- a/tools/check-image-size.sh +++ b/tools/check-image-size.sh @@ -72,8 +72,8 @@ BUDGETS=( # and an abandoned request kept with its interface until the device # replies (#90, 5473e26e), 2026-09-26 (micro 204,052, minimal 238,240). # 365,468 with per-interface TCP ACK policy (#109): config parsing and - # publishing the WiFi/default-or-explicit ceiling into each NX_INTERFACE. - # This adds 468 bytes over the previous resident-image budget. + # publishing the WiFi/default-or-explicit ceiling into each NX_INTERFACE; + # 365,316 once the device-name helpers live once, in sana2_policy.c. "default:src/bsdsocket/bsdsocket.library:366000" # 41,412 after stateless receive-checksum verification was added to the # EL3 and word/long NE2000 direct paths, 2026-09-15. 43,620 with