Re: [lwip-users] MEM_SIZE
Il 15/03/2018 11:28, Simon Goldschmidt ha scritto: Giuseppe Modugno wrote: [..] I think with the following options: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 1 #define MEM_USE_CUSTOM_POOLS 1 /* Needed by MEM_USE_POOLS */ It's MEMP_USE_CUSTOM_POOLS, not MEM_USE_CUSTOM_POOLS. It was a typo. And it compiles for me, see the win32 port for an example. Yes, now it compiles without errors. The file lwippools.h lacked the LWIP_MALLOC_MEMPOOL macros to define the set of pools used by lwip in case MEM_USE_POOLS is set. ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Giuseppe Modugno wrote: > [..] > I think with the following options: > > #define MEM_LIBC_MALLOC 0 > #define MEM_USE_POOLS 1 > #define MEM_USE_CUSTOM_POOLS 1 /* Needed by MEM_USE_POOLS */ It's MEMP_USE_CUSTOM_POOLS, not MEM_USE_CUSTOM_POOLS. And it compiles for me, see the win32 port for an example. Simon ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Giuseppe Modugno wrote: > [..] > In my case, I have a completely free (not used by the linker) 32kB RAM > region starting from 0x2007C000. To instruct lwip to use that region for > heap, I think I have to define: > > #define MEM_SIZE (32 * 1024 - 1 * SIZEOF_STRUCT_MEM) > #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) > > Supposing we don't need other additional space for alignment. > In this case the total free heap memory available for data is exactly > MEM_SIZE, that is less than 32kB. > > Is it correct? I think so, yes. However, your definition of MEM_SIZE won't compile outside of mem.c. Maybe it would be better to rework the code to use MEM_SIZE as size of the available block, at least if an external block is used... Simon ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Problems when setting MEMP_MEM_MALLOC
Il 14/03/2018 21:24, Nathan Hartman ha scritto: On Mar 14, 2018, at 3:24 PM, "goldsi...@gmx.de"wrote: On 14.03.2018 17:09, Giuseppe Modugno wrote: #define MEM_LIBC_MALLOC 1 If I try to set MEMP_MEM_MALLOC, I have some strange problems. I suspect threading issues. I checked on win32 and it seems to work fine. In the end, there's not really much lwIP does here, everything is delegated to your C library's malloc code. Maybe that code isn't thread-safe? In that case, you need to define mem_clib_*() to wrapper functions that protect the heap. Just a guess: it sounds like your linker script may be placing the heap in the wrong place, not allocating one at all, and/or it may not be where your C library expects it to be. It is very important to give your application enough stack and enough heap, and to make sure they do not clobber each other as they grow. I'm starting thinking about an issue similar to "out of memory". Every time the custom file is opened, a mem_malloc(1024) is called and every time the pointer returned is increased. I'm sure the allocated space is freed in fs_close_custom. Maybe it's a problem with fragmentation... I have to make additional tests. ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] Problems when setting MEMP_MEM_MALLOC
Il 14/03/2018 20:24, goldsi...@gmx.de ha scritto: On 14.03.2018 17:09, Giuseppe Modugno wrote: #define MEM_LIBC_MALLOC 1 If I try to set MEMP_MEM_MALLOC, I have some strange problems. I suspect threading issues. I checked on win32 and it seems to work fine. In the end, there's not really much lwIP does here, everything is delegated to your C library's malloc code. Maybe that code isn't thread-safe? In that case, you need to define mem_clib_*() to wrapper functions that protect the heap. I'm using NewlibNano as C library. However I'm using NOSYS=1 and I don't use threads. In my application, "threads" are only interrupt service routines, but I don't call mem_malloc from any ISR (I don't think lwip uses interrupts at all). So I don't think it is caused by a threading issue. ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Il 14/03/2018 16:42, Giuseppe Modugno ha scritto: I was experimenting with lwip memory allocator. I defined: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 0 #define MEM_SIZE (32 * 1024) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) I'm using LPC1768 that has a 32kB SRAM block starting from address 0x2007C000. However I have a Hard Fault error during mem_init(), because ram_end is initialized to 0x2007C000 + (32*1024), that is over the available memory. So MEM_SIZE should be smaller than available heap memory. Another question regarding memory management of lwip. I understood lwip uses memory pools for many things (TCP pcbs, UDP pcbs, RAW pcb, timers and so on). The memory pools are defined in include/lwip/priv/memp_std.h. They aren't allocated from the heap, but from pools. I think because it is supposed they must be allocated frequently, so they could bring to fragmentation and the allocation should be fast. Does lwip use strictly heap (mem_malloc) for its own purposes? It seems yes (I see some mem_malloc calls in httpd, dhcp, pbuf, ...). Is it possible to compile lwip so it doesn't use heap at all? I think with the following options: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 1 #define MEM_USE_CUSTOM_POOLS 1 /* Needed by MEM_USE_POOLS */ In this way, heap implementation isn't a real heap, but a set of different-sized pools. This set is defined in arhc/lwippools.h. Is it correct? I tried to compile with this options, but I have this error (for example compiling memp.c): mingw32-gcc.exe -Wall -std=c11 -Wall -pedantic -Wparentheses -Wsequence-point -Wextra -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wold-style-definition -Wcast-align -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Wno-address -Wunreachable-code -Wuninitialized -Wlogical-op -Wno-format -g -DLWIP_DEBUG -DDEBUG -Isrc\lwip\src\include -Isrc -Isrc\ports\mingw\lwip_arch -Isrc\ports\mingw -Isrc\bus -Isrc\WpdPack\Include -I..\..\..\work_git -Isrc\lwip\src\include\lwip\apps -c C:\Users\Giuseppe\Documents\work_git\webserver\webserver\src\lwip\src\core\memp.c -o mingw\Debug\src\lwip\src\core\memp.o In file included from src\lwip\src\include/lwip/memp.h:58:0, from C:\Users\Giuseppe\Documents\work_git\webserver\webserver\src\lwip\src\core\memp.c:48: src\lwip\src\include/lwip/priv/memp_priv.h:89:5: error: expected expression before ')' token ) , ^ ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users
Re: [lwip-users] MEM_SIZE
Il 14/03/2018 20:26, goldsi...@gmx.de ha scritto: On 14.03.2018 16:42, Giuseppe Modugno wrote: I was experimenting with lwip memory allocator. I defined: #define MEM_LIBC_MALLOC 0 #define MEM_USE_POOLS 0 #define MEM_SIZE (32 * 1024) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) I'm using LPC1768 that has a 32kB SRAM block starting from address 0x2007C000. However I have a Hard Fault error during mem_init(), because ram_end is initialized to 0x2007C000 + (32*1024), that is over the available memory. So MEM_SIZE should be smaller than available heap memory. Is that a question? Or an action request? It was a question, even if I forgot to add a question mark :-) To my understanding, the comment above #ifndef LWIP_RAM_HEAP_POINTER in mem.c clearly states that enough memory is required. It does NOT say that amount is MEM_SIZE. If you want, create a patch with a better documentation and we could apply it. Ah ok, I now understand the comment "we need one struct mem at the end and some room for alignment". MEM_SIZE isn't the total available memory for heap management (including accessory structs), but it is the *useful* memory space the application needs for the heap (excluding accessory structs). For example, if MEM_SIZE is 1024, I can be sure one malloc(1024) won't fail. In my case, I have a completely free (not used by the linker) 32kB RAM region starting from 0x2007C000. To instruct lwip to use that region for heap, I think I have to define: #define MEM_SIZE (32 * 1024 - 1 * SIZEOF_STRUCT_MEM) #define LWIP_RAM_HEAP_POINTER ( (void *)0x2007C000 ) Supposing we don't need other additional space for alignment. In this case the total free heap memory available for data is exactly MEM_SIZE, that is less than 32kB. Is it correct? ___ lwip-users mailing list lwip-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/lwip-users