hwc: add some logging

We are seeing errors where a device's hwcVsyncThread is not present for some
reason.  The surface flinger has not crashed, so either the thread never got
created, or it exited withouth throwing an error.  This patch adds some more
verbose on-error logging to the HWC as an attempt to verify the theory that the
thread does not get created, or fails in pthread_create.  While we're at it, we
add the same logging at pthread_create() for hwcUeventThread, as well.

Also, replace the lseek()+read() with a pread() combo in the vsync thread.

Change-Id: I555d786a7d66ff4ef1dbfd95947a7d9341e56f11
related-to-bug: 7305728
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/libhwcomposer/hwc_vsync.cpp b/libhwcomposer/hwc_vsync.cpp
index d4afd78..28ac86d 100644
--- a/libhwcomposer/hwc_vsync.cpp
+++ b/libhwcomposer/hwc_vsync.cpp
@@ -34,6 +34,8 @@
 
 namespace qhwc {
 
+#define HWC_VSYNC_THREAD_NAME "hwcVsyncThread"
+
 static void *vsync_loop(void *param)
 {
     const char* vsync_timestamp_fb0 = "/sys/class/graphics/fb0/vsync_event";
@@ -42,7 +44,7 @@
 
     hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param);
 
-    char thread_name[64] = "hwcVsyncThread";
+    char thread_name[64] = HWC_VSYNC_THREAD_NAME;
     prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
     setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY +
                 android::PRIORITY_MORE_FAVORABLE);
@@ -100,11 +102,9 @@
             }
         }
 
-       // Open success - read now
-       lseek(fd_timestamp, 0, SEEK_SET);
        for(int i = 0; i < MAX_RETRY_COUNT; i++) {
-           len = read(fd_timestamp, vdata, MAX_DATA);
-           if(len < 0 && errno == EAGAIN) {
+           len = pread(fd_timestamp, vdata, MAX_DATA, 0);
+           if(len < 0 && (errno == EAGAIN || errno == EINTR)) {
                ALOGW("%s: vsync read: EAGAIN, retry (%d/%d).",
                      __FUNCTION__, i, MAX_RETRY_COUNT);
                continue;
@@ -113,7 +113,7 @@
            }
        }
 
-       if (len < 0){
+       if (len < 0) {
            ALOGE ("FATAL:%s:not able to read file:%s, %s", __FUNCTION__,
                   vsync_timestamp_fb0, strerror(errno));
            close (fd_timestamp);
@@ -143,9 +143,14 @@
 
 void init_vsync_thread(hwc_context_t* ctx)
 {
+    int ret;
     pthread_t vsync_thread;
     ALOGI("Initializing VSYNC Thread");
-    pthread_create(&vsync_thread, NULL, vsync_loop, (void*) ctx);
+    ret = pthread_create(&vsync_thread, NULL, vsync_loop, (void*) ctx);
+    if (ret) {
+        ALOGE("%s: failed to create %s: %s", __FUNCTION__,
+            HWC_VSYNC_THREAD_NAME, strerror(ret));
+    }
 }
 
 }; //namespace