Re: CPUfreq - udelay() interaction issues

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Saravana Kannan
Date: Friday, April 23, 2010 - 7:49 pm

- Venkatesh since his email is bouncing with "unknown address".

Mathieu Desnoyers wrote:

Yes, udelay has an _at least_ guarantee. Extra delay is not much of a 
concern and is probably unavoidable.


A lot of device drivers use udelay to meet h/w or protocol spec 
requirements and if we randomly don't meet it, we would hit issues that 
are hard to debug. So, I think proper working of udelay is quite a bit 
important.


I agree, a spin lock would be a no-no for many reasons. Semaphore is not 
really a problem in atomic contexts because cpufreq can't interrupt us 
either -- so we don't need to grab a semaphore.

I was testing the waters about the actual existence of the bug before I 
spent time to propose a clear solution. I guess I could have explained 
the solution better -- explain further down.


Seems a bit more complicated than what I had in mind. This is touching 
the scheduler I think we can get away without having to. Also, there is 
no simple implementation for the "slowpath" that can guarantee the delay 
without starting over the loop and hoping not to get interrupted or just 
giving up and doing a massively inaccurate delay (like msleep, etc).

I was thinking of something along the lines of this:

udelay()
{
   if (!is_atomic())
	down_read(&freq_sem);
   /* else
	do nothing since cpufreq can't interrupt you.
   */

   call usual code since cpufreq is not going to preempt you.

   if (!is_atomic())
	up_read(&freq_sem);
}

__cpufreq_driver_target(...)
{
   down_write(&freq_sem);
   cpufreq_driver->target(...);
   up_write(&freq_sem);
}

In the implementation of the cpufreq driver, they just need to make sure 
they always increase the LPJ _before_ increasing the freq and decrease 
the LPJ _after_ decreasing the freq. This is make sure that when an 
interrupt handler preempts the cpufreq driver code (since atomic 
contexts aren't looking at the r/w semaphore) the LPJ value will be good 
enough to satisfy the _at least_ guarantee of udelay().

For the CPU switching issue, I think the solution I proposed is quite 
simple and should work.

Does my better explained solution look palatable?

Thanks,
Saravana


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: CPUfreq - udelay() interaction issues, Mathieu Desnoyers, (Fri Apr 23, 11:40 am)
Re: CPUfreq - udelay() interaction issues, Arjan van de Ven, (Fri Apr 23, 12:22 pm)
Re: CPUfreq - udelay() interaction issues, Mathieu Desnoyers, (Fri Apr 23, 12:55 pm)
Re: CPUfreq - udelay() interaction issues, Saravana Kannan, (Fri Apr 23, 7:49 pm)
Re: CPUfreq - udelay() interaction issues, Saravana Kannan, (Fri Apr 23, 7:57 pm)
Re: CPUfreq - udelay() interaction issues, Pavel Machek, (Fri Apr 23, 10:56 pm)
Re: CPUfreq - udelay() interaction issues, Mathieu Desnoyers, (Sat Apr 24, 6:58 am)
Re: CPUfreq - udelay() interaction issues, Arjan van de Ven, (Sat Apr 24, 11:56 am)
Re: CPUfreq - udelay() interaction issues, Mathieu Desnoyers, (Sat Apr 24, 2:00 pm)
Re: CPUfreq - udelay() interaction issues, Arjan van de Ven, (Sat Apr 24, 4:20 pm)
Re: CPUfreq - udelay() interaction issues, Saravana Kannan, (Tue Apr 27, 4:41 pm)