summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-07-18 13:56:54 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-07-21 17:49:04 +0100
commit49d0abc5c80d6ed49eb1ba019cc95d44bf0f5029 (patch)
treebd6436c97f24dccbd8dac2cb74cabc0aa166aed2 /bitbake/lib
parent66f04cba71549f5b0bbfb699e1f662db7c9e8355 (diff)
downloadpoky-49d0abc5c80d6ed49eb1ba019cc95d44bf0f5029.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: ee5fce67ce35b025c68aa61e2e758903269ee346) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-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 f688f7dd68..016036dbce 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -2226,6 +2226,15 @@ def path_is_descendant(descendant, ancestor):
2226 2226
2227 return False 2227 return False
2228 2228
2229# Recomputing the sets in signal.py is expensive (bitbake -pP idle)
2230# so try and use _signal directly to avoid it
2231valid_signals = signal.valid_signals()
2232try:
2233 import _signal
2234 sigmask = _signal.pthread_sigmask
2235except ImportError:
2236 sigmask = signal.pthread_sigmask
2237
2229# If we don't have a timeout of some kind and a process/thread exits badly (for example 2238# If we don't have a timeout of some kind and a process/thread exits badly (for example
2230# OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better 2239# OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better
2231# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. 2240# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked.
@@ -2235,7 +2244,7 @@ def path_is_descendant(descendant, ancestor):
2235@contextmanager 2244@contextmanager
2236def lock_timeout(lock): 2245def lock_timeout(lock):
2237 try: 2246 try:
2238 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) 2247 s = sigmask(signal.SIG_BLOCK, valid_signals)
2239 held = lock.acquire(timeout=5*60) 2248 held = lock.acquire(timeout=5*60)
2240 if not held: 2249 if not held:
2241 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) 2250 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack())
@@ -2243,17 +2252,17 @@ def lock_timeout(lock):
2243 yield held 2252 yield held
2244 finally: 2253 finally:
2245 lock.release() 2254 lock.release()
2246 signal.pthread_sigmask(signal.SIG_SETMASK, s) 2255 sigmask(signal.SIG_SETMASK, s)
2247 2256
2248# A version of lock_timeout without the check that the lock was locked and a shorter timeout 2257# A version of lock_timeout without the check that the lock was locked and a shorter timeout
2249@contextmanager 2258@contextmanager
2250def lock_timeout_nocheck(lock): 2259def lock_timeout_nocheck(lock):
2251 l = False 2260 l = False
2252 try: 2261 try:
2253 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) 2262 s = sigmask(signal.SIG_BLOCK, valid_signals)
2254 l = lock.acquire(timeout=10) 2263 l = lock.acquire(timeout=10)
2255 yield l 2264 yield l
2256 finally: 2265 finally:
2257 if l: 2266 if l:
2258 lock.release() 2267 lock.release()
2259 signal.pthread_sigmask(signal.SIG_SETMASK, s) 2268 sigmask(signal.SIG_SETMASK, s)