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#6662 public traces, part 9: TLB simulator with v2p #6961

Merged
merged 55 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b1c1b2d
i#6662 public traces, part8: v2p textproto reader
edeiana Aug 21, 2024
a0d1e39
clang-format
edeiana Aug 21, 2024
9f6e9aa
Addressed PR feedback 1/2.
edeiana Aug 28, 2024
7494769
Merge remote-tracking branch 'origin/i6662-v2p-textproto-reader' into…
edeiana Aug 28, 2024
1c173af
Added page_size, page_count, bytes_mapped when parsing v2p.textproto.
edeiana Aug 30, 2024
ec28eda
Merge remote-tracking branch 'origin/i6662-v2p-textproto-reader' into…
edeiana Aug 30, 2024
1f61c75
Renaming gen_v2p_map to init_v2p_info_from_file.
edeiana Aug 31, 2024
6919828
Merge remote-tracking branch 'origin/i6662-v2p-textproto-reader' into…
edeiana Aug 31, 2024
26fc0a3
Now checking if path to v2p.textproto is empty.
edeiana Aug 31, 2024
4adf11d
Merge remote-tracking branch 'origin/i6662-v2p-textproto-reader' into…
edeiana Aug 31, 2024
a744f9e
Fix warning as error on windows build.
edeiana Aug 31, 2024
2e6f172
Merge remote-tracking branch 'origin/i6662-v2p-textproto-reader' into…
edeiana Aug 31, 2024
9a4011e
i#6662 public traces, part 9: TLB simulator with v2p
edeiana Aug 31, 2024
3975a61
Addressed PR feedback.
edeiana Sep 9, 2024
9a0babf
Added const to param in unit test.
edeiana Sep 9, 2024
60a21b0
Merge branch 'master' into i6662-v2p-textproto-reader
edeiana Sep 9, 2024
5f3555e
Ignoring textproto comments when parsing virtual-to-physical info.
edeiana Sep 9, 2024
b86ebe8
Improved comments.
edeiana Sep 9, 2024
c952ac5
Merge remote-tracking branch 'origin/i6662-v2p-textproto-reader' into…
edeiana Sep 9, 2024
4d651e7
Aligning use of v2p_reader_t with new interface name "create".
edeiana Sep 10, 2024
8d0598e
Merge branch 'master' into i6662-v2p-tlb-simulator
edeiana Sep 10, 2024
2eafca9
Adds v2p.textproto to an arm trace.
edeiana Sep 10, 2024
6b5ef98
Added TLB simulator test with v2p.textproto file.
edeiana Sep 11, 2024
8cbe339
Merge branch 'master' into i6662-v2p-tlb-simulator
edeiana Sep 11, 2024
e50eb6d
Renamed test.
edeiana Sep 11, 2024
1c6d385
Removed tab from v2p.textproto because cmake complains about it.
edeiana Sep 11, 2024
1531449
Adding src to test?
edeiana Sep 11, 2024
0a37dfd
Add templatex for v2p test.
edeiana Sep 11, 2024
303dbe4
basedir
edeiana Sep 11, 2024
97b5628
Fixed templatex for v2p tlb test.
edeiana Sep 11, 2024
91bc0ec
Addressing PR feedback.
edeiana Sep 13, 2024
72a2108
clang-format.
edeiana Sep 13, 2024
d1b3537
Expected output fixed.
edeiana Sep 13, 2024
fada9c2
Fixed bug: setting use_v2p_file to true.
edeiana Sep 15, 2024
f75ae32
Moving delete before error message to avoid leaks if ERRORMSG crashes.
edeiana Sep 15, 2024
7dcb6c8
Added tlb_simulator unit tests to check actual use of both virtual an…
edeiana Sep 15, 2024
66f482f
clang-format.
edeiana Sep 15, 2024
2210885
Only running tlb_simulator unit test for X64.
edeiana Sep 15, 2024
d11a444
Moved ifdef.
edeiana Sep 15, 2024
223bdef
Added -v2p_file to doc.
edeiana Sep 15, 2024
dca67f6
Now using istream.
edeiana Sep 17, 2024
d8444ae
Moved end to end test. It was running only on cross-compiled dr.
edeiana Sep 17, 2024
b587c2b
Added explicit path to v2p.textproto now that it's not in raw/ nor in…
edeiana Sep 17, 2024
01bbbd5
Fixed templatex.
edeiana Sep 17, 2024
0e8ddfd
Fix templatex 2.
edeiana Sep 17, 2024
1f0d66b
Attempting to fix , issue in templatex.
edeiana Sep 17, 2024
1a0fe46
Now using std::String instead of char* in drcachesim_unit_Tests.
edeiana Sep 17, 2024
fdc8c43
Enabling test only for X64.
edeiana Sep 17, 2024
6b3d0ec
Moved v2p_file to be a TLB knob.
edeiana Sep 17, 2024
ce2db1b
clang-format.
edeiana Sep 17, 2024
89298dd
Merge branch 'master' into i6662-v2p-tlb-simulator
edeiana Sep 17, 2024
1bfe33f
clang-format.
edeiana Sep 17, 2024
5c88793
Fix templatex.
edeiana Sep 18, 2024
513beb5
Merge branch 'master' into i6662-v2p-tlb-simulator
edeiana Sep 18, 2024
124cc87
Merge branch 'master' into i6662-v2p-tlb-simulator
edeiana Sep 18, 2024
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
2 changes: 1 addition & 1 deletion clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ if (BUILD_TESTS)

add_executable(tool.drcachesim.unit_tests tests/drcachesim_unit_tests.cpp
tests/cache_replacement_policy_unit_test.cpp tests/config_reader_unit_test.cpp
tests/v2p_reader_unit_test.cpp)
tests/v2p_reader_unit_test.cpp tests/tlb_simulator_unit_test.cpp)
target_link_libraries(tool.drcachesim.unit_tests drmemtrace_simulator
# Link test_helpers first, or else the zlib main takes over.
drmemtrace_static drmemtrace_analyzer test_helpers ${zlib_libs})
Expand Down
7 changes: 6 additions & 1 deletion clients/drcachesim/analyzer_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
* DAMAGE.
*/

#include "analysis_tool.h"
#include "analyzer.h"
#include "analyzer_multi.h"
#include "common/options.h"
#include "common/utils.h"
#include "common/directory_iterator.h"
#include "tlb_simulator.h"
#include "tracer/raw2trace_directory.h"
#include "tracer/raw2trace.h"
#include "reader/file_reader.h"
Expand Down Expand Up @@ -214,7 +216,10 @@ analyzer_multi_t::create_analysis_tool_from_options(const std::string &tool)
knobs.verbose = op_verbose.get_value();
knobs.cpu_scheduling = op_cpu_scheduling.get_value();
knobs.use_physical = op_use_physical.get_value();
return tlb_simulator_create(knobs);
std::string v2p_file_path =
get_aux_file_path(op_v2p_file.get_value(), DRMEMTRACE_V2P_FILENAME);
analysis_tool_t *tlb_simulator = tlb_simulator_create(knobs, v2p_file_path);
edeiana marked this conversation as resolved.
Show resolved Hide resolved
return tlb_simulator;
} else if (tool == HISTOGRAM) {
return histogram_tool_create(op_line_size.get_value(), op_report_top.get_value(),
op_verbose.get_value());
Expand Down
7 changes: 7 additions & 0 deletions clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ droption_t<unsigned int> op_virt2phys_freq(
"The units are the number of memory accesses per forced access. A value of 0 "
"uses the cached values for the entire application execution.");

droption_t<std::string> op_v2p_file(
DROPTION_SCOPE_FRONTEND, "v2p_file", "", "Path to v2p.textproto for simulator tools",
"Simulators like " CPU_CACHE ", " MISS_ANALYZER ", and " TLB
" can use v2p.textproto to translate virtual addresses to physical ones. "
"If the file is named v2p.textproto and is in the same directory as the trace file, "
"or a raw/ subdirectory below the trace file, this parameter can be omitted.");

droption_t<bool> op_cpu_scheduling(
DROPTION_SCOPE_CLIENT, "cpu_scheduling", false,
"Map threads to cores matching recorded cpu execution",
Expand Down
1 change: 1 addition & 0 deletions clients/drcachesim/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ extern dynamorio::droption::droption_t<bool> op_instr_only_trace;
extern dynamorio::droption::droption_t<bool> op_coherence;
extern dynamorio::droption::droption_t<bool> op_use_physical;
extern dynamorio::droption::droption_t<unsigned int> op_virt2phys_freq;
extern dynamorio::droption::droption_t<std::string> op_v2p_file;
extern dynamorio::droption::droption_t<bool> op_cpu_scheduling;
extern dynamorio::droption::droption_t<dynamorio::droption::bytesize_t> op_max_trace_size;
extern dynamorio::droption::droption_t<dynamorio::droption::bytesize_t>
Expand Down
7 changes: 7 additions & 0 deletions clients/drcachesim/common/trace_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,13 @@ typedef struct _pt_data_buf_t pt_data_buf_t;
*/
#define DRMEMTRACE_KALLSYMS_FILENAME "kallsyms"

/**
* The name of the file in -offline mode where virtual to physical information is stored.
* This file contains a mapping from virtual to physical addresses, the page size used,
* the number of pages, and the number of bytes mapped.
*/
#define DRMEMTRACE_V2P_FILENAME "v2p.textproto"

} // namespace drmemtrace
} // namespace dynamorio

Expand Down
20 changes: 4 additions & 16 deletions clients/drcachesim/reader/v2p_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
#include "v2p_reader.h"

#include <cstdint>
#include <sstream>
#include <stdint.h>

#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -76,19 +74,8 @@ v2p_reader_t::get_value_from_line(std::string line, uint64_t &value)
}

std::string
v2p_reader_t::create_v2p_info_from_file(std::string path_to_file, v2p_info_t &v2p_info)
v2p_reader_t::create_v2p_info_from_file(std::ifstream &v2p_file, v2p_info_t &v2p_info)
edeiana marked this conversation as resolved.
Show resolved Hide resolved
{
if (path_to_file.empty()) {
return "ERROR: Path to v2p.textproto is empty.";
}

std::stringstream error_ss;
std::ifstream file(path_to_file);
if (!file.is_open()) {
error_ss << "ERROR: Failed to open " << path_to_file << ".";
return error_ss.str();
}

const std::string page_size_key = "page_size";
const std::string page_count_key = "page_count";
const std::string bytes_mapped_key = "bytes_mapped";
Expand All @@ -98,8 +85,9 @@ v2p_reader_t::create_v2p_info_from_file(std::string path_to_file, v2p_info_t &v2
addr_t virtual_address = 0;
uint64_t value = 0;
std::string error_str;
std::stringstream error_ss;
std::string line;
while (std::getline(file, line)) {
while (std::getline(v2p_file, line)) {
// Ignore comments in v2p.textproto file.
if (starts_with(line, "#"))
continue;
Expand Down
3 changes: 2 additions & 1 deletion clients/drcachesim/reader/v2p_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "trace_entry.h"

#include <cstdint>
#include <fstream>
#include <string>
#include <unordered_map>

Expand All @@ -68,7 +69,7 @@ class v2p_reader_t {
v2p_reader_t() = default;

std::string
create_v2p_info_from_file(std::string path_to_file, v2p_info_t &v2p_info);
create_v2p_info_from_file(std::ifstream &v2p_file, v2p_info_t &v2p_info);

private:
std::string
Expand Down
25 changes: 25 additions & 0 deletions clients/drcachesim/simulator/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "options.h"
#include "utils.h"
#include "trace_entry.h"
#include "v2p_reader.h"

namespace dynamorio {
namespace drmemtrace {
Expand Down Expand Up @@ -87,6 +88,26 @@ simulator_t::init_knobs(unsigned int num_cores, uint64_t skip_refs, uint64_t war
}
}

std::string
simulator_t::create_v2p_from_file(std::ifstream &v2p_file)
{
// If we are not using physical addresses, we don't need a virtual to physical mapping
// at all.
if (!knob_use_physical_)
return "";

v2p_reader_t v2p_reader;
v2p_info_t v2p_info;
std::string error_str = v2p_reader.create_v2p_info_from_file(v2p_file, v2p_info);
if (!error_str.empty()) {
return error_str;
}
virt2phys_ = v2p_info.v2p_map;
page_size_ = static_cast<size_t>(v2p_info.page_size);
use_v2p_file_ = true;
return "";
}

std::string
simulator_t::initialize_stream(memtrace_stream_t *serial_stream)
{
Expand Down Expand Up @@ -138,6 +159,10 @@ simulator_t::process_memref(const memref_t &memref)
}
if (!knob_use_physical_)
return true;
// If we already have a virtual to physical mapping in a v2p file use that one and
// ignore the one in the trace, if any.
edeiana marked this conversation as resolved.
Show resolved Hide resolved
if (use_v2p_file_)
return true;
if (memref.marker.marker_type == TRACE_MARKER_TYPE_PAGE_SIZE) {
if (page_size_ != 0 && page_size_ != memref.marker.marker_value) {
ERRMSG("Error: conflicting page size markers");
Expand Down
11 changes: 11 additions & 0 deletions clients/drcachesim/simulator/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <stddef.h>
#include <stdint.h>

#include <fstream>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -71,24 +72,32 @@ class simulator_t : public analysis_tool_t {
bool
process_memref(const memref_t &memref) override;

virtual std::string
create_v2p_from_file(std::ifstream &v2p_file);

protected:
// Initialize knobs. Success or failure is indicated by setting/resetting
// the success variable.
void
init_knobs(unsigned int num_cores, uint64_t skip_refs, uint64_t warmup_refs,
double warmup_fraction, uint64_t sim_refs, bool cpu_scheduling,
bool use_physical, unsigned int verbose);

void
print_core(int core) const;

int
find_emptiest_core(std::vector<int> &counts) const;

virtual int
core_for_thread(memref_tid_t tid);

virtual void
handle_thread_exit(memref_tid_t tid);

addr_t
virt2phys(addr_t virt) const;

memref_t
memref2phys(memref_t memref) const;

Expand Down Expand Up @@ -133,6 +142,8 @@ class simulator_t : public analysis_tool_t {
size_t page_size_ = 0;
std::unordered_map<addr_t, addr_t> virt2phys_;
addr_t prior_phys_addr_ = 0;
// Indicates whether the simulator uses a v2p file for virtual to physical mapping.
bool use_v2p_file_ = false;
};

} // namespace drmemtrace
Expand Down
43 changes: 41 additions & 2 deletions clients/drcachesim/simulator/tlb_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <stddef.h>

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
Expand All @@ -53,9 +54,30 @@ namespace dynamorio {
namespace drmemtrace {

analysis_tool_t *
tlb_simulator_create(const tlb_simulator_knobs_t &knobs)
tlb_simulator_create(const tlb_simulator_knobs_t &knobs,
const std::string &v2p_file_path = "")
{
return new tlb_simulator_t(knobs);
if (v2p_file_path.empty())
return new tlb_simulator_t(knobs);

std::ifstream fin;
fin.open(v2p_file_path);
if (!fin.is_open()) {
ERRMSG("Failed to open the v2p file '%s'\n", v2p_file_path.c_str());
return nullptr;
}

tlb_simulator_t *sim = new tlb_simulator_t(knobs);
std::string error_str = sim->create_v2p_from_file(fin);
fin.close();

if (!error_str.empty()) {
delete sim;
ERRMSG("ERROR: v2p_reader failed with: %s\n", error_str.c_str());
return nullptr;
}

return sim;
}

tlb_simulator_t::tlb_simulator_t(const tlb_simulator_knobs_t &knobs)
Expand Down Expand Up @@ -132,6 +154,23 @@ tlb_simulator_t::~tlb_simulator_t()
delete[] lltlbs_;
}

std::string
tlb_simulator_t::create_v2p_from_file(std::ifstream &v2p_file)
{
// If we are not using physical addresses, we don't need a virtual to physical mapping
// at all.
if (!knobs_.use_physical)
return "";

std::string error_str = simulator_t::create_v2p_from_file(v2p_file);
if (!error_str.empty()) {
return error_str;
}
// Overwrite tlb_simulator_t page size with simulator_t page size.
knobs_.page_size = page_size_;
edeiana marked this conversation as resolved.
Show resolved Hide resolved
return "";
}

bool
tlb_simulator_t::process_memref(const memref_t &memref)
{
Expand Down
2 changes: 2 additions & 0 deletions clients/drcachesim/simulator/tlb_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class tlb_simulator_t : public simulator_t {
process_memref(const memref_t &memref) override;
bool
print_results() override;
std::string
create_v2p_from_file(std::ifstream &v2p_file) override;

protected:
// Create a tlb_t object with a specific replacement policy.
Expand Down
3 changes: 2 additions & 1 deletion clients/drcachesim/simulator/tlb_simulator_create.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ struct tlb_simulator_knobs_t {

/** Creates an instance of a TLB simulator. */
analysis_tool_t *
tlb_simulator_create(const tlb_simulator_knobs_t &knobs);
tlb_simulator_create(const tlb_simulator_knobs_t &knobs,
const std::string &v2p_file_path);

} // namespace drmemtrace
} // namespace dynamorio
Expand Down
2 changes: 2 additions & 0 deletions clients/drcachesim/tests/drcachesim_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <assert.h>
#include "config_reader_unit_test.h"
#include "v2p_reader_unit_test.h"
#include "tlb_simulator_unit_test.h"
#include "cache_replacement_policy_unit_test.h"
#include "simulator/cache.h"
#include "simulator/cache_lru.h"
Expand Down Expand Up @@ -844,6 +845,7 @@ test_main(int argc, const char *argv[])
unit_test_cache_accessors();
unit_test_config_reader(argv[1]);
unit_test_v2p_reader(argv[1]);
unit_test_tlb_simulator(argv[1]);
unit_test_cache_associativity();
unit_test_cache_size();
unit_test_cache_line_size();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# VirtualToPhysical
# Instance name: vm00_threadsig
# Generated: 2024-09-10T13:31:45.379962795-07:00
address_mapping_group {
page_size: 2097152
address_mapping {
virtual_address: 281464337858560
physical_address: 10485760
}
address_mapping {
virtual_address: 281464329469952
physical_address: 8388608
}
address_mapping {
virtual_address: 281464346247168
physical_address: 12582912
}
address_mapping {
virtual_address: 281474899116032
physical_address: 18874368
}
address_mapping {
virtual_address: 281464321081344
physical_address: 6291456
}
address_mapping {
virtual_address: 281464350441472
physical_address: 14680064
}
address_mapping {
virtual_address: 1895825408
physical_address: 4194304
}
address_mapping {
virtual_address: 4194304
physical_address: 2097152
}
address_mapping {
virtual_address: 281472940376064
physical_address: 16777216
}
information {
page_count: 9
bytes_mapped: 18874368
}
}
information {
page_count: 9
bytes_mapped: 18874368
}
Loading
Loading