Tuesday, February 8, 2011

The Social Network: (In)accuracies regarding the Computer Science

Typically, movies that have any relevance with computing or technology tend to irritate me, regarding technological accuracy as well as the overall atmosphere and attitude of characters. One may think that movies involving technology would be my passion, but I've spent so much time with actual technical people that I always find their portrayal in film a bit off.

I recently got a chance to watch 'The Social Network', and I found that overall it was a great film. I expected this much, as it had a great cast, an excellent director (Fincher), and a score produced by Trent Reznor, of all people. I had been apprehensive about seeing it because I knew there would find fault with the way it represented technology in some way. I also felt that Facebook was still too young to warrant its accolades in film, and that this was a cheap way to cash in on its popularity. A movie about a web site that I barely care about didn't seem to have it's appeal to me.

I wound up loving the atmosphere it created, and I mostly liked the portrayal of the characters and the programmer mindset. In many ways I was taken back to my recent CS education, I saw many parallels between Mark's character and my own as a student. The time spent in labs, the endless barrage of projects.

However my initial hesitations remained correct, there were things that did bother me. Much attention has been paid to how the movie has it's inaccuracies in terms of the people and company being portrayed, and I don't want to rehash that. (Though, for all the talk about this movie NOT being a documentary, I was surprised when Mark Zuckerburg's character was actually called 'Mark Zuckerburg'. Similarly, the company was actually Facebook, etc. I incorrectly assumed that the names had all been changed to protect the innocent.) The things that get to me are technical. They're mostly pedantic in nature, and I understand that. Still, in much the way a medical professional cringes when they may watch anything involving medicine, or the way how the screen portrayal of crime & justice is at best a parody of reality, as a programmer it's hard not to focus on what is off in a movie like this instead of just enjoying it.

There was a lot that I did feel they got right, though. I think in a sense they managed to capture the feel of a tech start-up, to the best of my knowledge. That shift between a personal project into a commercial endeavor. They used a (modified) version of Mark's real LiveJournal posting of that day to describe his little Facemash activity. The content of the message felt authentic (because it was), but the delivery perhaps not so. I've never heard anyone talk like that, but I've seen people write like that. Hard to describe to a non-programmer, but the dramatic inflections were just.. off. Overall I liked that it showed how the youngest billionaire started out with that hacker ethic, but they perhaps got his motivation wrong. As Mark Zuckerburg has pointed out, it's hard for people who are not programmers to understand the desire to build something for the sake of creating it, and Hollywood went out of the way to imply that his creations were for the sake of women and money. Never mind that the real Facemash featured both men and women, but I digress.

I paused the screen to see the software that Mark was using, and we got nice KDE desktops on a presumably Linux-based system. Appropriate versions for the era, too. No one set background images, though, odd. Mark does mention that he was using Mozilla as a browser, while we see the default KDE's Konquerer on his screen. Producers probably too lazy to find the appropriate antiquated version and have it installed. Plus this flashes by the screen for only a few frames.

Mark uses Emacs (yay!) and we see that throughout. We see a bash session where it looks like he installs a 'php-elisp' package (appropriate) and tries to run Emacs twice. I can't recall the errors but I think they were just console warning messages that would display on run. Now, he does say he's writing Perl, but we can assume he was well versed in such, and only installed Emac's PHP package as part of his struggle to understand one of the dorm's face-book's that he complains about.

Most technical things in the film were correct, but again I mention that the delivery of these technical subjects just felt odd to me. "Give me the algorithm!!" isn't really something that I've heard myself, although yes, algorithms are an integral part of Computer Science and it's neat that we saw some emphasis. Mark probably would have just looked it up in his text, or asked a friend politely. The Hollywood way to do it was to write it on a dorm window in wax pencil, it reminded me of the over-the-top depictions of NORAD in film, where everything is written on upright sheets of glowing glass.

There was the scene where mark asks for an additional LAMP server, which in reality I don't think he would have enumerated the acronym in the way he did. The line there seemed like a forced attempt at authenticity, but the dramatic reading of "Linux, Apache, MySQL" was off.

Those "He's plugged in!" lines were ridiculous too. It's not the Matrix, I've never heard of software engineers at a system being referred to as being "plugged in". Although it's true - don't interrupt someone when they're writing code - they're on a roll.

I realize I'm being pedantic here, and so I don't really fault the movie for it. They have to make the topic exciting, after all. I just find it personally distracting to see my field portrayed the way it is, and that is why I have a hard time watching movies like this. The Net, Antitrust, Swordfish, it's always a similar story for me. The Social Network is the best so far, but they were still off.

The scene that went over the top was the Hacking competition scene. Now, I've been involved in ACM programming competitions, and I've seen a few hacking competitions. I don't know how they do things at Harvard but that was ridiculous. Real hacking competitions are lengthy, and while they may involve a few beers they are not drinking games. The audiences are also a few notches toned down, or nonexistent. It makes for a poor spectator sport. Milestone results are generally posted onto some bulletin, where people can check in periodically. Programming is an intense intellectual discipline, and few people have the tolerance to maintain enough composure after two shots to get any real work done. Let alone 8 shots. The programming competitions I've been involved in had zero spectators, lasted a few hours, and almost no one spoke. You would have thought this scene was a wrestling match.

The scene that really got to me was the OS lecture scene. The professor asks the course a question, to which no one can reply. Mark leaves the course, is insulted for doing so, and then casually gives the correct response. This is a trope I've seen a number of times before, we get to see a nice contrast between Mark's intellect and his attitude. Of course, when I hear a question being asked in this film, my mind will scramble to come up to an answer. When I could not follow the discussion, this was frustrating. I rewound that scene three times, trying to understand what the actual question being asked was, and how the answer relates. Confused, I turned to the internet to find any technical discussion on this scene and turned up in failure. I did not find any (hence the inspiration for this blog post), but I did find the original film's script for the scene. Continued searching revealed the actual Harvard CS161 lecture notes to a 2007 course. Let's compare:

MARK is in his Operating Systems class. This is considered the
hardest class at Harvard and MARK is one of the 50 students
with their laptops open as the professor takes them through an
impossibly difficult lesson.
Okay, let’s look at a sample problem:
Suppose we’re given a computer with a 16-
bit virtual address and a page size of
256 bytes.
A GIRL scribbles something on a piece of paper. Then hands it
to the student next to her and nods that it should be passed
over to MARK. While that’s happening--
The system uses one-level page tables,
that start at address 0x0400. Maybe you
want to have DMA on your 16-bit system,
who knows? The first few pages are
reserved for hardware flags, etc.
MARK opens the note. It reads “U dick”.
He looks over and sees a couple of GIRLS looking at him with
Assume page table entries have eight
status bits.
MARK closes his laptop, gets up and starts to head out of the
The eight status bits would be--
(re: MARK)
And I see we have our first surrender.
Don’t worry, Mr. Zuckerberg, brighter men
than you have tried and failed at this
(calling back)
1 valid bit, 1 modify bit, 1 reference
bit and 5 permission bits.
That is correct. Does everybody see how
he got there?

Lecture Notes:
Computer Science 161: Operating Systems
Processes, Scheduling, VM, Writing a Design Doc
CS161 Course Staff
March 8, 2007
3 VM
VM is one of the most useful things you learn in this course, since probably for the first time you no longer need to be surprised by the “magic” the operating system provides. It’s also one of Matt’s favorite topics, and so will appear on the midterm. This wouldn’t necessarily be a great reason to really learn it, but you also have to implement it so understanding what’s happening sooner rather then later will save us all a lot of trouble.
Key terms: page table, MMU, TLB, TLB miss, page fault, page frame,
internal fragmentation, external fragmentation
A sample problem: Suppose we are given a computer with a 16-bit virtual
addresses, and a page size of 256 bytes. The system uses one-level page tables, which start at address 0x0400. (The first few pages are reserved for hardware flags, etc. Maybe you wanted to have DMA on your 16-bit system, who knows?) Assume page table entries have eight status bits: 1 valid bit, 1 modify bit, 1 reference bit, and 5 permissions bits (this is a very secure system).

*How many pages are there? How much memory do the page tables require?

One of these is clearly derived from the other, obviously the former was lifted strait off of the latter. In a way this is cool, to have dialog in a movie taken from the actual course it's supposed to represent, but the delivery was botched. I mostly liked what the scene was supposed to be, there was a slide with an MMU on it, and what appeared to be the mapping of virtual memory pages to real memory. This would have been a very relevant slide for the topic under discussion (Virtual Memory). Now, having seen the original source to the dialog in this scene, the question makes sense. Or rather, it makes sense to me why the question makes no sense at all.

In the lecture notes, the professor is describing a hypothetical system, while providing additional irrelevant commentary in describing it. (Everything in parenthesis.) In the film, the entire question is delivered with an inquisitive tone, including the bits that are not inquisitive. Then the killer is that the actual question about paging is never asked in the film, but rather the professor asks about the assumptions in the page table entry. The problem is that the fact that this hypothetical system used one valid, one modify, one reference, and five permission bits is made up, just as a demonstration. There is no way to infer this knowledge from the question being asked. Unless the students had read the mind of the professor, or had notes printed out, no one could know.

Mark is not giving an answer to a question, and the professor hasn't even asked one. Mark isn't even giving critical details to the question, but rather just the embellishment part of the question. The actual question that would have been asked, is never asked in the film. ("How many pages are there? How much memory do the page tables require?") This is the question I was anticipating, recalling the sorts of problems faced in my own system arch and OS courses regarding paging.

I may as well go ahead and answer it. To the best of my knowledge, this means that we have a system capable of addressing 65536 bytes (2^16) of memory. Divided into 256 byte chunks, that means we have 256 pages on the system. (8 + 8 bits, in other words) Since each of these 256 pages requires a one byte page table entry (As mentioned, the 1/1/1/5 being irrelevant), that means our page table is an even 256 bytes, fitting nicely into the first page (of the four reserved for system, 0x0400 being the first 1K of memory). The breakdown of the 8 bytes is inconsequential for our example, it is extraneous information. It is mentioned just as a hypothetical. (More so to keep things at a simple one byte entry.)

So long as I'm not overlooking something, this question is actually pretty tame, I suspect it to be a feeler question used to introduce the topic to students in CS161. Even if I'm missing something in my answer, that's outside of the point that this dialog was seriously botched.

What's truly frustrating about this scene - and why I don't feel that I'm being pedantic in saying so - is that the entire purpose of this scene is to illustrate Mark's brilliance, by having him giving a correct answer to a difficult question. But they got it so wrong, he's uttering nonsense in the context of a non-question. To anyone familiar with the material, no, we *don't* see how he got there. They seem to have worked very hard at creating some level of accuracy, I'm surprised that no one pointed this out. They certainly had some technical reviewers.

It is acceptable and forgivable when a film has technical inaccuracies hidden in the background that are displayed for a single frame, the fact that they happen makes sense. But gaping holes like this just gut this scene. It hurts personally, because it ruins what could have been the first, best, and last scene in a major motion picture that takes place in a computer science OS lecture room. I appreciate it when a movie features characters outside of those that are familiar to Hollywood, (Usually menial service industry tasks and the movie industry itself.) and it's an opportunity for people to peer into the lives of others. I and most other programmers feel that the discipline is not well understood outside of the field ("You like, know how to fix computers and use Photoshop, right??") and here was the shot to get a glimpse of reality. Perhaps some of the character of the lecture was accurate, but the material was insulted in a way, by not checking its accuracy.

Imagine a professor asking a question in a math course,

Professor -- "One train is leaving City A at 100km/hr, towards City B. A second train leaves City B at.. anybody?"

Student -- "160km/hr!"

Professor -- "That is correct. Does everyone see how he got there?"


Lastly, the OS lecture had way too many girls in class. It's a well discussed issue among CS educators that for some reason the field is dominated by men, it is a profession that is 95% male. No one really knows why this is so, and why the related field of mathematics has women outnumbering men in many places. If only my classes had that many women in them. (Not for personal reasons, of course, but for egalitarian reasons.) Discussion online has corroborated this, students that have taken CS161 at Harvard agree, mostly dudes.

Thursday, February 25, 2010

Followup on Super Hybrid Engine (SuperHE) on 1005PE

The solution for enabling SuperHE is trivial, for my purposes at least.

A modern kernel should load the eeepc_laptop kernel module, and this has support for SuperHE out of the box. UNR and other distributions will not enable it however. That's up to you.

The eeepc_laptop module exposes an interface via the sys filesystem.

#echo 2 > /sys/devices/platform/eeepc/cpufv

Will turn it on. (Note it's done as root.)
In order to have this be the case after a resume from suspend or hibernate, you have to add a bash script to the power management tools, located in /etc/pm/sleep.d

All scripts in this directory are called when your system sleeps or hibernates, or wakes up or resumes. It is passed a parameter matching that action. Resuming from sleep is "resume", and waking up from hibernate is "thaw".

case "$1" in
echo 2 > /sys/devices/platform/eeepc/cpufv

I named this "10_superhe" as the other scripts were prefixed with a "10". My guess is it deals with ordering, much like the init system. It shouldn't really matter. Make sure it is executable "chmod a+x 10_superhe" and that should be it!

When my system resumes or thaws, there is an extra half second pause (this would always happen when enabling superhe), and so I could tell it was working. You can verify by "cat cpufv" within the eeepc directory.

Note that this won't run after a traditional boot. You can use rc.local or your .xinitrc for that. Note also that this makes SuperHE on maximum power save all the time. That is how I want it, as if I'm using this thing, I'm on battery. It charges near my desktop. I'm sure this script could hook in to laptop_mode or maybe even cpufreqd if you want superhe only on when on battery. It is possible that this would then only be enabled upon switching to battery, and wouldn't persist past a resume. In that case, you would have to use a more complex system that would track battery state.

Saturday, February 20, 2010

.name, what a shame...

I recently registered a second domain name and considered using a more esoteric tld, and in doing so came across ".name". It's pretty interesting, if you look at the Wikipedia entry. The idea was that every person could have their own domain, free and clear.


Unfortunately, ICANN messed things up and didn't regulate it well, let only certain people get second level domains which only others could register third-level. That kind of fell through and now .name is as open as .info and .com.

Kind of a shame. When you think of it, the entire concept of the domain name industry is a bit odd. All you're doing is paying for the right to use a DNS entry, really. How cool would it be if we could all register our own .name, and have it point to what we want. ISP service comes with email, and it used to come with some news and web space, shouldn't it come with some DNS entries too? The lack of a simple and universal system like this is one of the reasons for why social presence on the internet consists of a multitude of walled gardens. The web itself should have become our social network.

And if .name seems kind of crazy, take a look at ENUM. It's another system that has been proposed to be built on top of DNS, using a record to store a number of phone numbers, both PSTN and VOIP, to a single number. Never built, but things would have been different. As it stands, Google Voice is the closest thing we have to that.

Asus eeepc 1005PE and Ubuntu Netbook Remix 9.10

Six months ago, I decided to go from my Thinkpad S30 and Z60m to a Desktop + Netbook combination. One machine for portability and one for grunt seem to be the best way to do things, but my grunty Z60m was getting old, and my portable S30 was positively ancient.

With the incredible pricing of Netbooks, down in the $300 range, and fast capable Desktops being possible for $400, this seemed like the better option than a $700 laptop. Component pricing has come way down, and I built a lower wattage, near-silent desktop in a nice MicroATX form factor. I thought I was done with desktops, but they have their place.

I chose the 1005HA for my netbooking. There were a number of sub-versions that weren't very well documented. It came in 3, 4, and 6 cell versions, and I opted for the 3 cell. Rated for 4 hours, under my usage 3 hours was more typical. The problem with only 3 hours of battery life is that you generally won't get 3 hours of usage out of it. After 2 hours, you really feel "on the clock", you know you have to get to an outlet before your machine hibernates itself. If that's the case, what's the point of a netbook? I would just seat myself near a power outlet, and cross my fingers that someone wouldn't trip on the cord. You have a nice svelte 2.8lb. machine, and another half pound of charger. I regretted not getting the 6 cell version, but even 6 hours isn't enough. I want to go somewhere and program all day, without worry.

Enter Pine Trail and the 1005PE

This also has many versions, (1005P, PE, PE-P? I forget them all. The PE has an MU17 and PU17 subversion.) and there is also the accompanying 1001P. It seems like only certain versions are available in certain locations, and vary by battery type, bluetooth, chiclet keyboards, and glossy screens. I think some lack wireless N as well.

I upgraded to the 1005PE-PU17, which is the grand-daddy of them all. Only $370 or so with free shipping from newegg, it seemed like the better deal. For some reason it is rated for a 14 hour battery life, while other 6-cell versions are only rated for 11 hours. I don't quite know what differs, but I've learned the importance of time away from an outlet. After migrating my data over, the 1005HA is now going to go on eBay. I estimate that my total upgrade cost will be around $150. Not bad, I could do this every 6 months if I had to. (So long as the upgrade were compelling enough.) Other than the new CPU, battery life, chiclet keyboard, bluetooth, wireless-n, and glossy screen, this thing is nearly identical to the last one. The logo on the back is the more professional ASUS one, instead of the cursive "eeepc" one. I like it. I'm told that this may have support for 3G wireless too. I would remove the battery and look for the SIM holder but I'm on battery life right now. I don't have a need for that, but that could be useful down the line.

Most of the battery life enhancements are due to the new Pine Trail chip. When Intel made the Atom, they focused on the biggest power draw in a system, the CPU. While they managed to reduce the cpu power draw to 2.5W, the chipset and io controller would be an additional 9.3W, for a total draw of 11.8. For Pine Trail, these parts became the new target. Pine Trail CPUs integrate the CPU and "chipset" onto a single die, along with the GPU. The new package has a power draw of only 7W.

My guess is that this is while running at full power as my total system draw is down to 5.0 +/- 0.5 Watts. Fully charged, my system tells me that I have 13 hours remaining, but it quickly drops to 11 hours, and that seems most accurate. The quoted 14 is probably with less wifi, dimmer screen. I used to resort to setting the screen at 30% on my 1005HA, now I happily set it around 70%. Bluetooth is off, but it's nice to have it for when/if I need it.

New Operating System(s)

One other difference I didn't mention is that the button that used to disable the touchpad is now a second power button for the ASUS ExpressGate. The touchpad disable button is now fn-F3. By default there was a roughly 10GB partition at the end of the disk, which I think was a combined restore/quick OS partition. I'm mixed on these secondary operating systems. I like how they are pretty much all Linux based, and provide a new convenience to people. They illustrate the weakness of booting speeds to the normal Windows operating systems. But a second OS is not the answer, I think it's best to simply make the first OS better. A secondary operating system wont share your browser bookmarks and history and cookies, and is just another thing to configure. It uses up its own space. Plus, Windows 7 is supposedly much faster at booting now. You should also be suspending/hibernating. It takes 10 seconds to resume from a hibernate, so why boot into expressgate? As an emergency/restore option that sounds good, but I still think that the answer is to make your first OS good enough to where you should never need to restore.

It came with Windows 7 Starter, which is a horrible excuse for an operating system. Microsoft is practically begging people to install Linux on netbooks with that offering. After a rough start for the early early adopters, (those that tried UNR on the 1005PE within the first week) things work really well now, 3 weeks or so after this laptop has been made available.

On my desktops and servers, I usually use Debian and Arch, they seem to be the best fit for me. But as the number of computers I have scales up, the hassle of maintaining things escalates exponentially. While I love tiling window managers, I don't have the time to spend a day installing arch and awesomewm on this thing. Plus my netbook is very likely to be borrowed by a friend. It's handy to have a guest account that uses Qwerty (Instead of my usual Dvorak.), that will connect to WPA2 networks without editing wpa_supplicant to get online. My netbook is the "public face" of linux for me, and I want to show it in the best light while reducing my own frustration. A more comprehensive distribution like Ubuntu is the best fit for this purpose. But with the tiny screens and resolution, a maximizing window manager and simplified launcher is ideal. I am more impressed with UNR every time I use it. Fewer clicks and less touchpad usage to do what I need. I just wish Firefox came with screen real-estate minimizing plugins and themes by default.

The official UNR compatibility page lists the few small steps you need to take to make your 1005PE run just fine with Linux. You're basically installing the latest kernel modules to fully support wifi without dropping out. I actually had that problem on my 1005HA, I wish I had upgraded then. (It would work for 20 - 60 minutes before cutting out completely. Restarting network manager and reloading the kernel module was necessary to fix it. I would usually just restart.)

Two issues remain

The first is the screen brightness buttons. They work, but irregularly. This problem is known, but no easy fix seems here. I just keep hitting it until I get a brightness I like. It's not that bad. After closing and opening laptop lid, it restores to full brightness, as it does after a suspend. The power options in the settings tab lets it automatically dim the screen due to unuse, but I've unchecked these options. My screen would randomly go to 100% brightness every once in a while, there was no clear pattern to it. Unchecking these options lets the brightness stay where I put it, once I find a brightness I like by playing with buttons.

The next issue is Asus' Super Hybrid Engine. This allows for the frequency scaling of the bus speed and maybe other things. UNR doesn't seem to use it by default. You can install a script for laptop-mode to automatically set these SHE options, it piggybacks on the laptop-mode mechanism. Arch Linux has a good description here, but the basics of it is that the kernel module eeepc_laptop supports SHE, but most userland environments never enable it.

More Power!

To enable it, check that eeepc_laptop is installed with lsmod. Then as root (sudo doesn't seem to work), take a look at /sys/devices/platform/eeepc/. There's a virtual file called "cpufv". Take a look at what it says with "cat cpufv". You should get a hex number, probably "0x301". The three possibilities are "0x300, 0x301, 0x302", or 0, 1, and 2. 0 is performance mode, 1 is... normal portable mode, and 2 is power saving mode. Simply echoing 2 into the virtual file enables it. "echo 2 > cpufv". This pretty much cut a Watt or two off of my power usage. This setting will not save after a suspend, or a reboot. I don't really want to piggyback on laptop_mode, so I'm looking for the best way to hook this in to the power management tools. Other than SuperHE, the usual cpu frequency scaling appears to work. Unplug laptop from wall, it goes into power saving mode. But SuperHE is really important, it gives me another 2 or 3 hours.

One thing that I set up with my 1005HA was a daemon that would disable the touchpad while typing. "Syndaemon" is the tool. This was preferable to manually enabling and disabling the touchpad. As it stands, the fn-F3 button combination do nothing. After all, it just generates an ACPI event that you can bind to whatever you like. For that matter, fn-space, fn-F7, fn-F8, and fn-F9 don't do what they are labeled as. That's fine as their functions are free to do whatever I want them to do. I think in windows they only work after installing Asus software. I'm not to keen on the function key alternates in general. I prefer using the Gnome/Ubuntu shortcut keys anyways for most things.

Speaking of they keyboard, I really am liking the chiclet style. However, the right shift key is no longer full sized. It's now cut into three buttons - shift, uparrow, and a second fn key. The old 1005HA had the up/down buttons half sized. I preferred that as it let me have a real shift key. I may wind up rebinding up arrow to shift as well. That's trivial in Arch/Debian with xmodmap, but I have to find the "right" way to do it in Ubuntu.

Two other things I've done to extend battery life. One is to lower the tx-power for my wireless card. "iwconfig wlan0 tx-power 15". This sets the wireless card to 15db instead of 20db. It appears to have given me an extra hour. I want to play around further with this, and see how low I can set it and have it still work well. I suspect that this is what I need to do to get the full rated 14 hours under Linux.

One additional issue I saw was the SD card reader. If you have an SD card in your reader, your system will consume an additional Watt of power! Whether the card is mounted or not. My guess is that this is hardware-related, not OS. Probably why my 1005HA didn't do so well with power, I always left a handy SD-card in there. Don't do that.

I played around with PowerTop to see if it offered any additional advice. It did, but they didn't seem to extend my battery that much. Plus its a hassle to implement all of its advice in a way that will persist beyond restarts/suspends.


Overall, the 1005PE truly allows for all-day computing. With wifi/bluetooth off, screen fully dim, idling, this thing could probably sit there for 20 hours. That's impressive, if not useful. To get 11 hours of real usage out of a machine is incredible, and it has revolutionized the way I work. I feel as if I just got a laptop for the first time, my last machines were still very much tethered. Now I can go anywhere I want, all day, and I leave my charger at home.

Saturday, September 12, 2009

Setting CPU Fan Speed Linux

I recently assembled a new desktop system. I want it to as reasonably quiet as possible. The motheboard's cpu fan header is 4 pin. What these new four pin headers do is allow for a variable pwm to be applied to them, which varies the cpu fan's speed.

One issue is that the stock fan, while not that loud, was leaving my temps a bit too warm. It is a lower powered AMD 245 "regor", but my case is a SUGO S02 from Silverstone - very cramped. I upgraded to an aftermarket Zalman 7000cu fan. This thing is a giant copper beast, with a bigger fan, but still compact enough to fit in my case. I was hoping I could shave off a few degrees and quiet it up a bit.

The one issue is that this new fan has only a 3 pin header, supposedly no pwm. It came with a manual adjustment knob that can let me vary the voltage by hand, but that meant another thing sticking out of the back of the case, or filling up the insides.

So at first I used a tool called fancontrol. It is installed in Arch Linux by default, but I'm sure its in all the big distribution's repositories. Fancontrol is a bash script that runs as a daemon, monitoring a temp you specify, and at speeds you want. You have to go through some time playing with its configuration tool, "pwmconfig".

To my surprise, it manages to control the fan speed of my 3-pin fan. It worked well, eventually I got things pretty quiet. As my load increases, and thus CPU temperatures, the fan speed does as well. There is one issue with this.

For a given load, the CPU will heat up, along with fan increases, until things stabilize at a certain level of heat/rpm/temperature. If you are lucky, it stabilizes at a particular value. But usually it stabilizes at a cycle. The temp hits 37 degrees, fan 1250rpm for me, and this lets the cpu warm to 38 degrees, where the fan is then kicked up to 1350rpm, cooling the cpu back down to 37. This can be an irritating cycle. At either speed, the fan is relatively quiet, but to hear the speedup and slowdown every 30 seconds is distracting.

So let's just set it manually. Googling for how to do this was not immediately apparent, so I wanted to clarify. Linux detects and has support for hardware monitoring devices, which use the very low level i2c bus. It exports an interface at /sys/class/hwmon. For me, /sys/class/hwmon/hwmon0/device is the usable device interface, which has numerous values within.

"pwm1" is the fan control value that we can play with. It stores a value from 0-255, indicating the voltage driving the fan. A value of 0 means the fan wont spin, a value of 255 means it spins at full speed. However, a value of up to 28 for me has the fan not moving either, so each fan is probably different.

'cat fan1_input' will return the rpm of the first fan, the cpu fan for me.
'cat pwm1' returns the value 0 - 255 that the fan is being told to spin at.
I use lm_sensors to see cpu temp and fan speed, but this data is all controlled by this hwmon device.

To alter the fan speed, first 'echo 1 > pwm1_enable', this will let the 'pwm1' value control it. Then experiment. I have found that 'echo 150 > pwm1' sets the fan high enough to where it cools down to the low 30's, but is not too loud. 'echo 65 > pwm1' is silent, although the cpu temp rises to almost 40C.

The nice thing about this is that I set a single temp/rpm/noise volume, no irritating cycles. Another nice thing about just setting this manually is that my fan has certain regions that have additional vibration. 1250rpm and things get a slight buzz. 1200rpm and even 1300rpm are quieter. I like the finer manual control.

As for now, my rc.local has both "echo 1 > /sys/class/hwmon/hwmon0/device/pwm1_enable" and "echo 65 > /sys/class/hwmon/hwmon0/device/pwm1". I generally have a similar load on the system, and don't do anything that will tax it too much for too long, so I am comfortable with this setup.

I'm still curious as to what the fourth pin on a 4 pin cpu fan was for. Obviously motherboards can modulate the 12v line in the 3 pin, which is the same in the 4. I can only guess that this is a legacy issue. Certain fans may not work well with changing the 12v line, and certain motherboards may lack a hardware monitoring device. But basically, if you see a good cpu fan and it is only 3 pin, you can still have full automated or manual control.

Friday, March 6, 2009

Batch Renaming music files with single digit track numbers, to prepend with a 0, with a Bash script.

So, you have a collection of music... say... 120GB of flac, ripped from CDs.

This collection is important to you, and took you a while to rip. You don't want to do it again.

You chose a filename schema $artistname/$albumname/$trackname - $songname.$fileextension

You like this schema, and its organized well, but one problem. Tracks 1 - 9 for each album have a single digit track number, but tracks 10 and up are two.

Some music players and programs view track 10 and 11 and on before tracks 1 - 9. There has to be a simple way to rename these files to have two digit filenames.

There is. There are programs out there that rename files based on the id3 tag, but lets say you don't want to bother with that, you just want to do a simple batch rename. A one line bash command will do the trick:

for file in [1-9]' '*; do mv "$file" 0"$file"; done

As I am new to bash scripting I wanted to figure out how to do this, and it took a full 15 minutes to figure out how bash escapes characters. It will evaluate shell variables inside double quotes, but not single quotes. The above one line script finds all files that start with a number from 1 through 9, and are immediately followed by a space. Conveniently, my 120GB of flac has a lot of these, and no other non-music files are there.

I saved the above to a script, zero_prepend.sh, chmod u+x zero_prepend.sh, and ./zero_prepend.sh within the directory that needs to be renamed.

I have to do that once on each album though. Let me figure out how to do this recursively on my entire collection.

Monday, December 15, 2008

RAM is cheap.

Upon reading a recent /. article on the collapse of the DRAM market, I was reminded of my first ram upgrade. Since I just accidentally created my Blogger account, and had the window open, why not reflect on it publicly. (I had a gmail account and couldn't find the "post comment" link, so I thought one had to be a Blogger member to comment... you don't.)

Now, we've all heard the stories of our tech lovers of yesteryear that go sort of as follows. "I bought X amount of ram for $HIGH amount of money!". Prices come down, we know that. My 1995 memory upgrade was around $400 for an additional 4MB, 72 pin SIMM for my IBM PS/1 whatever, which had 4MB already. That PC was bought in 1994, so you know.

My father took me to the CompUSA (which closed down just a few months ago) and we showed the guy behind the counter every document and manual that came with our computer - and after flipping through, he saw a random "how to install memory" diagram for which he could determine what kind of RAM we needed. At the time I would have been lost to tell him myself.

That upgrade we made was perhaps middle-of-the-road. Going from the obsolete to "acceptably current" 8MB, but a far cry from a top of the line 16MB machine or so. It didn't just make the system "snappier", but categorically ENABLED the use of software that could not be used before, whatever maybe latest Print Shop Pro or education software we used. Less interesting than how much $400 of memory would go today, is how I don't think you could spend that much if you tried.

So newegg.com tells me that if you are looking for the $$ server memory, that a pair of 4GB DDR2 5300 ECC Fully Buffered modules is $269 for Kingston. 8GB, for a pretty beefy server. I think the top of the line x86 single-system can handle 64GB, but I have not really looked into it. Someone also looks to be selling a $600 option for the same thing, but I think the point is clear. Other than for pretty beefy servers, that sounds like overkill - especially for playing educational titles and the latest Paint Shop Pro. Most desktop users would be hard pressed to find any benefit over 2GB. Empty ram is useless ram, and above 2GB will stay empty for most desktop use. Even top-of-the-line gaming. The pace of progress isn't just accelerating, the rate at which it does so increases itself. (Search for the "Law of accelerating returns.")

The point I take from this is that, when I think to the future, 13 years from now, I may not be laughing about how I paid a whopping $30 for 2GB of DDR2... I could be laughing how I paid for memory at all. Will a "midrange" memory upgrade in 2021 be just $1? Or will it be on-die with some other component in a system? Whereas my $30 memory buy means I can run more programs at the same time (as opposed to completely opening the door to software that could not run at all), will that extra $1 spent on your embedded system of the future open up the same degree of possibility? Will my life-assistant AI do a few more chores for me while I sleep? I do not doubt the increasing ability for us to make use of additional computation power, but I think that there will be a much wider range in system configuration that can have use. And as absurd as it seems in 2008 to picture RAM coming with a chipset or cpu, I guess the same could be said for serial ports, hard drive controllers, and even audio chipsets coming with motherboards a decade ago.