forked from iqiyi/dpvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_data.c
98 lines (82 loc) · 2.39 KB
/
global_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2021 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <string.h>
#include <rte_cycles.h>
#include "global_data.h"
char *dpvs_pid_file;
char *dpvs_ipc_file;
char *dpvs_conf_file;
RTE_DEFINE_PER_LCORE(uint32_t, g_dpvs_poll_tick);
unsigned int g_version;
uint64_t g_cycles_per_sec;
dpvs_lcore_role_t g_lcore_role[DPVS_MAX_LCORE];
int g_lcore_index2id[DPVS_MAX_LCORE];
int g_lcore_id2index[DPVS_MAX_LCORE];
int g_lcore_num;
lcoreid_t g_master_lcore_id;
lcoreid_t g_kni_lcore_id = 0; /* By default g_kni_lcore_id is 0 and it indicates KNI core is not configured. */
uint8_t g_slave_lcore_num;
uint8_t g_isol_rx_lcore_num;
uint64_t g_slave_lcore_mask;
uint64_t g_isol_rx_lcore_mask;
int global_data_init(void)
{
int i;
g_cycles_per_sec = rte_get_timer_hz();
g_lcore_num = 0;
for (i = 0; i < DPVS_MAX_LCORE; i++) {
g_lcore_role[i] = LCORE_ROLE_IDLE;
g_lcore_index2id[i] = -1;
g_lcore_id2index[i] = -1;
}
return EDPVS_OK;
}
int version_parse(const char *strver)
{
int i, j = 0;
size_t len;
unsigned int version = 0, mask = 0xFF;
char *sver;
if (strver[0] == 'v' || strver[0] == 'V') {
sver = strdup(&strver[1]);
len = strlen(&strver[1]);
} else {
sver = strdup(strver);
len = strlen(strver);
}
if (unlikely(sver == NULL))
return 0;
for (i = 0; i < len && mask < 0xFFFFFF; i++) {
if ('.' == sver[i] || '-' == sver[i]) {
sver[i] = '\0';
version = ((version << 8) | atoi(&sver[j])) & mask;
mask |= mask << 8;
j = i + 1;
continue;
}
if (!isdigit(sver[i]))
break;
}
version = ((version << 8) | atoi(&sver[j])) & mask;
free(sver);
return version;
}
int global_data_term(void)
{
return EDPVS_OK;
}