Skip to content

Commit

Permalink
Address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Nov 3, 2023
1 parent 581faa6 commit e84a063
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 88 deletions.
1 change: 1 addition & 0 deletions include/lo2s/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct Config
// NEC SX-Aurora Tsubasa
bool use_nec;
std::chrono::microseconds nec_read_interval;
std::chrono::milliseconds nec_check_interval;
};

const Config& config();
Expand Down
2 changes: 1 addition & 1 deletion include/lo2s/monitor/main_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MainMonitor
std::unique_ptr<metric::sensors::Recorder> sensors_recorder_;
#endif
#ifdef HAVE_VEOSINFO
std::vector<std::unique_ptr<nec::NecMonitorMain>> nec_monitors_;
std::vector<std::unique_ptr<nec::NecMonitorMain>> nec_monitors_;
#endif
};
} // namespace monitor
Expand Down
12 changes: 6 additions & 6 deletions include/lo2s/monitor/nec_monitor_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

extern "C"
{
#include <veosinfo/veosinfo.h>
#include <veosinfo/veosinfo.h>

#include <libved.h>
}
Expand All @@ -40,7 +40,7 @@ namespace lo2s
{
namespace nec
{
class NecMonitorMain : public monitor::ThreadedMonitor
class NecMonitorMain : public monitor::ThreadedMonitor
{
public:
NecMonitorMain(trace::Trace& trace, NecDevice device);
Expand All @@ -57,13 +57,13 @@ namespace nec
void finalize_thread() override;

private:
std::optional<NecDevice> get_device_of(Thread thread);
std::vector<Thread> get_tasks_of(NecDevice device);
std::optional<NecDevice> get_device_of(Thread thread);
std::vector<Thread> get_tasks_of(NecDevice device);
std::map<Thread, NecThreadMonitor> monitors_;
trace::Trace& trace_;
NecDevice device_;
std::atomic<bool> stopped_;
std::atomic<bool> stopped_;
ve_nodeinfo nodeinfo_;
};
} // namespace monitor
} // namespace nec
} // namespace lo2s
6 changes: 3 additions & 3 deletions include/lo2s/monitor/nec_thread_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace lo2s
{
namespace nec
{
class NecThreadMonitor : public monitor::PollMonitor
class NecThreadMonitor : public monitor::PollMonitor
{
public:
NecThreadMonitor(Thread thread, trace::Trace& trace, NecDevice device);
Expand All @@ -47,12 +47,12 @@ namespace nec
void monitor(int fd) override;

private:
std::chrono::microseconds nec_read_interval_;
std::chrono::microseconds nec_read_interval_;
otf2::writer::local& otf2_writer_;
Thread nec_thread_;
trace::Trace& trace_;
NecDevice device_;
perf::CallingContextManager cctx_manager_;
};
} // namespace monitor
} // namespace nec
} // namespace lo2s
28 changes: 14 additions & 14 deletions include/lo2s/topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ class Topology
return cpus_;
}

const std::set<NecDevice> nec_devices() const
{
std::set<NecDevice> devices;

const std::regex nec_regex("/sys/class/ve/ve(\\d)");

for (auto& dir_entry : std::filesystem::directory_iterator("/sys/class/ve"))
const std::set<NecDevice> nec_devices() const
{
std::smatch nec_match;
std::set<NecDevice> devices;

const std::regex nec_regex("/sys/class/ve/ve(\\d)");

auto path = dir_entry.path().string();
if (std::regex_match(path, nec_match, nec_regex))
for (auto& dir_entry : std::filesystem::directory_iterator("/sys/class/ve"))
{
devices.emplace(NecDevice(std::stoi(nec_match[1])));
std::smatch nec_match;

auto path = dir_entry.path().string();
if (std::regex_match(path, nec_match, nec_regex))
{
devices.emplace(NecDevice(std::stoi(nec_match[1])));
}
}
}

return devices;
}
return devices;
}

Core core_of(Cpu cpu) const
{
Expand Down
13 changes: 7 additions & 6 deletions include/lo2s/trace/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ class Trace
return interrupt_generator_;
}

const otf2::definition::interrupt_generator nec_interrupt_generator() const
{
return nec_interrupt_generator_;
}
const otf2::definition::interrupt_generator nec_interrupt_generator() const
{
return nec_interrupt_generator_;
}

const otf2::definition::system_tree_node& system_tree_cpu_node(Cpu cpu) const
{
Expand Down Expand Up @@ -260,7 +260,7 @@ class Trace
}

const otf2::definition::location& location(const ExecutionScope& scope)
{
{
MeasurementScope sample_scope = MeasurementScope::sample(scope);

const auto& intern_location = registry_.emplace<otf2::definition::location>(
Expand Down Expand Up @@ -335,7 +335,8 @@ class Trace

otf2::definition::interrupt_generator& interrupt_generator_;

otf2::definition::detail::weak_ref<otf2::definition::interrupt_generator> nec_interrupt_generator_;
otf2::definition::detail::weak_ref<otf2::definition::interrupt_generator>
nec_interrupt_generator_;
// TODO add location groups (processes), read path from /proc/self/exe symlink

std::map<Thread, std::string> thread_names_;
Expand Down
21 changes: 11 additions & 10 deletions include/lo2s/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ class NecDevice
{
return lhs.id_ < rhs.id_;
}

private:
int id_;
int id_;
};

} // namespace lo2s
Expand Down Expand Up @@ -348,26 +349,26 @@ struct formatter<lo2s::Cpu>
}
};

template <>
struct formatter<lo2s::NecDevice>
{
template <>
struct formatter<lo2s::NecDevice>
{
constexpr auto parse(format_parse_context& ctx)
{
auto it = ctx.begin(), end = ctx.end();
if(it != end && *it != '}')
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it != '}')
{
throw format_error("invalid format");
throw format_error("invalid format");
}

return it;
return it;
}

template <typename FormatContext>
auto format(const lo2s::NecDevice& device, FormatContext& ctx) const
{
return fmt::format_to(ctx.out(), "VE {}", device.as_int());
return fmt::format_to(ctx.out(), "VE {}", device.as_int());
}
};
};
} // namespace fmt

namespace std
Expand Down
16 changes: 13 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,16 @@ void parse_program_options(int argc, const char** argv)
io_options.toggle("block-io",
"Enable recording of block I/O events (requires access to debugfs)");

nec_options.toggle("nec", "Enable NEC SX-Aurora Tsubasa sampling");
nec_options.option("nec-readout-interval", "NEC sampling interval in microseconds").optional().metavar("MSEC").default_value("1");
nec_options.toggle("nec", "Enable NEC Vector Engine sampling");
nec_options.option("nec-readout-interval", "NEC sampling interval")
.optional()
.metavar("USEC")
.default_value("1");
nec_options.option("nec-check-interval", "The interval between checks for new VE processes")
.optional()
.metavar("MSEC")
.default_value("100");

nitro::options::arguments arguments;
try
{
Expand Down Expand Up @@ -618,9 +626,11 @@ void parse_program_options(int argc, const char** argv)
std::chrono::milliseconds(arguments.as<std::uint64_t>("userspace-readout-interval"));

config.nec_read_interval =

std::chrono::microseconds(arguments.as<std::uint64_t>("nec-readout-interval"));

config.nec_check_interval =
std::chrono::milliseconds(arguments.as<std::uint64_t>("nec-check-interval"));

if (arguments.provided("perf-readout-interval"))
{
config.perf_read_interval =
Expand Down
16 changes: 8 additions & 8 deletions src/monitor/main_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ MainMonitor::MainMonitor() : trace_(), metrics_(trace_)

#ifdef HAVE_VEOSINFO

for(auto device : Topology::instance().nec_devices())
{
nec_monitors_.emplace_back(std::make_unique<nec::NecMonitorMain>(trace_, device ));
for (auto device : Topology::instance().nec_devices())
{
nec_monitors_.emplace_back(std::make_unique<nec::NecMonitorMain>(trace_, device));

nec_monitors_.back()->start();
nec_monitors_.back()->start();
}
#endif
}
Expand Down Expand Up @@ -178,10 +178,10 @@ MainMonitor::~MainMonitor()
}

#ifdef HAVE_VEOSINFO
for (auto& nec_monitor : nec_monitors_)
{
nec_monitor->stop();
}
for (auto& nec_monitor : nec_monitors_)
{
nec_monitor->stop();
}
#endif

// Notify trace, that we will end recording now. That means, get_time() of this call will be
Expand Down
35 changes: 17 additions & 18 deletions src/monitor/nec_monitor_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,57 @@ namespace lo2s
namespace nec
{

std::optional<NecDevice> NecMonitorMain::get_device_of(Thread thread)
std::optional<NecDevice> NecMonitorMain::get_device_of(Thread thread)
{
// /sys/class/ve/ve0 is not device 0, because that would make too much sense
// So look the device id up here

for (int i = 0; i < nodeinfo_.total_node_count; i++)
{
if (!ve_check_pid(nodeinfo_.nodeid[i], thread.as_pid_t()))
{
return NecDevice(nodeinfo_.nodeid[i]);
return NecDevice(nodeinfo_.nodeid[i]);
}
}
return std::optional<NecDevice>();
}

std::vector<Thread> NecMonitorMain::get_tasks_of(NecDevice device)
{
std::ifstream task_stream(fmt::format("/sys/class/ve/ve{}/task_id_all", device.as_int()));
std::ifstream task_stream(fmt::format("/sys/class/ve/ve{}/task_id_all", device.as_int()));

std::vector<Thread> threads;

while (true)
{
pid_t pid;
task_stream >> pid;
if(!task_stream)
{
if (!task_stream)
{
break;
}
}
threads.emplace_back(Thread(pid));
}

return threads;
}

NecMonitorMain::NecMonitorMain(trace::Trace& trace, NecDevice device)
: ThreadedMonitor(trace, fmt::format("{}", device)), trace_(trace), device_(device),
stopped_(false)
{
NecMonitorMain::NecMonitorMain(trace::Trace& trace, NecDevice device)
: ThreadedMonitor(trace, fmt::format("{}", device)), trace_(trace), device_(device), stopped_(false)
{
auto ret = ve_node_info(&nodeinfo_);
if (ret == -1)
{
Log::error() << "Failed to get Vector Engine node information!";
throw_errno();
}
}
}

void NecMonitorMain::run()
{
void NecMonitorMain::run()
{
while (!stopped_)
{
auto threads = get_tasks_of(device_);
auto threads = get_tasks_of(device_);
for (auto monitor = monitors_.begin(); monitor != monitors_.end();)
{
if (std::find(threads.begin(), threads.end(), monitor->first) == threads.end())
Expand Down Expand Up @@ -114,9 +113,9 @@ std::vector<Thread> NecMonitorMain::get_tasks_of(NecDevice device)
ret.first->second.start();
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(config().nec_check_interval);
}
}
}

void NecMonitorMain::stop()
{
Expand All @@ -131,5 +130,5 @@ void NecMonitorMain::finalize_thread()
monitor.second.stop();
}
}
} // namespace monitor
} // namespace nec
} // namespace lo2s
16 changes: 8 additions & 8 deletions src/monitor/nec_thread_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ namespace lo2s
namespace nec
{
NecThreadMonitor::NecThreadMonitor(Thread thread, trace::Trace& trace, NecDevice device)
: PollMonitor(trace, fmt::format("VE{} {}", device, thread.as_pid_t()), std::chrono::duration_cast<std::chrono::nanoseconds>(config().nec_read_interval)),
nec_read_interval_(config().nec_read_interval),
otf2_writer_(trace.nec_writer(device, thread)), nec_thread_(thread), trace_(trace),
device_(device), cctx_manager_(trace)
: PollMonitor(trace, fmt::format("VE{} {}", device, thread.as_pid_t()),
std::chrono::duration_cast<std::chrono::nanoseconds>(config().nec_read_interval)),
nec_read_interval_(config().nec_read_interval), otf2_writer_(trace.nec_writer(device, thread)),
nec_thread_(thread), trace_(trace), device_(device), cctx_manager_(trace)
{
cctx_manager_.thread_enter(nec_thread_.as_process(), thread);
otf2_writer_.write_calling_context_enter(lo2s::time::now(), cctx_manager_.current(), 2);
Expand All @@ -50,11 +50,11 @@ void NecThreadMonitor::monitor([[maybe_unused]] int fd)

auto ret = ve_get_regvals(device_.as_int(), nec_thread_.as_pid_t(), 1, reg, &val);

if(ret == -1)
{
if (ret == -1)
{
Log::error() << "Failed to the vector engine instruction counter value!";
throw_errno();
}
}

otf2::chrono::time_point tp = lo2s::time::now();
otf2_writer_.write_calling_context_sample(tp, cctx_manager_.sample_ref(val), 2,
Expand All @@ -70,5 +70,5 @@ void NecThreadMonitor::finalize_thread()

cctx_manager_.finalize(&otf2_writer_);
}
} // namespace monitor
} // namespace nec
} // namespace lo2s
Loading

0 comments on commit e84a063

Please sign in to comment.