OSDN Git Service

GMIN-3044: Fix a few edge cases in filtering code
[android-x86/hardware-intel-libsensors.git] / control.c
index bc41557..3a827ae 100644 (file)
--- a/control.c
+++ b/control.c
@@ -15,6 +15,7 @@
 #include "utils.h"
 #include "transform.h"
 #include "calibration.h"
+#include "description.h"
 
 /* Currently active sensors count, per device */
 static int poll_sensors_per_dev[MAX_DEVICES];  /* poll-mode sensors */
@@ -26,6 +27,10 @@ static int poll_fd; /* epoll instance covering all enabled sensors */
 
 static int active_poll_sensors; /* Number of enabled poll-mode sensors */
 
+/* We use pthread condition variables to get worker threads out of sleep */
+static pthread_cond_t  thread_release_cond     [MAX_SENSORS];
+static pthread_mutex_t thread_release_mutex    [MAX_SENSORS];
+
 /*
  * We associate tags to each of our poll set entries. These tags have the
  * following values:
@@ -224,6 +229,7 @@ int adjust_counters (int s, int enabled)
                                break;
 
                        case SENSOR_TYPE_GYROSCOPE:
+                       case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
                                gyro_cal_init(&sensor_info[s]);
                                break;
                }
@@ -234,9 +240,6 @@ int adjust_counters (int s, int enabled)
                ALOGI("Disabling sensor %d (iio device %d: %s)\n", s, dev_num,
                      sensor_info[s].friendly_name);
 
-               if (sensor_type == SENSOR_TYPE_MAGNETIC_FIELD)
-                       compass_store_data(&sensor_info[s]);
-
                sensor_info[s].enable_count--;
 
                if (sensor_info[s].enable_count > 0)
@@ -244,8 +247,17 @@ int adjust_counters (int s, int enabled)
 
                /* Sensor disabled, lower report available flag */
                sensor_info[s].report_pending = 0;
+
+               if (sensor_type == SENSOR_TYPE_MAGNETIC_FIELD)
+                       compass_store_data(&sensor_info[s]);
        }
 
+
+       /* If uncalibrated type and pair is already active don't adjust counters */
+       if (sensor_type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED &&
+               sensor_info[sensor_info[s].pair_idx].enable_count != 0)
+                       return 0;
+
        /* We changed the state of a sensor - adjust per iio device counters */
 
        /* If this is a regular event-driven sensor */
@@ -271,12 +283,16 @@ int adjust_counters (int s, int enabled)
 }
 
 
-static int get_field_count (int sensor_type)
+static int get_field_count (int s)
 {
+       int catalog_index = sensor_info[s].catalog_index;
+       int sensor_type   = sensor_catalog[catalog_index].type;
+
        switch (sensor_type) {
                case SENSOR_TYPE_ACCELEROMETER:         /* m/s^2        */
                case SENSOR_TYPE_MAGNETIC_FIELD:        /* micro-tesla  */
                case SENSOR_TYPE_ORIENTATION:           /* degrees      */
+               case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
                case SENSOR_TYPE_GYROSCOPE:             /* radians/s    */
                        return 3;
 
@@ -291,9 +307,6 @@ static int get_field_count (int sensor_type)
                case SENSOR_TYPE_ROTATION_VECTOR:
                        return  4;
 
-               case SENSOR_TYPE_DEVICE_PRIVATE_BASE:   /* Hidden for now */
-                       return 0;                       /* Drop sample */
-
                default:
                        ALOGE("Unknown sensor type!\n");
                        return 0;                       /* Drop sample */
@@ -301,12 +314,13 @@ static int get_field_count (int sensor_type)
 }
 
 
-/* Check and honor termination requests */
-#define CHECK_CANCEL(s)                                                               \
-       if (sensor_info[s].thread_data_fd[1] == -1) {                          \
-                       ALOGV("Acquisition thread for S%d exiting\n", s);      \
-                       pthread_exit(0);                                       \
-       }
+static void time_add(struct timespec *out, struct timespec *in, int64_t ns)
+{
+       int64_t target_ts = 1000000000LL * in->tv_sec + in->tv_nsec + ns;
+
+       out->tv_sec = target_ts / 1000000000;
+       out->tv_nsec = target_ts % 1000000000;
+}
 
 
 static void* acquisition_routine (void* param)
@@ -321,17 +335,13 @@ static void* acquisition_routine (void* param)
         */
 
        int s = (int) param;
-       int report_fd;
-       int catalog_index;
-       int sensor_type;
        int num_fields;
-       uint32_t period;
-       int64_t entry_ts;
        struct sensors_event_t data = {0};
        int c;
-       int sampling_rate;
        int ret;
-       uint32_t elapsed;
+       struct timespec entry_time;
+       struct timespec target_time;
+       int64_t period;
 
        ALOGV("Entering data acquisition thread for sensor %d\n", s);
 
@@ -345,14 +355,19 @@ static void* acquisition_routine (void* param)
                return NULL;
        }
 
-       sensor_type = sensor_catalog[sensor_info[s].catalog_index].type;
-       num_fields  = get_field_count(sensor_type);
+       num_fields = get_field_count(s);
 
-       while (1) {
-               CHECK_CANCEL(s)
+       /*
+        * Each condition variable is associated to a mutex that has to be
+        * locked by the thread that's waiting on it. We use these condition
+        * variables to get the acquisition threads out of sleep quickly after
+        * the sampling rate is adjusted, or the sensor is disabled.
+        */
+       pthread_mutex_lock(&thread_release_mutex[s]);
 
+       while (1) {
                /* Pinpoint the moment we start sampling */
-               entry_ts = get_timestamp();
+               clock_gettime(CLOCK_REALTIME, &entry_time);
 
                ALOGV("Acquiring sample data for sensor %d through sysfs\n", s);
 
@@ -360,8 +375,12 @@ static void* acquisition_routine (void* param)
                for (c=0; c<num_fields; c++) {
                        data.data[c] = acquire_immediate_value(s, c);
 
+                       /* Check and honor termination requests */
+                       if (sensor_info[s].thread_data_fd[1] == -1)
+                               goto exit;
+
                        ALOGV("\tfield %d: %f\n", c, data.data[c]);
-                       CHECK_CANCEL(s)
+
                }
 
                /* If the sample looks good */
@@ -373,18 +392,32 @@ static void* acquisition_routine (void* param)
                                        num_fields * sizeof(float));
                }
 
-               CHECK_CANCEL(s)
+               /* Check and honor termination requests */
+               if (sensor_info[s].thread_data_fd[1] == -1)
+                       goto exit;
 
-               /* Sleep a little, deducting read & write times */
-               elapsed = (get_timestamp() - entry_ts) / 1000;
 
-               period = (uint32_t)
-                        (1000000000LL / sensor_info[s].sampling_rate / 1000);
+               period = (int64_t) (1000000000.0/ sensor_info[s].sampling_rate);
 
-               if (period > elapsed)
-                       usleep(period - elapsed);
+               time_add(&target_time, &entry_time, period);
+
+               /*
+                * Wait until the sampling time elapses, or a rate change is
+                * signaled, or a thread exit is requested.
+                */
+               ret = pthread_cond_timedwait(   &thread_release_cond[s],
+                                               &thread_release_mutex[s],
+                                               &target_time);
+
+               /* Check and honor termination requests */
+               if (sensor_info[s].thread_data_fd[1] == -1)
+                               goto exit;
        }
 
+exit:
+       ALOGV("Acquisition thread for S%d exiting\n", s);
+       pthread_mutex_unlock(&thread_release_mutex[s]);
+       pthread_exit(0);
        return NULL;
 }
 
@@ -398,6 +431,10 @@ static void start_acquisition_thread (int s)
 
        ALOGV("Initializing acquisition context for sensor %d\n", s);
 
+       /* Create condition variable and mutex for quick thread release */
+       ret = pthread_cond_init(&thread_release_cond[s], NULL);
+       ret = pthread_mutex_init(&thread_release_mutex[s], NULL);
+
        /* Create a pipe for inter thread communication */
        ret = pipe(sensor_info[s].thread_data_fd);
 
@@ -427,7 +464,7 @@ static void stop_acquisition_thread (int s)
        /* Delete the incoming side of the pipe from our poll set */
        epoll_ctl(poll_fd, EPOLL_CTL_DEL, incoming_data_fd, NULL);
 
-       /* Mark the pipe ends as invalid ; that's a cheap exit signal */
+       /* Mark the pipe ends as invalid ; that's a cheap exit flag */
        sensor_info[s].thread_data_fd[0] = -1;
        sensor_info[s].thread_data_fd[1] = -1;
 
@@ -435,32 +472,54 @@ static void stop_acquisition_thread (int s)
        close(incoming_data_fd);
        close(outgoing_data_fd);
 
-       /* Wait end of thread, and clean up thread handle */
+       /* Stop acquisition thread and clean up thread handle */
+       pthread_cond_signal(&thread_release_cond[s]);
        pthread_join(sensor_info[s].acquisition_thread, NULL);
 
        /* Clean up our sensor descriptor */
        sensor_info[s].acquisition_thread = -1;
+
+       /* Delete condition variable and mutex */
+       pthread_cond_destroy(&thread_release_cond[s]);
+       pthread_mutex_destroy(&thread_release_mutex[s]);
 }
 
 
 int sensor_activate(int s, int enabled)
 {
        char device_name[PATH_MAX];
-       char trigger_name[MAX_NAME_SIZE + 16];
-       int c;
        struct epoll_event ev = {0};
        int dev_fd;
        int ret;
        int dev_num = sensor_info[s].dev_num;
-       int i = sensor_info[s].catalog_index;
        int is_poll_sensor = !sensor_info[s].num_channels;
 
+       /* If we want to activate gyro calibrated and gyro uncalibrated is activated
+        * Deactivate gyro uncalibrated - Uncalibrated releases handler
+        * Activate gyro calibrated     - Calibrated has handler
+        * Reactivate gyro uncalibrated - Uncalibrated gets data from calibrated */
+
+       /* If we want to deactivate gyro calibrated and gyro uncalibrated is active
+        * Deactivate gyro uncalibrated - Uncalibrated no longer gets data from handler
+        * Deactivate gyro calibrated   - Calibrated releases handler
+        * Reactivate gyro uncalibrated - Uncalibrated has handler */
+
+       if (sensor_catalog[sensor_info[s].catalog_index].type == SENSOR_TYPE_GYROSCOPE &&
+               sensor_info[s].pair_idx && sensor_info[sensor_info[s].pair_idx].enable_count != 0) {
+
+                               sensor_activate(sensor_info[s].pair_idx, 0);
+                               ret = sensor_activate(s, enabled);
+                               sensor_activate(sensor_info[s].pair_idx, 1);
+                               return ret;
+       }
+
        ret = adjust_counters(s, enabled);
 
        /* If the operation was neutral in terms of state, we're done */
        if (ret <= 0)
                return ret;
 
+
        if (!is_poll_sensor) {
 
                /* Stop sampling */
@@ -469,11 +528,9 @@ int sensor_activate(int s, int enabled)
 
                /* If there's at least one sensor enabled on this iio device */
                if (trig_sensors_per_dev[dev_num]) {
-                       sprintf(trigger_name, "%s-dev%d",
-                                       sensor_info[s].internal_name, dev_num);
 
                        /* Start sampling */
-                       setup_trigger(dev_num, trigger_name);
+                       setup_trigger(dev_num, sensor_info[s].trigger_name);
                        enable_buffer(dev_num, 1);
                }
        }
@@ -501,6 +558,13 @@ int sensor_activate(int s, int enabled)
                                close(dev_fd);
                                device_fd[dev_num] = -1;
                        }
+
+               /* If we recorded a trail of samples for filtering, delete it */
+               if (sensor_info[s].history) {
+                       free(sensor_info[s].history);
+                       sensor_info[s].history = NULL;
+                       sensor_info[s].history_size = 0;
+               }
                return 0;
        }
 
@@ -520,9 +584,7 @@ int sensor_activate(int s, int enabled)
 
                ALOGV("Opened %s: fd=%d\n", device_name, dev_fd);
 
-               if (is_poll_sensor)
-                       start_acquisition_thread(s);
-               else {
+               if (!is_poll_sensor) {
 
                        /* Add this iio device fd to the set of watched fds */
                        ev.events = EPOLLIN;
@@ -540,6 +602,12 @@ int sensor_activate(int s, int enabled)
                }
        }
 
+       /* Ensure that on-change sensors send at least one event after enable */
+       sensor_info[s].prev_val = -1;
+
+       if (is_poll_sensor)
+               start_acquisition_thread(s);
+
        return 0;
 }
 
@@ -553,7 +621,7 @@ static int integrate_device_report(int dev_num)
        unsigned char *target;
        unsigned char *source;
        int size;
-       int ts;
+       int64_t ts;
 
        /* There's an incoming report on the specified iio device char dev fd */
 
@@ -579,6 +647,8 @@ static int integrate_device_report(int dev_num)
 
        ALOGV("Read %d bytes from iio device %d\n", len, dev_num);
 
+       /* Map device report to sensor reports */
+
        for (s=0; s<MAX_SENSORS; s++)
                if (sensor_info[s].dev_num == dev_num &&
                    sensor_info[s].enable_count) {
@@ -605,28 +675,33 @@ static int integrate_device_report(int dev_num)
 
                        sensor_info[s].report_ts = ts;
                        sensor_info[s].report_pending = 1;
+                       sensor_info[s].report_initialized = 1;
                }
 
        return 0;
 }
 
 
-static int propagate_sensor_report(int s, struct sensors_event_tdata)
+static int propagate_sensor_report(int s, struct sensors_event_t  *data)
 {
        /* There's a sensor report pending for this sensor ; transmit it */
 
-       int catalog_index       = sensor_info[s].catalog_index;
-       int sensor_type         = sensor_catalog[catalog_index].type;
-       int num_fields          = get_field_count(sensor_type);
+       int catalog_index = sensor_info[s].catalog_index;
+       int sensor_type   = sensor_catalog[catalog_index].type;
+       int num_fields    = get_field_count(s);
        int c;
        unsigned char* current_sample;
-       int64_t current_ts = get_timestamp();
-       int64_t delta;
 
        /* If there's nothing to return... we're done */
        if (!num_fields)
                return 0;
 
+
+       /* Only return uncalibrated event if also gyro active */
+       if (sensor_type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED &&
+               sensor_info[sensor_info[s].pair_idx].enable_count != 0)
+                       return 0;
+
        memset(data, 0, sizeof(sensors_event_t));
 
        data->version   = sizeof(sensors_event_t);
@@ -647,7 +722,6 @@ static int propagate_sensor_report(int s, struct sensors_event_t* data)
        }
 
        /* Convert the data into the expected Android-level format */
-
        for (c=0; c<num_fields; c++) {
 
                data->data[c] = sensor_info[s].ops.transform
@@ -665,26 +739,122 @@ static int propagate_sensor_report(int s, struct sensors_event_t* data)
 }
 
 
+static void synthetize_duplicate_samples (void)
+{
+       /*
+        * Some sensor types (ex: gyroscope) are defined as continuously firing
+        * by Android, despite the fact that we can be dealing with iio drivers
+        * that only report events for new samples. For these we generate
+        * reports periodically, duplicating the last data we got from the
+        * driver. This is not necessary for polling sensors.
+        */
+
+       int s;
+       int64_t current_ts;
+       int64_t target_ts;
+       int64_t period;
+
+       for (s=0; s<sensor_count; s++) {
+
+               /* Ignore disabled sensors */
+               if (!sensor_info[s].enable_count)
+                       continue;
+
+               /* If the sensor can generate duplicates, leave it alone */
+               if (!(sensor_info[s].quirks & QUIRK_TERSE_DRIVER))
+                       continue;
+
+               /* If we haven't seen a sample, there's nothing to duplicate */
+               if (!sensor_info[s].report_initialized)
+                       continue;
+
+               /* If a sample was recently buffered, leave it alone too */
+               if (sensor_info[s].report_pending)
+                       continue;
+
+               /* We also need a valid sampling rate to be configured */
+               if (!sensor_info[s].sampling_rate)
+                       continue;
+
+               period = (int64_t) (1000000000.0/ sensor_info[s].sampling_rate);
+
+               current_ts = get_timestamp();
+               target_ts = sensor_info[s].report_ts + period;
+
+               if (target_ts <= current_ts) {
+                       /* Mark the sensor for event generation */
+                       sensor_info[s].report_ts = current_ts;
+                       sensor_info[s].report_pending = 1;
+               }
+       }
+}
+
+
 static void integrate_thread_report (uint32_t tag)
 {
        int s = tag - THREAD_REPORT_TAG_BASE;
-       int incoming_data_fd;
-       int catalog_index       = sensor_info[s].catalog_index;
-       int sensor_type         = sensor_catalog[catalog_index].type;
-       int num_fields          = get_field_count(sensor_type);
        int len;
        int expected_len;
 
-       sensor_info[s].report_ts = get_timestamp();
+       expected_len = get_field_count(s) * sizeof(float);
 
-       incoming_data_fd = sensor_info[s].thread_data_fd[0];
+       len = read(sensor_info[s].thread_data_fd[0],
+                  sensor_info[s].report_buffer,
+                  expected_len);
 
-       expected_len = num_fields * sizeof(float);
+       if (len == expected_len) {
+               sensor_info[s].report_ts = get_timestamp();
+               sensor_info[s].report_pending = 1;
+       }
+}
 
-       len= read(incoming_data_fd, sensor_info[s].report_buffer, expected_len);
 
-       if (len == expected_len)
-               sensor_info[s].report_pending = 1;
+static int get_poll_wait_timeout (void)
+{
+       /*
+        * Compute an appropriate timeout value, in ms, for the epoll_wait
+        * call that's going to await for iio device reports and incoming
+        * reports from our sensor sysfs data reader threads.
+        */
+
+       int s;
+       int64_t target_ts = INT64_MAX;
+       int64_t ms_to_wait;
+       int64_t period;
+
+       /*
+        * Check if have have to deal with "terse" drivers that only send events
+        * when there is motion, despite the fact that the associated Android
+        * sensor type is continuous rather than on-change. In that case we have
+        * to duplicate events. Check deadline for the nearest upcoming event.
+        */
+       for (s=0; s<sensor_count; s++)
+               if (sensor_info[s].enable_count &&
+                   (sensor_info[s].quirks & QUIRK_TERSE_DRIVER) &&
+                   sensor_info[s].sampling_rate) {
+                       period = (int64_t) (1000000000.0 /
+                                               sensor_info[s].sampling_rate);
+
+                       if (sensor_info[s].report_ts + period < target_ts)
+                               target_ts = sensor_info[s].report_ts + period;
+               }
+
+       /* If we don't have such a driver to deal with */
+       if (target_ts == INT64_MAX)
+               return -1; /* Infinite wait */
+
+       ms_to_wait = (target_ts - get_timestamp()) / 1000000;
+
+       /*
+        * If the target timestamp is very close or already behind us, wait
+        * nonetheless for a millisecond in order to a) avoid busy loops, and
+        * b) give a chance for the driver to report data before we repeat the
+        * last received sample.
+        */
+       if (ms_to_wait <= 0)
+               return 1;
+
+       return ms_to_wait;
 }
 
 
@@ -693,10 +863,9 @@ int sensor_poll(struct sensors_event_t* data, int count)
        int s;
        int i;
        int nfds;
-       int delta;
        struct epoll_event ev[MAX_DEVICES];
-       int64_t target_ts;
        int returned_events;
+       int event_count;
 
        /* Get one or more events from our collection of sensors */
 
@@ -705,16 +874,38 @@ return_available_sensor_reports:
        returned_events = 0;
 
        /* Check our sensor collection for available reports */
-       for (s=0; s<sensor_count && returned_events<count; s++)
+       for (s=0; s<sensor_count && returned_events < count; s++)
                if (sensor_info[s].report_pending) {
-
+                       event_count = 0;
                        /* Lower flag */
                        sensor_info[s].report_pending = 0;
 
                        /* Report this event if it looks OK */
-                       returned_events +=
-                            propagate_sensor_report(s, &data[returned_events]);
-
+                       event_count = propagate_sensor_report(s, &data[returned_events]);
+
+                       /* Duplicate only if both cal & uncal are active */
+                       if (sensor_catalog[sensor_info[s].catalog_index].type == SENSOR_TYPE_GYROSCOPE &&
+                                       sensor_info[s].pair_idx && sensor_info[sensor_info[s].pair_idx].enable_count != 0) {
+                                       struct gyro_cal* gyro_data = (struct gyro_cal*) sensor_info[s].cal_data;
+
+                                       memcpy(&data[returned_events + event_count], &data[returned_events],
+                                                       sizeof(struct sensors_event_t) * event_count);
+                                       for (i = 0; i < event_count; i++) {
+                                               data[returned_events + i].type = SENSOR_TYPE_GYROSCOPE_UNCALIBRATED;
+                                               data[returned_events + i].sensor = sensor_info[s].pair_idx;
+
+                                               data[returned_events + i].data[0] = data[returned_events + i].data[0] + gyro_data->bias[0];
+                                               data[returned_events + i].data[1] = data[returned_events + i].data[1] + gyro_data->bias[1];
+                                               data[returned_events + i].data[2] = data[returned_events + i].data[2] + gyro_data->bias[2];
+
+                                               data[returned_events + i].uncalibrated_gyro.bias[0] = gyro_data->bias[0];
+                                               data[returned_events + i].uncalibrated_gyro.bias[1] = gyro_data->bias[1];
+                                               data[returned_events + i].uncalibrated_gyro.bias[2] = gyro_data->bias[2];
+                                       }
+                                       event_count <<= 1;
+                       }
+                       sensor_info[sensor_info[s].pair_idx].report_pending = 0;
+                       returned_events += event_count;
                        /*
                         * If the sample was deemed invalid or unreportable,
                         * e.g. had the same value as the previously reported
@@ -729,13 +920,16 @@ await_event:
 
        ALOGV("Awaiting sensor data\n");
 
-       nfds = epoll_wait(poll_fd, ev, MAX_DEVICES, -1);
+       nfds = epoll_wait(poll_fd, ev, MAX_DEVICES, get_poll_wait_timeout());
 
        if (nfds == -1) {
-               ALOGI("epoll_wait returned -1 (%s)\n", strerror(errno));
+               ALOGE("epoll_wait returned -1 (%s)\n", strerror(errno));
                goto await_event;
        }
 
+       /* Synthetize duplicate samples if needed */
+       synthetize_duplicate_samples();
+
        ALOGV("%d fds signalled\n", nfds);
 
        /* For each of the signalled sources */
@@ -775,32 +969,34 @@ int sensor_set_delay(int s, int64_t ns)
        const char *prefix      =       sensor_catalog[i].tag;
        float new_sampling_rate; /* Granted sampling rate after arbitration   */
        float cur_sampling_rate; /* Currently used sampling rate              */
-       float req_sampling_rate; /* Requested ; may be different from granted */
        int per_sensor_sampling_rate;
        int per_device_sampling_rate;
-       int max_supported_rate = 0;
+       float max_supported_rate = 0;
        char freqs_buf[100];
        char* cursor;
        int n;
-       int sr;
+       float sr;
 
        if (!ns) {
                ALOGE("Rejecting zero delay request on sensor %d\n", s);
                return -EINVAL;
        }
 
-       new_sampling_rate = req_sampling_rate = 1000000000L/ns;
+       new_sampling_rate = 1000000000LL/ns;
 
-       if (new_sampling_rate < 1) {
-               ALOGI("Sub-HZ sampling rate requested on on sensor %d\n", s);
+       /*
+        * Artificially limit ourselves to 1 Hz or higher. This is mostly to
+        * avoid setting up the stage for divisions by zero.
+        */
+       if (new_sampling_rate < 1)
                new_sampling_rate = 1;
-       }
 
        sensor_info[s].sampling_rate = new_sampling_rate;
 
        /* If we're dealing with a poll-mode sensor */
        if (!sensor_info[s].num_channels) {
-               /* The new sampling rate will be used on next iteration */
+               /* Interrupt current sleep so the new sampling gets used */
+               pthread_cond_signal(&thread_release_cond[s]);
                return 0;
        }
 
@@ -849,10 +1045,6 @@ int sensor_set_delay(int s, int64_t ns)
                        /* Decode a single value */
                        sr = strtod(cursor, NULL);
 
-                       /* Cap sampling rate to CAP_SENSOR_MAX_FREQUENCY*/
-                        if (sr > CAP_SENSOR_MAX_FREQUENCY)
-                                 break;
-
                        if (sr > max_supported_rate)
                                max_supported_rate = sr;
 
@@ -868,10 +1060,6 @@ int sensor_set_delay(int s, int64_t ns)
                         * in the allowed frequencies string.
                         */
                        if (sr > new_sampling_rate) {
-                               ALOGI(
-                       "Increasing sampling rate on sensor %d from %g to %g\n",
-                               s, (double) req_sampling_rate, (double) sr);
-
                                new_sampling_rate = sr;
                                break;
                        }
@@ -890,8 +1078,6 @@ int sensor_set_delay(int s, int64_t ns)
        if (max_supported_rate &&
                new_sampling_rate > max_supported_rate) {
                new_sampling_rate = max_supported_rate;
-               ALOGI(  "Can't support %g sampling rate, lowering to %g\n",
-                       (double) req_sampling_rate, (double) new_sampling_rate);
        }
 
 
@@ -899,7 +1085,7 @@ int sensor_set_delay(int s, int64_t ns)
        if (new_sampling_rate == cur_sampling_rate)
                return 0;
 
-       ALOGI("Sensor %d sampling rate switched to %g\n", s, new_sampling_rate);
+       ALOGI("Sensor %d sampling rate set to %g\n", s, new_sampling_rate);
 
        if (trig_sensors_per_dev[dev_num])
                enable_buffer(dev_num, 0);
@@ -916,7 +1102,6 @@ int sensor_set_delay(int s, int64_t ns)
 int allocate_control_data (void)
 {
        int i;
-       struct epoll_event ev = {0};
 
        for (i=0; i<MAX_DEVICES; i++)
                device_fd[i] = -1;