Skip to content

Commit

Permalink
feat(sampling): Remove support for systems that do not have use_clockid
Browse files Browse the repository at this point in the history
use_clockid is present since Linux 4.1 and allows for finer grained
control over the used perf clock.

All observed systems, like ZIH's Taurus and DKRZ' Levante, have support
for use_clockid, so we can safely remove this codepath.
  • Loading branch information
cvonelm committed Apr 27, 2023
1 parent 8f3ac68 commit 51a3fdb
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
compiler: [g++-9, g++-10, clang++-10, clang++-11, clang++-12]
build-type: [Debug, RelWithDebInfo]
hw_breakpoint: [ON, OFF]
perf_clockid: [ON, OFF]

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -42,7 +41,7 @@ jobs:
- name: Run CMake configure
env:
CXX: ${{ matrix.compiler }}
run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DUSE_HW_BREAKPOINT_COMPAT=${{ matrix.hw_breakpoint }} -DUSE_PERF_CLOCKID=${{ matrix.perf_clockid }}
run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DUSE_HW_BREAKPOINT_COMPAT=${{ matrix.hw_breakpoint }}}
- name: Build
run: make -j 2
- name: Create source tarball
Expand Down
17 changes: 5 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ endif()
CMAKE_DEPENDENT_OPTION(USE_RADARE "Enable Radare support." ON "Radare_FOUND" OFF)
option(USE_HW_BREAKPOINT_COMPAT "Time synchronization fallback for old kernels without hardware breakpoint support." OFF)
add_feature_info("USE_HW_BREAKPOINT_COMPAT" USE_HW_BREAKPOINT_COMPAT "Time synchronization fallback for old kernels without hardware breakpoint support.")
option(USE_PERF_CLOCKID "Enables specifying a custom reference clock for recorded events" ON)
add_feature_info("USE_PERF_CLOCKID" USE_PERF_CLOCKID "Enables specifying a custom reference clock for recorded events")
option(IWYU "Developer option for include what you use." OFF)
option(UML_LOOK "Generate graphs with an UML look" OFF)
add_feature_info("USE_RADARE" USE_RADARE "Use Radare to add instruction information to samples.")
Expand All @@ -128,6 +126,11 @@ add_feature_info("USE_LIBAUDIT" USE_LIBAUDIT "Use libaudit for syscall name reso
# system configuration checks
CHECK_INCLUDE_FILES(linux/hw_breakpoint.h HAVE_HW_BREAKPOINT_H)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_attr" clockid linux/perf_event.h HAVE_PERF_EVENT_ATTR_CLOCKID)

if(NOT HAVE_PERF_EVENT_ATTR_CLOCKID)
message(FATAL_ERROR "The system is not able to use custom reference clocks for perf events. Make sure that you are running on system that supports use_clockid with perf")
endif()

check_function_exists(clock_gettime CLOCK_GETTIME_FOUND)
if(NOT CLOCK_GETTIME_FOUND)
set(CMAKE_REQUIRED_LIBRARIES "rt")
Expand Down Expand Up @@ -328,16 +331,6 @@ else()
endif()
endif()

# extra feature for newer kernel version
if (USE_PERF_CLOCKID)
if(NOT HAVE_PERF_EVENT_ATTR_CLOCKID)
message(SEND_ERROR "The system is not able to use custom reference clocks for perf events. Consider deactivating USE_PERF_CLOCKID.")
endif()
else()
if (HAVE_PERF_EVENT_ATTR_CLOCKID)
message(WARNING "The system claims to support custom reference clocks for perf events. Consider activating USE_PERF_CLOCKID to enable the options -k,--clockid.")
endif()
endif()

configure_file(include/lo2s/build_config.hpp.in include/lo2s/build_config.hpp)

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ Combine that with the abundance of backports of particular features by different
In the effort to keep compatible with older kernels, several quirks have been added to `lo2s`:

1. The initial time synchronization between lo2s and the kernel-space perf is done with a hardware breakpoint. If your kernel doesn't support that, you can disable it using the CMake option `USE_HW_BREAKPOINT_COMPAT`.
2. The used clock source for the kernel-space time measurments can be changed, however if you kernel doesn't support that, you can disable it with the CMake option `USE_PERF_CLOCKID`.
3. If you get the following error message: `event 'ref-cycles' is not available as a metric leader!`, you can fallback to the bus-cycles metric as leader using `--metric-leader bus-cycles`.
2. If you get the following error message: `event 'ref-cycles' is not available as a metric leader!`, you can fallback to the bus-cycles metric as leader using `--metric-leader bus-cycles`.

# Working with traces

Expand Down
1 change: 0 additions & 1 deletion include/lo2s/build_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@

#cmakedefine USE_HW_BREAKPOINT_COMPAT

#cmakedefine USE_PERF_CLOCKID

#cmakedefine LO2S_COPYRIGHT_YEAR "@LO2S_COPYRIGHT_YEAR@"
5 changes: 1 addition & 4 deletions include/lo2s/perf/sample/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ class Reader : public EventReader<T>
<< ", enable_on_exec: " << enable_on_exec;

struct perf_event_attr perf_attr = common_perf_event_attrs();
#ifdef USE_PERF_CLOCKID

if (config().use_pebs)
{
perf_attr.use_clockid = 0;
}
#endif

perf_attr.exclude_kernel = config().exclude_kernel;
perf_attr.sample_period = config().sampling_period;
Expand Down Expand Up @@ -165,12 +164,10 @@ class Reader : public EventReader<T>
if (fd_ < 0)
{
Log::error() << "perf_event_open for sampling failed";
#ifdef USE_PERF_CLOCKID
if (perf_attr.use_clockid)
{
Log::error() << "maybe the specified clock is unavailable?";
}
#endif
throw_errno();
}
Log::debug() << "Using precise_ip level: " << perf_attr.precise_ip;
Expand Down
2 changes: 1 addition & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ void parse_program_options(int argc, const char** argv)
const auto& clock = lo2s::time::ClockProvider::get_clock_by_name(requested_clock_name);

lo2s::Log::debug() << "Using clock \'" << clock.name << "\'.";
#if defined(USE_PERF_CLOCKID) && !defined(USE_HW_BREAKPOINT_COMPAT)
#ifndef USE_HW_BREAKPOINT_COMPAT
config.use_clockid = true;
config.clockid = clock.id;
#else
Expand Down
4 changes: 2 additions & 2 deletions src/perf/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct perf_event_attr common_perf_event_attrs()
attr.size = sizeof(struct perf_event_attr);
attr.disabled = 1;

#if !defined(USE_HW_BREAKPOINT_COMPAT) && defined(USE_PERF_CLOCKID)
#ifndef USE_HW_BREAKPOINT_COMPAT
attr.use_clockid = config().use_clockid;
attr.clockid = config().clockid;
#endif
Expand Down Expand Up @@ -125,7 +125,7 @@ int perf_event_description_open(ExecutionScope scope, const EventDescription& de
// Needed when scaling multiplexed events, and recognize activation phases
perf_attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;

#if !defined(USE_HW_BREAKPOINT_COMPAT) && defined(USE_PERF_CLOCKID)
#ifndef USE_HW_BREAKPOINT_COMPAT
perf_attr.use_clockid = config().use_clockid;
perf_attr.clockid = config().clockid;
#endif
Expand Down

0 comments on commit 51a3fdb

Please sign in to comment.