[lkml]   [2021]   [Dec]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v3] kunit: tool: Default --jobs to number of CPUs
From: David Gow <>

The --jobs parameter for kunit_tool currently defaults to 8 CPUs,
regardless of the number available. For systems with significantly more
(or less), this is not as efficient. Instead, default --jobs to the
number of CPUs available to the process: while there are as many
superstitions as to exactly what the ideal jobs:CPU ratio is, this seems
sufficiently sensible to me.

A new helper function to get the default number of jobs is added:
get_default_jobs() -- this is used in kunit_tool_test instead of a
hardcoded value, or an explicit call to len(os.sched_getaffinity()), so
should be more flexible if this needs to change in the future.

Signed-off-by: David Gow <>
Signed-off-by: Daniel Latypov <>
Reviewed-by: Daniel Latypov <>
Reviewed-by: Brendan Higgins <>
Changes since v2:
- Rebased by Daniel Latypov onto linxu-kselftest kunit branch.
There was a trivial conflict in

Changes since v1:
- Use len(os.sched_getaffinity()) instead of os.cpu_count(), which gives
the number of available processors (to this process), rather than the
- Fix, which had 8 jobs hardcoded in a couple of
- Thanks to Daniel Latypov for these suggestions.
tools/testing/kunit/ | 5 ++++-
tools/testing/kunit/ | 5 +++--
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/kunit/ b/tools/testing/kunit/
index f1be71811369..7a706f96f68d 100755
--- a/tools/testing/kunit/
+++ b/tools/testing/kunit/
@@ -282,6 +282,9 @@ def massage_argv(argv: Sequence[str]) -> Sequence[str]:
return f'{arg}={pseudo_bool_flag_defaults[arg]}'
return list(map(massage_arg, argv))

+def get_default_jobs() -> int:
+ return len(os.sched_getaffinity(0))
def add_common_opts(parser) -> None:
help='As in the make command, it specifies the build '
@@ -332,7 +335,7 @@ def add_build_opts(parser) -> None:
help='As in the make command, "Specifies the number of '
'jobs (commands) to run simultaneously."',
- type=int, default=8, metavar='jobs')
+ type=int, default=get_default_jobs(), metavar='jobs')

def add_exec_opts(parser) -> None:
diff --git a/tools/testing/kunit/ b/tools/testing/kunit/
index b80e333a20cb..352369dffbd9 100755
--- a/tools/testing/kunit/
+++ b/tools/testing/kunit/
@@ -527,7 +527,7 @@ class KUnitMainTest(unittest.TestCase):
def test_build_passes_args_pass(self):
kunit.main(['build'], self.linux_source_mock)
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
- self.linux_source_mock.build_kernel.assert_called_once_with(False, 8, '.kunit', None)
+ self.linux_source_mock.build_kernel.assert_called_once_with(False, kunit.get_default_jobs(), '.kunit', None)
self.assertEqual(self.linux_source_mock.run_kernel.call_count, 0)

def test_exec_passes_args_pass(self):
@@ -633,8 +633,9 @@ class KUnitMainTest(unittest.TestCase):

def test_build_builddir(self):
build_dir = '.kunit'
+ jobs = kunit.get_default_jobs()
kunit.main(['build', '--build_dir', build_dir], self.linux_source_mock)
- self.linux_source_mock.build_kernel.assert_called_once_with(False, 8, build_dir, None)
+ self.linux_source_mock.build_kernel.assert_called_once_with(False, jobs, build_dir, None)

def test_exec_builddir(self):
build_dir = '.kunit'
base-commit: 1ee2ba89bea86d6389509e426583b49ac19b86f2

 \ /
  Last update: 2021-12-15 21:51    [W:0.049 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site