Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#6426: Add schedule_stats tool #6442

Merged
merged 5 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ add_exported_library(drmemtrace_syscall_mix STATIC tools/syscall_mix.cpp)
add_exported_library(drmemtrace_view STATIC tools/view.cpp)
add_exported_library(drmemtrace_func_view STATIC tools/func_view.cpp)
add_exported_library(drmemtrace_invariant_checker STATIC tools/invariant_checker.cpp)
add_exported_library(drmemtrace_schedule_stats STATIC tools/schedule_stats.cpp)

target_link_libraries(drmemtrace_invariant_checker drdecode)

Expand Down Expand Up @@ -273,7 +274,8 @@ configure_DynamoRIO_standalone(drcachesim)
target_link_libraries(drcachesim drmemtrace_simulator drmemtrace_reuse_distance
drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts
drmemtrace_opcode_mix drmemtrace_syscall_mix drmemtrace_view drmemtrace_func_view
drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker)
drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker
drmemtrace_schedule_stats)
if (UNIX)
target_link_libraries(drcachesim dl)
endif ()
Expand Down Expand Up @@ -346,6 +348,7 @@ install_client_nonDR_header(drmemtrace tools/histogram_create.h)
install_client_nonDR_header(drmemtrace tools/reuse_time_create.h)
install_client_nonDR_header(drmemtrace tools/basic_counts_create.h)
install_client_nonDR_header(drmemtrace tools/opcode_mix_create.h)
install_client_nonDR_header(drmemtrace tools/schedule_stats_create.h)
install_client_nonDR_header(drmemtrace tools/syscall_mix_create.h)
install_client_nonDR_header(drmemtrace simulator/cache_simulator.h)
install_client_nonDR_header(drmemtrace simulator/cache_simulator_create.h)
Expand Down Expand Up @@ -573,6 +576,7 @@ restore_nonclient_flags(drmemtrace_func_view)
restore_nonclient_flags(drmemtrace_record_filter)
restore_nonclient_flags(drmemtrace_analyzer)
restore_nonclient_flags(drmemtrace_invariant_checker)
restore_nonclient_flags(drmemtrace_schedule_stats)

# We need to pass /EHsc and we pull in libcmtd into drcachesim from a dep lib.
# Thus we need to override the /MT with /MTd.
Expand Down Expand Up @@ -638,6 +642,7 @@ add_win32_flags(drmemtrace_func_view)
add_win32_flags(drmemtrace_record_filter)
add_win32_flags(drmemtrace_analyzer)
add_win32_flags(drmemtrace_invariant_checker)
add_win32_flags(drmemtrace_schedule_stats)
add_win32_flags(directory_iterator)
add_win32_flags(test_helpers)
if (WIN32 AND DEBUG)
Expand Down Expand Up @@ -809,7 +814,7 @@ if (BUILD_TESTS)
drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts
drmemtrace_opcode_mix drmemtrace_syscall_mix drmemtrace_view drmemtrace_func_view
drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker
drmemtrace_analyzer)
drmemtrace_schedule_stats drmemtrace_analyzer)
if (UNIX)
target_link_libraries(tool.drcachesim.core_sharded dl)
endif ()
Expand Down
4 changes: 4 additions & 0 deletions clients/drcachesim/analyzer_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "tools/invariant_checker.h"
#include "tools/invariant_checker_create.h"
#include "tools/opcode_mix_create.h"
#include "tools/schedule_stats_create.h"
#include "tools/syscall_mix_create.h"
#include "tools/reuse_distance_create.h"
#include "tools/reuse_time_create.h"
Expand Down Expand Up @@ -427,6 +428,9 @@ analyzer_multi_t::create_analysis_tool_from_options(const std::string &simulator
op_verbose.get_value());
} else if (simulator_type == INVARIANT_CHECKER) {
return create_invariant_checker();
} else if (simulator_type == SCHEDULE_STATS) {
return schedule_stats_tool_create(op_schedule_stats_print_every.get_value(),
op_verbose.get_value());
} else {
auto tool = create_external_tool(simulator_type);
if (tool == nullptr) {
Expand Down
9 changes: 8 additions & 1 deletion clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "options.h"

#include <cstdint>
#include <string>

#include "dr_api.h" // For IF_X86_ELSE.
Expand Down Expand Up @@ -460,7 +461,7 @@ droption_t<std::string>
"Specifies the types of simulators, separated by a colon (\":\").",
"Predefined types: " CPU_CACHE ", " MISS_ANALYZER ", " TLB
", " REUSE_DIST ", " REUSE_TIME ", " HISTOGRAM ", " BASIC_COUNTS
", or " INVARIANT_CHECKER
", " INVARIANT_CHECKER ", or " SCHEDULE_STATS
". The external types: name of a tool identified by a "
"name.drcachesim config file in the DR tools directory.");

Expand Down Expand Up @@ -854,5 +855,11 @@ droption_t<std::string>
"Path with stored as-traced schedule for replay.");
#endif

// Schedule_stats options.
droption_t<uint64_t>
op_schedule_stats_print_every(DROPTION_SCOPE_ALL, "schedule_stats_print_every", 5000,
"A letter is printed every N instrs",
"A letter is printed every N instrs or N waits");

} // namespace drmemtrace
} // namespace dynamorio
20 changes: 13 additions & 7 deletions clients/drcachesim/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
#ifndef _OPTIONS_H_
#define _OPTIONS_H_ 1

#define REPLACE_POLICY_NON_SPECIFIED ""
#define REPLACE_POLICY_LRU "LRU"
#define REPLACE_POLICY_LFU "LFU"
#define REPLACE_POLICY_FIFO "FIFO"
#define PREFETCH_POLICY_NEXTLINE "nextline"
#define PREFETCH_POLICY_NONE "none"
#define CPU_CACHE "cache"
// Tool names (for -simulator_type option).
#define MISS_ANALYZER "miss_analyzer"
#define TLB "TLB"
#define HISTOGRAM "histogram"
Expand All @@ -53,10 +47,21 @@
#define VIEW "view"
#define FUNC_VIEW "func_view"
#define INVARIANT_CHECKER "invariant_checker"
#define SCHEDULE_STATS "schedule_stats"

// Constants used by specific tools.
#define REPLACE_POLICY_NON_SPECIFIED ""
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
#define REPLACE_POLICY_LRU "LRU"
#define REPLACE_POLICY_LFU "LFU"
#define REPLACE_POLICY_FIFO "FIFO"
#define PREFETCH_POLICY_NEXTLINE "nextline"
#define PREFETCH_POLICY_NONE "none"
#define CPU_CACHE "cache"
#define CACHE_TYPE_INSTRUCTION "instruction"
#define CACHE_TYPE_DATA "data"
#define CACHE_TYPE_UNIFIED "unified"
#define CACHE_PARENT_MEMORY "memory"

// The expected pattern for a single_op_value is:
// function_name|function_id|arguments_num
// where function_name can contain spaces (for instance, C++ namespace prefix)
Expand Down Expand Up @@ -191,6 +196,7 @@ extern dynamorio::droption::droption_t<std::string> op_record_file;
extern dynamorio::droption::droption_t<std::string> op_replay_file;
extern dynamorio::droption::droption_t<std::string> op_cpu_schedule_file;
#endif
extern dynamorio::droption::droption_t<uint64_t> op_schedule_stats_print_every;

} // namespace drmemtrace
} // namespace dynamorio
Expand Down
76 changes: 76 additions & 0 deletions clients/drcachesim/tests/schedule_stats_nopreempt.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Schedule stats tool results:
Total counts:
4 cores
8 threads
638938 instructions
5 total context switches
0.0078255 CSPKI \(context switches per 1000 instructions\)
127788 instructions per context switch
5 voluntary context switches
0 direct context switches
100.00% voluntary switches
0.00% direct switches
161 system calls
2 maybe-blocking system calls
0 direct switch requests
0 waits
Core #0 counts:
. threads
*[0-9]* instructions
. total context switches
0.0[0-9.]* CSPKI \(context switches per 1000 instructions\)
*[0-9]* instructions per context switch
. voluntary context switches
0 direct context switches
100.00% voluntary switches
0.00% direct switches
*[0-9]* system calls
. maybe-blocking system calls
0 direct switch requests
0 waits
Core #1 counts:
2 threads
*[0-9]* instructions
. total context switches
0.0[0-9.]* CSPKI \(context switches per 1000 instructions\)
*[0-9]* instructions per context switch
. voluntary context switches
0 direct context switches
100.00% voluntary switches
0.00% direct switches
.. system calls
. maybe-blocking system calls
0 direct switch requests
0 waits
Core #2 counts:
2 threads
*[0-9]* instructions
1 total context switches
0.0[0-9.]* CSPKI \(context switches per 1000 instructions\)
*[0-9]* instructions per context switch
1 voluntary context switches
0 direct context switches
100.00% voluntary switches
0.00% direct switches
.. system calls
. maybe-blocking system calls
0 direct switch requests
0 waits
Core #3 counts:
2 threads
*[0-9]* instructions
1 total context switches
0.0[0-9.]* CSPKI \(context switches per 1000 instructions\)
*[0-9]* instructions per context switch
1 voluntary context switches
0 direct context switches
100.00% voluntary switches
0.00% direct switches
.. system calls
. maybe-blocking system calls
0 direct switch requests
0 waits
Core #0 schedule: [A-H,]*
Core #1 schedule: [A-H,]*
Core #2 schedule: [A-H,]*
Core #3 schedule: [A-H,]*
Loading
Loading