lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT


From: Giuseppe Modugno
Subject: Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
Date: Thu, 13 Oct 2022 08:48:30 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2

Il 12/10/2022 21:11, goldsimon@gmx.de ha scritto:
Am 11.10.2022 um 17:11 schrieb Giuseppe Modugno:
Another thing I can't understand is why the code around
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is needed if:

  * NO_SYS=1
  * MEM_USE_POOLS=0
  * MEM_LIBC_MALLOC=0
  * SYS_LIGHTWEIGHT_PROT=1
  * sys_arch_protect() simply disables interrupts

In mem_malloc there's a point where LWIP_MEM_ALLOC_PROTECT is called,
before the "scan through the heap searching for a free block". Why
during the scan, for each loop, UNPROTECT/PROTECT are called? The
comment says /* allow mem_free or mem_trim to run */.

Maybe this is done because the scan could take a long time to finish
(for big and fragmented heap) and having interrupts disabled for so long
time is not good? So the interrupts are enabled and disabled for each
loop to give them opportunity to run?

Exactly:
- Heap allocation takes a mutex as it should not block interrupts while
scanning for memory (takes too long).
- Heap free is fast as it does not need to scan.

Therefore, heap allocation uses double protection: mutex to block
against other allocations, PROTECT/UNPROTECT to protect against
concurrent free.

Ok, thank you for the answer.

Do you think it's possible to implement a pbuf_free_callback() in NO_SYS=1 that can be called in ISR instead instead of pbuf_free()?

The goal is to avoid disabling interrupts at all setting SYS_LIGHTWEIGHT_PROT=0 to disable PROTECT/UNPROTECT mechanism.

The only lwip function that NXP code uses in ISR is pbuf_free() (that needs to be protected with disabling interrupts and LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT), so I'm searching an alternative way to avoid this.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]