|
41 | 41 | ------------------------------------ |
42 | 42 | */ |
43 | 43 | /** |
44 | | - * MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by the C-library |
45 | | - * instead of lwIP's internal allocator. Default is 0; enabled on EE |
46 | | - * because newlib's malloc is already linked in and the heap pool is |
47 | | - * cheaper than a duplicate lwIP heap. |
| 44 | + * MEM_LIBC_MALLOC==1: use libc's malloc/free for lwIP's mem_malloc / |
| 45 | + * mem_free (which serve PBUF_RAM allocations and a handful of other |
| 46 | + * sites — DHCP options, ARP, DNS, slip/ppp/zepif which we don't build). |
| 47 | + * Internally lwIP's pbuf_alloc(PBUF_RAM) computes the payload pointer |
| 48 | + * with `LWIP_MEM_ALIGN(p + SIZEOF_STRUCT_PBUF + offset)`, which only |
| 49 | + * stays inside the allocated chunk when 'p' is already MEM_ALIGNMENT- |
| 50 | + * aligned. That is why MEM_ALIGNMENT must match the underlying |
| 51 | + * allocator's alignment — see MEM_ALIGNMENT below. |
48 | 52 | */ |
49 | 53 | #define MEM_LIBC_MALLOC 1 |
50 | 54 |
|
51 | | -/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which |
52 | | - lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 |
53 | | - byte alignment -> define MEM_ALIGNMENT to 2. */ |
54 | | -#define MEM_ALIGNMENT 64 //SP193: must be 64, to deal with the EE cache design. |
| 55 | +/* MEM_ALIGNMENT: must equal the alignment libc's malloc returns, |
| 56 | + because pbuf_alloc(PBUF_RAM) computes |
| 57 | + payload = LWIP_MEM_ALIGN(p + SIZEOF_STRUCT_PBUF + offset) |
| 58 | + inside an allocation sized assuming p is already MEM_ALIGNMENT- |
| 59 | + aligned. If MEM_ALIGNMENT > newlib's alignment the payload pointer |
| 60 | + overruns the chunk and corrupts the next-chunk header on the |
| 61 | + freelist (TLB misses inside _malloc_r / _free_r). |
| 62 | +
|
| 63 | + 16 is the contract baked into the toolchain configuration. See |
| 64 | + newlib/newlib/configure.host: |
| 65 | +
|
| 66 | + mips64r5900*) |
| 67 | + machine_dir=r5900 |
| 68 | + newlib_cflags="${newlib_cflags} -DMALLOC_ALIGNMENT=16" |
| 69 | + ;; |
| 70 | +
|
| 71 | + so for the mips64r5900el-ps2-elf target newlib is built with |
| 72 | + -DMALLOC_ALIGNMENT=16, which sets _mallocr.c's MALLOC_ALIGNMENT |
| 73 | + directly (overriding the SIZE_SZ-derived default of 8). 16 is also |
| 74 | + what samples/malloc_stress observes empirically. |
| 75 | +
|
| 76 | + The historical value here was 64 with a comment about "the EE cache |
| 77 | + design" (SP193). That was over-cautious: PBUF_POOL pbufs (the only |
| 78 | + ones touched by IOP->EE DMA + cache invalidate) come from memp's |
| 79 | + static pools and are always 64-byte aligned regardless of |
| 80 | + MEM_ALIGNMENT; PBUF_RAM pbufs (TX, ARP, DNS, ...) only see DMA |
| 81 | + writeback, where misalignment harmlessly over-flushes extra cache |
| 82 | + lines. The IOP-side lwipopts has used MEM_ALIGNMENT=4 forever for |
| 83 | + the same reason. */ |
| 84 | +#define MEM_ALIGNMENT 16 |
55 | 85 |
|
56 | 86 | /** |
57 | 87 | * MEM_SIZE: the size of the heap memory. If the application will send |
|
103 | 133 | #define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN |
104 | 134 |
|
105 | 135 | /** |
106 | | - * LWIP_TCPIP_CORE_LOCKING_INPUT: when LWIP_TCPIP_CORE_LOCKING is enabled, |
107 | | - * this lets tcpip_input() grab the mutex for input packets as well, |
108 | | - * instead of allocating a message and passing it to tcpip_thread. |
109 | | - * |
110 | | - * ATTENTION: this does not work when tcpip_input() is called from |
111 | | - * interrupt context! |
| 136 | + * LWIP_TCPIP_CORE_LOCKING==1: matches lwIP 2.2.1's upstream default. With |
| 137 | + * LWIP_COMPAT_MUTEX in arch/cc.h the core lock is a binary semaphore taken |
| 138 | + * directly on the calling app thread for socket/netconn API calls; lwIP |
| 139 | + * releases it before any blocking I/O wait so the tcpip thread + netif |
| 140 | + * input continue to make progress. Saves a context switch + sem wait per |
| 141 | + * API call versus the message-passing alternative. |
| 142 | + */ |
| 143 | +#define LWIP_TCPIP_CORE_LOCKING 1 |
| 144 | + |
| 145 | +/** |
| 146 | + * LWIP_TCPIP_CORE_LOCKING_INPUT==1: tcpip_input() takes the core mutex |
| 147 | + * directly instead of allocating a message. Safe here because the netif |
| 148 | + * input callback runs in a regular thread, not interrupt context. |
112 | 149 | */ |
113 | 150 | #define LWIP_TCPIP_CORE_LOCKING_INPUT 1 |
114 | 151 |
|
|
134 | 171 | #define LWIP_DHCP 1 |
135 | 172 | #endif |
136 | 173 |
|
137 | | -/** |
138 | | - * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. |
139 | | - */ |
140 | | -#define DHCP_DOES_ARP_CHECK 0 //Don't do the ARP check because an IP address would be first required. |
141 | | - |
142 | | -/** |
143 | | - * LWIP_DHCP_CHECK_LINK_UP==1: dhcp_start() only really starts if the netif has |
144 | | - * NETIF_FLAG_LINK_UP set in its flags. As this is only an optimization and |
145 | | - * netif drivers might not set this flag, the default is off. If enabled, |
146 | | - * netif_set_link_up() must be called to continue dhcp starting. |
147 | | - */ |
148 | | -#define LWIP_DHCP_CHECK_LINK_UP 1 |
| 174 | +/* LWIP_DHCP_DOES_ACD_CHECK / LWIP_ACD left at upstream defaults (=1 when |
| 175 | + * LWIP_DHCP=1) so the RFC 5227 Address Conflict Detection probe runs on |
| 176 | + * any DHCP-offered IP. EE applications run on user home networks where |
| 177 | + * IP collisions are a real (if uncommon) failure mode; the few KB of |
| 178 | + * code and ~1-2 s extra DHCP-bind delay are worth the robustness. The |
| 179 | + * IOP lwIP build forces both off because ps2link runs in controlled |
| 180 | + * bench environments where the IRX size + tick savings matter more. */ |
149 | 181 |
|
150 | 182 | /* |
151 | 183 | ---------------------------------- |
|
208 | 240 | ---------- Socket options ---------- |
209 | 241 | ------------------------------------ |
210 | 242 | */ |
211 | | -/* LWIP_SOCKET_SET_ERRNO==1: Set errno when socket functions cannot complete |
212 | | - * successfully, as required by POSIX. Default is POSIX-compliant. |
213 | | - */ |
214 | | -#define LWIP_SOCKET_SET_ERRNO 0 |
215 | 243 | /** |
216 | 244 | * LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names. |
217 | 245 | * Disable this option if you use a POSIX operating system that uses the same |
|
0 commit comments