Skip to content

Commit

Permalink
eal: enhance lock annotations for rwlock
Browse files Browse the repository at this point in the history
Convert rwlock to the clang capability annotations.

Signed-off-by: David Marchand <[email protected]>
  • Loading branch information
david-marchand committed Nov 18, 2024
1 parent 452a3d8 commit 8936e37
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 149 deletions.
2 changes: 1 addition & 1 deletion lib/eal/common/eal_memalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);

int
eal_memalloc_init(void)
__rte_shared_locks_required(rte_mcfg_mem_get_lock());
__rte_requires_shared_capability(rte_mcfg_mem_get_lock());

int
eal_memalloc_cleanup(void);
Expand Down
2 changes: 1 addition & 1 deletion lib/eal/common/eal_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int rte_eal_memseg_init(void);
* 0 on success, negative on error
*/
int rte_eal_memory_init(void)
__rte_shared_locks_required(rte_mcfg_mem_get_lock());
__rte_requires_shared_capability(rte_mcfg_mem_get_lock());

/**
* Configure timers
Expand Down
23 changes: 12 additions & 11 deletions lib/eal/include/generic/rte_rwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include <errno.h>
#include <stdbool.h>

#include <rte_branch_prediction.h>
#include <rte_common.h>
Expand Down Expand Up @@ -57,7 +58,7 @@ extern "C" {
/* Writer is waiting or has lock */
#define RTE_RWLOCK_READ 0x4 /* Reader increment */

typedef struct __rte_lockable {
typedef struct __rte_capability("rwlock") {
RTE_ATOMIC(int32_t) cnt;
} rte_rwlock_t;

Expand Down Expand Up @@ -90,7 +91,7 @@ rte_rwlock_init(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_read_lock(rte_rwlock_t *rwl)
__rte_shared_lock_function(rwl)
__rte_acquire_shared_capability(rwl)
__rte_no_thread_safety_analysis
{
int32_t x;
Expand Down Expand Up @@ -127,7 +128,7 @@ rte_rwlock_read_lock(rte_rwlock_t *rwl)
*/
static inline int
rte_rwlock_read_trylock(rte_rwlock_t *rwl)
__rte_shared_trylock_function(0, rwl)
__rte_try_acquire_shared_capability(false, rwl)
__rte_no_thread_safety_analysis
{
int32_t x;
Expand Down Expand Up @@ -160,7 +161,7 @@ rte_rwlock_read_trylock(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_read_unlock(rte_rwlock_t *rwl)
__rte_unlock_function(rwl)
__rte_release_shared_capability(rwl)
__rte_no_thread_safety_analysis
{
rte_atomic_fetch_sub_explicit(&rwl->cnt, RTE_RWLOCK_READ, rte_memory_order_release);
Expand All @@ -178,7 +179,7 @@ rte_rwlock_read_unlock(rte_rwlock_t *rwl)
*/
static inline int
rte_rwlock_write_trylock(rte_rwlock_t *rwl)
__rte_exclusive_trylock_function(0, rwl)
__rte_try_acquire_capability(false, rwl)
__rte_no_thread_safety_analysis
{
int32_t x;
Expand All @@ -200,7 +201,7 @@ rte_rwlock_write_trylock(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_write_lock(rte_rwlock_t *rwl)
__rte_exclusive_lock_function(rwl)
__rte_acquire_capability(rwl)
__rte_no_thread_safety_analysis
{
int32_t x;
Expand Down Expand Up @@ -238,7 +239,7 @@ rte_rwlock_write_lock(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_write_unlock(rte_rwlock_t *rwl)
__rte_unlock_function(rwl)
__rte_release_capability(rwl)
__rte_no_thread_safety_analysis
{
rte_atomic_fetch_sub_explicit(&rwl->cnt, RTE_RWLOCK_WRITE, rte_memory_order_release);
Expand Down Expand Up @@ -276,7 +277,7 @@ rte_rwlock_write_is_locked(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)
__rte_shared_lock_function(rwl);
__rte_acquire_shared_capability(rwl);

/**
* Commit hardware memory transaction or release the read lock if the lock is used as a fall-back
Expand All @@ -286,7 +287,7 @@ rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)
__rte_unlock_function(rwl);
__rte_release_shared_capability(rwl);

/**
* Try to execute critical section in a hardware memory transaction, if it
Expand All @@ -303,7 +304,7 @@ rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)
__rte_exclusive_lock_function(rwl);
__rte_acquire_capability(rwl);

/**
* Commit hardware memory transaction or release the write lock if the lock is used as a fall-back
Expand All @@ -313,7 +314,7 @@ rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)
*/
static inline void
rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl)
__rte_unlock_function(rwl);
__rte_release_capability(rwl);

#ifdef __cplusplus
}
Expand Down
24 changes: 12 additions & 12 deletions lib/eal/include/rte_eal_memconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,84 +48,84 @@ rte_mcfg_ethdev_get_lock(void);
*/
void
rte_mcfg_mem_read_lock(void)
__rte_shared_lock_function(rte_mcfg_mem_get_lock());
__rte_acquire_shared_capability(rte_mcfg_mem_get_lock());

/**
* Unlock the internal EAL shared memory configuration for shared access.
*/
void
rte_mcfg_mem_read_unlock(void)
__rte_unlock_function(rte_mcfg_mem_get_lock());
__rte_release_shared_capability(rte_mcfg_mem_get_lock());

/**
* Lock the internal EAL shared memory configuration for exclusive access.
*/
void
rte_mcfg_mem_write_lock(void)
__rte_exclusive_lock_function(rte_mcfg_mem_get_lock());
__rte_acquire_capability(rte_mcfg_mem_get_lock());

/**
* Unlock the internal EAL shared memory configuration for exclusive access.
*/
void
rte_mcfg_mem_write_unlock(void)
__rte_unlock_function(rte_mcfg_mem_get_lock());
__rte_release_capability(rte_mcfg_mem_get_lock());

/**
* Lock the internal EAL TAILQ list for shared access.
*/
void
rte_mcfg_tailq_read_lock(void)
__rte_shared_lock_function(rte_mcfg_tailq_get_lock());
__rte_acquire_shared_capability(rte_mcfg_tailq_get_lock());

/**
* Unlock the internal EAL TAILQ list for shared access.
*/
void
rte_mcfg_tailq_read_unlock(void)
__rte_unlock_function(rte_mcfg_tailq_get_lock());
__rte_release_shared_capability(rte_mcfg_tailq_get_lock());

/**
* Lock the internal EAL TAILQ list for exclusive access.
*/
void
rte_mcfg_tailq_write_lock(void)
__rte_exclusive_lock_function(rte_mcfg_tailq_get_lock());
__rte_acquire_capability(rte_mcfg_tailq_get_lock());

/**
* Unlock the internal EAL TAILQ list for exclusive access.
*/
void
rte_mcfg_tailq_write_unlock(void)
__rte_unlock_function(rte_mcfg_tailq_get_lock());
__rte_release_capability(rte_mcfg_tailq_get_lock());

/**
* Lock the internal EAL Mempool list for shared access.
*/
void
rte_mcfg_mempool_read_lock(void)
__rte_shared_lock_function(rte_mcfg_mempool_get_lock());
__rte_acquire_shared_capability(rte_mcfg_mempool_get_lock());

/**
* Unlock the internal EAL Mempool list for shared access.
*/
void
rte_mcfg_mempool_read_unlock(void)
__rte_unlock_function(rte_mcfg_mempool_get_lock());
__rte_release_shared_capability(rte_mcfg_mempool_get_lock());

/**
* Lock the internal EAL Mempool list for exclusive access.
*/
void
rte_mcfg_mempool_write_lock(void)
__rte_exclusive_lock_function(rte_mcfg_mempool_get_lock());
__rte_acquire_capability(rte_mcfg_mempool_get_lock());

/**
* Unlock the internal EAL Mempool list for exclusive access.
*/
void
rte_mcfg_mempool_write_unlock(void)
__rte_unlock_function(rte_mcfg_mempool_get_lock());
__rte_release_capability(rte_mcfg_mempool_get_lock());

/**
* Lock the internal EAL Timer Library lock for exclusive access.
Expand Down
4 changes: 2 additions & 2 deletions lib/ethdev/ethdev_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ eth_dev_allocated(const char *name)

static uint16_t
eth_dev_find_free_port(void)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock())
__rte_requires_capability(rte_mcfg_ethdev_get_lock())
{
uint16_t i;

Expand All @@ -65,7 +65,7 @@ eth_dev_find_free_port(void)

static struct rte_eth_dev *
eth_dev_get(uint16_t port_id)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock())
__rte_requires_capability(rte_mcfg_ethdev_get_lock())
{
struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];

Expand Down
4 changes: 2 additions & 2 deletions lib/ethdev/ethdev_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ void eth_dev_fp_ops_setup(struct rte_eth_fp_ops *fpo,


void *eth_dev_shared_data_prepare(void)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock());
__rte_requires_capability(rte_mcfg_ethdev_get_lock());
void eth_dev_shared_data_release(void)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock());
__rte_requires_capability(rte_mcfg_ethdev_get_lock());

void eth_dev_rxq_release(struct rte_eth_dev *dev, uint16_t qid);
void eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid);
Expand Down
4 changes: 2 additions & 2 deletions lib/ethdev/rte_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ rte_eth_dev_is_valid_port(uint16_t port_id)

static int
eth_is_valid_owner_id(uint64_t owner_id)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock())
__rte_requires_capability(rte_mcfg_ethdev_get_lock())
{
if (owner_id == RTE_ETH_DEV_NO_OWNER ||
eth_dev_shared_data->next_owner_id <= owner_id)
Expand Down Expand Up @@ -471,7 +471,7 @@ rte_eth_dev_owner_new(uint64_t *owner_id)
static int
eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
const struct rte_eth_dev_owner *new_owner)
__rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock())
__rte_requires_capability(rte_mcfg_ethdev_get_lock())
{
struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
struct rte_eth_dev_owner *port_owner;
Expand Down
8 changes: 4 additions & 4 deletions lib/hash/rte_cuckoo_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ 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_acquire_capability(&h->readwrite_lock)
__rte_no_thread_safety_analysis
{
if (h->writer_takes_lock && h->hw_trans_mem_support)
Expand All @@ -631,7 +631,7 @@ __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_acquire_shared_capability(&h->readwrite_lock)
__rte_no_thread_safety_analysis
{
if (h->readwrite_concur_support && h->hw_trans_mem_support)
Expand All @@ -642,7 +642,7 @@ __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_release_capability(&h->readwrite_lock)
__rte_no_thread_safety_analysis
{
if (h->writer_takes_lock && h->hw_trans_mem_support)
Expand All @@ -653,7 +653,7 @@ __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_release_shared_capability(&h->readwrite_lock)
__rte_no_thread_safety_analysis
{
if (h->readwrite_concur_support && h->hw_trans_mem_support)
Expand Down
8 changes: 4 additions & 4 deletions lib/vhost/iotlb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

static __rte_always_inline void
vhost_user_iotlb_rd_lock(struct vhost_virtqueue *vq)
__rte_shared_lock_function(&vq->iotlb_lock)
__rte_acquire_shared_capability(&vq->iotlb_lock)
{
rte_rwlock_read_lock(&vq->iotlb_lock);
}

static __rte_always_inline void
vhost_user_iotlb_rd_unlock(struct vhost_virtqueue *vq)
__rte_unlock_function(&vq->iotlb_lock)
__rte_release_shared_capability(&vq->iotlb_lock)
{
rte_rwlock_read_unlock(&vq->iotlb_lock);
}

static __rte_always_inline void
vhost_user_iotlb_wr_lock(struct vhost_virtqueue *vq)
__rte_exclusive_lock_function(&vq->iotlb_lock)
__rte_acquire_capability(&vq->iotlb_lock)
{
rte_rwlock_write_lock(&vq->iotlb_lock);
}

static __rte_always_inline void
vhost_user_iotlb_wr_unlock(struct vhost_virtqueue *vq)
__rte_unlock_function(&vq->iotlb_lock)
__rte_release_capability(&vq->iotlb_lock)
{
rte_rwlock_write_unlock(&vq->iotlb_lock);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ cleanup_device(struct virtio_net *dev, int destroy)

static void
vhost_free_async_mem(struct vhost_virtqueue *vq)
__rte_exclusive_locks_required(&vq->access_lock)
__rte_requires_capability(&vq->access_lock)
{
if (!vq->async)
return;
Expand Down Expand Up @@ -439,7 +439,7 @@ free_device(struct virtio_net *dev)

static __rte_always_inline int
log_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)
__rte_shared_locks_required(&vq->iotlb_lock)
__rte_requires_shared_capability(&vq->iotlb_lock)
{
if (likely(!(vq->ring_addrs.flags & (1 << VHOST_VRING_F_LOG))))
return 0;
Expand Down Expand Up @@ -488,7 +488,7 @@ translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,

static int
vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
__rte_shared_locks_required(&vq->iotlb_lock)
__rte_requires_shared_capability(&vq->iotlb_lock)
{
uint64_t req_size, size;

Expand Down Expand Up @@ -527,7 +527,7 @@ vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)

static int
vring_translate_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)
__rte_shared_locks_required(&vq->iotlb_lock)
__rte_requires_shared_capability(&vq->iotlb_lock)
{
uint64_t req_size, size;

Expand Down Expand Up @@ -1772,7 +1772,7 @@ rte_vhost_extern_callback_register(int vid,

static __rte_always_inline int
async_channel_register(struct virtio_net *dev, struct vhost_virtqueue *vq)
__rte_exclusive_locks_required(&vq->access_lock)
__rte_requires_capability(&vq->access_lock)
{
struct vhost_async *async;
int node = vq->numa_node;
Expand Down
Loading

0 comments on commit 8936e37

Please sign in to comment.