Commit Graph

20 Commits

Author SHA1 Message Date
Alin Jerpelea 339457dda3 mm: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-13 08:49:05 +08:00
Tiago Medicci Serrano 50aeea2dc0 mm/iob: Simplify IOB alloc/free logic
- `g_iob_sem.semcount` must be equal to the total number of free IOBs.
It can also be negative if there are no free IOBs and there are threads
waiting for an IOB.
- g_throttle_sem.semcount represents the number of IOBs available for
throttled IOB allocations. Like any other semaphore, it should only go
negative if there is a thread waiting for it.
- Both semaphores are related to the same resource (free IOBs), hence,
they must be incremented/decremented simultaneously:
  - Whenever a IOB buffer is freed, if a thread is waiting for a
non-throttled IOB or a thread is waiting for a throttled IOB and we
have at least `CONFIG_IOB_THROTTLE` buffers available, the IOB is put
in the committed list (`g_iob_committed`). Otherwise, it is put in the
common free list (`g_iob_freelist`).
  - `g_iob_sem` is always incremented when an IOB buffer is freed, but
`g_throttle_sem` is incremented only if we have at least CONFIG_IOB_THROTTLE
buffers free.
  - Both semaphores are posted with the schedule locked to avoid any
mismatches in the semaphores count.
  - If a task is waiting for an IOB semaphore (`iob_allocwait`) is
awakened and would check the `g_iob_committed`. The highest priority
task waiting for a semaphore will be awakened first.
2024-06-25 15:21:00 +08:00
zhanghongyu b934555fd1 mm/iob: Support alloc IOB via malloc
Support the network interface card driver to receive zero copies of packets and send and receive giant frame packets, allowing drivers to initialize the DMA buffer to the iob structure, and we can apply for IOB with large memory

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-26 01:06:21 +08:00
Xiang Xiao 9e4a1be8d4 mm/iob: Replace the critical section with spin lock
Base on discusion: https://github.com/apache/nuttx/issues/10981

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-30 11:18:34 +02:00
Xiang Xiao ba9486de4a iob: Remove iob_user_e enum and related code
since it is impossible to track producer and consumer
correctly if TCP/IP stack pass IOB directly to netdev

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-15 08:41:20 +03:00
Alin Jerpelea bcee9c391c mm: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can mograte the licenses
to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-09 01:21:53 -08:00
Gregory Nutt 1382ea5447 mm/: Coding style clean-up
Run tools/nxstyle against all C files under mm/ and correct coding standard violations.
2020-02-13 15:16:53 +01:00
Xiang Xiao 5c80b94820 Replace #include <semaphore.h> to #include <nuttx/semaphore.h>
Since the kernel side should call nxsem_xxx instead and remove the unused inclusion
2020-02-01 08:27:30 -06:00
Anthony Merlino 70404ed0dc Merged in antmerlino/nuttx/iobinstrumentation (pull request #1001)
Iobinstrumentation

* mm/iob: Introduces producer/consumer id to every iob call. This is so that the calls can be instrumented to monitor the IOB resources.

* iob instrumentation - Merges producer/consumer enumeration for simpler IOB user.

* fs/procfs: Starts adding support for /proc/iobinfo

* fs/procfs: Finishes first pass of simple IOB user stastics and /proc/iobinfo entry

Approved-by: Gregory Nutt <gnutt@nuttx.org>
2019-08-16 22:42:25 +00:00
Gregory Nutt b21c12bd18 Fix errors found in build testing:
arch/mips/src:  Previous commit used CP0 register definitions that were not defined in the cp0.h header file.  Probably these were from the Microchip hacked up GCC toolchain but are not generally available.  Fix:  Add definitions to NuttX cp0.h header file.

mm/iob:  Eliminate some warnings about testing the value of an undefined pre-processor variable.
2019-05-25 11:45:22 -06:00
Xiang Xiao 1ecc33b7db mm/iob: Miscellaneous changes and fixes from code review. 2019-01-26 09:56:27 -06:00
Xiang Xiao 4721381d1c mm/iob/iob_alloc.c: iob_allocwait should decrease semcount manually. 2019-01-26 09:24:12 -06:00
Gregory Nutt 22da175629 mm/iob: Add a divider that can be used to reduce the rate of IOB notifications. 2018-09-13 06:56:29 -06:00
Gregory Nutt 76eec53e4f mm/iob: iob_navail() was returning the number of free IOB chain queue entries, not the number of free IOBs. Completely misnamed. 2018-09-12 06:40:18 -06:00
Gregory Nutt 39df7ed0c0 mm/iob and sched/semaphore: Work around some issues with the IOB throttle semaphore. It has some odd behaviors that can cause assertions in sem_post(). Also, it seems to get outside of its range occasionally. Need to REVISIT this. 2018-09-10 11:32:09 -06:00
Gregory Nutt fc127fd297 sched/signal: Add a generic signal notification facility. Modify the custom IOB available notifier so that it is now just a wrapper around this generic signal notification. This generic signal notification faility will, eventually, be used to support network polling.
Squashed commit of the following:

    mm/iob:  The IOB available notifier is now just a wrapper around the common signal notifier.

    sched/signal:  Add a generic signal notification facility.

    sched/signal/sig_evthread.c:  More trivial naming changes.

    sched/signal:  Rename nxsig_notification() to nxsig_evthread() to make forthcoming naming additions more consistent.
2018-09-09 08:32:37 -06:00
Gregory Nutt bba8541ad6 mm/iob: Add an IOB notifier that will send a signal to any registered threads that want to be notified when an IOB has been freed. This is an untested work-in-progress and is intended to be a part of a larger solution to correctly handling network poll operations. 2018-09-08 11:21:18 -06:00
Gregory Nutt 42a0796615 Squashed commit of the following:
sched/semaphore:  Add nxsem_post() which is identical to sem_post() except that it never modifies the errno variable.  Changed all references to sem_post in the OS to nxsem_post().

    sched/semaphore:  Add nxsem_destroy() which is identical to sem_destroy() except that it never modifies the errno variable.  Changed all references to sem_destroy() in the OS to nxsem_destroy().

    libc/semaphore and sched/semaphore:  Add nxsem_getprotocol() and nxsem_setprotocola which are identical to sem_getprotocol() and set_setprotocol() except that they never modifies the errno variable.  Changed all references to sem_setprotocol in the OS to nxsem_setprotocol().  sem_getprotocol() was not used in the OS
2017-10-03 15:35:24 -06:00
Gregory Nutt 6a3800f611 There can be a failure in IOB allocation to some asynchronous behavior caused by the use of sem_post(). Consider this scenario:
Task A holds an IOB.  There are no further IOBs.  The value of semcount is zero.
Task B calls iob_alloc().  Since there are not IOBs, it calls sem_wait().  The v
alue of semcount is now -1.

Task A frees the IOB.  iob_free() adds the IOB to the free list and calls sem_post() this makes Task B ready to run and sets semcount to zero NOT 1.  There is one IOB in the free list and semcount is zero.  When Task B wakes up it would increment the sem_count back to the correct value.

But an interrupt or another task runs occurs before Task B executes.  The interrupt or other tak takes the IOB off of the free list and decrements the semcount.  But since semcount is then < 0, this causes the assertion because that is an invalid state in the interrupt handler.

So I think that the root cause is that there the asynchrony between incrementing the semcount.  This change separates the list of IOBs:  Currently there is only a free list of IOBs.  The problem, I believe, is because of asynchronies due sem_post() post cause the semcount and the list content to become out of sync.  This change adds a new 'committed' list:  When there is a task waiting for an IOB, it will go into the committed list rather than the free list before the semaphore is posted.  On the waiting side, when awakened from the semaphore wait, it will expect to find its IOB in the committed list, rather than free list.

In this way, the content of the free list and the value of the semaphore count always remain in sync.
2017-05-16 11:03:35 -06:00
Gregory Nutt 2043e1a114 IOBs: Move from driver/iob to a better location in mm/iob 2017-05-09 07:35:30 -06:00