Skip to content

Commit

Permalink
libs/libc/queue: inline queue list to improve performance
Browse files Browse the repository at this point in the history
add a config CONFIG_LIBC_INLINE_QUEUE to inline the queue list

test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Jul 21, 2024
1 parent b706891 commit be39def
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 556 deletions.
225 changes: 225 additions & 0 deletions include/nuttx/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
* Pre-processor Definitions
****************************************************************************/

#ifdef CONFIG_LIBC_INLINE_QUEUE
# ifndef STATIC_INLINE
#define STATIC_INLINE static inline_function
# endif
#else
# define STATIC_INLINE
#endif

#define sq_init(q) \
do \
{ \
Expand Down Expand Up @@ -343,24 +351,241 @@ extern "C"

/* Add nodes to queues */

#ifndef CONFIG_LIBC_INLINE_QUEUE
void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
FAR sq_queue_t *queue);
#else
STATIC_INLINE void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
FAR sq_queue_t *queue)
{
if (!queue->head || prev == queue->tail)
{
sq_addlast(node, queue);
}
else
{
node->flink = prev->flink;
prev->flink = node;
}
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
FAR dq_queue_t *queue);
#else
STATIC_INLINE void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
FAR dq_queue_t *queue)
{
if (!queue->head || prev == queue->tail)
{
dq_addlast(node, queue);
}
else
{
FAR dq_entry_t *next = prev->flink;
node->blink = prev;
node->flink = next;
next->blink = node;
prev->flink = node;
}
}
#endif

/* Remove nodes from queues */

#ifndef CONFIG_LIBC_INLINE_QUEUE
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, FAR sq_queue_t *queue);
#else
STATIC_INLINE FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node,
FAR sq_queue_t *queue)
{
FAR sq_entry_t *ret = node->flink;

if (queue->head && ret)
{
if (queue->tail == ret)
{
queue->tail = node;
node->flink = NULL;
}
else
{
node->flink = ret->flink;
}

ret->flink = NULL;
}

return ret;
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node, FAR dq_queue_t *queue);
#else
STATIC_INLINE FAR dq_entry_t *dq_remafter(FAR dq_entry_t *node,
FAR dq_queue_t *queue)
{
FAR dq_entry_t *ret = node->flink;

if (queue->head != NULL && ret != NULL)
{
dq_rem(ret, queue);
}

return ret;
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue);
#else
STATIC_INLINE FAR sq_entry_t *sq_remlast(FAR sq_queue_t *queue)
{
FAR sq_entry_t *ret = queue->tail;

if (ret)
{
if (queue->head == queue->tail)
{
queue->head = NULL;
queue->tail = NULL;
}
else
{
FAR sq_entry_t *prev;
for (prev = queue->head;
prev && prev->flink != ret;
prev = prev->flink);

if (prev)
{
prev->flink = NULL;
queue->tail = prev;
}
}

ret->flink = NULL;
}

return ret;
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue);
#else
STATIC_INLINE FAR dq_entry_t *dq_remlast(FAR dq_queue_t *queue)
{
FAR dq_entry_t *ret = queue->tail;

if (ret)
{
FAR dq_entry_t *prev = ret->blink;
if (!prev)
{
queue->head = NULL;
queue->tail = NULL;
}
else
{
queue->tail = prev;
prev->flink = NULL;
}

ret->flink = NULL;
ret->blink = NULL;
}

return ret;
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue);
#else
STATIC_INLINE FAR sq_entry_t *sq_remfirst(FAR sq_queue_t *queue)
{
FAR sq_entry_t *ret = queue->head;

if (ret)
{
queue->head = ret->flink;
if (!queue->head)
{
queue->tail = NULL;
}

ret->flink = NULL;
}

return ret;
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue);
#else
STATIC_INLINE FAR dq_entry_t *dq_remfirst(FAR dq_queue_t *queue)
{
FAR dq_entry_t *ret = queue->head;

if (ret)
{
FAR dq_entry_t *next = ret->flink;
if (!next)
{
queue->head = NULL;
queue->tail = NULL;
}
else
{
queue->head = next;
next->blink = NULL;
}

ret->flink = NULL;
ret->blink = NULL;
}

return ret;
}
#endif

/* Count nodes in queues */

#ifndef CONFIG_LIBC_INLINE_QUEUE
size_t sq_count(FAR sq_queue_t *queue);
#else
STATIC_INLINE size_t sq_count(FAR sq_queue_t *queue)
{
FAR sq_entry_t *node;
size_t count;

for (node = queue->head, count = 0;
node != NULL;
node = node->flink, count++);

return count;
}
#endif

#ifndef CONFIG_LIBC_INLINE_QUEUE
size_t dq_count(FAR dq_queue_t *queue);
#else
STATIC_INLINE size_t dq_count(FAR dq_queue_t *queue)
{
FAR dq_entry_t *node;
size_t count;

for (node = queue->head, count = 0;
node != NULL;
node = node->flink, count++);

return count;
}
#endif

#undef EXTERN
#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions libs/libc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ source "libs/libc/stream/Kconfig"
source "libs/libc/regex/Kconfig"
source "libs/libc/gpsutils/Kconfig"
source "libs/libc/fdt/Kconfig"
source "libs/libc/queue/Kconfig"
15 changes: 3 additions & 12 deletions libs/libc/queue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
#
# ##############################################################################

target_sources(
c
PRIVATE sq_addafter.c
sq_remlast.c
sq_remfirst.c
sq_remafter.c
sq_count.c
dq_addafter.c
dq_remlast.c
dq_remfirst.c
dq_remafter.c
dq_count.c)
if(NOT CONFIG_LIBC_INLINE_QUEUE)
target_sources(c PRIVATE queue.c)
endif()
10 changes: 10 additions & 0 deletions libs/libc/queue/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config LIBC_INLINE_QUEUE
bool "Inline queue list to improve the performance"
default n
---help---
Inline queue list to improve the performance
7 changes: 5 additions & 2 deletions libs/libc/queue/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
#
############################################################################

ifneq ($(CONFIG_LIBC_INLINE_QUEUE),y)

# Add the queue C files to the build

CSRCS += sq_addafter.c sq_remlast.c sq_remfirst.c sq_remafter.c sq_count.c
CSRCS += dq_addafter.c dq_remlast.c dq_remfirst.c dq_remafter.c dq_count.c
CSRCS += queue.c

# Add the queue directory to the build

DEPPATH += --dep-path queue
VPATH += :queue

endif
54 changes: 0 additions & 54 deletions libs/libc/queue/dq_addafter.c

This file was deleted.

Loading

0 comments on commit be39def

Please sign in to comment.