From: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
To: <dev@dpdk.org>
Cc: hofors@lysator.liu.se, "Morten Brørup" <mb@smartsharesystems.com>,
"Tyler Retzlaff" <roretzla@linux.microsoft.com>,
"Stephen Hemminger" <stephen@networkplumber.org>,
"Harry van Haaren" <harry.van.haaren@intel.com>,
"Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
Subject: [RFC v4 3/4] service: use multi-word bitset to represent service flags
Date: Fri, 16 Feb 2024 11:23:47 +0100 [thread overview]
Message-ID: <20240216102348.480407-3-mattias.ronnblom@ericsson.com> (raw)
In-Reply-To: <20240216102348.480407-1-mattias.ronnblom@ericsson.com>
Use a multi-word bitset to track which services are mapped to which
lcores, allowing the RTE_SERVICE_NUM_MAX compile-time constant to be >
64.
Replace array-of-bytes service-currently-active flags with a more
compact multi-word bitset-based representation, reducing memory
footprint somewhat.
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
lib/eal/common/rte_service.c | 70 ++++++++++++++----------------------
1 file changed, 27 insertions(+), 43 deletions(-)
diff --git a/lib/eal/common/rte_service.c b/lib/eal/common/rte_service.c
index d959c91459..ac96ecaca8 100644
--- a/lib/eal/common/rte_service.c
+++ b/lib/eal/common/rte_service.c
@@ -11,6 +11,7 @@
#include <eal_trace_internal.h>
#include <rte_lcore.h>
+#include <rte_bitset.h>
#include <rte_branch_prediction.h>
#include <rte_common.h>
#include <rte_cycles.h>
@@ -63,11 +64,11 @@ struct service_stats {
/* the internal values of a service core */
struct core_state {
/* map of services IDs are run on this core */
- uint64_t service_mask;
+ RTE_BITSET_DECLARE(mapped_services, RTE_SERVICE_NUM_MAX);
RTE_ATOMIC(uint8_t) runstate; /* running or stopped */
RTE_ATOMIC(uint8_t) thread_active; /* indicates when thread is in service_run() */
uint8_t is_service_core; /* set if core is currently a service core */
- uint8_t service_active_on_lcore[RTE_SERVICE_NUM_MAX];
+ RTE_BITSET_DECLARE(service_active_on_lcore, RTE_SERVICE_NUM_MAX);
RTE_ATOMIC(uint64_t) loops;
RTE_ATOMIC(uint64_t) cycles;
struct service_stats service_stats[RTE_SERVICE_NUM_MAX];
@@ -81,11 +82,6 @@ static uint32_t rte_service_library_initialized;
int32_t
rte_service_init(void)
{
- /* Hard limit due to the use of an uint64_t-based bitmask (and the
- * clzl intrinsic).
- */
- RTE_BUILD_BUG_ON(RTE_SERVICE_NUM_MAX > 64);
-
if (rte_service_library_initialized) {
EAL_LOG(NOTICE,
"service library init() called, init flag %d",
@@ -296,7 +292,7 @@ rte_service_component_unregister(uint32_t id)
/* clear the run-bit in all cores */
for (i = 0; i < RTE_MAX_LCORE; i++)
- lcore_states[i].service_mask &= ~(UINT64_C(1) << id);
+ rte_bitset_clear(lcore_states[i].mapped_services, id);
memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl));
@@ -410,7 +406,7 @@ service_runner_do_callback(struct rte_service_spec_impl *s,
/* Expects the service 's' is valid. */
static int32_t
-service_run(uint32_t i, struct core_state *cs, uint64_t service_mask,
+service_run(uint32_t i, struct core_state *cs, const uint64_t *mapped_services,
struct rte_service_spec_impl *s, uint32_t serialize_mt_unsafe)
{
if (!s)
@@ -424,12 +420,12 @@ service_run(uint32_t i, struct core_state *cs, uint64_t service_mask,
RUNSTATE_RUNNING ||
rte_atomic_load_explicit(&s->app_runstate, rte_memory_order_acquire) !=
RUNSTATE_RUNNING ||
- !(service_mask & (UINT64_C(1) << i))) {
- cs->service_active_on_lcore[i] = 0;
+ !rte_bitset_test(mapped_services, i)) {
+ rte_bitset_clear(cs->service_active_on_lcore, i);
return -ENOEXEC;
}
- cs->service_active_on_lcore[i] = 1;
+ rte_bitset_set(cs->service_active_on_lcore, i);
if ((service_mt_safe(s) == 0) && (serialize_mt_unsafe == 1)) {
if (!rte_spinlock_trylock(&s->execute_lock))
@@ -454,7 +450,7 @@ rte_service_may_be_active(uint32_t id)
return -EINVAL;
for (i = 0; i < lcore_count; i++) {
- if (lcore_states[ids[i]].service_active_on_lcore[id])
+ if (rte_bitset_test(lcore_states[ids[i]].service_active_on_lcore, id))
return 1;
}
@@ -474,7 +470,9 @@ rte_service_run_iter_on_app_lcore(uint32_t id, uint32_t serialize_mt_unsafe)
*/
rte_atomic_fetch_add_explicit(&s->num_mapped_cores, 1, rte_memory_order_relaxed);
- int ret = service_run(id, cs, UINT64_MAX, s, serialize_mt_unsafe);
+ RTE_BITSET_DECLARE(all_services, RTE_SERVICE_NUM_MAX);
+ rte_bitset_set_all(all_services, RTE_SERVICE_NUM_MAX);
+ int ret = service_run(id, cs, all_services, s, serialize_mt_unsafe);
rte_atomic_fetch_sub_explicit(&s->num_mapped_cores, 1, rte_memory_order_relaxed);
@@ -485,7 +483,6 @@ static int32_t
service_runner_func(void *arg)
{
RTE_SET_USED(arg);
- uint8_t i;
const int lcore = rte_lcore_id();
struct core_state *cs = &lcore_states[lcore];
@@ -497,20 +494,11 @@ service_runner_func(void *arg)
*/
while (rte_atomic_load_explicit(&cs->runstate, rte_memory_order_acquire) ==
RUNSTATE_RUNNING) {
+ ssize_t id;
- const uint64_t service_mask = cs->service_mask;
- uint8_t start_id;
- uint8_t end_id;
-
- if (service_mask == 0)
- continue;
-
- start_id = rte_ctz64(service_mask);
- end_id = 64 - rte_clz64(service_mask);
-
- for (i = start_id; i < end_id; i++) {
+ RTE_BITSET_FOREACH_SET(id, cs->mapped_services, RTE_SERVICE_NUM_MAX) {
/* return value ignored as no change to code flow */
- service_run(i, cs, service_mask, service_get(i), 1);
+ service_run(id, cs, cs->mapped_services, service_get(id), 1);
}
rte_atomic_store_explicit(&cs->loops, cs->loops + 1, rte_memory_order_relaxed);
@@ -519,8 +507,7 @@ service_runner_func(void *arg)
/* Switch off this core for all services, to ensure that future
* calls to may_be_active() know this core is switched off.
*/
- for (i = 0; i < RTE_SERVICE_NUM_MAX; i++)
- cs->service_active_on_lcore[i] = 0;
+ rte_bitset_clear_all(cs->service_active_on_lcore, RTE_SERVICE_NUM_MAX);
/* Use SEQ CST memory ordering to avoid any re-ordering around
* this store, ensuring that once this store is visible, the service
@@ -586,7 +573,7 @@ rte_service_lcore_count_services(uint32_t lcore)
if (!cs->is_service_core)
return -ENOTSUP;
- return rte_popcount64(cs->service_mask);
+ return rte_bitset_count_set(cs->mapped_services, RTE_SERVICE_NUM_MAX);
}
int32_t
@@ -639,25 +626,23 @@ service_update(uint32_t sid, uint32_t lcore, uint32_t *set, uint32_t *enabled)
!lcore_states[lcore].is_service_core)
return -EINVAL;
- uint64_t sid_mask = UINT64_C(1) << sid;
if (set) {
- uint64_t lcore_mapped = lcore_states[lcore].service_mask &
- sid_mask;
+ uint64_t lcore_mapped = rte_bitset_test(lcore_states[lcore].mapped_services, sid);
if (*set && !lcore_mapped) {
- lcore_states[lcore].service_mask |= sid_mask;
+ rte_bitset_set(lcore_states[lcore].mapped_services, sid);
rte_atomic_fetch_add_explicit(&rte_services[sid].num_mapped_cores,
1, rte_memory_order_relaxed);
}
if (!*set && lcore_mapped) {
- lcore_states[lcore].service_mask &= ~(sid_mask);
+ rte_bitset_clear(lcore_states[lcore].mapped_services, sid);
rte_atomic_fetch_sub_explicit(&rte_services[sid].num_mapped_cores,
1, rte_memory_order_relaxed);
}
}
if (enabled)
- *enabled = !!(lcore_states[lcore].service_mask & (sid_mask));
+ *enabled = rte_bitset_test(lcore_states[lcore].mapped_services, sid);
return 0;
}
@@ -699,11 +684,11 @@ set_lcore_state(uint32_t lcore, int32_t state)
int32_t
rte_service_lcore_reset_all(void)
{
- /* loop over cores, reset all to mask 0 */
+ /* loop over cores, reset all mapped services */
uint32_t i;
for (i = 0; i < RTE_MAX_LCORE; i++) {
if (lcore_states[i].is_service_core) {
- lcore_states[i].service_mask = 0;
+ rte_bitset_clear_all(lcore_states[i].mapped_services, RTE_SERVICE_NUM_MAX);
set_lcore_state(i, ROLE_RTE);
/* runstate act as guard variable Use
* store-release memory order here to synchronize
@@ -731,7 +716,7 @@ rte_service_lcore_add(uint32_t lcore)
set_lcore_state(lcore, ROLE_SERVICE);
/* ensure that after adding a core the mask and state are defaults */
- lcore_states[lcore].service_mask = 0;
+ rte_bitset_clear_all(lcore_states[lcore].mapped_services, RTE_SERVICE_NUM_MAX);
/* Use store-release memory order here to synchronize with
* load-acquire in runstate read functions.
*/
@@ -814,12 +799,11 @@ rte_service_lcore_stop(uint32_t lcore)
uint32_t i;
struct core_state *cs = &lcore_states[lcore];
- uint64_t service_mask = cs->service_mask;
for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) {
- int32_t enabled = service_mask & (UINT64_C(1) << i);
- int32_t service_running = rte_service_runstate_get(i);
- int32_t only_core = (1 ==
+ bool enabled = rte_bitset_test(cs->mapped_services, i);
+ bool service_running = rte_service_runstate_get(i);
+ bool only_core = (1 ==
rte_atomic_load_explicit(&rte_services[i].num_mapped_cores,
rte_memory_order_relaxed));
--
2.34.1
next prev parent reply other threads:[~2024-02-16 10:31 UTC|newest]
Thread overview: 114+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 13:13 [RFC v3] eal: add bitset type Mattias Rönnblom
2024-01-31 16:02 ` Stephen Hemminger
2024-01-31 16:28 ` Mattias Rönnblom
2024-01-31 16:06 ` Stephen Hemminger
2024-01-31 18:45 ` Mattias Rönnblom
2024-02-01 8:04 ` Morten Brørup
2024-02-02 10:19 ` Mattias Rönnblom
2024-02-02 12:42 ` Morten Brørup
2024-02-16 10:23 ` [RFC v4 1/4] " Mattias Rönnblom
2024-02-16 10:23 ` [RFC v4 2/4] eal: add bitset test suite Mattias Rönnblom
2024-02-16 10:23 ` Mattias Rönnblom [this message]
2024-02-16 10:23 ` [RFC v4 4/4] event/dsw: optimize serving port logic Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 1/6] eal: add bitset type Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 2/6] eal: add bitset test suite Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 3/6] eal: add atomic bitset functions Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 4/6] eal: add unit tests for atomic bitset operations Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 5/6] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-05-05 7:33 ` [RFC v5 6/6] event/dsw: optimize serving port logic Mattias Rönnblom
2024-08-09 20:14 ` [PATCH 1/6] eal: add bitset type Mattias Rönnblom
2024-08-09 20:14 ` [PATCH 2/6] eal: add bitset test suite Mattias Rönnblom
2024-09-12 4:51 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 3/6] eal: add atomic bitset functions Mattias Rönnblom
2024-09-12 4:51 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 4/6] eal: add unit tests for atomic bitset operations Mattias Rönnblom
2024-09-12 4:52 ` Tyler Retzlaff
2024-10-09 20:29 ` Morten Brørup
2024-08-09 20:14 ` [PATCH 5/6] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-09-12 4:52 ` Tyler Retzlaff
2024-08-09 20:14 ` [PATCH 6/6] event/dsw: add support for larger port count Mattias Rönnblom
2024-09-12 4:53 ` Tyler Retzlaff
2024-08-20 17:09 ` [PATCH 1/6] eal: add bitset type Mattias Rönnblom
2024-09-02 13:55 ` Morten Brørup
2024-09-02 14:46 ` Mattias Rönnblom
2024-09-02 14:49 ` Mattias Rönnblom
2024-09-12 4:51 ` Tyler Retzlaff
2024-09-17 9:36 ` [PATCH v7 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-10-03 16:47 ` Robin Jarry
2024-10-04 7:31 ` Mattias Rönnblom
2024-10-04 8:05 ` Robin Jarry
2024-10-04 8:40 ` Mattias Rönnblom
2024-10-04 11:51 ` Robin Jarry
2024-10-04 12:19 ` Thomas Monjalon
2024-10-06 8:55 ` Mattias Rönnblom
2024-10-06 9:47 ` Mattias Rönnblom
2024-10-06 12:25 ` Robin Jarry
2024-10-06 13:09 ` Robin Jarry
2024-10-06 14:17 ` Mattias Rönnblom
2024-10-06 15:58 ` Robin Jarry
2024-10-10 10:24 ` Mattias Rönnblom
2024-10-10 10:39 ` Bruce Richardson
2024-09-20 10:47 ` [PATCH v12 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 5/7] eal: add atomic " Mattias Rönnblom
2024-09-20 10:47 ` [PATCH v12 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-10-10 10:45 ` David Marchand
2024-10-10 11:55 ` Mattias Rönnblom
2024-10-10 12:14 ` David Marchand
2024-10-10 12:35 ` Mattias Rönnblom
2024-10-10 13:07 ` Thomas Monjalon
2024-10-11 8:35 ` David Marchand
2024-10-11 15:06 ` Morten Brørup
2024-10-11 15:11 ` David Marchand
2024-10-11 15:15 ` Morten Brørup
2024-10-11 15:18 ` David Marchand
2024-09-20 10:47 ` [PATCH v12 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-10-09 20:18 ` [PATCH v12 0/7] Improve EAL bit operations API David Marchand
2024-09-20 6:24 ` [PATCH v11 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 5/7] eal: add atomic " Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-20 6:24 ` [PATCH v11 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 5/7] eal: add atomic " Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-19 19:31 ` [PATCH v10 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 4/6] eal: add atomic " Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-18 9:04 ` [PATCH v9 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 4/6] eal: add atomic " Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-17 10:48 ` [PATCH v8 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 4/6] eal: add atomic " Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-17 9:36 ` [PATCH v7 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-10-10 8:30 ` [PATCH v2 0/4] Add bitset type David Marchand
2024-10-10 8:30 ` [PATCH v2 1/4] eal: add " David Marchand
2024-10-11 9:35 ` Mattias Rönnblom
2024-10-16 11:30 ` David Marchand
2024-10-16 13:37 ` Mattias Rönnblom
2024-10-10 8:30 ` [PATCH v2 2/4] bitset: add atomic functions David Marchand
2024-10-10 8:30 ` [PATCH v2 3/4] service: use multi-word bitset to represent service flags David Marchand
2024-10-10 8:30 ` [PATCH v2 4/4] event/dsw: add support for larger port count David Marchand
2024-10-14 15:08 ` [PATCH v2 0/4] Add bitset type David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240216102348.480407-3-mattias.ronnblom@ericsson.com \
--to=mattias.ronnblom@ericsson.com \
--cc=dev@dpdk.org \
--cc=harry.van.haaren@intel.com \
--cc=hofors@lysator.liu.se \
--cc=mb@smartsharesystems.com \
--cc=roretzla@linux.microsoft.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).