Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755444AbdLUSdg (ORCPT ); Thu, 21 Dec 2017 13:33:36 -0500 Received: from mail-out-1.itc.rwth-aachen.de ([134.130.5.46]:35125 "EHLO mail-out-1.itc.rwth-aachen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752500AbdLUSbx (ORCPT ); Thu, 21 Dec 2017 13:31:53 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2C2CwAD/Tta/54agoZbHQEBBQELAYM+g?= =?us-ascii?q?giDf5k0gVqZZQqFO4RMQxQBAQEBAQEBAQFrKIVNDwFGNQImAl8OijAEpEOCJ4h?= =?us-ascii?q?TghwBAQgCASUJAYEFgnCCEoM/KQyHe2iCDgwxgmUFik6YeoETljOJfCmHPpZSA?= =?us-ascii?q?gICAgkCGoE7NiKBT3CCeoRXiXgBgRUBAQE?= X-IPAS-Result: =?us-ascii?q?A2C2CwAD/Tta/54agoZbHQEBBQELAYM+ggiDf5k0gVqZZQq?= =?us-ascii?q?FO4RMQxQBAQEBAQEBAQFrKIVNDwFGNQImAl8OijAEpEOCJ4hTghwBAQgCASUJA?= =?us-ascii?q?YEFgnCCEoM/KQyHe2iCDgwxgmUFik6YeoETljOJfCmHPpZSAgICAgkCGoE7NiK?= =?us-ascii?q?BT3CCeoRXiXgBgRUBAQE?= X-IronPort-AV: E=Sophos;i="5.45,437,1508796000"; d="scan'208";a="30554753" From: =?UTF-8?q?Stefan=20Br=C3=BCns?= To: CC: Peter Meerwald-Stadler , =?UTF-8?q?Stefan=20Br=C3=BCns?= , Maciej Purski , , "Andrew F . Davis" , Lars-Peter Clausen , Jonathan Cameron , Hartmut Knaack Subject: [PATCH v2 0/7] iio: adc: ina2xx: Rework CNVR alignment, fix busy loops Date: Thu, 21 Dec 2017 19:31:31 +0100 X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [92.228.148.100] X-ClientProxiedBy: rwthex-s1-a.rwth-ad.de (2002:8682:1a98::8682:1a98) To rwthex-w2-a.rwth-ad.de (2002:8682:1a9e::8682:1a9e) Message-ID: <6decf59e-45bf-4690-bf66-1734e81913d9@rwthex-w2-a.rwth-ad.de> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2650 Lines: 62 Currently, the INA2xx driver may end up causing 100% load on a single core and fully loading the I2C bus, which is caused by two different issues: The code uses a udelay to bridge the gab between two subsequent samples. As the sampling interval may be up to 16 seconds, the CPU is busy waiting most of the time. The second issue manifests when using the (default) "synchronous" mode. The code polls for a set conversion ready flag, but fails to align the sampling interval to the raising flag. The polling interval is (rightfully) slighly shorter than the sampling interval, so after some samples the sampling thread is continously polling. The patch series fixes both issues: Patch 1 and 2 are just some small cosmetic changes. Patch 3 removes an unnecessary read. According to the datasheet, the CNVR flag is only cleared by reading the power register, but is cleared by reading any of the measurement registers, thus the dummy read can be skipped. This behaviour has been confirmed by TI technical support. Patch 4 replaces the udelay with usleep_range. Patch 5 reworks the delay logic. Previously the IIO timestamp clock was used to capture entry and exit times of the work function. The timestamp clock is user selectable and may be non-monotonic. Also, any time spent outside the work function is not accounted for. Patch 6 moves the timestap capture to the end of the conversion ready status poll. Patch 7 addresses the alignment issue. Every time an unset flag is seen on poll loop entry, the reference timestamp is readjusted. Both old and fixed behaviour has been verified using a logic analyzer. In synchrounous mode, every few samples a double read of the status register can be observed, showing the raising status flag, the other samples are evenly spaced at sampling intervals inbetween. Changes in v2: - add a comment mentioning skipping samples on overrun - Describe old behaviour in commit message more clearly No real code changes, but added a comment in patch 5, and clarified commit messages of patch 5 and 7. Stefan BrĂ¼ns (7): iio: adc: ina2xx: Remove bogus cast for data argument iio: adc: ina2xx: Clarify size requirement for data buffer iio: adc: ina2xx: Remove unneeded dummy read to clear CNVR flag iio: adc: ina2xx: Do not udelay for several seconds iio: adc: ina2xx: Use a monotonic clock for delay calculation iio: adc: ina2xx: Align timestamp with conversion ready flag iio: adc: ina2xx: Actually align the loop with the conversion ready flag drivers/iio/adc/ina2xx-adc.c | 110 +++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 45 deletions(-) -- 2.15.1