There is a recurring pattern in DPDK code: on first use, do something, on last use, undo something. In a lot of cases, these reference counters are atomic or otherwise thread-safe, but in cases where they're not, we use raw integers and do manual checks and counter updates instead.
This patchset attempts to provide a really minimal "usage counter" library that does *only* that: track usage of resources. The patchset does not do a full DPDK conversion to these counters, but it does convert a few things to demonstrate what it would look like if we had them. Anatoly Burakov (8): eal: add usage count helpers vfio: use usage counters dev: replace raw refcount with usage count vhost: use usage counters for vchan tracking acl: use usage counters for ref counting thash: use usage counters for ref counting lpm: use usage counters for ref counting net/nbl: track devices with usage counters doc/api/doxy-api-index.md | 1 + drivers/net/nbl/nbl_common/nbl_userdev.c | 22 +++--- lib/acl/acl.h | 4 +- lib/acl/acl_bld.c | 9 +-- lib/eal/include/meson.build | 1 + lib/eal/include/rte_usage_count.h | 96 ++++++++++++++++++++++++ lib/eal/linux/eal_dev.c | 20 +++-- lib/eal/linux/eal_vfio.c | 7 +- lib/eal/linux/eal_vfio.h | 5 +- lib/eal/linux/eal_vfio_group.c | 11 +-- lib/hash/rte_thash.c | 10 +-- lib/lpm/rte_lpm6.c | 13 ++-- lib/vhost/vhost.c | 5 +- lib/vhost/vhost.h | 3 +- 14 files changed, 151 insertions(+), 56 deletions(-) create mode 100644 lib/eal/include/rte_usage_count.h -- 2.52.0

