Skip to contentSkip to conversation

Notes: automatic fan clock divider selection in adm9240

DISCUSSION Grant Coady 3 participants 3 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Greetings,

Working on tweaking adm9240 driver, just finished documenting a method for automatic fan clock divider control in the driver. Code suggested by Jean Delvare, implemented and tweaked for correct behaviour in the face of unreasonable user input.

Please note the driver I wish I hadn't posted twice (by accident) last night is not finished. Current driver is at
http://scatter.mine.nu/lmsensors/adm9240/adm9240.c
and may be posted again as a patch later today, with documentation.

Latest driver documentation at
http://scatter.mine.nu/lmsensors/adm9240/
which is what I am mainly working on now for the adm9240 driver.

Test scripts and results from same location.

Cheers,
Grant.

automatic fan clock divider selection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
problem

````````
1. End user turns on lmsensors and gets a zero fan speed reading, fan is 
   spinning, why does this happen?

2. Confusion over how fan speed is measured with the common 22500Hz clock 
   via a fan clock divider and gated into a counter for one fan revolution
   period.  Chips usually count alternate pulses, so the fan is expected 
   deliver two pulses per revolution.

3. If a particular fan delivers more or less than two pulses per revolution, 
   the indicated fan speed may be scaled in user space.  The sensor fan 
   clock divider does not perform this function.  The sensor fan clock 
   divider adjusts the range and resolution of the fan speed measurement 
   reported by the chip and thus the driver.

4. A common default fan clock divider is two, this suits fans that run at 
   3000..5000 rpm but gives no fan speed reading for slower fans.

solution
`````````

Automatic fan clock divider selection in the driver, simplify the user interface and Just Works.

user control

`````````````
Most reliable method for automatic fan clock divider selection is when 
the user specifies a minimum fan speed alarm point.  This tells the 
driver what speed range the user expects and the driver tries to adjust 
to that, if it cannot, known behaviour results:

* If the user specifies a value too low to be measured, low 
  speed alarm will be disabled.

* If the user specifies a way too high low speed setting, the 
  fan speed alarm will be asserted.

driver control
```````````````

In the absence of user setting a reasonable fan speed limit, the driver will adjust the fan clock divider to provide a valid fan speed indication.

implementation

```````````````
adm9240 implements automatic fan clock divider selection using a method 
suggested by Jean Delvare with some tweaking to suit observed performance, 
particularly behaviour in response to unreasonable user input.

loss of information?
`````````````````````

Fan clock divider accessors are no longer supported by adm9240, but the fan clock divider changes are reported to the debug log. Example, 'modprobe adm9240; wy_set_limits' results in /var/log/debug:

Apr 11 07:49:33 peetoo kernel: adm9240 0-002d: adm9240 stopped, started comparator mode
Apr 11 07:49:44 peetoo kernel: adm9240 0-002d: adjust fan 1 clock divider to 4
Apr 11 07:49:44 peetoo kernel: adm9240 0-002d: adjust fan 2 clock divider to 8
#1 lore raw

Hi Grant,

Quoted 4 lines

Working on tweaking adm9240 driver, just finished documenting a method for automatic fan clock divider control in the driver. Code suggested by Jean Delvare, implemented and tweaked for correct behaviour in the face of unreasonable user input.

I am all in favor of this (obviously). Could you please detail what kind of changes you did on top of my original w83627ehf code? If it sounds good I'll backport to my driver.

Thanks,
--
Jean Delvare

#2 lore raw
In reply to Grant Coady

Hi Khali, All,

Quoted 8 lines · Jean Delvare
Quoted 4 lines

Working on tweaking adm9240 driver, just finished documenting a method for automatic fan clock divider control in the driver. Code suggested by Jean Delvare, implemented and tweaked for correct behaviour in the face of unreasonable user input.

I am all in favor of this (obviously). Could you please detail what kind of changes you did on top of my original w83627ehf code? If it sounds good I'll backport to my driver.

the rules are (correct me if I got it wrong again):

1. user sets fan speed limit to zero
disable low fan speed alarm, no touch fan_div

2. user set fan speed limit too low to measure
set fan_min to 254 * div_max, set fan_div to div_max (8 in my case)

enable low speed alarm, an alarm will be reported when fan speed drops below measurable range

3. otherwise
select fan clock divider to suit new low fan speed limit enable low fan speed alarm

the fan speed measurement code will adjust fan clock divider to ensure the fan speed will be reported, an adjustment in fan clock divider will also adjust fan low speed limit point, but not to 0.

point 2 is different and allows driver to report fan speed alarm while fan speed is too slow to measure

point 3 changes: stop fan_div going one step too far, forcing fan_min to be > 0 as zero is an error state that should not happen (potential for div/0).

Please let me know if you want me to update lm87.c again, or any driver you can test. Once you okay the algorithm I can start on other drivers.

Current test generator and older results here:
http://scatter.mine.nu/hwmon/auto-fan-div/zx-test-fan-div

Yesterday and this morning I separated error sources in auto fan clock divider operation:

* An error in setting fan minimum limit due to rounding large numbers to register size with discrete fan clock dividers.

This is set a fan minimum speed limit, then read it back to check computation and rounding errors.

* An error introduced when auto fan clock divider adjusts fan_min to keep fan speed reporting. The system trades off minimum speed limit setpoint accuracy for being able to always display fan speed.

Implications for user-space ````````````````````````````
Fan readings should be retried when zero is reported, auto fan clock divider operation is in response to reading the fan speed.

Auto fan clock divider adjustment (as currently implemented) can only change fan clock divider one step per read.

adm9240 driver has a 1.75s measurement cycle to accommodate sleep 2 in scripts :)

Example shell script for retry on zero fan speed:

#!/bin/bash
#
# demonstration: reading fan speed from adm9240
#
# Copyright (C) 2005 Grant Coady <[email protected]> #
# GPLv2 per linux/COPYING by reference
#
devpath="/sys/bus/i2c/devices/0-002d"
#
case $1 in
1) fanpath="$devpath/fan1_input";;
2) fanpath="$devpath/fan2_input";;
*) echo -e "\n\tUsage: $0 <fan_number>\n"; exit 1;;
esac

retry=1
retry_max=3

echo -e "\n\tReading $fanpath"
read fan_rpm < "$fanpath"

while [ $fan_rpm -eq 0 -a $retry -le $retry_max ]; do
echo -e "\twait for retry $retry" sleep 2
read fan_rpm < "$fanpath"
(( retry++ ))
done
echo -e "\tFan $1 rpm = $fan_rpm\n"
#end

Okay, there it is, and in writing this closing note on auto fan div I realise the current algorithm has one drawback, the requirement for the retries in order to get a fan speed reading under some conditions.

Considering some chips have seven fan clock divider values, waiting up to a quarter minute for valid fan speed indication is a little too much?

--Grant.