-
Notifications
You must be signed in to change notification settings - Fork 14
Some Multiprocessing Added #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MrMatch246
wants to merge
4
commits into
fuzzware-fuzzer:main
Choose a base branch
from
MrMatch246:multi_proc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fae6a73
Added Multiprocessing for do_genstats
MrMatch246 d40102f
Added Multiprocessing for missing main dir trace generation
MrMatch246 c7d1744
Merge branch 'fuzzware-fuzzer:main' into multi_proc
MrMatch246 ad1502c
Merge branch 'fuzzware-fuzzer:main' into multi_proc
MrMatch246 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import time | ||
import uuid | ||
from pathlib import Path | ||
|
||
import multiprocessing as mp | ||
import rq | ||
from fuzzware_pipeline.logging_handler import logging_handler | ||
from rq.worker import WorkerStatus | ||
|
@@ -16,14 +16,14 @@ | |
from ..util.config import load_extra_args, parse_extra_args | ||
|
||
logger = logging_handler().get_logger("tracegen") | ||
|
||
MULTI = True | ||
FORKSRV_FD = 198 | ||
|
||
# Make sure these names are synchronized with the argument names below | ||
ARGNAME_BBL_SET_PATH, ARGNAME_MMIO_SET_PATH = "bbl_set_path", "mmio_set_path" | ||
ARGNAME_EXTRA_ARGS = "extra_args" | ||
FORKSERVER_UNSUPPORTED_TRACE_ARGS = ("mmio_trace_path", "bbl_trace_path", "ram_trace_path") | ||
def gen_traces(config_path, input_path, bbl_trace_path=None, ram_trace_path=None, mmio_trace_path=None, bbl_set_path=None, mmio_set_path=None, extra_args=None, silent=False, bbl_hash_path=None): | ||
def gen_traces(config_path, input_path, bbl_trace_path=None, ram_trace_path=None, mmio_trace_path=None, bbl_set_path=None, mmio_set_path=None, extra_args=None, silent=False, bbl_hash_path=None,queue=None): | ||
extra_args = list(extra_args) if extra_args else [] | ||
|
||
if bbl_trace_path is not None: | ||
|
@@ -40,6 +40,7 @@ def gen_traces(config_path, input_path, bbl_trace_path=None, ram_trace_path=None | |
extra_args += ["--bb-hash-out", bbl_hash_path] | ||
|
||
run_target(config_path, input_path, extra_args, silent=silent, stdout=subprocess.DEVNULL if silent else None, stderr=subprocess.DEVNULL if silent else None) | ||
queue.put(1) | ||
return True | ||
|
||
def batch_gen_native_traces(config_path, input_paths, extra_args=None, bbl_set_paths=None, mmio_set_paths=None, bbl_hash_paths=None, silent=False): | ||
|
@@ -67,6 +68,11 @@ def batch_gen_native_traces(config_path, input_paths, extra_args=None, bbl_set_p | |
|
||
gentrace_proc.destroy() | ||
|
||
def multi_proc_manager(function=None,arg_tuple_list=[]): | ||
with mp.Pool() as p: | ||
p.starmap(function, arg_tuple_list) | ||
|
||
|
||
def gen_missing_maindir_traces(maindir, required_trace_prefixes, fuzzer_nums=None, tracedir_postfix="", log_progress=False, verbose=False, crashing_inputs=False): | ||
projdir = nc.project_base(maindir) | ||
config_path = nc.config_file_for_main_path(maindir) | ||
|
@@ -143,21 +149,27 @@ def gen_missing_maindir_traces(maindir, required_trace_prefixes, fuzzer_nums=Non | |
if log_progress: | ||
logger.info(f"Generating traces took {time.time() - start_time:.02f} seconds for {len(input_paths)} input(s)") | ||
else: | ||
m = mp.Manager() | ||
processed_queue=m.Queue() | ||
num_processed = 0 | ||
job_args_multi = [] | ||
iteration = 0 | ||
for input_path, bbl_trace_path, ram_trace_path, mmio_trace_path, bbl_set_path, mmio_set_path, bbl_hash_path in jobs_for_config: | ||
gen_traces(str(config_path), str(input_path), | ||
bbl_trace_path=bbl_trace_path, ram_trace_path=ram_trace_path, mmio_trace_path=mmio_trace_path, | ||
bbl_set_path=bbl_set_path, mmio_set_path=mmio_set_path, bbl_hash_path=bbl_hash_path, | ||
extra_args=extra_args, silent=not verbose | ||
) | ||
num_processed += 1 | ||
|
||
job_args_multi.append((str(config_path), str(input_path), bbl_trace_path, ram_trace_path, mmio_trace_path, | ||
bbl_set_path, mmio_set_path, extra_args, not verbose, bbl_hash_path, processed_queue)) | ||
iteration += 1 | ||
p = mp.Process(target=multi_proc_manager, args=(gen_traces,job_args_multi)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. We want to be able to limit the number of cores/parallel processes used |
||
p.start() | ||
while num_processed < iteration: | ||
num_processed+=processed_queue.get(block=True,timeout=100) | ||
if log_progress: | ||
if num_processed > 0 and num_processed % 50 == 0: | ||
time_passed = round(time.time() - start_time) | ||
relative_done = (num_processed+1) / num_gentrace_jobs | ||
relative_done = (num_processed + 1) / num_gentrace_jobs | ||
time_estimated = round((relative_done ** (-1)) * time_passed) | ||
logger.info(f"[*] Processed {num_processed}/{num_gentrace_jobs} in {time_passed} seconds. Estimated seconds remaining: {time_estimated-time_passed}") | ||
logger.info( | ||
f"[*] Processed {num_processed}/{num_gentrace_jobs} in {time_passed} seconds. Estimated seconds remaining: {time_estimated - time_passed}") | ||
p.join() | ||
|
||
def gen_all_missing_traces(projdir, trace_name_prefixes=None, log_progress=False, verbose=False, crashing_inputs=False): | ||
if trace_name_prefixes is None: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think mp.Process does not limit the number of concurrent processes. We want to be able to limit this number so that other fuzzing runs are not impacted by the trace generation taking up all computation.
multiprocessing.Pool
should be able to limit this number.Given that, we can add a
-n
argument similar to thefuzzware pipeline -n <num_cores>
argument which allows setting the max number of cores/parallel processes used by trace generation.