aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ioam/export-common/ioam_export.h
diff options
context:
space:
mode:
authorjaszha03 <jason.zhang2@arm.com>2019-07-11 20:47:24 +0000
committerDave Barach <openvpp@barachs.net>2019-07-31 13:53:55 +0000
commit5cdde5c25a0e71d923a6d56e5c94e058887f95d8 (patch)
treec54eeb5a91ce67417806fabd1fca8d287993e71d /src/plugins/ioam/export-common/ioam_export.h
parent9a4e631890a70978d414b4937cb94b50cfd778e6 (diff)
vppinfra: refactor test_and_set spinlocks to use clib_spinlock_t
Spinlock performance improved when implemented with compare_and_exchange instead of test_and_set. All instances of test_and_set locks were refactored to use clib_spinlock_t when possible. Some locks e.g. ssvm synchronize between processes rather than threads, so they cannot directly use clib_spinlock_t. Type: refactor Change-Id: Ia16b5d4cd49209b2b57b8df6c94615c28b11bb60 Signed-off-by: Jason Zhang <jason.zhang2@arm.com> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com> Reviewed-by: Lijian Zhang <Lijian.Zhang@arm.com>
Diffstat (limited to 'src/plugins/ioam/export-common/ioam_export.h')
-rw-r--r--src/plugins/ioam/export-common/ioam_export.h18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/plugins/ioam/export-common/ioam_export.h b/src/plugins/ioam/export-common/ioam_export.h
index 672576ebded..b1bca9bf91f 100644
--- a/src/plugins/ioam/export-common/ioam_export.h
+++ b/src/plugins/ioam/export-common/ioam_export.h
@@ -28,6 +28,7 @@
#include <vppinfra/hash.h>
#include <vppinfra/error.h>
#include <vppinfra/elog.h>
+#include <vppinfra/lock.h>
#include <vlib/threads.h>
@@ -62,7 +63,7 @@ typedef struct
/* Vector of per thread ioam_export_buffer_t to buffer pool index */
u32 *buffer_per_thread;
/* Lock per thread to swap buffers between worker and timer process */
- volatile u32 **lockp;
+ clib_spinlock_t *lockp;
/* time scale transform */
u32 unix_time_0;
@@ -194,9 +195,7 @@ ioam_export_thread_buffer_init (ioam_export_main_t * em, vlib_main_t * vm)
ioam_export_thread_buffer_free (em);
return (-2);
}
- em->lockp[i] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
- clib_memset ((void *) em->lockp[i], 0, CLIB_CACHE_LINE_BYTES);
+ clib_spinlock_init (&em->lockp[i]);
}
return (1);
}
@@ -404,7 +403,7 @@ ioam_export_process_common (ioam_export_main_t * em, vlib_main_t * vm,
for (i = 0; i < vec_len (em->buffer_per_thread); i++)
{
/* If the worker thread is processing export records ignore further checks */
- if (*em->lockp[i] == 1)
+ if (CLIB_SPINLOCK_IS_LOCKED (&em->lockp[i]))
continue;
eb = pool_elt_at_index (em->buffer_pool, em->buffer_per_thread[i]);
if (eb->records_in_this_buffer > 0
@@ -436,11 +435,10 @@ ioam_export_process_common (ioam_export_main_t * em, vlib_main_t * vm,
*/
for (i = 0; i < vec_len (thread_index); i++)
{
- while (clib_atomic_test_and_set (em->lockp[thread_index[i]]))
- ;
+ clib_spinlock_lock (&em->lockp[thread_index[i]]);
em->buffer_per_thread[thread_index[i]] =
vec_pop (vec_buffer_indices);
- clib_atomic_release (em->lockp[thread_index[i]]);
+ clib_spinlock_unlock (&em->lockp[thread_index[i]]);
}
/* Send the buffers */
@@ -479,7 +477,7 @@ do { \
from = vlib_frame_vector_args (F); \
n_left_from = (F)->n_vectors; \
next_index = (N)->cached_next_index; \
- while (clib_atomic_test_and_set ((EM)->lockp[(VM)->thread_index])); \
+ clib_spinlock_lock (&(EM)->lockp[(VM)->thread_index]); \
my_buf = ioam_export_get_my_buffer (EM, (VM)->thread_index); \
my_buf->touched_at = vlib_time_now (VM); \
while (n_left_from > 0) \
@@ -622,7 +620,7 @@ do { \
} \
vlib_node_increment_counter (VM, export_node.index, \
EXPORT_ERROR_RECORDED, pkts_recorded); \
- *(EM)->lockp[(VM)->thread_index] = 0; \
+ clib_spinlock_unlock (&(EM)->lockp[(VM)->thread_index]); \
} while(0)
#endif /* __included_ioam_export_h__ */