mirror of
https://git.yoctoproject.org/poky
synced 2026-02-06 16:56:37 +01:00
When we switched to recipe specific sysroots (rss), performance took a nose dive. Its easy to blame rss but it turns out not to be entirely at fault. Three configurations are compared here: a) Pre-RSS (revision45df694a9f) b) Post-RSS (revision226a508da9) c) as b) with this change Overall build times: a) 22794.25user 2687.88system 30:32.84elapsed 1390%CPU (0avgtext+0avgdata 919056maxresident)k b) 22677.25user 3238.79system 36:16.68elapsed 1190%CPU (0avgtext+0avgdata 918896maxresident)k c) 23571.84user 3383.65system 31:36.83elapsed 1421%CPU (0avgtext+0avgdata 919068maxresident)k For the overall build and sstate directories, du -s shows: a) 3992588 build-pre-rss/sstate-cache 30804484 build-pre-rss/tmp b) 4013272 build-with-rss/sstate-cache 36519084 build-with-rss/tmp c) 4014744 build-with-rss2/sstate-cache 35336960 build-with-rss2/tmp However more worryingly: $ du -s build-pre-rss/tmp/sysroots/ 2506092 build-pre-rss/tmp/sysroots/ $ du -s build-with-rss/tmp/sysroots-components/ 3790712 build-with-rss/tmp/sysroots-components/ $ du -s build-with-rss2/tmp/sysroots-components/ 2467544 build-with-rss2/tmp/sysroots-components/ These numbers *should* be equivalent but as you can see, b) is ~1.2GB larger. The reason turned out to be patchelf. Taking a specific binary from a specific recipe, bc from bc-native, in a) its 82kb (stripped) yet in b) its 2.17MB. $ ./patchelf --set-interpreter /bin/rp bc warning: working around a Linux kernel bug by creating a hole of 2084864 bytes in ‘bc’ https://github.com/NixOS/patchelf/blob/master/src/patchelf.cc#L710 shows that this "hole" is just padded zeros using memset, its not a proper sparse hole. This patch copies files with cp --sparse=always after modifying them with patchelf, then replacing the original file. The better fix will be to fix this in patchself itself and seek() there when writing the new file but that means new uninative tarballs and will take a bit of work so I'm proposing this workaround in the meantime. Also, this patch drops error handling since subprocess check_output() tracebacks will print this information if the command fails so we can simplify the code. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
129 lines
5.5 KiB
Plaintext
129 lines
5.5 KiB
Plaintext
UNINATIVE_LOADER ?= "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/lib/${@bb.utils.contains('BUILD_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', 'ld-linux.so.2', d)}"
|
|
UNINATIVE_STAGING_DIR ?= "${STAGING_DIR}"
|
|
|
|
UNINATIVE_URL ?= "unset"
|
|
UNINATIVE_TARBALL ?= "${BUILD_ARCH}-nativesdk-libc.tar.bz2"
|
|
# Example checksums
|
|
#UNINATIVE_CHECKSUM[i586] = "dead"
|
|
#UNINATIVE_CHECKSUM[x86_64] = "dead"
|
|
UNINATIVE_DLDIR ?= "${DL_DIR}/uninative/"
|
|
|
|
addhandler uninative_event_fetchloader
|
|
uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted"
|
|
|
|
addhandler uninative_event_enable
|
|
uninative_event_enable[eventmask] = "bb.event.ConfigParsed"
|
|
|
|
python uninative_event_fetchloader() {
|
|
"""
|
|
This event fires on the parent and will try to fetch the tarball if the
|
|
loader isn't already present.
|
|
"""
|
|
|
|
chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH"))
|
|
if not chksum:
|
|
bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH"))
|
|
|
|
loader = d.getVar("UNINATIVE_LOADER")
|
|
loaderchksum = loader + ".chksum"
|
|
if os.path.exists(loader) and os.path.exists(loaderchksum):
|
|
with open(loaderchksum, "r") as f:
|
|
readchksum = f.read().strip()
|
|
if readchksum == chksum:
|
|
return
|
|
|
|
import subprocess
|
|
try:
|
|
# Save and restore cwd as Fetch.download() does a chdir()
|
|
olddir = os.getcwd()
|
|
|
|
tarball = d.getVar("UNINATIVE_TARBALL")
|
|
tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR"), chksum)
|
|
tarballpath = os.path.join(tarballdir, tarball)
|
|
|
|
if not os.path.exists(tarballpath):
|
|
bb.utils.mkdirhier(tarballdir)
|
|
if d.getVar("UNINATIVE_URL") == "unset":
|
|
bb.fatal("Uninative selected but not configured, please set UNINATIVE_URL")
|
|
|
|
localdata = bb.data.createCopy(d)
|
|
localdata.setVar('FILESPATH', "")
|
|
localdata.setVar('DL_DIR', tarballdir)
|
|
|
|
srcuri = d.expand("${UNINATIVE_URL}${UNINATIVE_TARBALL};sha256sum=%s" % chksum)
|
|
bb.note("Fetching uninative binary shim from %s" % srcuri)
|
|
|
|
fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False)
|
|
fetcher.download()
|
|
localpath = fetcher.localpath(srcuri)
|
|
if localpath != tarballpath and os.path.exists(localpath) and not os.path.exists(tarballpath):
|
|
os.symlink(localpath, tarballpath)
|
|
|
|
cmd = d.expand("mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; cd ${UNINATIVE_STAGING_DIR}-uninative; tar -xjf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; ${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux ${UNINATIVE_LOADER} ${UNINATIVE_LOADER} ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so" % chksum)
|
|
subprocess.check_output(cmd, shell=True)
|
|
|
|
with open(loaderchksum, "w") as f:
|
|
f.write(chksum)
|
|
|
|
enable_uninative(d)
|
|
|
|
except bb.fetch2.BBFetchException as exc:
|
|
bb.warn("Disabling uninative as unable to fetch uninative tarball: %s" % str(exc))
|
|
bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.")
|
|
except subprocess.CalledProcessError as exc:
|
|
bb.warn("Disabling uninative as unable to install uninative tarball: %s" % str(exc))
|
|
bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.")
|
|
finally:
|
|
os.chdir(olddir)
|
|
}
|
|
|
|
python uninative_event_enable() {
|
|
"""
|
|
This event handler is called in the workers and is responsible for setting
|
|
up uninative if a loader is found.
|
|
"""
|
|
enable_uninative(d)
|
|
}
|
|
|
|
def enable_uninative(d):
|
|
loader = d.getVar("UNINATIVE_LOADER")
|
|
if os.path.exists(loader):
|
|
bb.debug(2, "Enabling uninative")
|
|
d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d))
|
|
d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp")
|
|
d.setVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", " uninative_changeinterp")
|
|
d.prependVar("PATH", "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:")
|
|
|
|
python uninative_changeinterp () {
|
|
import subprocess
|
|
import stat
|
|
import oe.qa
|
|
|
|
if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)):
|
|
return
|
|
|
|
sstateinst = d.getVar('SSTATE_INSTDIR')
|
|
for walkroot, dirs, files in os.walk(sstateinst):
|
|
for file in files:
|
|
if file.endswith(".so") or ".so." in file:
|
|
continue
|
|
f = os.path.join(walkroot, file)
|
|
if os.path.islink(f):
|
|
continue
|
|
s = os.stat(f)
|
|
if not ((s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH)):
|
|
continue
|
|
elf = oe.qa.ELFFile(f)
|
|
try:
|
|
elf.open()
|
|
except oe.qa.NotELFFileError:
|
|
continue
|
|
if not elf.isDynamic():
|
|
continue
|
|
|
|
subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)
|
|
subprocess.check_output(("cp", "--sparse=always", f, f + ".sparse"), stderr=subprocess.STDOUT)
|
|
os.unlink(f)
|
|
os.rename(f + ".sparse", f)
|
|
}
|