diff options
author | Mikhail Kashkarov <m.kashkarov@partner.samsung.com> | 2019-08-28 22:49:12 +0300 |
---|---|---|
committer | Mikhail Kashkarov <m.kashkarov@partner.samsung.com> | 2019-09-05 13:50:59 +0300 |
commit | 034885f92a8d17a2520a45d99d565c315cd3b288 (patch) | |
tree | bdc442f97bc1a92db31d8ca371b045b043276765 | |
parent | 7773fcfe77b28e9a0e75e49bb191e7c25a2e38f5 (diff) | |
download | qemu-accel-034885f92a8d17a2520a45d99d565c315cd3b288.tar.gz qemu-accel-034885f92a8d17a2520a45d99d565c315cd3b288.tar.bz2 qemu-accel-034885f92a8d17a2520a45d99d565c315cd3b288.zip |
[S] Parallelize patch_binary usage
Spawn $n_jobs count processes to do patch_binary in parallel. A pipe is used to
dispatch the files among the processes.
With previous patches for warnings elimination and parallelization time for
patching binaries goes from ~230sec -> 6sec (with sanitized environment)
Change-Id: Iae3859d67f700b90fae809c45bea706b3e6162e4
-rw-r--r-- | packaging/qemu-accel-aarch64.spec | 42 | ||||
-rw-r--r-- | packaging/qemu-accel-armv7hl.spec | 42 | ||||
-rw-r--r-- | packaging/qemu-accel-armv7l.spec | 42 | ||||
-rw-r--r-- | packaging/qemu-accel.spec.in | 42 |
4 files changed, 152 insertions, 16 deletions
diff --git a/packaging/qemu-accel-aarch64.spec b/packaging/qemu-accel-aarch64.spec index 621343d..c011fdf 100644 --- a/packaging/qemu-accel-aarch64.spec +++ b/packaging/qemu-accel-aarch64.spec @@ -244,10 +244,44 @@ function patch_binary { fi } -for binary in $binaries -do - patch_binary $binary $LD -done +# Spawn single job which reads input to extract filename by index +function run_single_job() { + local arg="$1" + while :; do + # Reads (FILENUM_DIGITS + 1) bytes. Note: to drop redirection usage we + # need dd with support for status=none + filenum=$(dd bs=$(( FILENUM_DIGITS + 1 )) count=1 2>/dev/null) + if [[ -z "$filenum" ]]; then + break + fi + # Get filename for 0x$filenum index and process it + patch_binary "${bin_array[$((0x$filenum))]}" "$LD" + done +} + +# Converting to the bash array to allow access by index +bin_array=($binaries) +# Use processors count + arbitrary addend. +n_jobs=$(( $(/usr/bin/getconf _NPROCESSORS_ONLN) + 3 )) +# Supports up to 16^FILENUM_DIGITS - 1 files: +# 16^5 - 1 = 1.048.575 files +FILENUM_DIGITS=5 + +# Send the input for the jobs: enumerate all files +for ((file = 0; file < ${#bin_array[@]}; file++)); do + printf "%0${FILENUM_DIGITS}x\\n" $file +done | ( + # Implementing simple Round-robin scheduling routine + exec 3<&0 + echo "Spawn $n_jobs jobs" + for ((i = 0; i < n_jobs; i++)); do + # The shell redirects stdin to /dev/null for background jobs. Work + # around this by duplicating fd 0 + run_single_job $i <&3 & + done + wait +) + set -x %{?multilib: diff --git a/packaging/qemu-accel-armv7hl.spec b/packaging/qemu-accel-armv7hl.spec index 0af6571..6d8cdb5 100644 --- a/packaging/qemu-accel-armv7hl.spec +++ b/packaging/qemu-accel-armv7hl.spec @@ -244,10 +244,44 @@ function patch_binary { fi } -for binary in $binaries -do - patch_binary $binary $LD -done +# Spawn single job which reads input to extract filename by index +function run_single_job() { + local arg="$1" + while :; do + # Reads (FILENUM_DIGITS + 1) bytes. Note: to drop redirection usage we + # need dd with support for status=none + filenum=$(dd bs=$(( FILENUM_DIGITS + 1 )) count=1 2>/dev/null) + if [[ -z "$filenum" ]]; then + break + fi + # Get filename for 0x$filenum index and process it + patch_binary "${bin_array[$((0x$filenum))]}" "$LD" + done +} + +# Converting to the bash array to allow access by index +bin_array=($binaries) +# Use processors count + arbitrary addend. +n_jobs=$(( $(/usr/bin/getconf _NPROCESSORS_ONLN) + 3 )) +# Supports up to 16^FILENUM_DIGITS - 1 files: +# 16^5 - 1 = 1.048.575 files +FILENUM_DIGITS=5 + +# Send the input for the jobs: enumerate all files +for ((file = 0; file < ${#bin_array[@]}; file++)); do + printf "%0${FILENUM_DIGITS}x\\n" $file +done | ( + # Implementing simple Round-robin scheduling routine + exec 3<&0 + echo "Spawn $n_jobs jobs" + for ((i = 0; i < n_jobs; i++)); do + # The shell redirects stdin to /dev/null for background jobs. Work + # around this by duplicating fd 0 + run_single_job $i <&3 & + done + wait +) + set -x %{?multilib: diff --git a/packaging/qemu-accel-armv7l.spec b/packaging/qemu-accel-armv7l.spec index 70012d1..86130b2 100644 --- a/packaging/qemu-accel-armv7l.spec +++ b/packaging/qemu-accel-armv7l.spec @@ -244,10 +244,44 @@ function patch_binary { fi } -for binary in $binaries -do - patch_binary $binary $LD -done +# Spawn single job which reads input to extract filename by index +function run_single_job() { + local arg="$1" + while :; do + # Reads (FILENUM_DIGITS + 1) bytes. Note: to drop redirection usage we + # need dd with support for status=none + filenum=$(dd bs=$(( FILENUM_DIGITS + 1 )) count=1 2>/dev/null) + if [[ -z "$filenum" ]]; then + break + fi + # Get filename for 0x$filenum index and process it + patch_binary "${bin_array[$((0x$filenum))]}" "$LD" + done +} + +# Converting to the bash array to allow access by index +bin_array=($binaries) +# Use processors count + arbitrary addend. +n_jobs=$(( $(/usr/bin/getconf _NPROCESSORS_ONLN) + 3 )) +# Supports up to 16^FILENUM_DIGITS - 1 files: +# 16^5 - 1 = 1.048.575 files +FILENUM_DIGITS=5 + +# Send the input for the jobs: enumerate all files +for ((file = 0; file < ${#bin_array[@]}; file++)); do + printf "%0${FILENUM_DIGITS}x\\n" $file +done | ( + # Implementing simple Round-robin scheduling routine + exec 3<&0 + echo "Spawn $n_jobs jobs" + for ((i = 0; i < n_jobs; i++)); do + # The shell redirects stdin to /dev/null for background jobs. Work + # around this by duplicating fd 0 + run_single_job $i <&3 & + done + wait +) + set -x %{?multilib: diff --git a/packaging/qemu-accel.spec.in b/packaging/qemu-accel.spec.in index e5fc9b8..192c077 100644 --- a/packaging/qemu-accel.spec.in +++ b/packaging/qemu-accel.spec.in @@ -241,10 +241,44 @@ function patch_binary { fi } -for binary in $binaries -do - patch_binary $binary $LD -done +# Spawn single job which reads input to extract filename by index +function run_single_job() { + local arg="$1" + while :; do + # Reads (FILENUM_DIGITS + 1) bytes. Note: to drop redirection usage we + # need dd with support for status=none + filenum=$(dd bs=$(( FILENUM_DIGITS + 1 )) count=1 2>/dev/null) + if [[ -z "$filenum" ]]; then + break + fi + # Get filename for 0x$filenum index and process it + patch_binary "${bin_array[$((0x$filenum))]}" "$LD" + done +} + +# Converting to the bash array to allow access by index +bin_array=($binaries) +# Use processors count + arbitrary addend. +n_jobs=$(( $(/usr/bin/getconf _NPROCESSORS_ONLN) + 3 )) +# Supports up to 16^FILENUM_DIGITS - 1 files: +# 16^5 - 1 = 1.048.575 files +FILENUM_DIGITS=5 + +# Send the input for the jobs: enumerate all files +for ((file = 0; file < ${#bin_array[@]}; file++)); do + printf "%0${FILENUM_DIGITS}x\\n" $file +done | ( + # Implementing simple Round-robin scheduling routine + exec 3<&0 + echo "Spawn $n_jobs jobs" + for ((i = 0; i < n_jobs; i++)); do + # The shell redirects stdin to /dev/null for background jobs. Work + # around this by duplicating fd 0 + run_single_job $i <&3 & + done + wait +) + set -x %{?multilib: |