OSDN Git Service

Use THREAD_CPUTIME to measure sensor activation time
authorViorel Suman <viorel.suman@intel.com>
Tue, 21 Jul 2015 06:26:29 +0000 (09:26 +0300)
committerbuildslave <sys_buildbot@intel.com>
Tue, 21 Jul 2015 19:01:32 +0000 (19:01 +0000)
CLOCK_BOOTTIME measures the overall time spend by
CPU on all processes while invoking the sensor activation.
In a multi-process multi-threaded environment this
creates the misperception that sensor activation
takes too long when resuming from suspended state.
Use CLOCK_THREAD_CPUTIME_ID instead of CLOCK_BOOTTIME
in order to measure the time spent by CPU on sensor
activation thread exclusively.

Change-Id: I362d76c8976cb566962c03b294462a6d6a0f69e7
Tracked-On: https://jira01.devtools.intel.com/browse/GMINL-12362
Signed-off-by: Viorel Suman <viorel.suman@intel.com>
Reviewed-on: https://android.intel.com:443/391994

entry.c
utils.c
utils.h

diff --git a/entry.c b/entry.c
index 3a4fa34..4cfff11 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -23,7 +23,7 @@ static int activate (__attribute__((unused)) struct sensors_poll_device_t* dev,
        if (init_count == 0 || handle < 0 || handle >= sensor_count)
                return -EINVAL;
 
-       entry_ts = get_timestamp_boot();
+       entry_ts = get_timestamp_thread();
 
        /*
         * The Intel sensor hub seems to have trouble enabling sensors before
@@ -47,7 +47,7 @@ static int activate (__attribute__((unused)) struct sensors_poll_device_t* dev,
 
        ret = sensor_activate(handle, enabled, 0);
 
-       elapsed_ms = (int) ((get_timestamp_boot() - entry_ts) / 1000000);
+       elapsed_ms = (int) ((get_timestamp_thread() - entry_ts) / 1000000);
 
        if (elapsed_ms) {
                if (enabled)
diff --git a/utils.c b/utils.c
index 4dd316f..488b70a 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -188,33 +188,36 @@ int sysfs_read_str(const char path[PATH_MAX], char *buf, int buf_len)
 }
 
 
-int64_t get_timestamp_realtime (void)
+int64_t get_timestamp (clockid_t clock_id)
 {
        struct timespec ts = {0};
-       clock_gettime(CLOCK_REALTIME, &ts);
 
-       return 1000000000LL * ts.tv_sec + ts.tv_nsec;
+       if (!clock_gettime(clock_id, &ts))
+               return 1000000000LL * ts.tv_sec + ts.tv_nsec;
+       else    /* in this case errno is set appropriately */
+               return -1;
 }
 
+int64_t get_timestamp_realtime (void)
+{
+       return get_timestamp(CLOCK_REALTIME);
+}
 
 int64_t get_timestamp_boot (void)
 {
-       struct timespec ts = {0};
-       clock_gettime(CLOCK_BOOTTIME, &ts);
-
-       return 1000000000LL * ts.tv_sec + ts.tv_nsec;
+       return get_timestamp(CLOCK_BOOTTIME);
 }
 
+int64_t get_timestamp_thread (void)
+{
+       return get_timestamp(CLOCK_THREAD_CPUTIME_ID);
+}
 
 int64_t get_timestamp_monotonic (void)
 {
-       struct timespec ts = {0};
-       clock_gettime(CLOCK_MONOTONIC, &ts);
-
-       return 1000000000LL * ts.tv_sec + ts.tv_nsec;
+       return get_timestamp(CLOCK_MONOTONIC);
 }
 
-
 void set_timestamp (struct timespec *out, int64_t target_ns)
 {
        out->tv_sec  = target_ns / 1000000000LL;
diff --git a/utils.h b/utils.h
index 3b8fa63..3ccf4c7 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -21,6 +21,7 @@ int   sysfs_read_uint64(const char path[PATH_MAX], uint64_t *value);
 void   set_timestamp   (struct timespec *out, int64_t target_ns);
 
 int64_t get_timestamp_boot     (void);
+int64_t get_timestamp_thread   (void);
 int64_t get_timestamp_realtime (void);
 int64_t get_timestamp_monotonic        (void);