2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 #define CM_N_BITS (sizeof(prox_cfg.core_mask[0]) * 8)
23 #define CM_ALL_N_BITS (sizeof(prox_cfg.core_mask) * 8)
25 struct prox_cfg prox_cfg = {
26 .update_interval_str = "1"
29 static int prox_cm_isset(const uint32_t lcore_id)
34 if (lcore_id > CM_ALL_N_BITS)
37 cm = __UINT64_C(1) << (lcore_id % CM_N_BITS);
38 cm_idx = PROX_CM_DIM - 1 - lcore_id / CM_N_BITS;
39 return !!(prox_cfg.core_mask[cm_idx] & cm);
42 int prox_core_active(const uint32_t lcore_id, const int with_master)
46 ret = prox_cm_isset(lcore_id);
51 return ret || lcore_id == prox_cfg.master;
53 return ret && lcore_id != prox_cfg.master;
56 int prox_core_next(uint32_t* lcore_id, const int with_master)
58 for (uint32_t i = *lcore_id + 1; i < CM_ALL_N_BITS; ++i) {
59 if (prox_core_active(i, with_master)) {
67 int prox_core_to_hex(char *dst, const size_t size, const int with_master)
71 uint32_t cm_first = 0;
72 uint32_t master = prox_cfg.master;
74 /* Minimum size of the string has to big enough to hold the
75 bitmask in hex (including the prefix "0x"). */
76 if (size < PROX_CM_STR_LEN)
79 snprintf(dst, size, "0x");
80 for (uint32_t i = 0; i < PROX_CM_DIM; ++i, cm_first = i) {
81 if ((with_master && ((CM_ALL_N_BITS - 1 - master) / CM_N_BITS == i * CM_N_BITS)) ||
82 prox_cfg.core_mask[i]) {
87 for (uint32_t i = cm_first; i < PROX_CM_DIM; ++i) {
88 cm = prox_cfg.core_mask[i];
89 if (with_master && ((CM_ALL_N_BITS - 1 - master) / CM_N_BITS == i)) {
90 cm |= (__UINT64_C(1) << (master % CM_N_BITS));
93 snprintf(dst + strlen(dst), size - strlen(dst), i == cm_first? "%lx" : "%016lx", cm);
99 int prox_core_to_str(char *dst, const size_t size, const int with_master)
101 uint32_t lcore_id = -1;
106 while (prox_core_next(&lcore_id, with_master) == 0) {
107 /* Stop printing to string if there is not engough
108 space left. Assume that adding 1 core to the string
109 will take at most 5 + 1 bytes implying that
110 lcore_id < 999. Check if ther is space for another
111 6 bytes to add an elipsis */
112 if (12 + strlen(dst) > size) {
113 if (6 + strlen(dst) > size) {
114 snprintf(dst + strlen(dst), size - strlen(dst), ", ...");
120 snprintf(dst + strlen(dst), size - strlen(dst), first? "%u" : ", %u", lcore_id);
127 void prox_core_clr(void)
129 memset(prox_cfg.core_mask, 0, sizeof(prox_cfg.core_mask));
132 int prox_core_set_active(const uint32_t lcore_id)
137 if (lcore_id > CM_ALL_N_BITS)
140 cm = __UINT64_C(1) << (lcore_id % CM_N_BITS);
141 cm_idx = PROX_CM_DIM - 1 - lcore_id / CM_N_BITS;
142 prox_cfg.core_mask[cm_idx] |= cm;