Showing posts with label power. Show all posts
Showing posts with label power. Show all posts

21.7.10

VIA Epia Homeserver Project - HDD Power Saving

The power consumption of a hard disk cannot be neglected in a system designed to be of low consumption. For the operating system, a flash based drive (SSD or CF disk) is a good solution, yet for high volume storage this is usually not affordable. Recently, hard disk drives in the terrabyte range especially designed to be power efficient have been announced such as Western Digital's Greenpower series or the Ecogreen drives of Samsung. Their offer is  a substantial decrease of power consumption (up to 40% claimed) at the expense of somewhat slower operation. This is achieved for instance by spinning only at 5400rpm instead of 7200rpm, which is still reasonable for media storage or backup and even for office applications.

This tutorial is on setting up a Samsung Ecogreen HD154UI drive in my Via Epia homeserver. The goal was to make use of the power saving features that the drive has to offer using the native linux tool hdparm.
This is a very powerful (and therefore dangerous!) program that can read or set many parameters of PATA or SATA drives in order to tune performance, power consumption, or even hot swap disks. As of the writing of this tutorial, I use hdparm v8.9, note that syntax might change later on. It is also important that the proper driver for the PATA and SATA chipset is either compiled in the kernel or loaded as a module.

All functionality of hdparm is available through command line, yet it is better to use /etc/hdparm.conf to adjust parameters, as it will make those effective after each system boot. Mine looks like this:

/dev/sda {
    dma = on
    interrupt_unmask = on
    mult_sect_io = 16
    write_cache = on
    transfer_mode = 70
    io32_support = 1
    apm = 1
    spindown_time = 60
}

with dma = on meaning DMA instead of PIO (this is the default anyway). Interrupt_unmask = on allowing the system to process multiple IRQs at the same time. mult_sect_io = 16 determines the number of simultaneously transferred blocks (safe to set it to its maximum value). Write_cache = on tells the system to cache write operations. This might be dangerous if a power-cut occurs, yet usually is a good idea to set. Transfer_mode = 70 sets UDMA6. Other UDMA, DMA, PIO settings can be found here. io32_support = 1 is quite straightforward and should be set as well. 

The rest are the power saving parameters: apm = X sets how aggressively the drive would enter power saving modes with 1 equals the lowest consumption and 255 means no power saving and maximum performance. Note that X being equal to 128 or above, no spindown is allowed. As I use my disk mostly for storage, I chose the lowest power setting, X=1. Spindown_time sets the length of inactivity before the drive spins down in 5 sec units, so that 60 means 5 minutes timeout. If you experience that you have to wait often to the drive to spin up, consider setting this parameter higher. 

It is very important to note that not only disk I/O but any disk operation including checking drive health status using smartmontools will cause the drive to spin up. This means that periodic checking of drive health or temperature will render this setting essentially useless.

If hdparm.conf is set up correctly, the new parameters will be effective upon the next boot and can be checked:

~#: hdparm -i /dev/sda

/dev/sda:

 Model=SAMSUNG HD154UI                         , FwRev=1AG01118, SerialNo=S1XWJ1KZ300133     
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=34902, SectSize=554, ECCbytes=4
 BuffType=DualPortCache, BuffSize=32767kB, MaxMultSect=16, MultSect=?16?
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=18446744072344861488
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4
 DMA modes:  mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6
 AdvancedPM=yes: unknown setting WriteCache=enabled
 Drive conforms to: unknown:  ATA/ATAPI-3,4,5,6,7

 * signifies the current active mode


20.7.10

VIA Epia Homeserver Project - CPU Frequency Scaling

Even though the VIA Epia platform is designed to be very power efficient out of the box, it can be made even better. One tool to do this is the CPU frequency scaling that is supported by both recent linux kernels and the Eden CPU. Specifically, the processor of the EN12000EG board runs at 1200MHz by default, but can go down to as low as 400MHz, resulting not only in reduced power consumption, but decreased heating as well. This especially comes handy for fanless systems, eventually resulting in lower die temperature and longer life span.

System setup

In order to utilize this feature the following kernel modules have to compiled (=Y), or installed as module (=M):
X86 CPU: CONFIG_X86_CPU=y 
VIA C7 CPU: CONFIG_MVIAC7=y

ACPI: (not sure if these are necessary, yet they won't hurt...)
CONFIG_ACPI=y 
CONFIG_ACPI_PROCESSOR=y

CONFIG_X86_PCC_CPUFREQ=y
CONFIG_X86_ACPI_CPUFREQ=y

(Note: # CONFIG_X86_E_POWERSAVER is not set because it is considered to be dangerous as no hardware limits are taken into account while tuning the CPU clock. However, I did not find any remarks nor observations on this driver).

CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_TABLE=y
CONFIG_CPU_FREQ_STAT=y
CONFIG_CPU_FREQ_STAT_DETAILS=y
CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=y
CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
CONFIG_CPU_FREQ_GOV_POWERSAVE=y
CONFIG_CPU_FREQ_GOV_USERSPACE=y
CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y

The options above sets the Governors that can be used later on. As you can see, there are five alternatives, Performance, Powersave, Userspace, Ondemand and Conservative.
The character of each governors  are the following:
  •  Performance: simply sets the highest available CPU frequency. Usually this is the default in stock kernels.
  • Powersave: sets the lowest available frequency no matter what the system load is.
  • Userspace: the CPU clock can be set manually thorugh the /sys interface
  • Ondemand: switches between the highest and lowest frequency according to the system load. The corresponding thresholds can be set via the the /sys interface. 
  • Conservative: such as above, although it can set intermediate frequency values as well. The trade-off is higher latency.
The default governor is quite straightforward to set, here I chose Conservative. In this tutorial, only this governor is discussed in detail, however, most of the arguments are straightforward to use for the others as well.

Test results

Upon booting with the new kernel and/or loading the corresponding modules, the influence of the governor is already visible (remember, Conservative governor is set):

#:  cat /proc/cpuinfo
processor    : 0
vendor_id    : CentaurHauls
cpu family    : 6
model        : 10
model name    : VIA Esther processor 1200MHz
stepping    : 9
cpu MHz        : 400.000
cache size    : 128 KB
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 1
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge cmov pat clflush acpi mmx fxsr sse sse2 tm nx pni est tm2 rng rng_en ace ace_en ace2 ace2_en phe phe_en pmm pmm_en
bogomips    : 797.99
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 32 bits virtual
power management:

showing that the CPU clock is set to 400MHz. If, however, some CPU intensive process is started (compiling kernel or some application is a good check :)) then increased demand results in increased clock frequency:

#:  cat /proc/cpuinfo
processor    : 0
vendor_id    : CentaurHauls
cpu family    : 6
model        : 10
model name    : VIA Esther processor 1200MHz
stepping    : 9
cpu MHz        : 1200.000
cache size    : 128 KB
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 1
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge cmov pat clflush acpi mmx fxsr sse sse2 tm nx pni est tm2 rng rng_en ace ace_en ace2 ace2_en phe phe_en pmm pmm_en
bogomips    : 2393.89
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 32 bits virtual
power management:

Detailed statistics is available via the /sys interface:

#: cat /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
1200000 38445
400000 42604408

which tells us both the available frequency values (in kHz) and the corresponding time that the CPU spent in that state in 10ms.

#: cat /sys/devices/system/cpu/cpu0/cpufreq/stats/trans_table
   From  :    To
         :   1200000    400000
  1200000:         0        51
   400000:        50         0 

This command provides a nice matrix in which the starting and end frequency for each transition is observed. Note that as the system boots up using the higher value, the difference of one means that now the clock is equal to the lower value.

The current frequency can be obtained as above by interrogating /proc/cpuinfo, however /sys tells it as well:

#: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
400000

The operation of this governor can be tuned via the nodes in /sys/devices/system/cpu/cpu0/cpufreq/conservative (followed by their default values):

down_threshold (20)
freq_step (5)
ignore_nice_load (0)
sampling_down_factor (1)
sampling_rate (200000)
sampling_rate_max (4294967295)
sampling_rate_min (200000)
up_threshold (80)

I however advise to be careful tampering with them. As each clock transition takes time the penalty can be serious performance degrade if the system is set to change frequency too often. On the other hand, increasing power consumption and heating is the result of too soft settings.

Conclusions

Using the Conservative governor is a reasonable improvement for my VIA Epia box, as the system now spends most of its time (over 99%!) in 400MHz instead of 1200MHz. In theory, however, some degradation of performance is associated with tuning the CPU frequency (as the clock transition takes time to occur), this was not observable for my system. 

Sadly enough, the governor was not able to tune the CPU clock continuously, it rather switched between the highest and lowest available values. Because of this, the Conservative and Ondemand governors essentially equivalent on this system. I am not sure if using CONFIG_X86_E_POWERSAVER instead of the default ACPI cpufreq driver solve this problem, this is to be tested.

20.5.10

VIA Epia Homeserver Project - Ingredients

I recently decided to put together a small linux box to be a media- and fileserver and router and to be a good playground as well :) My goal is to have a box which is small, quiet and has a low power consumption and not to be forgotten, cheap. From now on, I will write about how to put it together from the bare scratch.
Let's see the ingredients for this project:

Motherboard:

I chose VIA Epia series because of its good availability and because of having a very good power consumption figure. Note that if you plan to play HD movies directly then this is most likely not your platform (better pick something based on Intel's Atom), yet for a router / file server box it is a good trade-off. For a router we need two physical ethernet interface and for high capacity storage SATA connectors. This is what one has to bear in mind when picking the actual device.
I chose EN12000EG because..., well it was a good deal on ebay :) Yet, it has two onboard SATA connectors, and one can add an additional ethernet interface via its PCI slot which is what I exactly did by putting a RTL8169-based gigabit ethernet card in. The motherboard is based on a VIA Eden processor meaning that it is completely fanless which is an important point as well.
Regarding to the memory: One 256MB 533MHz DDR2 one would do it, as we will not need anything that consumes a great deal of system memory. It has to be noted however that the onboard VGA takes 64MB out of the value above.
It is a good thing that the motherboard is well documented, all documentation is available at VIA.

System hard disk:

For this purpose, I will use a 4GB CF card, which is enough for the bare system. To hook this up to the main board, a CF to IDE converter is necessary, which is in the 1 USD range on ebay. Note that it is a good idea to buy a dual CF converter (so that one will be the master and one will be the slave device) for optional temporary storage for for instance torrent, as the main hard disk can be still turned off and does not consume any power. 

Main hard disk:

This will be a Samsung EcoGreen drive as we do not need really fast random seek, rather a low power and reasonable sized storage. Anyhow, the box should be designed so that it turns off the hard drive whenever possible.

Case:

For some reason, cases designed for mini-ITX motherboards are rather expensive. Because of this, I choose a mini-ATX /ITX case, Codegen's MX-31-A2. The only drawback is that the built-in power supply is designed to be capable of 300W output so that it is expected to have very low efficiency for low power systems. This is to be measured later so that I can decide whether it is necessary to replace it.

20.3.10

HP Notebook slow while plugged in

I recently encountered a quite strange behavior of my HP 6910p computer. It became extraordinary slow if hooked on the charger. By slow I mean that Windows booting up took more than half an hour (I tested this only once :) ) and afterwards Task Manager showed 100% CPU usage for both cores all the time, no matter if no userspace program was running. This itself could have been a simple Windows issue, but essentially the same happened for a Linux Live CD, and even worse: the BIOS menu was definitely slow to respond. However if I removed the charger (so that it ran on battery), everything went back to normal. 
Realizing that this is a hardware problem I had it repaired under warranty (they replaced the motherboard), after which everything went normal for some days and then the issue reappeared. This happened during the weekend (obviously) so I had to do something. What I noticed was that by moving the cable of the charger sometimes it can be healed. So the resolution was simple: the wire is broken somewhere. But which wire? I have never noticed a power failure, meaning that only the third one in the middle can be the source of the problem. Yes, recent notebooks demand a charger with an additional line which might tell if the charger is a proper one or not. If this connection is not present then the power management of the notebook must fall back to some extra low profile rendering the CPUs slow and the computer essentially useless.
So apart from saying a big thanks to HP I only could cut the wiring open and resolder this inner wire after which I applied a plenty of thin teflon tape to prevent it from either breaking or shorting to the other ones.
Now everything is back to normal, the long-term solution however is buying a new power supply.

28.1.10

Inside a LED lamp

Using LED lamps instead of incandescent bulbs and fluorescent lamps is argued to be power efficient thus economically favorable. Longer life span is also usually cited as an advantage. I wanted to look into the details for a long time and recently I ordered some LED lamps on ebay, so I took one of them apart to see what is inside...
The lamp is a 48 LED device, and is written to use 4.5W on a 230V power supply. My intention is to present the schematics of the lamp so that we can see the details of its operation.

LED basics:


Just to understand the main building block of the lamp: LEDs (light emitting diodes) are semiconductor heterostructure devices meaning that they have rectifying properties so that current only passes through one direction, while in the other way around it doesn't. While this is true for all diodes, the plus for LEDs is that light emission will happen only when they are conducting. Even if this is the case there is a certain threshold for the light emission to start which is around 3.5V for blue and white LEDs. Above this threshold the current through the device rises exponentially so it needs to be regulated which is usually achieved by either an external resistor in series or a current generating power supply circuit.

LED lamp:


Let's see what we have here: Regulation on the AC side is done by C1 as it acts as a finite impedance at 50Hz. The point is that the this is achieved without any unnecessary dissipation as there is no heat generated on C1. D1 is an integrated Graetz-bridge which rectifies the input voltage. The role of C2 is smoothing the output and R4 is an additional protection for the LED block. R1, R2 and R3 discharge the capacitors after switching the lamp off (most likely due to safety reasons). I also put some measurement data on the schematics: the 48 LEDs in series operate from a sum of 179V meaning that each LED has a voltage drop of 3.73V on average, in good agreement with our expectations. The 110mV voltage across the 10 Ohm resistor tells that 11mA flows through the LEDs meaning that the dissipation of the block is 11mA×179V=1.97W which is way lower than the expected 4.5W! Indeed it is not surprising that the light output of this lamp is not enough especially if compared to compact fluorescent lamps. The power factor can also be calculated: the voltage drop over C1 is 124V leading to a  power factor of 0.84. This value of course becomes important if LED lighting is to take a major role in households.
In conclusion it turns out that the electrical circuit is as simple as possible leading to a high average lifetime of the device (I expect it to be comparable to the couple of thousand hours of compact fluorescent lamps). No 50Hz wobbling of the light output is also a benefit of the device. However the efficiency of the principle described above is given by the fact that many low power LEDs was put in series leading to a voltage drop of 179V on the LED block with only 11mA current consumption. High power LEDs cannot be used this way since each single (!) chip has a light output better then this entire block while consuming several hundred mA-s at around 3.5V (a good example is Cree's XLamp series). This means that a more complicated power supply is necessary for such a LED lamp which together with the more expensive LED means more expensive device but way better light output as well (especially true for devices equipped with three or four high power LEDs), so I recommend buying such a lamp instead of these cheap ones.

16.1.10

Why not charging battery on wifi signal?

I just became aware of this nice piece of video made on CES 2010.



They argue that batteries of cellphones and similar devices can be recharged by solely relying on power emitted by wifi hotspots. In fact for me this is somewhat hard to believe so let's make some calculations:
First, let's assume that the efficiency of the device is 100%, meaning that all received signal is converted to battery power (this is quite optimistic, since charging up a battery usually worse than 70%). Anyhow, if we have a single cell LiIon battery of 1500mAh, that will need approximately 1.5Ah*3.7V=5.55Wh energy input to be charged up completely.
Now let's see the other side of the equation: According to this howto page, the maximum transmitted power of a wifi hotspot can be 1W. This itself would be sufficient if we can catch everything, our battery is charged up in 5.55 hours. In fact, usually this is not the case (luckily for others, because they still would like to use wifi as it is intended :) ). For me it seems, that the size of the device is around 5cm × 10cm, giving an area of 50cm^2. You can measure this for example at 2:24 in the video above, where you have the hand of the guy for comparison. In this case, if we are 1m away from the access point, then this 1W goes through an area of 12.5m^2 (simply assuming that it the pattern isotrop), meaning that we catch 0.005/12.5=0.0004 part of the transmitted power. This is 0.04%! Anyhow, we get a power input of 0.4mW, so the time we need to charge up the battery above will be:
5.55Wh/0.0004W = 13875h = 578 days = 1.6 years.
I think I have been quite generous with the approximations above, so this might be some sort of best case scenario :) In fact, if go further away from the access point, the power input will cut off with the second power of the distance, and also the power conversion can add a factor of at least two.
I anyhow wish good luck for every end users so that they can make a single charge once every elections :)