lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20150128074254.GA31048@amd>
Date:	Wed, 28 Jan 2015 08:42:54 +0100
From:	Pavel Machek <pavel@....cz>
To:	Tina Ruchandani <ruchandani.tina@...il.com>
Cc:	Linux PM List <linux-pm@...r.kernel.org>,
	Arnd Bergmann <arnd@...db.de>, Len Brown <len.brown@...el.com>,
	"Rafael J. Wysocki" <rjw@...ysocki.net>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] PM: Use 64-bit timekeeping

On Wed 2015-01-28 10:08:37, Tina Ruchandani wrote:
> The freezer try_to_freeze_tasks uses 'struct timeval' for start
> and end times, tracking time taken to freeze tasks. 'struct timeval'
> on 32-bit systems will have its tv_sec overflow in year 2038 and
> beyond. This patches uses 'ktime_t' (which has 64 bit values
> for seconds) for start and end time.
> 
> Suggested-by: Arnd Bergmann <arnd@...db.de>
> Signed-off-by: Tina Ruchandani <ruchandani.tina@...il.com>

Nicer code, and without the overflow. Thanks!

Acked-by: Pavel Machek <pavel@....cz>


> ---
> Changes in v2:
> 	- Use ktime_t to be able to use ktime_ms_delta
> 	  which is more efficient than timespec64 based methods.
> ---
>  kernel/power/process.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/power/process.c b/kernel/power/process.c
> index 5a6ec86..52414dd 100644
> --- a/kernel/power/process.c
> +++ b/kernel/power/process.c
> @@ -17,6 +17,7 @@
>  #include <linux/delay.h>
>  #include <linux/workqueue.h>
>  #include <linux/kmod.h>
> +#include <linux/ktime.h>
>  #include <trace/events/power.h>
x>  
>  /* 
> @@ -30,13 +31,12 @@ static int try_to_freeze_tasks(bool user_only)
>  	unsigned long end_time;
>  	unsigned int todo;
>  	bool wq_busy = false;
> -	struct timeval start, end;
> -	u64 elapsed_msecs64;
> +	ktime_t start, end;
>  	unsigned int elapsed_msecs;
>  	bool wakeup = false;
>  	int sleep_usecs = USEC_PER_MSEC;
>  
> -	do_gettimeofday(&start);
> +	start = ktime_get();
>  
>  	end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs);
>  
> @@ -78,10 +78,8 @@ static int try_to_freeze_tasks(bool user_only)
>  			sleep_usecs *= 2;
>  	}
>  
> -	do_gettimeofday(&end);
> -	elapsed_msecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
> -	do_div(elapsed_msecs64, NSEC_PER_MSEC);
> -	elapsed_msecs = elapsed_msecs64;
> +	end = ktime_get();
> +	elapsed_msecs = (unsigned int) ktime_ms_delta(end, start);
>  
>  	if (todo) {
>  		printk("\n");

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ