OCT 1. 优化vCPE BRAS后线程linux系统文件描述符fd资源占用 1100+->300+
This commit is contained in:
parent
701d9ac1f0
commit
f262e748ea
|
@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
|
|||
INCLUDE(CMakeDependentOption)
|
||||
|
||||
OPTION(VCPE_AGENT "Enable vCPE agent test application" OFF)
|
||||
OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" OFF)
|
||||
OPTION(VCPE_PPPOE "Enable vCPE work befof PPPoE mode" OFF)
|
||||
OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF)
|
||||
OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF)
|
||||
OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF)
|
||||
|
@ -18,6 +18,8 @@ INCLUDE(system_libs)
|
|||
SET(VCPE_VERSION "1.0.1")
|
||||
PROJECT(vCPE VERSION "${VCPE_VERSION}")
|
||||
CMAKE_DEPENDENT_OPTION(USED_HTTP_SVR "Build-in http(s) server support" ON "USED_OPENDHCPD OR USED_OPENDHCPDDNS" OFF)
|
||||
CMAKE_DEPENDENT_OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" ON "VCPE_PPPOE" OFF)
|
||||
CMAKE_DEPENDENT_OPTION(USED_ZMQ "ZeroMQ support for vCPE" ON "VCPE_PPPOE" OFF)
|
||||
|
||||
# 数据库开关
|
||||
OPTION(USED_REDIS "Add redis database support for vCPE" OFF)
|
||||
|
@ -96,6 +98,16 @@ IF (USED_HTTP_SVR)
|
|||
MESSAGE("Select Option USED_HTTP_SVR")
|
||||
ENDIF ()
|
||||
|
||||
IF (USED_ZMQ)
|
||||
LIST(APPEND COMMON_DEFINE "-DZEROMQ_ON")
|
||||
MESSAGE("Select Option USED_ZMQ")
|
||||
ENDIF ()
|
||||
|
||||
IF (VCPE_PPPOE)
|
||||
LIST(APPEND COMMON_DEFINE "-DPPPOE_ON")
|
||||
MESSAGE("Select Option VCPE_PPPOE")
|
||||
ENDIF ()
|
||||
|
||||
IF (USED_LWIP)
|
||||
LIST(APPEND COMMON_DEFINE "-DLWIP_ON")
|
||||
MESSAGE("Select Option USED_LWIP")
|
||||
|
|
|
@ -16,7 +16,7 @@ SET(CMAKE_C_STANDARD 99)
|
|||
FILE(GLOB VCPE_HEADS include/*.h include/uthash/*.h include/s2j/*.h
|
||||
./httpserver/include/*.h ./httpserver/src/haywire/*.h ./httpserver/src/haywire/configuration/*.h)
|
||||
|
||||
IF (USED_LWIP)
|
||||
IF (VCPE_PPPOE)
|
||||
AUX_SOURCE_DIRECTORY(pppoe VCPE_SRC)
|
||||
AUX_SOURCE_DIRECTORY(user VCPE_SRC)
|
||||
ENDIF ()
|
||||
|
|
|
@ -17,7 +17,9 @@ AUX_SOURCE_DIRECTORY(banner C_SRC)
|
|||
AUX_SOURCE_DIRECTORY(configure C_SRC)
|
||||
AUX_SOURCE_DIRECTORY(network C_SRC)
|
||||
AUX_SOURCE_DIRECTORY(task C_SRC)
|
||||
IF (USED_ZMQ)
|
||||
AUX_SOURCE_DIRECTORY(mq C_SRC)
|
||||
ENDIF ()
|
||||
AUX_SOURCE_DIRECTORY(cmdline C_SRC)
|
||||
AUX_SOURCE_DIRECTORY(crypto C_SRC)
|
||||
AUX_SOURCE_DIRECTORY(hardware C_SRC)
|
||||
|
|
|
@ -98,10 +98,12 @@ static CFG_ITEM g_cfgItem[] = {
|
|||
DEF_CFG_ITEM(CFG_DB_SQLITE_DB_NAME, "database.sqlite_dbname", VAL_STR, "", "SQLite3 database file name"),
|
||||
DEF_CFG_ITEM(CFG_DB_SQLITE_PASSWD, "database.sqlite_passwd", VAL_STR, ".main", "SQLite3 database password"),
|
||||
#endif
|
||||
#ifdef ZEROMQ_ON
|
||||
/* 消息队列相配置 */
|
||||
/* ZeroMq配置 */
|
||||
DEF_CFG_ITEM(CFG_MQ_SVR_PORT, "zero_mq.svr_port", VAL_INT, "6278", "ZeroMQ server port"),
|
||||
DEF_CFG_ITEM(CFG_MQ_DATA_PATH, "zero_mq.agent_addr", VAL_STR, "ipc:///tmp/msg_fifo0", "ZeroMQ Agent data path"),
|
||||
#endif
|
||||
/* vxLan 隧道配置 */
|
||||
DEF_CFG_ITEM(CFG_VXLAN_NIC_NAME, "vxlan_wan.nic", VAL_STR, "", "Network card name to send data"),
|
||||
DEF_CFG_ITEM(CFG_VXLAN_SUPPORT, "vxlan_wan.enable", VAL_BOOL, "1", "Is support vxLan tune"),
|
||||
|
|
|
@ -183,6 +183,7 @@ const char *cfg_get_mysql_database() {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef ZEROMQ_ON
|
||||
int cfg_get_zero_mq_port() {
|
||||
return (unsigned short)cfg_get_integral_value(CFG_MQ_SVR_PORT);
|
||||
}
|
||||
|
@ -190,3 +191,4 @@ int cfg_get_zero_mq_port() {
|
|||
const char *cfg_get_zero_mq_data_path() {
|
||||
return cfg_get_string_value(CFG_MQ_DATA_PATH);
|
||||
}
|
||||
#endif
|
|
@ -135,25 +135,7 @@ static void cpuUsedRefresh() {
|
|||
}
|
||||
}
|
||||
|
||||
_Noreturn void cpuCalcCb(void *UNUSED(pArg)) {
|
||||
do {
|
||||
unsigned int period = cfg_get_cpu_refresh_period();
|
||||
|
||||
if (cfg_get_watch_cpu()) {
|
||||
cpuUsedRefresh();
|
||||
}
|
||||
|
||||
if (period < REFRESH_MAX_PERIOD && period >= 1) {
|
||||
uv_sleep(1000 * period);
|
||||
} else {
|
||||
uv_sleep(1000);
|
||||
}
|
||||
} while (TRUE);
|
||||
}
|
||||
|
||||
int cpu_watch_init() {
|
||||
static uv_thread_t uvThread;
|
||||
|
||||
memset(&g_cpuInfo, 0, sizeof(CPU_INFO));
|
||||
|
||||
g_cpuInfo.nCpus = get_cpu_number();
|
||||
|
@ -163,9 +145,6 @@ int cpu_watch_init() {
|
|||
get_cpu_desc(&g_cpuInfo.cpuCoreDesc);
|
||||
|
||||
g_isInit = TRUE;
|
||||
|
||||
uv_thread_create(&uvThread, cpuCalcCb, NULL);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -184,6 +163,8 @@ int get_cpu_info(PCPU_INFO pInfo) {
|
|||
get_cpu_desc(&g_cpuInfo.cpuCoreDesc);
|
||||
|
||||
g_isInit = TRUE;
|
||||
} else if (cfg_get_watch_cpu()) {
|
||||
cpuUsedRefresh();
|
||||
}
|
||||
|
||||
memcpy(pInfo, &g_cpuInfo, sizeof(CPU_INFO));
|
||||
|
|
|
@ -105,6 +105,10 @@ int get_disk_info(PDISK_INFO pInfo) {
|
|||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
if (cfg_get_watch_disk()) {
|
||||
disk_info_refresh();
|
||||
}
|
||||
|
||||
uv_rwlock_rdlock(&g_uvLock);
|
||||
pInfo->nItems = HASH_COUNT(g_diskPartInfo);
|
||||
pInfo->timestamp = time(NULL);
|
||||
|
@ -122,32 +126,12 @@ int get_disk_info(PDISK_INFO pInfo) {
|
|||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
_Noreturn void diskRefreshCb(void *UNUSED(pArg)) {
|
||||
do {
|
||||
unsigned int period = cfg_get_disk_refresh_period();
|
||||
|
||||
if (cfg_get_watch_disk()) {
|
||||
disk_info_refresh();
|
||||
}
|
||||
|
||||
if (period < REFRESH_MAX_PERIOD && period >= 1) {
|
||||
uv_sleep(1000 * period);
|
||||
} else {
|
||||
uv_sleep(1000);
|
||||
}
|
||||
} while (TRUE);
|
||||
}
|
||||
|
||||
int disk_watch_info() {
|
||||
static uv_thread_t uvThread;
|
||||
|
||||
uv_rwlock_init(&g_uvLock);
|
||||
|
||||
if (disk_info_refresh() != ERR_SUCCESS) {
|
||||
return -ERR_SYS_DISK_GET_INFO;
|
||||
}
|
||||
|
||||
uv_thread_create(&uvThread, diskRefreshCb, NULL);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
|
@ -9,51 +9,48 @@
|
|||
#include "user_errno.h"
|
||||
#include "config.h"
|
||||
#include "misc.h"
|
||||
#include "task_manager.h"
|
||||
|
||||
static HARDWARE_INFO g_hardwareInfo;
|
||||
|
||||
_Noreturn void hardwareRefreshCb(void *UNUSED(pArg)) {
|
||||
do {
|
||||
unsigned int period = cfg_get_hardware_refresh_period();
|
||||
|
||||
void hardwareRefreshCb(uv_timer_t *UNUSED(pArg)) {
|
||||
if (cfg_get_watch_sensor()) {
|
||||
get_sensor_info(&g_hardwareInfo.sensorInfo);
|
||||
}
|
||||
|
||||
if (cfg_get_watch_disk()) {
|
||||
get_disk_info(&g_hardwareInfo.diskInfo);
|
||||
}
|
||||
|
||||
if (cfg_get_watch_cpu()) {
|
||||
get_cpu_info(&g_hardwareInfo.cpuInfo);
|
||||
}
|
||||
|
||||
if (cfg_get_watch_memory()) {
|
||||
get_memory_info(&g_hardwareInfo.memInfo);
|
||||
}
|
||||
|
||||
if (period < REFRESH_MAX_PERIOD && period >= 1) {
|
||||
uv_sleep(1000 * period);
|
||||
} else {
|
||||
uv_sleep(1000);
|
||||
}
|
||||
|
||||
uv_sleep(1000);
|
||||
} while (TRUE);
|
||||
printf("%s\n", get_hardware_json());
|
||||
}
|
||||
|
||||
int init_hardware() {
|
||||
static uv_thread_t uvThread;
|
||||
static uv_timer_t uvTm;
|
||||
unsigned int period = cfg_get_hardware_refresh_period();
|
||||
|
||||
if (period >= REFRESH_MAX_PERIOD) {
|
||||
period = 10000;
|
||||
} else {
|
||||
period *= 1000;
|
||||
}
|
||||
|
||||
uv_timer_init(get_task_manager(), &uvTm);
|
||||
|
||||
memset(&g_hardwareInfo, 0, sizeof(HARDWARE_INFO));
|
||||
|
||||
uv_thread_create(&uvThread, hardwareRefreshCb, NULL);
|
||||
|
||||
cpu_watch_init();
|
||||
memory_watch_init();
|
||||
disk_watch_info();
|
||||
sensor_watch_init();
|
||||
|
||||
uv_timer_start(&uvTm, hardwareRefreshCb, period, period);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
//#define CMD_SENSOR_INFO ("ipmitool sensor | awk '{gsub(/\|/, \"\"); print $0}'")
|
||||
#define CMD_SENSOR_INFO ("ipmitool sensor")
|
||||
#define CMD_IPMITOOL_ENABLE ("whereis ipmitool | awk '{print $2}'")
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_SENSOR_STR]; ///< 传感器名称
|
||||
|
@ -42,9 +43,16 @@ static int sensor_info_refresh() {
|
|||
int errCode = ERR_SUCCESS;
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
char *pRet = NULL;
|
||||
|
||||
if (shell_with_output(CMD_IPMITOOL_ENABLE, &pRet) != ERR_SUCCESS || pRet == NULL || strlen(pRet) == 0) {
|
||||
if (pRet) {
|
||||
free(pRet);
|
||||
}
|
||||
return -ERR_ITEM_UNEXISTS;
|
||||
}
|
||||
|
||||
fp = popen(CMD_SENSOR_INFO, "r");
|
||||
|
||||
if (fp == NULL) {
|
||||
return -ERR_OPEN_FILE;
|
||||
}
|
||||
|
@ -132,6 +140,10 @@ int get_sensor_info(PSENSOR_INFO pInfo) {
|
|||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
if (cfg_get_watch_sensor()) {
|
||||
sensor_info_refresh();
|
||||
}
|
||||
|
||||
uv_rwlock_rdlock(&g_uvLock);
|
||||
pInfo->nItems = HASH_COUNT(g_pSensorInfo);
|
||||
pInfo->timestamp = time(NULL);
|
||||
|
@ -149,25 +161,7 @@ int get_sensor_info(PSENSOR_INFO pInfo) {
|
|||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
_Noreturn void sensorRefreshCb(void *UNUSED(pArg)) {
|
||||
do {
|
||||
unsigned int period = cfg_get_sensor_refresh_period();
|
||||
|
||||
if (cfg_get_watch_sensor()) {
|
||||
sensor_info_refresh();
|
||||
}
|
||||
|
||||
if (period < REFRESH_MAX_PERIOD && period >= 1) {
|
||||
uv_sleep(1000 * period);
|
||||
} else {
|
||||
uv_sleep(1000);
|
||||
}
|
||||
} while (TRUE);
|
||||
}
|
||||
|
||||
int sensor_watch_init() {
|
||||
|
||||
static uv_thread_t uvThread;
|
||||
int i, devOk = FALSE;
|
||||
int n = ARRAY_SIZE(g_ipmiDev);
|
||||
|
||||
|
@ -188,7 +182,5 @@ int sensor_watch_init() {
|
|||
return -ERR_SYS_SENSOR_GET_INFO;
|
||||
}
|
||||
|
||||
uv_thread_create(&uvThread, sensorRefreshCb, NULL);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
|
@ -95,33 +95,13 @@ static int memory_info_refresh() {
|
|||
return errCode;
|
||||
}
|
||||
|
||||
_Noreturn void memRefreshCb(void *UNUSED(pArg)) {
|
||||
do {
|
||||
unsigned int period = cfg_get_mem_refresh_period();
|
||||
|
||||
if (cfg_get_watch_memory()) {
|
||||
memory_info_refresh();
|
||||
}
|
||||
|
||||
if (period < REFRESH_MAX_PERIOD && period >= 1) {
|
||||
uv_sleep(1000 * period);
|
||||
} else {
|
||||
uv_sleep(1000);
|
||||
}
|
||||
} while (TRUE);
|
||||
}
|
||||
|
||||
int memory_watch_init() {
|
||||
static uv_thread_t uvThread;
|
||||
|
||||
uv_rwlock_init(&g_uvLock);
|
||||
|
||||
if (memory_info_refresh() != ERR_SUCCESS) {
|
||||
return -ERR_SYS_DISK_GET_INFO;
|
||||
}
|
||||
|
||||
uv_thread_create(&uvThread, memRefreshCb, NULL);
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -142,6 +122,10 @@ int get_memory_info(PMEMORY_INFO pInfo) {
|
|||
return -ERR_INPUT_PARAMS;
|
||||
}
|
||||
|
||||
if (cfg_get_watch_memory()) {
|
||||
memory_info_refresh();
|
||||
}
|
||||
|
||||
uv_rwlock_rdlock(&g_uvLock);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
|
|
|
@ -61,8 +61,10 @@ typedef enum {
|
|||
CFG_DB_SQLITE_DB_NAME,
|
||||
CFG_DB_SQLITE_PASSWD,
|
||||
#endif
|
||||
#ifdef ZEROMQ_ON
|
||||
CFG_MQ_SVR_PORT,
|
||||
CFG_MQ_DATA_PATH,
|
||||
#endif
|
||||
CFG_VXLAN_NIC_NAME,
|
||||
CFG_VXLAN_SUPPORT,
|
||||
CFG_VXLAN_PEER_IP,
|
||||
|
|
|
@ -134,7 +134,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
|
|||
if (cfg_get_hardware_watch_enable()) {
|
||||
init_hardware();
|
||||
}
|
||||
|
||||
#ifdef ZEROMQ_ON
|
||||
if ((ret = mq_init()) != ERR_SUCCESS) {
|
||||
LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret);
|
||||
}
|
||||
|
@ -142,6 +142,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
|
|||
if ((ret = mq_data_init()) != ERR_SUCCESS) {
|
||||
LOG_MOD(error, ZLOG_MOD_INIT, "Message queue init error: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
#ifdef HTTPSERVER_ON
|
||||
http_svr_init();
|
||||
#endif
|
||||
|
@ -156,7 +157,9 @@ void user_uninit() {
|
|||
#ifdef HTTPSERVER_ON
|
||||
http_svr_uinit();
|
||||
#endif
|
||||
#ifdef ZEROMQ_ON
|
||||
mq_uninit();
|
||||
#endif
|
||||
zlog_fini();
|
||||
uninit_config_system();
|
||||
uv_loop_close(get_task_manager());
|
||||
|
|
Loading…
Reference in New Issue