Category Archives: Uncategorized

Saving Power with CPU Frequency Scaling

Yesterday I wrote about the climate crisis. Today, let’s start doing something about it.

Electricity, especially in the United States and China, turns out to be a pretty dirty energy source. Most of our electricity is generated using coal, which despite promises of “clean coal” to come, burns dirty. Not only does it contribute to global warming, but it also has been shown to have an adverse impact on health.

So let’s start simple: reduce the amount of electricity our computers consume. Even for an individual person, this can add up to quite a bit of energy (and money) savings in a year. When you think about multiplying this over companies, server rooms, etc., it adds up fast. This works on desktops, servers, laptops, whatever.

The easiest way to save power is with CPU frequency scaling. This is a technology that lets you adjust how fast a running CPU runs, while it’s running. When CPUs run at slower speeds, they consume less power. Most CPUs are set to their maximum speed all the time, even when the system isn’t using them. Linux has support for keeping the CPU at maximum speed unless it is idle. By turning on this feature, we can save power at virtually no cost to performance. The Linux feature to handle CPU frequency scaling is called cpufreq.

Set up modules

Let’s start by checking to see whether cpufreq support is already enabled in your kernel. These commands will need to be run as root.

# cd /sys/devices/system/cpu/cpu0
# ls -l

If you see an entry called cpufreq, you are good and can skip to the governor selection below.

If not, you’ll need to load cpufreq support into your kernel. Let’s get a list of available drivers:

# ls /lib/modules/`uname -r`/kernel/arch/*/kernel/cpu/cpufreq

Now it’s guess time. It doesn’t really hurt if you guess wrong; you’ll just get a harmless error message. One hint, though: try acpi-cpufreq last; it’s the option of last resort.

On my system, I see:

acpi-cpufreq.ko     longrun.ko      powernow-k8.ko         speedstep-smi.ko
cpufreq-nforce2.ko  p4-clockmod.ko  speedstep-centrino.ko
gx-suspmod.ko       powernow-k6.ko  speedstep-ich.ko
longhaul.ko         powernow-k7.ko  speedstep-lib.ko

For each guess, you’ll run modprobe with the driver name. I have an Athlon64, which is a K8 machine, so I run:

#modprobe powernow-k8

Note that you leave off the “.ko” bit. If you don’t get any error message, it worked.

Once you find a working module, edit /etc/modules and add the module name there (again without the “.ko”) so it will be loaded for you on boot.

Governor Selection

Next, we need to load the driver that tells the kernel what governor to use. The governor is the thing that monitors the system and adjusts the speed accordingly.

I’m going to suggest the ondemand governor. This governor keeps the system’s speed at maximum unless it is pretty sure that the system is idle. So this will be the one that will let you save power with the least performance impact.

Let’s load the module now:

# modprobe cpufreq_ondemand

You should also edit /etc/modules and add a line that says simply cpufreq_ondemand to the end of the file so that the ondemand governor loads at next boot.

Turning It On

Now, back under /sys/devices/system/cpu/cpu0, you should see a cpufreq directory. cd into it.

To turn on the ondemand governor, run this:

# echo echo ondemand > scaling_governor

That’s it, your governor is enabled. You can see what it’s doing like this:

# cat cpuinfo_min_freq
800000
# cat cpuinfo_max_freq
2200000
# cat cpuinfo_cur_freq
800000

That shows that my CPU can go as low as 800MHz, as high as 2.2GHz, and that at the present moment, it’s running at 800MHz presently.

Now, check your scaling governor settings:

# cat scaling_min_freq
800000
# cat scaling_max_freq
800000

This is showing that the system is constraining the governor to only ever operate on an 800MHz to 800MHz range. That’s not what I want; I want it to scale over the entire range of the CPU. Since my cpuinfo_max_freq was 2200000, I want to write that out to scaling_max_freq as well:

echo 2200000 > scaling_max_freq

Making This The Default

The last step is to make this happen on each boot. Open up your /etc/sysfs.conf file. If you don’t have one, you will want to run a command such as apt-get install sysfsutils (or the appropriate one for your distribution).

Add a line like this:

devices/system/cpu/cpu0/cpufreq/scaling_governor = ondemand
devices/system/cpu/cpu0/cpufreq/scaling_max_freq = 2200000

Remember to replace the 2200000 with your own cpu_max_freq value.

IMPORTANT NOTE: If you have a dual-core CPU, or more than one CPU, you’ll need to add a line for each CPU. For instance:

devices/system/cpu/cpu1/cpufreq/scaling_governor = ondemand
devices/system/cpu/cpu1/cpufreq/scaling_max_freq = 2200000

You can see what all CPU devices you have with ls /sys/devices/system/cpu.

Now, save this file, and you’ll have CPU frequency scaling saving you money, and helping the environment, every time you boot. And with the ondemand governor, chances are you’ll never notice any performance loss.

This article showed you how to save power using CPU frequency scaling on Linux. I have no idea if it’s possible to do the same on Windows, Mac, or the various BSDs, but it would be great if someone would leave comments with links to resources for doing that if so.

Updated: added scaling_max_freq info

The Climate Crisis

Wow.

We just watched An Inconvenient Truth. Not much in there was new to me, but to see it all presented at once is amazing.

There are vast undisputed scientific facts out there — for instance, that CO2 content in the atmosphere is higher than it’s been ever — and we can go back 650,000 years. The linkage between that and temperatures is inescapable.

Gore makes a good point: shouldn’t we be worried about more than terrorism?

Does the thought of parts of Manhattan, San Francisco, and large parts of Florida going underwater suggest a problem exists?

This really is critical and urgent.

We’ve already been thinking about it lately as we renovate our house. We’re paying a little more now for things like airtight insulation, low-energy lighting, efficient heating. Not only will it save us money in the long run, it will help improve our lives and Jacob’s life down the road.

The movie’s website is over at climatecrisis.net.

Reactions to Israel and Lebanon

I was surprised by the reactions to my story Saturday on Israel and Lebanon. Several pro-Israel posters are apparently in complete denial about what the Israeli military forces are doing.

Today, the American network ABC reported that Israel had bombed a Kleenex manufacturer, numerous farms, and all the major roads out of Lebanon. And they showed pictures of all of these during their evening newscast.

I find it highly unlikely that ABC is making this up.

One person asked, essentially, “do you really think a democracy could do this?” Yes. It’s happened many times before. The United States and Britain did this sort of thing when they destroyed tens of thousands of homes and killed over 25,000 people, most of them civilians, in the bombing of Dresden. The United States also was responsible for the nuclear bombs dropped over japan, killing 140,000 people instantly and countless more due to the effects of the atomic weapon.

Being a democracy is no guarantee against extremism. Some Israel supporters need to take a hard look at what their military is doing.

As I explained, none of this is to defend the attacks against Israel, which of course are also terrible.

But I think Israel’s strategy is going to wind up costing them — they are creating huge numbers of angry Lebanese, that perhaps didn’t have the motivation to attack Israel before, but now do. (Of course, the same error could be attributed to their enemy)

And both sides are catching innocent civilians more than military targets.

It’s very sad.

Israel and Lebanon

You know, I’m sick and tired of this whole “you wronged us, therefore you will pay” attitude that there seems to be in international politics today. Both sides of the whole terrorism thing seem to have that attitude.

But the latest sanity-defying news is that Israel is bombing wheat silos, food stores, and lines of civilians trying to escape Lebanon. Huh? What is the strategic value in having starving civilians in Lebanon? To me, it seems like a recipe to make things worse for Israel. You kill people’s family in Lebanon, and you create large numbers of very mad family members that now have a reason to plan terrorist attacks on Israel.

It defies sense.

Why don’t people try to value human life for once, everywhere?

Today’s New Word: “Tuttled”

So remember Jerry Taylor, the man from Tuttle, OK that threatened to call the FBI on a Linux vendor because an unrelated hosting company had misconfigured Apache?

Well, this story is just getting funnier and funnier.

First off is this story from the Tuttle Times. It basically repeats Taylor’s view that the CentOS people were expected to help him with his problem, and that he was somehow entitled to their help. But there are some funny tidbits in the story:

“Phone calls from across the country started coming in to the newspaper and city offices, and e-mails from Switzerland, Australia, Wales and England were received. Many of the web sites discussing the exchange are in foreign languages.” I hate to break it to you, but Australia, Wales, and England all speak English.

(Ok, so they did switch from talking about email to web, but it still sounds funny.)

“In their search to find out more, web surfers discovered that the Tuttle Times online forums were hacked, and theorized that it was in retribution for the e-mails. Those forums, however, were corrupted several months ago, and the newspaper’s now former web hosts did not repair it after numerous requests. New forums should be available at the Times site in the coming weeks.” I’m so glad to know that your forums were merely corrupted for months and not hacked. Sounds like the IT problems in this town extend well past the city building.

Taylor said: “[CentOS is] a free operating system that this guy gives away, which tells you how much time he’s got on his hands.” Grumble.

Quoting Tuttle Mayor Paxton (trying to say what was more important than this): We have issues with sewer. People here want better park facilities. They want a library. I think this has just validated every stereotype people have about Oklahoma.

Tuttle is more than 7 times larger than my hometown in Kansas, and yet my hometown has had a library for years.

Jerry Taylor also reported having 500 e-mails and numerous phone messages when he arrived to work Monday.

There’s a new blurb on the Wikipedia page about Tuttle about all this. And in their talk page about the now-deleted article on Jerry Taylor, one person wrote: “Mr. Taylor’s actions have coined a new term of art “Tuttled”, in reference to the invocation of criminal consequences by one who is ignorant of the true situation. Since this is now a part of the English vernacular the story behind the term should be explained to give it an historical context. It is no longer about the action of a single person and an attempt to publicly vilify him, it is about a world-wide common experience of dealing with a Kafka-esque minor government official who, through ignorance, creates problems far beyond their normal sphere of influence. The page should be returned to the public.”

The Register has two new stories about it. The first reports that Taylor has been interviewed by all sorts of media and says that he did the right thing. The second, Linux conquered, Tuttle man takes on London is a story about the grandson of the namesake of Tuttle, OK — who happens to be the current US ambassador to the UK. This person is refusing to pay the regular London car fees. The mayor of London said: “It would actually be quite nice if the American ambassador in Britain could pay the charge like everybody else and not skive out of it like some chiseling little crook.”

And finally, there’s some incredibly funny photoshop work on this one over at fark.com (you have to scroll down a ways). Also, this comment:

“A small-town American politician wants a British newspaper to turn off the Internet.

Say that to yourself a few times. Please.”

Asterisk At Work

It’s been a little while since I wrote about Asterisk. It’s about time to update the story.

I’ve been using Asterisk at home for awhile, but now we’re going to use it at work.

The need

We have approximately 150 internal extensions here, and they are being supported by a Nortel PBX. This PBX is being end-of-lifed, and it would cost well over $100,000 to replace it, once the cost of the two required Windows servers (!) was factored in. Not only that, but it still isn’t as flexible as Asterisk.

Along with that, we have a need for internal wireless phones. We have a large manufacturing area, and we have people that would like to be able to use a wireless phone anywhere on the shop floor or office areas. No single cellphone company provides a signal that is strong enough to reach everywhere in the building — not to mention that there would be big airtime fees. So we are planning to deploy 802.11b wireless phones for this purpose.

Hardware

The decision was made to go ahead with Asterisk. We will be replacing all office phones with Polycom IP501 units. This means running about 90 new runs of CAT5 to people’s desks.

For our Asterisk server, we got a HP DL385 2U server with dual dual-core Opteron 2GHz CPUs. We’ve really had good luck with Linux on these DL385s, and with HP’s support. We got redundant power supplies, disks, fans, etc. on that machine. The CPU on here is probably more than we need, but telephones are very important to us and we wanted to make sure that we don’t have any issues down the road.

We purchased two A104d quad-T1 interface cards with hardware echo cancellation. Very nice cards. The drivers have been a little troublesome. But Sangoma’s tech support is awesome. They logged onto our box and I was watching as they were hacking on the kernel module right there. Tech support like that is rare. I highly recommend Sangoma.

We really need only one of those cards, but they’re the only component of the Asterisk server that isn’t completely standard. So the second is on hand as a spare.

For our analog phones, we are using two Adtran TA 750 channel banks. Each has a T1 interface and a 50-pin telco (“Amphenol”) connector for a punch block. So we can run 24 channels off each of those. Our consultants (see below) suggested getting them used from Colspar Communications. We found them fully loaded with FXS cards for $250 each. We bought three — two for production use and one for a hot spare.

These are very solid and nice units. The only problem we had is that the voicemail indicator lamps (MWI lights) on our old analog phones wouldn’t light up. Turns out that Asterisk with a T1 channel bank uses digital FSK lamp, whereas our older analog phones expected a certain line voltage to indicate messages waiting. After some Googling, I found add-on FSK lamps from American Science & Surplus for $1.50 each. Nice.

In our other building, we have a gigabit fiber-optic link, so we purchased an AudioCodes MP124 SIP-analog gateway. It’s working well so far, except it’s not working with voicemail indicator lamps at all. It seems to be a firmware issue that is incompatible with Asterisk in some way. We’re investigating now.

For wireless phones, we’re using the Hitachi IP5000. We’re not terribly pleased with the quality of wifi phones in general, but this one seems pretty solid. And it doesn’t crash every few minutes like the Zyxel model we tried.

The Telco

Our current phone system has about 23 analog lines for interaction with the outside world. We wanted to get a voice T1 with PRI channel for the Asterisk system.

Our local telephone company is Sprint, and this has been the annoying part. First they tried to quote us an Internet connection. Then it took a very long time for them to even get us a quote for the voice T1. And now we have signed the contracts but are still waiting for an install date.

Consultants

While I had used Asterisk before, it was in a home setting. Not exactly business-critical, and not dealing with hundreds of extensions, T1 lines, and all the rest. So it seemed reasonable to get someone experienced with that sort of thing to help us out and make sure we weren’t making mistakes that would cost us down the road.

I posted on the asterisk-biz mailing list describing what we would like to do. I got a bunch of supplies from consultants, and we wound up selecting Asteria Solutions Group. At the beginning, we wanted some advice about server sizing, phones that work well in business settings, etc.

I think that most consultants are not used to working with people that have significant Linux experience, and a good deal of Asterisk experience, already. Asteria was a little surprised with our situation at first, I think, but has been very helpful. They’ve educated us on the ins and outs of T1 technology, pointed us to Colspar (which saved us a ton of money on analog gateways), and helped us with some obscure questions. They were also fine to have a much smaller involvement with our project than they would probably normally have. I highly recommend them.

Surprises

You’ll never believe just how hard it is to buy phones from Polycom. They won’t sell directly to people, nor will they even list authorized retailers on their website. You have to call them, leave a message, and in a few days they’ll let you know where to go.

Some online retailers such as atacomm sell Polycom phones, but they’re not authorized to do so, so you don’t get any warranty or have the right to get firmware from Polycom.

What’s more, Polycom usually expects people to need configuration assistance with their phones. But I think that when I told them we need 90 IP-501s, had already configured 5 on our network, and needed no assistance, they were happy to work with us.

Reactions

We’ve deployed desk phones all over by now. So office workers have two phones on their desk right now (one from the old system, one from the new). We’ve heard a lot of positive comments from people about the new phones. And all the features of Asterisk — music on hold, flexible queues, etc — will be really helpful here.

Cost

Even with the cost of all new phones, new CAT5 runs and labor for that, consulting time, etc., we still expect Asterisk to be far cheaper than the latest Nortel PBX.

Also…

I recently wrote an article about Asterisk for Free Software Magazine. I’ll let you know when/if it gets published.

Energy policy? What energy policy?

So am I the only one that thinks that our (American) energy policy is absolutely, completely insane?

We all know we have some problems:

  • Environmental damange and global warming
  • Rising oil costs and dwindling oil supply
  • Dependence on foreign energy sources

So, what did our great stewards of democracy in Washington decide to do?

Well, first they approved massive subsidies for oil companies. Next, they decided to spend money researching underwater oil drilling. They put all their effort into getting a little bit of oil out of Alaska. And they sign some sort of treaty that really commits nobody to anything with India, China, Australia, and some other people.

So, I want to go up there and ask them:

You are doing all of this WHY???

The world is going to be moving away from oil, and the sooner we join it, the better.

Otherwise, instead of depending on Saudi oil, we will depend on Japanese hybrids and Chinese solar panels, because nobody here cared to spend money to research non-oil products.

Adventures in Networking

So I’ve had this notion recently of running Ethernet from our basement utility room to several rooms throughout the house. This would let us use VOIP phones at several locations, among other things. My Grand Plan was to use the existing phone cabling as a rope. Tie one end to the shiny new CAT5e cabling, then go pull on the other one.

But it hit a big snag. Several, actually. Apparantly, the phone cables are stapled to the house’s support structure — INSIDE THE WALLS! I would have a punch multiple holes in the drywall to make this scheme work.

So plans must be re-hatched.

The shortest run is to the office, which is adjacent to the utility room. I’ve just been running Ethernet cables under the door for some time, and I’d like to put in proper jacks. The wall that the jacks should go on has — yes, a phone cord in it, and yes, it’s stapled. But to discover that, I had to enter the crawlspace above the basement ceiling and below the main floor — a space about 1.5 feet high and not much more wide, and infested with all sorts of sharp pointy things (mostly nails), pipes, wires, etc. I only had to crawl about 10 feet but it took quite a while.

So, what to do? My dad suggested using a weighted chain, dropping it down the hole, then fashioning a hook to catch it from the existing electrical box. (Which, BTW, can’t be removed because it ALSO is fastened to the supports in a manner that requires access to the wall interior) I that that could work, and might also try adding a magnet to the mix. But it will require another visit to the crawlspace, and I’m just not quite up for that kind of fun yet.

So I started work on problem : an ethernet run from the basement to the bedroom, which is a second-story location. I figure the total length of this run is still about 20 feet or so, not bad at all. But, not only are stapes involved, but this one is an outside wall. That means no crawlspace access, but also insulation to deal with. The main reason for this cable run is to enable the use of a VOIP phone.

I pondered the situation for a few days, then started checking out Ethernet cabling specs. It turns out that a 10Mb link requires only 4 conductors (2 pair). The not-quite-cat3 “mystery cable” (appears to be unshielded, untwisted) has 6 conductors. Phone associates at 10Mb anyway. Could it work???

YES! With some punch-down ends from cat5ecableguy, I’ve got it working. I still can’t quite believe it, but it works.

Here are some links I found useful: