summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-07-29 16:42:25 -0400
committerSteve Sakoman <steve@sakoman.com>2025-08-04 09:12:23 -0700
commitc9d46475eba1e4de8409cd74c1df61dc81f29ae2 (patch)
treee6808f503da98edd05984def18e396b5d1ba8e26 /bitbake/lib/bb/utils.py
parentb4ecf098a662a471439892cefac159f34ed7e7c1 (diff)
downloadpoky-c9d46475eba1e4de8409cd74c1df61dc81f29ae2.tar.gz
bitbake: utils: Optimise signal/sigmask performance
Running "time bitbake -pP idle" with a valid cache shows around 800,000 calls to enum creation from python's signal.py. We don't care about this overhead and it adversely affects cache load time quite badly. Try and use _signal directly, falling back to signal, which avoids this overhead we don't need and makes cache loading much faster. (Bitbake rev: 710f98844ae30416bdf6a01b655df398b49574ec) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit ee5fce67ce35b025c68aa61e2e758903269ee346) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 5486f9599d..0832422683 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -1876,6 +1876,15 @@ def path_is_descendant(descendant, ancestor):
1876 1876
1877 return False 1877 return False
1878 1878
1879# Recomputing the sets in signal.py is expensive (bitbake -pP idle)
1880# so try and use _signal directly to avoid it
1881valid_signals = signal.valid_signals()
1882try:
1883 import _signal
1884 sigmask = _signal.pthread_sigmask
1885except ImportError:
1886 sigmask = signal.pthread_sigmask
1887
1879# If we don't have a timeout of some kind and a process/thread exits badly (for example 1888# If we don't have a timeout of some kind and a process/thread exits badly (for example
1880# OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better 1889# OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better
1881# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. 1890# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked.
@@ -1885,7 +1894,7 @@ def path_is_descendant(descendant, ancestor):
1885@contextmanager 1894@contextmanager
1886def lock_timeout(lock): 1895def lock_timeout(lock):
1887 try: 1896 try:
1888 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) 1897 s = sigmask(signal.SIG_BLOCK, valid_signals)
1889 held = lock.acquire(timeout=5*60) 1898 held = lock.acquire(timeout=5*60)
1890 if not held: 1899 if not held:
1891 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) 1900 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack())
@@ -1893,16 +1902,16 @@ def lock_timeout(lock):
1893 yield held 1902 yield held
1894 finally: 1903 finally:
1895 lock.release() 1904 lock.release()
1896 signal.pthread_sigmask(signal.SIG_SETMASK, s) 1905 sigmask(signal.SIG_SETMASK, s)
1897 1906
1898# A version of lock_timeout without the check that the lock was locked and a shorter timeout 1907# A version of lock_timeout without the check that the lock was locked and a shorter timeout
1899@contextmanager 1908@contextmanager
1900def lock_timeout_nocheck(lock): 1909def lock_timeout_nocheck(lock):
1901 try: 1910 try:
1902 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) 1911 s = sigmask(signal.SIG_BLOCK, valid_signals)
1903 l = lock.acquire(timeout=10) 1912 l = lock.acquire(timeout=10)
1904 yield l 1913 yield l
1905 finally: 1914 finally:
1906 if l: 1915 if l:
1907 lock.release() 1916 lock.release()
1908 signal.pthread_sigmask(signal.SIG_SETMASK, s) 1917 sigmask(signal.SIG_SETMASK, s)