LJ Archive

UpFront

diff -u: What's New in Kernel Development

Zack Brown

Issue #224, December 2012

Developers can run into trouble if they don't follow security procedures for submitting code. Thierry Reding tried to send the new PWM subsystem to Linus Torvalds, only to be stopped at the gate. The code had been under development for more than a year; it had been in linux-next for a while already, and Linus thought the code itself looked good.

But, Thierry had not participated in a key-signing event to join the kernel developer web of trust. Without that assurance of his identity, Linus wouldn't accept any code from him. On a more technical note, Linus also wanted to see some “Signed-off-by” tags from people who actually used the PWM subsystem.

The PWM (Pulse Width Modulation) subsystem works on rectangular pulse waves of the sort needed to adjust the power signals to computer fans and display backlights. Thierry's work was intended to replace the old clunky API completely, with its various restrictions and problems, with a nice clean interface.

A lot of developers offered their “Signed-off-by” tags to Thierry's work after that, including Arnd Bergmann, who added that the code was an essential piece needed to build ARM kernels for multiple platforms.

Sebastian Andrzej Siewior also met up with Thierry and signed his GPG key, thus indoctrinating Thierry into the web of trust. Linus accepted the code, and kernel development proceeded.

Sometimes it's a good idea to use special-case data values that have a completely different meaning from usual, and sometimes it's not.

Jean Delvare wanted to address a problem with device ID numbers. Sometimes, a single device type could have multiple instances on a given system, where the actual device ID didn't really matter and couldn't be predicted. Only one of the devices would have a meaningful ID at any given time.

Jean's idea was to use negative ID numbers for those devices. Then, the system would be able to know right away that those ID numbers were just throw-aways that could be discarded afterward. But, users would see only an ordinary positive ID number that they could use to mount and unmount the device as usual.

Greg Kroah-Hartman didn't like “overloading” the device IDs in this way. Jean's approach might be more efficient with RAM usage, because it wouldn't be creating a whole new variable to hold the information about which IDs were throw-aways, but it would add complexity and messiness to the kernel.

So, Jean redid his patch, keeping his prized feature of having throw-away device IDs, but using a regular old boolean variable to identify those IDs, instead of encoding it into the sign of the number. Greg accepted the new patch and sent it along to Linus Torvalds for inclusion in the main tree.

Recently, Ben Hutchings announced that he'd decided to maintain the 3.2 kernel as a stable kernel series as a long-term commitment, at least through 2015.

Typically, every kernel that's released by Linus Torvalds has a few follow-up releases from various folks like Greg Kroah-Hartman and others that add stability. But once in a while Greg, or Ben or really anyone who wants to, will pick a kernel and do longer-term maintenance on it.

This time, Ben had decided to support the 3.2 kernel for the rest of the Debian 7.0 life cycle, which he estimated would take him through to the end of 2015. After that, he said, he'd either hand maintainership over to someone else who was interested or just let that kernel drop.

Of course, just because he's maintaining the kernel specifically for Debian, doesn't mean the same kernel won't run great on any other system. The 3.2 kernel probably will come to be quite well-respected throughout the world before it's set aside.

Android Candy: AirDroid

Shawn Powers

Issue #224, December 2012

I love my Samsung Galaxy S2. Unfortunately, like I mentioned last month, it's difficult to access the internal storage. FolderSync was great for managing the internal storage, but there's a lot more to Android than file storage. Enter: AirDroid.

By creating a Web server on your phone or tablet, AirDroid allows you to connect via the browser on your desktop computer. Once connected, AirDroid allows just about every interaction imaginable with your Android device. With AirDroid you can:

  • Send SMS messages from your browser.

  • Install and remove apps.

  • Manage photos, ringtones and music.

  • Control and record the Android screen (rooted devices only).

For managing files, I still say FolderSync is hard to beat. For every other sort of interaction with your Android device, AirDroid is pretty great. Plus, it's completely free! Check it out at www.airdroid.com.

Image from the Google Play Store

Gaming Like It's 1993

Shawn Powers

Issue #224, December 2012

Two things happened in 1993: I attended my first year of college, and I played a lot of Scorched Earth. Oddly enough, the latter seemed to have more of an effect on my later career choices.

If you're nostalgic for the good old days of Shareware software on floppy disks, you really might enjoy the open-source Atomic Tanks, which is a modern-day clone of the old shoot 'em up tank game. Sticking remarkably close to the original, Atomic Tanks looks and plays just like the Scorched Earth of old. There are newer twists on the old classic, even some open-source ones like Scorched3D (www.scorched3d.co.uk) with better graphics and more realistic gameplay. I actually prefer Atomic Tanks' retro look, however, and if you played Scorched Earth from a floppy disk back in the day, you might too. Check it out at atanks.sourceforge.net.

Non-Linux FOSS

Shawn Powers

Issue #224, December 2012

Apple has shipped an X11 application with its OS for as many versions as I can remember. With its latest releases, however, the use of XQuartz really has provided a seamless X Window System experience. If you want to use the latest version of XQuartz, you'll have to get it from the Web site (xquartz.macosforge.org). The one Apple delivers via Software Update isn't as new. Because Apple does include older versions of XQuartz, it's important to know the Software Update process will write over your newer version if you're not careful.

What does XQuartz provide? For me, its native X11 server means tunneling X11 traffic over an SSH connection can be done right inside the OS X terminal app. With older versions of OS X, you had to start X11 separately, then tunnel in with the non-native-looking Xterm. XQuartz make the process seamless!

OS X's Terminal app tunneled into a Linux machine, running gnome-terminal, with XQuartz running in the dock.

Rsync, It's GRRRRaphical!

Shawn Powers

Issue #224, December 2012

Every year for our Readers' Choice survey, the venerable tool rsync gets votes for favorite backup tool. That never surprises us, because every time I need to copy a group of files and folders, rsync is the tool I use by default. It really has everything—local folder support, SSH tunneling support, delta-only synchronization, speed, versatility, and quite frankly, it's just a great program. It has everything—except a GUI.

Don't get me wrong; rsync works great without a GUI. I use it on the command line almost daily. The problem with rsync's amazing power is a rather complex set of arguments. It's possible to learn those flags, but for the neophyte user, they can be overwhelming. That's where Grsync really shines.

Grsync does a great job of turning countless command-line options into a manageable collection of check boxes and text-entry areas. When you add the nifty “sessions” feature that remembers settings along with source and destinations, it turns into the perfect filesystem sync tool. If you've ever felt rsync was powerful but too complex to use on a regular basis, I highly recommend Grsync. For making such a powerful tool accessible to the unwashed masses, Grsync gets this month's Editors' Choice Award. Now go copy some files! See grsync.sourceforge.net.

Scientific Visualization with NCL

Joey Bernard

Issue #224, December 2012

Many of my previous articles have looked at software packages that do scientific calculations and generate scientific results. But, columns of numbers are nearly impossible to make sense of—at least, by regular human beings. So what can you do? The answer is visualization. We do massive amounts of processing visually, and the easiest way for us to review information is through some graphical format. Because of the power of graphical representations, several packages have been written by different groups. In this article, I'm looking at NCL (the NCAR Command Language, www.ncl.ucar.edu). NCAR is the National Center for Atmospheric Research, where the Computational and Information Systems Laboratory develops NCL. NCL is an interpreted language designed specifically for data analysis and visualization. It supports several different file formats used in scientific computations, and it also provides several data analysis functions built-in.

NCL is available as both source code and precompiled binaries. These are hosted at the Earth System Grid Web site (www.earthsystemgrid.org). The first step is to get an account on the Earth System Grid site. Once your registration is complete, you can download either the source code or the binaries for the system that interests you. The binaries are packaged as tarballs, and they have been compiled for both Debian-based and Red Hat-based systems. You can select between 32-bit and 64-bit binaries. Once you have the correct tarball downloaded, you can unpack it in the directory of your choice. The usual place on UNIX systems is /usr/local, but you are free to place it anywhere on your system.

After unpacking, you need to set several environment variables before actually using NCL. The first is the environment variable NCARG_ROOT. You need to set this to the parent directory containing the NCL executables and libraries. For example, if you unpack NCL in /usr/local, you would set NCARG_ROOT=/usr/local. You also need to add the location of the NCL executables to your path. In this example, you would add $NCARG_ROOT/bin or /usr/local/bin to the PATH environment variable. You also need to create a configuration file in your home directory, named .hluresfile. This file will hold configuration options like the default font and the default color table.

Once everything is set up, you quickly can test whether NCL is working correctly by running:

ng4ex gsun01n

This command copies an NCL script file named gsun01n.ncl into your current working directory and runs it through NCL to produce some graphical output.

If you decide to build NCL from source, you need to install a number of extra libraries to handle all the possible input file formats, as well as all the possible output graphics formats. A full set of instructions is available at www.ncl.ucar.edu/Download/build_from_src.shtml.

It is strongly advised that you try to use the prebuilt binaries first, before going through all the work involved in building NCL from scratch.

Now that NCL is installed and ready to use, what can you actually do with it? If you enter the command ncl, you will get a prompt where you can enter commands. Entering the following command tells NCL to start recording the commands you issue in your current NCL session:

record "my_script.ncl"

When you are done, type stop record to tell NCL to stop recording your session. At this point, you will have an NCL script that you can reuse later, if you wish.

Once you have your NCL script, you can run it through NCL with the command:


ncl <my_script.ncl

This is only one way to develop an NCL script. Remember, NCL is a full programming language, and you can write your scripts from scratch, once you know enough of the commands that are available.

The first structure to learn is the format of an NCL script. Scripts all start with the command begin and finish with the command end. Everything else happens between those two statements.

In NCL, four general groups of objects are available. The first group is the workstation objects. These objects represent the graphical devices that act as display devices that the graphical functions use to draw on. These could be an X11 window, an NCAR Computer Graphics Metafile or a PostScript file. This second group is data objects. Data objects store the actual information used in your analysis and graphical presentation. The third group is the view objects, which represent the elements of your graphical representation. These might be things like text objects, tick marks or contour plots, among others. The fourth is the group of “other” objects, which includes everything else, such as overlays or annotations. You can create new objects by using the commands:

objectname = create "object_character_name" 
 ↪class_name parent_object
end create

where you create a new object based off an existing parent object.

So, what does a basic graphical display look like? You can generate something simple with the following example:

begin
x11 = create "x11" xWorkstationClass defaultapp
end create
text = create "text" textItemClass x11
end create
draw(text)
frame(x11)
end

Save these commands into a file named sample1.ncl. To run it, you can execute ncl <sample1.ncl. The first three lines create an X11 object to draw on. The next two lines create a text object. You need the draw command to generate the text object, while the frame command instantiates the graphical display on your screen.

What if you want to import data in order to do some processing? NCL can handle many of the file formats used in scientific computational work. As a simple case, let's say you have some code that simply dumps the result as an ASCII representation of the values of interest. You can load this data with the command:

file_data = asciiread("/full/path/to/file", file_size, "float")

This will read in file_size numbers from the file given and import them as a float type. Once you've done this, you can grab subsets using indices and assign them to variables. For example, you could create a new array with:

array1 = new(64, float)

and then assign the first 64 elements from the file with the command:

array1(0:63) = file_data(0:63)

Graphing is a bit more complex. The first step is to create a data object that will store the values to be graphed. For example, you could use something like this:

field1 = create "field1" coordArraysClass defaultapp
   "caYArray": (Y-data)
   "caXArray": (X-data)
end create

where you would replace X-data and Y-data with the actual data arrays you want to use. Once this is done, you actually can do the graphing with:

xy_plot = create "xy_plot" xyPlotClass wks
   "xyCoordData": field1
end create
draw(xy_plot)
frame(wks)

This creates an xy_plot object, based on the data you imported into NCL. Next you need to run the draw command and then call the frame command to instantiate the plot.

If you simply want to view the graph, you can call frame on an X11 display object. Or, you can save the graph to a file by calling frame with a file object, like a PostScript file.

There are many possible gotchas when writing and running NCL scripts. Many of these will lead to inefficient code, mostly due to the fact that NCL is an interpreted language. The first item to look at is whether you are using loops unnecessarily. Whenever possible, you should try to use built-in functions to do any processing, rather than try to do the processing yourself. As an example, say you wanted to multiply two 100x100 arrays. If you did it yourself, you probably would write some looping code like this:

do i = 0,99
   do j = 0,99
      c(i,j) = a(i,j)*b(i,j)
   end do
end do

In NCL, you equivalently could write:

c = a*b

This is not only shorter, it is also much more efficient. Instead of having to go through each iteration of the loop and ending up incurring the cost of evaluating the statements on each iteration of the loop, the multiplication is evaluated as a single statement by NCL and is handed to the underlying libraries that handle matrix multiplication as a single statement. You also should try to make sure that you pull out as many operations from the loop as possible and apply them a single time after the loop operation is finished. Additionally, sometimes the processing you are trying to do is simply too intensive. In those cases, you can tell NCL to load and use external C- or FORTRAN-compiled objects to handle this processing.

This has been only the barest of introductions to NCL. NCL is a full programming language, with loop structures and conditional statements. You have variables, objects and loads of built-in functions. You can check out all of the possibilities by visiting the NCL and Earth System Grid Web sites. You might be surprised at the analysis that is possible.

They Said It—Misguided Edition

You have zero privacy anyway. Get over it.

—Scott McNealy

As the majority of hobbyists must be aware, most of you steal your software.

—Bill Gates

I'm sorry, Dave, I'm afraid I can't do that.

—HAL, from 2001: A Space Odyssey

It looks like you're writing a letter. Would you like help?

—Clippy, from Microsoft Office 97

The Internet is a series of tubes.

—Senator Ted Stevens

LJ Archive