Determine GC type based on BUILT_KERNEL_VERSION_FILE.
How it works: 1. build/make/core/Makefile generates a txt file with the kernel version, which is taken from an explicit BOARD_KERNEL_VERSION value, or extracted from the kernel image on the source tree, or extracted from the kernel image extracted from the prebuilt boot.img. The file is saved at $ANDROID_PRODUCT_OUT/obj/PACKAGING/check_vintf_all_intermediates/kernel_version.txt. 2. If PRODUCT_ENABLE_UFFD_GC is "default", meaning the GC type needs to be determined by the kernel version, build/make/core/Makefile copies kernel_version.txt to out/soong/dexpreopt/kernel_version_for_uffd_gc.txt. 3. build/soong/dexpreopt/config.go writes the the UFFD GC flag to out/soong/dexpreopt/uffd_gc_flag.txt. The flag is determined by an explicit PRODUCT_ENABLE_UFFD_GC value or by contruct_uffd_gc_flag.py, which reads kernel_version_for_uffd_gc.txt and determines the flag accordingly. 4. dex2oat takes the UFFD GC flag from uffd_gc_flag.txt. 5. post_process_props.py mangles ro.dalvik.vm.enable_uffd_gc based on the same logic. Bug: 321751629 Bug: 319554951 Bug: 318763448 Bug: 319648491 Test: m --no-skip-soong-tests nothing Test: atest uffd_gc_utils_test Test: Build with `OVERRIDE_ENABLE_UFFD_GC=default m` for device with no UFFD support - 1. Check the existence of `-Xgc:CMC` in out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation (dex2oat invocation for a boot image) 2. Check the existence of `-Xgc:CMC` in out/soong/.intermediates/packages/apps/Settings/Settings/android_common/dexpreopt/Settings/oat/arm64/package.invocation (dex2oat invocation for an app defined in .bp) 3. Check the existence of `-Xgc:CMC` in $ANDROID_PRODUCT_OUT/obj/APPS/Dialer_intermediates/oat/arm64/package.invocation (dex2oat invocation for an app defined in .mk) 4. Check the value of ro.dalvik.vm.enable_uffd_gc in $ANDROID_PRODUCT_OUT/product/etc/build.prop Test: Build with `OVERRIDE_ENABLE_UFFD_GC=default m` for device with UFFD support, and do the steps above. Test: Build with `OVERRIDE_ENABLE_UFFD_GC=true m`, and do the steps above. Test: Build with `OVERRIDE_ENABLE_UFFD_GC=false m`, and do the steps above. Change-Id: I8df6e5be1644da05d2d5c57b3520f29601dfd7a4
This commit is contained in:
@@ -287,6 +287,11 @@ endif
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Do this early because sysprop.mk depends on BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC.
|
||||||
|
ifeq (default,$(ENABLE_UFFD_GC))
|
||||||
|
BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC := $(OUT_DIR)/soong/dexpreopt/kernel_version_for_uffd_gc.txt
|
||||||
|
endif # ENABLE_UFFD_GC
|
||||||
|
|
||||||
include $(BUILD_SYSTEM)/sysprop.mk
|
include $(BUILD_SYSTEM)/sysprop.mk
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
@@ -5256,6 +5261,34 @@ my_board_extracted_kernel :=
|
|||||||
|
|
||||||
endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
|
endif # PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
|
||||||
|
|
||||||
|
ifeq (default,$(ENABLE_UFFD_GC))
|
||||||
|
|
||||||
|
ifneq (,$(BUILT_KERNEL_VERSION_FILE))
|
||||||
|
$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC): $(BUILT_KERNEL_VERSION_FILE)
|
||||||
|
$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC):
|
||||||
|
cp $(BUILT_KERNEL_VERSION_FILE) $(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC)
|
||||||
|
else
|
||||||
|
# We make this a warning rather than an error to avoid breaking too many builds. When it happens,
|
||||||
|
# we use a placeholder as the kernel version, which is consumed by uffd_gc_utils.py.
|
||||||
|
$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC):
|
||||||
|
echo $$'\
|
||||||
|
Unable to determine UFFD GC flag because the kernel version is not available and\n\
|
||||||
|
PRODUCT_ENABLE_UFFD_GC is "default".\n\
|
||||||
|
You can fix this by:\n\
|
||||||
|
1. [Recommended] Making the kernel version available.\n\
|
||||||
|
(1). Set PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS to "true".\n\
|
||||||
|
(2). If you are still getting this message after doing so, see the warning about\n\
|
||||||
|
PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS in the build logs.\n\
|
||||||
|
or\n\
|
||||||
|
2. Explicitly setting PRODUCT_ENABLE_UFFD_GC to "true" or "false" based on the kernel version.\n\
|
||||||
|
(1). Set PRODUCT_ENABLE_UFFD_GC to "true" if the kernel is a GKI kernel and is android12-5.4\n\
|
||||||
|
or above, or a non-GKI kernel that supports userfaultfd(2) and MREMAP_DONTUNMAP.\n\
|
||||||
|
(2). Set PRODUCT_ENABLE_UFFD_GC to "false" otherwise.'\
|
||||||
|
&& echo '<unknown-kernel>' > $@
|
||||||
|
endif # BUILT_KERNEL_VERSION_FILE
|
||||||
|
|
||||||
|
endif # ENABLE_UFFD_GC == "default"
|
||||||
|
|
||||||
# -- Check VINTF compatibility of build.
|
# -- Check VINTF compatibility of build.
|
||||||
# Skip partial builds; only check full builds. Only check if:
|
# Skip partial builds; only check full builds. Only check if:
|
||||||
# - PRODUCT_ENFORCE_VINTF_MANIFEST is true
|
# - PRODUCT_ENFORCE_VINTF_MANIFEST is true
|
||||||
|
@@ -12,38 +12,15 @@
|
|||||||
# ENABLE_UFFD_GC: Whether to use userfaultfd GC.
|
# ENABLE_UFFD_GC: Whether to use userfaultfd GC.
|
||||||
|
|
||||||
config_enable_uffd_gc := \
|
config_enable_uffd_gc := \
|
||||||
$(firstword $(OVERRIDE_ENABLE_UFFD_GC) $(PRODUCT_ENABLE_UFFD_GC))
|
$(firstword $(OVERRIDE_ENABLE_UFFD_GC) $(PRODUCT_ENABLE_UFFD_GC) default)
|
||||||
|
|
||||||
ifeq (,$(filter-out default,$(config_enable_uffd_gc)))
|
ifeq (,$(filter default true false,$(config_enable_uffd_gc)))
|
||||||
ENABLE_UFFD_GC := true
|
|
||||||
|
|
||||||
# Disable userfaultfd GC if the device doesn't support it (i.e., if
|
|
||||||
# `min(ro.board.api_level ?? ro.board.first_api_level ?? MAX_VALUE,
|
|
||||||
# ro.product.first_api_level ?? ro.build.version.sdk ?? MAX_VALUE) < 31`)
|
|
||||||
# This logic aligns with how `ro.vendor.api_level` is calculated in
|
|
||||||
# `system/core/init/property_service.cpp`.
|
|
||||||
# We omit the check on `ro.build.version.sdk` here because we are on the latest build system.
|
|
||||||
board_api_level := $(firstword $(BOARD_API_LEVEL) $(BOARD_SHIPPING_API_LEVEL))
|
|
||||||
ifneq (,$(board_api_level))
|
|
||||||
ifeq (true,$(call math_lt,$(board_api_level),31))
|
|
||||||
ENABLE_UFFD_GC := false
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(PRODUCT_SHIPPING_API_LEVEL))
|
|
||||||
ifeq (true,$(call math_lt,$(PRODUCT_SHIPPING_API_LEVEL),31))
|
|
||||||
ENABLE_UFFD_GC := false
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
else ifeq (true,$(config_enable_uffd_gc))
|
|
||||||
ENABLE_UFFD_GC := true
|
|
||||||
else ifeq (false,$(config_enable_uffd_gc))
|
|
||||||
ENABLE_UFFD_GC := false
|
|
||||||
else
|
|
||||||
$(error Unknown PRODUCT_ENABLE_UFFD_GC value: $(config_enable_uffd_gc))
|
$(error Unknown PRODUCT_ENABLE_UFFD_GC value: $(config_enable_uffd_gc))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ADDITIONAL_PRODUCT_PROPERTIES += ro.dalvik.vm.enable_uffd_gc=$(ENABLE_UFFD_GC)
|
ENABLE_UFFD_GC := $(config_enable_uffd_gc)
|
||||||
|
# If the value is "default", it will be mangled by post_process_props.py.
|
||||||
|
ADDITIONAL_PRODUCT_PROPERTIES += ro.dalvik.vm.enable_uffd_gc=$(config_enable_uffd_gc)
|
||||||
|
|
||||||
# Create APEX_BOOT_JARS_EXCLUDED which is a list of jars to be removed from
|
# Create APEX_BOOT_JARS_EXCLUDED which is a list of jars to be removed from
|
||||||
# ApexBoorJars when built from mainline prebuilts.
|
# ApexBoorJars when built from mainline prebuilts.
|
||||||
|
@@ -57,6 +57,7 @@ my_boot_image_module :=
|
|||||||
# Build the boot.zip which contains the boot jars and their compilation output
|
# Build the boot.zip which contains the boot jars and their compilation output
|
||||||
# We can do this only if preopt is enabled and if the product uses libart config (which sets the
|
# We can do this only if preopt is enabled and if the product uses libart config (which sets the
|
||||||
# default properties for preopting).
|
# default properties for preopting).
|
||||||
|
# At the time of writing, this is only for ART Cloud.
|
||||||
ifeq ($(WITH_DEXPREOPT), true)
|
ifeq ($(WITH_DEXPREOPT), true)
|
||||||
ifneq ($(WITH_DEXPREOPT_ART_BOOT_IMG_ONLY), true)
|
ifneq ($(WITH_DEXPREOPT_ART_BOOT_IMG_ONLY), true)
|
||||||
ifeq ($(PRODUCT_USES_DEFAULT_ART_CONFIG), true)
|
ifeq ($(PRODUCT_USES_DEFAULT_ART_CONFIG), true)
|
||||||
@@ -95,15 +96,16 @@ bootclasspath_arg := $(subst $(space),:,$(patsubst $(dexpreopt_root_dir)%,%,$(DE
|
|||||||
bootclasspath_locations_arg := $(subst $(space),:,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS))
|
bootclasspath_locations_arg := $(subst $(space),:,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS))
|
||||||
boot_images := $(subst :,$(space),$(DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE$(DEXPREOPT_INFIX)))
|
boot_images := $(subst :,$(space),$(DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE$(DEXPREOPT_INFIX)))
|
||||||
boot_image_arg := $(subst $(space),:,$(patsubst /%,%,$(boot_images)))
|
boot_image_arg := $(subst $(space),:,$(patsubst /%,%,$(boot_images)))
|
||||||
dex2oat_extra_args := $(if $(filter true,$(ENABLE_UFFD_GC)),--runtime-arg -Xgc:CMC)
|
uffd_gc_flag_txt := $(OUT_DIR)/soong/dexpreopt/uffd_gc_flag.txt
|
||||||
|
|
||||||
boot_zip_metadata_txt := $(dir $(boot_zip))boot_zip/METADATA.txt
|
boot_zip_metadata_txt := $(dir $(boot_zip))boot_zip/METADATA.txt
|
||||||
|
$(boot_zip_metadata_txt): $(uffd_gc_flag_txt)
|
||||||
$(boot_zip_metadata_txt):
|
$(boot_zip_metadata_txt):
|
||||||
rm -f $@
|
rm -f $@
|
||||||
echo "bootclasspath = $(bootclasspath_arg)" >> $@
|
echo "bootclasspath = $(bootclasspath_arg)" >> $@
|
||||||
echo "bootclasspath-locations = $(bootclasspath_locations_arg)" >> $@
|
echo "bootclasspath-locations = $(bootclasspath_locations_arg)" >> $@
|
||||||
echo "boot-image = $(boot_image_arg)" >> $@
|
echo "boot-image = $(boot_image_arg)" >> $@
|
||||||
echo "extra-args = $(dex2oat_extra_args)" >> $@
|
echo "extra-args = `cat $(uffd_gc_flag_txt)`" >> $@
|
||||||
|
|
||||||
$(call dist-for-goals, droidcore, $(boot_zip_metadata_txt))
|
$(call dist-for-goals, droidcore, $(boot_zip_metadata_txt))
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ ifeq ($(WRITE_SOONG_VARIABLES),true)
|
|||||||
$(call add_json_str, Dex2oatXmx, $(DEX2OAT_XMX))
|
$(call add_json_str, Dex2oatXmx, $(DEX2OAT_XMX))
|
||||||
$(call add_json_str, Dex2oatXms, $(DEX2OAT_XMS))
|
$(call add_json_str, Dex2oatXms, $(DEX2OAT_XMS))
|
||||||
$(call add_json_str, EmptyDirectory, $(OUT_DIR)/empty)
|
$(call add_json_str, EmptyDirectory, $(OUT_DIR)/empty)
|
||||||
$(call add_json_bool, EnableUffdGc, $(filter true,$(ENABLE_UFFD_GC)))
|
$(call add_json_str, EnableUffdGc, $(ENABLE_UFFD_GC))
|
||||||
|
|
||||||
ifdef TARGET_ARCH
|
ifdef TARGET_ARCH
|
||||||
$(call add_json_map, CpuVariant)
|
$(call add_json_map, CpuVariant)
|
||||||
|
@@ -124,7 +124,7 @@ $(if $(filter true,$(BUILD_BROKEN_DUP_SYSPROP)),\
|
|||||||
$(eval _option := --allow-dup)\
|
$(eval _option := --allow-dup)\
|
||||||
)
|
)
|
||||||
|
|
||||||
$(2): $(POST_PROCESS_PROPS) $(INTERNAL_BUILD_ID_MAKEFILE) $(3) $(6)
|
$(2): $(POST_PROCESS_PROPS) $(INTERNAL_BUILD_ID_MAKEFILE) $(3) $(6) $(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC)
|
||||||
$(hide) echo Building $$@
|
$(hide) echo Building $$@
|
||||||
$(hide) mkdir -p $$(dir $$@)
|
$(hide) mkdir -p $$(dir $$@)
|
||||||
$(hide) rm -f $$@ && touch $$@
|
$(hide) rm -f $$@ && touch $$@
|
||||||
@@ -148,7 +148,10 @@ endif
|
|||||||
echo "$$(line)" >> $$@;\
|
echo "$$(line)" >> $$@;\
|
||||||
)\
|
)\
|
||||||
)
|
)
|
||||||
$(hide) $(POST_PROCESS_PROPS) $$(_option) --sdk-version $(PLATFORM_SDK_VERSION) $$@ $(5)
|
$(hide) $(POST_PROCESS_PROPS) $$(_option) \
|
||||||
|
--sdk-version $(PLATFORM_SDK_VERSION) \
|
||||||
|
--kernel-version-file-for-uffd-gc "$(BUILT_KERNEL_VERSION_FILE_FOR_UFFD_GC)" \
|
||||||
|
$$@ $(5)
|
||||||
$(hide) $(foreach file,$(strip $(6)),\
|
$(hide) $(foreach file,$(strip $(6)),\
|
||||||
if [ -f "$(file)" ]; then\
|
if [ -f "$(file)" ]; then\
|
||||||
cat $(file) >> $$@;\
|
cat $(file) >> $$@;\
|
||||||
|
@@ -25,6 +25,9 @@ python_binary_host {
|
|||||||
python_binary_host {
|
python_binary_host {
|
||||||
name: "post_process_props",
|
name: "post_process_props",
|
||||||
srcs: ["post_process_props.py"],
|
srcs: ["post_process_props.py"],
|
||||||
|
libs: [
|
||||||
|
"uffd_gc_utils",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
python_test_host {
|
python_test_host {
|
||||||
@@ -34,6 +37,9 @@ python_test_host {
|
|||||||
"post_process_props.py",
|
"post_process_props.py",
|
||||||
"test_post_process_props.py",
|
"test_post_process_props.py",
|
||||||
],
|
],
|
||||||
|
libs: [
|
||||||
|
"uffd_gc_utils",
|
||||||
|
],
|
||||||
test_config: "post_process_props_unittest.xml",
|
test_config: "post_process_props_unittest.xml",
|
||||||
test_suites: ["general-tests"],
|
test_suites: ["general-tests"],
|
||||||
}
|
}
|
||||||
@@ -45,9 +51,12 @@ python_binary_host {
|
|||||||
|
|
||||||
genrule_defaults {
|
genrule_defaults {
|
||||||
name: "extract_kernel_release_defaults",
|
name: "extract_kernel_release_defaults",
|
||||||
tools: ["extract_kernel", "lz4"],
|
tools: [
|
||||||
|
"extract_kernel",
|
||||||
|
"lz4",
|
||||||
|
],
|
||||||
out: ["kernel_release.txt"],
|
out: ["kernel_release.txt"],
|
||||||
cmd: "$(location) --tools lz4:$(location lz4) --input $(in) --output-release > $(out)"
|
cmd: "$(location) --tools lz4:$(location lz4) --input $(in) --output-release > $(out)",
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_binary_host {
|
cc_binary_host {
|
||||||
@@ -79,8 +88,8 @@ python_binary_host {
|
|||||||
version: {
|
version: {
|
||||||
py3: {
|
py3: {
|
||||||
embedded_launcher: true,
|
embedded_launcher: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
python_test_host {
|
python_test_host {
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from uffd_gc_utils import should_enable_uffd_gc
|
||||||
|
|
||||||
# Usage: post_process_props.py file.prop [disallowed_key, ...]
|
# Usage: post_process_props.py file.prop [disallowed_key, ...]
|
||||||
# Disallowed keys are removed from the property file, if present
|
# Disallowed keys are removed from the property file, if present
|
||||||
|
|
||||||
@@ -27,7 +29,7 @@ PROP_VALUE_MAX = 91
|
|||||||
|
|
||||||
# Put the modifications that you need to make into the */build.prop into this
|
# Put the modifications that you need to make into the */build.prop into this
|
||||||
# function.
|
# function.
|
||||||
def mangle_build_prop(prop_list):
|
def mangle_build_prop(prop_list, kernel_version_file_for_uffd_gc):
|
||||||
# If ro.debuggable is 1, then enable adb on USB by default
|
# If ro.debuggable is 1, then enable adb on USB by default
|
||||||
# (this is for userdebug builds)
|
# (this is for userdebug builds)
|
||||||
if prop_list.get_value("ro.debuggable") == "1":
|
if prop_list.get_value("ro.debuggable") == "1":
|
||||||
@@ -38,6 +40,11 @@ def mangle_build_prop(prop_list):
|
|||||||
else:
|
else:
|
||||||
val = val + ",adb"
|
val = val + ",adb"
|
||||||
prop_list.put("persist.sys.usb.config", val)
|
prop_list.put("persist.sys.usb.config", val)
|
||||||
|
if prop_list.get_value("ro.dalvik.vm.enable_uffd_gc") == "default":
|
||||||
|
assert kernel_version_file_for_uffd_gc != ""
|
||||||
|
enable_uffd_gc = should_enable_uffd_gc(kernel_version_file_for_uffd_gc)
|
||||||
|
prop_list.put("ro.dalvik.vm.enable_uffd_gc",
|
||||||
|
"true" if enable_uffd_gc else "false")
|
||||||
|
|
||||||
def validate_grf_props(prop_list):
|
def validate_grf_props(prop_list):
|
||||||
"""Validate GRF properties if exist.
|
"""Validate GRF properties if exist.
|
||||||
@@ -233,6 +240,7 @@ def main(argv):
|
|||||||
parser.add_argument("filename")
|
parser.add_argument("filename")
|
||||||
parser.add_argument("disallowed_keys", metavar="KEY", type=str, nargs="*")
|
parser.add_argument("disallowed_keys", metavar="KEY", type=str, nargs="*")
|
||||||
parser.add_argument("--sdk-version", type=int, required=True)
|
parser.add_argument("--sdk-version", type=int, required=True)
|
||||||
|
parser.add_argument("--kernel-version-file-for-uffd-gc", required=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.filename.endswith("/build.prop"):
|
if not args.filename.endswith("/build.prop"):
|
||||||
@@ -240,7 +248,7 @@ def main(argv):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
props = PropList(args.filename)
|
props = PropList(args.filename)
|
||||||
mangle_build_prop(props)
|
mangle_build_prop(props, args.kernel_version_file_for_uffd_gc)
|
||||||
if not override_optional_props(props, args.allow_dup):
|
if not override_optional_props(props, args.allow_dup):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not validate_grf_props(props):
|
if not validate_grf_props(props):
|
||||||
|
Reference in New Issue
Block a user