aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-12-12 23:32:12 +0100
committerDave Barach <openvpp@barachs.net>2020-12-14 12:14:21 +0000
commit62c25abaa3e93be5815172d391295a6ab0390122 (patch)
tree3d252a33a032c8c3320f6b007b61b6ee29b161b8 /src
parentdc01471be72b272922bf6c9ef9e6221162ab906a (diff)
vppinfra: simpler and faster pool_foreach
- reduces number of instructions generated 4 times compared to old code - adds pool_foreach2 which is more friendly to clang-format Type: improvement Change-Id: I51e9c7fb09655c60d883987dadf5b2666c12b3f7 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/nat/nat44_cli.c2
-rw-r--r--src/vnet/devices/virtio/vhost_user.c1
-rw-r--r--src/vppinfra/pool.h46
3 files changed, 33 insertions, 16 deletions
diff --git a/src/plugins/nat/nat44_cli.c b/src/plugins/nat/nat44_cli.c
index d9cfe32287d..29807649ff8 100644
--- a/src/plugins/nat/nat44_cli.c
+++ b/src/plugins/nat/nat44_cli.c
@@ -750,7 +750,7 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
u32 count = 0;
u64 now = vlib_time_now (vm);
- u64 sess_timeout_time;
+ u64 sess_timeout_time = 0;
u32 udp_sessions = 0;
u32 tcp_sessions = 0;
diff --git a/src/vnet/devices/virtio/vhost_user.c b/src/vnet/devices/virtio/vhost_user.c
index d8c79ea17aa..f7cecef4d19 100644
--- a/src/vnet/devices/virtio/vhost_user.c
+++ b/src/vnet/devices/virtio/vhost_user.c
@@ -1230,6 +1230,7 @@ vhost_user_process (vlib_main_t * vm,
/* try to connect */
strncpy (sun.sun_path, (char *) vui->sock_filename,
sizeof (sun.sun_path) - 1);
+ sun.sun_path[sizeof (sun.sun_path) - 1] = 0;
/* Avoid hanging VPP if the other end does not accept */
if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index c74e76f0a4c..d7be8cb1f01 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -422,6 +422,20 @@ _pool_free (void *v)
return 0;
}
+static_always_inline uword
+pool_get_first_index (void *pool)
+{
+ pool_header_t *h = pool_header (pool);
+ return clib_bitmap_first_clear (h->free_bitmap);
+}
+
+static_always_inline uword
+pool_get_next_index (void *pool, uword last)
+{
+ pool_header_t *h = pool_header (pool);
+ return clib_bitmap_next_clear (h->free_bitmap, last + 1);
+}
+
/** Free a pool. */
#define pool_free(p) (p) = _pool_free(p)
@@ -509,17 +523,16 @@ do { \
@c pool_foreach which builds a vector of active indices, and a
vec_foreach() (or plain for-loop) to walk the active index vector.
*/
+
+#define pool_foreach2(VAR,POOL) \
+ if (POOL) \
+ for (VAR = POOL + pool_get_first_index (POOL); \
+ VAR < vec_end (POOL); \
+ VAR = POOL + pool_get_next_index (POOL, VAR - POOL))
+
#define pool_foreach(VAR,POOL,BODY) \
-do { \
- uword _pool_foreach_lo, _pool_foreach_hi; \
- pool_foreach_region (_pool_foreach_lo, _pool_foreach_hi, (POOL), \
- ({ \
- for ((VAR) = (POOL) + _pool_foreach_lo; \
- (VAR) < (POOL) + _pool_foreach_hi; \
- (VAR)++) \
- do { BODY; } while (0); \
- })); \
-} while (0)
+ pool_foreach2(VAR,POOL) \
+ { BODY; }
/** Returns pointer to element at given index.
@@ -553,13 +566,16 @@ do { \
_pool_var(rv); \
})
+#define pool_foreach_index2(i,v) \
+ if (v) \
+ for (i = pool_get_first_index (v); \
+ i < vec_len (v); \
+ i = pool_get_next_index (v, i)) \
+
/** Iterate pool by index. */
#define pool_foreach_index(i,v,body) \
- for ((i) = 0; (i) < vec_len (v); (i)++) \
- { \
- if (! pool_is_free_index ((v), (i))) \
- do { body; } while (0); \
- }
+ pool_foreach_index2 (i,v) \
+ { body; }
/**
* @brief Remove all elements from a pool in a safe way