Enable lock annotations on most libraries and drivers
Subsystems (4)
cover Enable lock annotations on most libraries and drivers
This is a followup of the series that introduced lock annotations. I reworked and made annotations work in what seemed the easier cases. In most cases, I chose to convert inline wrappers around the EAL lock API to simple macro: I did not see much value in those wrappers and this is way simpler than adding __rte_*lock_function tags everywhere.
A list of libraries and drivers still need more work as their code have non obvious locks handling. For those components, the check is opted out.
I leave it to their respective maintainers to enable the checks later.
Maintainers, please review.
Signature · 69 lines
David Marchand David Marchand (14): malloc: rework heap lock handling mem: rework malloc heap init mem: annotate shared memory config locks hash: annotate cuckoo hash lock graph: annotate graph lock drivers: inherit lock annotations for Intel drivers net/cxgbe: inherit lock annotations net/fm10k: annotate mailbox lock net/sfc: rework locking in proxy code net/sfc: inherit lock annotations net/virtio: annotate lock for guest announce raw/ifpga: inherit lock annotations vdpa/sfc: inherit lock annotations enable lock check .../prog_guide/env_abstraction_layer.rst | 5 +- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/iavf/iavf_osdep.h | 39 +++-------- drivers/common/iavf/iavf_prototype.h | 6 -- drivers/common/idpf/base/idpf_osdep.h | 26 ++------ drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/cxgbe/base/adapter.h | 35 ++-------- drivers/net/enic/meson.build | 1 + drivers/net/fm10k/fm10k_ethdev.c | 2 + drivers/net/hns3/meson.build | 1 + drivers/net/i40e/base/i40e_osdep.h | 8 +-- drivers/net/i40e/base/i40e_prototype.h | 5 -- drivers/net/i40e/i40e_ethdev.c | 24 ------- drivers/net/ice/base/ice_osdep.h | 26 ++------ drivers/net/mlx5/meson.build | 1 + drivers/net/sfc/sfc.h | 41 ++---------- drivers/net/sfc/sfc_ev.c | 6 +- drivers/net/sfc/sfc_repr.c | 38 ++--------- drivers/net/sfc/sfc_repr_proxy.c | 59 +++++++++-------- drivers/net/virtio/virtio_ethdev.c | 8 +-- drivers/net/virtio/virtio_ethdev.h | 7 +- drivers/raw/ifpga/afu_pmd_core.c | 17 +---- drivers/vdpa/sfc/sfc_vdpa.h | 41 ++---------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 ++-- lib/eal/common/eal_common_mcfg.c | 66 +++++++++++-------- lib/eal/common/eal_common_memory.c | 10 +-- lib/eal/common/malloc_heap.c | 55 +++++++++++----- lib/eal/common/malloc_heap.h | 3 + lib/eal/common/rte_malloc.c | 10 --- lib/eal/freebsd/eal.c | 13 ++++ lib/eal/include/rte_eal_memconfig.h | 63 ++++++++++++++---- lib/eal/linux/eal.c | 13 ++++ lib/eal/version.map | 4 ++ lib/eal/windows/eal.c | 13 ++++ lib/graph/graph.c | 10 ++- lib/graph/graph_private.h | 10 ++- lib/hash/rte_cuckoo_hash.c | 8 +++ lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 47 files changed, 313 insertions(+), 389 deletions(-) -- 2.39.2
PATCH 1/14 malloc: rework heap lock handling
Move all heap->lock manipulation to malloc_heap.c to have a single location where to look at and make higher level code unaware of this locking constraint.
The destroy helper has been reworked to zero all the heap object but leave the lock untouched. The heap lock is then released through the standard API.
This makes the code less scary even though, at this point of its life, the heap object is probably referenced only by the caller.
--- lib/eal/common/malloc_heap.c | 45 +++++++++++++++++++++++++++--------- lib/eal/common/rte_malloc.c | 10 -------- 2 files changed, 34 insertions(+), 21 deletions(-)
lib/eal/common/malloc_heap.c +34 -11
@@ -1292,6 +1292,8 @@ int malloc_heap_add_external_memory(struct malloc_heap *heap, struct rte_memseg_list *msl) { + rte_spinlock_lock(&heap->lock); +/* erase contents of new memory */ memset (msl->base_va,0 , msl->len);
@@ -1308,6 +1310,11 @@ malloc_heap_add_external_memory(struct malloc_heap *heap,eal_memalloc_mem_event_notify (RTE_MEM_EVENT_ALLOC , msl->base_va, msl->len); +/* mark it as heap segment */ + msl->heap =1 ; + +rte_spinlock_unlock (&heap->lock); +return 0 ; }
@@ -1315,7 +1322,12 @@ int malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr, size_t len) { - struct malloc_elem *elem = heap->first; + struct malloc_elem *elem; +int ret =-1 ; + +rte_spinlock_lock (&heap->lock); + + elem = heap->first;/* find element with specified va address */ while (elem !=NULL && elem != va_addr) {
@@ -1323,20 +1335,24 @@ malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,/* stop if we've blown past our VA */ if (elem > (struct malloc_elem *)va_addr) { rte_errno =ENOENT ; -return -1 ; + goto out; } }/* check if element was found */ if (elem ==NULL || elem->msl->len != len) { rte_errno =ENOENT ; -return -1 ; + goto out; }/* if element's size is not equal to segment len, segment is busy */ if (elem->state ==ELEM_BUSY || elem->size != len) { rte_errno =EBUSY ; -return -1 ; + goto out; } -return destroy_elem (elem, len); + ret =destroy_elem (elem, len); + +out: +rte_spinlock_unlock (&heap->lock); +return ret; }int
@@ -1372,23 +1388,30 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name)int malloc_heap_destroy (struct malloc_heap *heap) { +int ret =-1 ; + +rte_spinlock_lock (&heap->lock); +if (heap->alloc_count !=0 ) {RTE_LOG (ERR ,EAL ,"Heap is still in use\n" ); rte_errno =EBUSY ; -return -1 ; + goto fail; }if (heap->first !=NULL || heap->last !=NULL ) {RTE_LOG (ERR ,EAL ,"Heap still contains memory segments\n" ); rte_errno =EBUSY ; -return -1 ; + goto fail; }if (heap->total_size !=0 )RTE_LOG (ERR ,EAL ,"Total size not zero, heap is likely corrupt\n" ); -/* after this, the lock will be dropped */ -memset (heap,0 ,sizeof (*heap)); - -return 0 ; +RTE_BUILD_BUG_ON (offsetof(struct malloc_heap , lock) !=0 ); +memset (RTE_PTR_ADD (heap,sizeof (heap->lock)),0 , +sizeof (*heap) -sizeof (heap->lock)); + ret =0 ; +fail: +rte_spinlock_unlock (&heap->lock); +return ret; }int
lib/eal/common/rte_malloc.c +0 -10
@@ -436,10 +436,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len, goto unlock; } -rte_spinlock_lock (&heap->lock); ret =malloc_heap_add_external_memory (heap, msl); - msl->heap =1 ;/* mark it as heap segment */ -rte_spinlock_unlock (&heap->lock); unlock:rte_mcfg_mem_write_unlock ();
@@ -482,9 +479,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len) goto unlock; } -rte_spinlock_lock (&heap->lock); ret =malloc_heap_remove_external_memory (heap, va_addr, len); -rte_spinlock_unlock (&heap->lock);if (ret !=0 ) goto unlock;
@@ -655,12 +650,7 @@ rte_malloc_heap_destroy(const char *heap_name) goto unlock; }/* sanity checks done, now we can destroy the heap */ -rte_spinlock_lock (&heap->lock); ret =malloc_heap_destroy (heap); - -/* if we failed, lock is still active */ -if (ret <0 ) -rte_spinlock_unlock (&heap->lock); unlock:rte_mcfg_mem_write_unlock ();
Signature · 1 line
2.39.2
PATCH 2/14 mem: rework malloc heap init
In reply to David Marchandrte_eal_memory_init() and rte_eal_malloc_heap_init() must be called in a common section taking rte_mcfg_mem_read_lock().
Split rte_eal_malloc_heap_init() in two so that the mem lock is taken in rte_eal_init() making lock checks trivial (once annotated in the next patch).
--- lib/eal/common/eal_common_memory.c | 10 +--------- lib/eal/common/malloc_heap.c | 10 ++++++---- lib/eal/common/malloc_heap.h | 3 +++ lib/eal/freebsd/eal.c | 13 +++++++++++++ lib/eal/linux/eal.c | 13 +++++++++++++ lib/eal/windows/eal.c | 13 +++++++++++++ 6 files changed, 49 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_memory.c +1 -9
@@ -1078,18 +1078,11 @@ rte_eal_memory_detach(void)int rte_eal_memory_init (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config;const struct internal_config *internal_conf =eal_get_internal_configuration (); -int retval; -RTE_LOG (DEBUG ,EAL ,"Setting up physically contiguous memory...\n" ); - -if (!mcfg) -return -1 ; -/* lock mem hotplug here, to prevent races while we init */ -rte_mcfg_mem_read_lock (); +RTE_LOG (DEBUG ,EAL ,"Setting up physically contiguous memory...\n" );if (rte_eal_memseg_init () <0 ) goto fail;
@@ -1108,7 +1101,6 @@ rte_eal_memory_init(void)return 0 ; fail: -rte_mcfg_mem_read_unlock ();return -1 ; }
lib/eal/common/malloc_heap.c +6 -4
@@ -1442,18 +1442,20 @@ rte_eal_malloc_heap_init(void) } } -if (register_mp_requests ()) {RTE_LOG (ERR ,EAL ,"Couldn't register malloc multiprocess actions\n" ); -rte_mcfg_mem_read_unlock ();return -1 ; } -/* unlock mem hotplug here. it's safe for primary as no requests can +return 0 ; +} + +int rte_eal_malloc_heap_populate (void ) +{ +/* mem hotplug is unlocked here. it's safe for primary as no requests can * even come before primary itself is fully initialized, and secondaries * do not need to initialize the heap. */ -rte_mcfg_mem_read_unlock ();/* secondary process does not need to initialize anything */ if (rte_eal_process_type () !=RTE_PROC_PRIMARY )
lib/eal/common/malloc_heap.h +3 -0
@@ -85,6 +85,9 @@ malloc_socket_to_heap_id(unsigned int socket_id);int rte_eal_malloc_heap_init (void ); +int +rte_eal_malloc_heap_populate (void ); +void rte_eal_malloc_heap_cleanup (void );
lib/eal/freebsd/eal.c +13 -0
@@ -26,6 +26,7 @@#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <rte_errno.h> #include <rte_per_lcore.h> #include <rte_lcore.h>
@@ -754,13 +755,25 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ; }if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
lib/eal/linux/eal.c +13 -0
@@ -30,6 +30,7 @@#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <rte_errno.h> #include <rte_lcore.h> #include <rte_service_component.h>
@@ -1197,7 +1198,10 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ;
@@ -1207,6 +1211,15 @@ rte_eal_init(int argc, char **argv)eal_hugedirs_unlock ();if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
lib/eal/windows/eal.c +13 -0
@@ -12,6 +12,7 @@#include <rte_debug.h> #include <rte_bus.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <eal_memcfg.h> #include <rte_errno.h> #include <rte_lcore.h>
@@ -387,13 +388,25 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ; }if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
Signature · 1 line
2.39.2
PATCH 3/14 mem: annotate shared memory config locks
In reply to David MarchandExpose internal locks via some internal accessors. Then annotate rte_mcfg_xxx_(read|write)_(|un)lock.
--- lib/eal/common/eal_common_mcfg.c | 66 +++++++++++++++++------------ lib/eal/include/rte_eal_memconfig.h | 63 +++++++++++++++++++++------ lib/eal/version.map | 4 ++ 3 files changed, 91 insertions(+), 42 deletions(-)
lib/eal/common/eal_common_mcfg.c +38 -28
@@ -69,102 +69,112 @@ eal_mcfg_update_from_internal(void) mcfg->version =RTE_VERSION ; } +rte_rwlock_t * +rte_mcfg_mem_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->memory_hotplug_lock; +} +void rte_mcfg_mem_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->memory_hotplug_lock); +rte_rwlock_read_lock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->memory_hotplug_lock); +rte_rwlock_read_unlock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->memory_hotplug_lock); +rte_rwlock_write_lock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->memory_hotplug_lock); +rte_rwlock_write_unlock (rte_mcfg_mem_get_lock ()); +} + +rte_rwlock_t * +rte_mcfg_tailq_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->qlock; }void rte_mcfg_tailq_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->qlock); +rte_rwlock_read_lock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->qlock); +rte_rwlock_read_unlock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->qlock); +rte_rwlock_write_lock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->qlock); +rte_rwlock_write_unlock (rte_mcfg_tailq_get_lock ()); +} + +rte_rwlock_t * +rte_mcfg_mempool_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->mplock; }void rte_mcfg_mempool_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->mplock); +rte_rwlock_read_lock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->mplock); +rte_rwlock_read_unlock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->mplock); +rte_rwlock_write_lock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->mplock); +rte_rwlock_write_unlock (rte_mcfg_mempool_get_lock ()); +} + +rte_spinlock_t * +rte_mcfg_timer_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->tlock; }void rte_mcfg_timer_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_spinlock_lock (&mcfg->tlock); +rte_spinlock_lock (rte_mcfg_timer_get_lock ()); }void rte_mcfg_timer_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_spinlock_unlock (&mcfg->tlock); +rte_spinlock_unlock (rte_mcfg_timer_get_lock ()); }bool
lib/eal/include/rte_eal_memconfig.h +49 -14
144 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -469,6 +469,10 @@ INTERNAL { rte_intr_vec_list_free; rte_intr_vec_list_index_get; rte_intr_vec_list_index_set; + rte_mcfg_mem_get_lock; + rte_mcfg_mempool_get_lock; + rte_mcfg_tailq_get_lock; + rte_mcfg_timer_get_lock; rte_mem_lock; rte_mem_map; rte_mem_page_size;
Signature · 1 line
2.39.2
PATCH 4/14 hash: annotate cuckoo hash lock
In reply to David Marchand__hash_rw_(reader|writer)_(|un)lock helpers take locks depending on conditions that are fixed at the rte_hash object initialisation. So we can tell clang that those helpers unconditionally take/release those locks (and waive the lock check on their implementation).
--- lib/hash/rte_cuckoo_hash.c | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/hash/rte_cuckoo_hash.c +8 -0
@@ -575,6 +575,8 @@ rte_hash_count(const struct rte_hash *h)/* Read write locks implemented using rte_rwlock */ static inline void __hash_rw_writer_lock (const struct rte_hash *h) + __rte_exclusive_lock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)rte_rwlock_write_lock_tm (h->readwrite_lock);
@@ -584,6 +586,8 @@ __hash_rw_writer_lock(const struct rte_hash *h)static inline void __hash_rw_reader_lock (const struct rte_hash *h) + __rte_shared_lock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)rte_rwlock_read_lock_tm (h->readwrite_lock);
@@ -593,6 +597,8 @@ __hash_rw_reader_lock(const struct rte_hash *h)static inline void __hash_rw_writer_unlock (const struct rte_hash *h) + __rte_unlock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)rte_rwlock_write_unlock_tm (h->readwrite_lock);
@@ -602,6 +608,8 @@ __hash_rw_writer_unlock(const struct rte_hash *h)static inline void __hash_rw_reader_unlock (const struct rte_hash *h) + __rte_unlock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)rte_rwlock_read_unlock_tm (h->readwrite_lock);
Signature · 1 line
2.39.2
PATCH 5/14 graph: annotate graph lock
In reply to David MarchandExport internal lock and annotate associated helper.
--- lib/graph/graph.c | 10 ++++++++-- lib/graph/graph_private.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
lib/graph/graph.c +8 -2
@@ -30,16 +30,22 @@ graph_list_head_get(void)return &graph_list; } +rte_spinlock_t * +graph_spinlock_get (void ) +{ +return &graph_lock; +} +void graph_spinlock_lock (void ) { -rte_spinlock_lock (&graph_lock); +rte_spinlock_lock (graph_spinlock_get ()); }void graph_spinlock_unlock (void ) { -rte_spinlock_unlock (&graph_lock); +rte_spinlock_unlock (graph_spinlock_get ()); } static int
lib/graph/graph_private.h +8 -2
@@ -10,6 +10,7 @@#include <rte_common.h> #include <rte_eal.h> +#include <rte_spinlock.h> #include "rte_graph.h" #include "rte_graph_worker.h"
@@ -148,20 +149,25 @@ STAILQ_HEAD(graph_head, graph);*/ struct graph_head *graph_list_head_get (void ); +rte_spinlock_t * +graph_spinlock_get (void ); +/* Lock functions */ /** * @internal * * Take a lock on the graph internal spin lock. */ -void graph_spinlock_lock (void ); +void graph_spinlock_lock(void) + __rte_exclusive_lock_function(graph_spinlock_get());/** * @internal * * Release a lock on the graph internal spin lock. */ -void graph_spinlock_unlock (void ); +void graph_spinlock_unlock(void) + __rte_unlock_function(graph_spinlock_get());/* Graph operations */ /**
Signature · 1 line
2.39.2
PATCH 6/14 drivers: inherit lock annotations for Intel drivers
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
--- drivers/common/iavf/iavf_osdep.h | 39 ++++++-------------------- drivers/common/iavf/iavf_prototype.h | 6 ---- drivers/common/idpf/base/idpf_osdep.h | 26 +++-------------- drivers/net/i40e/base/i40e_osdep.h | 8 +++--- drivers/net/i40e/base/i40e_prototype.h | 5 ---- drivers/net/i40e/i40e_ethdev.c | 24 ---------------- drivers/net/ice/base/ice_osdep.h | 26 +++-------------- 7 files changed, 20 insertions(+), 114 deletions(-)
drivers/common/iavf/iavf_osdep.h +8 -31
@@ -170,11 +170,6 @@ struct iavf_virt_mem {u32 size; } __rte_packed; -/* SW spinlock */ -struct iavf_spinlock { -rte_spinlock_t spinlock; -}; -#define iavf_allocate_dma_mem (h, m, unused, s, a) \ iavf_allocate_dma_mem_d(h, m, s, a)#define iavf_free_dma_mem (h, m) iavf_free_dma_mem_d(h, m)
@@ -182,32 +177,14 @@ struct iavf_spinlock {#define iavf_allocate_virt_mem (h, m, s) iavf_allocate_virt_mem_d(h, m, s)#define iavf_free_virt_mem (h, m) iavf_free_virt_mem_d(h, m) -static inline void -iavf_init_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -iavf_acquire_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -iavf_release_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp) -{ -} +/* SW spinlock */ +struct iavf_spinlock { +rte_spinlock_t spinlock; +}; -#define iavf_init_spinlock (_sp) iavf_init_spinlock_d(_sp) -#define iavf_acquire_spinlock (_sp) iavf_acquire_spinlock_d(_sp) -#define iavf_release_spinlock (_sp) iavf_release_spinlock_d(_sp) -#define iavf_destroy_spinlock (_sp) iavf_destroy_spinlock_d(_sp) +#define iavf_init_spinlock (sp) rte_spinlock_init(&(sp)->spinlock) +#define iavf_acquire_spinlock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define iavf_release_spinlock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define iavf_destroy_spinlock (sp) RTE_SET_USED(sp)#endif /* _IAVF_OSDEP_H_ */
drivers/common/iavf/iavf_prototype.h +0 -6
@@ -76,12 +76,6 @@ STATIC INLINE struct iavf_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)return iavf_ptype_lookup[ptype]; } -/* prototype for functions used for SW spinlocks */ -void iavf_init_spinlock (struct iavf_spinlock *sp); -void iavf_acquire_spinlock (struct iavf_spinlock *sp); -void iavf_release_spinlock (struct iavf_spinlock *sp); -void iavf_destroy_spinlock (struct iavf_spinlock *sp); -__rte_internal void iavf_vf_parse_hw_config(struct iavf_hw *hw,struct virtchnl_vf_resource *msg);
drivers/common/idpf/base/idpf_osdep.h +4 -22
@@ -210,28 +210,10 @@ struct idpf_lock {rte_spinlock_t spinlock; }; -static inline void -idpf_init_lock (struct idpf_lock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -idpf_acquire_lock (struct idpf_lock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -idpf_release_lock (struct idpf_lock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -idpf_destroy_lock(__rte_unused struct idpf_lock *sp) -{ -} +#define idpf_init_lock (sp) rte_spinlock_init(&(sp)->spinlock) +#define idpf_acquire_lock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define idpf_release_lock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define idpf_destroy_lock (sp) RTE_SET_USED(sp)struct idpf_hw ;
drivers/net/i40e/base/i40e_osdep.h +4 -4
@@ -215,10 +215,10 @@ struct i40e_spinlock {rte_spinlock_t spinlock; }; -#define i40e_init_spinlock (_sp) i40e_init_spinlock_d(_sp) -#define i40e_acquire_spinlock (_sp) i40e_acquire_spinlock_d(_sp) -#define i40e_release_spinlock (_sp) i40e_release_spinlock_d(_sp) -#define i40e_destroy_spinlock (_sp) i40e_destroy_spinlock_d(_sp) +#define i40e_init_spinlock (sp) rte_spinlock_init(&(sp)->spinlock) +#define i40e_acquire_spinlock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define i40e_release_spinlock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define i40e_destroy_spinlock (sp) RTE_SET_USED(sp)#define I40E_NTOHS (a) rte_be_to_cpu_16(a)#define I40E_NTOHL (a) rte_be_to_cpu_32(a)
drivers/net/i40e/base/i40e_prototype.h +0 -5
@@ -546,11 +546,6 @@ i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed) } }#endif /* PF_DRIVER */ -/* prototype for functions used for SW spinlocks */ -void i40e_init_spinlock (struct i40e_spinlock *sp); -void i40e_acquire_spinlock (struct i40e_spinlock *sp); -void i40e_release_spinlock (struct i40e_spinlock *sp); -void i40e_destroy_spinlock (struct i40e_spinlock *sp);/* i40e_common for VF drivers*/ void i40e_vf_parse_hw_config(struct i40e_hw *hw,
drivers/net/i40e/i40e_ethdev.c +0 -24
@@ -4622,30 +4622,6 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,return I40E_SUCCESS ; } -void -i40e_init_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -void -i40e_acquire_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -void -i40e_release_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -void -i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp) -{ -return ; -} -/** * Get the hardware capabilities, which will be parsed * and saved into struct i40e_hw.
drivers/net/ice/base/ice_osdep.h +4 -22
@@ -211,28 +211,10 @@ struct ice_lock {rte_spinlock_t spinlock; }; -static inline void -ice_init_lock (struct ice_lock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -ice_acquire_lock (struct ice_lock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -ice_release_lock (struct ice_lock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -ice_destroy_lock(__rte_unused struct ice_lock *sp) -{ -} +#define ice_init_lock (sp) rte_spinlock_init(&(sp)->spinlock) +#define ice_acquire_lock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define ice_release_lock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define ice_destroy_lock (sp) RTE_SET_USED(sp)struct ice_hw ;
Signature · 1 line
2.39.2
PATCH 7/14 net/cxgbe: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
--- drivers/net/cxgbe/base/adapter.h | 35 +++++++------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)
drivers/net/cxgbe/base/adapter.h +7 -28
@@ -351,28 +351,19 @@ struct adapter {* t4_os_rwlock_init - initialize rwlock * @lock: the rwlock */ -static inline void t4_os_rwlock_init (rte_rwlock_t *lock) -{ -rte_rwlock_init (lock); -} +#define t4_os_rwlock_init (lock) rte_rwlock_init(lock)/** * t4_os_write_lock - get a write lock * @lock: the rwlock */ -static inline void t4_os_write_lock (rte_rwlock_t *lock) -{ -rte_rwlock_write_lock (lock); -} +#define t4_os_write_lock (lock) rte_rwlock_write_lock(lock)/** * t4_os_write_unlock - unlock a write lock * @lock: the rwlock */ -static inline void t4_os_write_unlock (rte_rwlock_t *lock) -{ -rte_rwlock_write_unlock (lock); -} +#define t4_os_write_unlock (lock) rte_rwlock_write_unlock(lock)/** * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
@@ -678,37 +669,25 @@ static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,* t4_os_lock_init - initialize spinlock * @lock: the spinlock */ -static inline void t4_os_lock_init (rte_spinlock_t *lock) -{ -rte_spinlock_init (lock); -} +#define t4_os_lock_init (lock) rte_spinlock_init(lock)/** * t4_os_lock - spin until lock is acquired * @lock: the spinlock */ -static inline void t4_os_lock (rte_spinlock_t *lock) -{ -rte_spinlock_lock (lock); -} +#define t4_os_lock (lock) rte_spinlock_lock(lock)/** * t4_os_unlock - unlock a spinlock * @lock: the spinlock */ -static inline void t4_os_unlock (rte_spinlock_t *lock) -{ -rte_spinlock_unlock (lock); -} +#define t4_os_unlock (lock) rte_spinlock_unlock(lock)/** * t4_os_trylock - try to get a lock * @lock: the spinlock */ -static inline int t4_os_trylock (rte_spinlock_t *lock) -{ -return rte_spinlock_trylock (lock); -} +#define t4_os_trylock (lock) rte_spinlock_trylock(lock)/** * t4_os_init_list_head - initialize
Signature · 1 line
2.39.2
PATCH 8/14 net/fm10k: annotate mailbox lock
In reply to David MarchandExpose requirements for helpers dealing with theFM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back) lock.
--- drivers/net/fm10k/fm10k_ethdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/fm10k/fm10k_ethdev.c +2 -0
@@ -116,6 +116,7 @@ fm10k_mbx_initlock(struct fm10k_hw *hw)static void fm10k_mbx_lock (struct fm10k_hw *hw) + __rte_exclusive_lock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {while (!rte_spinlock_trylock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)))rte_delay_us (FM10K_MBXLOCK_DELAY_US );
@@ -123,6 +124,7 @@ fm10k_mbx_lock(struct fm10k_hw *hw)static void fm10k_mbx_unlock (struct fm10k_hw *hw) + __rte_unlock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {rte_spinlock_unlock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)); }
Signature · 1 line
2.39.2
PATCH 9/14 net/sfc: rework locking in proxy code
In reply to David MarchandRemove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id() now only resolves the sa object and sfc_adapter_(|un)lock() are added were necessary.
This will simplify lock checks later.
--- drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 29 deletions(-)
drivers/net/sfc/sfc_repr_proxy.c +30 -29
@@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id) dev = &rte_eth_devices[pf_port_id]; sa =sfc_adapter_by_eth_dev (dev); -sfc_adapter_lock (sa); -return sa; } -static void -sfc_put_adapter (struct sfc_adapter *sa) -{ -sfc_adapter_unlock (sa); -} -static struct sfc_repr_proxy_port *sfc_repr_proxy_find_port (struct sfc_repr_proxy *rp,uint16_t repr_id) {
@@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, }sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ;
@@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, fail_alloc_port: fail_port_exists:sfc_log_init (sa,"failed: %s" ,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; fail_port_remove: fail_no_port:sfc_log_init (sa,"failed: %s" ,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; } rxq = &port->rxq[queue_id];if (rp->dp_rxq[queue_id].mp !=NULL && rp->dp_rxq[queue_id].mp != mp) {sfc_err (sa,"multiple mempools per queue are not supported" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOTSUP ; }
@@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].ref_count++;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ; }
@@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].mp =NULL ;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa); }int
@@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }
@@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, *egress_mport = port->egress_mport;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ; }
@@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, txq->ring =NULL ;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa); }int
@@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) }sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ;
@@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) fail_not_found:sfc_err (sa,"failed to start repr %u proxy port: %s" , repr_id,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }if (!port->enabled) {sfc_log_init (sa,"repr %u proxy port is not started - skip" , repr_id); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)sfc_err (sa,"failed to stop representor proxy TxQ %u: %s" , repr_id,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; } }
@@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port->enabled = false;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa); port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port (repr_id=%u)" , __func__, repr_id); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }
@@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id, __func__, repr_id, rte_strerror(rc)); } -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
Signature · 1 line
2.39.2
PATCH 10/14 net/sfc: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
One additional change is required in sfc_ev_qpoll() so that clang does see the same lock is being manipulated.
--- drivers/net/sfc/sfc.h | 41 ++++++-------------------------------- drivers/net/sfc/sfc_ev.c | 6 ++++-- drivers/net/sfc/sfc_repr.c | 38 +++++------------------------------ 3 files changed, 15 insertions(+), 70 deletions(-)
drivers/net/sfc/sfc.h +6 -35
@@ -333,41 +333,12 @@ sfc_sa2shared(struct sfc_adapter *sa)* change the lock in one place. */ -static inline void -sfc_adapter_lock_init (struct sfc_adapter *sa) -{ -rte_spinlock_init (&sa->lock); -} - -static inline int -sfc_adapter_is_locked (struct sfc_adapter *sa) -{ -return rte_spinlock_is_locked (&sa->lock); -} - -static inline void -sfc_adapter_lock (struct sfc_adapter *sa) -{ -rte_spinlock_lock (&sa->lock); -} - -static inline int -sfc_adapter_trylock (struct sfc_adapter *sa) -{ -return rte_spinlock_trylock (&sa->lock); -} - -static inline void -sfc_adapter_unlock (struct sfc_adapter *sa) -{ -rte_spinlock_unlock (&sa->lock); -} - -static inline void -sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa) -{ -/* Just for symmetry of the API */ -} +#define sfc_adapter_lock_init (sa) rte_spinlock_init(&(sa)->lock) +#define sfc_adapter_is_locked (sa) rte_spinlock_is_locked(&(sa)->lock) +#define sfc_adapter_lock (sa) rte_spinlock_lock(&(sa)->lock) +#define sfc_adapter_trylock (sa) rte_spinlock_trylock(&(sa)->lock) +#define sfc_adapter_unlock (sa) rte_spinlock_unlock(&(sa)->lock) +#define sfc_adapter_lock_fini (sa) RTE_SET_USED(sa)static inline unsigned int sfc_nb_counter_rxq (const struct sfc_adapter_shared *sas)
drivers/net/sfc/sfc_ev.c +4 -2
@@ -570,6 +570,8 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {void sfc_ev_qpoll (struct sfc_evq *evq) { +struct sfc_adapter *sa; +SFC_ASSERT (evq->init_state ==SFC_EVQ_STARTED || evq->init_state ==SFC_EVQ_STARTING );
@@ -577,8 +579,8 @@ sfc_ev_qpoll(struct sfc_evq *evq)efx_ev_qpoll (evq->common, &evq->read_ptr, evq->callbacks, evq); -if (unlikely (evq->exception) &&sfc_adapter_trylock (evq->sa)) { -struct sfc_adapter *sa = evq->sa; + sa = evq->sa; +if (unlikely (evq->exception) &&sfc_adapter_trylock (sa)) {int rc;if (evq->dp_rxq !=NULL ) {
drivers/net/sfc/sfc_repr.c +5 -33
@@ -112,39 +112,11 @@ sfc_repr_by_eth_dev(struct rte_eth_dev *eth_dev)* change the lock in one place. */ -static inline void -sfc_repr_lock_init (struct sfc_repr *sr) -{ -rte_spinlock_init (&sr->lock); -} - -#if defined(RTE_LIBRTE_SFC_EFX_DEBUG ) || defined(RTE_ENABLE_ASSERT ) - -static inline int -sfc_repr_lock_is_locked (struct sfc_repr *sr) -{ -return rte_spinlock_is_locked (&sr->lock); -} - -#endif - -static inline void -sfc_repr_lock (struct sfc_repr *sr) -{ -rte_spinlock_lock (&sr->lock); -} - -static inline void -sfc_repr_unlock (struct sfc_repr *sr) -{ -rte_spinlock_unlock (&sr->lock); -} - -static inline void -sfc_repr_lock_fini(__rte_unused struct sfc_repr *sr) -{ -/* Just for symmetry of the API */ -} +#define sfc_repr_lock_init (sr) rte_spinlock_init(&(sr)->lock) +#define sfc_repr_lock_is_locked (sr) rte_spinlock_is_locked(&(sr)->lock) +#define sfc_repr_lock (sr) rte_spinlock_lock(&(sr)->lock) +#define sfc_repr_unlock (sr) rte_spinlock_unlock(&(sr)->lock) +#define sfc_repr_lock_fini (sr) RTE_SET_USED(sr)static void sfc_repr_rx_queue_stop (void *queue)
Signature · 1 line
2.39.2
PATCH 11/14 net/virtio: annotate lock for guest announce
In reply to David MarchandExpose requirements for helpers dealing with the
VIRTIO_DEV_TO_HW(dev)->state_lock lock.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_ethdev.h | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -1149,11 +1149,11 @@ virtio_dev_pause(struct rte_eth_dev *dev) {struct virtio_hw *hw = dev->data->dev_private; -rte_spinlock_lock (&hw->state_lock); +rte_spinlock_lock (&VIRTIO_DEV_TO_HW (dev)->state_lock);if (hw->started ==0 ) {/* Device is just stopped. */ -rte_spinlock_unlock (&hw->state_lock); +rte_spinlock_unlock (&VIRTIO_DEV_TO_HW (dev)->state_lock);return -1 ; } hw->started =0 ;
@@ -1174,7 +1174,7 @@ virtio_dev_resume(struct rte_eth_dev *dev)struct virtio_hw *hw = dev->data->dev_private; hw->started =1 ; -rte_spinlock_unlock (&hw->state_lock); +rte_spinlock_unlock (&VIRTIO_DEV_TO_HW (dev)->state_lock); }/*
@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev) }/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +if (virtio_dev_pause (dev) !=0 ) {rte_pktmbuf_free (rarp_mbuf);return ; }
drivers/net/virtio/virtio_ethdev.h +5 -2
@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev); +#define VIRTIO_DEV_TO_HW (dev) ((struct virtio_hw *)(dev)->data->dev_private) +int virtio_dev_pause(struct rte_eth_dev *dev) + __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)->state_lock); +void virtio_dev_resume(struct rte_eth_dev *dev) + __rte_unlock_function(&VIRTIO_DEV_TO_HW(dev)->state_lock);int virtio_dev_stop (struct rte_eth_dev *dev);int virtio_dev_close (struct rte_eth_dev *dev); int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
Signature · 1 line
2.39.2
PATCH 12/14 raw/ifpga: inherit lock annotations
In reply to David MarchandThe checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
- dev->sd can't be NULL either as it would mean the application is calling those helpers for a dev pointer that did not pass initialisation,
Once the checks are removed, the only thing that remains is calls to the rte_spinlock API, so simply use macros and inherit annotations from the lock API.
--- drivers/raw/ifpga/afu_pmd_core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/raw/ifpga/afu_pmd_core.c +2 -15
@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];TAILQ_HEAD (afu_drv_list, afu_rawdev_drv);static struct afu_drv_list afu_pmd_list =TAILQ_HEAD_INITIALIZER (afu_pmd_list); -static inline int afu_rawdev_trylock (struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return 0 ; - -return rte_spinlock_trylock (&dev->sd->lock); -} - -static inline void afu_rawdev_unlock (struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return ; - -rte_spinlock_unlock (&dev->sd->lock); -} +#define afu_rawdev_trylock (dev) rte_spinlock_trylock(&dev->sd->lock) +#define afu_rawdev_unlock (dev) rte_spinlock_unlock(&dev->sd->lock)static int afu_rawdev_configure (const struct rte_rawdev *rawdev,rte_rawdev_obj_t config,size_t config_size)
Signature · 1 line
2.39.2
PATCH 13/14 vdpa/sfc: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
sfc_vdpa_ops.c was relying on an implicit cast of the dev_handle to a vdpa adapter object. Add an explicit conversion.
--- drivers/vdpa/sfc/sfc_vdpa.h | 41 +++++---------------------------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +++++------ 2 files changed, 13 insertions(+), 42 deletions(-)
drivers/vdpa/sfc/sfc_vdpa.h +6 -35
@@ -122,40 +122,11 @@ sfc_vdpa_adapter_by_dev_handle(void *dev_handle)* Add wrapper functions to acquire/release lock to be able to remove or * change the lock in one place. */ -static inline void -sfc_vdpa_adapter_lock_init (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_init (&sva->lock); -} - -static inline int -sfc_vdpa_adapter_is_locked (struct sfc_vdpa_adapter *sva) -{ -return rte_spinlock_is_locked (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_lock (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_lock (&sva->lock); -} - -static inline int -sfc_vdpa_adapter_trylock (struct sfc_vdpa_adapter *sva) -{ -return rte_spinlock_trylock (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_unlock (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_unlock (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva) -{ -/* Just for symmetry of the API */ -} +#define sfc_vdpa_adapter_lock_init (sva) rte_spinlock_init(&(sva)->lock) +#define sfc_vdpa_adapter_is_locked (sva) rte_spinlock_is_locked(&(sva)->lock) +#define sfc_vdpa_adapter_lock (sva) rte_spinlock_lock(&(sva)->lock) +#define sfc_vdpa_adapter_trylock (sva) rte_spinlock_trylock(&(sva)->lock) +#define sfc_vdpa_adapter_unlock (sva) rte_spinlock_unlock(&(sva)->lock) +#define sfc_vdpa_adapter_lock_fini (sva) RTE_SET_USED(sva)#endif /* _SFC_VDPA_H */
drivers/vdpa/sfc/sfc_vdpa_ops.c +7 -7
@@ -577,7 +577,7 @@ sfc_vdpa_notify_ctrl(void *arg)if (ops_data ==NULL )return NULL ; -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle)); vid = ops_data->vid;
@@ -586,7 +586,7 @@ sfc_vdpa_notify_ctrl(void *arg)"vDPA (%s): Notifier could not get configured" , ops_data->vdpa_dev->device->name); -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return NULL ; }
@@ -637,7 +637,7 @@ sfc_vdpa_dev_config(int vid) ops_data->vid = vid; -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));sfc_vdpa_log_init (ops_data->dev_handle,"configuring" ); rc =sfc_vdpa_configure (ops_data);
@@ -653,7 +653,7 @@ sfc_vdpa_dev_config(int vid)if (rc !=0 ) goto fail_vdpa_notify; -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));sfc_vdpa_log_init (ops_data->dev_handle,"done" );
@@ -666,7 +666,7 @@ sfc_vdpa_dev_config(int vid)sfc_vdpa_close (ops_data); fail_vdpa_config: -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return -1 ; }
@@ -688,7 +688,7 @@ sfc_vdpa_dev_close(int vid)return -1 ; } -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));if (ops_data->is_notify_thread_started == true) {void *status; ret =pthread_cancel (ops_data->notify_tid);
@@ -710,7 +710,7 @@ sfc_vdpa_dev_close(int vid)sfc_vdpa_stop (ops_data);sfc_vdpa_close (ops_data); -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return 0 ; }
Signature · 1 line
2.39.2
PATCH 14/14 enable lock check
In reply to David MarchandNow that a lot of components can be compiled with the lock checks, invert the logic and opt out for components not ready yet:
- drivers/bus/dpaa,
- drivers/common/cnxk,
- drivers/common/mlx5,
- drivers/event/cnxk,
- drivers/net/bnx2x,
- drivers/net/bnxt,
- drivers/net/cnxk,
- drivers/net/enic,
- drivers/net/hns3,
- drivers/net/mlx5,
- lib/ipsec,
- lib/timer,
--- doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++-- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/enic/meson.build | 1 + drivers/net/hns3/meson.build | 1 + drivers/net/mlx5/meson.build | 1 + lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 16 files changed, 17 insertions(+), 5 deletions(-)
doc/guides/prog_guide/env_abstraction_layer.rst +3 -2
@@ -550,8 +550,9 @@ Some general comments: waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please discuss it on the mailing list, -A DPDK library/driver can enable/disable the checks by setting -``annotate_locks`` accordingly in its ``meson.build`` file. +The checks are enabled by default for libraries and drivers. +They can be disabled by setting ``annotate_locks`` to ``false`` in +the concerned library/driver ``meson.build``. IOVA Mode Detection ~~~~~~~~~~~~~~~~~~~
drivers/bus/dpaa/meson.build +1 -0
@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith') endif includes += include_directories('include', 'base/qbman') +annotate_locks = false
drivers/common/cnxk/meson.build +1 -0
@@ -88,3 +88,4 @@ sources += files('cnxk_telemetry_bphy.c', deps += ['bus_pci', 'net', 'telemetry'] pmd_supports_disable_iova_as_pa = true +annotate_locks = false
drivers/common/mlx5/meson.build +1 -0
@@ -40,3 +40,4 @@ endif mlx5_config = configuration_data() subdir(exec_env) configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config) +annotate_locks = false
drivers/event/cnxk/meson.build +1 -0
@@ -480,3 +480,4 @@ endforeach deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk'] pmd_supports_disable_iova_as_pa = true +annotate_locks = false
drivers/meson.build +1 -1
@@ -91,7 +91,7 @@ foreach subpath:subdirs build = true # set to false to disable, e.g. missing deps reason = '<unknown reason>' # set if build == false to explain name = drv - annotate_locks = false + annotate_locks = true sources = [] headers = [] driver_sdk_headers = [] # public headers included by drivers
drivers/net/bnx2x/meson.build +1 -0
@@ -21,3 +21,4 @@ sources = files( 'ecore_sp.c', 'elink.c', ) +annotate_locks = false
drivers/net/bnxt/meson.build +1 -0
@@ -68,3 +68,4 @@ if arch_subdir == 'x86' elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64') sources += files('bnxt_rxtx_vec_neon.c') endif +annotate_locks = false
drivers/net/cnxk/meson.build +1 -0
@@ -196,3 +196,4 @@ endforeach headers = files('rte_pmd_cnxk.h') pmd_supports_disable_iova_as_pa = true +annotate_locks = false
drivers/net/enic/meson.build +1 -0
@@ -39,3 +39,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64') c_args: [cflags, '-mavx2']) objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c') endif +annotate_locks = false
drivers/net/hns3/meson.build +1 -0
@@ -38,6 +38,7 @@ sources = files( 'hns3_common.c', 'hns3_dump.c', ) +annotate_locks = false deps += ['hash']
drivers/net/mlx5/meson.build +1 -0
@@ -79,3 +79,4 @@ testpmd_sources += files('mlx5_testpmd.c') subdir(exec_env) subdir('hws') +annotate_locks = false
lib/ipsec/meson.build +1 -0
@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c', headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h') +annotate_locks = false deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
lib/meson.build +1 -1
@@ -120,7 +120,7 @@ foreach l:libraries reason = '<unknown reason>' # set if build == false to explain why name = l use_function_versioning = false - annotate_locks = false + annotate_locks = true sources = [] headers = [] indirect_headers = [] # public headers not directly included by apps
lib/timer/meson.build +1 -0
@@ -3,3 +3,4 @@ sources = files('rte_timer.c') headers = files('rte_timer.h') +annotate_locks = false
lib/vhost/meson.build +0 -1
@@ -18,7 +18,6 @@ endif dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h')) cflags += '-fno-strict-aliasing' -annotate_locks = true sources = files( 'fd_man.c', 'iotlb.c',
Signature · 1 line
2.39.2
v2 cover Enable lock annotations on most libraries and drivers
In reply to David MarchandThis is a followup of the series that introduced lock annotations. I reworked and made annotations work in what seemed the easier cases. In most cases, I chose to convert inline wrappers around the EAL lock API to simple macro: I did not see much value in those wrappers and this is way simpler than adding __rte_*lock_function tags everywhere.
A list of libraries and drivers still need more work as their code have non obvious locks handling. For those components, the check is opted out.
I leave it to their respective maintainers to enable the checks later.
FreeBSD libc pthread API has lock annotations while Linux glibc has none.
We could simply disable the check on FreeBSD, but having this check, a few issues got raised in drivers that are built with FreeBSD. For now, I went with a simple #ifdef FreeBSD for pthread mutex related annotations in our code.
Maintainers, please review.
Signature · 89 lines
David Marchand Changes since v1: - annotate code relying on pthread mutexes for FreeBSD libc that put annotations on its pthread API, - annotate Windows alarm code, David Marchand (20): malloc: rework heap lock handling mem: rework malloc heap init mem: annotate shared memory config locks hash: annotate cuckoo hash lock graph: annotate graph lock drivers: inherit lock annotations for Intel drivers net/cxgbe: inherit lock annotations net/fm10k: annotate mailbox lock net/sfc: rework locking in proxy code net/sfc: inherit lock annotations net/virtio: annotate lock for guest announce raw/ifpga: inherit lock annotations vdpa/sfc: inherit lock annotations ipc: annotate pthread mutex ethdev: annotate pthread mutex net/failsafe: fix mutex locking net/failsafe: annotate pthread mutex net/hinic: annotate pthread mutex eal/windows: disable lock check on alarm code enable lock check .../prog_guide/env_abstraction_layer.rst | 5 +- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/iavf/iavf_osdep.h | 39 +---- drivers/common/iavf/iavf_prototype.h | 6 - drivers/common/idpf/base/idpf_osdep.h | 26 +--- drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/cxgbe/base/adapter.h | 35 +---- drivers/net/enic/meson.build | 1 + drivers/net/failsafe/failsafe_ether.c | 3 +- drivers/net/failsafe/failsafe_flow.c | 23 ++- drivers/net/failsafe/failsafe_ops.c | 142 +++++++++++++----- drivers/net/failsafe/failsafe_private.h | 6 + drivers/net/fm10k/fm10k_ethdev.c | 2 + drivers/net/hinic/base/hinic_compat.h | 6 + drivers/net/hns3/meson.build | 1 + drivers/net/i40e/base/i40e_osdep.h | 8 +- drivers/net/i40e/base/i40e_prototype.h | 5 - drivers/net/i40e/i40e_ethdev.c | 24 --- drivers/net/ice/base/ice_osdep.h | 26 +--- drivers/net/mlx5/meson.build | 1 + drivers/net/sfc/sfc.h | 41 +---- drivers/net/sfc/sfc_ev.c | 6 +- drivers/net/sfc/sfc_repr.c | 38 +---- drivers/net/sfc/sfc_repr_proxy.c | 59 ++++---- drivers/net/virtio/virtio_ethdev.c | 8 +- drivers/net/virtio/virtio_ethdev.h | 7 +- drivers/raw/ifpga/afu_pmd_core.c | 17 +-- drivers/vdpa/sfc/sfc_vdpa.h | 41 +---- drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +- lib/eal/common/eal_common_mcfg.c | 66 ++++---- lib/eal/common/eal_common_memory.c | 10 +- lib/eal/common/eal_common_proc.c | 3 + lib/eal/common/malloc_heap.c | 55 +++++-- lib/eal/common/malloc_heap.h | 3 + lib/eal/common/rte_malloc.c | 10 -- lib/eal/freebsd/eal.c | 13 ++ lib/eal/include/rte_eal_memconfig.h | 63 ++++++-- lib/eal/linux/eal.c | 13 ++ lib/eal/version.map | 4 + lib/eal/windows/eal.c | 13 ++ lib/eal/windows/eal_alarm.c | 2 + lib/ethdev/rte_flow.c | 8 + lib/graph/graph.c | 10 +- lib/graph/graph_private.h | 10 +- lib/hash/rte_cuckoo_hash.c | 8 + lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 55 files changed, 461 insertions(+), 434 deletions(-) -- 2.39.2
PATCH v2 1/20 malloc: rework heap lock handling
Move all heap->lock manipulation to malloc_heap.c to have a single location where to look at and make higher level code unaware of this locking constraint.
The destroy helper has been reworked to zero all the heap object but leave the lock untouched. The heap lock is then released through the standard API.
This makes the code less scary even though, at this point of its life, the heap object is probably referenced only by the caller.
--- lib/eal/common/malloc_heap.c | 45 +++++++++++++++++++++++++++--------- lib/eal/common/rte_malloc.c | 10 -------- 2 files changed, 34 insertions(+), 21 deletions(-)
lib/eal/common/malloc_heap.c +34 -11
@@ -1292,6 +1292,8 @@ int malloc_heap_add_external_memory(struct malloc_heap *heap, struct rte_memseg_list *msl) { + rte_spinlock_lock(&heap->lock); +/* erase contents of new memory */ memset (msl->base_va,0 , msl->len);
@@ -1308,6 +1310,11 @@ malloc_heap_add_external_memory(struct malloc_heap *heap,eal_memalloc_mem_event_notify (RTE_MEM_EVENT_ALLOC , msl->base_va, msl->len); +/* mark it as heap segment */ + msl->heap =1 ; + +rte_spinlock_unlock (&heap->lock); +return 0 ; }
@@ -1315,7 +1322,12 @@ int malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr, size_t len) { - struct malloc_elem *elem = heap->first; + struct malloc_elem *elem; +int ret =-1 ; + +rte_spinlock_lock (&heap->lock); + + elem = heap->first;/* find element with specified va address */ while (elem !=NULL && elem != va_addr) {
@@ -1323,20 +1335,24 @@ malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,/* stop if we've blown past our VA */ if (elem > (struct malloc_elem *)va_addr) { rte_errno =ENOENT ; -return -1 ; + goto out; } }/* check if element was found */ if (elem ==NULL || elem->msl->len != len) { rte_errno =ENOENT ; -return -1 ; + goto out; }/* if element's size is not equal to segment len, segment is busy */ if (elem->state ==ELEM_BUSY || elem->size != len) { rte_errno =EBUSY ; -return -1 ; + goto out; } -return destroy_elem (elem, len); + ret =destroy_elem (elem, len); + +out: +rte_spinlock_unlock (&heap->lock); +return ret; }int
@@ -1372,23 +1388,30 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name)int malloc_heap_destroy (struct malloc_heap *heap) { +int ret =-1 ; + +rte_spinlock_lock (&heap->lock); +if (heap->alloc_count !=0 ) {RTE_LOG (ERR ,EAL ,"Heap is still in use\n" ); rte_errno =EBUSY ; -return -1 ; + goto fail; }if (heap->first !=NULL || heap->last !=NULL ) {RTE_LOG (ERR ,EAL ,"Heap still contains memory segments\n" ); rte_errno =EBUSY ; -return -1 ; + goto fail; }if (heap->total_size !=0 )RTE_LOG (ERR ,EAL ,"Total size not zero, heap is likely corrupt\n" ); -/* after this, the lock will be dropped */ -memset (heap,0 ,sizeof (*heap)); - -return 0 ; +RTE_BUILD_BUG_ON (offsetof(struct malloc_heap , lock) !=0 ); +memset (RTE_PTR_ADD (heap,sizeof (heap->lock)),0 , +sizeof (*heap) -sizeof (heap->lock)); + ret =0 ; +fail: +rte_spinlock_unlock (&heap->lock); +return ret; }int
lib/eal/common/rte_malloc.c +0 -10
@@ -436,10 +436,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len, goto unlock; } -rte_spinlock_lock (&heap->lock); ret =malloc_heap_add_external_memory (heap, msl); - msl->heap =1 ;/* mark it as heap segment */ -rte_spinlock_unlock (&heap->lock); unlock:rte_mcfg_mem_write_unlock ();
@@ -482,9 +479,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len) goto unlock; } -rte_spinlock_lock (&heap->lock); ret =malloc_heap_remove_external_memory (heap, va_addr, len); -rte_spinlock_unlock (&heap->lock);if (ret !=0 ) goto unlock;
@@ -655,12 +650,7 @@ rte_malloc_heap_destroy(const char *heap_name) goto unlock; }/* sanity checks done, now we can destroy the heap */ -rte_spinlock_lock (&heap->lock); ret =malloc_heap_destroy (heap); - -/* if we failed, lock is still active */ -if (ret <0 ) -rte_spinlock_unlock (&heap->lock); unlock:rte_mcfg_mem_write_unlock ();
Signature · 1 line
2.39.2
PATCH v2 2/20 mem: rework malloc heap init
In reply to David Marchandrte_eal_memory_init() and rte_eal_malloc_heap_init() must be called in a common section taking rte_mcfg_mem_read_lock().
Split rte_eal_malloc_heap_init() in two so that the mem lock is taken in rte_eal_init() making lock checks trivial (once annotated in the next patch).
--- lib/eal/common/eal_common_memory.c | 10 +--------- lib/eal/common/malloc_heap.c | 10 ++++++---- lib/eal/common/malloc_heap.h | 3 +++ lib/eal/freebsd/eal.c | 13 +++++++++++++ lib/eal/linux/eal.c | 13 +++++++++++++ lib/eal/windows/eal.c | 13 +++++++++++++ 6 files changed, 49 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_memory.c +1 -9
@@ -1078,18 +1078,11 @@ rte_eal_memory_detach(void)int rte_eal_memory_init (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config;const struct internal_config *internal_conf =eal_get_internal_configuration (); -int retval; -RTE_LOG (DEBUG ,EAL ,"Setting up physically contiguous memory...\n" ); - -if (!mcfg) -return -1 ; -/* lock mem hotplug here, to prevent races while we init */ -rte_mcfg_mem_read_lock (); +RTE_LOG (DEBUG ,EAL ,"Setting up physically contiguous memory...\n" );if (rte_eal_memseg_init () <0 ) goto fail;
@@ -1108,7 +1101,6 @@ rte_eal_memory_init(void)return 0 ; fail: -rte_mcfg_mem_read_unlock ();return -1 ; }
lib/eal/common/malloc_heap.c +6 -4
@@ -1442,18 +1442,20 @@ rte_eal_malloc_heap_init(void) } } -if (register_mp_requests ()) {RTE_LOG (ERR ,EAL ,"Couldn't register malloc multiprocess actions\n" ); -rte_mcfg_mem_read_unlock ();return -1 ; } -/* unlock mem hotplug here. it's safe for primary as no requests can +return 0 ; +} + +int rte_eal_malloc_heap_populate (void ) +{ +/* mem hotplug is unlocked here. it's safe for primary as no requests can * even come before primary itself is fully initialized, and secondaries * do not need to initialize the heap. */ -rte_mcfg_mem_read_unlock ();/* secondary process does not need to initialize anything */ if (rte_eal_process_type () !=RTE_PROC_PRIMARY )
lib/eal/common/malloc_heap.h +3 -0
@@ -85,6 +85,9 @@ malloc_socket_to_heap_id(unsigned int socket_id);int rte_eal_malloc_heap_init (void ); +int +rte_eal_malloc_heap_populate (void ); +void rte_eal_malloc_heap_cleanup (void );
lib/eal/freebsd/eal.c +13 -0
@@ -26,6 +26,7 @@#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <rte_errno.h> #include <rte_per_lcore.h> #include <rte_lcore.h>
@@ -754,13 +755,25 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ; }if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
lib/eal/linux/eal.c +13 -0
@@ -30,6 +30,7 @@#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <rte_errno.h> #include <rte_lcore.h> #include <rte_service_component.h>
@@ -1197,7 +1198,10 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ;
@@ -1207,6 +1211,15 @@ rte_eal_init(int argc, char **argv)eal_hugedirs_unlock ();if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
lib/eal/windows/eal.c +13 -0
@@ -12,6 +12,7 @@#include <rte_debug.h> #include <rte_bus.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <eal_memcfg.h> #include <rte_errno.h> #include <rte_lcore.h>
@@ -387,13 +388,25 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ; }if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
Signature · 1 line
2.39.2
PATCH v2 3/20 mem: annotate shared memory config locks
In reply to David MarchandExpose internal locks via some internal accessors. Then annotate rte_mcfg_xxx_(read|write)_(|un)lock.
--- lib/eal/common/eal_common_mcfg.c | 66 +++++++++++++++++------------ lib/eal/include/rte_eal_memconfig.h | 63 +++++++++++++++++++++------ lib/eal/version.map | 4 ++ 3 files changed, 91 insertions(+), 42 deletions(-)
lib/eal/common/eal_common_mcfg.c +38 -28
@@ -69,102 +69,112 @@ eal_mcfg_update_from_internal(void) mcfg->version =RTE_VERSION ; } +rte_rwlock_t * +rte_mcfg_mem_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->memory_hotplug_lock; +} +void rte_mcfg_mem_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->memory_hotplug_lock); +rte_rwlock_read_lock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->memory_hotplug_lock); +rte_rwlock_read_unlock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->memory_hotplug_lock); +rte_rwlock_write_lock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->memory_hotplug_lock); +rte_rwlock_write_unlock (rte_mcfg_mem_get_lock ()); +} + +rte_rwlock_t * +rte_mcfg_tailq_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->qlock; }void rte_mcfg_tailq_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->qlock); +rte_rwlock_read_lock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->qlock); +rte_rwlock_read_unlock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->qlock); +rte_rwlock_write_lock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->qlock); +rte_rwlock_write_unlock (rte_mcfg_tailq_get_lock ()); +} + +rte_rwlock_t * +rte_mcfg_mempool_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->mplock; }void rte_mcfg_mempool_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->mplock); +rte_rwlock_read_lock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->mplock); +rte_rwlock_read_unlock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->mplock); +rte_rwlock_write_lock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->mplock); +rte_rwlock_write_unlock (rte_mcfg_mempool_get_lock ()); +} + +rte_spinlock_t * +rte_mcfg_timer_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->tlock; }void rte_mcfg_timer_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_spinlock_lock (&mcfg->tlock); +rte_spinlock_lock (rte_mcfg_timer_get_lock ()); }void rte_mcfg_timer_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_spinlock_unlock (&mcfg->tlock); +rte_spinlock_unlock (rte_mcfg_timer_get_lock ()); }bool
lib/eal/include/rte_eal_memconfig.h +49 -14
144 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -469,6 +469,10 @@ INTERNAL { rte_intr_vec_list_free; rte_intr_vec_list_index_get; rte_intr_vec_list_index_set; + rte_mcfg_mem_get_lock; + rte_mcfg_mempool_get_lock; + rte_mcfg_tailq_get_lock; + rte_mcfg_timer_get_lock; rte_mem_lock; rte_mem_map; rte_mem_page_size;
Signature · 1 line
2.39.2
PATCH v2 4/20 hash: annotate cuckoo hash lock
In reply to David Marchand__hash_rw_(reader|writer)_(|un)lock helpers take locks depending on conditions that are fixed at the rte_hash object initialisation. So we can tell clang that those helpers unconditionally take/release those locks (and waive the lock check on their implementation).
--- lib/hash/rte_cuckoo_hash.c | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/hash/rte_cuckoo_hash.c +8 -0
@@ -575,6 +575,8 @@ rte_hash_count(const struct rte_hash *h)/* Read write locks implemented using rte_rwlock */ static inline void __hash_rw_writer_lock (const struct rte_hash *h) + __rte_exclusive_lock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)rte_rwlock_write_lock_tm (h->readwrite_lock);
@@ -584,6 +586,8 @@ __hash_rw_writer_lock(const struct rte_hash *h)static inline void __hash_rw_reader_lock (const struct rte_hash *h) + __rte_shared_lock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)rte_rwlock_read_lock_tm (h->readwrite_lock);
@@ -593,6 +597,8 @@ __hash_rw_reader_lock(const struct rte_hash *h)static inline void __hash_rw_writer_unlock (const struct rte_hash *h) + __rte_unlock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)rte_rwlock_write_unlock_tm (h->readwrite_lock);
@@ -602,6 +608,8 @@ __hash_rw_writer_unlock(const struct rte_hash *h)static inline void __hash_rw_reader_unlock (const struct rte_hash *h) + __rte_unlock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)rte_rwlock_read_unlock_tm (h->readwrite_lock);
Signature · 1 line
2.39.2
PATCH v2 5/20 graph: annotate graph lock
In reply to David MarchandExport internal lock and annotate associated helper.
--- lib/graph/graph.c | 10 ++++++++-- lib/graph/graph_private.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
lib/graph/graph.c +8 -2
@@ -30,16 +30,22 @@ graph_list_head_get(void)return &graph_list; } +rte_spinlock_t * +graph_spinlock_get (void ) +{ +return &graph_lock; +} +void graph_spinlock_lock (void ) { -rte_spinlock_lock (&graph_lock); +rte_spinlock_lock (graph_spinlock_get ()); }void graph_spinlock_unlock (void ) { -rte_spinlock_unlock (&graph_lock); +rte_spinlock_unlock (graph_spinlock_get ()); } static int
lib/graph/graph_private.h +8 -2
@@ -10,6 +10,7 @@#include <rte_common.h> #include <rte_eal.h> +#include <rte_spinlock.h> #include "rte_graph.h" #include "rte_graph_worker.h"
@@ -148,20 +149,25 @@ STAILQ_HEAD(graph_head, graph);*/ struct graph_head *graph_list_head_get (void ); +rte_spinlock_t * +graph_spinlock_get (void ); +/* Lock functions */ /** * @internal * * Take a lock on the graph internal spin lock. */ -void graph_spinlock_lock (void ); +void graph_spinlock_lock(void) + __rte_exclusive_lock_function(graph_spinlock_get());/** * @internal * * Release a lock on the graph internal spin lock. */ -void graph_spinlock_unlock (void ); +void graph_spinlock_unlock(void) + __rte_unlock_function(graph_spinlock_get());/* Graph operations */ /**
Signature · 1 line
2.39.2
PATCH v2 6/20 drivers: inherit lock annotations for Intel drivers
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
--- drivers/common/iavf/iavf_osdep.h | 39 ++++++-------------------- drivers/common/iavf/iavf_prototype.h | 6 ---- drivers/common/idpf/base/idpf_osdep.h | 26 +++-------------- drivers/net/i40e/base/i40e_osdep.h | 8 +++--- drivers/net/i40e/base/i40e_prototype.h | 5 ---- drivers/net/i40e/i40e_ethdev.c | 24 ---------------- drivers/net/ice/base/ice_osdep.h | 26 +++-------------- 7 files changed, 20 insertions(+), 114 deletions(-)
drivers/common/iavf/iavf_osdep.h +8 -31
@@ -170,11 +170,6 @@ struct iavf_virt_mem {u32 size; } __rte_packed; -/* SW spinlock */ -struct iavf_spinlock { -rte_spinlock_t spinlock; -}; -#define iavf_allocate_dma_mem (h, m, unused, s, a) \ iavf_allocate_dma_mem_d(h, m, s, a)#define iavf_free_dma_mem (h, m) iavf_free_dma_mem_d(h, m)
@@ -182,32 +177,14 @@ struct iavf_spinlock {#define iavf_allocate_virt_mem (h, m, s) iavf_allocate_virt_mem_d(h, m, s)#define iavf_free_virt_mem (h, m) iavf_free_virt_mem_d(h, m) -static inline void -iavf_init_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -iavf_acquire_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -iavf_release_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp) -{ -} +/* SW spinlock */ +struct iavf_spinlock { +rte_spinlock_t spinlock; +}; -#define iavf_init_spinlock (_sp) iavf_init_spinlock_d(_sp) -#define iavf_acquire_spinlock (_sp) iavf_acquire_spinlock_d(_sp) -#define iavf_release_spinlock (_sp) iavf_release_spinlock_d(_sp) -#define iavf_destroy_spinlock (_sp) iavf_destroy_spinlock_d(_sp) +#define iavf_init_spinlock (sp) rte_spinlock_init(&(sp)->spinlock) +#define iavf_acquire_spinlock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define iavf_release_spinlock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define iavf_destroy_spinlock (sp) RTE_SET_USED(sp)#endif /* _IAVF_OSDEP_H_ */
drivers/common/iavf/iavf_prototype.h +0 -6
@@ -76,12 +76,6 @@ STATIC INLINE struct iavf_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)return iavf_ptype_lookup[ptype]; } -/* prototype for functions used for SW spinlocks */ -void iavf_init_spinlock (struct iavf_spinlock *sp); -void iavf_acquire_spinlock (struct iavf_spinlock *sp); -void iavf_release_spinlock (struct iavf_spinlock *sp); -void iavf_destroy_spinlock (struct iavf_spinlock *sp); -__rte_internal void iavf_vf_parse_hw_config(struct iavf_hw *hw,struct virtchnl_vf_resource *msg);
drivers/common/idpf/base/idpf_osdep.h +4 -22
@@ -210,28 +210,10 @@ struct idpf_lock {rte_spinlock_t spinlock; }; -static inline void -idpf_init_lock (struct idpf_lock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -idpf_acquire_lock (struct idpf_lock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -idpf_release_lock (struct idpf_lock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -idpf_destroy_lock(__rte_unused struct idpf_lock *sp) -{ -} +#define idpf_init_lock (sp) rte_spinlock_init(&(sp)->spinlock) +#define idpf_acquire_lock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define idpf_release_lock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define idpf_destroy_lock (sp) RTE_SET_USED(sp)struct idpf_hw ;
drivers/net/i40e/base/i40e_osdep.h +4 -4
@@ -215,10 +215,10 @@ struct i40e_spinlock {rte_spinlock_t spinlock; }; -#define i40e_init_spinlock (_sp) i40e_init_spinlock_d(_sp) -#define i40e_acquire_spinlock (_sp) i40e_acquire_spinlock_d(_sp) -#define i40e_release_spinlock (_sp) i40e_release_spinlock_d(_sp) -#define i40e_destroy_spinlock (_sp) i40e_destroy_spinlock_d(_sp) +#define i40e_init_spinlock (sp) rte_spinlock_init(&(sp)->spinlock) +#define i40e_acquire_spinlock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define i40e_release_spinlock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define i40e_destroy_spinlock (sp) RTE_SET_USED(sp)#define I40E_NTOHS (a) rte_be_to_cpu_16(a)#define I40E_NTOHL (a) rte_be_to_cpu_32(a)
drivers/net/i40e/base/i40e_prototype.h +0 -5
@@ -546,11 +546,6 @@ i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed) } }#endif /* PF_DRIVER */ -/* prototype for functions used for SW spinlocks */ -void i40e_init_spinlock (struct i40e_spinlock *sp); -void i40e_acquire_spinlock (struct i40e_spinlock *sp); -void i40e_release_spinlock (struct i40e_spinlock *sp); -void i40e_destroy_spinlock (struct i40e_spinlock *sp);/* i40e_common for VF drivers*/ void i40e_vf_parse_hw_config(struct i40e_hw *hw,
drivers/net/i40e/i40e_ethdev.c +0 -24
@@ -4622,30 +4622,6 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,return I40E_SUCCESS ; } -void -i40e_init_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -void -i40e_acquire_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -void -i40e_release_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -void -i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp) -{ -return ; -} -/** * Get the hardware capabilities, which will be parsed * and saved into struct i40e_hw.
drivers/net/ice/base/ice_osdep.h +4 -22
@@ -211,28 +211,10 @@ struct ice_lock {rte_spinlock_t spinlock; }; -static inline void -ice_init_lock (struct ice_lock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -ice_acquire_lock (struct ice_lock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -ice_release_lock (struct ice_lock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -ice_destroy_lock(__rte_unused struct ice_lock *sp) -{ -} +#define ice_init_lock (sp) rte_spinlock_init(&(sp)->spinlock) +#define ice_acquire_lock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define ice_release_lock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define ice_destroy_lock (sp) RTE_SET_USED(sp)struct ice_hw ;
Signature · 1 line
2.39.2
PATCH v2 7/20 net/cxgbe: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
--- drivers/net/cxgbe/base/adapter.h | 35 +++++++------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)
drivers/net/cxgbe/base/adapter.h +7 -28
@@ -351,28 +351,19 @@ struct adapter {* t4_os_rwlock_init - initialize rwlock * @lock: the rwlock */ -static inline void t4_os_rwlock_init (rte_rwlock_t *lock) -{ -rte_rwlock_init (lock); -} +#define t4_os_rwlock_init (lock) rte_rwlock_init(lock)/** * t4_os_write_lock - get a write lock * @lock: the rwlock */ -static inline void t4_os_write_lock (rte_rwlock_t *lock) -{ -rte_rwlock_write_lock (lock); -} +#define t4_os_write_lock (lock) rte_rwlock_write_lock(lock)/** * t4_os_write_unlock - unlock a write lock * @lock: the rwlock */ -static inline void t4_os_write_unlock (rte_rwlock_t *lock) -{ -rte_rwlock_write_unlock (lock); -} +#define t4_os_write_unlock (lock) rte_rwlock_write_unlock(lock)/** * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
@@ -678,37 +669,25 @@ static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,* t4_os_lock_init - initialize spinlock * @lock: the spinlock */ -static inline void t4_os_lock_init (rte_spinlock_t *lock) -{ -rte_spinlock_init (lock); -} +#define t4_os_lock_init (lock) rte_spinlock_init(lock)/** * t4_os_lock - spin until lock is acquired * @lock: the spinlock */ -static inline void t4_os_lock (rte_spinlock_t *lock) -{ -rte_spinlock_lock (lock); -} +#define t4_os_lock (lock) rte_spinlock_lock(lock)/** * t4_os_unlock - unlock a spinlock * @lock: the spinlock */ -static inline void t4_os_unlock (rte_spinlock_t *lock) -{ -rte_spinlock_unlock (lock); -} +#define t4_os_unlock (lock) rte_spinlock_unlock(lock)/** * t4_os_trylock - try to get a lock * @lock: the spinlock */ -static inline int t4_os_trylock (rte_spinlock_t *lock) -{ -return rte_spinlock_trylock (lock); -} +#define t4_os_trylock (lock) rte_spinlock_trylock(lock)/** * t4_os_init_list_head - initialize
Signature · 1 line
2.39.2
PATCH v2 8/20 net/fm10k: annotate mailbox lock
In reply to David MarchandExpose requirements for helpers dealing with theFM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back) lock.
--- drivers/net/fm10k/fm10k_ethdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/fm10k/fm10k_ethdev.c +2 -0
@@ -116,6 +116,7 @@ fm10k_mbx_initlock(struct fm10k_hw *hw)static void fm10k_mbx_lock (struct fm10k_hw *hw) + __rte_exclusive_lock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {while (!rte_spinlock_trylock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)))rte_delay_us (FM10K_MBXLOCK_DELAY_US );
@@ -123,6 +124,7 @@ fm10k_mbx_lock(struct fm10k_hw *hw)static void fm10k_mbx_unlock (struct fm10k_hw *hw) + __rte_unlock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {rte_spinlock_unlock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)); }
Signature · 1 line
2.39.2
PATCH v2 9/20 net/sfc: rework locking in proxy code
In reply to David MarchandRemove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id() now only resolves the sa object and sfc_adapter_(|un)lock() are added were necessary.
This will simplify lock checks later.
--- drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 29 deletions(-)
drivers/net/sfc/sfc_repr_proxy.c +30 -29
@@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id) dev = &rte_eth_devices[pf_port_id]; sa =sfc_adapter_by_eth_dev (dev); -sfc_adapter_lock (sa); -return sa; } -static void -sfc_put_adapter (struct sfc_adapter *sa) -{ -sfc_adapter_unlock (sa); -} -static struct sfc_repr_proxy_port *sfc_repr_proxy_find_port (struct sfc_repr_proxy *rp,uint16_t repr_id) {
@@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, }sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ;
@@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, fail_alloc_port: fail_port_exists:sfc_log_init (sa,"failed: %s" ,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; fail_port_remove: fail_no_port:sfc_log_init (sa,"failed: %s" ,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; } rxq = &port->rxq[queue_id];if (rp->dp_rxq[queue_id].mp !=NULL && rp->dp_rxq[queue_id].mp != mp) {sfc_err (sa,"multiple mempools per queue are not supported" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOTSUP ; }
@@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].ref_count++;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ; }
@@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].mp =NULL ;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa); }int
@@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }
@@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, *egress_mport = port->egress_mport;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ; }
@@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, txq->ring =NULL ;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa); }int
@@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) }sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ;
@@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) fail_not_found:sfc_err (sa,"failed to start repr %u proxy port: %s" , repr_id,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }if (!port->enabled) {sfc_log_init (sa,"repr %u proxy port is not started - skip" , repr_id); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)sfc_err (sa,"failed to stop representor proxy TxQ %u: %s" , repr_id,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; } }
@@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port->enabled = false;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa); port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port (repr_id=%u)" , __func__, repr_id); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }
@@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id, __func__, repr_id, rte_strerror(rc)); } -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
Signature · 1 line
2.39.2
PATCH v2 10/20 net/sfc: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
One additional change is required in sfc_ev_qpoll() so that clang does see the same lock is being manipulated.
--- drivers/net/sfc/sfc.h | 41 ++++++-------------------------------- drivers/net/sfc/sfc_ev.c | 6 ++++-- drivers/net/sfc/sfc_repr.c | 38 +++++------------------------------ 3 files changed, 15 insertions(+), 70 deletions(-)
drivers/net/sfc/sfc.h +6 -35
@@ -333,41 +333,12 @@ sfc_sa2shared(struct sfc_adapter *sa)* change the lock in one place. */ -static inline void -sfc_adapter_lock_init (struct sfc_adapter *sa) -{ -rte_spinlock_init (&sa->lock); -} - -static inline int -sfc_adapter_is_locked (struct sfc_adapter *sa) -{ -return rte_spinlock_is_locked (&sa->lock); -} - -static inline void -sfc_adapter_lock (struct sfc_adapter *sa) -{ -rte_spinlock_lock (&sa->lock); -} - -static inline int -sfc_adapter_trylock (struct sfc_adapter *sa) -{ -return rte_spinlock_trylock (&sa->lock); -} - -static inline void -sfc_adapter_unlock (struct sfc_adapter *sa) -{ -rte_spinlock_unlock (&sa->lock); -} - -static inline void -sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa) -{ -/* Just for symmetry of the API */ -} +#define sfc_adapter_lock_init (sa) rte_spinlock_init(&(sa)->lock) +#define sfc_adapter_is_locked (sa) rte_spinlock_is_locked(&(sa)->lock) +#define sfc_adapter_lock (sa) rte_spinlock_lock(&(sa)->lock) +#define sfc_adapter_trylock (sa) rte_spinlock_trylock(&(sa)->lock) +#define sfc_adapter_unlock (sa) rte_spinlock_unlock(&(sa)->lock) +#define sfc_adapter_lock_fini (sa) RTE_SET_USED(sa)static inline unsigned int sfc_nb_counter_rxq (const struct sfc_adapter_shared *sas)
drivers/net/sfc/sfc_ev.c +4 -2
@@ -570,6 +570,8 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {void sfc_ev_qpoll (struct sfc_evq *evq) { +struct sfc_adapter *sa; +SFC_ASSERT (evq->init_state ==SFC_EVQ_STARTED || evq->init_state ==SFC_EVQ_STARTING );
@@ -577,8 +579,8 @@ sfc_ev_qpoll(struct sfc_evq *evq)efx_ev_qpoll (evq->common, &evq->read_ptr, evq->callbacks, evq); -if (unlikely (evq->exception) &&sfc_adapter_trylock (evq->sa)) { -struct sfc_adapter *sa = evq->sa; + sa = evq->sa; +if (unlikely (evq->exception) &&sfc_adapter_trylock (sa)) {int rc;if (evq->dp_rxq !=NULL ) {
drivers/net/sfc/sfc_repr.c +5 -33
@@ -112,39 +112,11 @@ sfc_repr_by_eth_dev(struct rte_eth_dev *eth_dev)* change the lock in one place. */ -static inline void -sfc_repr_lock_init (struct sfc_repr *sr) -{ -rte_spinlock_init (&sr->lock); -} - -#if defined(RTE_LIBRTE_SFC_EFX_DEBUG ) || defined(RTE_ENABLE_ASSERT ) - -static inline int -sfc_repr_lock_is_locked (struct sfc_repr *sr) -{ -return rte_spinlock_is_locked (&sr->lock); -} - -#endif - -static inline void -sfc_repr_lock (struct sfc_repr *sr) -{ -rte_spinlock_lock (&sr->lock); -} - -static inline void -sfc_repr_unlock (struct sfc_repr *sr) -{ -rte_spinlock_unlock (&sr->lock); -} - -static inline void -sfc_repr_lock_fini(__rte_unused struct sfc_repr *sr) -{ -/* Just for symmetry of the API */ -} +#define sfc_repr_lock_init (sr) rte_spinlock_init(&(sr)->lock) +#define sfc_repr_lock_is_locked (sr) rte_spinlock_is_locked(&(sr)->lock) +#define sfc_repr_lock (sr) rte_spinlock_lock(&(sr)->lock) +#define sfc_repr_unlock (sr) rte_spinlock_unlock(&(sr)->lock) +#define sfc_repr_lock_fini (sr) RTE_SET_USED(sr)static void sfc_repr_rx_queue_stop (void *queue)
Signature · 1 line
2.39.2
PATCH v2 11/20 net/virtio: annotate lock for guest announce
In reply to David MarchandExpose requirements for helpers dealing with the
VIRTIO_DEV_TO_HW(dev)->state_lock lock.
--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_ethdev.h | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -4
@@ -1149,11 +1149,11 @@ virtio_dev_pause(struct rte_eth_dev *dev) {struct virtio_hw *hw = dev->data->dev_private; -rte_spinlock_lock (&hw->state_lock); +rte_spinlock_lock (&VIRTIO_DEV_TO_HW (dev)->state_lock);if (hw->started ==0 ) {/* Device is just stopped. */ -rte_spinlock_unlock (&hw->state_lock); +rte_spinlock_unlock (&VIRTIO_DEV_TO_HW (dev)->state_lock);return -1 ; } hw->started =0 ;
@@ -1174,7 +1174,7 @@ virtio_dev_resume(struct rte_eth_dev *dev)struct virtio_hw *hw = dev->data->dev_private; hw->started =1 ; -rte_spinlock_unlock (&hw->state_lock); +rte_spinlock_unlock (&VIRTIO_DEV_TO_HW (dev)->state_lock); }/*
@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev) }/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +if (virtio_dev_pause (dev) !=0 ) {rte_pktmbuf_free (rarp_mbuf);return ; }
drivers/net/virtio/virtio_ethdev.h +5 -2
@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev); +#define VIRTIO_DEV_TO_HW (dev) ((struct virtio_hw *)(dev)->data->dev_private) +int virtio_dev_pause(struct rte_eth_dev *dev) + __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)->state_lock); +void virtio_dev_resume(struct rte_eth_dev *dev) + __rte_unlock_function(&VIRTIO_DEV_TO_HW(dev)->state_lock);int virtio_dev_stop (struct rte_eth_dev *dev);int virtio_dev_close (struct rte_eth_dev *dev); int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
Signature · 1 line
2.39.2
RE: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
Hi David,
Quoted 60 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, February 24, 2023 11:12 PM
To: [email protected]
Cc: [email protected]; Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Subject: [PATCH v2 11/20] net/virtio: annotate lock for guest announceExpose requirements for helpers dealing with the
VIRTIO_DEV_TO_HW(dev)->state_lock lock.Signed-off-by David Marchand <[email protected]>--- drivers/net/virtio/virtio_ethdev.c | 8 ++++---- drivers/net/virtio/virtio_ethdev.h | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-)drivers/net/virtio/virtio_ethdev.c +4
-4@@ -1149,11 +1149,11 @@ virtio_dev_pause(struct rte_eth_dev *dev) {struct virtio_hw *hw = dev->data->dev_private; -rte_spinlock_lock (&hw->state_lock); +rte_spinlock_lock (&VIRTIO_DEV_TO_HW (dev)->state_lock);if (hw->started ==0 ) {/* Device is just stopped. */ -rte_spinlock_unlock (&hw->state_lock); +rte_spinlock_unlock (&VIRTIO_DEV_TO_HW (dev)->state_lock);return -1 ; } hw->started =0 ;@@ -1174,7 +1174,7 @@ virtio_dev_resume(struct rte_eth_dev *dev)struct virtio_hw *hw = dev->data->dev_private; hw->started =1 ; -rte_spinlock_unlock (&hw->state_lock); +rte_spinlock_unlock (&VIRTIO_DEV_TO_HW (dev)->state_lock); }/* @@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev) }/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +if (virtio_dev_pause (dev) !=0 ) {rte_pktmbuf_free (rarp_mbuf);return ; }drivers/net/virtio/virtio_ethdev.h +0
-0
drivers/net/virtio/virtio_ethdev.h int eth_virtio_dev_init(struct rte_eth_dev *eth_dev); · line 119
Quoted 10 lines
drivers/net/virtio/virtio_ethdev.h +3
-2@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev); +#define VIRTIO_DEV_TO_HW (dev) ((struct virtio_hw *)(dev)->data- >dev_private) +int virtio_dev_pause(struct rte_eth_dev *dev) + __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)- >state_lock);
Just curious, why this is trylock instead of lock?
Thanks,
Chenbo
Quoted 7 lines
drivers/net/virtio/virtio_ethdev.h +2
-0+void virtio_dev_resume(struct rte_eth_dev *dev) + __rte_unlock_function(&VIRTIO_DEV_TO_HW(dev)->state_lock);int virtio_dev_stop (struct rte_eth_dev *dev);int
virtio_dev_close(struct rte_eth_dev *dev);
int virtio_inject_pkts(structrte_eth_dev*dev, structrte_mbuf**tx_pkts,
--
2.39.2
Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
Hello Chenbo,
Adding Maxime too.
Quoted 21 lines · Chenbo
Quoted 21 lines
drivers/net/virtio/virtio_ethdev.c +1
-1@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev) }/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +if (virtio_dev_pause (dev) !=0 ) {rte_pktmbuf_free (rarp_mbuf);return ; }drivers/net/virtio/virtio_ethdev.h +1
-2@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev); +#define VIRTIO_DEV_TO_HW (dev) ((struct virtio_hw *)(dev)->data-
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.h int eth_virtio_dev_init(struct rte_eth_dev *eth_dev); · line 119
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +2
-0>dev_private) +int virtio_dev_pause(struct rte_eth_dev *dev) + __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)- >state_lock);Just curious, why this is trylock instead of lock?
I wrote this patch some time ago.
At the time, I must say that I preferred removing those helpers (the only caller is virtio_notify_peers()).
It seems those helpers were added as a kind of api for future usecases, it seemed a reason for keeping them.
So I changed my mind and just annotated them.
For your question, annotating with "lock" would tell clang that the function always takes the lock, regardless of the function return value.
One alternative to this patch could be to always take the lock (+annotate dev_pause as "lock"), and have the caller release the lock if != 0 return value.
But it seems counterintuitive to me.
WDYT?
Signature · 1 line
David Marchand
Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
Hi,
Quoted 45 lines · David Marchand
Hello Chenbo,
Adding Maxime too.
Quoted 21 lines · Chenbo
Quoted 21 lines
(quoted diff) +1
-1@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev) } /* If virtio port just stopped, no need to send RARP */ - if (virtio_dev_pause(dev) < 0) { + if (virtio_dev_pause(dev) != 0) { rte_pktmbuf_free(rarp_mbuf); return; }drivers/net/virtio/virtio_ethdev.h +1
-2@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev); +#define VIRTIO_DEV_TO_HW (dev) ((struct virtio_hw *)(dev)->data-Quoted 6 lines
drivers/net/virtio/virtio_ethdev.h int eth_virtio_dev_init(struct rte_eth_dev *eth_dev); · line 119
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +2
-0> dev_private) +int virtio_dev_pause(struct rte_eth_dev *dev) + __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)- > state_lock);Just curious, why this is trylock instead of lock?
I wrote this patch some time ago.
At the time, I must say that I preferred removing those helpers (the only caller isvirtio_notify_peers()).
It seems those helpers were added as a kind of api for future usecases, it seemed a reason for keeping them.
So I changed my mind and just annotated them.For your question, annotating with "lock" would tell clang that the function always takes the lock, regardless of the function return value.
Quoted 8 lines
One alternative to this patch could be to always take the lock (+annotate
dev_pauseas "lock"), and have the caller release the lock if != 0 return value.
But it seems counterintuitive to me.WDYT?
As discussed with David off-list, I think we could simplify and inline virtio_dev_pause()/virtio_dev_resume() into virtio_notify_peers() since there are no other users of these functions (see below).
Any objection?
drivers/net/virtio/virtio_ethdev.c +16 -38
@@ -1144,43 +1144,10 @@ virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features)return 0 ; } -int -virtio_dev_pause (struct rte_eth_dev *dev) -{ -struct virtio_hw *hw = dev->data->dev_private; - -rte_spinlock_lock (&hw->state_lock); - -if (hw->started ==0 ) { -/* Device is just stopped. */ -rte_spinlock_unlock (&hw->state_lock); -return -1 ; - } - hw->started =0 ; -/* -* Prevent the worker threads from touching queues to avoid contention, -* 1 ms should be enough for the ongoing Tx function to finish. -*/ -rte_delay_ms (1 ); -return 0 ; -} - -/* -* Recover hw state to let the worker threads continue. -*/ -void -virtio_dev_resume (struct rte_eth_dev *dev) -{ -struct virtio_hw *hw = dev->data->dev_private; - - hw->started =1 ; -rte_spinlock_unlock (&hw->state_lock); -} -/* * Should be called only after device is paused. */ -int +static int virtio_inject_pkts (struct rte_eth_dev *dev,struct rte_mbuf **tx_pkts,int nb_pkts) {
@@ -1216,14 +1183,25 @@ virtio_notify_peers(struct rte_eth_dev *dev)return ; } -/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +rte_spinlock_lock (&hw->state_lock); + +if (hw->started ==0 ) { +/* If virtio port just stopped, no need to send RARP */ rte_pktmbuf_free (rarp_mbuf); -return ; + goto out_unlock; } +/* +* Prevent the worker threads from touching queues to avoid contention, +* 1 ms should be enough for the ongoing Tx function to finish. +*/ +rte_delay_ms (1 ); +virtio_inject_pkts (dev, &rarp_mbuf,1 ); -virtio_dev_resume (dev); + hw->started =1 ; + +out_unlock: +rte_spinlock_unlock (&hw->state_lock); } static void
drivers/net/virtio/virtio_ethdev.h +0 -4
@@ -112,12 +112,8 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev);int virtio_dev_stop (struct rte_eth_dev *dev);int virtio_dev_close (struct rte_eth_dev *dev); -int virtio_inject_pkts (struct rte_eth_dev *dev,struct rte_mbuf **tx_pkts, -int nb_pkts); bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t
rx_buf_size,
bool rx_scatter_enabled, const char **error);
RE: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
Hi David & Maxime,
Quoted 66 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, February 28, 2023 12:28 AM
To: David Marchand <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announceHi,
Quoted 8 lines · David Marchand
Hello Chenbo,
Adding Maxime too.
Quoted 3 lines · Chenbo
Quoted 3 lines
(quoted diff) +0
-0@@ -1217,7 +1217,7 @@ virtio_notify_peers(struct rte_eth_dev *dev) }Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +1
-1/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +if (virtio_dev_pause (dev) !=0 ) {rte_pktmbuf_free (rarp_mbuf);Quoted 8 lines
drivers/net/virtio/virtio_ethdev.h int eth_virtio_dev_init(struct rte_eth_dev
Quoted 8 lines
(quoted diff) +0
-0return; }drivers/net/virtio/virtio_ethdev.h +0
-0@@ -112,8 +112,11 @@ int eth_virtio_dev_init(struct rte_eth_dev
*eth_dev);Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/virtio/virtio_ethdev.h +1
-2void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev); +#define VIRTIO_DEV_TO_HW (dev) ((struct virtio_hw *)(dev)->data-Quoted 6 lines
drivers/net/virtio/virtio_ethdev.h int eth_virtio_dev_init(struct rte_eth_dev · line 118
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.h +2
-0> dev_private) +int virtio_dev_pause(struct rte_eth_dev *dev) + __rte_exclusive_trylock_function(0, &VIRTIO_DEV_TO_HW(dev)- > state_lock);Just curious, why this is trylock instead of lock?
I wrote this patch some time ago.
At the time, I must say that I preferred removing those helpers (the only caller isvirtio_notify_peers()).
It seems those helpers were added as a kind of api for future usecases, it seemed a reason for keeping them.
So I changed my mind and just annotated them.For your question, annotating with "lock" would tell clang that the function always takes the lock, regardless of the function return value.
Quoted 8 lines
One alternative to this patch could be to always take the lock (+annotate
dev_pauseas "lock"), and have the caller release the lock if != 0 return value.
But it seems counterintuitive to me.WDYT?
Quoted 5 lines
As discussed with David off-list, I think we could simplify and inline virtio_dev_pause()/virtio_dev_resume() into
virtio_notify_peers()since there are no other users of these functions (see below).Any objection?
This LGTM, it makes things easier..
Thanks,
Chenbo
Quoted 103 lines
drivers/net/virtio/virtio_ethdev.c +1
-34@@ -1144,43 +1144,10 @@ virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features) return 0; } -int -virtio_dev_pause (struct rte_eth_dev *dev) -{ -struct virtio_hw *hw = dev->data->dev_private; - -rte_spinlock_lock (&hw->state_lock); - -if (hw->started ==0 ) { -/* Device is just stopped. */ -rte_spinlock_unlock (&hw->state_lock); -return -1 ; - } - hw->started =0 ; -/* -* Prevent the worker threads from touching queues to avoid contention, -* 1 ms should be enough for the ongoing Tx function to finish. -*/ -rte_delay_ms (1 ); -return 0 ; -} - -/* -* Recover hw state to let the worker threads continue. -*/ -void -virtio_dev_resume (struct rte_eth_dev *dev) -{ -struct virtio_hw *hw = dev->data->dev_private; - - hw->started =1 ; -rte_spinlock_unlock (&hw->state_lock); -} -/* * Should be called only after device is paused. */ -int +static int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,int
nb_pkts)
{drivers/net/virtio/virtio_ethdev.c +15
-4@@ -1216,14 +1183,25 @@ virtio_notify_peers(struct rte_eth_dev *dev)return ; } -/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +rte_spinlock_lock (&hw->state_lock); + +if (hw->started ==0 ) { +/* If virtio port just stopped, no need to send RARP */ rte_pktmbuf_free (rarp_mbuf); -return ; + goto out_unlock; } +/* +* Prevent the worker threads from touching queues to avoid contention, +* 1 ms should be enough for the ongoing Tx function to finish. +*/ +rte_delay_ms (1 ); +virtio_inject_pkts (dev, &rarp_mbuf,1 ); -virtio_dev_resume (dev); + hw->started =1 ; + +out_unlock: +rte_spinlock_unlock (&hw->state_lock); }static void
drivers/net/virtio/virtio_ethdev.h +0
-4@@ -112,12 +112,8 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev);int virtio_dev_stop (struct rte_eth_dev *dev);int virtio_dev_close (struct rte_eth_dev *dev); -int virtio_inject_pkts (struct rte_eth_dev *dev,struct rte_mbuf **tx_pkts, -int nb_pkts); bool virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,bool rx_scatter_enabled, const char **error);
Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
In reply to Maxime CoquelinQuoted 3 lines · Maxime Coquelin
As discussed with David off-list, I think we could simplify and inline virtio_dev_pause()/virtio_dev_resume() into
virtio_notify_peers()since there are no other users of these functions (see below).
I was looking at doing this and, as we discussed offlist, realised what the "inject" code was doing.
I don't like the idea of keeping virtio_inject_pkts as a helper. This is tightly linked to the hw->started + usleep() trick, and this code has no check about its requirement on hw->started == 0. I'd rather "inline" and remove this helper too.
As a second step, I wrote a fix using an additional lock per txq to remove this usleep() thing.
Though I think it is too late to consider merging this new change in the release.
WDYT?
Signature · 1 line
David Marchand
Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
Quoted 6 lines · David Marchand
Quoted 3 lines · Maxime Coquelin
As discussed with David off-list, I think we could simplify and inline virtio_dev_pause()/virtio_dev_resume() into
virtio_notify_peers()since there are no other users of these functions (see below).
Quoted 7 lines
I was looking at doing this and, as we discussed offlist, realised what the "inject" code was doing.
I don't like the idea of keeping
virtio_inject_pktsas a helper. This is tightly linked to thehw->started+usleep()trick, and this code has no check about its requirement onhw->started== 0. I'd rather "inline" and remove this helper too.
Makes sense, do you want to submit it or are you willing me to do it?
Quoted 5 lines
As a second step, I wrote a fix using an additional lock per txq to remove this
usleep()thing.
Though I think it is too late to consider merging this new change in the release.
WDYT?
I agree this is too late for this release. Let's try this for v23.07.
Thanks,
Maxime
Re: [PATCH v2 11/20] net/virtio: annotate lock for guest announce
Quoted 10 lines · Maxime Coquelin
Quoted 9 lines · David Marchand
Quoted 3 lines · Maxime Coquelin
As discussed with David off-list, I think we could simplify and inline virtio_dev_pause()/virtio_dev_resume() into
virtio_notify_peers()since there are no other users of these functions (see below).I was looking at doing this and, as we discussed offlist, realised what the "inject" code was doing.
Quoted 6 lines
Quoted 4 lines
I don't like the idea of keeping
virtio_inject_pktsas a helper. This is tightly linked to thehw->started+usleep()trick, and this code has no check about its requirement onhw->started== 0. I'd rather "inline" and remove this helper too.Makes sense, do you want to submit it or are you willing me to do it?
I'll handle it, either during this release, or the next one. This code has always been ugly, this can wait one more release.
Signature · 1 line
David Marchand
PATCH v2 12/20 raw/ifpga: inherit lock annotations
In reply to David MarchandThe checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
- dev->sd can't be NULL either as it would mean the application is calling those helpers for a dev pointer that did not pass initialisation,
Once the checks are removed, the only thing that remains is calls to the rte_spinlock API, so simply use macros and inherit annotations from the lock API.
--- drivers/raw/ifpga/afu_pmd_core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/raw/ifpga/afu_pmd_core.c +2 -15
@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];TAILQ_HEAD (afu_drv_list, afu_rawdev_drv);static struct afu_drv_list afu_pmd_list =TAILQ_HEAD_INITIALIZER (afu_pmd_list); -static inline int afu_rawdev_trylock (struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return 0 ; - -return rte_spinlock_trylock (&dev->sd->lock); -} - -static inline void afu_rawdev_unlock (struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return ; - -rte_spinlock_unlock (&dev->sd->lock); -} +#define afu_rawdev_trylock (dev) rte_spinlock_trylock(&dev->sd->lock) +#define afu_rawdev_unlock (dev) rte_spinlock_unlock(&dev->sd->lock)static int afu_rawdev_configure (const struct rte_rawdev *rawdev,rte_rawdev_obj_t config,size_t config_size)
Signature · 1 line
2.39.2
RE: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
Hi,
Quoted 51 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, February 24, 2023 11:12 PM
To: [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>
Subject: [PATCH v2 12/20] raw/ifpga: inherit lock annotationsThe checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
-dev->sdcan't be NULL either as it would mean the application is calling those helpers for a dev pointer that did not pass initialisation,Once the checks are removed, the only thing that remains is calls to the
rte_spinlockAPI, so simply use macros and inherit annotations from the lock API.Signed-off-by David Marchand <[email protected]>--- drivers/raw/ifpga/afu_pmd_core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)drivers/raw/ifpga/afu_pmd_core.c +2
-14@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS +1 ];TAILQ_HEAD (afu_drv_list, afu_rawdev_drv);static struct afu_drv_list afu_pmd_list =TAILQ_HEAD_INITIALIZER (afu_pmd_list); -static inline int afu_rawdev_trylock(struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return 0 ; - -return rte_spinlock_trylock (&dev->sd->lock); -} - -static inline void afu_rawdev_unlock(struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return ; - -rte_spinlock_unlock (&dev->sd->lock); -} +#define afu_rawdev_trylock (dev) rte_spinlock_trylock(&dev->sd->lock) +#define afu_rawdev_unlock (dev) rte_spinlock_unlock(&dev->sd->lock)static int afu_rawdev_configure (const struct rte_rawdev *rawdev,rte_rawdev_obj_t config,size_t config_size) --
Quoted 1 line
2.39.2
It looks good for me.
Huang, Wei
Reviewed-byRE: [PATCH v2 12/20] raw/ifpga: inherit lock annotations
Hi,
Quoted 58 lines
-----Original Message-----
From: Xu, Rosen <[email protected]>
Sent: Monday, February 27, 2023 14:29
To: David Marchand <[email protected]>; [email protected]
Cc: [email protected]; Zhang, Tianfei <[email protected]>; Huang, Wei <[email protected]>
Subject: RE: [PATCH v2 12/20] raw/ifpga: inherit lock annotationsHi,
Quoted 48 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, February 24, 2023 11:12 PM
To: [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>
Subject: [PATCH v2 12/20] raw/ifpga: inherit lock annotationsThe checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
-dev->sdcan't be NULL either as it would mean the application is calling those helpers for a dev pointer that did not pass initialisation,Once the checks are removed, the only thing that remains is calls to the
rte_spinlockAPI, so simply use macros and inherit annotations from the lock API.Signed-off-by David Marchand <[email protected]>--- drivers/raw/ifpga/afu_pmd_core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)drivers/raw/ifpga/afu_pmd_core.c +2
-13@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS +1 ];TAILQ_HEAD (afu_drv_list, afu_rawdev_drv);static struct afu_drv_list afu_pmd_list =TAILQ_HEAD_INITIALIZER (afu_pmd_list); -static inline int afu_rawdev_trylock(struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return 0 ; - -return rte_spinlock_trylock (&dev->sd->lock); -} - -static inline void afu_rawdev_unlock(struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return ; - -rte_spinlock_unlock (&dev->sd->lock); -} +#define afu_rawdev_trylock (dev) rte_spinlock_trylock(&dev->sd->lock) +#define afu_rawdev_unlock (dev) rte_spinlock_unlock(&dev->sd->lock)
Quoted 8 lines
Quoted 4 lines
drivers/raw/ifpga/afu_pmd_core.c +0
-1static int afu_rawdev_configure (const struct rte_rawdev *rawdev,rte_rawdev_obj_t config,size_t config_size) --2.39.2
It looks good for me.
Reviewed-by Rosen Xu <[email protected]>
Agree that pointer check is redundant, rte_spinlock API can be called directly.
PATCH v2 13/20 vdpa/sfc: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
sfc_vdpa_ops.c was relying on an implicit cast of the dev_handle to a vdpa adapter object. Add an explicit conversion.
--- drivers/vdpa/sfc/sfc_vdpa.h | 41 +++++---------------------------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +++++------ 2 files changed, 13 insertions(+), 42 deletions(-)
drivers/vdpa/sfc/sfc_vdpa.h +6 -35
@@ -122,40 +122,11 @@ sfc_vdpa_adapter_by_dev_handle(void *dev_handle)* Add wrapper functions to acquire/release lock to be able to remove or * change the lock in one place. */ -static inline void -sfc_vdpa_adapter_lock_init (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_init (&sva->lock); -} - -static inline int -sfc_vdpa_adapter_is_locked (struct sfc_vdpa_adapter *sva) -{ -return rte_spinlock_is_locked (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_lock (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_lock (&sva->lock); -} - -static inline int -sfc_vdpa_adapter_trylock (struct sfc_vdpa_adapter *sva) -{ -return rte_spinlock_trylock (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_unlock (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_unlock (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva) -{ -/* Just for symmetry of the API */ -} +#define sfc_vdpa_adapter_lock_init (sva) rte_spinlock_init(&(sva)->lock) +#define sfc_vdpa_adapter_is_locked (sva) rte_spinlock_is_locked(&(sva)->lock) +#define sfc_vdpa_adapter_lock (sva) rte_spinlock_lock(&(sva)->lock) +#define sfc_vdpa_adapter_trylock (sva) rte_spinlock_trylock(&(sva)->lock) +#define sfc_vdpa_adapter_unlock (sva) rte_spinlock_unlock(&(sva)->lock) +#define sfc_vdpa_adapter_lock_fini (sva) RTE_SET_USED(sva)#endif /* _SFC_VDPA_H */
drivers/vdpa/sfc/sfc_vdpa_ops.c +7 -7
@@ -577,7 +577,7 @@ sfc_vdpa_notify_ctrl(void *arg)if (ops_data ==NULL )return NULL ; -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle)); vid = ops_data->vid;
@@ -586,7 +586,7 @@ sfc_vdpa_notify_ctrl(void *arg)"vDPA (%s): Notifier could not get configured" , ops_data->vdpa_dev->device->name); -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return NULL ; }
@@ -637,7 +637,7 @@ sfc_vdpa_dev_config(int vid) ops_data->vid = vid; -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));sfc_vdpa_log_init (ops_data->dev_handle,"configuring" ); rc =sfc_vdpa_configure (ops_data);
@@ -653,7 +653,7 @@ sfc_vdpa_dev_config(int vid)if (rc !=0 ) goto fail_vdpa_notify; -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));sfc_vdpa_log_init (ops_data->dev_handle,"done" );
@@ -666,7 +666,7 @@ sfc_vdpa_dev_config(int vid)sfc_vdpa_close (ops_data); fail_vdpa_config: -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return -1 ; }
@@ -688,7 +688,7 @@ sfc_vdpa_dev_close(int vid)return -1 ; } -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));if (ops_data->is_notify_thread_started == true) {void *status; ret =pthread_cancel (ops_data->notify_tid);
@@ -710,7 +710,7 @@ sfc_vdpa_dev_close(int vid)sfc_vdpa_stop (ops_data);sfc_vdpa_close (ops_data); -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return 0 ; }
Signature · 1 line
2.39.2
PATCH v2 14/20 ipc: annotate pthread mutex
In reply to David Marchandpthread_cond_timedwait() requires pending_requests.lock being taken.
--- lib/eal/common/eal_common_proc.c | 3 +++ 1 file changed, 3 insertions(+)
lib/eal/common/eal_common_proc.c +3 -0
@@ -908,6 +908,9 @@ mp_request_async(const char *dst, struct rte_mp_msg *req,static int mp_request_sync (const char *dst,struct rte_mp_msg *req, struct rte_mp_reply *reply, const struct timespec *ts) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_exclusive_locks_required(pending_requests.lock) +#endif {int ret;pthread_condattr_t attr;
Signature · 1 line
2.39.2
PATCH v2 15/20 ethdev: annotate pthread mutex
In reply to David Marchandfts_enter/exit take mutexes depending on device flags set at initialisation.
Annotate those helpers and, since clang does not support conditional locking, waive the lock check on their implementation.
--- lib/ethdev/rte_flow.c | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/ethdev/rte_flow.c +8 -0
@@ -297,6 +297,10 @@ rte_flow_dynf_metadata_register(void)static inline void fts_enter(struct rte_eth_dev *dev) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_exclusive_lock_function(dev->data->flow_ops_mutex) + __rte_no_thread_safety_analysis +#endif {if (!(dev->data->dev_flags &RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE ))pthread_mutex_lock (&dev->data->flow_ops_mutex);
@@ -304,6 +308,10 @@ fts_enter(struct rte_eth_dev *dev)static inline void fts_exit(struct rte_eth_dev *dev) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_unlock_function(dev->data->flow_ops_mutex) + __rte_no_thread_safety_analysis +#endif {if (!(dev->data->dev_flags &RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE ))pthread_mutex_unlock (&dev->data->flow_ops_mutex);
Signature · 1 line
2.39.2
PATCH v2 16/20 net/failsafe: fix mutex locking
In reply to David MarchandThe pthread mutex API describes cases where locking might fail. Check fts_enter wrapper return code.
--- drivers/net/failsafe/failsafe_ether.c | 3 +- drivers/net/failsafe/failsafe_flow.c | 23 +++-- drivers/net/failsafe/failsafe_ops.c | 142 +++++++++++++++++++------- 3 files changed, 123 insertions(+), 45 deletions(-)
drivers/net/failsafe/failsafe_ether.c +2 -1
@@ -592,7 +592,8 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused, {struct sub_device *sdev = cb_arg; -fs_lock (fs_dev (sdev),0 ); +if (fs_lock (fs_dev (sdev),0 ) !=0 ) +return -1 ;/* Switch as soon as possible tx_dev. */ fs_switch_dev (fs_dev (sdev), sdev);/* Use safe bursts in any case. */
drivers/net/failsafe/failsafe_flow.c +16 -7
@@ -72,7 +72,9 @@ fs_flow_validate(struct rte_eth_dev *dev,uint8_t i;int ret; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {DEBUG ("Calling rte_flow_validate on sub_device %d" , i); ret = rte_flow_validate(PORT_ID(sdev),
@@ -99,7 +101,8 @@ fs_flow_create(struct rte_eth_dev *dev,struct rte_flow *flow;uint8_t i; -fs_lock (dev,0 ); +if (fs_lock (dev,0 ) !=0 ) +return NULL ; flow =fs_flow_allocate (attr, patterns, actions); FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { flow->flows[i] = rte_flow_create(PORT_ID(sdev),
@@ -137,8 +140,9 @@ fs_flow_destroy(struct rte_eth_dev *dev,ERROR ("Invalid flow" );return -EINVAL ; } - ret =0 ; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {int local_ret;
@@ -169,7 +173,9 @@ fs_flow_flush(struct rte_eth_dev *dev,uint8_t i;int ret; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {DEBUG ("Calling rte_flow_flush on sub_device %d" , i); ret =rte_flow_flush (PORT_ID (sdev), error);
@@ -197,7 +203,8 @@ fs_flow_query(struct rte_eth_dev *dev, {struct sub_device *sdev; -fs_lock (dev,0 ); +if (fs_lock (dev,0 ) !=0 ) +return -1 ; sdev =TX_SUBDEV (dev);if (sdev !=NULL ) { int ret = rte_flow_query(PORT_ID(sdev),
@@ -223,7 +230,9 @@ fs_flow_isolate(struct rte_eth_dev *dev,uint8_t i;int ret; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV(sdev, i, dev) {if (sdev->state <DEV_PROBED )continue ;
drivers/net/failsafe/failsafe_ops.c +105 -37
359 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v2 16/20] net/failsafe: fix mutex locking
Quoted 4 lines · David Marchand
The pthread mutex API describes cases where locking might fail. Check
fts_enterwrapper return code.Signed-off-by David Marchand <[email protected]>
Hello David,
Thanks for the fix,
Signature · 1 line
Gaetan Rivet
PATCH v2 17/20 net/failsafe: annotate pthread mutex
In reply to David MarchandAnnotate wrappers on top of the pthread mutex API.
--- drivers/net/failsafe/failsafe_private.h | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/failsafe/failsafe_private.h +6 -0
@@ -403,6 +403,9 @@ fs_dev(struct sub_device *sdev) {*/ static inline int fs_lock(struct rte_eth_dev *dev, unsigned int is_alarm) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_exclusive_trylock_function(0, PRIV(dev)->hotplug_mutex) +#endif {int ret;
@@ -430,6 +433,9 @@ fs_lock(struct rte_eth_dev *dev, unsigned int is_alarm)*/ static inline void fs_unlock(struct rte_eth_dev *dev, unsigned int is_alarm) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_unlock_function(PRIV(dev)->hotplug_mutex) +#endif {int ret;
Signature · 1 line
2.39.2
PATCH v2 18/20 net/hinic: annotate pthread mutex
In reply to David MarchandAnnotate wrappers on top of the pthread mutex API.
--- drivers/net/hinic/base/hinic_compat.h | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/hinic/base/hinic_compat.h +6 -0
@@ -224,6 +224,9 @@ static inline int hinic_mutex_destroy(pthread_mutex_t *pthreadmutex) } static inline int hinic_mutex_lock(pthread_mutex_t *pthreadmutex) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_exclusive_trylock_function(0, *pthreadmutex) +#endif {int err;struct timespec tout;
@@ -239,6 +242,9 @@ static inline int hinic_mutex_lock(pthread_mutex_t *pthreadmutex) } static inline int hinic_mutex_unlock(pthread_mutex_t *pthreadmutex) +#ifdef RTE_EXEC_ENV_FREEBSD + __rte_unlock_function(*pthreadmutex) +#endif {return pthread_mutex_unlock (pthreadmutex); }
Signature · 1 line
2.39.2
PATCH v2 19/20 eal/windows: disable lock check on alarm code
In reply to David MarchandThis code uses locks to implement synchronisation between two threads. There seems nothing wrong with it, just silence the clang lock check.
--- lib/eal/windows/eal_alarm.c | 2 ++ 1 file changed, 2 insertions(+)
lib/eal/windows/eal_alarm.c +2 -0
@@ -224,6 +224,7 @@ struct intr_task {static void intr_thread_entry (void *arg) + __rte_no_thread_safety_analysis {struct intr_task *task = arg; task->func (task->arg);
@@ -232,6 +233,7 @@ intr_thread_entry(void *arg)static int intr_thread_exec_sync (void (*func)(void *arg),void *arg) + __rte_no_thread_safety_analysis {struct intr_task task;int ret;
Signature · 1 line
2.39.2
PATCH v2 20/20 enable lock check
In reply to David MarchandNow that a lot of components can be compiled with the lock checks, invert the logic and opt out for components not ready yet:
- drivers/bus/dpaa,
- drivers/common/cnxk,
- drivers/common/mlx5,
- drivers/event/cnxk,
- drivers/net/bnx2x,
- drivers/net/bnxt,
- drivers/net/cnxk,
- drivers/net/enic,
- drivers/net/hns3,
- drivers/net/mlx5,
- lib/ipsec,
- lib/timer,
--- doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++-- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/enic/meson.build | 1 + drivers/net/hns3/meson.build | 1 + drivers/net/mlx5/meson.build | 1 + lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 16 files changed, 17 insertions(+), 5 deletions(-)
doc/guides/prog_guide/env_abstraction_layer.rst +3 -2
@@ -550,8 +550,9 @@ Some general comments: waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please discuss it on the mailing list, -A DPDK library/driver can enable/disable the checks by setting -``annotate_locks`` accordingly in its ``meson.build`` file. +The checks are enabled by default for libraries and drivers. +They can be disabled by setting ``annotate_locks`` to ``false`` in +the concerned library/driver ``meson.build``. IOVA Mode Detection ~~~~~~~~~~~~~~~~~~~
drivers/bus/dpaa/meson.build +1 -0
@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith') endif includes += include_directories('include', 'base/qbman') +annotate_locks = false
drivers/common/cnxk/meson.build +1 -0
@@ -88,3 +88,4 @@ sources += files('cnxk_telemetry_bphy.c', deps += ['bus_pci', 'net', 'telemetry'] pmd_supports_disable_iova_as_pa = true +annotate_locks = false
drivers/common/mlx5/meson.build +1 -0
@@ -40,3 +40,4 @@ endif mlx5_config = configuration_data() subdir(exec_env) configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config) +annotate_locks = false
drivers/event/cnxk/meson.build +1 -0
@@ -480,3 +480,4 @@ endforeach deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk'] pmd_supports_disable_iova_as_pa = true +annotate_locks = false
drivers/meson.build +1 -1
@@ -91,7 +91,7 @@ foreach subpath:subdirs build = true # set to false to disable, e.g. missing deps reason = '<unknown reason>' # set if build == false to explain name = drv - annotate_locks = false + annotate_locks = true sources = [] headers = [] driver_sdk_headers = [] # public headers included by drivers
drivers/net/bnx2x/meson.build +1 -0
@@ -21,3 +21,4 @@ sources = files( 'ecore_sp.c', 'elink.c', ) +annotate_locks = false
drivers/net/bnxt/meson.build +1 -0
@@ -68,3 +68,4 @@ if arch_subdir == 'x86' elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64') sources += files('bnxt_rxtx_vec_neon.c') endif +annotate_locks = false
drivers/net/cnxk/meson.build +1 -0
@@ -196,3 +196,4 @@ endforeach headers = files('rte_pmd_cnxk.h') pmd_supports_disable_iova_as_pa = true +annotate_locks = false
drivers/net/enic/meson.build +1 -0
@@ -39,3 +39,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64') c_args: [cflags, '-mavx2']) objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c') endif +annotate_locks = false
drivers/net/hns3/meson.build +1 -0
@@ -38,6 +38,7 @@ sources = files( 'hns3_common.c', 'hns3_dump.c', ) +annotate_locks = false deps += ['hash']
drivers/net/mlx5/meson.build +1 -0
@@ -79,3 +79,4 @@ testpmd_sources += files('mlx5_testpmd.c') subdir(exec_env) subdir('hws') +annotate_locks = false
lib/ipsec/meson.build +1 -0
@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c', headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h') +annotate_locks = false deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
lib/meson.build +1 -1
@@ -120,7 +120,7 @@ foreach l:libraries reason = '<unknown reason>' # set if build == false to explain why name = l use_function_versioning = false - annotate_locks = false + annotate_locks = true sources = [] headers = [] indirect_headers = [] # public headers not directly included by apps
lib/timer/meson.build +1 -0
@@ -3,3 +3,4 @@ sources = files('rte_timer.c') headers = files('rte_timer.h') +annotate_locks = false
lib/vhost/meson.build +0 -1
@@ -18,7 +18,6 @@ endif dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h')) cflags += '-fno-strict-aliasing' -annotate_locks = true sources = files( 'fd_man.c', 'iotlb.c',
Signature · 1 line
2.39.2
RE: [PATCH v2 20/20] enable lock check
Quoted 231 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, February 24, 2023 11:12 PM
To: [email protected]
Cc: [email protected]; Burakov, Anatoly <[email protected]>; Hemant Agrawal <[email protected]>; Sachin Saxena <[email protected]>; Nithin Dabilpuram <[email protected]>; Kiran Kumar K <[email protected]>; Sunil Kumar Kori <[email protected]>; Satha Rao <[email protected]>; Matan Azrad <[email protected]>; Viacheslav Ovsiienko <[email protected]>; Pavan Nikhilesh <[email protected]>; Shijith Thotton <[email protected]>; Rasesh Mody <[email protected]>; Shahed Shaikh <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; Daley, John <[email protected]>; Hyong Youb Kim <[email protected]>; Dongdong Liu <[email protected]>; Yisen Zhuang <[email protected]>; Konstantin Ananyev <[email protected]>; Medvedkin, Vladimir <[email protected]>; Carrillo, Erik G <[email protected]>; Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Subject: [PATCH v2 20/20] enable lock checkNow that a lot of components can be compiled with the lock checks, invert the logic and opt out for components not ready yet:
-drivers/bus/dpaa,
-drivers/common/cnxk,
-drivers/common/mlx5,
-drivers/event/cnxk,
-drivers/net/bnx2x,
-drivers/net/bnxt,
-drivers/net/cnxk,
-drivers/net/enic,
-drivers/net/hns3,
-drivers/net/mlx5,
- lib/ipsec,
- lib/timer,Signed-off-by David Marchand <[email protected]>--- doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++-- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/enic/meson.build | 1 + drivers/net/hns3/meson.build | 1 + drivers/net/mlx5/meson.build | 1 + lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 16 files changed, 17 insertions(+), 5 deletions(-)doc/guides/prog_guide/env_abstraction_layer.rst +0
-0@@ -550,8 +550,9 @@ Some general comments: waiving checks with ``__rte_no_thread_safety_analysis`` in your code,please
discuss it on the mailing list,doc/guides/prog_guide/env_abstraction_layer.rst +3
-2-A DPDK library/driver can enable/disable the checks by setting -``annotate_locks`` accordingly in its ``meson.build`` file. +The checks are enabled by default for libraries and drivers. +They can be disabled by setting ``annotate_locks`` to ``false`` in +the concerned library/driver ``meson.build``. IOVA Mode Detection ~~~~~~~~~~~~~~~~~~~drivers/bus/dpaa/meson.build +1
-0@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith') endif includes += include_directories('include', 'base/qbman') +annotate_locks = falsedrivers/common/cnxk/meson.build +1
-0@@ -88,3 +88,4 @@ sources += files('cnxk_telemetry_bphy.c', deps += ['bus_pci', 'net', 'telemetry'] pmd_supports_disable_iova_as_pa = true +annotate_locks = falsedrivers/common/mlx5/meson.build +1
-0@@ -40,3 +40,4 @@ endif mlx5_config = configuration_data() subdir(exec_env) configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config) +annotate_locks = falsedrivers/event/cnxk/meson.build +1
-0@@ -480,3 +480,4 @@ endforeach deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk'] pmd_supports_disable_iova_as_pa = true +annotate_locks = falsedrivers/meson.build +1
-1@@ -91,7 +91,7 @@ foreach subpath:subdirs build = true # set to false to disable, e.g. missing deps reason = '<unknown reason>' # set if build == false to explain name = drv - annotate_locks = false + annotate_locks = true sources = [] headers = [] driver_sdk_headers = [] # public headers included by driversdrivers/net/bnx2x/meson.build +1
-0@@ -21,3 +21,4 @@ sources = files( 'ecore_sp.c', 'elink.c', ) +annotate_locks = falsedrivers/net/bnxt/meson.build +1
-0@@ -68,3 +68,4 @@ if arch_subdir == 'x86' elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64') sources += files('bnxt_rxtx_vec_neon.c') endif +annotate_locks = falsedrivers/net/cnxk/meson.build +1
-0@@ -196,3 +196,4 @@ endforeach headers = files('rte_pmd_cnxk.h') pmd_supports_disable_iova_as_pa = true +annotate_locks = falsedrivers/net/enic/meson.build +1
-0@@ -39,3 +39,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64') c_args: [cflags, '-mavx2']) objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c') endif +annotate_locks = falsedrivers/net/hns3/meson.build +1
-0@@ -38,6 +38,7 @@ sources = files( 'hns3_common.c', 'hns3_dump.c', ) +annotate_locks = false deps += ['hash']drivers/net/mlx5/meson.build +1
-0@@ -79,3 +79,4 @@ testpmd_sources += files('mlx5_testpmd.c') subdir(exec_env) subdir('hws') +annotate_locks = falselib/ipsec/meson.build +1
-0@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c', headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h') +annotate_locks = false deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']lib/meson.build +1
-1@@ -120,7 +120,7 @@ foreach l:libraries reason = '<unknown reason>' # set if build == false to explain why name = l use_function_versioning = false - annotate_locks = false + annotate_locks = true sources = [] headers = [] indirect_headers = [] # public headers not directly included by appslib/timer/meson.build +1
-0@@ -3,3 +3,4 @@ sources = files('rte_timer.c') headers = files('rte_timer.h') +annotate_locks = falselib/vhost/meson.build +0
-1@@ -18,7 +18,6 @@ endif dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h')) cflags += '-fno-strict-aliasing' -annotate_locks = true sources = files( 'fd_man.c','iotlb.c',
Quoted 2 lines
--
2.39.2
For lib/vhost:
Quoted 11 lines · David Marchand
This is a followup of the series that introduced lock annotations. I reworked and made annotations work in what seemed the easier cases. In most cases, I chose to convert inline wrappers around the EAL lock API to simple macro: I did not see much value in those wrappers and this is way simpler than adding __rte_*lock_function tags everywhere.
A list of libraries and drivers still need more work as their code have non obvious locks handling. For those components, the check is opted out.
I leave it to their respective maintainers to enable the checks later.
Quoted 7 lines
FreeBSD libc pthread API has lock annotations while Linux glibc has none.
We could simply disable the check on FreeBSD, but having this check, a few issues got raised in drivers that are built with FreeBSD. For now, I went with a simple #ifdef FreeBSD for pthread mutex related annotations in our code.
Hi David,
This is a great change, thanks for doing it.
However I am not sure I understand the logic regarding the '#ifdef FREEBSD'.
These annotations provide static hints to clang's thread safety analysis. What is the dependency on FreeBSD glibc?
Signature · 1 line
Gaetan Rivet
Salut Gaëtan,
Quoted 8 lines · Gaëtan Rivet
Quoted 7 lines
FreeBSD libc pthread API has lock annotations while Linux glibc has none.
We could simply disable the check on FreeBSD, but having this check, a few issues got raised in drivers that are built with FreeBSD. For now, I went with a simple #ifdef FreeBSD for pthread mutex related annotations in our code.
Quoted 7 lines
Hi David,
This is a great change, thanks for doing it.
However I am not sure I understand the logic regarding the '#ifdef FREEBSD'.These annotations provide static hints to clang's thread safety analysis. What is the dependency on FreeBSD glibc?
FreeBSD libc added clang annotations, while glibc did not.
FreeBSD 13.1 libc:
int pthread_mutex_lock(pthread_mutex_t * __mutex)
__locks_exclusive(*__mutex);
With:
#if __has_extension(c_thread_safety_attributes)
#define __lock_annotate(x) __attribute__((x))
#else
#define __lock_annotate(x)
#endif
/* Function acquires an exclusive or shared lock. */
#define __locks_exclusive(...) \
__lock_annotate(exclusive_lock_function(__VA_ARGS__))glibc:
extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
__THROWNL __nonnull ((1));
Since glibc does not declare that pthread_mutex_t is lockable, adding an annotation triggers an error for Linux (taking eal_common_proc.c patch 14 as an example):
../lib/eal/common/eal_common_proc.c:911:2: error:
'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'pthread_mutex_t' [-Werror,-Wthread-safety-attributes]
__rte_exclusive_locks_required(pending_requests.lock)
^
../lib/eal/include/rte_lock_annotations.h:23:17: note: expanded from
macro '__rte_exclusive_locks_required'
__attribute__((exclusive_locks_required(__VA_ARGS__)))
^We could wrap this annotation in a new construct (which would require some build time check wrt pthread API state).
Not sure it is worth the effort though, for now.
Signature · 1 line
David Marchand
Quoted 59 lines · David Marchand
Salut Gaëtan,
Quoted 8 lines · Gaëtan Rivet
Quoted 7 lines
FreeBSD libc pthread API has lock annotations while Linux glibc has none.
We could simply disable the check on FreeBSD, but having this check, a few issues got raised in drivers that are built with FreeBSD. For now, I went with a simple #ifdef FreeBSD for pthread mutex related annotations in our code.Quoted 7 lines
Hi David,
This is a great change, thanks for doing it.
However I am not sure I understand the logic regarding the '#ifdef FREEBSD'.These annotations provide static hints to clang's thread safety analysis. What is the dependency on FreeBSD glibc?
FreeBSD libc added clang annotations, while glibc did not.
FreeBSD 13.1 libc:
intpthread_mutex_lock(pthread_mutex_t * __mutex)__locks_exclusive(*__mutex);With:
#if
__has_extension(c_thread_safety_attributes)
#define__lock_annotate(x)__attribute__((x))
#else
#define__lock_annotate(x)
#endif/* Function acquires an exclusive or shared lock. */
#define __locks_exclusive(...) \ __lock_annotate(exclusive_lock_function(__VA_ARGS__))glibc:
extern intpthread_mutex_lock(pthread_mutex_t*__mutex)__THROWNL __nonnull ((1));Since glibc does not declare that
pthread_mutex_tis lockable, adding an annotation triggers an error for Linux (takingeal_common_proc.cpatch 14 as an example):
../lib/eal/common/eal_common_proc.c:911:2: error:
'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'pthread_mutex_t' [-Werror,-Wthread-safety-attributes]__rte_exclusive_locks_required(pending_requests.lock) ^ ../lib/eal/include/rte_lock_annotations.h:23:17: note: expanded from macro '__rte_exclusive_locks_required' __attribute__((exclusive_locks_required(__VA_ARGS__))) ^
Quoted 7 lines
We could wrap this annotation in a new construct (which would require some build time check wrt pthread API state).
Not sure it is worth the effort though, for now.Signature · 1 line
David Marchand
Ah ok, so if I understand correctly, DPDK would need to declare some '__rte_lockable rte_mutex' and associated functions for transparent support, to wrap above the pthread API.
Unless it happens, would it be possible to condition the thread-safety annotations to FREEBSD as well?
Maybe have two versions of the annotations:
__rte_exclusive_locks_required() /* Conditioned on clang */ __pthread_exclusive_locks_required() /* Conditioned on glibc/pthread support */
the first one to use on RTE types that can be declared with __rte_lockable, the second for pthread objects that we don't want to replace.
I know the namespace is not great so maybe named another way.
The '#ifdef FREEBSD' ossifies the annotation support at the function level, when this is a matter of types. This impedance mismatch would mean large changes if someone was to make this support evolve at some point.
Signature · 1 line
Gaetan Rivet
Quoted 3 lines · Gaëtan Rivet
Ah ok, so if I understand correctly, DPDK would need to declare some '
__rte_lockablerte_mutex' and associated functions for transparent support, to wrap above the pthread API.
Yes, this is what I had in mind for the mid/long term but it was too late for 23.03 after -rc1.
The Windows porting effort will probably need this abstraction too as we are trying to stop relying on the pthread API.
I don't see this item in Microsoft roadmap, though.
Quoted 9 lines
Unless it happens, would it be possible to condition the thread-safety annotations to FREEBSD as well?
Maybe have two versions of the annotations:
__rte_exclusive_locks_required()/* Conditioned on clang */__pthread_exclusive_locks_required()/* Conditioned on glibc/pthread support */
Quoted 7 lines
the first one to use on RTE types that can be declared with
__rte_lockable, the second for pthread objects that we don't want to replace.
I know the namespace is not great so maybe named another way.The '#ifdef FREEBSD' ossifies the annotation support at the function level, when this is a matter of types. This impedance mismatch would mean large changes if someone was to make this support evolve at some point.
I don't see how it requires large changes with the current approach. The patches in this series are a matter of lines.
If we come up with the right abstraction later, this uglyness will be removed.
In any case, I am running short of time for 23.03.
I am missing reviews from driver maintainers, which is a pity. Thomas raised an eyebrow on the malloc: and mem: patches too.
I will probably defer this series to the next release.
Signature · 1 line
David Marchand
Hello Tyler,
Quoted 11 lines · David Marchand
Quoted 3 lines · Gaëtan Rivet
Ah ok, so if I understand correctly, DPDK would need to declare some '
__rte_lockablerte_mutex' and associated functions for transparent support, to wrap above the pthread API.Yes, this is what I had in mind for the mid/long term but it was too late for 23.03 after -rc1.
The Windows porting effort will probably need this abstraction too as we are trying to stop relying on the pthread API.
I don't see this item in Microsoft roadmap, though.
Do you have an opinion on this topic?
Thanks.
Signature · 1 line
David Marchand
Quoted 8 lines · David Marchand
Hello Tyler,
Quoted 5 lines · David Marchand
Quoted 3 lines · Gaëtan Rivet
Ah ok, so if I understand correctly, DPDK would need to declare some '
__rte_lockablerte_mutex' and associated functions for transparent support, to wrap above the pthread API.
Quoted 8 lines
Quoted 6 lines
Yes, this is what I had in mind for the mid/long term but it was too late for 23.03 after -rc1.
The Windows porting effort will probably need this abstraction too as we are trying to stop relying on the pthread API.
I don't see this item in Microsoft roadmap, though.Do you have an opinion on this topic?
Sorry David I got distracted I'll review the thread again. I think with Windows toolsets we left off with expanding empty for now?
Anyway, I'll take another pass today if I get a chance.
Quoted 5 lines
Thanks.
Signature · 1 line
David Marchand
Quoted 8 lines · David Marchand
Hello Tyler,
Quoted 5 lines · David Marchand
Quoted 3 lines · Gaëtan Rivet
Ah ok, so if I understand correctly, DPDK would need to declare some '
__rte_lockablerte_mutex' and associated functions for transparent support, to wrap above the pthread API.
Quoted 8 lines
Quoted 6 lines
Yes, this is what I had in mind for the mid/long term but it was too late for 23.03 after -rc1.
The Windows porting effort will probably need this abstraction too as we are trying to stop relying on the pthread API.
I don't see this item in Microsoft roadmap, though.Do you have an opinion on this topic?
Okay, trying to grok the question here. If the question is do we want to introduce a mutex/condition variable and lock/unlock signal/wait abstraction?
I would certainly like to see reduced conditional compilation that applications have to perform for the platform features. I also really would like to purge the remaining pthread_{mutex,condvar} shim since it is unsightly.
With msvc I think we could probably achieve the same with C11 threads but I haven't investigated feasability and said with no investigation older glibc may not provide the optional feature.
In the absence of C11 threads we can provide an rte_ abstraction but I don't think I can put it on the roadmap until basic msvc support is stood up (a question of resource prioritization as always).
I could commit to looking at it once msvc and atomics changes are merged the earliest possible time frame for that is the start of the 23.11 cycle. If that happens at decent velocity I could even see adding it to 23.11 roadmap.
For now if someone else decides to introduce an abstraction I would just caution strongly not to remove __rte_experimental from any API added until I get a chance to focus on it.
ty
Quoted 5 lines
Thanks.
Signature · 1 line
David Marchand
Quoted 32 lines · Tyler Retzlaff
Quoted 8 lines · David Marchand
Hello Tyler,
Quoted 5 lines · David Marchand
Quoted 3 lines · Gaëtan Rivet
Ah ok, so if I understand correctly, DPDK would need to declare some '
__rte_lockablerte_mutex' and associated functions for transparent support, to wrap above the pthread API.Quoted 8 lines
Quoted 6 lines
Yes, this is what I had in mind for the mid/long term but it was too late for 23.03 after -rc1.
The Windows porting effort will probably need this abstraction too as we are trying to stop relying on the pthread API.
I don't see this item in Microsoft roadmap, though.Do you have an opinion on this topic?
Okay, trying to grok the question here. If the question is do we want to introduce a mutex/condition variable and lock/unlock signal/wait abstraction?
I would certainly like to see reduced conditional compilation that applications have to perform for the platform features. I also really would like to purge the remaining pthread_{mutex,condvar} shim since it is unsightly.
With msvc I think we could probably achieve the same with C11 threads but I haven't investigated feasability and said with no investigation older glibc may not provide the optional feature.
Quoted 8 lines
In the absence of C11 threads we can provide an
rte_abstraction but I don't think I can put it on the roadmap until basic msvc support is stood up (a question of resource prioritization as always).I could commit to looking at it once msvc and atomics changes are merged the earliest possible time frame for that is the start of the 23.11 cycle. If that happens at decent velocity I could even see adding it to 23.11 roadmap.
Ok for me.
Quoted 4 lines
For now if someone else decides to introduce an abstraction I would just caution strongly not to remove
__rte_experimentalfrom any API added until I get a chance to focus on it.
We *could* introduce an internal API.
But I prefer we wait for your input on this topic rather than introduce some artificial API.
I'll simply disable those checks on FreeBSD.
Signature · 1 line
David Marchand
v3 cover Enable lock annotations on most libraries and drivers
In reply to David MarchandThis is a followup of the series that introduced lock annotations. I reworked and made annotations work in what seemed the easier cases. In most cases, I chose to convert inline wrappers around the EAL lock API to simple macro: I did not see much value in those wrappers and this is way simpler than adding __rte_*lock_function tags everywhere.
A list of libraries and drivers still need more work as their code have non obvious locks handling. For those components, the check is opted out.
I leave it to their respective maintainers to enable the checks later.
FreeBSD libc pthread API has lock annotations while Linux glibc has none. Until we get a proper abstraction for mutexes, the simpler is to disable the check on FreeBSD.
Maintainers, please review.
Signature · 89 lines
David Marchand Changes since v2: - simplify malloc heap change, - rework virtio code, - disable check on FreeBSD when using pthread mutexes, Changes since v1: - annotate code relying on pthread mutexes for FreeBSD libc that put annotations on its pthread API, - annotate Windows alarm code, David Marchand (16): malloc: rework heap destroy mem: rework malloc heap init mem: annotate shared memory config locks hash: annotate cuckoo hash lock graph: annotate graph lock drivers: inherit lock annotations for Intel drivers net/cxgbe: inherit lock annotations net/fm10k: annotate mailbox lock net/sfc: rework locking in proxy code net/sfc: inherit lock annotations net/virtio: rework guest announce notify helper raw/ifpga: inherit lock annotations vdpa/sfc: inherit lock annotations net/failsafe: fix mutex locking eal/windows: disable lock check on alarm code enable lock check .../prog_guide/env_abstraction_layer.rst | 5 +- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/iavf/iavf_osdep.h | 39 +---- drivers/common/iavf/iavf_prototype.h | 6 - drivers/common/idpf/base/idpf_osdep.h | 26 +--- drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/cxgbe/base/adapter.h | 35 +---- drivers/net/enic/meson.build | 1 + drivers/net/failsafe/failsafe_ether.c | 3 +- drivers/net/failsafe/failsafe_flow.c | 23 ++- drivers/net/failsafe/failsafe_ops.c | 142 +++++++++++++----- drivers/net/failsafe/meson.build | 4 + drivers/net/fm10k/fm10k_ethdev.c | 2 + drivers/net/hinic/meson.build | 4 + drivers/net/hns3/meson.build | 1 + drivers/net/i40e/base/i40e_osdep.h | 8 +- drivers/net/i40e/base/i40e_prototype.h | 5 - drivers/net/i40e/i40e_ethdev.c | 24 --- drivers/net/ice/base/ice_osdep.h | 26 +--- drivers/net/mlx5/meson.build | 1 + drivers/net/sfc/sfc.h | 41 +---- drivers/net/sfc/sfc_ev.c | 6 +- drivers/net/sfc/sfc_repr.c | 38 +---- drivers/net/sfc/sfc_repr_proxy.c | 59 ++++---- drivers/net/virtio/virtio_ethdev.c | 75 +++------ drivers/net/virtio/virtio_ethdev.h | 4 - drivers/raw/ifpga/afu_pmd_core.c | 17 +-- drivers/vdpa/sfc/sfc_vdpa.h | 41 +---- drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +- lib/eal/common/eal_common_mcfg.c | 66 ++++---- lib/eal/common/eal_common_memory.c | 10 +- lib/eal/common/malloc_heap.c | 16 +- lib/eal/common/malloc_heap.h | 3 + lib/eal/common/rte_malloc.c | 5 +- lib/eal/freebsd/eal.c | 13 ++ lib/eal/include/rte_eal_memconfig.h | 63 ++++++-- lib/eal/linux/eal.c | 13 ++ lib/eal/meson.build | 4 + lib/eal/version.map | 4 + lib/eal/windows/eal.c | 13 ++ lib/eal/windows/eal_alarm.c | 2 + lib/ethdev/meson.build | 4 + lib/graph/graph.c | 10 +- lib/graph/graph_private.h | 10 +- lib/hash/rte_cuckoo_hash.c | 8 + lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 55 files changed, 435 insertions(+), 473 deletions(-) -- 2.39.2
PATCH v3 1/16 malloc: rework heap destroy
The destroy helper has been reworked to zero all the heap object but leave the lock untouched. The heap lock is then released through the standard API.
---
Changes since v2:
- shrinked the change to the required part,
--- lib/eal/common/malloc_heap.c | 6 ++++-- lib/eal/common/rte_malloc.c | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-)
lib/eal/common/malloc_heap.c +4 -2
@@ -1385,8 +1385,10 @@ malloc_heap_destroy(struct malloc_heap *heap)if (heap->total_size !=0 )RTE_LOG (ERR ,EAL ,"Total size not zero, heap is likely corrupt\n" ); -/* after this, the lock will be dropped */ -memset (heap,0 ,sizeof (*heap)); +/* Reset all of the heap but the (hold) lock so caller can release it. */ +RTE_BUILD_BUG_ON (offsetof(struct malloc_heap , lock) !=0 ); +memset (RTE_PTR_ADD (heap,sizeof (heap->lock)),0 , +sizeof (*heap) -sizeof (heap->lock));return 0 ; }
lib/eal/common/rte_malloc.c +1 -4
@@ -657,10 +657,7 @@ rte_malloc_heap_destroy(const char *heap_name)/* sanity checks done, now we can destroy the heap */ rte_spinlock_lock (&heap->lock); ret =malloc_heap_destroy (heap); - -/* if we failed, lock is still active */ -if (ret <0 ) -rte_spinlock_unlock (&heap->lock); +rte_spinlock_unlock (&heap->lock); unlock:rte_mcfg_mem_write_unlock ();
Signature · 1 line
2.39.2
PATCH v3 2/16 mem: rework malloc heap init
In reply to David Marchandrte_eal_memory_init() and rte_eal_malloc_heap_init() must be called in a common section taking rte_mcfg_mem_read_lock().
Split rte_eal_malloc_heap_init() in two so that the mem lock is taken in rte_eal_init() making lock checks trivial (once annotated in the next patch).
--- lib/eal/common/eal_common_memory.c | 10 +--------- lib/eal/common/malloc_heap.c | 10 ++++++---- lib/eal/common/malloc_heap.h | 3 +++ lib/eal/freebsd/eal.c | 13 +++++++++++++ lib/eal/linux/eal.c | 13 +++++++++++++ lib/eal/windows/eal.c | 13 +++++++++++++ 6 files changed, 49 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_memory.c +1 -9
@@ -1078,18 +1078,11 @@ rte_eal_memory_detach(void)int rte_eal_memory_init (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config;const struct internal_config *internal_conf =eal_get_internal_configuration (); -int retval; -RTE_LOG (DEBUG ,EAL ,"Setting up physically contiguous memory...\n" ); - -if (!mcfg) -return -1 ; -/* lock mem hotplug here, to prevent races while we init */ -rte_mcfg_mem_read_lock (); +RTE_LOG (DEBUG ,EAL ,"Setting up physically contiguous memory...\n" );if (rte_eal_memseg_init () <0 ) goto fail;
@@ -1108,7 +1101,6 @@ rte_eal_memory_init(void)return 0 ; fail: -rte_mcfg_mem_read_unlock ();return -1 ; }
lib/eal/common/malloc_heap.c +6 -4
@@ -1421,18 +1421,20 @@ rte_eal_malloc_heap_init(void) } } -if (register_mp_requests ()) {RTE_LOG (ERR ,EAL ,"Couldn't register malloc multiprocess actions\n" ); -rte_mcfg_mem_read_unlock ();return -1 ; } -/* unlock mem hotplug here. it's safe for primary as no requests can +return 0 ; +} + +int rte_eal_malloc_heap_populate (void ) +{ +/* mem hotplug is unlocked here. it's safe for primary as no requests can * even come before primary itself is fully initialized, and secondaries * do not need to initialize the heap. */ -rte_mcfg_mem_read_unlock ();/* secondary process does not need to initialize anything */ if (rte_eal_process_type () !=RTE_PROC_PRIMARY )
lib/eal/common/malloc_heap.h +3 -0
@@ -85,6 +85,9 @@ malloc_socket_to_heap_id(unsigned int socket_id);int rte_eal_malloc_heap_init (void ); +int +rte_eal_malloc_heap_populate (void ); +void rte_eal_malloc_heap_cleanup (void );
lib/eal/freebsd/eal.c +13 -0
@@ -26,6 +26,7 @@#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <rte_errno.h> #include <rte_per_lcore.h> #include <rte_lcore.h>
@@ -754,13 +755,25 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ; }if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
lib/eal/linux/eal.c +13 -0
@@ -30,6 +30,7 @@#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <rte_errno.h> #include <rte_lcore.h> #include <rte_service_component.h>
@@ -1193,7 +1194,10 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ;
@@ -1203,6 +1207,15 @@ rte_eal_init(int argc, char **argv)eal_hugedirs_unlock ();if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
lib/eal/windows/eal.c +13 -0
@@ -12,6 +12,7 @@#include <rte_debug.h> #include <rte_bus.h> #include <rte_eal.h> +#include <rte_eal_memconfig.h> #include <eal_memcfg.h> #include <rte_errno.h> #include <rte_lcore.h>
@@ -387,13 +388,25 @@ rte_eal_init(int argc, char **argv)return -1 ; } +rte_mcfg_mem_read_lock (); +if (rte_eal_memory_init () <0 ) { +rte_mcfg_mem_read_unlock ();rte_eal_init_alert ("Cannot init memory" ); rte_errno =ENOMEM ;return -1 ; }if (rte_eal_malloc_heap_init () <0 ) { +rte_mcfg_mem_read_unlock (); +rte_eal_init_alert ("Cannot init malloc heap" ); + rte_errno =ENODEV ; +return -1 ; + } + +rte_mcfg_mem_read_unlock (); + +if (rte_eal_malloc_heap_populate () <0 ) {rte_eal_init_alert ("Cannot init malloc heap" ); rte_errno =ENODEV ;return -1 ;
Signature · 1 line
2.39.2
PATCH v3 3/16 mem: annotate shared memory config locks
In reply to David MarchandExpose internal locks via some internal accessors. Then annotate rte_mcfg_xxx_(read|write)_(|un)lock.
--- lib/eal/common/eal_common_mcfg.c | 66 +++++++++++++++++------------ lib/eal/include/rte_eal_memconfig.h | 63 +++++++++++++++++++++------ lib/eal/version.map | 4 ++ 3 files changed, 91 insertions(+), 42 deletions(-)
lib/eal/common/eal_common_mcfg.c +38 -28
@@ -69,102 +69,112 @@ eal_mcfg_update_from_internal(void) mcfg->version =RTE_VERSION ; } +rte_rwlock_t * +rte_mcfg_mem_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->memory_hotplug_lock; +} +void rte_mcfg_mem_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->memory_hotplug_lock); +rte_rwlock_read_lock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->memory_hotplug_lock); +rte_rwlock_read_unlock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->memory_hotplug_lock); +rte_rwlock_write_lock (rte_mcfg_mem_get_lock ()); }void rte_mcfg_mem_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->memory_hotplug_lock); +rte_rwlock_write_unlock (rte_mcfg_mem_get_lock ()); +} + +rte_rwlock_t * +rte_mcfg_tailq_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->qlock; }void rte_mcfg_tailq_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->qlock); +rte_rwlock_read_lock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->qlock); +rte_rwlock_read_unlock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->qlock); +rte_rwlock_write_lock (rte_mcfg_tailq_get_lock ()); }void rte_mcfg_tailq_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->qlock); +rte_rwlock_write_unlock (rte_mcfg_tailq_get_lock ()); +} + +rte_rwlock_t * +rte_mcfg_mempool_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->mplock; }void rte_mcfg_mempool_read_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_lock (&mcfg->mplock); +rte_rwlock_read_lock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_read_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_read_unlock (&mcfg->mplock); +rte_rwlock_read_unlock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_write_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_lock (&mcfg->mplock); +rte_rwlock_write_lock (rte_mcfg_mempool_get_lock ()); }void rte_mcfg_mempool_write_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_rwlock_write_unlock (&mcfg->mplock); +rte_rwlock_write_unlock (rte_mcfg_mempool_get_lock ()); +} + +rte_spinlock_t * +rte_mcfg_timer_get_lock (void ) +{ +return &rte_eal_get_configuration ()->mem_config->tlock; }void rte_mcfg_timer_lock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_spinlock_lock (&mcfg->tlock); +rte_spinlock_lock (rte_mcfg_timer_get_lock ()); }void rte_mcfg_timer_unlock (void ) { -struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; -rte_spinlock_unlock (&mcfg->tlock); +rte_spinlock_unlock (rte_mcfg_timer_get_lock ()); }bool
lib/eal/include/rte_eal_memconfig.h +49 -14
144 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -469,6 +469,10 @@ INTERNAL { rte_intr_vec_list_free; rte_intr_vec_list_index_get; rte_intr_vec_list_index_set; + rte_mcfg_mem_get_lock; + rte_mcfg_mempool_get_lock; + rte_mcfg_tailq_get_lock; + rte_mcfg_timer_get_lock; rte_mem_lock; rte_mem_map; rte_mem_page_size;
Signature · 1 line
2.39.2
PATCH v3 4/16 hash: annotate cuckoo hash lock
In reply to David Marchand__hash_rw_(reader|writer)_(|un)lock helpers take locks depending on conditions that are fixed at the rte_hash object initialisation. So we can tell clang that those helpers unconditionally take/release those locks (and waive the lock check on their implementation).
--- lib/hash/rte_cuckoo_hash.c | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/hash/rte_cuckoo_hash.c +8 -0
@@ -575,6 +575,8 @@ rte_hash_count(const struct rte_hash *h)/* Read write locks implemented using rte_rwlock */ static inline void __hash_rw_writer_lock (const struct rte_hash *h) + __rte_exclusive_lock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)rte_rwlock_write_lock_tm (h->readwrite_lock);
@@ -584,6 +586,8 @@ __hash_rw_writer_lock(const struct rte_hash *h)static inline void __hash_rw_reader_lock (const struct rte_hash *h) + __rte_shared_lock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)rte_rwlock_read_lock_tm (h->readwrite_lock);
@@ -593,6 +597,8 @@ __hash_rw_reader_lock(const struct rte_hash *h)static inline void __hash_rw_writer_unlock (const struct rte_hash *h) + __rte_unlock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->writer_takes_lock && h->hw_trans_mem_support)rte_rwlock_write_unlock_tm (h->readwrite_lock);
@@ -602,6 +608,8 @@ __hash_rw_writer_unlock(const struct rte_hash *h)static inline void __hash_rw_reader_unlock (const struct rte_hash *h) + __rte_unlock_function(&h->readwrite_lock) + __rte_no_thread_safety_analysis {if (h->readwrite_concur_support && h->hw_trans_mem_support)rte_rwlock_read_unlock_tm (h->readwrite_lock);
Signature · 1 line
2.39.2
PATCH v3 5/16 graph: annotate graph lock
In reply to David MarchandExport internal lock and annotate associated helper.
--- lib/graph/graph.c | 10 ++++++++-- lib/graph/graph_private.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
lib/graph/graph.c +8 -2
@@ -30,16 +30,22 @@ graph_list_head_get(void)return &graph_list; } +rte_spinlock_t * +graph_spinlock_get (void ) +{ +return &graph_lock; +} +void graph_spinlock_lock (void ) { -rte_spinlock_lock (&graph_lock); +rte_spinlock_lock (graph_spinlock_get ()); }void graph_spinlock_unlock (void ) { -rte_spinlock_unlock (&graph_lock); +rte_spinlock_unlock (graph_spinlock_get ()); } static int
lib/graph/graph_private.h +8 -2
@@ -10,6 +10,7 @@#include <rte_common.h> #include <rte_eal.h> +#include <rte_spinlock.h> #include "rte_graph.h" #include "rte_graph_worker.h"
@@ -148,20 +149,25 @@ STAILQ_HEAD(graph_head, graph);*/ struct graph_head *graph_list_head_get (void ); +rte_spinlock_t * +graph_spinlock_get (void ); +/* Lock functions */ /** * @internal * * Take a lock on the graph internal spin lock. */ -void graph_spinlock_lock (void ); +void graph_spinlock_lock(void) + __rte_exclusive_lock_function(graph_spinlock_get());/** * @internal * * Release a lock on the graph internal spin lock. */ -void graph_spinlock_unlock (void ); +void graph_spinlock_unlock(void) + __rte_unlock_function(graph_spinlock_get());/* Graph operations */ /**
Signature · 1 line
2.39.2
PATCH v3 6/16 drivers: inherit lock annotations for Intel drivers
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
--- drivers/common/iavf/iavf_osdep.h | 39 ++++++-------------------- drivers/common/iavf/iavf_prototype.h | 6 ---- drivers/common/idpf/base/idpf_osdep.h | 26 +++-------------- drivers/net/i40e/base/i40e_osdep.h | 8 +++--- drivers/net/i40e/base/i40e_prototype.h | 5 ---- drivers/net/i40e/i40e_ethdev.c | 24 ---------------- drivers/net/ice/base/ice_osdep.h | 26 +++-------------- 7 files changed, 20 insertions(+), 114 deletions(-)
drivers/common/iavf/iavf_osdep.h +8 -31
@@ -170,11 +170,6 @@ struct iavf_virt_mem {u32 size; } __rte_packed; -/* SW spinlock */ -struct iavf_spinlock { -rte_spinlock_t spinlock; -}; -#define iavf_allocate_dma_mem (h, m, unused, s, a) \ iavf_allocate_dma_mem_d(h, m, s, a)#define iavf_free_dma_mem (h, m) iavf_free_dma_mem_d(h, m)
@@ -182,32 +177,14 @@ struct iavf_spinlock {#define iavf_allocate_virt_mem (h, m, s) iavf_allocate_virt_mem_d(h, m, s)#define iavf_free_virt_mem (h, m) iavf_free_virt_mem_d(h, m) -static inline void -iavf_init_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -iavf_acquire_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -iavf_release_spinlock_d (struct iavf_spinlock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -iavf_destroy_spinlock_d(__rte_unused struct iavf_spinlock *sp) -{ -} +/* SW spinlock */ +struct iavf_spinlock { +rte_spinlock_t spinlock; +}; -#define iavf_init_spinlock (_sp) iavf_init_spinlock_d(_sp) -#define iavf_acquire_spinlock (_sp) iavf_acquire_spinlock_d(_sp) -#define iavf_release_spinlock (_sp) iavf_release_spinlock_d(_sp) -#define iavf_destroy_spinlock (_sp) iavf_destroy_spinlock_d(_sp) +#define iavf_init_spinlock (sp) rte_spinlock_init(&(sp)->spinlock) +#define iavf_acquire_spinlock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define iavf_release_spinlock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define iavf_destroy_spinlock (sp) RTE_SET_USED(sp)#endif /* _IAVF_OSDEP_H_ */
drivers/common/iavf/iavf_prototype.h +0 -6
@@ -76,12 +76,6 @@ STATIC INLINE struct iavf_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)return iavf_ptype_lookup[ptype]; } -/* prototype for functions used for SW spinlocks */ -void iavf_init_spinlock (struct iavf_spinlock *sp); -void iavf_acquire_spinlock (struct iavf_spinlock *sp); -void iavf_release_spinlock (struct iavf_spinlock *sp); -void iavf_destroy_spinlock (struct iavf_spinlock *sp); -__rte_internal void iavf_vf_parse_hw_config(struct iavf_hw *hw,struct virtchnl_vf_resource *msg);
drivers/common/idpf/base/idpf_osdep.h +4 -22
@@ -210,28 +210,10 @@ struct idpf_lock {rte_spinlock_t spinlock; }; -static inline void -idpf_init_lock (struct idpf_lock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -idpf_acquire_lock (struct idpf_lock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -idpf_release_lock (struct idpf_lock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -idpf_destroy_lock(__rte_unused struct idpf_lock *sp) -{ -} +#define idpf_init_lock (sp) rte_spinlock_init(&(sp)->spinlock) +#define idpf_acquire_lock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define idpf_release_lock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define idpf_destroy_lock (sp) RTE_SET_USED(sp)struct idpf_hw ;
drivers/net/i40e/base/i40e_osdep.h +4 -4
@@ -215,10 +215,10 @@ struct i40e_spinlock {rte_spinlock_t spinlock; }; -#define i40e_init_spinlock (_sp) i40e_init_spinlock_d(_sp) -#define i40e_acquire_spinlock (_sp) i40e_acquire_spinlock_d(_sp) -#define i40e_release_spinlock (_sp) i40e_release_spinlock_d(_sp) -#define i40e_destroy_spinlock (_sp) i40e_destroy_spinlock_d(_sp) +#define i40e_init_spinlock (sp) rte_spinlock_init(&(sp)->spinlock) +#define i40e_acquire_spinlock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define i40e_release_spinlock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define i40e_destroy_spinlock (sp) RTE_SET_USED(sp)#define I40E_NTOHS (a) rte_be_to_cpu_16(a)#define I40E_NTOHL (a) rte_be_to_cpu_32(a)
drivers/net/i40e/base/i40e_prototype.h +0 -5
@@ -546,11 +546,6 @@ i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed) } }#endif /* PF_DRIVER */ -/* prototype for functions used for SW spinlocks */ -void i40e_init_spinlock (struct i40e_spinlock *sp); -void i40e_acquire_spinlock (struct i40e_spinlock *sp); -void i40e_release_spinlock (struct i40e_spinlock *sp); -void i40e_destroy_spinlock (struct i40e_spinlock *sp);/* i40e_common for VF drivers*/ void i40e_vf_parse_hw_config(struct i40e_hw *hw,
drivers/net/i40e/i40e_ethdev.c +0 -24
@@ -4635,30 +4635,6 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,return I40E_SUCCESS ; } -void -i40e_init_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -void -i40e_acquire_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -void -i40e_release_spinlock_d (struct i40e_spinlock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -void -i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp) -{ -return ; -} -/** * Get the hardware capabilities, which will be parsed * and saved into struct i40e_hw.
drivers/net/ice/base/ice_osdep.h +4 -22
@@ -211,28 +211,10 @@ struct ice_lock {rte_spinlock_t spinlock; }; -static inline void -ice_init_lock (struct ice_lock *sp) -{ -rte_spinlock_init (&sp->spinlock); -} - -static inline void -ice_acquire_lock (struct ice_lock *sp) -{ -rte_spinlock_lock (&sp->spinlock); -} - -static inline void -ice_release_lock (struct ice_lock *sp) -{ -rte_spinlock_unlock (&sp->spinlock); -} - -static inline void -ice_destroy_lock(__rte_unused struct ice_lock *sp) -{ -} +#define ice_init_lock (sp) rte_spinlock_init(&(sp)->spinlock) +#define ice_acquire_lock (sp) rte_spinlock_lock(&(sp)->spinlock) +#define ice_release_lock (sp) rte_spinlock_unlock(&(sp)->spinlock) +#define ice_destroy_lock (sp) RTE_SET_USED(sp)struct ice_hw ;
Signature · 1 line
2.39.2
PATCH v3 7/16 net/cxgbe: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
--- drivers/net/cxgbe/base/adapter.h | 35 +++++++------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)
drivers/net/cxgbe/base/adapter.h +7 -28
@@ -351,28 +351,19 @@ struct adapter {* t4_os_rwlock_init - initialize rwlock * @lock: the rwlock */ -static inline void t4_os_rwlock_init (rte_rwlock_t *lock) -{ -rte_rwlock_init (lock); -} +#define t4_os_rwlock_init (lock) rte_rwlock_init(lock)/** * t4_os_write_lock - get a write lock * @lock: the rwlock */ -static inline void t4_os_write_lock (rte_rwlock_t *lock) -{ -rte_rwlock_write_lock (lock); -} +#define t4_os_write_lock (lock) rte_rwlock_write_lock(lock)/** * t4_os_write_unlock - unlock a write lock * @lock: the rwlock */ -static inline void t4_os_write_unlock (rte_rwlock_t *lock) -{ -rte_rwlock_write_unlock (lock); -} +#define t4_os_write_unlock (lock) rte_rwlock_write_unlock(lock)/** * ethdev2pinfo - return the port_info structure associated with a rte_eth_dev
@@ -678,37 +669,25 @@ static inline void t4_os_set_hw_addr(struct adapter *adapter, int port_idx,* t4_os_lock_init - initialize spinlock * @lock: the spinlock */ -static inline void t4_os_lock_init (rte_spinlock_t *lock) -{ -rte_spinlock_init (lock); -} +#define t4_os_lock_init (lock) rte_spinlock_init(lock)/** * t4_os_lock - spin until lock is acquired * @lock: the spinlock */ -static inline void t4_os_lock (rte_spinlock_t *lock) -{ -rte_spinlock_lock (lock); -} +#define t4_os_lock (lock) rte_spinlock_lock(lock)/** * t4_os_unlock - unlock a spinlock * @lock: the spinlock */ -static inline void t4_os_unlock (rte_spinlock_t *lock) -{ -rte_spinlock_unlock (lock); -} +#define t4_os_unlock (lock) rte_spinlock_unlock(lock)/** * t4_os_trylock - try to get a lock * @lock: the spinlock */ -static inline int t4_os_trylock (rte_spinlock_t *lock) -{ -return rte_spinlock_trylock (lock); -} +#define t4_os_trylock (lock) rte_spinlock_trylock(lock)/** * t4_os_init_list_head - initialize
Signature · 1 line
2.39.2
PATCH v3 8/16 net/fm10k: annotate mailbox lock
In reply to David MarchandExpose requirements for helpers dealing with theFM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back) lock.
--- drivers/net/fm10k/fm10k_ethdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/fm10k/fm10k_ethdev.c +2 -0
@@ -116,6 +116,7 @@ fm10k_mbx_initlock(struct fm10k_hw *hw)static void fm10k_mbx_lock (struct fm10k_hw *hw) + __rte_exclusive_lock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {while (!rte_spinlock_trylock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)))rte_delay_us (FM10K_MBXLOCK_DELAY_US );
@@ -123,6 +124,7 @@ fm10k_mbx_lock(struct fm10k_hw *hw)static void fm10k_mbx_unlock (struct fm10k_hw *hw) + __rte_unlock_function(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)) {rte_spinlock_unlock (FM10K_DEV_PRIVATE_TO_MBXLOCK (hw->back)); }
Signature · 1 line
2.39.2
PATCH v3 9/16 net/sfc: rework locking in proxy code
In reply to David MarchandRemove one extra layer for proxy code: sfc_get_adapter_by_pf_port_id() now only resolves the sa object. sfc_adapter_(|un)lock() are added were necessary.
This will simplify lock checks later.
--- drivers/net/sfc/sfc_repr_proxy.c | 59 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 29 deletions(-)
drivers/net/sfc/sfc_repr_proxy.c +30 -29
@@ -51,17 +51,9 @@ sfc_get_adapter_by_pf_port_id(uint16_t pf_port_id) dev = &rte_eth_devices[pf_port_id]; sa =sfc_adapter_by_eth_dev (dev); -sfc_adapter_lock (sa); -return sa; } -static void -sfc_put_adapter (struct sfc_adapter *sa) -{ -sfc_adapter_unlock (sa); -} -static struct sfc_repr_proxy_port *sfc_repr_proxy_find_port (struct sfc_repr_proxy *rp,uint16_t repr_id) {
@@ -1289,6 +1281,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id,int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1341,7 +1334,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, }sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ;
@@ -1352,7 +1345,7 @@ sfc_repr_proxy_add_port(uint16_t pf_port_id, uint16_t repr_id, fail_alloc_port: fail_port_exists:sfc_log_init (sa,"failed: %s" ,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1366,6 +1359,7 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1393,14 +1387,14 @@ sfc_repr_proxy_del_port(uint16_t pf_port_id, uint16_t repr_id)sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; fail_port_remove: fail_no_port:sfc_log_init (sa,"failed: %s" ,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1416,6 +1410,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1423,14 +1418,14 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; } rxq = &port->rxq[queue_id];if (rp->dp_rxq[queue_id].mp !=NULL && rp->dp_rxq[queue_id].mp != mp) {sfc_err (sa,"multiple mempools per queue are not supported" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOTSUP ; }
@@ -1440,7 +1435,7 @@ sfc_repr_proxy_add_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].ref_count++;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1455,6 +1450,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1462,7 +1458,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ; }
@@ -1475,7 +1471,7 @@ sfc_repr_proxy_del_rxq(uint16_t pf_port_id, uint16_t repr_id, rp->dp_rxq[queue_id].mp =NULL ;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa); }int
@@ -1489,6 +1485,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1496,7 +1493,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }
@@ -1507,7 +1504,7 @@ sfc_repr_proxy_add_txq(uint16_t pf_port_id, uint16_t repr_id, *egress_mport = port->egress_mport;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1522,6 +1519,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id,struct sfc_adapter *sa; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1529,7 +1527,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ; }
@@ -1538,7 +1536,7 @@ sfc_repr_proxy_del_txq(uint16_t pf_port_id, uint16_t repr_id, txq->ring =NULL ;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa); }int
@@ -1551,6 +1549,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1594,7 +1593,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) }sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ;
@@ -1606,7 +1605,7 @@ sfc_repr_proxy_start_repr(uint16_t pf_port_id, uint16_t repr_id) fail_not_found:sfc_err (sa,"failed to start repr %u proxy port: %s" , repr_id,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
@@ -1621,6 +1620,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa);sfc_log_init (sa,"entry" );
@@ -1628,14 +1628,14 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port" , __func__); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }if (!port->enabled) {sfc_log_init (sa,"repr %u proxy port is not started - skip" , repr_id); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1662,7 +1662,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id)sfc_err (sa,"failed to stop representor proxy TxQ %u: %s" , repr_id,rte_strerror (rc)); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; } }
@@ -1670,7 +1670,7 @@ sfc_repr_proxy_stop_repr(uint16_t pf_port_id, uint16_t repr_id) port->enabled = false;sfc_log_init (sa,"done" ); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return 0 ; }
@@ -1685,13 +1685,14 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id,int rc; sa =sfc_get_adapter_by_pf_port_id (pf_port_id); +sfc_adapter_lock (sa); rp =sfc_repr_proxy_by_adapter (sa); port =sfc_repr_proxy_find_port (rp, repr_id);if (port ==NULL ) {sfc_err (sa,"%s() failed: no such port (repr_id=%u)" , __func__, repr_id); -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return ENOENT ; }
@@ -1703,7 +1704,7 @@ sfc_repr_proxy_repr_entity_mac_addr_set(uint16_t pf_port_id, uint16_t repr_id, __func__, repr_id, rte_strerror(rc)); } -sfc_put_adapter (sa); +sfc_adapter_unlock (sa);return rc; }
Signature · 1 line
2.39.2
PATCH v3 10/16 net/sfc: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
One additional change is required in sfc_ev_qpoll() so that clang does see the same lock is being manipulated.
--- drivers/net/sfc/sfc.h | 41 ++++++-------------------------------- drivers/net/sfc/sfc_ev.c | 6 ++++-- drivers/net/sfc/sfc_repr.c | 38 +++++------------------------------ 3 files changed, 15 insertions(+), 70 deletions(-)
drivers/net/sfc/sfc.h +6 -35
@@ -333,41 +333,12 @@ sfc_sa2shared(struct sfc_adapter *sa)* change the lock in one place. */ -static inline void -sfc_adapter_lock_init (struct sfc_adapter *sa) -{ -rte_spinlock_init (&sa->lock); -} - -static inline int -sfc_adapter_is_locked (struct sfc_adapter *sa) -{ -return rte_spinlock_is_locked (&sa->lock); -} - -static inline void -sfc_adapter_lock (struct sfc_adapter *sa) -{ -rte_spinlock_lock (&sa->lock); -} - -static inline int -sfc_adapter_trylock (struct sfc_adapter *sa) -{ -return rte_spinlock_trylock (&sa->lock); -} - -static inline void -sfc_adapter_unlock (struct sfc_adapter *sa) -{ -rte_spinlock_unlock (&sa->lock); -} - -static inline void -sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa) -{ -/* Just for symmetry of the API */ -} +#define sfc_adapter_lock_init (sa) rte_spinlock_init(&(sa)->lock) +#define sfc_adapter_is_locked (sa) rte_spinlock_is_locked(&(sa)->lock) +#define sfc_adapter_lock (sa) rte_spinlock_lock(&(sa)->lock) +#define sfc_adapter_trylock (sa) rte_spinlock_trylock(&(sa)->lock) +#define sfc_adapter_unlock (sa) rte_spinlock_unlock(&(sa)->lock) +#define sfc_adapter_lock_fini (sa) RTE_SET_USED(sa)static inline unsigned int sfc_nb_counter_rxq (const struct sfc_adapter_shared *sas)
drivers/net/sfc/sfc_ev.c +4 -2
@@ -570,6 +570,8 @@ static const efx_ev_callbacks_t sfc_ev_callbacks_dp_tx = {void sfc_ev_qpoll (struct sfc_evq *evq) { +struct sfc_adapter *sa; +SFC_ASSERT (evq->init_state ==SFC_EVQ_STARTED || evq->init_state ==SFC_EVQ_STARTING );
@@ -577,8 +579,8 @@ sfc_ev_qpoll(struct sfc_evq *evq)efx_ev_qpoll (evq->common, &evq->read_ptr, evq->callbacks, evq); -if (unlikely (evq->exception) &&sfc_adapter_trylock (evq->sa)) { -struct sfc_adapter *sa = evq->sa; + sa = evq->sa; +if (unlikely (evq->exception) &&sfc_adapter_trylock (sa)) {int rc;if (evq->dp_rxq !=NULL ) {
drivers/net/sfc/sfc_repr.c +5 -33
@@ -112,39 +112,11 @@ sfc_repr_by_eth_dev(struct rte_eth_dev *eth_dev)* change the lock in one place. */ -static inline void -sfc_repr_lock_init (struct sfc_repr *sr) -{ -rte_spinlock_init (&sr->lock); -} - -#if defined(RTE_LIBRTE_SFC_EFX_DEBUG ) || defined(RTE_ENABLE_ASSERT ) - -static inline int -sfc_repr_lock_is_locked (struct sfc_repr *sr) -{ -return rte_spinlock_is_locked (&sr->lock); -} - -#endif - -static inline void -sfc_repr_lock (struct sfc_repr *sr) -{ -rte_spinlock_lock (&sr->lock); -} - -static inline void -sfc_repr_unlock (struct sfc_repr *sr) -{ -rte_spinlock_unlock (&sr->lock); -} - -static inline void -sfc_repr_lock_fini(__rte_unused struct sfc_repr *sr) -{ -/* Just for symmetry of the API */ -} +#define sfc_repr_lock_init (sr) rte_spinlock_init(&(sr)->lock) +#define sfc_repr_lock_is_locked (sr) rte_spinlock_is_locked(&(sr)->lock) +#define sfc_repr_lock (sr) rte_spinlock_lock(&(sr)->lock) +#define sfc_repr_unlock (sr) rte_spinlock_unlock(&(sr)->lock) +#define sfc_repr_lock_fini (sr) RTE_SET_USED(sr)static void sfc_repr_rx_queue_stop (void *queue)
Signature · 1 line
2.39.2
PATCH v3 11/16 net/virtio: rework guest announce notify helper
In reply to David MarchandInline existing helpers virtio_dev_(pause|resume) into virtio_notify_peers().
This makes the lock check on hw->state_lock trivial.
--- drivers/net/virtio/virtio_ethdev.c | 75 ++++++++---------------------- drivers/net/virtio/virtio_ethdev.h | 4 -- 2 files changed, 19 insertions(+), 60 deletions(-)
drivers/net/virtio/virtio_ethdev.c +19 -56
@@ -1144,57 +1144,6 @@ virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features)return 0 ; } -int -virtio_dev_pause (struct rte_eth_dev *dev) -{ -struct virtio_hw *hw = dev->data->dev_private; - -rte_spinlock_lock (&hw->state_lock); - -if (hw->started ==0 ) { -/* Device is just stopped. */ -rte_spinlock_unlock (&hw->state_lock); -return -1 ; - } - hw->started =0 ; -/* -* Prevent the worker threads from touching queues to avoid contention, -* 1 ms should be enough for the ongoing Tx function to finish. -*/ -rte_delay_ms (1 ); -return 0 ; -} - -/* -* Recover hw state to let the worker threads continue. -*/ -void -virtio_dev_resume (struct rte_eth_dev *dev) -{ -struct virtio_hw *hw = dev->data->dev_private; - - hw->started =1 ; -rte_spinlock_unlock (&hw->state_lock); -} - -/* -* Should be called only after device is paused. -*/ -int -virtio_inject_pkts (struct rte_eth_dev *dev,struct rte_mbuf **tx_pkts, -int nb_pkts) -{ -struct virtio_hw *hw = dev->data->dev_private; -struct virtnet_tx *txvq = dev->data->tx_queues[0 ]; -int ret; - - hw->inject_pkts = tx_pkts; - ret = dev->tx_pkt_burst (txvq, tx_pkts, nb_pkts); - hw->inject_pkts =NULL ; - -return ret; -} -static void virtio_notify_peers (struct rte_eth_dev *dev) {
@@ -1216,14 +1165,28 @@ virtio_notify_peers(struct rte_eth_dev *dev)return ; } -/* If virtio port just stopped, no need to send RARP */ -if (virtio_dev_pause (dev) <0 ) { +rte_spinlock_lock (&hw->state_lock); +if (hw->started ==0 ) { +/* If virtio port just stopped, no need to send RARP */ rte_pktmbuf_free (rarp_mbuf); -return ; + goto out; } + hw->started =0 ; -virtio_inject_pkts (dev, &rarp_mbuf,1 ); -virtio_dev_resume (dev); +/* +* Prevent the worker threads from touching queues to avoid contention, +* 1 ms should be enough for the ongoing Tx function to finish. +*/ +rte_delay_ms (1 ); + + hw->inject_pkts = &rarp_mbuf; + dev->tx_pkt_burst (dev->data->tx_queues[0 ], &rarp_mbuf,1 ); + hw->inject_pkts =NULL ; + + hw->started =1 ; + +out: +rte_spinlock_unlock (&hw->state_lock); } static void
drivers/net/virtio/virtio_ethdev.h +0 -4
@@ -112,12 +112,8 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);void virtio_interrupt_handler (void *param); -int virtio_dev_pause (struct rte_eth_dev *dev); -void virtio_dev_resume (struct rte_eth_dev *dev);int virtio_dev_stop (struct rte_eth_dev *dev);int virtio_dev_close (struct rte_eth_dev *dev); -int virtio_inject_pkts (struct rte_eth_dev *dev,struct rte_mbuf **tx_pkts, -int nb_pkts);bool virtio_rx_check_scatter (uint16_t max_rx_pkt_len,uint16_t rx_buf_size,bool rx_scatter_enabled,const char **error);
Signature · 1 line
2.39.2
PATCH v3 12/16 raw/ifpga: inherit lock annotations
In reply to David MarchandThe checks in those helpers are useless:
- all (start/stop/reset/test) callers ensure that dev != NULL,
- dev->sd can't be NULL either as it would mean the application is calling those helpers for a dev pointer that did not pass initialisation,
Once the checks are removed, the only thing that remains is calls to the rte_spinlock API, so simply use macros and inherit annotations from the lock API.
--- drivers/raw/ifpga/afu_pmd_core.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/raw/ifpga/afu_pmd_core.c +2 -15
@@ -23,21 +23,8 @@ static struct rte_afu_uuid afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1];TAILQ_HEAD (afu_drv_list, afu_rawdev_drv);static struct afu_drv_list afu_pmd_list =TAILQ_HEAD_INITIALIZER (afu_pmd_list); -static inline int afu_rawdev_trylock (struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return 0 ; - -return rte_spinlock_trylock (&dev->sd->lock); -} - -static inline void afu_rawdev_unlock (struct afu_rawdev *dev) -{ -if (!dev || !dev->sd) -return ; - -rte_spinlock_unlock (&dev->sd->lock); -} +#define afu_rawdev_trylock (dev) rte_spinlock_trylock(&dev->sd->lock) +#define afu_rawdev_unlock (dev) rte_spinlock_unlock(&dev->sd->lock)static int afu_rawdev_configure (const struct rte_rawdev *rawdev,rte_rawdev_obj_t config,size_t config_size)
Signature · 1 line
2.39.2
PATCH v3 13/16 vdpa/sfc: inherit lock annotations
In reply to David MarchandDue to clang limitation, inline helpers don't inherit lock annotations from the EAL lock API.
Replace them with macros.
sfc_vdpa_ops.c was relying on an implicit cast of the dev_handle to a vdpa adapter object. Add an explicit conversion.
--- drivers/vdpa/sfc/sfc_vdpa.h | 41 +++++---------------------------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 14 +++++------ 2 files changed, 13 insertions(+), 42 deletions(-)
drivers/vdpa/sfc/sfc_vdpa.h +6 -35
@@ -122,40 +122,11 @@ sfc_vdpa_adapter_by_dev_handle(void *dev_handle)* Add wrapper functions to acquire/release lock to be able to remove or * change the lock in one place. */ -static inline void -sfc_vdpa_adapter_lock_init (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_init (&sva->lock); -} - -static inline int -sfc_vdpa_adapter_is_locked (struct sfc_vdpa_adapter *sva) -{ -return rte_spinlock_is_locked (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_lock (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_lock (&sva->lock); -} - -static inline int -sfc_vdpa_adapter_trylock (struct sfc_vdpa_adapter *sva) -{ -return rte_spinlock_trylock (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_unlock (struct sfc_vdpa_adapter *sva) -{ -rte_spinlock_unlock (&sva->lock); -} - -static inline void -sfc_vdpa_adapter_lock_fini(__rte_unused struct sfc_vdpa_adapter *sva) -{ -/* Just for symmetry of the API */ -} +#define sfc_vdpa_adapter_lock_init (sva) rte_spinlock_init(&(sva)->lock) +#define sfc_vdpa_adapter_is_locked (sva) rte_spinlock_is_locked(&(sva)->lock) +#define sfc_vdpa_adapter_lock (sva) rte_spinlock_lock(&(sva)->lock) +#define sfc_vdpa_adapter_trylock (sva) rte_spinlock_trylock(&(sva)->lock) +#define sfc_vdpa_adapter_unlock (sva) rte_spinlock_unlock(&(sva)->lock) +#define sfc_vdpa_adapter_lock_fini (sva) RTE_SET_USED(sva)#endif /* _SFC_VDPA_H */
drivers/vdpa/sfc/sfc_vdpa_ops.c +7 -7
@@ -577,7 +577,7 @@ sfc_vdpa_notify_ctrl(void *arg)if (ops_data ==NULL )return NULL ; -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle)); vid = ops_data->vid;
@@ -586,7 +586,7 @@ sfc_vdpa_notify_ctrl(void *arg)"vDPA (%s): Notifier could not get configured" , ops_data->vdpa_dev->device->name); -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return NULL ; }
@@ -637,7 +637,7 @@ sfc_vdpa_dev_config(int vid) ops_data->vid = vid; -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));sfc_vdpa_log_init (ops_data->dev_handle,"configuring" ); rc =sfc_vdpa_configure (ops_data);
@@ -653,7 +653,7 @@ sfc_vdpa_dev_config(int vid)if (rc !=0 ) goto fail_vdpa_notify; -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));sfc_vdpa_log_init (ops_data->dev_handle,"done" );
@@ -666,7 +666,7 @@ sfc_vdpa_dev_config(int vid)sfc_vdpa_close (ops_data); fail_vdpa_config: -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return -1 ; }
@@ -688,7 +688,7 @@ sfc_vdpa_dev_close(int vid)return -1 ; } -sfc_vdpa_adapter_lock (ops_data->dev_handle); +sfc_vdpa_adapter_lock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));if (ops_data->is_notify_thread_started == true) {void *status; ret =pthread_cancel (ops_data->notify_tid);
@@ -710,7 +710,7 @@ sfc_vdpa_dev_close(int vid)sfc_vdpa_stop (ops_data);sfc_vdpa_close (ops_data); -sfc_vdpa_adapter_unlock (ops_data->dev_handle); +sfc_vdpa_adapter_unlock (sfc_vdpa_adapter_by_dev_handle (ops_data->dev_handle));return 0 ; }
Signature · 1 line
2.39.2
PATCH v3 14/16 net/failsafe: fix mutex locking
In reply to David MarchandThe pthread mutex API describes cases where locking might fail. Check fts_enter wrapper return code.
--- drivers/net/failsafe/failsafe_ether.c | 3 +- drivers/net/failsafe/failsafe_flow.c | 23 +++-- drivers/net/failsafe/failsafe_ops.c | 142 +++++++++++++++++++------- 3 files changed, 123 insertions(+), 45 deletions(-)
drivers/net/failsafe/failsafe_ether.c +2 -1
@@ -592,7 +592,8 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused, {struct sub_device *sdev = cb_arg; -fs_lock (fs_dev (sdev),0 ); +if (fs_lock (fs_dev (sdev),0 ) !=0 ) +return -1 ;/* Switch as soon as possible tx_dev. */ fs_switch_dev (fs_dev (sdev), sdev);/* Use safe bursts in any case. */
drivers/net/failsafe/failsafe_flow.c +16 -7
@@ -72,7 +72,9 @@ fs_flow_validate(struct rte_eth_dev *dev,uint8_t i;int ret; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {DEBUG ("Calling rte_flow_validate on sub_device %d" , i); ret = rte_flow_validate(PORT_ID(sdev),
@@ -99,7 +101,8 @@ fs_flow_create(struct rte_eth_dev *dev,struct rte_flow *flow;uint8_t i; -fs_lock (dev,0 ); +if (fs_lock (dev,0 ) !=0 ) +return NULL ; flow =fs_flow_allocate (attr, patterns, actions); FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { flow->flows[i] = rte_flow_create(PORT_ID(sdev),
@@ -137,8 +140,9 @@ fs_flow_destroy(struct rte_eth_dev *dev,ERROR ("Invalid flow" );return -EINVAL ; } - ret =0 ; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {int local_ret;
@@ -169,7 +173,9 @@ fs_flow_flush(struct rte_eth_dev *dev,uint8_t i;int ret; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {DEBUG ("Calling rte_flow_flush on sub_device %d" , i); ret =rte_flow_flush (PORT_ID (sdev), error);
@@ -197,7 +203,8 @@ fs_flow_query(struct rte_eth_dev *dev, {struct sub_device *sdev; -fs_lock (dev,0 ); +if (fs_lock (dev,0 ) !=0 ) +return -1 ; sdev =TX_SUBDEV (dev);if (sdev !=NULL ) { int ret = rte_flow_query(PORT_ID(sdev),
@@ -223,7 +230,9 @@ fs_flow_isolate(struct rte_eth_dev *dev,uint8_t i;int ret; -fs_lock (dev,0 ); + ret =fs_lock (dev,0 ); +if (ret !=0 ) +return ret; FOREACH_SUBDEV(sdev, i, dev) {if (sdev->state <DEV_PROBED )continue ;
drivers/net/failsafe/failsafe_ops.c +105 -37
359 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v3 15/16 eal/windows: disable lock check on alarm code
In reply to David MarchandThis code uses locks to implement synchronisation between two threads. There seems nothing wrong with it, just silence the clang lock check.
--- lib/eal/windows/eal_alarm.c | 2 ++ 1 file changed, 2 insertions(+)
lib/eal/windows/eal_alarm.c +2 -0
@@ -224,6 +224,7 @@ struct intr_task {static void intr_thread_entry (void *arg) + __rte_no_thread_safety_analysis {struct intr_task *task = arg; task->func (task->arg);
@@ -232,6 +233,7 @@ intr_thread_entry(void *arg)static int intr_thread_exec_sync (void (*func)(void *arg),void *arg) + __rte_no_thread_safety_analysis {struct intr_task task;int ret;
Signature · 1 line
2.39.2
Re: [PATCH v3 15/16] eal/windows: disable lock check on alarm code
Quoted 5 lines · David Marchand
This code uses locks to implement synchronisation between two threads. There seems nothing wrong with it, just silence the clang lock check.
Signed-off-by David Marchand <[email protected]>---
Re: [PATCH v3 15/16] eal/windows: disable lock check on alarm code
In reply to David MarchandQuoted 5 lines · David Marchand
This code uses locks to implement synchronisation between two threads. There seems nothing wrong with it, just silence the clang lock check.
Signed-off-by David Marchand <[email protected]>
PATCH v3 16/16 enable lock check
In reply to David MarchandNow that a lot of components can be compiled with the lock checks, invert the logic and opt out for components not ready yet:
- drivers/bus/dpaa,
- drivers/common/cnxk,
- drivers/common/mlx5,
- drivers/event/cnxk,
- drivers/net/bnx2x,
- drivers/net/bnxt,
- drivers/net/cnxk,
- drivers/net/enic,
- drivers/net/hns3,
- drivers/net/mlx5,
- lib/ipsec,
- lib/timer,
The FreeBSD pthread API has been annotated but Linux glibc does not have those annotations. Disable lock checks for FreeBSD where pthread_mutex_* are used:
- drivers/net/failsafe,
- drivers/net/hinic,
- lib/eal,
- lib/ethdev,
---
Changes since v2:
- disabled checks on FreeBSD when code relies on pthread mutexes,
--- doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++-- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/enic/meson.build | 1 + drivers/net/failsafe/meson.build | 4 ++++ drivers/net/hinic/meson.build | 4 ++++ drivers/net/hns3/meson.build | 1 + drivers/net/mlx5/meson.build | 1 + lib/eal/meson.build | 4 ++++ lib/ethdev/meson.build | 4 ++++ lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 20 files changed, 33 insertions(+), 5 deletions(-)
doc/guides/prog_guide/env_abstraction_layer.rst +3 -2
@@ -550,8 +550,9 @@ Some general comments: waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please discuss it on the mailing list, -A DPDK library/driver can enable/disable the checks by setting -``annotate_locks`` accordingly in its ``meson.build`` file. +The checks are enabled by default for libraries and drivers. +They can be disabled by setting ``annotate_locks`` to ``false`` in +the concerned library/driver ``meson.build``. IOVA Mode Detection ~~~~~~~~~~~~~~~~~~~
drivers/bus/dpaa/meson.build +1 -0
@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith') endif includes += include_directories('include', 'base/qbman') +annotate_locks = false
drivers/common/cnxk/meson.build +1 -0
@@ -89,3 +89,4 @@ sources += files('cnxk_telemetry_bphy.c', deps += ['bus_pci', 'net', 'telemetry'] require_iova_in_mbuf = false +annotate_locks = false
drivers/common/mlx5/meson.build +1 -0
@@ -45,3 +45,4 @@ endif mlx5_config = configuration_data() subdir(exec_env) configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config) +annotate_locks = false
drivers/event/cnxk/meson.build +1 -0
@@ -480,3 +480,4 @@ endforeach deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk'] require_iova_in_mbuf = false +annotate_locks = false
drivers/meson.build +1 -1
@@ -92,7 +92,7 @@ foreach subpath:subdirs build = true # set to false to disable, e.g. missing deps reason = '<unknown reason>' # set if build == false to explain name = drv - annotate_locks = false + annotate_locks = true sources = [] headers = [] driver_sdk_headers = [] # public headers included by drivers
drivers/net/bnx2x/meson.build +1 -0
@@ -21,3 +21,4 @@ sources = files( 'ecore_sp.c', 'elink.c', ) +annotate_locks = false
drivers/net/bnxt/meson.build +1 -0
@@ -72,3 +72,4 @@ if arch_subdir == 'x86' elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64') sources += files('bnxt_rxtx_vec_neon.c') endif +annotate_locks = false
drivers/net/cnxk/meson.build +1 -0
@@ -197,3 +197,4 @@ endforeach headers = files('rte_pmd_cnxk.h') require_iova_in_mbuf = false +annotate_locks = false
drivers/net/enic/meson.build +1 -0
@@ -43,3 +43,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64') c_args: [cflags, '-mavx2']) objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c') endif +annotate_locks = false
drivers/net/failsafe/meson.build +4 -0
@@ -29,3 +29,7 @@ sources = files( ) require_iova_in_mbuf = false + +if is_freebsd + annotate_locks = false +endif
drivers/net/hinic/meson.build +4 -0
@@ -18,3 +18,7 @@ sources = files( ) includes += include_directories('base') + +if is_freebsd + annotate_locks = false +endif
drivers/net/hns3/meson.build +1 -0
@@ -32,6 +32,7 @@ sources = files( 'hns3_common.c', 'hns3_dump.c', ) +annotate_locks = false require_iova_in_mbuf = false
drivers/net/mlx5/meson.build +1 -0
@@ -82,3 +82,4 @@ testpmd_sources += files('mlx5_testpmd.c') subdir(exec_env) subdir('hws') +annotate_locks = false
lib/eal/meson.build +4 -0
@@ -32,3 +32,7 @@ endif if cc.has_function('getentropy', prefix : '#include <unistd.h>') cflags += '-DRTE_LIBEAL_USE_GETENTROPY' endif + +if is_freebsd + annotate_locks = false +endif
lib/ethdev/meson.build +4 -0
@@ -44,3 +44,7 @@ driver_sdk_headers += files( ) deps += ['net', 'kvargs', 'meter', 'telemetry'] + +if is_freebsd + annotate_locks = false +endif
lib/ipsec/meson.build +1 -0
@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c', headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h') +annotate_locks = false deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
lib/meson.build +1 -1
@@ -121,7 +121,7 @@ foreach l:libraries reason = '<unknown reason>' # set if build == false to explain why name = l use_function_versioning = false - annotate_locks = false + annotate_locks = true sources = [] headers = [] indirect_headers = [] # public headers not directly included by apps
lib/timer/meson.build +1 -0
@@ -3,3 +3,4 @@ sources = files('rte_timer.c') headers = files('rte_timer.h') +annotate_locks = false
lib/vhost/meson.build +0 -1
@@ -18,7 +18,6 @@ endif dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h')) cflags += '-fno-strict-aliasing' -annotate_locks = true sources = files( 'fd_man.c', 'iotlb.c',
Signature · 1 line
2.39.2
Re: [PATCH v3 16/16] enable lock check
Quoted 74 lines · David Marchand
Now that a lot of components can be compiled with the lock checks, invert the logic and opt out for components not ready yet:
-drivers/bus/dpaa,
-drivers/common/cnxk,
-drivers/common/mlx5,
-drivers/event/cnxk,
-drivers/net/bnx2x,
-drivers/net/bnxt,
-drivers/net/cnxk,
-drivers/net/enic,
-drivers/net/hns3,
-drivers/net/mlx5,
- lib/ipsec,
- lib/timer,The FreeBSD pthread API has been annotated but Linux glibc does not have those annotations. Disable lock checks for FreeBSD where pthread_mutex_* are used:
-drivers/net/failsafe,
-drivers/net/hinic,
- lib/eal,
- lib/ethdev,Signed-off-by David Marchand <[email protected]>Reviewed-by Chenbo Xia <[email protected]>---
Changes since v2:
- disabled checks on FreeBSD when code relies on pthread mutexes,--- doc/guides/prog_guide/env_abstraction_layer.rst | 5 +++-- drivers/bus/dpaa/meson.build | 1 + drivers/common/cnxk/meson.build | 1 + drivers/common/mlx5/meson.build | 1 + drivers/event/cnxk/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/meson.build | 1 + drivers/net/bnxt/meson.build | 1 + drivers/net/cnxk/meson.build | 1 + drivers/net/enic/meson.build | 1 + drivers/net/failsafe/meson.build | 4 ++++ drivers/net/hinic/meson.build | 4 ++++ drivers/net/hns3/meson.build | 1 + drivers/net/mlx5/meson.build | 1 + lib/eal/meson.build | 4 ++++ lib/ethdev/meson.build | 4 ++++ lib/ipsec/meson.build | 1 + lib/meson.build | 2 +- lib/timer/meson.build | 1 + lib/vhost/meson.build | 1 - 20 files changed, 33 insertions(+), 5 deletions(-)doc/guides/prog_guide/env_abstraction_layer.rst +3
-2@@ -550,8 +550,9 @@ Some general comments: waiving checks with ``__rte_no_thread_safety_analysis`` in your code, please discuss it on the mailing list, -A DPDK library/driver can enable/disable the checks by setting -``annotate_locks`` accordingly in its ``meson.build`` file. +The checks are enabled by default for libraries and drivers. +They can be disabled by setting ``annotate_locks`` to ``false`` in +the concerned library/driver ``meson.build``. IOVA Mode Detection ~~~~~~~~~~~~~~~~~~~drivers/bus/dpaa/meson.build +0
-0
drivers/bus/dpaa/meson.build if cc.has_argument('-Wno-pointer-arith') · line 32
Quoted 4 lines
drivers/bus/dpaa/meson.build +1
-0@@ -29,3 +29,4 @@ if cc.has_argument('-Wno-pointer-arith') endif includes += include_directories('include', 'base/qbman') +annotate_locks = false
Quoted 190 lines
drivers/common/cnxk/meson.build +1
-0@@ -89,3 +89,4 @@ sources += files('cnxk_telemetry_bphy.c', deps += ['bus_pci', 'net', 'telemetry'] require_iova_in_mbuf = false +annotate_locks = falsedrivers/common/mlx5/meson.build +1
-0@@ -45,3 +45,4 @@ endif mlx5_config = configuration_data() subdir(exec_env) configure_file(output: 'mlx5_autoconf.h', configuration: mlx5_config) +annotate_locks = falsedrivers/event/cnxk/meson.build +1
-0@@ -480,3 +480,4 @@ endforeach deps += ['bus_pci', 'common_cnxk', 'net_cnxk', 'crypto_cnxk'] require_iova_in_mbuf = false +annotate_locks = falsedrivers/meson.build +1
-1@@ -92,7 +92,7 @@ foreach subpath:subdirs build = true # set to false to disable, e.g. missing deps reason = '<unknown reason>' # set if build == false to explain name = drv - annotate_locks = false + annotate_locks = true sources = [] headers = [] driver_sdk_headers = [] # public headers included by driversdrivers/net/bnx2x/meson.build +1
-0@@ -21,3 +21,4 @@ sources = files( 'ecore_sp.c', 'elink.c', ) +annotate_locks = falsedrivers/net/bnxt/meson.build +1
-0@@ -72,3 +72,4 @@ if arch_subdir == 'x86' elif arch_subdir == 'arm' and dpdk_conf.get('RTE_ARCH_64') sources += files('bnxt_rxtx_vec_neon.c') endif +annotate_locks = falsedrivers/net/cnxk/meson.build +1
-0@@ -197,3 +197,4 @@ endforeach headers = files('rte_pmd_cnxk.h') require_iova_in_mbuf = false +annotate_locks = falsedrivers/net/enic/meson.build +1
-0@@ -43,3 +43,4 @@ elif cc.has_argument('-mavx2') and dpdk_conf.get('RTE_ARCH_64') c_args: [cflags, '-mavx2']) objs += enic_avx2_lib.extract_objects('enic_rxtx_vec_avx2.c') endif +annotate_locks = falsedrivers/net/failsafe/meson.build +4
-0@@ -29,3 +29,7 @@ sources = files( ) require_iova_in_mbuf = false + +if is_freebsd + annotate_locks = false +endifdrivers/net/hinic/meson.build +4
-0@@ -18,3 +18,7 @@ sources = files( ) includes += include_directories('base') + +if is_freebsd + annotate_locks = false +endifdrivers/net/hns3/meson.build +1
-0@@ -32,6 +32,7 @@ sources = files( 'hns3_common.c', 'hns3_dump.c', ) +annotate_locks = false require_iova_in_mbuf = falsedrivers/net/mlx5/meson.build +1
-0@@ -82,3 +82,4 @@ testpmd_sources += files('mlx5_testpmd.c') subdir(exec_env) subdir('hws') +annotate_locks = falselib/eal/meson.build +4
-0@@ -32,3 +32,7 @@ endif if cc.has_function('getentropy', prefix : '#include <unistd.h>') cflags += '-DRTE_LIBEAL_USE_GETENTROPY' endif + +if is_freebsd + annotate_locks = false +endiflib/ethdev/meson.build +4
-0@@ -44,3 +44,7 @@ driver_sdk_headers += files( ) deps += ['net', 'kvargs', 'meter', 'telemetry'] + +if is_freebsd + annotate_locks = false +endiflib/ipsec/meson.build +1
-0@@ -13,5 +13,6 @@ sources = files('esp_inb.c', 'esp_outb.c', headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h') +annotate_locks = false deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']lib/meson.build +1
-1@@ -121,7 +121,7 @@ foreach l:libraries reason = '<unknown reason>' # set if build == false to explain why name = l use_function_versioning = false - annotate_locks = false + annotate_locks = true sources = [] headers = [] indirect_headers = [] # public headers not directly included by appslib/timer/meson.build +1
-0@@ -3,3 +3,4 @@ sources = files('rte_timer.c') headers = files('rte_timer.h') +annotate_locks = falselib/vhost/meson.build +0
-1@@ -18,7 +18,6 @@ endif dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h')) cflags += '-fno-strict-aliasing' -annotate_locks = true sources = files( 'fd_man.c', 'iotlb.c',
Signature · 3 lines
Thanks, Sachin Saxena (NXP)
Thomas Monjalon
Applied04/04/2023 14:48, David Marchand:
Quoted 10 lines
This is a followup of the series that introduced lock annotations. I reworked and made annotations work in what seemed the easier cases. In most cases, I chose to convert inline wrappers around the EAL lock API to simple macro: I did not see much value in those wrappers and this is way simpler than adding __rte_*lock_function tags everywhere.
A list of libraries and drivers still need more work as their code have non obvious locks handling. For those components, the check is opted out.
I leave it to their respective maintainers to enable the checks later.
Some drivers require some effort to enable the lock checks at compilation:
bnx2x, bnxt, cnxk, dpaa, enic, failsafe, hinic, hns3, mlx5
Quoted 5 lines
FreeBSD libc pthread API has lock annotations while Linux glibc has none. Until we get a proper abstraction for mutexes, the simpler is to disable the check on FreeBSD.
Maintainers, please review.
Applied, thanks.