From baff465f668aff2d4b5b410ad28a40138b423323 Mon Sep 17 00:00:00 2001 From: Ganesh Mahendran Date: Mon, 5 Mar 2018 19:07:06 +0800 Subject: [PATCH] continue read file when returned count > 0 In android, we met a lot of watchdog timeout which caused by read file "/d/wakeup_sources". The root cause is that in kernel side wakeup.c, it uses single_open() interface to show the stats. But single_open() interface requires that the whole output must fit into a single buffer(physical continuous). This will lead to timeout when system memory is not in a good situation. Problem in kenrel side has been merged in [1]. Then kernel will return max a page bytes to user space. So in KernelWakelockReader, we need to read again when returned count > 0. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.0-rc4&id=00ee22c28915d111ba415750a3311d7678fd1206 Change-Id: If7886514c609c8d6338532c67c1cee79f2754ab1 Signed-off-by: Ganesh Mahendran --- .../com/android/internal/os/KernelWakelockReader.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/java/com/android/internal/os/KernelWakelockReader.java b/core/java/com/android/internal/os/KernelWakelockReader.java index 46667d1ea688f..86b2a90dd64e7 100644 --- a/core/java/com/android/internal/os/KernelWakelockReader.java +++ b/core/java/com/android/internal/os/KernelWakelockReader.java @@ -66,7 +66,7 @@ public class KernelWakelockReader { */ public final KernelWakelockStats readKernelWakelockStats(KernelWakelockStats staleStats) { byte[] buffer = new byte[32*1024]; - int len; + int len = 0; boolean wakeup_sources; final long startTime = SystemClock.uptimeMillis(); @@ -87,7 +87,11 @@ public class KernelWakelockReader { } } - len = is.read(buffer); + int cnt; + while ((cnt = is.read(buffer, len, buffer.length - len)) > 0) { + len += cnt; + } + is.close(); } catch (java.io.IOException e) { Slog.wtf(TAG, "failed to read kernel wakelocks", e);