[PATCH] D27685: [libFuzzer] Diff 9 - 2 - Properly use unsigned for workers, jobs and NumberOfCpuCores.
Marcos Pividori via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 12 13:43:18 PST 2016
mpividori created this revision.
mpividori added reviewers: kcc, zturner, amccarth.
mpividori added a subscriber: llvm-commits.
mpividori set the repository for this revision to rL LLVM.
According to amccarth's suggestions in: https://reviews.llvm.org/D27234?id=79657#inline-234115 , I modify `NumberOfCpuCores()` to return unsigned.
The number of cpus is used to define the number of workers in:
Flags.workers = std::min(NumberOfCpuCores() / 2, Flags.jobs);
So, I decided to update the `worker` and `jobs` flags to be defined as unsigned. These are not strictly necessary changes, I could have casted the result of the division to int, as :
Flags.workers = std::min(int(NumberOfCpuCores() / 2), Flags.jobs);
But I decided it would be better to avoid that and properly use unsigned for workers and jobs.
Repository:
rL LLVM
https://reviews.llvm.org/D27685
Files:
lib/Fuzzer/FuzzerDriver.cpp
lib/Fuzzer/FuzzerFlags.def
lib/Fuzzer/FuzzerUtil.cpp
lib/Fuzzer/FuzzerUtil.h
Index: lib/Fuzzer/FuzzerUtil.h
===================================================================
--- lib/Fuzzer/FuzzerUtil.h
+++ lib/Fuzzer/FuzzerUtil.h
@@ -38,7 +38,7 @@
std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC);
-int NumberOfCpuCores();
+unsigned NumberOfCpuCores();
bool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out);
Index: lib/Fuzzer/FuzzerUtil.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtil.cpp
+++ lib/Fuzzer/FuzzerUtil.cpp
@@ -195,7 +195,7 @@
Printf(FallbackFMT, PC);
}
-int NumberOfCpuCores() {
+unsigned NumberOfCpuCores() {
unsigned N = std::thread::hardware_concurrency();
if (!N) {
Printf("WARNING: std::thread::hardware_concurrency not well defined for "
Index: lib/Fuzzer/FuzzerFlags.def
===================================================================
--- lib/Fuzzer/FuzzerFlags.def
+++ lib/Fuzzer/FuzzerFlags.def
@@ -51,10 +51,10 @@
"Experimental. Use value profile to guide fuzzing.")
FUZZER_FLAG_INT(use_cmp, 1, "Use CMP traces to guide mutations")
FUZZER_FLAG_INT(shrink, 0, "Experimental. Try to shrink corpus elements.")
-FUZZER_FLAG_INT(jobs, 0, "Number of jobs to run. If jobs >= 1 we spawn"
+FUZZER_FLAG_UNSIGNED(jobs, 0, "Number of jobs to run. If jobs >= 1 we spawn"
" this number of jobs in separate worker processes"
" with stdout/stderr redirected to fuzz-JOB.log.")
-FUZZER_FLAG_INT(workers, 0,
+FUZZER_FLAG_UNSIGNED(workers, 0,
"Number of simultaneous worker processes to run the jobs."
" If zero, \"min(jobs,NumberOfCpuCores()/2)\" is used.")
FUZZER_FLAG_INT(reload, 1,
Index: lib/Fuzzer/FuzzerDriver.cpp
===================================================================
--- lib/Fuzzer/FuzzerDriver.cpp
+++ lib/Fuzzer/FuzzerDriver.cpp
@@ -200,10 +200,10 @@
}
}
-static void WorkerThread(const std::string &Cmd, std::atomic<int> *Counter,
- int NumJobs, std::atomic<bool> *HasErrors) {
+static void WorkerThread(const std::string &Cmd, std::atomic<unsigned> *Counter,
+ unsigned NumJobs, std::atomic<bool> *HasErrors) {
while (true) {
- int C = (*Counter)++;
+ unsigned C = (*Counter)++;
if (C >= NumJobs) break;
std::string Log = "fuzz-" + std::to_string(C) + ".log";
std::string ToRun = Cmd + " > " + Log + " 2>&1\n";
@@ -213,7 +213,7 @@
if (ExitCode != 0)
*HasErrors = true;
std::lock_guard<std::mutex> Lock(Mu);
- Printf("================== Job %d exited with exit code %d ============\n",
+ Printf("================== Job %u exited with exit code %d ============\n",
C, ExitCode);
fuzzer::CopyFileToErr(Log);
}
@@ -236,14 +236,14 @@
}
static int RunInMultipleProcesses(const std::vector<std::string> &Args,
- int NumWorkers, int NumJobs) {
- std::atomic<int> Counter(0);
+ unsigned NumWorkers, unsigned NumJobs) {
+ std::atomic<unsigned> Counter(0);
std::atomic<bool> HasErrors(false);
std::string Cmd = CloneArgsWithoutX(Args, "jobs", "workers");
std::vector<std::thread> V;
std::thread Pulse(PulseThread);
Pulse.detach();
- for (int i = 0; i < NumWorkers; i++)
+ for (unsigned i = 0; i < NumWorkers; i++)
V.push_back(std::thread(WorkerThread, Cmd, &Counter, NumJobs, &HasErrors));
for (auto &T : V)
T.join();
@@ -378,7 +378,7 @@
if (Flags.jobs > 0 && Flags.workers == 0) {
Flags.workers = std::min(NumberOfCpuCores() / 2, Flags.jobs);
if (Flags.workers > 1)
- Printf("Running %d workers\n", Flags.workers);
+ Printf("Running %u workers\n", Flags.workers);
}
if (Flags.workers > 0 && Flags.jobs > 0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27685.81132.patch
Type: text/x-patch
Size: 3828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161212/dc4cc6b6/attachment.bin>
More information about the llvm-commits
mailing list