LJ Archive


diff -u: What's New in Kernel Development

Zack Brown

Issue #244, August 2014

One problem with Linux has been its implementation of system calls. As Andy Lutomirski pointed out recently, it's very messy. Even identifying which system calls were implemented for which architectures, he said, was very difficult, as was identifying the mapping between a call's name and its number, and mapping between call argument registers and system call arguments.

Some user programs like strace and glibc needed to know this sort of information, but their way of gathering it together—although well accomplished—was very messy too.

Andy proposed slogging through the kernel code and writing up a text file that would serve as a “master list” of system calls, giving the call name, the corresponding call number, the supported architectures and other information. Among other things, this would allow tools like glibc to eliminate their ugly implementations and use a simple library to get this information out of the kernel.

H. Peter Anvin liked the idea, but said it would take a lot of work to get it right. He mentioned that he'd been advocating something along the same lines for a long time, dating back to his work on klibc.

Various other folks liked Andy's idea as well—particularly anyone involved with user code that currently had to deduce system call organization piecemeal. David Howells remarked that it would be wonderful if strace could rely on Andy's master list as well. And, Michael Kerrisk said the manpages project also would be interested in tracking the progress of the master list.

There's always a special case that would benefit from tweaking the process scheduler just a little bit beyond The Good. Recently, Khalid Aziz from Oracle submitted some code to allow user processes to claim additional timeslices. Typically, the kernel itself controls that sort of resource allocation, because otherwise the system is dependent on the friendliness or well-codedness of user applications.

But, Khalid's database folks had noticed a problem with large numbers of threads vying for the same mutex. If one of those threads had the mutex and was almost ready to give it up, the scheduler might run through the whole queue of other processes, none of which could actually run because they were all waiting for that one mutex. And like a thumb in the eye, the process holding the mutex was all set to give it up, but couldn't, since it had been preempted. Much better, Khalid said, would be to allow the process holding the mutex to delay preemption, long enough to give up that mutex. Then all the other processes could take their turn and do actual work, rather than spend their precious timeslices spinning on an unavailable lock.

Khalid said his code showed a 3–5% speedup relative to the previous case. But, there was still a fair bit of reluctance to accept his code into the kernel.

In particular, H. Peter Anvin pointed out that Khalid's code allowed userspace to transform the kernel's natural preemptive multitasking into a cooperative multitasking model, in which processes all had to agree on who would get timeslices, and when—and some processes could aggressively claim timeslices at the expense of the others.

Davidlohr Bueso pointed out that a voluntary preemption model might work better with the kernel's existing implementation, allowing processes to give up their timeslice to another process voluntarily. There was no danger from hostile processes there.

There were various suggestions for alternatives to Khalid's design, but Khalid always pointed out that his way was fastest. But, Thomas Gleixner said that “It's a horrible idea. What you are creating is a crystal ball-based form of time-bound priority ceiling with the worst userspace interface I've ever seen.”

That was the real problem, apparently. Giving user code the ability to preempt the normal scheduling process meant that neither the kernel nor other userspace processes could predict the behavior of the system, or even properly debug problems.

At one point Thomas said, “What you're trying to do is essentially creating an ABI which we have to support and maintain forever. And that definitely is worth a few serious questions.” He added, “If we allow you to special-case your database workload, then we have no argument why we should not do the same thing for real-time workloads where the SCHED_FAIR housekeeping thread can hold a lock shortly to access some important data in the SCHED_FIFO real-time computation thread. Of course the RT people want to avoid the lock contention as much as you do, just for different reasons.”

Eric W. Biederman also objected to Khalid's code, saying, “You allow any task to extend its timeslice. Which means I will get the question why does why does really_important_job only miss its latency guarantees when running on the same box as sched_preempt_using_job?” And he said, “Your change appears to have extremely difficult to debug non-local effects.”

There seems to be a lot of interest in implementing a feature like what Khalid has proposed, but there also seems to be security concerns, debugability concerns and maintainability concerns that make the whole thing very iffy. But, it's still possible that Khalid could address those concerns and come up with a patch that does what the database people want, without the mess.

Android Candy: Oyster—Netflix for Books!

Shawn Powers

Issue #244, August 2014

For avid readers who can't find the time to visit their local library or struggle to carry giant tomes of awesomeness around with them, eBooks have become a convenient way to consume books. Whether it's on a Kindle, a Nook or in an app on your phone, eBooks are the ultimate in portability. Sometimes, however, it can be difficult to find the book you want in a format you can read. Enter Oyster (www.oysterbooks.com).

Netflix has taken movie streaming to the point where it's more common to stream a movie than it is to rent a DVD. Heck, many of us have abandoned all television entertainment options except Netflix. Oyster is an app designed to do the same for books. For $9.95 a month, you get access to more than a half-million books and enjoy unlimited reading on your Android-powered device.

The app features cross-device (and cross-platform) location sync, off-line reading and a 30-day free trial with unlimited book reading. Like Netflix, Oyster does use DRM on its titles. Because the books aren't ever owned by me, I personally don't have a moral dilemma with DRM in this case, but for some it will be a showstopper. Nevertheless, due to its wide selection, awesome idea and cross-platform availability, Oyster takes this month's Editors' Choice award!

Non-Linux FOSS: a Virtualized Cisco Infrastructure?

Shawn Powers

Issue #244, August 2014

We're all familiar with the idea of virtualized computers. Not only are they a great way to better utilize resources in a server room, but they also allow you to create and destroy servers in the blink of an eye. That's perfect for a lab or training environment. Unfortunately, it's always taken a rack of actual hardware to create a training lab for Cisco hardware. Thanks to GNS3 (Graphical Network Simulator 3), that's no longer the case.

Screenshot provided by www.gns3.net.

GNS3 is an open-source application that creates a virtual infrastructure of Cisco (or other) hardware. Not only can you watch the traffic flow, but you also can connect directly to the virtual devices and configure them like the actual hardware devices they represent. On the surface, it looks like a Visio diagram, but it's a diagram that actually does something!

Whether you're actively trying to learn to use Cisco devices or just want to try out some networking scenarios, GNS3 is an incredible tool for sandboxing network hardware. It does require you to provide the IOS firmware (they can't provide Cisco's operating systems themselves), but that's it. It works under Windows, along with OS X and Linux. If you're interested, download a copy today at www.gns3.net.

Getting Good Vibrations with Linux

Joey Bernard

Issue #244, August 2014

Vibrations and wave motions describe many different physical systems. In fact, most systems that dissipate energy do so through waves of one form or another. In this article, I take a look at gvb (Good ViBrations, www.pietrobattiston.it/gvb), a Linux application you can use to visualize and model wave motion and vibrations.

Installation should be relatively easy. It already should exist in the packaging system of most distributions. For example, on Debian-based systems, you can install it with this:

sudo apt-get install gvb

You will notice that a large number of Python requirements also are installed. This gives you an idea of what you need as requirements if you want to build gvb from source.

Now that you have gvb and its requirements installed, you can start it by running the command gvb. When it starts, you will see a main display window with a pane on the right-hand side with calculation options. In the main window, there will be a starting sine wave form.

Figure 1. When you first start gvb, you will see a sine wave ready to start modeling.

Just to make sure that everything is working, you can click on the start button in the right-hand pane. This starts the calculations used to model the wave motion and shows each time step in the main display window. You should see the evolution of a basic sine wave happening.

Let's use this starting waveform to play with some of the available calculation options. The first option is the speed of the wave. You can change this while the wave is being modeled and animated, so you can see in real time how the wave changes with a different speed.

Below the start button are three available options. The calculation drop-down lets you change the algorithm used to do the calculations. The default is eig, and the other three methods are quad, naif and naif matrix. When you select any of the other three methods, the step size option at the top of the pane becomes active.

You then can change the size of the steps used in calculating the wave motion. You can set the number of frames per second to display. The higher this value is, the smoother your wave animation will be. You probably won't notice any improvement beyond 30 frames per second, simply due to the limits of human vision.

The last option allows you to change what graphics are actually rendered in the display. Wave shows the waveform itself. Temp displays a color map representing the amplitude with different colors. Speed displays the waveform, like Wave, but it also includes a series of bars along the wave indicating the magnitude of the speed at those points along the wave. This display helps students get a feeling for how fast the different parts of the wave are moving.

Before going on, it would be worth spending a few minutes to take a cursory look at the types of calculations gvb can do. The default calculation method is eig. This method actually uses the eig() function found in the linalg part of NumPy. This uses the plane wave expansion method to get an eigenvalue formulation of the problem and solve that.

The naif calculation method is a naive method. It simply takes the current amplitude of the wave at some point and calculates how far it should travel based on a linear application of the current speed at that point.

The naif matrix method just tries to speed up the naif method by treating the wave as a vector rather than point by point. Neither of these two methods should be used for any reason other than to see just how bad they are.

The last method is quad. This method expands on the simplistic speed calculation of the naif method with a more accurate method. In most cases, you simply will want to use the eig method, as it is the most accurate for most situations.

Up until now, I've only been discussing a sinusoidal wave on a string. But really interesting things happen when you can look at other starting waveforms. There are a series of pre-programmed waveforms available for you under the menu entry Disposition→1 dimension: precooked. Here you will find more than a dozen available options.

You also may have noticed that there is also an entry for two-dimensional precooked options. That's right, gvb can model waves on a membrane as well.

Figure 2. You even can model waves on a membrane with gvb.

If you select one of these precooked options, you should notice that the graphics option is changed to 3-D, and the type of drawing is changed from rope to membrane. Clicking the start button will show you how the starting waveform propagates across the given membrane. Under the Disposition menu entry, there also are entries for advanced one- and two-dimensional systems. Selecting one of these will pop up a new window where you can set the various parameters for your own model.

Figure 3. The advanced window allows you to create your own customized waveforms.

You still are limited to sinusoidal, triangular, square and peak waves as your base forms. If you have something even more complicated in mind, you actually can define the amplitude and speed at each point in a text file. For example, to model a string, the text file will have three lines. The first line will contain the shape—in this case, the number of points along the string. The second line will contain a series of amplitude values, comma-separated, one for each point. The third line will contain a series of speed values, comma-separated, one for each point. You next need to end the file with a new-line character at the end. Then, you can read this into gvb to provide your starting waveform. This gives you maximum flexibility. You can do the equivalent two-dimensional input file if you want to model a membrane rather than a string.

One final thing you may want to do with gvb is generate a movie of the wave you are modeling. Selecting the menu entry Options→Save frames as png will pull up a file selection window. You need to choose a directory to store all of the image files for each frame of the animation. Once this is done and you click the start button, a PNG file will be written out for each frame. In order to generate a movie out of those, you need to have FFmpeg installed on your system. Then, all you have to do is change directory to the spot where gvb is writing out these image files and run the command:

ffmpeg -i *.png video.mp4

Now you have a video file that you can share displaying the wave evolution that you are modeling.

As you have seen, gvb can be a very fun application to use. It especially gives students a more intuitive feel for how waves behave, in both one and two dimensions. The ability to visualize the speeds for various sections also helps conceptualize the physics involved. Hopefully, the teachers out there will keep gvb in mind when they are planning their next science class to help students understand wave mechanics.

IndieBox: for Gamers Who Miss Boxes!

Shawn Powers

Issue #244, August 2014

There are lots of cool ideas on the Internet that never really make it out of the “startup” phase. IndieBox has been around only for a few months, but I really, really hope it catches on.

Here's the idea:

  • Every month, you get a Linux/Mac/Windows-compatible Indie game in the mail.

  • The games come on a really cool USB drive shaped like a credit card covered in awesome game art. It's like a modern-day Nintendo cartridge.

  • Inside the game box (which is also covered in game art), you'll find posters, keychains, cardboard cutouts, CDs of game music or anything else the folks at IndieBox can scrape together to make the monthly game awesome and nostalgic.

  • Most months you'll also get a Steam code, because although old-school boxed games are awesome, Steam still is really convenient.

Photo courtesy of www.theindiebox.com.

As someone who belongs to a “coffee of the month” club, I can assure you that getting a fresh new thing every month in the mail is fun and exciting. When that new thing is a nostalgic trip to my youth, plus a really fun cross-platform game? For me, it's worth the $16.99 a month. If you miss the days of buying games in a box from the department store, you'll love the IndieBox experience. Check it out at www.theindiebox.com.

Roll Your Own YouTube/Flickr with MediaGoblin

Shawn Powers

Issue #244, August 2014

Everyone has wasted an afternoon on YouTube clicking through videos of talking cats, screaming goats and bad-lip-reading renditions of popular movies. Heck, there are plenty of YouTube videos of me doing odd and silly things as well. (Does anyone remember 'Buntu Family Theater?) For important family videos, however, I much prefer to control my own data. I've tried over the years to keep an archive of home movies and such in a folder on a server somewhere, but they never get seen because getting to them in inconvenient. That's where MediaGoblin comes in.

MediaGoblin is an open-source Web-based application that allows you to host audio, video and photographic media on your own server. It still allows that media to be easily viewed via the Web, however, so you get the convenience of YouTube with the security of hosting files yourself.

Hosting your own local version of YouTube might not be your cup of tea, but for me, it's a great compromise between convenience and data privacy. If you want to give MediaGoblin a try, head over to www.mediagoblin.org and download a copy today. Or, check out one of the many publicly hosted installations to see if you like the interface. The screenshot here is from roaming-initiative.com/mediagoblin/u/jeeelo/m/hackers and includes an interview that hits home for nerds like us!

They Said It

It is not always the same thing to be a good man and a good citizen.


Life is a reciprocal exchange. To move forward, you have to give back.

—Oprah Winfrey

It is only possible to live happily ever after on a day-to-day basis.

—Margaret Bonnano

The greater man the greater courtesy.

—Alfred Lord Tennyson

That is not what Geek means to me. We are more than the hobbies that we do or the things that we like. To me, Geek means an outsider, a rebel, a dreamer, a creator, a fighter. It's a person who dares to love something that isn't conventional.

—Felicia Day

LJ Archive