diff mbox series

[05/10] roms/edk2-funcs.sh: add the qemu_edk2_get_thread_count() function

Message ID 20190309004826.9027-6-lersek@redhat.com
State New
Headers show
Series bundle edk2 platform firmware with QEMU | expand

Commit Message

Laszlo Ersek March 9, 2019, 12:48 a.m. UTC
The edk2 "build" utility natively supports building modules (that is, INF
files) in parallel. The feature is not useful when building a single
module (with the "-m" option), but it is useful for platform firmware
builds (which include many modules). Add a function that determines the
"-n" option argument for "build", from the MAKEFLAGS variable (i.e. based
on the presence of a make job server).

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 roms/edk2-funcs.sh | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Philippe Mathieu-Daudé March 10, 2019, 3:13 p.m. UTC | #1
On 3/9/19 1:48 AM, Laszlo Ersek wrote:
> The edk2 "build" utility natively supports building modules (that is, INF
> files) in parallel. The feature is not useful when building a single
> module (with the "-m" option), but it is useful for platform firmware
> builds (which include many modules). Add a function that determines the
> "-n" option argument for "build", from the MAKEFLAGS variable (i.e. based
> on the presence of a make job server).
> 
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  roms/edk2-funcs.sh | 25 ++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/roms/edk2-funcs.sh b/roms/edk2-funcs.sh
> index 22a5dc8f6ab6..7fc62f074c59 100644
> --- a/roms/edk2-funcs.sh
> +++ b/roms/edk2-funcs.sh
> @@ -226,3 +226,28 @@ qemu_edk2_set_cross_env()
>  
>    eval "export $cross_prefix_var=\$cross_prefix"
>  }
> +
> +
> +# Determine the "-n" option argument (that is, the number of modules to build
> +# in parallel) for the edk2 "build" utility. Print the result to the standard
> +# output.
> +#
> +# Parameters:
> +#   $1: the value of the MAKEFLAGS variable
> +qemu_edk2_get_thread_count()
> +{
> +  local makeflags="$1"
> +
> +  if [[ "$makeflags" == *--jobserver-auth=* ]] ||
> +     [[ "$makeflags" == *--jobserver-fds=* ]]; then
> +    # If there is a job server, allow the edk2 "build" utility to parallelize
> +    # as many module builds as there are logical CPUs in the system. The "make"
> +    # instances forked by "build" are supposed to limit themselves through the
> +    # job server. The zero value below causes the edk2 "build" utility to fetch
> +    # the logical CPU count with Python's multiprocessing.cpu_count() method.
> +    printf '0\n'

Nice, it works smoothly :)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +  else
> +    # Build a single module at a time.
> +    printf '1\n'
> +  fi
> +}
>
Laszlo Ersek March 12, 2019, 3:41 p.m. UTC | #2
On 03/10/19 16:13, Philippe Mathieu-Daudé wrote:
> On 3/9/19 1:48 AM, Laszlo Ersek wrote:
>> The edk2 "build" utility natively supports building modules (that is, INF
>> files) in parallel. The feature is not useful when building a single
>> module (with the "-m" option), but it is useful for platform firmware
>> builds (which include many modules). Add a function that determines the
>> "-n" option argument for "build", from the MAKEFLAGS variable (i.e. based
>> on the presence of a make job server).
>>
>> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
>> ---
>>  roms/edk2-funcs.sh | 25 ++++++++++++++++++++
>>  1 file changed, 25 insertions(+)
>>
>> diff --git a/roms/edk2-funcs.sh b/roms/edk2-funcs.sh
>> index 22a5dc8f6ab6..7fc62f074c59 100644
>> --- a/roms/edk2-funcs.sh
>> +++ b/roms/edk2-funcs.sh
>> @@ -226,3 +226,28 @@ qemu_edk2_set_cross_env()
>>  
>>    eval "export $cross_prefix_var=\$cross_prefix"
>>  }
>> +
>> +
>> +# Determine the "-n" option argument (that is, the number of modules to build
>> +# in parallel) for the edk2 "build" utility. Print the result to the standard
>> +# output.
>> +#
>> +# Parameters:
>> +#   $1: the value of the MAKEFLAGS variable
>> +qemu_edk2_get_thread_count()
>> +{
>> +  local makeflags="$1"
>> +
>> +  if [[ "$makeflags" == *--jobserver-auth=* ]] ||
>> +     [[ "$makeflags" == *--jobserver-fds=* ]]; then
>> +    # If there is a job server, allow the edk2 "build" utility to parallelize
>> +    # as many module builds as there are logical CPUs in the system. The "make"
>> +    # instances forked by "build" are supposed to limit themselves through the
>> +    # job server. The zero value below causes the edk2 "build" utility to fetch
>> +    # the logical CPU count with Python's multiprocessing.cpu_count() method.
>> +    printf '0\n'
> 
> Nice, it works smoothly :)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
>> +  else
>> +    # Build a single module at a time.
>> +    printf '1\n'
>> +  fi
>> +}
>>

Thanks!
diff mbox series

Patch

diff --git a/roms/edk2-funcs.sh b/roms/edk2-funcs.sh
index 22a5dc8f6ab6..7fc62f074c59 100644
--- a/roms/edk2-funcs.sh
+++ b/roms/edk2-funcs.sh
@@ -226,3 +226,28 @@  qemu_edk2_set_cross_env()
 
   eval "export $cross_prefix_var=\$cross_prefix"
 }
+
+
+# Determine the "-n" option argument (that is, the number of modules to build
+# in parallel) for the edk2 "build" utility. Print the result to the standard
+# output.
+#
+# Parameters:
+#   $1: the value of the MAKEFLAGS variable
+qemu_edk2_get_thread_count()
+{
+  local makeflags="$1"
+
+  if [[ "$makeflags" == *--jobserver-auth=* ]] ||
+     [[ "$makeflags" == *--jobserver-fds=* ]]; then
+    # If there is a job server, allow the edk2 "build" utility to parallelize
+    # as many module builds as there are logical CPUs in the system. The "make"
+    # instances forked by "build" are supposed to limit themselves through the
+    # job server. The zero value below causes the edk2 "build" utility to fetch
+    # the logical CPU count with Python's multiprocessing.cpu_count() method.
+    printf '0\n'
+  else
+    # Build a single module at a time.
+    printf '1\n'
+  fi
+}