Skip to content

Commit 4dfb878

Browse files
authored
i#6662 public traces: allow one missing virtual_address in v2p.textproto (#7174)
The textproto format does not have fields with value == 0. In some cases a trace can use virtual address 0x0, which would result in a missing virtual_address field in `v2p.textproto`. Previously we did not allow any missing fields in `v2p.textproto`, so this case needs to be handled. We do so relying on the fact that multiple missing virtual_address fields would try to map 0x0 multiple times, resulting in an error. We add the missing virtual_address case to the unit tests. Issue #6662
1 parent 7922cfa commit 4dfb878

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

clients/drcachesim/reader/v2p_reader.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ v2p_reader_t::create_v2p_info_from_file(std::istream &v2p_file, v2p_info_t &v2p_
8181
const std::string bytes_mapped_key = "bytes_mapped";
8282
const std::string virtual_address_key = "virtual_address";
8383
const std::string physical_address_key = "physical_address";
84-
// Assumes virtual_address 0 is not in the v2p file.
8584
addr_t virtual_address = 0;
8685
uint64_t value = 0;
8786
std::string error_str;
@@ -103,20 +102,19 @@ v2p_reader_t::create_v2p_info_from_file(std::istream &v2p_file, v2p_info_t &v2p_
103102

104103
found = line.find(physical_address_key);
105104
if (found != std::string::npos) {
106-
error_str = get_value_from_line(line, value);
107-
if (!error_str.empty())
108-
return error_str;
109-
addr_t physical_address = static_cast<addr_t>(value);
110-
if (virtual_address == 0) {
111-
error_ss << "ERROR: no corresponding " << virtual_address_key << " for "
112-
<< physical_address_key << " " << physical_address << ".";
113-
return error_ss.str();
114-
}
105+
// Two missing virtual_address fields in the textproto will hit this
106+
// condition, as virtual_address will be 0 for both.
107+
// We do allow one missing virtual_address in case the trace uses
108+
// virtual_address 0.
115109
if (v2p_info.v2p_map.count(virtual_address) > 0) {
116110
error_ss << "ERROR: " << virtual_address_key << " " << virtual_address
117111
<< " is already present in v2p_map.";
118112
return error_ss.str();
119113
}
114+
error_str = get_value_from_line(line, value);
115+
if (!error_str.empty())
116+
return error_str;
117+
addr_t physical_address = static_cast<addr_t>(value);
120118
v2p_info.v2p_map[virtual_address] = physical_address;
121119
}
122120
virtual_address = 0;

clients/drcachesim/reader/v2p_reader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
* }
4141
* In create_v2p_info_from_file() we rely on the fact that virtual_address and
4242
* physical_address are one after the other on two different lines.
43+
* The only exception is a single missing virtual_address field, which indicates
44+
* virtual_address = 0x0 ("no presence" == "0" in a textproto). This can happen if the
45+
* trace makes use of that virtual address.
4346
* The virtual-to-physical mapping along with the page size, page count, and number of
4447
* bytes mapped is stored in memory in a v2p_info_t object.
4548
*/

clients/drcachesim/tests/v2p_example.textproto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ address_mapping_group {
1111
virtual_address: 0x456
1212
physical_address: 0x4
1313
}
14+
address_mapping {
15+
# Missing virtual_address field on purpose (== virtual_address: 0x0)
16+
physical_address: 0x6
17+
}
1418
address_mapping {
1519
virtual_address: 0x789
1620
physical_address: 0x5

clients/drcachesim/tests/v2p_reader_unit_test.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ namespace drmemtrace {
4545
static void
4646
check_v2p_info(const v2p_info_t &v2p_info)
4747
{
48-
// Change the number of entries if v2p_map_example.textproto is updated.
48+
// Change NUM_ENTRIES if clients/drcachesim/tests/v2p_example.textproto is updated.
4949
// Must be equal to the number of "address_mapping {...}" blocks in the textproto.
50-
constexpr size_t NUM_ENTRIES = 3;
50+
constexpr size_t NUM_ENTRIES = 4;
5151
if (v2p_info.v2p_map.size() != NUM_ENTRIES) {
5252
std::cerr << "v2p_map incorrect number of entries. Expected " << NUM_ENTRIES
5353
<< " got " << v2p_info.v2p_map.size() << ".\n";
5454
exit(1);
5555
}
5656

57-
// Virtual and physical addresses must be aligned with v2p_example.textproto.
58-
const std::vector<addr_t> virtual_addresses = { 0x123, 0x456, 0x789 };
59-
const std::vector<addr_t> physical_addresses = { 0x3, 0x4, 0x5 };
57+
// Virtual and physical addresses must be aligned with
58+
// clients/drcachesim/tests/v2p_example.textproto.
59+
const std::vector<addr_t> virtual_addresses = { 0x123, 0x456, 0x0, 0x789 };
60+
const std::vector<addr_t> physical_addresses = { 0x3, 0x4, 0x6, 0x5 };
6061
for (int i = 0; i < virtual_addresses.size(); ++i) {
6162
auto key_val = v2p_info.v2p_map.find(virtual_addresses[i]);
6263
if (key_val != v2p_info.v2p_map.end()) {

0 commit comments

Comments
 (0)