From d26d13cb354bb49296aacd036a0f3927684b65eb Mon Sep 17 00:00:00 2001 From: EliasTheGrandMasterOfMistakes Date: Wed, 4 Jun 2025 16:31:56 -0300 Subject: [PATCH 1/9] waydroid: Introduce a libinit libinit based on sm8150-common Co-authored-by: Sebastiano Barezzi --- BoardConfig.mk | 4 ++ libinit/Android.bp | 24 ++++++++++ libinit/include/libinit_dalvik_heap.h | 23 +++++++++ libinit/include/libinit_utils.h | 16 +++++++ libinit/init_waydroid_waydroid.cpp | 13 ++++++ libinit/libinit_dalvik_heap.cpp | 67 +++++++++++++++++++++++++++ libinit/libinit_utils.cpp | 37 +++++++++++++++ 7 files changed, 184 insertions(+) create mode 100644 libinit/Android.bp create mode 100644 libinit/include/libinit_dalvik_heap.h create mode 100644 libinit/include/libinit_utils.h create mode 100644 libinit/init_waydroid_waydroid.cpp create mode 100644 libinit/libinit_dalvik_heap.cpp create mode 100644 libinit/libinit_utils.cpp diff --git a/BoardConfig.mk b/BoardConfig.mk index 469aa90..3960128 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -27,6 +27,10 @@ TARGET_FLATTEN_APEX := true # Platform TARGET_BOARD_PLATFORM := waydroid +# Init +TARGET_INIT_VENDOR_LIB ?= //$(COMMON_PATH):init_waydroid_waydroid +TARGET_RECOVERY_DEVICE_MODULES ?= init_waydroid_waydroid + # Kernel TARGET_NO_KERNEL := true diff --git a/libinit/Android.bp b/libinit/Android.bp new file mode 100644 index 0000000..54de217 --- /dev/null +++ b/libinit/Android.bp @@ -0,0 +1,24 @@ +// +// Copyright (C) 2021 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_static { + name: "libinit_waydroid_waydroid", + srcs: [ + "libinit_dalvik_heap.cpp", + "libinit_utils.cpp", + ], + whole_static_libs: ["libbase"], + export_include_dirs: ["include"], + recovery_available: true, +} + +cc_library_static { + name: "init_waydroid_waydroid", + srcs: ["init_waydroid_waydroid.cpp"], + whole_static_libs: ["libinit_waydroid_waydroid"], + include_dirs: ["system/core/init"], + recovery_available: true, +} diff --git a/libinit/include/libinit_dalvik_heap.h b/libinit/include/libinit_dalvik_heap.h new file mode 100644 index 0000000..75144b2 --- /dev/null +++ b/libinit/include/libinit_dalvik_heap.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_DALVIK_HEAP_H +#define LIBINIT_DALVIK_HEAP_H + +#include + +typedef struct dalvik_heap_info { + std::string heapstartsize; + std::string heapgrowthlimit; + std::string heapsize; + std::string heapminfree; + std::string heapmaxfree; + std::string heaptargetutilization; +} dalvik_heap_info_t; + +void set_dalvik_heap(void); + +#endif // LIBINIT_DALVIK_HEAP_H diff --git a/libinit/include/libinit_utils.h b/libinit/include/libinit_utils.h new file mode 100644 index 0000000..ac2d673 --- /dev/null +++ b/libinit/include/libinit_utils.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_UTILS_H +#define LIBINIT_UTILS_H + +#include + +void property_override(std::string prop, std::string value, bool add = true); + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product = false); + +#endif // LIBINIT_UTILS_H diff --git a/libinit/init_waydroid_waydroid.cpp b/libinit/init_waydroid_waydroid.cpp new file mode 100644 index 0000000..623cd71 --- /dev/null +++ b/libinit/init_waydroid_waydroid.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "vendor_init.h" + +void vendor_load_properties() { + set_dalvik_heap(); +} diff --git a/libinit/libinit_dalvik_heap.cpp b/libinit/libinit_dalvik_heap.cpp new file mode 100644 index 0000000..81426fe --- /dev/null +++ b/libinit/libinit_dalvik_heap.cpp @@ -0,0 +1,67 @@ + /* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + + #include + #include + + #include + + #define HEAPSTARTSIZE_PROP "dalvik.vm.heapstartsize" + #define HEAPGROWTHLIMIT_PROP "dalvik.vm.heapgrowthlimit" + #define HEAPSIZE_PROP "dalvik.vm.heapsize" + #define HEAPMINFREE_PROP "dalvik.vm.heapminfree" + #define HEAPMAXFREE_PROP "dalvik.vm.heapmaxfree" + #define HEAPTARGETUTILIZATION_PROP "dalvik.vm.heaptargetutilization" + + #define GB(b) (b * 1024ull * 1024 * 1024) + + static const dalvik_heap_info_t dalvik_heap_info_6144 = { + .heapstartsize = "16m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "32m", + .heaptargetutilization = "0.5", + }; + + static const dalvik_heap_info_t dalvik_heap_info_4096 = { + .heapstartsize = "8m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "16m", + .heaptargetutilization = "0.6", + }; + + static const dalvik_heap_info_t dalvik_heap_info_2048 = { + .heapstartsize = "8m", + .heapgrowthlimit = "192m", + .heapsize = "512m", + .heapminfree = "512k", + .heapmaxfree = "8m", + .heaptargetutilization = "0.75", + }; + + void set_dalvik_heap() { + struct sysinfo sys; + const dalvik_heap_info_t *dhi; + + sysinfo(&sys); + + if (sys.totalram > GB(5)) + dhi = &dalvik_heap_info_6144; + else if (sys.totalram > GB(3)) + dhi = &dalvik_heap_info_4096; + else + dhi = &dalvik_heap_info_2048; + + property_override(HEAPSTARTSIZE_PROP, dhi->heapstartsize); + property_override(HEAPGROWTHLIMIT_PROP, dhi->heapgrowthlimit); + property_override(HEAPSIZE_PROP, dhi->heapsize); + property_override(HEAPTARGETUTILIZATION_PROP, dhi->heaptargetutilization); + property_override(HEAPMINFREE_PROP, dhi->heapminfree); + property_override(HEAPMAXFREE_PROP, dhi->heapmaxfree); + } diff --git a/libinit/libinit_utils.cpp b/libinit/libinit_utils.cpp new file mode 100644 index 0000000..322d66a --- /dev/null +++ b/libinit/libinit_utils.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include +#include + +#include + +void property_override(std::string prop, std::string value, bool add) { + auto pi = (prop_info *) __system_property_find(prop.c_str()); + if (pi != nullptr) { + __system_property_update(pi, value.c_str(), value.length()); + } else if (add) { + __system_property_add(prop.c_str(), prop.length(), value.c_str(), value.length()); + } +} + +std::vector ro_props_default_source_order = { + "system.", + "", +}; + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product) { + std::string prop_name; + + for (const auto &source : ro_props_default_source_order) { + if (product) + prop_name = "ro.product." + source + prop; + else + prop_name = "ro." + source + "build." + prop; + + property_override(prop_name, value, true); + } From 966f69654ab3604363c101d05089aab3813b0bf1 Mon Sep 17 00:00:00 2001 From: EliasTheGrandMasterOfMistakes Date: Thu, 5 Jun 2025 00:14:41 -0300 Subject: [PATCH 2/9] waydroid: libinit: Add initial libinit dalvik's dex2oat manager This is a simples init program that reads number of cpus and use this to defines dalvik.vm.*.dex2oat properties --- libinit/include/libinit_dalvik_vm.h | 23 +++++++++ libinit/libinit_dalvik_vm.cpp | 75 +++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 libinit/include/libinit_dalvik_vm.h create mode 100644 libinit/libinit_dalvik_vm.cpp diff --git a/libinit/include/libinit_dalvik_vm.h b/libinit/include/libinit_dalvik_vm.h new file mode 100644 index 0000000..f9e020f --- /dev/null +++ b/libinit/include/libinit_dalvik_vm.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_DALVIK_VM_H +#define LIBINIT_DALVIK_VM_H + +#include + +typedef struct dalvik_vm_info { + std::string backgroundcpuset; + std::string backgroundthreads; + std::string bootcpuset; + std::string bootcputhreads; + std::string dexcpuset; + std::string dexcputhreads; +} dalvik_heap_info_t; + +void set_dalvik_heap(void); + +#endif // LIBINIT_DALVIK_HEAP_H diff --git a/libinit/libinit_dalvik_vm.cpp b/libinit/libinit_dalvik_vm.cpp new file mode 100644 index 0000000..325ea48 --- /dev/null +++ b/libinit/libinit_dalvik_vm.cpp @@ -0,0 +1,75 @@ + /* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + + #include + #include + + #include + + #define VMBACKGROUNDCPUSET_PROP "dalvik.vm.background-dex2oat-cpu-set" + #define VMBACKGROUNDTHREADS_PROP "dalvik.vm.background-dex2oat-threads" + #define VMBOOTCPUSET_PROP "dalvik.vm.boot-dex2oat-cpu-set" + #define VMBOOTCPUTHREADS_PROP "dalvik.vm.boot-dex2oat-threads" + #define VMDEXCPUSET_PROP "dalvik.vm.dex2oat-cpu-set" + #define VMDEXCPUTHREADS_PROP "dalvik.vm.dex2oat-threads" + + static const dalvik_vm_info_t dalvik_vm_info_8 = { + .backgroundcpuset = "0,1,2,3,4,5,6,7", + .backgroundthreads = "8", + .bootcpuset = "0,1,2,3,4,5,6,7", + .bootcputhreads = "8", + .dexcpuset = "0,1,2,3,4,5,6,7", + .dexcputhreads = "8", + }; + + static const dalvik_vm_info_t dalvik_vm_info_6 = { + .backgroundcpuset = "0,1,2,3,4,5", + .backgroundthreads = "6", + .bootcpuset = "0,1,2,3,4,5", + .bootcputhreads = "6", + .dexcpuset = "0,1,2,3,4,5", + .dexcputhreads = "6", + }; + + static const dalvik_vm_info_t dalvik_vm_info_4 = { + .backgroundcpuset = "0,1,2,3", + .backgroundthreads = "4", + .bootcpuset = "0,1,2,3", + .bootcputhreads = "4", + .dexcpuset = "0,1,2,3", + .dexcputhreads = "4", + }; + + static const dalvik_vm_info_t dalvik_vm_info_2 = { + .backgroundcpuset = "0,1", + .backgroundthreads = "2", + .bootcpuset = "0,1", + .bootcputhreads = "2", + .dexcpuset = "0,1", + .dexcputhreads = "2", + }; + + void set_dalvik_vm() { + const dalvik_vm_info_t *thi; + + int ncpus = get_nprocs_conf(); + + if (ncpus == 2) + thi = &dalvik_vm_info_2; + else if (ncpus == 4) + thi = &dalvik_vm_info_2; + else if (ncpus = 6) + thi = &dalvik_vm_info_6; + else (ncpus >= 8) + thi = &dalvik_vm_info_8; + + property_override(VMBACKGROUNDCPUSET_PROP, thi->backgroundcpuset); + property_override(VMBACKGROUNDTHREADS_PROP, thi->backgroundthreads); + property_override(VMBOOTCPUSET_PROP, thi->bootcpuset); + property_override(VMBOOTCPUTHREADS_PROP, thi->bootcputhreads); + property_override(VMDEXCPUSET_PROP, thi->dexcpuset); + property_override(VMDEXCPUTHREADS_PROP, thi->dexcputhreads); + } From b3b1e4e458385375608dd28e87d766e2fc868d41 Mon Sep 17 00:00:00 2001 From: EliasTheGrandMasterOfMistakes Date: Thu, 5 Jun 2025 00:34:24 -0300 Subject: [PATCH 3/9] waydroid: libinit: Add more dalvik_heap variants Imported from device_xiaomi_marble Co-Authored-By: SebaUbuntu Co-Authored-By: Ramii Ahmed Co-Authored-By: luk1337 Co-Authored-By: Arian Co-Authored-By: Mohammed Althaf Thayyil Co-Authored-By: YuKongA <70465933+YuKongA@users.noreply.github.com> --- libinit/libinit_dalvik_heap.cpp | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libinit/libinit_dalvik_heap.cpp b/libinit/libinit_dalvik_heap.cpp index 81426fe..311e425 100644 --- a/libinit/libinit_dalvik_heap.cpp +++ b/libinit/libinit_dalvik_heap.cpp @@ -18,6 +18,34 @@ #define GB(b) (b * 1024ull * 1024 * 1024) + + static const dalvik_heap_info_t dalvik_heap_info_16384 = { + .heapstartsize = "32m", + .heapgrowthlimit = "448m", + .heapsize = "640m", + .heapminfree = "16m", + .heapmaxfree = "64m", + .heaptargetutilization = "0.4", + }; + + static const dalvik_heap_info_t dalvik_heap_info_12288 = { + .heapstartsize = "24m", + .heapgrowthlimit = "384m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "56m", + .heaptargetutilization = "0.42", + }; + + static const dalvik_heap_info_t dalvik_heap_info_8192 = { + .heapstartsize = "24m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "48m", + .heaptargetutilization = "0.46", + }; + static const dalvik_heap_info_t dalvik_heap_info_6144 = { .heapstartsize = "16m", .heapgrowthlimit = "256m", @@ -51,7 +79,13 @@ sysinfo(&sys); - if (sys.totalram > GB(5)) + if (sys.totalram > GB(15)) + dhi = &dalvik_heap_info_16384; + else if (sys.totalram > GB(11)) + dhi = &dalvik_heap_info_12288; + else if (sys.totalram > GB(7)) + dhi = &dalvik_heap_info_8192; + else if (sys.totalram > GB(5)) dhi = &dalvik_heap_info_6144; else if (sys.totalram > GB(3)) dhi = &dalvik_heap_info_4096; From e7aba84e6ec0659ca84c456be9a8715d850f1804 Mon Sep 17 00:00:00 2001 From: EliasTheGrandMasterOfMistakes Date: Thu, 5 Jun 2025 00:46:27 -0300 Subject: [PATCH 4/9] waydroid: libinit: Enable ro.config.low_ram on low ram devices When a device with low ram (6GB or lower) we can just enable "ro.config.low_ram" which will reduce memory usage --- libinit/libinit_dalvik_heap.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libinit/libinit_dalvik_heap.cpp b/libinit/libinit_dalvik_heap.cpp index 311e425..eaeaacf 100644 --- a/libinit/libinit_dalvik_heap.cpp +++ b/libinit/libinit_dalvik_heap.cpp @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ - #include + #include "include/libinit_utils.h" +#include #include #include @@ -15,6 +16,7 @@ #define HEAPMINFREE_PROP "dalvik.vm.heapminfree" #define HEAPMAXFREE_PROP "dalvik.vm.heapmaxfree" #define HEAPTARGETUTILIZATION_PROP "dalvik.vm.heaptargetutilization" + #define LOWMEMORYRAM_PROP "ro.config.low_ram" #define GB(b) (b * 1024ull * 1024 * 1024) @@ -98,4 +100,8 @@ property_override(HEAPTARGETUTILIZATION_PROP, dhi->heaptargetutilization); property_override(HEAPMINFREE_PROP, dhi->heapminfree); property_override(HEAPMAXFREE_PROP, dhi->heapmaxfree); + + if (sys.totalram >= GB(5) && sys.totalram <= GB(6)) { + property_override(LOWMEMORYRAM_PROP, "true"); + } } From dd85ff6a99ed77bff9060b19d81d8c66ddd8e0b9 Mon Sep 17 00:00:00 2001 From: EliasTheGrandMasterOfMistakes Date: Thu, 5 Jun 2025 00:53:52 -0300 Subject: [PATCH 5/9] fix: waydroid: libinit: Add initial libinit dalvik's dex2oat manager --- libinit/Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/libinit/Android.bp b/libinit/Android.bp index 54de217..9a2a396 100644 --- a/libinit/Android.bp +++ b/libinit/Android.bp @@ -8,6 +8,7 @@ cc_library_static { name: "libinit_waydroid_waydroid", srcs: [ "libinit_dalvik_heap.cpp", + "libinit_dalvik_vm.cpp", "libinit_utils.cpp", ], whole_static_libs: ["libbase"], From 3b993f295e8699d7eac37eab715f151922c5a272 Mon Sep 17 00:00:00 2001 From: mathieuchartier Date: Wed, 4 Jun 2025 15:46:49 -0300 Subject: [PATCH 6/9] waydroid: set PRODUCT_SYSTEM_SERVER_COMPILER_FILTER Speed profile services and wifi-service to reduce RAM and storage. --- device.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/device.mk b/device.mk index 5cda3fa..6b2f391 100644 --- a/device.mk +++ b/device.mk @@ -230,6 +230,9 @@ PRODUCT_PACKAGES += \ PRODUCT_SOONG_NAMESPACES += \ $(LOCAL_PATH) +# Speed profile services and wifi-service to reduce RAM and storage.Add commentMore actions +PRODUCT_SYSTEM_SERVER_COMPILER_FILTER := speed-profile + # Binder IPC PRODUCT_PACKAGES += \ vndservicemanager From 6c3d7b413f96d241ff4a647fa8c9fe2d27841e66 Mon Sep 17 00:00:00 2001 From: nnippon99 Date: Wed, 4 Jun 2025 15:49:07 -0300 Subject: [PATCH 7/9] waydroid: set PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK to true Signed-off-by: nnippon99 --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index 6b2f391..797bd95 100644 --- a/device.mk +++ b/device.mk @@ -232,6 +232,7 @@ PRODUCT_SOONG_NAMESPACES += \ # Speed profile services and wifi-service to reduce RAM and storage.Add commentMore actions PRODUCT_SYSTEM_SERVER_COMPILER_FILTER := speed-profile +PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK := true # Binder IPC PRODUCT_PACKAGES += \ From d9fc9eb53bb20cebee07747e81376046078de17c Mon Sep 17 00:00:00 2001 From: ghostrider-reborn Date: Wed, 4 Jun 2025 15:55:06 -0300 Subject: [PATCH 8/9] waydroid: Speed preopt Settings & SystemUI - Add Settings & SystemUI The default ART setting is quicken: run DEX code verification and optimize some DEX instructions to get better interpreter performance. This commit switches performance critical applications to speed: run DEX code verification and AOT-compile all methods. PRODUCT_DEXPREOPT_SPEED_APPS (New in Android O) List of applications that have been identified as core to the products and which are desirable to compile with the speed compiler filter. For example, persistent apps such as SystemUI get a chance to use profile-guided compilation only at the next reboot, so it may be better for the product to have these apps always AOT-compiled. Signed-off-by: DarkAngelGR --- device.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/device.mk b/device.mk index 797bd95..d945c6a 100644 --- a/device.mk +++ b/device.mk @@ -210,6 +210,11 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute.xml \ frameworks/native/data/etc/android.software.freeform_window_management.xml:system/etc/permissions/android.software.freeform_window_management.xml +# Preopt critical applications +PRODUCT_DEXPREOPT_SPEED_APPS += \ + Settings \ + SystemUI + # Power PRODUCT_PACKAGES += \ android.hardware.power@1.0-service.waydroid From 5549e7847033bae81938525b66b07c5b5ab3dea9 Mon Sep 17 00:00:00 2001 From: EliasTheGrandMasterOfMistakes Date: Wed, 4 Jun 2025 15:03:01 -0300 Subject: [PATCH 9/9] waydroid: prop: Remove Dalvik Heap properties --- system.prop | 8 -------- 1 file changed, 8 deletions(-) diff --git a/system.prop b/system.prop index de8cf1d..59fc812 100644 --- a/system.prop +++ b/system.prop @@ -5,14 +5,6 @@ import /vendor_extra/build.prop vendor.gralloc.disable_ubwc af.thread.throttle=false audio.deep_buffer.media=true -# Provides overrides to configure the Dalvik heap for a 4GB phone -dalvik.vm.heapstartsize=8m -dalvik.vm.heapgrowthlimit=192m -dalvik.vm.heapsize=512m -dalvik.vm.heaptargetutilization=0.6 -dalvik.vm.heapminfree=8m -dalvik.vm.heapmaxfree=16m - # SurfaceFlinger ro.surface_flinger.max_frame_buffer_acquired_buffers=3 ro.surface_flinger.running_without_sync_framework=true