|
|
Subscribe / Log in / New account

LCA: Catching up with X.org

Did you know...?

LWN.net is a subscriber-supported publication; we rely on subscribers to keep the entire operation going. Please help out by buying a subscription and keeping LWN on the net.

By Jonathan Corbet
January 23, 2009
For years, linux.conf.au has been one of the best places to go to catch up with the state of the X Window System; the 2009 event was no exception. There was a big difference this time around, though. X talks have typically been all about the great changes which are coming in the near future. This time, the X developers had a different story: most of those great changes are done and will soon be heading toward a distribution near you.

[Keith Packard] Keith Packard's talk started with that theme. When he spoke at LCA2008, there were a few missing features in X.org. Small things like composited three-dimensional graphics, monitor hotplugging, shared graphical objects, kernel-based mode setting, and kernel-based two-dimensional drawing. One of the main things holding all of that work back was the lack of a memory manager which could work with the graphics processor (GPU). It was, Keith said, much like programming everything in early Fortran; doing things with memory was painful.

That problem is history; X now has a kernel-based memory management system. It can be used to allocate persistent objects which are shared between the CPU and the GPU. Since graphical objects are persistent, applications no longer need to make backup copies of everything; these objects will not disappear. Objects have globally-visible names, which, among other things, allows them to be shared between applications. They can even be shared between different APIs, with objects being transformed between various types (image, texture, etc.) as needed. It looks, in fact, an awful lot like a filesystem; there may eventually be a virtual filesystem interface to these objects.

This memory manager is, of course, the graphics execution manager, or GEM. It is new code; the developers first started talking about the need to start over with a new memory manager in March, 2008. The first implementation was posted in April, and the code was merged for the 2.6.28 kernel, released in December. In the process, the GEM developers dropped a lot of generality; they essentially abandoned the task of supporting BSD systems, for example ("sorry about that," says Keith). They also limit support to some Intel hardware at this point. After seeing attempts at large, general solutions fail, the GEM developers decided to focus on getting one thing working, and to generalize thereafter. There is work in progress to get GEM working with ATI chipsets, but that project will not be done for a little while yet.

Moving data between caches is very expensive, so caching must be managed with great care. This is a task they had assumed would be hard. "Unfortunately," says Keith, "we were right." GEM is built around the shmfs filesystem code; much of the fundamental object allocation is done there. That part is easy; the biggest hassle turns out to be in the area of cache management. Even on Intel hardware, which is alleged to be fully cache-coherent, there are caching issues which arise when dealing with the GPU. Moving data between caches is very expensive, so caching must be managed with great care. This is a task they had assumed would be hard. "Unfortunately," says Keith, "we were right."

One fundamental design feature of GEM is the use of global names for graphical objects. Unlike previous APIs, GEM does not deal with physical addresses of objects in its API. That allows the kernel to move things around as needed; as a result, every application can work with the assumption that it has access to the full GPU memory aperture. Graphical objects, in turn, are referenced by "batch buffers," which contain sequences of operations for the GPU. The batch buffer is the fundamental scheduling unit used by GEM; by allowing multiple applications to schedule batch buffers for execution, the GEM developers hope to be able to take advantage of the parallelism of the GPU.

GEM replaces the "balkanized" memory management found in earlier APIs. Persistent objects eliminate a number of annoyances, such as the dumping of textures at every task switch. What is also gone is the allocation of the entire memory aperture at startup time; memory is now allocated as needed. And lots of data copying has been taken out. All told, it is a much cleaner and better-performing solution than its predecessors.

Getting this code into the kernel was a classic example of working well with the community. The developers took pains to post their code early, then they listened to the comments which came back. In the process of responding to reviews, they were able to make some internal kernel API changes which made life easier. In general, they found, when you actively engage the kernel community, making changes is easy.

The next step was the new DRI2 X extension, intended to replace the (now legacy) DRI extension. It only has three requests, enabling connection to the hardware and buffer allocation. The DRI shared memory area (and its associated lock) have been removed, eliminating a whole class of problems. Buffer management is all done in the X server; that makes life a lot easier.

Then, there is the kernel mode-setting (KMS) API - the other big missing piece. KMS gets user-space applications out of the business of programming the adapter directly, putting the kernel in control. The KMS code (merged for 2.6.29) also implements the fbdev interface, meaning that graphics and the console now share the same driver. Among other things, that will let the kernel present a traceback when the system panics, even if X is running. Fast user switching is another nice feature which falls out of the KMS merge. KMS also eliminates the need for the X server to run with root privileges, which should help security-conscious Linux users sleep better at night. The X server is a huge body of code which, as a rule, has never been through a serious security audit. It's a lot better if that code can be run in an unprivileged mode.

Finally, KMS holds out the promise of someday supporting non-graphical uses of the GPU. See the GPGPU site for information on the kinds of things people try to do once they see the GPU as a more general-purpose coprocessor.

All is not yet perfect, naturally. Beyond its limited hardware support, the new code also does not yet solve the longstanding "tearing" problem. Tearing happens when an update is not coordinated with the monitor's vertical refresh, causing half-updated screens. It is hard to solve without stalling the GPU to wait for vertical refresh, an operation which kills performance. So the X developers are looking at ways to context-switch the GPU. Then buffer copies can be queued in the kernel and caused to happen after the vertical refresh interrupt. It's a somewhat hard problem, but, says Keith, it will be fixed soon.

There is reason to believe this promise. The X developers have managed to create and merge a great deal of code over the course of the last year. Keith's talk was a sort of a celebration; the multi-year process of bringing X out of years of stagnation and into the 21st century is coming to a close. That is certainly an achievement worth celebrating.

Postscript: Keith's talk concerned the video output aspect of the X Window System, but an output-only system is not particularly interesting. The other side of the equation - input - was addressed by Peter Hutterer in a separate session. Much of the talk was dedicated to describing the current state of affairs on the input side of X. Suffice to say that it is a complex collection of software modules which have been bolted on over the years; see the diagram in the background of the picture to the right.

[Peter Hutterer] What is more interesting is where things are going from here. A lot of work is being done in this area, though, according to Peter, only a couple of developers are doing it. Much of the classic configuration-file magic has been superseded by HAL-based autoconfiguration code. The complex sequence of events which follows the attachment of a keyboard is being simplified. Various limits - on the number of buttons on a device, for example - are being lifted. And, of course, the multi-pointer X work (discussed at LCA2008) is finding its way into the mainline X server and into distributions.

The problems in the input side of X have received less attention, but it is still an area which has been crying out for work for some time. Now that work, too, is heading toward completion. For users of X (and that is almost all of us), life is indeed getting better.

Index entries for this article
Conferencelinux.conf.au/2009


(Log in to post comments)

LCA: Catching up with X.org

Posted Jan 23, 2009 16:56 UTC (Fri) by kev009 (guest, #43906) [Link]

I bet the XFree86 guys are feeling like bigger idiots by the day. This is what happens when you try and mess with free software and put off good developers. Quite nice poetic justice as XFree86 fades to nothingness.

I do, however, hope that these new features can be made to work on BSD and other UNIX platforms in time. It would be a shame for FreeBSD, quite a nice kernel/OS itself, to be in the position Linux has been in for this time simply because of popularity.

LCA: Catching up with X.org

Posted Jan 23, 2009 19:09 UTC (Fri) by drag (guest, #31333) [Link]

It should be possible to make these things work on BSD.

The DRI2 interface is what you need to have in order to communicate between the userspace Mesa-based drivers and in-kernel memory management stuff.

So if the BSD folks are able to modify their kernels to support the DRI2 interface and it's limited set of operations then compatibility should follow.

Probably the biggest problem is that I suppose the BSD folks rely on X drivers heavily for their GUI stuff. With the DRI2/GEM/KMS/Gallium3D stuff the need for X.org's DDX drivers are evaporating.

That is in the future the need for things like xorg-drv-video-intel (or whatever) will be gone. Instead of running your GUI as root you should be able to run it using normal everyday APIs that are available to any other application under your user account.

So unless the BSD folks get their butts into gear then they will get left behind and end up having to force to deal with a huge amount of Linux-isms... It's going to be very difficult for X.org to avoid shovelling to much Linux-specific code when the interfaces they need in BSD are simply non-existent.

-----------------------------------------

One of big features for Vista, for example, was a new userspace driver model for graphics. As part of it they touted a new kernel memory manager for graphics. This was one of the big issues that early Vista users had... their video drivers from XP wouldn't work that well and the new vista-specific drivers were not mature.

And I expect that if anybody here was to look at OS X they would have a similar setup for their composited interface.

So I think that if you want to provide modern graphics and modern APIs that take advantage of GPUs this is just the sort of thing you need.

Plus moving your GUI out of being setuid root binary is always going to be a good thing.

LCA: Catching up with X.org

Posted Jan 23, 2009 21:15 UTC (Fri) by jamesh (guest, #1159) [Link]

Note that the commands being stuffed in the batch buffers are still very GPU-dependent. There is still a need for GPU-specific drivers with all this work.

LCA: Catching up with X.org

Posted Jan 24, 2009 0:11 UTC (Sat) by drag (guest, #31333) [Link]

Well that is what Gallium is designed to deal with right? Provide a winsys driver that is hardware dependent and then use that as a way to translate GPU-independent APIs to GPU-specific instructions...

Gallium3D should be introduced in a testable form in Mesa 7.5.

LCA: Catching up with X.org

Posted Jan 23, 2009 19:13 UTC (Fri) by branden (guest, #7029) [Link]

Having dealt, some years ago, on a regular basis with some of the "core"* XFree86 members, I am confident that they feel thoroughly vindicated by the course of events.

Yes, that's right. Best not to think about it too hard. ;-)

* XFree86 disbanded its core team contemporaneously with the mass exodus to X.Org; my guess is that they twigged correctly that there was no point having a "core" development team when there was not going to be a "periphery".

LCA: Catching up with X.org

Posted Jan 24, 2009 8:45 UTC (Sat) by flewellyn (subscriber, #5047) [Link]

So they deliberately sabotaged the project in order to spur someone else to do the improvements they didn't want to do?

That's not making sense to me.

LCA: Catching up with X.org

Posted Jan 26, 2009 13:29 UTC (Mon) by branden (guest, #7029) [Link]

No. I'll stop being so opaque.

I can't find the mailing list reference--and for all I know the message isn't archived anymore, but at one point one of the erstwhile core team members bluntly said (generously paraphrased) that the project had far too many users, was too Linux-centric, and that times were much better when they were just a small group of friends hacking up a descendant of X386 for their own fun and edification.

Now, I don't know if this opinion was shared by all of the core team, or even that this wasn't necessarily a sarcastic rant, but it does render XFree86's philosophy of project management comprehensible, and their actions rational within that framework.

The only wart on it is that these goals were not (and are not) stated forthrightly. XFree86's conception of its userbase was a mass of essentially anonymous people who could use the code if they wanted to, were welcome to file bugs or submit patches, but should not ever expect more than the most perfunctory conversation, or to ever enjoy elevation into the clubhouse. (That said, one developer, after many years, did achieve such an ascension, apparently through years of hard work and the forging of a personal friendship with a core team member, in part through trade shows).

XFree86 did deviate from that founding principle, leading to such things as (gulp) a public bug tracker, public betas, a second tier of half a dozen or so serious contributors, and even the injection of an X architect into the core team, but all of these served to poison the original vision.

By these lights, the X-Oz license, later the XFree86 1.1 license, makes perfect sense. By crafting a license whose terms were objectionable to most of the community and its developers (especially the smelly proletariat comfortable with the GPL and impure variants of the original BSD licenses which were missing clauses), but to which the trait of "freedom" could still arguably be said to apply--and thus positive relations with the beloved *BSD projects preserved--it succeeded in metaphorically nailing a "KEEP OUT" sign to the clubhouse door.

That even the *BSDs gave up on XFree86 is, under this model, regrettable but by no means an indication of failure. In a way, it's better this way, because the proceedings of XFree86's august society are even less frequently disturbed.

The BSDs

Posted Jan 24, 2009 0:01 UTC (Sat) by dbnichol (subscriber, #39622) [Link]

There are a couple guys (Owain Ainsworth for OpenBSD and Robert Noland for FreeBSD) working to get the drm side going.

LCA: Catching up with X.org

Posted Jan 24, 2009 0:18 UTC (Sat) by jwb (guest, #15467) [Link]

"All told, it is a much cleaner and better-performing solution than its predecessors."

I object to the introduction of facts not in evidence. I haven't heard anyone claim that Intel + GEM graphics performance is better than the way it was before. My experience and the experience of pretty much every user posting to the xorg mailing list is that the latest bits are a noticeable regression. The problem is finding what caused the regression. Is UXA worse than EXA? Are they both worse than XAA? Is GEM busted? Nobody can tell.

LCA: Catching up with X.org

Posted Jan 24, 2009 0:37 UTC (Sat) by nix (subscriber, #2304) [Link]

Text scrolling performance in X.org 1.5 is intolerably awful, I know that
(we're talking five seconds of 100% CPU consumption by X on an Athlon IV
to repaint the screen just once).

As soon as I figure out how to get sysprof to report backtraces inside X
with other than ?, I'll report it...

LCA: Catching up with X.org

Posted Jan 25, 2009 23:32 UTC (Sun) by jlokier (guest, #52227) [Link]

Sounds like a configuration error - using software scrolling (no acceleration) and not using a shadow framebuffer. That results in a lot of reads from video memory to the CPU (not GPU), which is often that sort of very slow.

Try enabling some kind of acceleration at least :-)
If you can't, perhaps you're using the "vesa" driver, in which case try enabling the shadow framebuffer.

This isn't new to Xorg 1.5, but maybe it configures itself differently and gets this wrong.

LCA: Catching up with X.org

Posted Jan 29, 2009 11:52 UTC (Thu) by nix (subscriber, #2304) [Link]

It's slow both with XAA and EXA, both of which should surely be accelerating. xterms forced to use core fonts scroll *fast*. Everything else is as fast as usual as well.

I wonder if render acceleration has been broken in recent versions of the ATI driver and/or x11-xserver 1.5... it's something that was only ever implemented for r200 cards anyway, so it could have been broken without most people noticing.

LCA: Catching up with X.org

Posted Feb 5, 2009 0:30 UTC (Thu) by nix (subscriber, #2304) [Link]

Fixed! The X-server-to-be, 1.6, is blindingly fast at client-side font
scrolling: client-side fonts, even antialiased ones, are very nearly as
fast as core fonts in 1.5. The glyph cache in 1.6 is excellent.

LCA: Catching up with X.org

Posted Jan 24, 2009 3:20 UTC (Sat) by mitchskin (guest, #32405) [Link]

Among other things, that will let the kernel present a traceback when the system panics, even if X is running.
Hey, this could be implemented as a bunch of white text on a blue background...

LCA: Catching up with X.org

Posted Jan 24, 2009 14:44 UTC (Sat) by jengelh (subscriber, #33263) [Link]

Been done already (but not merged). Google "colored kernel output".

LCA: Catching up with X.org

Posted Jan 31, 2009 1:17 UTC (Sat) by giraffedata (guest, #1954) [Link]

But you still don't see anything if the crash happens while you're in graphics mode. If you want the look and feel of old Windows, you need this new X function.

LCA: Catching up with X.org

Posted Jan 24, 2009 11:37 UTC (Sat) by modernjazz (guest, #4185) [Link]

Very exciting. Thanks for catching us up on the big picture.

LCA: Catching up with X.org

Posted Jan 24, 2009 22:04 UTC (Sat) by wingo (guest, #26929) [Link]

One big unclear issue for me is the status of input redirection. It's clear that the in-kernel GPU memory manager was essential to support output redirection (compiz with direct rendering is a case of this), but what support exists for mapping clicks on polygons to clicks in X windows coordinates?

It's so difficult to get a clear picture on GPUs these days, because the know-nothing fora get all of the google hits.

LCA: Catching up with X.org

Posted Jan 26, 2009 1:16 UTC (Mon) by njs (subscriber, #40338) [Link]

Input redirection is mostly unrelated to GPUs, but last I heard (6 months ago, maybe?), this was somewhat stalled -- the first approach, of the server handing off input events to a special client (the compositing manager) and letting it do the coordinate conversions, turned out not to work. (They ran into problems coordinating everyone during e.g. grab handling.) The new idea is for the compositing manager to actually upload a triangle mesh to the server and then have the server use that to do the coordinate transformation itself... but no-one was actively working on this, and there's a limited quantity of keithp-types to go around.

Someone else may have more detailed/up-to-date information.

LCA: Catching up with X.org

Posted Jan 26, 2009 17:53 UTC (Mon) by yokem_55 (subscriber, #10498) [Link]

Qt 4.5 seems to have some support for input redirection. See the WolfenQt demo for an example. But I'm not sure if this is quite the same thing.

LCA: Catching up with X.org

Posted Jan 30, 2009 2:46 UTC (Fri) by jamesh (guest, #1159) [Link]

This isn't something a toolkit could implement itself.

Imagine a compositing window manager that takes a particular window and renders it at twice its original dimensions. Input redirection is needed to let the user interact with this zoomed window in a way that the underlying application can understand (halve the x and y coordinates and translate to match the real window position).

All this has to happen before the input reaches the application. After all, we want clicks that occur outside the application's window to be directed to it.

LCA: Catching up with X.org

Posted Jan 27, 2009 6:48 UTC (Tue) by nikanth (guest, #50093) [Link]

KMS is cool.. Expecting fancy oops messages better than the infamous Blue Screen of Death.

Also wonder about the state of the MPX: Multi-Pointer X. Is that merged now? Can I use 2 mouses now? Any distro that supports this?

LCA: Catching up with X.org

Posted Feb 6, 2009 6:46 UTC (Fri) by luya (subscriber, #50741) [Link]


Copyright © 2009, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds