Getting systemtap examples working with --bpf backend

William Cohen wcohen@redhat.com
Tue May 21 17:11:00 GMT 2019


On 5/20/19 3:52 PM, William Cohen wrote:
> On 5/16/19 9:41 AM, William Cohen wrote:
>> I noticed https://elinux.org/images/d/dc/Kernel-Analysis-Using-eBPF-Daniel-Thompson-Linaro.pdf mentioned on page 29 that many of the systemtap examples did not work with the bpf back end and led to frustration.  Today I took a quick survey of how badly the examples are broken by adding the following line to the beginning of the run_command function in check.exp trying:
>>
>>     set command [ string map {"stap " "stap --bpf "} $command ]
>>
>> Most of the examples fail.  There are a few that actually do appear to run are just doing things in probe begin or end handlers (with the exception of cachestat*) :
>>
>> PASS: systemtap.examples/general/ansi_colors run
>> PASS: systemtap.examples/general/ansi_colors2 run
>> PASS: systemtap.examples/general/helloworld run
>> PASS: systemtap.examples/memory/cachestat run
>> PASS: systemtap.examples/memory/cachestat_bpf run
>> PASS: systemtap.examples/memory/kmalloc-top run
>>
>> The non-bpf cachestat works because it just probes raw functions. Most examples fail because of various missing syscall.*/syscall_any probe points and gettimeofday_*() functions.  The time functions should be something easy to get working in bpf as there is already a nanosecond time function and its results could be scaled for microseconds, milliseconds, and seconds.
>>
>> -Will
>>
> 
> Hi,
> 
> The cachestat_bpf test has been folded into the cachestat test to minimize duplication.  The helloworld tests has been set to run with the bpf back end.  The kmalloc-top test is actually a perl script isn't running the generating code with the bpf backend.  The ansi_colors and ansi_colors2 compile and run but their output is not checked and it results do not have the proper color formatting like the regular systemtap version (due to not handling octal escapes, PR23559)
> 
> The systemtap example heavily leverage the systemtap tapsets.  Currently, the bpf has few tapsets.  Things like syscall.* probe points and gettimeofday_* functions are not available for systemtap bpf generation.  However, probably don't want to blindly duplicate all the tapsets in the tapsets/linux directory for tapsets/bpf.
> 
> There is already a bpf ktime_get_ns available.  If there was a time offset generated, then it should be possible to have gettimeofday_* functions for bpf, allowing some additional scripts to work. Alternatively, don't worry about the offset at the moment as most of the example are taking the difference between two gettimeofday_* function calls.
> 
> A number of examples are using multdimensional-arrays  this can also be implicit when using the @entry() operation. However, these examples are not going to work because of PR23478.  Examples such as hugepage_cow_delays fail in the folowing manner:
> 
> 
> attempting command stap --bpf -p4 hugepage_cow_delays.stp
> OUT semantic error: unhandled multi-dimensional array: identifier 'gettimeofday_us' at hugepage_cow_delays.stp:8:37
>         source:     <<< (gettimeofday_us() - @entry(gettimeofday_us()))
>                                                     ^
> 
> Pass 4: compilation failed.  [man error::pass4]
> child process exited abnormally
> RC 1
> 
> 
> -Will
> 

Hi,

Attached is a proposed tapset file for tapsets/bpf to provide gettimeofday_* function for scripts that are using the time of day.  It has a global variable for a time offset to convert the ktime_get_ns into gettimeofday_ns.  Expect that some type of probe begin would set that up, but don't have anything doing that yet. Any thoughts or comments about this?

-Will
-------------- next part --------------
// timestamp tapset -- gettimeofday variants
// Copyright (C) 2005-2009 Red Hat Inc.
// Copyright (C) 2006 Intel Corporation.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.

global __gtod_offset = 0 /* FIXME need to set appropriately on startup */

/**
 * sfunction gettimeofday_ns - Number of nanoseconds since UNIX epoch
 *
 * Description: This function returns the number of nanoseconds
 * since the UNIX epoch.
 */
function gettimeofday_ns:long ()
{ /* pure */ /* unprivileged */
  return (ktime_get_ns() + __gtod_offset)
}

/**
 * sfunction gettimeofday_us - Number of microseconds since UNIX epoch
 *
 * Description: This function returns the number of microseconds
 * since the UNIX epoch.
 */
function gettimeofday_us:long () {
  return gettimeofday_ns() / 1000;
}

/**
 * sfunction gettimeofday_ms - Number of milliseconds since UNIX epoch
 *
 * Description: This function returns the number of milliseconds
 * since the UNIX epoch.
 */
function gettimeofday_ms:long () {
  return gettimeofday_ns() / 1000000;
}

/**
 * sfunction gettimeofday_s - Number of seconds since UNIX epoch
 *
 * Description: This function returns the number of seconds since
 * the UNIX epoch.
 */
function gettimeofday_s:long () {
  return gettimeofday_ns() / 1000000000;
}


More information about the Systemtap mailing list