Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ckmalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonKnittel committed Nov 4, 2024
2 parents 8289acc + b205a07 commit 6b8e9a8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
5 changes: 0 additions & 5 deletions src/correctness_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ CorrectnessChecker::CorrectnessChecker(HeapFactory& heap_factory, bool verbose)
: MallocRunner(heap_factory, MallocRunnerOptions{ .verbose = verbose }),
heap_factory_(&heap_factory) {}

/* static */
bool CorrectnessChecker::IsFailedTestStatus(const absl::Status& status) {
return status.message().starts_with(kFailedTestPrefix);
}

/* static */
absl::Status CorrectnessChecker::Check(
TracefileReader& reader, HeapFactory& heap_factory, bool verbose,
Expand Down
2 changes: 0 additions & 2 deletions src/correctness_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class CorrectnessChecker : public MallocRunner<> {
public:
explicit CorrectnessChecker(HeapFactory& heap_factory, bool verbose);

static bool IsFailedTestStatus(const absl::Status& status);

static absl::Status Check(
TracefileReader& reader, HeapFactory& heap_factory, bool verbose = false,
const TracefileExecutorOptions& options = TracefileExecutorOptions());
Expand Down
29 changes: 20 additions & 9 deletions src/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,26 @@ absl::StatusOr<TraceResult> RunTrace(const std::string& tracefile,
heap_factory.Reset();

if (result.correct) {
DEFINE_OR_RETURN(double, mega_ops,
Perftest::TimeTrace(
reader, absl::GetFlag(FLAGS_perftest_iters), options));
DEFINE_OR_RETURN(
double, utilization,
Utiltest::MeasureUtilization(reader, heap_factory, options));

result.mega_ops = mega_ops;
result.utilization = utilization;
auto perf_util_result =
[&reader, &heap_factory,
&options]() -> absl::StatusOr<std::pair<double, double>> {
DEFINE_OR_RETURN(
double, mega_ops,
Perftest::TimeTrace(reader, absl::GetFlag(FLAGS_perftest_iters),
options));
DEFINE_OR_RETURN(
double, utilization,
Utiltest::MeasureUtilization(reader, heap_factory, options));

return std::make_pair(mega_ops, utilization);
}();
if (!perf_util_result.ok()) {
result.correct = false;
} else {
auto [mega_ops, utilization] = perf_util_result.value();
result.mega_ops = mega_ops;
result.utilization = utilization;
}
}

return result;
Expand Down
8 changes: 8 additions & 0 deletions src/malloc_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class MallocRunner {
HeapFactory& heap_factory,
const MallocRunnerOptions& options = MallocRunnerOptions());

static bool IsFailedTestStatus(const absl::Status& status);

virtual absl::Status PostAlloc(void* ptr, size_t size,
std::optional<size_t> alignment,
bool is_calloc) = 0;
Expand Down Expand Up @@ -74,6 +76,12 @@ MallocRunner<Config>::MallocRunner(HeapFactory& heap_factory,
const MallocRunnerOptions& options)
: heap_factory_(&heap_factory), options_(options) {}

/* static */
template <MallocRunnerConfig Config>
bool MallocRunner<Config>::IsFailedTestStatus(const absl::Status& status) {
return status.message().starts_with(kFailedTestPrefix);
}

template <MallocRunnerConfig Config>
absl::Status MallocRunner<Config>::InitializeHeap() {
if (heap_factory_ != nullptr) {
Expand Down
2 changes: 2 additions & 0 deletions src/tracefile_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,12 @@ absl::Status TracefileExecutor<Allocator>::ProcessorWorker(
void FlushOps(HashIdMap& id_map_container) {
for (const auto [id, ptr] : id_map) {
bool inserted = id_map_container.SetId(id, ptr);
(void) inserted;
assert(inserted);
}
for (uint64_t erased_id : erased_ids) {
size_t erased_elems = id_map_container.ClearId(erased_id);
(void) erased_elems;
assert(erased_elems == 1);
}
id_map.clear();
Expand Down
29 changes: 15 additions & 14 deletions src/utiltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ absl::Status Utiltest::PostAlloc(void* ptr, size_t size,
auto [it, inserted] = size_map_.insert({ ptr, size });
if (!inserted) {
return absl::InternalError(
absl::StrFormat("Allocated pointer %p of size %zu conflicts with "
absl::StrFormat("%s Allocated pointer %p of size %zu conflicts with "
"existing allocation %p of size %zu",
ptr, size, it->first, it->second));
kFailedTestPrefix, ptr, size, it->first, it->second));
}

return absl::OkStatus();
Expand All @@ -75,8 +75,9 @@ absl::Status Utiltest::PreRealloc(void* ptr, size_t size) {
absl::Status Utiltest::PostRealloc(void* new_ptr, void* old_ptr, size_t size) {
auto it = size_map_.find(old_ptr);
if (it == size_map_.end()) {
return absl::InternalError(absl::StrFormat(
"Reallocated memory %p not found in size map.", old_ptr));
return absl::InternalError(
absl::StrFormat("%s Reallocated memory %p not found in size map.",
kFailedTestPrefix, old_ptr));
}
const size_t old_size = RoundUp(it->second);

Expand All @@ -90,10 +91,10 @@ absl::Status Utiltest::PostRealloc(void* new_ptr, void* old_ptr, size_t size) {
if (new_ptr == old_ptr) {
auto result = size_map_.assign(new_ptr, size);
if (!result.has_value()) {
return absl::InternalError(
absl::StrFormat("Reassigning size of realloc-ed memory %p from %zu "
"to %zu failed, not found in map.",
new_ptr, old_size, size));
return absl::InternalError(absl::StrFormat(
"%s Reassigning size of realloc-ed memory %p from %zu "
"to %zu failed, not found in map.",
kFailedTestPrefix, new_ptr, old_size, size));
}
return absl::OkStatus();
}
Expand All @@ -108,10 +109,10 @@ absl::Status Utiltest::PostRealloc(void* new_ptr, void* old_ptr, size_t size) {

auto [new_it, inserted] = size_map_.insert({ new_ptr, size });
if (!inserted) {
return absl::InternalError(
absl::StrFormat("Reallocated pointer %p of size %zu conflicts with "
"existing allocation %p of size %zu",
new_ptr, size, new_it->first, new_it->second));
return absl::InternalError(absl::StrFormat(
"%s Reallocated pointer %p of size %zu conflicts with "
"existing allocation %p of size %zu",
kFailedTestPrefix, new_ptr, size, new_it->first, new_it->second));
}

return absl::OkStatus();
Expand All @@ -124,8 +125,8 @@ absl::Status Utiltest::PreRelease(void* ptr) {

auto it = size_map_.find(ptr);
if (it == size_map_.end()) {
return absl::InternalError(
absl::StrFormat("Freed memory %p not found in size map.", ptr));
return absl::InternalError(absl::StrFormat(
"%s Freed memory %p not found in size map.", kFailedTestPrefix, ptr));
}
const size_t old_size = RoundUp(it->second);

Expand Down

0 comments on commit 6b8e9a8

Please sign in to comment.