summaryrefslogtreecommitdiff
path: root/tools/lib/python/jobserver.py
diff options
context:
space:
mode:
authorJonathan Corbet <corbet@lwn.net>2026-01-23 21:46:08 +0300
committerJonathan Corbet <corbet@lwn.net>2026-01-23 21:46:08 +0300
commit330367bdc176a8f52cc4c5065ba0312277202dee (patch)
tree4e7965522177b29a5f51c3fb85f285e8b69585ff /tools/lib/python/jobserver.py
parentffb569d59c253399efb2345ddfefe7929cd7e2a8 (diff)
parentef6aa110d8888a14dfb2e843794097263c45a06b (diff)
downloadlinux-330367bdc176a8f52cc4c5065ba0312277202dee.tar.xz
Merge branch 'mauro' into docs-mw
Mauro's work to include documentation from our Python modules. His cover letter follows: This is an extended version of: https://lore.kernel.org/linux-doc/cover.1768488832.git.mchehab+huawei@kernel.org/ It basically adds everything we currently have inside libs/tool/python to "tools" book inside documentation. This version should be independent of the other series yet to be merged, (including the jobserver one). The vast amount of changes here are docstring cleanups and additions. They mainly consists on: - ensuring that every phrase will end with a period, making it uniform along all files; - cleaning ups to better uniform docstrings; - variable descriptions now use "#:" markup, as it allows autodoc to add them inside the documentation; - added some missing docstrings; - some new blank lines at comments to make ReST syntax parser happy; - add a couple of sphinx markups (mainly, code blocks). Most of those are minor changes, affecting only comments. It also has one patch per libarary type, adding them to docs. For kernel-doc, I did the cleanups first, as there is one code block inside tools/lib/python/kdoc/latex_fonts.py that would cause a Sphinx crash without such markups. The series actually starts with 3 fixes: - avoid "*" markups on indexes with deep> 3 to override text - a variable rename to stop abusing doctree name - don't rely on cwd to get Documentation/ location patch 4 adds support to document scripts either at: - tools/ - scripts/ patch 5 contains a CSS to better display autodoc html output. For those who want to play with documentation, documenting a python file is very simple. All it takes is to use: .. automodule:: lib.python.<dir+name> Usually, we add a couple of control members to it to adjust the desired documentation scope (add/remove members, showing class inheritance, showing members that currently don't have docstrings, etc). That's why we're using: .. automodule:: lib.python.kdoc.enrich_formatter :members: :show-inheritance: :undoc-members: (and similar) inside tools/kdoc*.rst. autodoc allows filtering in/out members, file docstrings, etc. It also allows documenting just some members or functions with directives like: ..autofunction: ..automember: Sphinx also has a helper script to generate .rst files with documentation: $ sphinx-apidoc -o foobar tools/lib/python/ which can be helpful to discover what should be documented, although changes are needed to use what it produces.
Diffstat (limited to 'tools/lib/python/jobserver.py')
-rwxr-xr-xtools/lib/python/jobserver.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/tools/lib/python/jobserver.py b/tools/lib/python/jobserver.py
index a7c70ff4c375..aba22c33393d 100755
--- a/tools/lib/python/jobserver.py
+++ b/tools/lib/python/jobserver.py
@@ -11,20 +11,23 @@ Interacts with the POSIX jobserver during the Kernel build time.
A "normal" jobserver task, like the one initiated by a make subrocess would do:
- open read/write file descriptors to communicate with the job server;
- - ask for one slot by calling:
+ - ask for one slot by calling::
+
claim = os.read(reader, 1)
- - when the job finshes, call:
+
+ - when the job finshes, call::
+
os.write(writer, b"+") # os.write(writer, claim)
Here, the goal is different: This script aims to get the remaining number
of slots available, using all of them to run a command which handle tasks in
parallel. To to that, it has a loop that ends only after there are no
slots left. It then increments the number by one, in order to allow a
-call equivalent to make -j$((claim+1)), e.g. having a parent make creating
+call equivalent to ``make -j$((claim+1))``, e.g. having a parent make creating
$claim child to do the actual work.
The end goal here is to keep the total number of build tasks under the
-limit established by the initial make -j$n_proc call.
+limit established by the initial ``make -j$n_proc`` call.
See:
https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html#POSIX-Jobserver
@@ -43,13 +46,14 @@ class JobserverExec:
Claim all slots from make using POSIX Jobserver.
The main methods here are:
+
- open(): reserves all slots;
- close(): method returns all used slots back to make;
- - run(): executes a command setting PARALLELISM=<available slots jobs + 1>
+ - run(): executes a command setting PARALLELISM=<available slots jobs + 1>.
"""
def __init__(self):
- """Initialize internal vars"""
+ """Initialize internal vars."""
self.claim = 0
self.jobs = b""
self.reader = None
@@ -57,7 +61,7 @@ class JobserverExec:
self.is_open = False
def open(self):
- """Reserve all available slots to be claimed later on"""
+ """Reserve all available slots to be claimed later on."""
if self.is_open:
return
@@ -155,7 +159,7 @@ class JobserverExec:
self.claim = len(self.jobs) + 1
def close(self):
- """Return all reserved slots to Jobserver"""
+ """Return all reserved slots to Jobserver."""
if not self.is_open:
return