MCPcopy Create free account
hub / github.com/F-Stack/f-stack / parse_lcore_mask

Function parse_lcore_mask

lib/ff_config.c:71–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71static int
72parse_lcore_mask(struct ff_config *cfg, const char *coremask)
73{
74 int i, j, idx = 0, shift = 0, zero_num = 0;
75 int count = 0;
76 char c;
77 int val;
78 uint16_t *proc_lcore;
79 char buf[RTE_MAX_LCORE] = {0};
80 char zero[RTE_MAX_LCORE] = {0};
81
82 if (coremask == NULL)
83 return 0;
84
85 cfg->dpdk.proc_lcore = (uint16_t *)calloc(RTE_MAX_LCORE, sizeof(uint16_t));
86 if (cfg->dpdk.proc_lcore == NULL) {
87 fprintf(stderr, "parse_lcore_mask malloc failed\n");
88 return 0;
89 }
90 proc_lcore = cfg->dpdk.proc_lcore;
91
92 /*
93 * Remove all blank characters ahead and after.
94 * Remove 0x/0X if exists.
95 */
96 while (isblank(*coremask))
97 coremask++;
98 if (coremask[0] == '0' && ((coremask[1] == 'x')
99 || (coremask[1] == 'X')))
100 coremask += 2;
101
102 i = strlen(coremask);
103 while ((i > 0) && isblank(coremask[i - 1]))
104 i--;
105
106 if (i == 0)
107 return 0;
108
109 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
110 c = coremask[i];
111 if (isxdigit(c) == 0) {
112 return 0;
113 }
114 val = xdigit2val(c);
115 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++) {
116 if ((1 << j) & val) {
117 proc_lcore[count] = idx;
118 if (cfg->dpdk.proc_id == count) {
119 zero_num = idx >> 2;
120 shift = idx & 0x3;
121 memset(zero,'0',zero_num);
122 snprintf(buf, sizeof(buf) - 1, "%llx%s",
123 (unsigned long long)1<<shift, zero);
124 cfg->dpdk.proc_mask = strdup(buf);
125 }
126 count++;
127 }
128 }

Callers 1

ini_parse_handlerFunction · 0.85

Calls 7

callocFunction · 0.85
isblankFunction · 0.85
isxdigitFunction · 0.85
memsetFunction · 0.85
snprintfFunction · 0.85
strdupFunction · 0.85
xdigit2valFunction · 0.70

Tested by

no test coverage detected