Skip to content

Commit 8e843ee

Browse files
[CAS] llvm-cas-test improvements (#11286)
Improve llvm-cas-test to fix some bugs and make it more stable in stress testing.
1 parent d7462d6 commit 8e843ee

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

llvm/tools/llvm-cas-test/llvm-cas-test.cpp

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/CAS/BuiltinUnifiedCASDatabases.h"
1111
#include "llvm/CAS/ObjectStore.h"
1212
#include "llvm/Support/CommandLine.h"
13+
#include "llvm/Support/CrashRecoveryContext.h"
1314
#include "llvm/Support/InitLLVM.h"
1415
#include "llvm/Support/Path.h"
1516
#include "llvm/Support/Program.h"
@@ -89,11 +90,11 @@ struct Config {
8990

9091
void constrainParameters() {
9192
// reduce the size of parameter if they are too big.
92-
NumShards = NumShards % MaxShards;
93-
NumChildren = NumChildren % MaxChildren;
94-
TreeDepth = TreeDepth % MaxDepth;
95-
DataLength = DataLength % MaxDataLength;
96-
PrecentFile = PrecentFile % 100;
93+
NumShards = OptNumShards ? OptNumShards : NumShards % MaxShards;
94+
NumChildren = OptNumChildren ? OptNumChildren : NumChildren % MaxChildren;
95+
TreeDepth = OptTreeDepth ? OptTreeDepth : TreeDepth % MaxDepth;
96+
DataLength = OptDataLength ? OptDataLength : DataLength % MaxDataLength;
97+
PrecentFile = OptPrecentFile ? OptPrecentFile : PrecentFile % 100;
9798

9899
if (ForceKill) {
99100
Settings |= Fork;
@@ -102,7 +103,7 @@ struct Config {
102103
}
103104

104105
bool extendToFile(uint8_t Seed) const {
105-
return ((float)Seed / (float)UINT8_MAX) > ((float)PrecentFile / 100.0f);
106+
return ((float)Seed / (float)UINT8_MAX) < ((float)PrecentFile / 100.0f);
106107
}
107108

108109
void init() {
@@ -139,35 +140,39 @@ static void fillData(ObjectStore &CAS, ActionCache &AC, const Config &Conf) {
139140
DefaultThreadPool ThreadPool(hardware_concurrency());
140141
for (size_t I = 0; I != Conf.NumShards; ++I) {
141142
ThreadPool.async([&] {
142-
std::vector<ObjectRef> Refs;
143-
for (unsigned Depth = 0; Depth < Conf.TreeDepth; ++Depth) {
144-
unsigned NumNodes = (Conf.TreeDepth - Depth + 1) * Conf.NumChildren + 1;
145-
std::vector<ObjectRef> Created;
146-
Created.reserve(NumNodes);
147-
ArrayRef<ObjectRef> PreviouslyCreated(Refs);
148-
for (unsigned I = 0; I < NumNodes; ++I) {
149-
std::vector<char> Data(Conf.DataLength);
150-
getRandomBytes(Data.data(), Data.size());
151-
// Use the first byte that generated to decide if we should make it
152-
// 64KB bigger and force that into a file based storage.
153-
if (Conf.extendToFile(Data[0]))
154-
Data.resize(64LL * 1024LL + Conf.DataLength);
155-
156-
if (Depth == 0) {
157-
auto Ref = ExitOnErr(CAS.store({}, Data));
158-
Created.push_back(Ref);
159-
} else {
160-
auto Parent = PreviouslyCreated.slice(I, Conf.NumChildren);
161-
auto Ref = ExitOnErr(CAS.store(Parent, Data));
162-
Created.push_back(Ref);
143+
CrashRecoveryContext CRC;
144+
CRC.RunSafely([&]() {
145+
std::vector<ObjectRef> Refs;
146+
for (unsigned Depth = 0; Depth < Conf.TreeDepth; ++Depth) {
147+
unsigned NumNodes =
148+
(Conf.TreeDepth - Depth + 1) * Conf.NumChildren + 1;
149+
std::vector<ObjectRef> Created;
150+
Created.reserve(NumNodes);
151+
ArrayRef<ObjectRef> PreviouslyCreated(Refs);
152+
for (unsigned I = 0; I < NumNodes; ++I) {
153+
std::vector<char> Data(Conf.DataLength);
154+
getRandomBytes(Data.data(), Data.size());
155+
// Use the first byte that generated to decide if we should make it
156+
// 64KB bigger and force that into a file based storage.
157+
if (Conf.extendToFile(Data[0]))
158+
Data.resize(64LL * 1024LL + Conf.DataLength);
159+
160+
if (Depth == 0) {
161+
auto Ref = ExitOnErr(CAS.store({}, Data));
162+
Created.push_back(Ref);
163+
} else {
164+
auto Parent = PreviouslyCreated.slice(I, Conf.NumChildren);
165+
auto Ref = ExitOnErr(CAS.store(Parent, Data));
166+
Created.push_back(Ref);
167+
}
163168
}
169+
// Put a self mapping in action cache to avoid cache poisoning.
170+
if (!Created.empty())
171+
ExitOnErr(
172+
AC.put(CAS.getID(Created.back()), CAS.getID(Created.back())));
173+
Refs.swap(Created);
164174
}
165-
// Put a self mapping in action cache to avoid cache poisoning.
166-
if (!Created.empty())
167-
ExitOnErr(
168-
AC.put(CAS.getID(Created.back()), CAS.getID(Created.back())));
169-
Refs.swap(Created);
170-
}
175+
});
171176
});
172177
}
173178
ThreadPool.wait();
@@ -181,7 +186,6 @@ static int genData() {
181186

182187
auto DB = ExitOnErr(cas::createOnDiskUnifiedCASDatabases(CASPath));
183188
fillData(*DB.first, *DB.second, Conf);
184-
185189
return 0;
186190
}
187191

0 commit comments

Comments
 (0)