[PATCH 1/3] CPU frequency scaling addon

Dave Jones davej at redhat.com
Mon Aug 14 11:44:04 PDT 2006


On Mon, Aug 14, 2006 at 08:14:04PM +0200, Holger Macht wrote:

 > > +/** @brief set a speed with traversing all intermediary speeds */
 > > +static int set_speed(struct userspace_interface *iface, int target_speed)
 > > +{
 > > +	int delta;
 > > +	int current_speed = iface->current_speed;
 > > +
 > > +	if (current_speed == target_speed)
 > > +		return -1;
 > > +
 > > +	if (current_speed > target_speed)
 > > +		delta = -1;
 > > +	else
 > > +		delta = 1;
 > > +
 > > +	do {
 > > +		current_speed += delta;
 > > +		write_speed(g_a_i(iface->speeds_kHz, current_speed), iface->base_cpu);
 > > +	} while (current_speed != target_speed);
 > > +
 > > +	return current_speed;
 > > +}
 > > 
 > > This looks seriously nasty.  If we're running at 2GHz and have a
 > > target of 800MHz, that's 1200 writes to sysfs we're going to do,
 > > which is just insane.
 > That's not the case.
 > 
 > > 
 > > The kernel exports the available steps for a reason, so that you
 > > don't have to guess at speeds like this.
 > 
 > The array iface->speeds_kHz only contains the steps exported by the
 > kernel. The current_speed variable is only used as the index of the array.

Ah, I missed this, in which case, it all looks very sensible :-)

		Dave

-- 
http://www.codemonkey.org.uk


More information about the hal mailing list