diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-07-29 14:43:09 -0400 |
---|---|---|
committer | Steve Sakoman <steve@sakoman.com> | 2025-08-04 07:55:06 -0700 |
commit | 511d3e23f5e769e669f767759ea936f33b2106cd (patch) | |
tree | 425b4ab9b30b56a4a250b28c33d8fe0a980eb835 | |
parent | bfb799ef2a961898ad43a5803ce75d2fdb9d6c0b (diff) | |
download | poky-511d3e23f5e769e669f767759ea936f33b2106cd.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: 982645110a19ebb94d519926a4e14c8a2a205cfd)
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>
-rw-r--r-- | bitbake/lib/bb/utils.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 67e22f4389..d2f11e4377 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -1854,6 +1854,15 @@ def path_is_descendant(descendant, ancestor): | |||
1854 | 1854 | ||
1855 | return False | 1855 | return False |
1856 | 1856 | ||
1857 | # Recomputing the sets in signal.py is expensive (bitbake -pP idle) | ||
1858 | # so try and use _signal directly to avoid it | ||
1859 | valid_signals = signal.valid_signals() | ||
1860 | try: | ||
1861 | import _signal | ||
1862 | sigmask = _signal.pthread_sigmask | ||
1863 | except ImportError: | ||
1864 | sigmask = signal.pthread_sigmask | ||
1865 | |||
1857 | # If we don't have a timeout of some kind and a process/thread exits badly (for example | 1866 | # If we don't have a timeout of some kind and a process/thread exits badly (for example |
1858 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better | 1867 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better |
1859 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. | 1868 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. |
@@ -1863,7 +1872,7 @@ def path_is_descendant(descendant, ancestor): | |||
1863 | @contextmanager | 1872 | @contextmanager |
1864 | def lock_timeout(lock): | 1873 | def lock_timeout(lock): |
1865 | try: | 1874 | try: |
1866 | s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) | 1875 | s = sigmask(signal.SIG_BLOCK, valid_signals) |
1867 | held = lock.acquire(timeout=5*60) | 1876 | held = lock.acquire(timeout=5*60) |
1868 | if not held: | 1877 | if not held: |
1869 | bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) | 1878 | bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) |
@@ -1871,16 +1880,16 @@ def lock_timeout(lock): | |||
1871 | yield held | 1880 | yield held |
1872 | finally: | 1881 | finally: |
1873 | lock.release() | 1882 | lock.release() |
1874 | signal.pthread_sigmask(signal.SIG_SETMASK, s) | 1883 | sigmask(signal.SIG_SETMASK, s) |
1875 | 1884 | ||
1876 | # A version of lock_timeout without the check that the lock was locked and a shorter timeout | 1885 | # A version of lock_timeout without the check that the lock was locked and a shorter timeout |
1877 | @contextmanager | 1886 | @contextmanager |
1878 | def lock_timeout_nocheck(lock): | 1887 | def lock_timeout_nocheck(lock): |
1879 | try: | 1888 | try: |
1880 | s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) | 1889 | s = sigmask(signal.SIG_BLOCK, valid_signals) |
1881 | l = lock.acquire(timeout=10) | 1890 | l = lock.acquire(timeout=10) |
1882 | yield l | 1891 | yield l |
1883 | finally: | 1892 | finally: |
1884 | if l: | 1893 | if l: |
1885 | lock.release() | 1894 | lock.release() |
1886 | signal.pthread_sigmask(signal.SIG_SETMASK, s) | 1895 | sigmask(signal.SIG_SETMASK, s) |