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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120928194152.GA29115@lizard>
Date:	Fri, 28 Sep 2012 12:41:52 -0700
From:	Anton Vorontsov <anton.vorontsov@...aro.org>
To:	Mathieu Poirier <mathieu.poirier@...aro.org>
Cc:	linux-kernel@...r.kernel.org, dwmw2@...radead.org
Subject: Re: [PATCH 52/57] power: abx500_chargalg: Use hrtimer

On Fri, Sep 28, 2012 at 12:33:51PM -0600, Mathieu Poirier wrote:
[...]
> >> @@ -413,11 +428,10 @@ static void abx500_chargalg_start_safety_timer(struct abx500_chargalg *di)
> >>  	}
> >>  
> >>  	di->events.safety_timer_expired = false;
> >> -	di->safety_timer.expires = timer_expiration;
> >> -	if (!timer_pending(&di->safety_timer))
> >> -		add_timer(&di->safety_timer);
> >> -	else
> >> -		mod_timer(&di->safety_timer, timer_expiration);
> >> +	hrtimer_set_expires_range(&di->safety_timer,
> >> +		ktime_set(timer_expiration * ONE_HOUR_IN_SECONDS, 0),
> >> +		ktime_set(FIVE_MINUTES_IN_SECONDS, 0));
> >> +	hrtimer_start_expires(&di->safety_timer, HRTIMER_MODE_REL);
> > 
> > OK, now we're chaning from timers to hrtimers, and their behaviour
> > might be different. I guess in this case you should check whether
> > old value 'before' new value, and if so, do nothing.
> 
> Would you mind being more descriptive - I'm affraid that I don't
> understand your suggestion.

I was partly referencing to my answer here
http://lkml.org/lkml/2012/9/27/678

There I was suggesting how to make abx500_chargalg_check_safety_timer()
simpler, but since in this patch you switching code to hrtimers, the logic
have to change too.

So, to put it even simpler, in this patch you don't even need to check for
time values, in abx500_chargalg_start_safety_timer(), you can just write

	if (hrtimer_active(&di->safety_timer))
		return;

	dev_dbg(di->dev, "starting safety timer\n");

	hrtimer_set_expires_range(&di->safety_timer,
		ktime_set(timer_expiration * ONE_HOUR_IN_SECONDS, 0),
		ktime_set(FIVE_MINUTES_IN_SECONDS, 0));
	hrtimer_start_expires(&di->safety_timer, HRTIMER_MODE_REL);

And you don't have to check for hrtimer_active() anywhere else...

[...]
> >> @@ -910,11 +918,11 @@ static void abx500_chargalg_check_safety_timer(struct abx500_chargalg *di)
> >>  	 * and charging will be stopped to protect the battery.
> >>  	 */
> >>  	if (di->batt_data.percent == 100 &&
> >> -		!timer_pending(&di->safety_timer)) {
> >> +		!hrtimer_active(&di->safety_timer)) {
> >>  		abx500_chargalg_start_safety_timer(di);
> >>  		dev_dbg(di->dev, "start safety timer\n");
> >>  	} else if (di->batt_data.percent != 100 &&
> >> -		timer_pending(&di->safety_timer)) {
> >> +		hrtimer_active(&di->safety_timer)) {
> >>  		abx500_chargalg_stop_safety_timer(di);
> >>  		dev_dbg(di->dev, "stop safety timer\n");
> >>  	}

..so with the above suggestion, this code will turn into just

	if (di->batt_data.percent < 100) {
		abx500_chargalg_stop_safety_timer(di);
		return;
	}
	abx500_chargalg_start_safety_timer(di);

Thanks,
Anton.
--
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