Skip to content

Commit ad659cc

Browse files
sulixshuahkh
authored andcommitted
kunit: tool: Default --jobs to number of CPUs
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 <[email protected]> Signed-off-by: Daniel Latypov <[email protected]> Reviewed-by: Daniel Latypov <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 85310a6 commit ad659cc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

tools/testing/kunit/kunit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ def massage_arg(arg: str) -> str:
282282
return f'{arg}={pseudo_bool_flag_defaults[arg]}'
283283
return list(map(massage_arg, argv))
284284

285+
def get_default_jobs() -> int:
286+
return len(os.sched_getaffinity(0))
287+
285288
def add_common_opts(parser) -> None:
286289
parser.add_argument('--build_dir',
287290
help='As in the make command, it specifies the build '
@@ -332,7 +335,7 @@ def add_build_opts(parser) -> None:
332335
parser.add_argument('--jobs',
333336
help='As in the make command, "Specifies the number of '
334337
'jobs (commands) to run simultaneously."',
335-
type=int, default=8, metavar='jobs')
338+
type=int, default=get_default_jobs(), metavar='jobs')
336339

337340
def add_exec_opts(parser) -> None:
338341
parser.add_argument('--timeout',

tools/testing/kunit/kunit_tool_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def test_config_passes_args_pass(self):
527527
def test_build_passes_args_pass(self):
528528
kunit.main(['build'], self.linux_source_mock)
529529
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
530-
self.linux_source_mock.build_kernel.assert_called_once_with(False, 8, '.kunit', None)
530+
self.linux_source_mock.build_kernel.assert_called_once_with(False, kunit.get_default_jobs(), '.kunit', None)
531531
self.assertEqual(self.linux_source_mock.run_kernel.call_count, 0)
532532

533533
def test_exec_passes_args_pass(self):
@@ -633,8 +633,9 @@ def test_config_builddir(self):
633633

634634
def test_build_builddir(self):
635635
build_dir = '.kunit'
636+
jobs = kunit.get_default_jobs()
636637
kunit.main(['build', '--build_dir', build_dir], self.linux_source_mock)
637-
self.linux_source_mock.build_kernel.assert_called_once_with(False, 8, build_dir, None)
638+
self.linux_source_mock.build_kernel.assert_called_once_with(False, jobs, build_dir, None)
638639

639640
def test_exec_builddir(self):
640641
build_dir = '.kunit'

0 commit comments

Comments
 (0)