From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 18 22:09:42 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0BFD91065670; Wed, 18 Apr 2012 22:09:42 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 6FE778FC14; Wed, 18 Apr 2012 22:09:41 +0000 (UTC) Received: by wern13 with SMTP id n13so6618111wer.13 for ; Wed, 18 Apr 2012 15:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=c9m62CQs56KDtUFmkBXJVPg4sPalzlc27HVR0Q4g2jk=; b=lubQ/mf/WmQgHywacGblX2GZzqwRHDyeYU58J8sBUT1hYNZevNy7Z2d0EsrSMc7vzV HDEhgvkkQREemrriWLzQriLTr0jEX72XfupCaAjqDAbw+CoL6gYNy+NUh+Aw/Dk1CZvh Fcwbgd6mYNTjkYYJ5aQEm7R1s+CwYN1Qpp2b+yb4st39kJnvAxjidrtDcKw46jRgPGig QPJRMXGX2dztNNUMonEjjwuJS43Yrz1lyB5c7Nf7ZoB1BezlpIXmVnShvSJJZIqVIUp2 35CjJyyc0Wa5hxpYOvOWyvGuhQuK8yIk0aAFnJ3pvqpF2vazL04ykNKL6eVSZuXyvNIq +07Q== MIME-Version: 1.0 Received: by 10.180.95.197 with SMTP id dm5mr20377508wib.20.1334786980662; Wed, 18 Apr 2012 15:09:40 -0700 (PDT) Received: by 10.180.85.71 with HTTP; Wed, 18 Apr 2012 15:09:40 -0700 (PDT) Date: Wed, 18 Apr 2012 18:09:40 -0400 Message-ID: From: Ryan Stone To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Cc: George Neville-Neil Subject: [PATCH] Implementation of DTrace sched provider (with bonus schedgraph script) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2012 22:09:42 -0000 I've implemented the sched provider for FreeBSD. This provider provides probes that fire when various scheduling decisions are made. This implementation is intended to be compatible with the implementation in Solaris and its derivatives, with the following caveats: Several probes reference features that are not implemented in FreeBSD. This probes are provided but will never fire. These probes are: cpucaps-sleep, cpucaps-wakeup, schedctl-nopreempt, schedctl-preempt and schedctl-yield. I've added some extra probes that do not exist in Solaris and its derivatives, to make it possible to implement a schedgraph DTrace script. These probes are lend-pri and load-change. Scripts intended to be portable to other implementations should not reference these probes. FreeBSD currently does not properly translate internal types to the portable implementation-independent types defined in the documentation. This means that your scripts will see a struct thread * where they should get a lwpsinfo_t *, for example. The patch implementing the sched provider can be found here: http://people.freebsd.org/~rstone/patches/sched_sdt.diff This patch is against r234420. It should apply cleanly to stable/9 as well as head, but it will not compile if applied against stable/8 because of a change in the arguments accepted by the SDT_PROBE_DEFINE* macros. My D script that collections schedgraph data can be found here: http://people.freebsd.org/~rstone/dtrace/schedgraph.d I recommend collecting data with the ring bufpolicy. This causes DTrace to collect data in per-cpu ring buffers which should guarantee that there is no dropped data points. The data is written to stdout when dtrace(1) exits. In my example I exit after running for 5 seconds, but you could just as easily modify the script to run until a certain probe fires and then exit, for example. The output of schedgraph.d isn't quite ready for processing by schedgraph. Here is a very short sh script that post-processes the data to make it parseable by schedgraph: http://people.freebsd.org/~rstone/dtrace/make_ktr Finally, schedgraph.d uses the cpu variable, which is currently not available in FreeBSD. Here is my patch (which I will commit to HEAD soon) that implements that variable. You will have to rebuild dtrace.ko and libdtrace.so. http://people.freebsd.org/~rstone/patches/dtrace_cpu.diff