Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Abhilash Jindal <klock.android@gmail.com>,
	linux-iio@vger.kernel.org, Richard Weinberger <richard@nod.at>,
	Harald Geyer <harald@ccbib.org>
Subject: Re: [PATCH] iio: dht11: Use boottime
Date: Sat, 30 Jan 2016 17:50:28 +0000	[thread overview]
Message-ID: <56ACF7E4.7040603@kernel.org> (raw)
In-Reply-To: <1453934762-6290-1-git-send-email-klock.android@gmail.com>

On 27/01/16 22:46, Abhilash Jindal wrote:
> Wall time obtained from ktime_get_real_ns is susceptible to sudden jumps due to
> user setting the time or due to NTP.  Boot time is constantly increasing time
> better suited for comparing two timestamps.
> 
> Signed-off-by: Abhilash Jindal <klock.android@gmail.com>
Seems sensible to me, but would like Richard / Harald to take a quick
look before I apply it.

Thanks,

Jonathan
> ---
>  drivers/iio/humidity/dht11.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
> index 1165b1c..cfc5a05 100644
> --- a/drivers/iio/humidity/dht11.c
> +++ b/drivers/iio/humidity/dht11.c
> @@ -117,7 +117,7 @@ static int dht11_decode(struct dht11 *dht11, int offset, int timeres)
>  	if (((hum_int + hum_dec + temp_int + temp_dec) & 0xff) != checksum)
>  		return -EIO;
>  
> -	dht11->timestamp = ktime_get_real_ns();
> +	dht11->timestamp = ktime_get_boot_ns();
>  	if (hum_int < 20) {  /* DHT22 */
>  		dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
>  					((temp_int & 0x80) ? -100 : 100);
> @@ -145,7 +145,7 @@ static irqreturn_t dht11_handle_irq(int irq, void *data)
>  
>  	/* TODO: Consider making the handler safe for IRQ sharing */
>  	if (dht11->num_edges < DHT11_EDGES_PER_READ && dht11->num_edges >= 0) {
> -		dht11->edges[dht11->num_edges].ts = ktime_get_real_ns();
> +		dht11->edges[dht11->num_edges].ts = ktime_get_boot_ns();
>  		dht11->edges[dht11->num_edges++].value =
>  						gpio_get_value(dht11->gpio);
>  
> @@ -164,7 +164,7 @@ static int dht11_read_raw(struct iio_dev *iio_dev,
>  	int ret, timeres;
>  
>  	mutex_lock(&dht11->lock);
> -	if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_real_ns()) {
> +	if (dht11->timestamp + DHT11_DATA_VALID_TIME < ktime_get_boot_ns()) {
>  		timeres = ktime_get_resolution_ns();
>  		if (DHT11_DATA_BIT_HIGH < 2 * timeres) {
>  			dev_err(dht11->dev, "timeresolution %dns too low\n",
> @@ -279,7 +279,7 @@ static int dht11_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	dht11->timestamp = ktime_get_real_ns() - DHT11_DATA_VALID_TIME - 1;
> +	dht11->timestamp = ktime_get_boot_ns() - DHT11_DATA_VALID_TIME - 1;
>  	dht11->num_edges = -1;
>  
>  	platform_set_drvdata(pdev, iio);
> 


  reply	other threads:[~2016-01-30 17:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-27 22:46 [PATCH] iio: dht11: Use boottime Abhilash Jindal
2016-01-30 17:50 ` Jonathan Cameron [this message]
2016-01-30 19:11   ` Harald Geyer
2016-01-31  5:08     ` Abhilash Jindal
2016-01-31 10:09       ` Harald Geyer
2016-02-01  5:15         ` Abhilash Jindal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56ACF7E4.7040603@kernel.org \
    --to=jic23@kernel.org \
    --cc=harald@ccbib.org \
    --cc=klock.android@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox