OSDN Git Service

Limit the time PAN can occupy the BTU stack thread
authorZhenye Zhu <zhenye@broadcom.com>
Tue, 26 Aug 2014 21:26:56 +0000 (14:26 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Wed, 3 Sep 2014 20:02:55 +0000 (13:02 -0700)
Also make sure tap read/write are non-blocking and PAN does not use the
complete shared buffer pool to avoid GKI buffer overruns.

Bug: 16374840
Change-Id: I6f96d1c8d2804d253d33fe37ff87275e03e55ddd

btif/src/btif_pan.c
include/bt_target.h

index ae395ba..32ae984 100644 (file)
@@ -428,6 +428,8 @@ int btpan_tap_open()
     BTM_GetLocalDeviceAddr (local_addr);
     if(tap_if_up(TAP_IF_NAME, local_addr) == 0)
     {
+        int flags = fcntl(fd, F_GETFL, 0);
+        fcntl(fd, F_SETFL, flags | O_NONBLOCK);
         return fd;
     }
     BTIF_TRACE_ERROR("can not bring up tap interface:%s", TAP_IF_NAME);
@@ -678,8 +680,10 @@ static void btu_exec_tap_fd_read(void *p_param) {
     if (fd == -1 || fd != btpan_cb.tap_fd)
         return;
 
-    // Keep sending until someone either turns off BTIF or disables data the flow.
-    while (btif_is_enabled() && btpan_cb.flow) {
+    // Don't occupy BTU context too long, avoid GKI buffer overruns and
+    // give other profiles a chance to run by limiting the amount of memory
+    // PAN can use from the shared pool buffer.
+    for(int i = 0; i < PAN_POOL_MAX && btif_is_enabled() && btpan_cb.flow; i++) {
         BT_HDR *buffer = (BT_HDR *)GKI_getpoolbuf(PAN_POOL_ID);
         if (!buffer) {
             BTIF_TRACE_WARNING("%s unable to allocate buffer for packet.", __func__);
index 839dcff..6d40997 100644 (file)
 
 #ifndef PAN_POOL_ID
 #define PAN_POOL_ID                 GKI_POOL_ID_3
+/* Maximum amount of the shared buffer to allocate for PAN */
+#define PAN_POOL_MAX                (GKI_BUF3_MAX / 4)
 #endif
 
 /* UNV pool for read/write serialization */