From 26ee49b71f60793b3250b741890c8d5548ea3182 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Fri, 29 Aug 2025 08:39:06 -0700 Subject: [PATCH 1/3] [CAS] llvm-cas-test fillData in RunSafely Try fillData in RunSafely context to capture crash trace. --- llvm/tools/llvm-cas-test/llvm-cas-test.cpp | 60 ++++++++++++---------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/llvm/tools/llvm-cas-test/llvm-cas-test.cpp b/llvm/tools/llvm-cas-test/llvm-cas-test.cpp index 431e517829747..0c27730357abd 100644 --- a/llvm/tools/llvm-cas-test/llvm-cas-test.cpp +++ b/llvm/tools/llvm-cas-test/llvm-cas-test.cpp @@ -10,6 +10,7 @@ #include "llvm/CAS/BuiltinUnifiedCASDatabases.h" #include "llvm/CAS/ObjectStore.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" @@ -139,35 +140,39 @@ static void fillData(ObjectStore &CAS, ActionCache &AC, const Config &Conf) { DefaultThreadPool ThreadPool(hardware_concurrency()); for (size_t I = 0; I != Conf.NumShards; ++I) { ThreadPool.async([&] { - std::vector Refs; - for (unsigned Depth = 0; Depth < Conf.TreeDepth; ++Depth) { - unsigned NumNodes = (Conf.TreeDepth - Depth + 1) * Conf.NumChildren + 1; - std::vector Created; - Created.reserve(NumNodes); - ArrayRef PreviouslyCreated(Refs); - for (unsigned I = 0; I < NumNodes; ++I) { - std::vector Data(Conf.DataLength); - getRandomBytes(Data.data(), Data.size()); - // Use the first byte that generated to decide if we should make it - // 64KB bigger and force that into a file based storage. - if (Conf.extendToFile(Data[0])) - Data.resize(64LL * 1024LL + Conf.DataLength); - - if (Depth == 0) { - auto Ref = ExitOnErr(CAS.store({}, Data)); - Created.push_back(Ref); - } else { - auto Parent = PreviouslyCreated.slice(I, Conf.NumChildren); - auto Ref = ExitOnErr(CAS.store(Parent, Data)); - Created.push_back(Ref); + CrashRecoveryContext CRC; + CRC.RunSafely([&]() { + std::vector Refs; + for (unsigned Depth = 0; Depth < Conf.TreeDepth; ++Depth) { + unsigned NumNodes = + (Conf.TreeDepth - Depth + 1) * Conf.NumChildren + 1; + std::vector Created; + Created.reserve(NumNodes); + ArrayRef PreviouslyCreated(Refs); + for (unsigned I = 0; I < NumNodes; ++I) { + std::vector Data(Conf.DataLength); + getRandomBytes(Data.data(), Data.size()); + // Use the first byte that generated to decide if we should make it + // 64KB bigger and force that into a file based storage. + if (Conf.extendToFile(Data[0])) + Data.resize(64LL * 1024LL + Conf.DataLength); + + if (Depth == 0) { + auto Ref = ExitOnErr(CAS.store({}, Data)); + Created.push_back(Ref); + } else { + auto Parent = PreviouslyCreated.slice(I, Conf.NumChildren); + auto Ref = ExitOnErr(CAS.store(Parent, Data)); + Created.push_back(Ref); + } } + // Put a self mapping in action cache to avoid cache poisoning. + if (!Created.empty()) + ExitOnErr( + AC.put(CAS.getID(Created.back()), CAS.getID(Created.back()))); + Refs.swap(Created); } - // Put a self mapping in action cache to avoid cache poisoning. - if (!Created.empty()) - ExitOnErr( - AC.put(CAS.getID(Created.back()), CAS.getID(Created.back()))); - Refs.swap(Created); - } + }); }); } ThreadPool.wait(); @@ -181,7 +186,6 @@ static int genData() { auto DB = ExitOnErr(cas::createOnDiskUnifiedCASDatabases(CASPath)); fillData(*DB.first, *DB.second, Conf); - return 0; } From 9f0121f3e8a9635a53bc20d5d75c21324a8fe4d6 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Fri, 29 Aug 2025 09:18:22 -0700 Subject: [PATCH 2/3] [CAS] Allow stress test parameter to control global parameter --- llvm/tools/llvm-cas-test/llvm-cas-test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/tools/llvm-cas-test/llvm-cas-test.cpp b/llvm/tools/llvm-cas-test/llvm-cas-test.cpp index 0c27730357abd..b5ff59c8a32e8 100644 --- a/llvm/tools/llvm-cas-test/llvm-cas-test.cpp +++ b/llvm/tools/llvm-cas-test/llvm-cas-test.cpp @@ -90,11 +90,11 @@ struct Config { void constrainParameters() { // reduce the size of parameter if they are too big. - NumShards = NumShards % MaxShards; - NumChildren = NumChildren % MaxChildren; - TreeDepth = TreeDepth % MaxDepth; - DataLength = DataLength % MaxDataLength; - PrecentFile = PrecentFile % 100; + NumShards = OptNumShards ? OptNumShards : NumShards % MaxShards; + NumChildren = OptNumChildren ? OptNumChildren : NumChildren % MaxChildren; + TreeDepth = OptTreeDepth ? OptTreeDepth : TreeDepth % MaxDepth; + DataLength = OptDataLength ? OptDataLength : DataLength % MaxDataLength; + PrecentFile = OptPrecentFile ? OptPrecentFile : PrecentFile % 100; if (ForceKill) { Settings |= Fork; From 0c3c5b7a933d80cf5ccdeac7555bbfa9d3a55f5a Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Sun, 31 Aug 2025 11:21:49 -0700 Subject: [PATCH 3/3] [CAS] Fix llvm-cas-test to correctly respect file precentage The file precentage was reversed to the other way around. --- llvm/tools/llvm-cas-test/llvm-cas-test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/tools/llvm-cas-test/llvm-cas-test.cpp b/llvm/tools/llvm-cas-test/llvm-cas-test.cpp index b5ff59c8a32e8..b5d6fbd59516f 100644 --- a/llvm/tools/llvm-cas-test/llvm-cas-test.cpp +++ b/llvm/tools/llvm-cas-test/llvm-cas-test.cpp @@ -103,7 +103,7 @@ struct Config { } bool extendToFile(uint8_t Seed) const { - return ((float)Seed / (float)UINT8_MAX) > ((float)PrecentFile / 100.0f); + return ((float)Seed / (float)UINT8_MAX) < ((float)PrecentFile / 100.0f); } void init() {