{"id":351,"date":"2013-11-07T10:06:10","date_gmt":"2013-11-07T09:06:10","guid":{"rendered":"http:\/\/www.simweb.ch\/blog\/?p=351"},"modified":"2013-11-07T10:08:05","modified_gmt":"2013-11-07T09:08:05","slug":"atom-d510-freebsd-cpu-scaling-temperature-and-the-non-existing-c-states","status":"publish","type":"post","link":"https:\/\/www.simweb.ch\/blog\/2013\/11\/atom-d510-freebsd-cpu-scaling-temperature-and-the-non-existing-c-states\/","title":{"rendered":"Atom D510: FreeBSD cpu scaling, temperature and the non-existing C-states"},"content":{"rendered":"<p>A D510MO board was lying in the shelves and I decided to give a try for some FreeBSD testing. One topic I wanted to check out was power saving and getting to know. Most CPUs nowadays (even the now dated D510 Atom) support frequency scaling and most often C-States. Without digging into the details of FreeBSD's 'powerd' enabling basic frequency scaling works as simple as adding the following line to \/etc\/rc.conf<\/p>\n<p>powerd_enable=\"YES\"<\/p>\n<p>sysctl can tell us what frequencies the CPU can work at ans the current freqency:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\"># sysctl dev.cpu | grep freq\r\ndev.cpu.0.freq: 208\r\ndev.cpu.0.freq_levels: 1666\/-1 1457\/-1 1249\/-1 1041\/-1 833\/-1 624\/-1 416\/-1 208\/-1<\/pre>\n<p>Now to check if the frequency scaling was working, hitting the CPU with some load was required, but where to take? On Windows a pretty simple tip taken from old journals was to fire up the system calculator app in scientific mode and let it calculcate very large factorials (german: Fakult\u00e4t) like 999999999999! which will load the CPU and cause some heating in order to verify how loud a system can become - or in this case: Cause the CPU frequency to go up under load and scale down when back idle. It turns out FreeBSD base ships a with console-based calculator \u00a0called bc (on most Linuxes it's GNU bc) which according to this yet old but still working article in Linux journal allows exactly this with a factorial function:<\/p>\n<pre># bc\r\ndefine f(x) {\r\n if (x &lt;= 1) return (1);\r\n return (x*f(x-1));\r\n}\r\n\r\nf(999999999)<\/pre>\n<p><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;\">In parallel on a second terminal execute \"powerd -v\" to see how the frequency goes up and down:<\/span><\/p>\n<pre class=\"brush: actionscript3; gutter: true; first-line: 1\"># powerd -v\r\npowerd: unable to determine AC line status\r\n[... system is idle, starting bc in the meantime ...]\r\nload   0%, current freq  208 MHz ( 7), wanted freq  208 MHz\r\nload   0%, current freq  208 MHz ( 7), wanted freq  208 MHz\r\nload   4%, current freq  208 MHz ( 7), wanted freq  208 MHz\r\n[...]\r\nload  38%, current freq  416 MHz ( 6), wanted freq  261 MHz\r\nload 141%, current freq  416 MHz ( 6), wanted freq 1044 MHz\r\nchanging clock speed from 416 MHz to 1249 MHz\r\nload 100%, current freq 1457 MHz ( 1), wanted freq 3332 MHz\r\nchanging clock speed from 1457 MHz to 1666 MHz\r\nload  93%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\nload 100%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\nload 100%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\nload 101%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\nload 100%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\n[ ... bc is running and now gets stopped ...]\r\nload 100%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\nload  68%, current freq 1666 MHz ( 0), wanted freq 3332 MHz\r\nload   0%, current freq 1666 MHz ( 0), wanted freq 3227 MHz\r\nload   0%, current freq 1666 MHz ( 0), wanted freq 3126 MHz\r\nload   0%, current freq 1666 MHz ( 0), wanted freq 3028 MHz\r\n[...]\r\nload   0%, current freq 1666 MHz ( 0), wanted freq 1453 MHz\r\nchanging clock speed from 1666 MHz to 1457 MHz\r\nload   0%, current freq 1457 MHz ( 1), wanted freq 1407 MHz\r\n[...]\r\nload   0%, current freq 1457 MHz ( 1), wanted freq 1238 MHz\r\nchanging clock speed from 1457 MHz to 1249 MHz\r\nload   0%, current freq 1249 MHz ( 2), wanted freq 1199 MHz\r\n[... we see all supported clock speeds freq_levels passing by]\r\nload   0%, current freq  416 MHz ( 6), wanted freq  208 MHz\r\nchanging clock speed from 416 MHz to 208 MHz\r\nload   6%, current freq  208 MHz ( 7), wanted freq  208 MHz<\/pre>\n<p>This little experiment show that powerd is not that agressive when slowing the frequency back down as quickly as it rushes up, maybe tha its something to tune more aggressively on laptops.<\/p>\n<p><strong>Temperature readings<\/strong><\/p>\n<p>For CPU temperatures it happens to be as simple as loading the 'coretemp' module via kldload coretemp. Adding\u00a0coretemp_load=\"YES\" to \/boot\/loader.conf enables the module ad system start. Afterwards CPU temperatures were readable via sysctl too:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\"># sysctl dev.cpu | grep temperature\r\ndev.cpu.0.temperature: 44.0C\r\ndev.cpu.1.temperature: 44.0C\r\ndev.cpu.2.temperature: 41.0C\r\ndev.cpu.3.temperature: 42.0C<\/pre>\n<p><strong>C-States<\/strong><\/p>\n<p>Now most CPUs also support C-States to send to sleep when possible which would be actually quite good for power saving. In FreeBSD it seems sysctl can be used to query what C-states the CPU cores support via dev.cpu.&lt;id&gt;.cx_supported i.e.<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\"># sysctl dev.cpu.1\r\n[...]\r\ndev.cpu.1.cx_supported: C1\/1\/3\r\ndev.cpu.1.cx_lowest: C1\r\ndev.cpu.1.cx_usage: 100.00% last 58973us\r\n[...]<\/pre>\n<p><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;\">Technically this would suggest that the CPU has the capability to use C3 but the current lowest C-State would be C1? I tried sysctl dev.cpu.1.cx_lowest=C3 as well as the global hw.acpi.cpu.cx_lowest=C3 (for boot this would be put in \/etc\/syctl.conf) but allas it remained always using 1 C-State.<\/span><\/p>\n<p>It seems the Atom D510 is one of those low-end CPUs that do not support C-States anyway as per <a href=\"http:\/\/ark.intel.com\/products\/43098\/\">ark.intel.com<\/a>. I've come across this thanks to <a href=\"http:\/\/www.freebsd.org\/cgi\/query-pr.cgi?pr=160561\">FreeBSD PR 160561<\/a> where a very similar D525 was reported.<br \/>\nPossibly the CPU isn't telling correctly about its supported C-states allas.<\/p>\n<p>This was done on FreeBSD 10-BETA3 btw.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A D510MO board was lying in the shelves and I decided to give a try for some FreeBSD testing. One topic I wanted to check out was power saving and getting to know. Most CPUs nowadays (even the now dated D510 Atom) support frequency scaling and most often C-States. Without digging into the details of &#8230; <a class=\"moretag\" href=\"https:\/\/www.simweb.ch\/blog\/2013\/11\/atom-d510-freebsd-cpu-scaling-temperature-and-the-non-existing-c-states\/\">more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[37,36,38],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-atom","tag-freebsd","tag-powerd"],"_links":{"self":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":0,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simweb.ch\/blog\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}