More Mutrace

Post Syndicated from Lennart Poettering original https://0pointer.net/blog/projects/mutrace2.html

Here’s a list of quick updates on my mutrace mutex profiler since
my initial announcement two weeks ago:

I added some special support for tracking down use of mutexes in realtime
threads. It’s a very simple extension that — if enabled — checks on each
mutex operation wheter it is executed by a realtime thread or not. (–track-rt) The
output of a test run of this you can find in this announcement on LAD.
Particularly interesting is that you can use this to track down which mutexes
are good candidates for priority inheritance.

The mutrace tarball now also includes a companion tool matrace
that can be used to track down memory allocation operations in realtime
threads. See the same lad announcement as above for example output of this
tool.

With help from Boudewijn Rempt I added some compatibility code for
profiling C++/Qt apps with mutrace, which he already used for some interesting
profiling results
on krita.

Finally, after my comments on the locking hotspots in glib’s type system,
Wim Taymans and Edward Hervey worked on turning the mutex-emulated rwlocks
into OS native ones with quite positive results, for more information see this
bug
.

As soon as my review request is fully processed mutrace will be available
in rawhide.

A snapshot tarball of mutrace you may find here
(despite the name of the tarball that’s just a snapshot, not the real release
0.1), for all those folks who are afraid of git, or don’t have a current
autoconf/automake/libtool installed.

Oh, and they named a unit after me.

Measuring Lock Contention

Post Syndicated from Lennart Poettering original https://0pointer.net/blog/projects/mutrace.html

When naively profiling multi-threaded applications the time spent waiting
for mutexes is not necessarily visible in the generated output. However lock
contention can have a big impact on the runtime behaviour of applications. On
Linux valgrind’s
drd
can be used to track down mutex contention. Unfortunately running
applications under valgrind/drd slows them down massively, often having the
effect of itself generating many of the contentions one is trying to track
down. Also due to its slowness it is very time consuming work.

To improve the situation if have now written a mutex profiler called
mutrace
. In contrast to valgrind/drd it does not virtualize the
CPU instruction set, making it a lot faster. In fact, the hooks mutrace
relies on to profile mutex operations should only minimally influence
application runtime. mutrace is not useful for finding
synchronizations bugs, it is solely useful for profiling locks.

Now, enough of this introductionary blabla. Let’s have a look on the data
mutrace can generate for you. As an example we’ll look at
gedit as a bit of a prototypical Gnome application. Gtk+ and the other
Gnome libraries are not really known for their heavy use of multi-threading,
and the APIs are generally not thread-safe (for a good reason). However,
internally subsytems such as gio do use threading quite extensibly.
And as it turns out there are a few hotspots that can be discovered with
mutrace:

$ LD_PRELOAD=/home/lennart/projects/mutrace/libmutrace.so gedit
mutrace: 0.1 sucessfully initialized.

gedit is now running and its mutex use is being profiled. For this example
I have now opened a file with it, typed a few letters and then quit the program
again without saving. As soon as gedit exits mutrace will print the
profiling data it gathered to stderr. The full output you can see
here.
The most interesting part is at the end of the generated output, a
breakdown of the most contended mutexes:

mutrace: 10 most contended mutexes:

 Mutex #   Locked  Changed    Cont. tot.Time[ms] avg.Time[ms] max.Time[ms]       Type
      35   368268      407      275      120,822        0,000        0,894     normal
       5   234645      100       21       86,855        0,000        0,494     normal
      26   177324       47        4       98,610        0,001        0,150     normal
      19    55758       53        2       23,931        0,000        0,092     normal
      53      106       73        1        0,769        0,007        0,160     normal
      25    15156       70        1        6,633        0,000        0,019     normal
       4      973       10        1        4,376        0,004        0,174     normal
      75       68       62        0        0,038        0,001        0,004     normal
       9     1663       52        0        1,068        0,001        0,412     normal
       3   136553       41        0       61,408        0,000        0,281     normal
     ...      ...      ...      ...          ...          ...          ...        ...

mutrace: Total runtime 9678,142 ms.

(Sorry, LC_NUMERIC was set to de_DE.UTF-8, so if you can’t make sense of
all the commas, think s/,/./g!)

For each mutex a line is printed. The ‘Locked’ column tells how often the
mutex was locked during the entire runtime of about 10s. The ‘Changed’ column
tells us how often the owning thread of the mutex changed. The ‘Cont.’ column
tells us how often the lock was already taken when we tried to take it and we
had to wait. The fifth column tell us for how long during the entire runtime
the lock was locked, the sixth tells us the average lock time, and the seventh
column tells us the longest time the lock was held. Finally, the last column
tells us what kind of mutex this is (recursive, normal or otherwise).

The most contended lock in the example above is #35. 275 times during the
runtime a thread had to wait until another thread released this mutex. All in
all more then 120ms of the entire runtime (about 10s) were spent with this
lock taken!

In the full output we can now look up which mutex #35 actually is:

Mutex #35 (0x0x7f48c7057d28) first referenced by:
	/home/lennart/projects/mutrace/libmutrace.so(pthread_mutex_lock+0x70) [0x7f48c97dc900]
	/lib64/libglib-2.0.so.0(g_static_rw_lock_writer_lock+0x6a) [0x7f48c674a03a]
	/lib64/libgobject-2.0.so.0(g_type_init_with_debug_flags+0x4b) [0x7f48c6e38ddb]
	/usr/lib64/libgdk-x11-2.0.so.0(gdk_pre_parse_libgtk_only+0x8c) [0x7f48c853171c]
	/usr/lib64/libgtk-x11-2.0.so.0(+0x14b31f) [0x7f48c891831f]
	/lib64/libglib-2.0.so.0(g_option_context_parse+0x90) [0x7f48c67308e0]
	/usr/lib64/libgtk-x11-2.0.so.0(gtk_parse_args+0xa1) [0x7f48c8918021]
	/usr/lib64/libgtk-x11-2.0.so.0(gtk_init_check+0x9) [0x7f48c8918079]
	/usr/lib64/libgtk-x11-2.0.so.0(gtk_init+0x9) [0x7f48c89180a9]
	/usr/bin/gedit(main+0x166) [0x427fc6]
	/lib64/libc.so.6(__libc_start_main+0xfd) [0x7f48c5b42b4d]
	/usr/bin/gedit() [0x4276c9]

As it appears in this Gtk+ program the rwlock type_rw_lock
(defined in glib’s gobject/gtype.c) is a hotspot. GLib’s rwlocks are
implemented on top of mutexes, so an obvious attempt in improving this could
be to actually make them use the operating system’s rwlock primitives.

If a mutex is used often but only ever by the same thread it cannot starve
other threads. The ‘Changed.’ column lists how often a specific mutex changed
the owning thread. If the number is high this means the risk of contention is
also high. The ‘Cont.’ column tells you about contention that actually took
place.

Due to the way mutrace works we cannot profile mutexes that are
used internally in glibc, such as those used for synchronizing stdio
and suchlike.

mutrace is implemented entirely in userspace. It
uses all kinds of exotic GCC, glibc and kernel features, so you might have a
hard time compiling and running it on anything but a very recent Linux
distribution. I have tested it on Rawhide but it should work on slightly older
distributions, too.

Make sure to build your application with -rdynamic to make the
backtraces mutrace generates useful.

As of now, mutrace only profiles mutexes. Adding support for
rwlocks should be easy to add though. Patches welcome.

The output mutrace generates can be influenced by various
MUTRACE_xxx environment variables. See the sources for more
information.

And now, please take mutrace and profile and speed up your application!

You may find the sources in my
git repository.

pthread_key_create() is dangerous

Post Syndicated from Lennart Poettering original https://0pointer.net/blog/projects/pthread-key-create.html

If you use pthread_key_create() with a non-NULL destructor
parameter (or an equivalent TLS construct) in a library/shared object then you
MUST link your library wth -z nodelete (or an equivalent
construct).

If you don’t, then you’ll have a lot of fun (like I just had) debugging
segfaults in the TLS destruction logic where functions are called that might
not even exist anymore in memory.

Now don’t tell me I hadn’t told you.

(Oh, and I hope I don’t need to mention that all GObject-based libraries should
link with -z nodelete anyway, for making sure the type system doesn’t
break.)

The Highest Man in Spain

Post Syndicated from Lennart Poettering original https://0pointer.net/blog/photos/canaries-360.html

Ever wanted to know what’s the view like being the highest person in all of Spain? — No? Hmm, can’t help you then. — Otherwise:

Pico del Teide

That’s on the summit of Pico del Teide at 3718m, on Tenerife island. Unless you leave solid ground this is as high as you can get in Spain. 163m lower it’s a bit more obvious that the Teide is a volcano:

Pico del Teide

And coming down to the surrounding caldera it’s even more obvious:

Pico del Teide

Pico del Teide

Pico del Teide

On a ridge next to the caldera you find the Teide Observatory:

Teide Observatory

The caldera is covered in old lava flows:

Caldera

Caldera

Vulcanism has created various interesting rock formations in the caldera:

Roques

Roques

Tenerife is not just about the Teide and its dusty caldera. In the north of the island you find the Anaga mountain range:

Tenerife North

Neighboring Gran Canaria was where our little trip started and ended, right after the Gran Canaria Desktop Summit. Gran Canaria has no Teide but a very impressive landscape nonetheless:

Roque Nublo

That’s the view from the Roque Nublo, the island’s most famous landmark. The rock itself is visible here (on the left):

Roque Nublo

Oh Nine Sixteen

Post Syndicated from Lennart Poettering original https://0pointer.net/blog/projects/oh-nine-sixteen.html

#nocomments y

As a followup to Oh Nine
Fifteen
here’s a little overview of the changes coming with PulseAudio 0.9.16 which will be part of
Fedora 12 (already in Rawhide; I think Ubuntu Karmic (?) will have it
too).

A New Mixer Logic

We now try to control more than just a single ALSA mixer element for volume
control. This increases the hardware volume range and granularity exposed and
should also help minimizing problems by incomplete or incorrect default mixer
initialization on the lower levels.

This also adds support for allowing selection of input/output ports for
sound cards. This is used to expose changing between Mic vs. Line-In for input
source selection and Headphones vs. Speaker for output selection (of course the
list of available port is strictly dependant on what you hardware supports).
The list of available ports is deliberately kept minimal.

Thanks to Bastien the newest GNOME Volume Control now exposes profile/port
switching quite nicely, which he
blogged about.
This
screenshot shows how the port (here called ‘Connector’) can be selected
in the new dialog.

The mixer rework also allows us to handle semi-pro/pro sound cards a bit
more flexibly. For example, which profiles/ports are exposed in PulseAudio or
how specific mixer elements are handled can now be controlled by editing .ini
file like configuration files in /usr/share/pulseaudio/alsa-mixer/.
Read
this mail for more information about this.

UPnP MediaServer Support

PulseAudio now integrates with Zeeshan’s fabulous Rygel UPnP/DLNA MediaServer. If enabled
Rygel will automatically expose all local audio devices which are managed by
PulseAudio as UPnP/DLNA MediaServer items which your UPnP/DLNA MediaRenderers
can now tune into. (Meaning: you can now stream audio from your PC directly to
your UPnP DMP (Digital Media Player) device, such as the PS3.) Communication
between Rygel and PulseAudio follows our little Media Server Spec on the
GNOME Wiki
. This nicely complements the RAOP (Apple Airport) support we
introduced in PulseAudio 0.9.15. In one of the next versions of
PulseAudio/Rygel we hope to add support for PulseAudio becoming a MediaRenderer
as well. This will then not only allow you to stream from your PC to your
DMP device, but also allows PulseAudio to act as
“networked speaker”, which can be used by any UPnP/AV/DLNA control point, such
as Windows’ Media Player.

Hotplug Support Improved

If you select a particular device as the default for a specific application
or class of streams, then when unplugging the device PulseAudio moves the stream
automatically to another audio device if one exists. New in PulseAudio 0.9.16
is that if you replug the audio device the stream will instantly be moved back,
requiring no further user intervention.

Also, PulseAudio now includes some implicit rules for doing the ‘right
thing’ when finding an audio device for an application. For example, unless
configured otherwise it will now route telephony applications automatically to
Bluetooth headsets if one is connected, in favour of the internal sound card of
the computer.

Surround Sound Support for Event Sounds

This is more a new feature of libcanberra than
of PulseAudio, but nonetheless: we now support surround for events sounds.
This allows us to play full 5.1 login sounds for example, in best THX cinema
fashion. We’d love to ship a 5.1 sound for login by default in sound-theme-freedesktop.
We’d be very thankful if you would be willing to contribute a sound
here, or two! A sound a bit less bombastic than the famous cinema THX effect
would probably be a good idea though.

And then there’s of course the usual batch of fixes and small improvements.
A substantial number of non-user visible changes have been made as well. For
example, as HAL is now obsolete PulseAudio now moved to udev for its device
discovery needs. We replaced our gdbm support by support for tdb. Also,
we stripped all security senstive code from PulseAudio, and ported it to use
RealtimeKit instead.
For the upcoming distributions that means that PulseAudio will run as real-time
process by default, improving drop-out safety.

And for some extra PA eye-candy, have a look on Impulse!

Microsoft Releases GPL’d Software (Again): Does This Change Anything?

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2009/07/29/microsoft-gpl.html

Microsoft has received much undeserved press about their recent release
of Linux drivers for their virtualization technology under GPLv2. I say
“undeserved” because I don’t particularly see why Microsoft
should be lauded merely for doing something that is in their own
interest that they’ve done before.

Most people have forgotten that Microsoft once had a GPL-based product
available for Windows NT. It was called Windows Services for
UNIX
, and AFAICT, remains available today (although perhaps
they’ve transitioned in recent years to no longer include GPL’d
software).

This product
was acquired
by Microsoft when they purchased Softway Systems
. The product was
based on GCC, and included a variety of GNU system utilities ported to
Windows. Microsoft was a compliant distributor of this software for
years, right during the time when they were calling the GPL an unAmerican
cancerous virus that eats up software like PacMan. The GPL is not a new
license to Microsoft; they only pretend that it is to give bad press to
the GPL or to give good press to themselves.

Another thing that’s not new to Microsoft is that they have no
interesting in contributing to Free Software unless it makes their
proprietary software more desirable. In my old example above, they
hoped to entice developers who preferred a Unix development environment to
switch to Windows NT. In the recent Linux driver release, they seek to
convince developers to switch from Xen and KVM to their proprietary
virtualization technology.

In fact, the only difference in this particular release is that, unlike
in the case of Softway’s
software, Microsoft
was apparently (according to Steve Hemminger) out of compliance
briefly
. According to Steve, Microsoft distributed binaries linked
to various GPL parts.

Meanwhile, Sam Ramji claimed that Microsoft were already planning to
release the software before Hemminger and Greg K-H contacted them. I do
believe Sam when he says that there was already talk inside Microsoft
about releasing the source underway before the Linux developers
began their enforcement effort. However, that internal Microsoft talk
doesn’t mean that there wasn’t a problem. As soon as one distributes
the binaries of a GPL’d work, one must provide the source (or an offer therefor) alongside
those binaries. Thus, if Microsoft released binaries and delayed in
releasing source, there was a GPL violation.

Like all GPL violations (and potential GPL violations), it’s left to
the copyright holders of the software to engage in enforcement. I think
it’s great
that, according
to Steve
and related press coverage, the Linux developers used the most common enforcement
strategy in the GPL community — quietly contact the company,
inform them of their obligations, and help them in a friendly way into
compliance. That process almost always works, and the fact that
Microsoft came into compliance shows the value of our community’s
standard enforcement practice.

Still, there is a more important item of note from a perspective of
software freedom. This Linux driver — whether it is released properly
under the GPL or kept proprietary in violation of the GPL — is designed to convince users to give up Free
virtualization platforms like Xen and KVM and use Microsoft’s
virtualization technology instead. From that perspective, it matters
little that it was released as Free Software: people should avoid the
software and use platforms for virtualization that respect their
freedom.

Someday, perhaps, Microsoft will take a proper place among other large
companies that actually contribute code that improves the general
infrastructure of Free Software. Many companies give generally useful
improvements back to Linux, GCC, and various other parts of the
GNU/Linux system. Microsoft has never done this: they only contribute
code when it improves Free Software interoperability with their
proprietary technology. The day that Microsoft actually changes its
attitude toward Free Software did not occur last week. Microsoft’s old
strategy stays the
same: try
to kill Free Software with patents
, and in the meantime, convince as
many Free Software users as possible to begin relying on Microsoft
proprietary technology.

Microsoft Patent Aggression Continues Against Free Software

Post Syndicated from Bradley M. Kuhn original http://ebb.org/bkuhn/blog/2009/07/17/microsoft-patent-aggression.html

I think this news
item from yesterday
mostly speaks for itself, but I could not let the
incident go by without blogging briefly about it.

There has been so much talk in the last two weeks that Microsoft has
changed with regard to its patent policy toward Free Software. We fool
ourselves if we trust any of the window-dressing that Microsoft has put
forward to convince us that we can trust them in this regard. Indeed, I
spoke extensively about this in my interview on the Linux
Outlaws
show
this week.

What we see in this agreement between the Melco Group and Microsoft is
another little above-water piece of the same patent aggression iceberg
that Microsoft has placed in our community’s way. They continue to shake
down companies that distribute GNU/Linux systems for patent royalties. As
I’ve written about before, it’s
difficult to judge if these are GPLv2-compliant, but they are almost
certainly not GPLv3-compliant
. If there were ever a moment for the
community to scramble to GPLv3, this would be it, if for no other reason
to defend ourselves against the looming aggression.

In the meantime, we’d be foolish to trust any sort of promises
Microsoft has to make about their patents. Would they really make a
reliable promise that would prevent their ongoing campaign of patent
aggression against Free Software?

Update: In related news, I was also glad to read FSF’s new statement on the issue, which includes some of the same comments I made on Linux Outlaws Episode 102.

The collective thoughts of the interwebz

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close