LJ Archive

UpFront

diff -u: What's New in Kernel Development

Zack Brown

Issue #183, July 2009

Geert Uytterhoeven has replaced the old, dead CVS repository for the m68k Linux port with a shiny new git repository, and added a make install build target, as well as various other code fixes.

Steven Rostedt has updated ftrace to let users turn kernel tracepoints on and off simply by setting values in files in the /debug directory.

Jaswinder Singh Rajput has added some performance-counting features to AMD K7 and later processors. A range of data can be tracked, including processor cycles, number of executed instructions, page faults and context switches. The patches seem likely to go into the kernel soon. Ingo Molnar has given his endorsement and offered some bug reports to which Jaswinder responded quickly.

Matthew Wilcox has done a major rewrite of the MSI HOWTO. The Message Signaled Interrupts (MSI) HOWTO had not been updated significantly since 2004. It provides a mechanism for triggering interrupts on PCI devices, entirely in software. Previously, PCI devices needed to have a physical pin corresponding to the desired interrupt. MSI is much more flexible, and proper documentation will be quite useful. Grant Gundler and Michael Ellerman offered their own technical feedback to the HOWTO, and Randy Dunlap and Sitsofe Wheeler helped polish up the language.

Cheng Renquan has enhanced the KBuild system, so that when viewing help for any given compilation option, the currently selected build choice is visible at the same time. He also made various less user-visible changes, and Randy Dunlap has signed off.

Alex Chiang has submitted a bunch of PCI patches, including code to create /sys/bus/pci/rescan, a user-controlled file that can force a rescan of all PCI buses on the system. He added several other files to the /sys/ directory to give greater and greater PCI control to the user.

It's nice to remove features that no one uses. For one thing, it can simplify kernel code greatly. H. Peter Anvin wanted to remove the zImage build target recently and asked if anyone was still using it. As it turns out, Woody Suwalkski noted that ARM still used zImage. H. Peter probably will remove it from the x86 tree and leave ARM alone.

Bartlomiej Zolnierkiewicz has expunged the IDE floppy and tape drivers from the kernel and the MAINTAINERS file and listed them in the CREDITS file instead. He thanked Gadi Oxman and Paul Bristow for all the work they did in the early days on those drivers.

Michael Kerrisk has removed his name as the official maintainer of the kernel man pages. The Linux Foundation funding has run out, and a supplemental round of Google funding also has run out, so now he'll have to focus on other things. He still plans to support the project as best he can, but he cautions that the man pages likely will be orphaned soon, if no further funding or willing maintainer steps forward.

bc—When Integers Aren't Enough

Joey Bernard

Issue #183, July 2009

Most people have the need to do some kind of math when they are using a computer. In shell scripts, you can make integer calculations by using functionality in the shell itself. But what if that's not enough? Luckily, the POSIX standard includes a very useful command-line utility called bc. With this, you can do arbitrary precision arithmetic. Actually, it is a complete, C-like language that can do some pretty sophisticated programming, supporting variables and functions.

In bc, numbers are all represented internally as a decimal number. They have a length, which is the total number of digits, and a scale, which is the number of decimal spaces. You can find these values by using the built-in functions length() and scale(). For example, the number 10.23 would have a length of 4 and a scale of 2. The variable scale holds the number of decimal places to keep when internal functions are executed. The default value is 0. bc supports all number bases from 2–16, with base-10 being the default. The input and output base of numbers can be set by using the variables ibase and obase. All of the basic mathematical operations are supported in bc. You can multiply, divide, add, subtract, do mod and exponentiation. There are all of the standard comparison operations too. Less than, less than or equal to, greater than, greater than or equal to, equal to and not equal to all give results of 0 for false and 1 for true. This is very useful in the conditional statements available in bc.

bc can be used in shell scripts or on the command line as a very effective calculator. It will read from a list of files given on the command line or read from standard input. On the command line, expressions simply can be echoed through a pipe to bc:

echo "1+1" | bc

The above will give the answer of 2. As a more complex example, the sine of 5 can be assigned to a shell variable with the following:

RESULT=`echo s(5) | bc -l`

The -l command-line option tells bc to load the math library, giving access to the trigonometric functions.

As a bit of a contrived example, say there are two values and you need to find out which one has a larger sine. With the math library and the built-in comparison operations, you can do this with the following:


echo "s(5) < s(10)" | bc -l

The result 1 is printed out on standard output, verifying that the sine of 5 is less than the sine of 10. bc can print out a text string telling the user whether the result is true or false with the following:


echo 'if (s(5) < s(10)) print "true\n" else print "false\n"' | bc -l

This prints out the word true. If this string is to be stored in a variable, the newline characters would be removed from the executable line. This value then can be used later in a shell script by saving it to a shell variable.

What if you have a data file of input values and you want to apply some function to them? Say you need to calculate the logarithm base-10 of each value and dump it into another file. The following example takes a list of the first ten numbers, calculates the logarithm base-10 of each number and writes the value into the file output.lst:

LIST="0 1 2 3 4 5 6 7 8 9"
for INPUT in $LIST
do
echo "l($INPUT)/l(10)" | bc -l >>output.lst
done

These examples already have done some useful work, but what if the requirements are more robust? Does this necessitate a move to a heavyweight math program, like Mathematica or Maple? Not necessarily. With bc, you can create and use functions to make more complicated calculations. Even recursive functions can be written, like in this example to calculate a factorial:


define f (x) {
   if (x <= 1) return (1);
   return (f(x-1) * x);
}
print "Factorial:"; factorial = read();
print f(factorial); print "\n";
quit

This can be dumped into a file called fact.bc and run through bc to get the factorial of some number by executing:

bc fact.bc

This script asks the user for a number and then finds the factorial. It can be used without interaction simply by feeding the number in to standard input with a pipe:

echo 10 | bc fact.bc

This prints out the factorial of 10 (3628800) to standard output. But, how fast can such a program be? For a variety of values run on a generic laptop, the following times were measured:

10       0.004s
100      0.004s
1000     0.028s
10000    3.099s

These times were averaged over three runs to account for varying system load. It seems more than fast enough to be useful for a lot of heavy work.

For a more scientific example, the following bc script finds how long it takes for an object to fall from a series of heights:

define t(h) {   
   g = 9.81;
   return (sqrt(2 * h / g));
}

Now there is no excuse for abandoning a shell script simply because it can't handle some mathematical problem. With bc, you can do a lot of really useful work straight from the command line. Go forth and enumerate.

EFI-X: When Dual Boot Isn't Enough

Shawn Powers

Issue #183, July 2009

I recently was contacted by the folks selling the EFI-X. It's a small USB device that allows EFI-booting operating systems to boot on traditional BIOS-based machines. The big selling point for such a device is that it allows native booting of Apple OS X on off-the-shelf PC hardware. I couldn't get any specifics as to why a Linux user would benefit from such hardware, but at the same time, I guess it's useful to know Linux is fully compatible with EFI-booting technology.

So although the $240 it takes to buy an EFI-X module won't really benefit your Linux install very much, if you want to install OS X on your trusty Linux machine, you now can do so. It most likely violates EULA terms with Apple to install on non-Apple hardware, but it doesn't require a hacked and pirated version of OS X to install. I bought an EFI-X, and OS X installed from the retail DVD right next to my Linux install. It takes a separate drive for each operating system, but I now have a triple-booting quad-core computer that cost less than $800. If you don't want to buy Apple hardware, but would like to dual- (or triple-) boot your system, check it out: www.expresshd.com.

Non-Linux FOSS

Mitch Frazier

Issue #183, July 2009

IronPython is an implementation of Python that runs on the .NET framework as well as on Mono. The current version of IronPython is compatible with Python 2.5, and an alpha release of a Python 2.6-compatible version also is available. IronPython is written entirely in C#, and the current version is built on top of the Dynamic Language Runtime (DLR).

IronPython features an interactive console that does full dynamic compilation of Python code to .NET. It provides full access to all .NET libraries while maintaining compatibility with the Python language.

There also is a Visual Studio plugin called IronPython Studio that supports the creation of Python-based GUI applications. In addition to IronPython, there are “Iron” versions of Ruby and Scheme (LISP). If you like Python but crave static typing, check out BOO for .NET/Mono.

IronPython is licensed under the terms of the “Microsoft Public License”, which was approved by the Open Source Initiative (OSI) in October 2007. The license allows redistribution of compiled code for either commercial or noncommercial use (similar to a BSD license). For this reason, although it is recognized as a “free” software license by the Free Software Foundation, it is considered incompatible with the GPL. And, if getting too close to Microsoft makes you nervous, be aware that the IronPython Project is hosted on a Microsoft-controlled site: codeplex.com.

IronPython Studio (from ironpythonstudio.codeplex.com

LJ Index, July 2009

1. Percent of US homes that don't have Internet access: 29

2. Percent of US homes that think the Internet is useless: 12.7

3. Highest average number of spams per user in a single day in 2008 (April 23) at Google: 194

4. Approximate number of spams per second that can be attributed to the McColo ISP (recently shut down): 33

5. Approximate number of spammers responsible for 80% of Internet spam: 200

6. Rank of US in list of “10 Worst Spam Origin Countries”: 1

7. Rank of China in list of “10 Worst Spam Origin Countries”: 2

8. Rank of Russian Federation in list of “10 Worst Spam Origin Countries”: 3

9. Rank of United Kingdom in list of “10 Worst Spam Origin Countries”: 4

10. Rank of South Korea in list of “10 Worst Spam Origin Countries”: 5

11. Approximate cost per megabyte of RAM in 1957: $411,041,792

12. Approximate cost per megabyte of RAM in 2008: $0.021

13. Billions of dollars of legal music downloads in 2008: 3.7

14. Percent increase in legal music downloads from 2007 to 2008: 25

15. Downloaded music sales as a percent of total music sales: 20

16. Percent of total music downloads that were not “legal”: 95

17. Average “step-on-it” factor used during software estimation phase: 2.5

18. Average number of weeks left to complete a software project: 2

19. US National Debt as of 04/05/09, 1:29:32pm CDT: $11,135,460,534,223.90

20. Change in the debt since last month's column: $185,190,792,300

1, 2: Park Associates

3: Google Message Security Data Centers

4: Spamcorp

5–10: Spamhaus

11, 12: www.jcmit.com/memoryprice.htm

13–16: IFPI

17, 18: Common knowledge

19: www.brillig.com/debt_clock

20: Math

Netbooks—Dying or Evolving?

Shawn Powers

Issue #183, July 2009

I'm just as guilty as everyone else that jumped on the Netbook bandwagon when it started with the 7" Eee PC. After a few weeks, the limitations of such tiny notebooks become fairly clear. The Netbook market has evolved to the point that it's almost laughable. What are the latest features of that market? Bigger screens! Ten- to twelve-inch screens are becoming the new rage in the “Netbook” world.

Um, we had 12" screens before. We called them notebooks. I'm not sure if the Netbook fascination is wearing off or if low-power laptops are just going to become the norm. Because “low power” is becoming a misnomer as the CPU speeds creep up on ultra-portables, I think the term Netbook might just die away.

Another option is that something like Android, Moblin or Ubuntu Netbook Remix will standardize the tiny-screen laptop market, and it will become more like a souped-up cell phone as opposed to a stripped-down notebook. One thing seems clear, the days of a 7–9" screen running a customized and minimal Linux distribution are fading away into history. Is the Netbook a dying fad or still an infant going through growing pains? Sadly, I think that depends on how hardware manufacturers choose to push their upcoming models.

I certainly don't have the ability to see the future, but I hope the future of Netbooks doesn't continue along the path of adopting Microsoft Windows. Low-powered hardware just begs to have the Linux kernel running on it. If the interface could be something standard that ran familiar applications, we might have a chance to retake the entire Netbook market. Only time will tell, and only hardware manufacturers can pick the standard.

They Said It

Don't you wish there was a knob on the TV to turn up the intelligence? There's one marked “Brightness”, but it doesn't work.

—Gallagher

Nobody in the game of football should be called a genius. A genius is somebody like Norman Einstein.

—Joe Theismann

Downgrade rights are hugely important for Windows 7. Will Microsoft offer downgrades [from Windows 7] to XP? They've not answered that question yet. But it's really important.

—Michael Silver, Garter analyst

One day soon the Gillette company will announce the development of a razor that, thanks to a computer microchip, can actually travel ahead in time and shave beard hairs that don't even exist yet.

—Dave Barry

Once a new technology rolls over you, if you're not part of the steamroller, you're part of the road.

—Stewart Brand

The Internet today is an open platform where the demand for Web sites and services dictates success. You've got barriers to entry that are low and equal for all comers. And it's because the Internet is a neutral platform that I can put on this podcast and transmit it over the Internet without having to go through some corporate media middleman. I can say what I want without censorship. I don't have to pay a special charge. But the big telephone and cable companies want to change the Internet as we know it. They say they want to create high-speed lanes on the Internet and strike exclusive contractual arrangements with Internet content-providers for access to those high-speed lanes. Those of us who can't pony up the cash for these high-speed connections will be relegated to the slow lanes....We can't have a situation in which the corporate duopoly dictates the future of the Internet and that's why I'm supporting what is called Net Neutrality.

—President Barack Obama

Stop Burning CDs; Burn USB Drives Instead

Shawn Powers

Issue #183, July 2009

It seems that every week there's a new version of some Linux distribution available. I don't know about you, but I have enough burned “last version” CDs to build a very reflective fort in the backyard. I'm also really bad about labeling CDs when I burn them, so I end up burning the same CD over and over. Thankfully, there is help for people like me—Unetbootin.

I did a video tutorial on this a while back, but the gist of Unetbootin is that you create a bootable USB drive instead of burning an installer CD. The application automatically will download the latest CD image, or you can create a bootable USB drive from an already-downloaded ISO file. Unetbootin even works in Windows, so if you're stuck with only a Windows machine, you can create a bootable USB drive to install our favorite operating system.

The great thing is that USB drives are easily rewritable. Most modern systems will boot from them without issue. The only downside is that it's harder to build forts out of USB drives. So, unless you really want to build that highly reflective fort, I'd suggest checking out Unetbootin.

Unetbootin video tutorial: www.linuxjournal.com/video/creating-bootable-usb-install-drives-unetbootin.

Mobile LinuxJournal.com

Katherine Druckman

Issue #183, July 2009

After reading all about mobile Linux this month, I'm guessing you might be in the mood to take your Linux Journal mobile too. If you haven't visited our mobile version at m.linuxjournal.com, you missed the chance to catch all the content you find on LinuxJournal.com formatted to fit your mobile device. Even if you have visited us on your mobile device, you may have missed the link to our mobile videos. Scroll down to the bottom of the screen, and you'll see a link to our videos on YouTube mobile, which provides our videos in 3gp format for your mobile device. Just think, now you can whip out Shawn Powers' tech tips any time and almost anywhere! Happy viewing!

LJ Archive