|
|
Subscribe / Log in / New account

Ktap almost gets into 3.13

By Jonathan Corbet
November 6, 2013
The ktap project surprised almost everybody when it made its 0.1 release last May. In short, ktap is a dynamic tracing tool; it works by embedding a Lua interpreter within the kernel and hooking it into the existing tracepoint mechanism. A suitably privileged user can load a script into the kernel; that script can enable tracepoints, boil down the resulting data, and return information back to user space. It thus fills a niche similar to that of SystemTap or DTrace, but with a smaller, simpler, and (for now) less-functional code base.

Ktap was reasonably well received from the outset, with a number of developers welcoming this functionality. The work was presented at LinuxCon Japan, and the 0.2 release followed at the end of July. After that, things quieted down for a bit until mid-October, when Greg Kroah-Hartman announced (on Google+) that ktap had been merged into the staging tree for the 3.13 release. This release, which already looked to be a relatively feature-heavy development cycle, appeared to be set to acquire a dynamic tracing framework as well.

It subsequently became clear, though, that some developers hadn't seen Greg's post and weren't happy. On October 24, Ingo Molnar sent a protest over the imminent merging of ktap. He added a "Nacked-by" for good measure; Steven Rostedt then followed up with a NACK of his own. After a Kernel Summit conversation with Ingo, Greg reverted the changes, removing ktap from the staging tree and, thus, from the queue for the 3.13 kernel. Those who have been waiting for this kind of dynamic tracing functionality in the Linux kernel will have to wait a bit longer.

What happened, and what's next

At a first glance, this incident could be mistaken as an example of a newcomer being rejected by the incumbent developers of the existing tracing functionality. One need not look much further, though, to see that a rather different explanation applies. The rejection of ktap, which looks highly likely to be a temporary affair, is more a story about the right and wrong ways to get new functionality into the kernel.

The first and foremost mistake is that the patches were never actually posted to the linux-kernel mailing list for review. Ktap developer Jovi Zhangwei has posted his release announcements there, and the code has always been available in a public git repository. But getting review for code in a repository is never easy; that certainly proved to be true in this case. While some developers knew about ktap and what it could do, few had actually looked at the implementation.

As Ingo pointed out in his objection, the form of the code in the staging tree (a single changeset adding 16,000 lines of code) did not make the review process any easier. Neither did the lack of documentation about the design of ktap.

The biggest complaint, though, was about the lack of integration with the kernel's existing tracing functionality. Ingo pointed out a couple of areas where that kind of integration might be useful:

  • The kernel currently has a simple interpreter used to implement filter conditions on tracepoints. The Lua bytecode interpreter offers a rather richer execution environment; it could perhaps be put to work implementing a more comprehensive conditional evaluation mechanism for tracepoints.

  • Rather than requiring a new set of commands, ktap scripts could be made part of the perf probe command, tying them more firmly into the existing system. Ingo's goal is clearly to have a single set of comprehensive tracing functionality that can all be exercised without having to know about the separate subsystems that implement it.

  • Ingo also requested the ability to extract ktap scripts from the kernel and turn them back into their source form. That, he said, would improve security by making it possible to examine any scripts running within the kernel.

In summary, Ingo said, the code looks like it could be useful and make the kernel's instrumentation better:

Despite my criticism, I'm actually a big proponent of safe kernel probing concepts and this code does have many of the qualities that I always wanted the tracepoint filter code to have in the long run.

So it appears that ktap should be able to get in eventually, but first Jovi has some work cut out for him to get this code into proper shape for merging. The good news is that he seems prepared to do that work. The hope is to have a reworked version of ktap reviewed and ready for the 3.14 development cycle; at that point, it should be able to go directly into the core kernel without a stay in the staging tree. This delay is likely to be frustrating for everybody involved, but the end result will almost certainly be an improved, in-kernel scripting facility for dynamic tracing.

Index entries for this article
KernelDevelopment tools/Kernel tracing
KernelTracing


to post comments

Ktap almost gets into 3.13

Posted Nov 7, 2013 6:49 UTC (Thu) by karim (subscriber, #114) [Link] (7 responses)

Seriously, making this part of perf makes it much less likely that I'll use it.

Ktap almost gets into 3.13

Posted Nov 7, 2013 13:14 UTC (Thu) by deater (subscriber, #11746) [Link] (1 responses)

> Seriously, making this part of perf makes it much less likely
> that I'll use it.

As long as Ingo maintains perf it's unlikely that any other profiling tool will get into the kernel unless it's through perf_event, even if it doesn't make sense.

It's why things like AMD Lightweight Profiling never made it into the kernel

And it's why things like ftrace tracing are part of perf, complicating the interface, which has led to recent bugs where a normal user can lock the kernel using the perf interface.

Ktap almost gets into 3.13

Posted Nov 7, 2013 14:24 UTC (Thu) by karim (subscriber, #114) [Link]

Yes, I'm fully aware of that. And while I respect Ingo's work a great deal, there are areas where it's my personal belief that his well-intentioned stewardship of key functionality is actually counter-productive. Specifically, his clout makes it so that any suggestion that runs counter to his own designs results in that proposal to be doomed to failure.

At this stage many of those that have tried are staying away. Personally I've given up on Linux ever providing meaningful online diagnostic to rival any of the other OSes out there. There's just too much kernel politics in the way. This recent idea that all new performance/monitoring stuff has to go through perf craziness is just one more on the list.

FWIW I think ftrace's user interface is kickass. It's not perfect and there are other ways of doing things, but ftrace certainly shows that it was architectured based on deep, real-life experience with tracing lots of data. Smarts just aren't enough.

Ktap almost gets into 3.13

Posted Nov 7, 2013 13:53 UTC (Thu) by lambda (subscriber, #40735) [Link] (4 responses)

I'm curious, what do you find wrong with perf? I've been looking for a good tracing framework recently, and figured that since perf is in mainline I should probably learn that, but I'm wondering if there are better choices out there.

It's bit frustrating that on Linux there are so many, all of which are either incomplete or out of tree; on Solaris, FreeBSD, or Mac OS X, the answer is just "dtrace", while I'm never quite sure which tracing framework to learn on Linux.

Ktap almost gets into 3.13

Posted Nov 7, 2013 14:41 UTC (Thu) by karim (subscriber, #114) [Link] (1 responses)

Well, a whole lot of things. First and foremost it's just not the user interface I would expect. Why, exactly, do I have to give a command that it has to run, like "sleep 10", to given an upper-bound to its running? Why not just give me a "-t 10". Then the data it gives is all sample-based. Sampling is nice, but I'd find it a whole lot more useful to be able to have performance counters being read at every hit to an ftrace trace point. But I wouldn't need perf for that. The way I see it is that perf is like a better gprof. That's just not powerful enough for me. Then again, I'm not a regular user and I might have a very peculiar way of solving problems.

Ktap almost gets into 3.13

Posted Nov 7, 2013 16:31 UTC (Thu) by deater (subscriber, #11746) [Link]

What you're talking about (performance counter dump every time a tracepoint is hit) should in theory be possible with the raw perf_event interface. Just set up the tracepoint and events to measure and have them "sample" every time the tracepoint is hit. I have no idea what kind of crazy command line you'd need to try to convince the "perf" tool to actually do that though, assuming it were possible.

Ktap almost gets into 3.13

Posted Nov 12, 2013 3:58 UTC (Tue) by bgregg (guest, #46639) [Link] (1 responses)

perf is great. I've used it's profiling (sampling), static tracing, and dynamic tracing abilities, and with access to local variables. And I've written and shared documentation about perf (conference talks, books).

pref can do a lot, but there are some things where the performance hit can make me hesitate. For example, timing a busy kernel function, where I'm interested in examining its distribution, to identify outliers or multiple modes. perf has an enable/trace/dump/post-process cycle to get to the answer I want. ktap (and DTrace and SystemTap) can execute arbitrary programs in kernel context, where it can filter and summarize using per-CPU buffers (eg, via kp_percpu_data()), and then emit an answer without making a trip to user-level to post-process data. It can also (more easily) let me build real time tools.

Ktap almost gets into 3.13

Posted Nov 13, 2013 20:35 UTC (Wed) by karim (subscriber, #114) [Link]

Hi Brendan (assuming this is Brendan Gregg),

Yes, it's been a pleasure watching the videos of some of those talks and I'm glad to see your "System Performance" title is finally out, I've been waiting for it for a while. Time to order a copy.

FWIW, I'm not saying perf is useless. Just that it doesn't do what I need. Then again, as I said, I'm not the typical user: I wrote LTT in the late '90s and maintained it for a few years. That doesn't necessarily make my opinion worth more than what others have to say, but I do have a fairly good handle on what such tools can be capable of and we're certainly not where we should be and my expectations, based on historical record, are fairly low.

License ?

Posted Nov 7, 2013 14:01 UTC (Thu) by meuh (guest, #22042) [Link] (4 responses)

I'm also concerned about the licensing.

The homepage states "License GPL v2" so does the README, "ktap is licensed under GPL v2".

But ktap source code is a derivative of Lua code, which is covered by a MIT license

* This file is part of ktap by Jovi Zhangwei.
*
* Copyright (C) 2012-2013 Jovi Zhangwei <jovi.zhangwei@gmail.com>.
*
* Copyright (C) 1994-2013 Lua.org, PUC-Rio.
* - The part of code in this file is copied from lua initially.
* - lua's MIT license is compatible with GPL.
*
* ktap is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.

The Lua origin of code portion was noted by user engla in comment Loops to article Ktap — yet another kernel tracer.

License ?

Posted Nov 7, 2013 15:05 UTC (Thu) by rahulsundaram (subscriber, #21946) [Link] (3 responses)

What exactly is your concern here?

License ?

Posted Nov 7, 2013 16:12 UTC (Thu) by meuh (guest, #22042) [Link] (2 responses)

Is it misleading to state GPLv2 license ? Would be MIT/GPLv2 more accurate ?

I've understand that MIT and GPLv2 are compatible licenses,
but does MIT license allows one to re-license code under a different one, even compatible ?

License ?

Posted Nov 7, 2013 16:16 UTC (Thu) by rahulsundaram (subscriber, #21946) [Link] (1 responses)

Yes, it does. It is a very permissive license and the combination is under GPLv2. That is accurate.

License ?

Posted Nov 15, 2013 20:18 UTC (Fri) by Wol (subscriber, #4433) [Link]

No MIT does NOT allow you to relicence code ... no licence will unless it explicitly says you can.

But you can mix MIT and GPL and the result can only be distributed under the GPL. If, however, the recipient strips out the GPL code, they can redistribute the MIT-licenced stuff under the MIT licence.

When you mix code under different licences, you can't change any of the licences, and you have to comply with all of them. The magic of the GPL lies in the fact that it is explicitly incompatible with any licence that restricts it. In order to be compatible with the GPL, any other licence must let you do everything the GPL lets you do. So, in complying with the GPL, you comply with all the compatible licences as a matter of course.

Cheers,
Wol

Review

Posted Nov 7, 2013 14:09 UTC (Thu) by meuh (guest, #22042) [Link]

The brief presence of ktap in staging and linux-next git tree give a chance for some developers to review the code.
I had myself a look to it and send some comments/patches on the list ktap@freelists.org (but had to subscribe in order to submit mail).

ktap 0.3

Posted Nov 7, 2013 14:15 UTC (Thu) by meuh (guest, #22042) [Link]

Ktap 0.3 was released in the end of October, see announcement on LWN.net, somewhere in Kernel development page of LWN.net Weekly Edition for October 31, 2013 ;).


Copyright © 2013, 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