[Bugfix][bug-view-1152] Fix the problem of high CPU load on nv instruction

Only Configure:No
Affected branch:master/intest
Affected module:nv
Is it affected on: only ZXIC
Self-test: Yes
Doc Update:No

Change-Id: I4a463a6e46655497b43b0089ed3710a142d2b2ca
diff --git a/ap/app/zte_comm/nvserver/nvserver.c b/ap/app/zte_comm/nvserver/nvserver.c
index fe5ba99..4e240f8 100755
--- a/ap/app/zte_comm/nvserver/nvserver.c
+++ b/ap/app/zte_comm/nvserver/nvserver.c
@@ -146,9 +146,14 @@
         }
         
         analyMsg(&rcvBuf, &sndBuf);
-        
+msgsnd_retry:
         if(-1 == msgsnd(msgId, &sndBuf, sizeof(T_NV_MSG_RESULT) - sizeof(long), 0))
         {
+            if (errno == EINTR)
+            {
+                printf("nvserver error: msgsnd fail, errno = EINTR!\n");
+                goto msgsnd_retry;
+            }
             printf("nvserver error: nvserver msgsnd fail, errno = %d!\n", errno);
             continue;   
         }   
diff --git a/ap/lib/libnvram/libnvram.a b/ap/lib/libnvram/libnvram.a
index 8bcec8c..f8ee1f2 100755
--- a/ap/lib/libnvram/libnvram.a
+++ b/ap/lib/libnvram/libnvram.a
Binary files differ
diff --git a/ap/lib/libnvram/libnvram.so b/ap/lib/libnvram/libnvram.so
index 199b514..9818c67 100755
--- a/ap/lib/libnvram/libnvram.so
+++ b/ap/lib/libnvram/libnvram.so
Binary files differ
diff --git a/ap/lib/libnvram/libnvram_sc.a b/ap/lib/libnvram/libnvram_sc.a
index 4a75c3d..88d24d8 100755
--- a/ap/lib/libnvram/libnvram_sc.a
+++ b/ap/lib/libnvram/libnvram_sc.a
Binary files differ
diff --git a/ap/lib/libnvram/libnvram_sc.so b/ap/lib/libnvram/libnvram_sc.so
index 817cf4c..c4c2700 100755
--- a/ap/lib/libnvram/libnvram_sc.so
+++ b/ap/lib/libnvram/libnvram_sc.so
Binary files differ
diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/nvserver/nvserver.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/nvserver/nvserver.c
index 139ac67..0f79713 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/nvserver/nvserver.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/nvserver/nvserver.c
@@ -337,9 +337,15 @@
         }
         wake_nvserver_lock();
         analyMsg(&rcvBuf, &sndBuf);
-        
+msgsnd_retry:
         if(-1 == msgsnd(msgId, &sndBuf, sizeof(T_NV_MSG_RESULT) - sizeof(long), 0))
         {
+            if (errno == EINTR)
+            {
+                printf("nvserver error: msgsnd fail, errno = EINTR!\n");
+                goto msgsnd_retry;
+            }
+            wake_nvserver_unlock();
             printf("nvserver error: nvserver msgsnd fail, errno = %d!\n", errno);
             continue;   
         }
diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/sdk/libnvram/nv_api.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/sdk/libnvram/nv_api.c
index 2b643da..d444b46 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/sdk/libnvram/nv_api.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/sdk/libnvram/nv_api.c
@@ -399,6 +399,31 @@
 

     return 0;

 }

+int clear_msg_queue(int msgId, T_NV_MSG_RESULT *msgRcv, long msg_type)

+{

+    while (1)

+    {

+        ssize_t ret = msgrcv(msgId, msgRcv, sizeof(T_NV_MSG_RESULT) - sizeof(long), msg_type, IPC_NOWAIT);

+        if (ret == -1)

+        {

+            if (errno == ENOMSG)

+            {

+                break;

+            }

+            else if (errno == EINTR)

+            {

+                continue;

+            }

+            else

+            {

+                perror("[libnvram]clear_msg_queue msgrcv");

+                return -1;

+            }

+        }

+    }

+

+    return 0;

+}

 

 /*******************************************************************************

 * ¹¦ÄÜÃèÊö:     procMsg

@@ -427,6 +452,11 @@
 retry1:

     if(-1 == msgsnd(msgId, msgSnd, sizeof(T_NV_MSG_INFO) - sizeof(long), 0) )

     {

+        if (errno == EINTR)

+        {

+            printf("nv error: msgsnd fail, errno = EINTR!\n");

+            goto retry1;

+        }

         printf("nv error: msgsnd fail, errno = %d!\n", errno);

         return -1;   

     }

@@ -434,13 +464,20 @@
 retry2:

     if(-1 == msgrcv(msgId, msgRcv, sizeof(T_NV_MSG_RESULT) - sizeof(long), msgSnd->pid, 0))

     {

+        if (errno == EINTR)

+        {

+            printf("nv error: msgrcv fail, errno = EINTR!\n");

+            goto retry2;

+        }

         printf("nv error: msgrcv fail, errno = %d!\n", errno);

+        clear_msg_queue(msgId, msgRcv, msgSnd->pid);

         goto retry1;   

     }

 

     if(msgSnd->msgIndex != msgRcv->msgIndex)

     {

-        printf("nv error:recv unknow msg pid = %d, tid = %d, key = %s, value = %s\n", getpid(), msgSnd->pid, msgSnd->key, msgRcv->value);

+        printf("nv error:recv unknow msg nvtype = %d, tid = %d, key = %s, index:%d:%d\n", msgSnd->nvType, msgSnd->pid, msgSnd->key, msgSnd->msgIndex, msgRcv->msgIndex);

+        clear_msg_queue(msgId, msgRcv, msgSnd->pid);

         goto retry1;

     }