-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add support for controlling the number of jobs used by some cmake tasks #107
base: master
Are you sure you want to change the base?
Conversation
- Add support for `build` arg `--cmake-jobs` to set the number of jobs to use. - Rename `_get_make_arguments()` to `_get_make_jobs_arguments()` for clarity
d1b7eb0
to
3b8132e
Compare
PR has been rebased onto master fixing the CI check failures. |
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.
Overall this LGTM. @dirk-thomas ?
Slight reorganisation to change jobs variable initialisation. Co-authored-by: Michel Hidalgo <[email protected]>
Rename `is_job_base_generator` to `is_job_based_generator` to be more correct
This better reflects the nature of the function.
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.
This looks great to me, but I'd appreciate @dirk-thomas or @cottsay input as well.
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.
Doesn't simply specifying the CMAKE_BUILD_PARALLEL_LEVEL
environment variable work for Ninja?
type=int, | ||
help='Number of jobs to use for supported generators (e.g., Ninja ' | ||
'Makefiles). Negative values subtract from the maximum ' | ||
'available, so --jobs=-1 uses all bar 1 available threads.') |
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.
'available, so --jobs=-1 uses all bar 1 available threads.') | |
'available, so --jobs=-1 uses all but 1 available threads.') |
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.
Not a typo
Co-authored-by: Michel Hidalgo <[email protected]>
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.
Doesn't simply specifying the
CMAKE_BUILD_PARALLEL_LEVEL
environment variable work for Ninja?
@cottsay Not sure, but it was introduced in CMake 3.12. I'm working with baseline support for 3.10 as ships with Ubuntu 18.04.
colcon_cmake/task/cmake/__init__.py
Outdated
:rtype: bool | ||
""" | ||
known_jobs_base_multi_configuration_generators = ( | ||
'Ninja Multi-Config', |
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 originally made this change on top of PR 106 then pulled this out. You can view this as a defensive or pre-emptive change. It should have little to no impact until then as the ninja multi-config won't really work yet.
colcon_cmake/task/cmake/build.py
Outdated
@@ -240,8 +249,8 @@ async def _build(self, args, env, *, additional_targets=None): | |||
cmd += ['--clean-first'] | |||
if multi_configuration_generator: | |||
cmd += ['--config', self._get_configuration(args)] | |||
else: | |||
job_args = self._get_make_arguments(env) | |||
if jobs_base_generator: |
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.
Similarly, the removal of the else
and replacing it with this separate condition check relates to ninja multi-config support, but should have no impact in isolation.
# the number of cores can't be determined | ||
return [] | ||
# Finalise jobs as as CPU count deducting the limit specified. | ||
jobs = max(jobs + jobs_args, 1) | ||
return [ | ||
'-j{jobs}'.format_map(locals()), |
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.
The rename of the function is based on this result. It can only return jobs. Will revert if appropriate.
@@ -343,8 +362,8 @@ async def _install(self, args, env): | |||
args.build_base, args.cmake_args) | |||
if multi_configuration_generator: | |||
cmd += ['--config', self._get_configuration(args)] | |||
elif allow_job_args: | |||
job_args = self._get_make_arguments(env) | |||
if allow_job_args: |
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.
This elif
to if
change also supports ninja multi-config.
type=int, | ||
help='Number of jobs to use for supported generators (e.g., Ninja ' | ||
'Makefiles). Negative values subtract from the maximum ' | ||
'available, so --jobs=-1 uses all bar 1 available threads.') |
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.
Not a typo
@cottsay Looking at the CMake 3.12 release notes, it looks like they added This changes the context of this PR a bit and I see the need to revise the original code I modified to deal with that as well. I propose the ideal solution is to use the changes I've made with CMake < 3.12. For CMake 3.12+, change this function to return My question is, are the changes better made in this PR or a to push this through and start a new PR? |
I see two conceptual changes:
The latter can be done in this PR, I think. The former should probably be done in a new PR. Thoughts? |
I fully agree with point 1, but would add that it's not just using On point 2, the deprecation warning only makes sense if
Again, I need more information aboug how the command line arguments interact with |
FYI,
|
Revised how jobs are specified. For cmake 3.12+, we use `cmake --build -jN`. For cmake < 3.12, we use `cmake --build [args] -- -jN -lN`, but only for Ninja and Makefiles generators. Note we no longer check if we have a jobs based generator. This is now managed internally to `_get_jobs_arguments()`. Also note we now add `--` inside `_get_jobs_arguments()` as it is not needed for CMake 3.12+
@cottsay @hidmic The changes are summaried as:
Note we no longer check if we have a jobs based generator. This is now managed internally to Also note we now add |
Since I don't have the spare time to review this change I leave it up to the co-maintainers to review and test this. A general - fairly significant - concern I have: the Travis CI integration for all |
Neither this PR nor master are getting test coverage on Linux or macOS because of the missing Travis builds.
I'm still not feeling great about merging a PR that adds a command line option to support such a narrow use case, especially one that has an official mechanism available in newer versions of CMake. Here's a completely different suggestion - could we expose a free-form |
Yes, I like this option. It does mean removing the |
I've created a new PR for the I managed to maintain We can deprecate this PR if the 110 is the preferred solution. |
This change adds support for
build
arg--cmake-jobs
to set the number of jobs to use to preserve CPU for the OS. It also renames_get_make_arguments()
to_get_make_jobs_arguments()
to better reflect the responsibilities of the function.There is currently support to set the number of job threads to the maximum available, unless the
MAKEFLAGS
environment variable is set. The assumption is thatMAKEFLAGS
will be used by the build framework to control the number of jobs. However, this is only true formake
- as far as I can tell,ninja
does not have any such environment variable based control (related issues reported against ninja 922, 1482).When
MAKEFLAGS
is not set, colcon will maxout the-j
argument for ninja. Since ninja is so efficient, this can make the computer unresponsive for the OS and other applications. This change has been made to allow the OS to remain somewhat responsive.As part of the change, I noted that
_get_make_arguments()
appears to be misnamed as the only thing it does is set the number of jobs to use, as evidenced by the use of the returned values. I've renamed it_get_make_jobs_arguments()
to better reflect this. Happy to revert this change if required.The
--cmake-jobs
args supports the following usage patterns: