[Feature][ZXW-303]Optimize the CPU usage of the qser_data_call_info_get interface
Only Configure: No
Affected branch: master
Affected module: data
Is it affected on both ZXIC and MTK: both
Self-test: Yes
Doc Update: No
Change-Id: If8e058b99240f31b647dc97f382b90b7629704bb
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data.cpp
index 7b29791..1cfea66 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data.cpp
@@ -17,6 +17,7 @@
#include <errno.h>
#include <vector>
#include "lynq_data_urc.h"
+#include "lynq_data_list_buffer.h"
#define LYNQ_SERVICE_PORT 8088
#define LYNQ_REC_BUF 8192
@@ -632,6 +633,7 @@
{
case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
LYINFLOG("LIBLYNQ_DATA receive RIL_UNSOL_DATA_CALL_LIST_CHANGED\n");
+ set_list_buffer_valid(false);
p->readInt32(&version);
p->readInt32(&num);
/* update apn start*/
@@ -1024,6 +1026,8 @@
data_timelimit = 0;
lynq_data_call_change_id = -1;
+ init_data_timer_all();
+
result = lynq_socket_client_start();
pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL);
if(result!=0)
@@ -1096,6 +1100,7 @@
pthread_mutex_lock(&s_lynq_urc_vector_mutex);
s_data_urc_wait_list.clear();
pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
+ deinit_data_timer_all();
LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
return 0;
}
@@ -1261,7 +1266,7 @@
}
continue;
}
-
+ set_list_buffer_valid(false);
bzero(type,LYNQ_TYPE_MAX_LEN);
bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
@@ -1677,7 +1682,7 @@
return error;
}
pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
-
+ set_list_buffer_valid(false);
bzero(type,LYNQ_TYPE_MAX_LEN);
bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN);
@@ -2077,7 +2082,12 @@
}
LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
memset(&interDataCallList,0,sizeof(interDataCallList));
- error = getDataCallLists(interDataCallList,&number);
+ if(get_list_from_buf(interDataCallList, &number) != 0)
+ {
+ error = getDataCallLists(interDataCallList, &number);
+ set_list_to_buf(interDataCallList, number);
+ }
+
if(error == 0)
{
for(int i = 0;i < number;i++)
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data_list_buffer.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data_list_buffer.cpp
new file mode 100755
index 0000000..6a1356d
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data_list_buffer.cpp
@@ -0,0 +1,157 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <signal.h>
+#include <time.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <climits>
+#include <stdlib.h>
+#include "liblog/lynq_deflog.h"
+#include "lynq_data.h"
+#include "lynq_data_list_buffer.h"
+#include <include/lynq_uci.h>
+
+#define LOG_UCI_FILE "lynq_uci"
+#define LOG_UCI_MODULE "lynq_data"
+#define USER_LOG_TAG "LYNQ_DATA_BUFFER"
+#define DEFAULT_PERIOD 5 //default 5s
+
+static timer_t s_list_buffer_timer;
+static int s_list_buffer_valid = false;
+static int s_state_buffer_valid_period;
+lynq_data_call_response_v11_t dataCallList_buffer[LYNQ_APN_CHANNEL_MAX];
+static int number_buffer=0;
+
+void start_data_timer(timer_t timer, int milliseconds)
+{
+ LYINFLOG("start_data_timer(), timer_id=%ld, time=%d",(long)timer, milliseconds);
+
+ struct itimerspec expire;
+ expire.it_interval.tv_sec = 0;
+ expire.it_interval.tv_nsec = 0;
+ expire.it_value.tv_sec = milliseconds/1000;
+ expire.it_value.tv_nsec = (milliseconds%1000)*1000000;
+ if (timer_settime(timer, 0, &expire, NULL) == -1) {
+ LYERRLOG("timer_settime failed reason=[%s]", strerror(errno));
+ }
+}
+void stop_data_timer(timer_t timer)
+{
+ LYINFLOG("stop_data_timer(), timer_id=%ld", (long)timer);
+ struct itimerspec timespec;
+ if(timer_gettime(timer, ×pec) == -1) {
+ LYERRLOG("stop_data_timer(), get time fail(%s)", strerror(errno));
+ return;
+ }
+ LYINFLOG("stop_data_timer(), tv_sec=%ld, tv_nsec=%ld",timespec.it_value.tv_sec, timespec.it_value.tv_nsec);
+ if((timespec.it_value.tv_sec == 0) && (timespec.it_value.tv_nsec == 0) ) {
+ LYINFLOG("stop_data_timer(), timer_id(%ld) had stopped, just return", (long)timer);
+ return;
+ } else {
+ start_data_timer(timer, 0);
+ }
+}
+
+void data_timer_handler(sigval_t sig)
+{
+ LYINFLOG("[%s] entry\n",__FUNCTION__);
+ s_list_buffer_valid = false;
+}
+
+int is_period_equal_not_valid(int period)
+{
+ return period<=0 || (period > INT_MAX/1000);
+}
+
+void init_data_timer_all()
+{
+ int ret;
+ char tmp[20]={0};
+ char lynq_state_buffer_valid_period[20]={0};
+ struct sigevent sevp;
+ memset(&sevp, 0, sizeof(sevp));
+ sevp.sigev_notify = SIGEV_THREAD;
+ sevp.sigev_notify_function = data_timer_handler;
+
+ ret = lynq_get_value(LOG_UCI_FILE, LOG_UCI_MODULE, "data_list_valid_period", tmp);
+ LYINFLOG("[%s] ret=%d, tmp is %s", __FUNCTION__, ret, tmp);
+ if(ret == 0)
+ {
+ s_state_buffer_valid_period = atoi(tmp);
+ if(is_period_equal_not_valid(s_state_buffer_valid_period))
+ {
+ s_state_buffer_valid_period = DEFAULT_PERIOD;
+ snprintf(lynq_state_buffer_valid_period,sizeof(lynq_state_buffer_valid_period),"%d",DEFAULT_PERIOD);
+ lynq_set_section(LOG_UCI_MODULE, LOG_UCI_MODULE);
+ lynq_set_value(LOG_UCI_MODULE, "data_list_valid_period", lynq_state_buffer_valid_period);
+ }
+ }
+ else
+ {
+ s_state_buffer_valid_period = DEFAULT_PERIOD;
+ snprintf(lynq_state_buffer_valid_period,sizeof(lynq_state_buffer_valid_period),"%d",DEFAULT_PERIOD);
+ lynq_set_section(LOG_UCI_MODULE, LOG_UCI_MODULE);
+ lynq_set_value(LOG_UCI_MODULE, "data_list_valid_period", lynq_state_buffer_valid_period);
+ }
+ LYINFLOG("[%s] s_state_buffer_valid_period = %d\n", __FUNCTION__, s_state_buffer_valid_period);
+ if(timer_create(CLOCK_MONOTONIC, &sevp, &s_list_buffer_timer) == -1) {
+ LYERRLOG("init_data_timer_all() failed reason=[%s]", strerror(errno));
+ }
+ LYINFLOG("init_data_timer_all(), timer_Id = %ld\n", (long)(s_list_buffer_timer));
+ s_list_buffer_valid = false;
+ return;
+}
+void deinit_data_timer_all()
+{
+ stop_data_timer(s_list_buffer_timer);
+ s_list_buffer_valid = false;
+
+ return;
+}
+
+void set_list_buffer_valid(int valid)
+{
+ LYINFLOG("[%s] entry\n",__FUNCTION__);
+
+ s_list_buffer_valid = valid;
+ if(s_list_buffer_valid==false)
+ {
+ stop_data_timer(s_list_buffer_timer);
+ }
+ else
+ {
+ start_data_timer(s_list_buffer_timer, s_state_buffer_valid_period*1000);
+ }
+ LYINFLOG("[%s] valid is %d",__FUNCTION__,valid);
+ return;
+}
+void set_list_to_buf(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int number)
+{
+ int ret;
+ int i;
+
+ LYINFLOG("[%s] entry\n",__FUNCTION__);
+ number_buffer = number;
+ memcpy(dataCallList_buffer, dataCallList, sizeof(lynq_data_call_response_v11_t)*LYNQ_APN_CHANNEL_MAX);
+ set_list_buffer_valid(true);
+
+ return;
+}
+int get_list_from_buf(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *number)
+{
+ if(s_list_buffer_valid == false)
+ {
+ LYINFLOG("%s buffer not valid",__FUNCTION__);
+ return 1;
+ }
+ *number = number_buffer;
+ memcpy(dataCallList, dataCallList_buffer, sizeof(lynq_data_call_response_v11_t)*LYNQ_APN_CHANNEL_MAX);
+
+ return 0;
+}
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data_list_buffer.h b/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data_list_buffer.h
new file mode 100755
index 0000000..db7b213
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-data/lynq_data_list_buffer.h
@@ -0,0 +1,18 @@
+#ifndef LYNQ_DATA_LIST_BUFFER_H
+#define LYNQ_DATA_LIST_BUFFER_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "lynq_data.h"
+
+void set_list_buffer_valid(int valid);
+void set_list_to_buf(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int number);
+int get_list_from_buf(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *number);
+void init_data_timer_all();
+void deinit_data_timer_all();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-data/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-data/makefile
index c36e038..a0c3e46 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-data/makefile
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-data/makefile
@@ -30,6 +30,7 @@
LOCAL_LIBS := \
-L. \
-ldl \
+ -lrt \
-lstdc++ \
-llog \
-lcutils \
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config b/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config
index aabd1ba..aef436c 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-uci/lynq_uci.config
@@ -40,3 +40,6 @@
config lynq_led_rw 'lynq_led'
option lynq_statusled_on '0'
option lynq_netled_on '0'
+
+config lynq_data 'lynq_data'
+ option data_list_valid_period '5'