Skip to content

Commit

Permalink
feat(sampling) Remove tracepoints based process switch recording support
Browse files Browse the repository at this point in the history
This PR removes support for process switch recording based on
tracepoints.

lo2s now requires support for PERF_RECORD_SWITCH, which was added in the
4.3 kernel and is widely backported to older systems. Neither Taurus nor
the Levante installation at DKRZ lack PERF_RECORD_SWITCH support.
  • Loading branch information
cvonelm committed Apr 27, 2023
1 parent 39f643a commit 8f3ac68
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 227 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_record_switch: [ON, OFF]
perf_clockid: [ON, OFF]

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -43,7 +42,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 }} -DUSE_PERF_RECORD_SWITCH=${{ matrix.perf_record_switch }}
run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DUSE_HW_BREAKPOINT_COMPAT=${{ matrix.hw_breakpoint }} -DUSE_PERF_CLOCKID=${{ matrix.perf_clockid }}
- name: Build
run: make -j 2
- name: Create source tarball
Expand Down
14 changes: 6 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,12 @@ if(PkgConfig_FOUND)
endif()


CHECK_STRUCT_HAS_BITFIELD("struct perf_event_attr" context_switch linux/perf_event.h HAVE_PERF_RECORD_SWITCH)

# configurable options
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")
CMAKE_DEPENDENT_OPTION(USE_PERF_RECORD_SWITCH "Uses PERF_RECORD_SWITCH for CPU Context Switches instead of the older tracepoint based solution" ON HAVE_PERF_RECORD_SWITCH OFF)
add_feature_info("USE_PERF_RECORD_SWITCH" USE_PERF_RECORD_SWITCH "Uses PERF_RECORD_SWITCH for CPU Context Switches instead of the older tracepoint based solution")
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 @@ -139,6 +135,12 @@ if(NOT CLOCK_GETTIME_FOUND)
unset(CMAKE_REQUIRED_LIBRARIES)
endif()

CHECK_STRUCT_HAS_BITFIELD("struct perf_event_attr" context_switch linux/perf_event.h HAVE_PERF_RECORD_SWITCH)

if(NOT HAVE_PERF_RECORD_SWITCH)
message(FATAL_ERROR "lo2s requires support for perf context switch recording. Make sure that you are running on a kernel that support context_switch with perf_event_open")
endif()

# detect version of running kernel
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LINUX_VERSION ${CMAKE_SYSTEM_VERSION})

Expand Down Expand Up @@ -337,10 +339,6 @@ else()
endif()
endif()

if(NOT USE_PERF_RECORD_SWITCH)
target_sources(lo2s PRIVATE src/perf/tracepoint/switch_writer.cpp)
endif()

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

# define include directory of target lo2s
Expand Down
2 changes: 0 additions & 2 deletions include/lo2s/build_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@

#cmakedefine USE_PERF_CLOCKID

#cmakedefine USE_PERF_RECORD_SWITCH

#cmakedefine LO2S_COPYRIGHT_YEAR "@LO2S_COPYRIGHT_YEAR@"
7 changes: 0 additions & 7 deletions include/lo2s/monitor/scope_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
#include <lo2s/perf/sample/writer.hpp>
#include <lo2s/perf/syscall/writer.hpp>

#ifndef USE_PERF_RECORD_SWITCH
#include <lo2s/perf/tracepoint/switch_writer.hpp>
#endif

#include <array>
#include <chrono>
#include <thread>
Expand Down Expand Up @@ -78,9 +74,6 @@ class ScopeMonitor : public PollMonitor
std::unique_ptr<perf::sample::Writer> sample_writer_;
std::unique_ptr<perf::counter::group::Writer> group_counter_writer_;
std::unique_ptr<perf::counter::userspace::Writer> userspace_counter_writer_;
#ifndef USE_PERF_RECORD_SWITCH
std::unique_ptr<perf::tracepoint::SwitchWriter> switch_writer_;
#endif
};
} // namespace monitor
} // namespace lo2s
2 changes: 0 additions & 2 deletions include/lo2s/perf/event_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,12 @@ class EventReader
case PERF_RECORD_MMAP2:
stop = crtp_this->handle((const RecordMmap2Type*)event_header_p);
break;
#ifdef USE_PERF_RECORD_SWITCH
case PERF_RECORD_SWITCH:
stop = crtp_this->handle((const RecordSwitchType*)event_header_p);
break;
case PERF_RECORD_SWITCH_CPU_WIDE:
stop = crtp_this->handle((const RecordSwitchCpuWideType*)event_header_p);
break;
#endif
case PERF_RECORD_THROTTLE: /* fall-through */
case PERF_RECORD_UNTHROTTLE:
throttle_samples++;
Expand Down
4 changes: 1 addition & 3 deletions include/lo2s/perf/sample/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ class Reader : public EventReader<T>
// name of a task. This is used to write a meaningful name for any
// traced thread to the archive.
perf_attr.comm = 1;

#ifdef USE_PERF_RECORD_SWITCH
perf_attr.context_switch = 1;
#endif

// We need this to get all mmap_events
if (enable_on_exec)
{
Expand Down
2 changes: 0 additions & 2 deletions include/lo2s/perf/sample/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ class Writer : public Reader<Writer>
bool handle(const Reader::RecordSampleType* sample);
bool handle(const Reader::RecordMmapType* mmap_event);
bool handle(const Reader::RecordCommType* comm);
#ifdef USE_PERF_RECORD_SWITCH
bool handle(const Reader::RecordSwitchCpuWideType* context_switch);
bool handle(const Reader::RecordSwitchType* context_switch);
#endif

void end();

Expand Down
73 changes: 0 additions & 73 deletions include/lo2s/perf/tracepoint/switch_writer.hpp

This file was deleted.

18 changes: 0 additions & 18 deletions src/monitor/scope_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ namespace monitor
ScopeMonitor::ScopeMonitor(ExecutionScope scope, MainMonitor& parent, bool enable_on_exec)
: PollMonitor(parent.trace(), scope.name(), config().perf_read_interval), scope_(scope)
{
#ifndef USE_PERF_RECORD_SWITCH
if (config().sampling)
#else
if (config().sampling || scope.is_cpu())
#endif
{
sample_writer_ =
std::make_unique<perf::sample::Writer>(scope, parent, parent.trace(), enable_on_exec);
Expand All @@ -76,14 +72,6 @@ ScopeMonitor::ScopeMonitor(ExecutionScope scope, MainMonitor& parent, bool enabl
add_fd(userspace_counter_writer_->fd());
}

#ifndef USE_PERF_RECORD_SWITCH
if (scope.is_cpu())
{
switch_writer_ =
std::make_unique<perf::tracepoint::SwitchWriter>(scope.as_cpu(), parent.trace());
}
#endif

// note: start() can now be called
}

Expand Down Expand Up @@ -128,12 +116,6 @@ void ScopeMonitor::monitor(int fd)
{
userspace_counter_writer_->read();
}
#ifndef USE_PERF_RECORD_SWITCH
if (switch_writer_ && (fd == timer_pfd().fd || fd == stop_pfd().fd))
{
switch_writer_->read();
}
#endif
}
} // namespace monitor
} // namespace lo2s
2 changes: 0 additions & 2 deletions src/perf/sample/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ otf2::chrono::time_point Writer::adjust_timepoints(otf2::chrono::time_point tp)
return tp;
}

#ifdef USE_PERF_RECORD_SWITCH
bool Writer::handle(const Reader::RecordSwitchCpuWideType* context_switch)
{
assert(scope_.is_cpu());
Expand Down Expand Up @@ -210,7 +209,6 @@ void Writer::update_calling_context(Process process, Thread thread, otf2::chrono
}
}

#endif
bool Writer::handle(const Reader::RecordCommType* comm)
{
if (!scope_.is_cpu())
Expand Down
108 changes: 0 additions & 108 deletions src/perf/tracepoint/switch_writer.cpp

This file was deleted.

0 comments on commit 8f3ac68

Please sign in to comment.