From aa719bb3e3b0c85037c9d4c644b2e8da6de22950 Mon Sep 17 00:00:00 2001 From: Rick Yiu Date: Sat, 21 Dec 2024 15:38:18 +0000 Subject: [PATCH 01/14] Remove ResetUclamp profiles Replaced with sched qos profiles. Bug: 355612114 Flag: NONE vendor task_profiles.json does not support flag Test: build pass Change-Id: Ib3ade136be980afeed5c63fbc88bac8cdcc2a4c5 --- task_profiles.json | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/task_profiles.json b/task_profiles.json index 103ff202..e02ea3ef 100644 --- a/task_profiles.json +++ b/task_profiles.json @@ -461,34 +461,6 @@ } ] }, - { - "Name": "ResetUclampGrp", - "Actions": [ - { - "Name": "WriteFile", - "Params": - { - "FilePath": "/proc/vendor_sched/uclamp_fork_reset_set", - "Value": "", - "LogFailures": "false" - } - } - ] - }, - { - "Name": "NoResetUclampGrp", - "Actions": [ - { - "Name": "WriteFile", - "Params": - { - "FilePath": "/proc/vendor_sched/uclamp_fork_reset_clear", - "Value": "", - "LogFailures": "false" - } - } - ] - }, { "Name": "HighestCfsPrioScheduling", "Actions": [ From 6864f9f43ba6b723c7ab9b63c9fc0eeda00f083a Mon Sep 17 00:00:00 2001 From: Yi-Yo Chiang Date: Thu, 9 Jan 2025 18:42:06 +0800 Subject: [PATCH 02/14] init-display-sh: Allow writing to kmsg modprobe would log errors to /dev/kmsg, need to explicit allow this. Bug: 388717752 Test: DeviceBootTest#SELinuxUncheckedDenialBootTest Change-Id: Iecb9d45e5ef08edc04c87d8f1375803c1df11621 --- conf/init.gs101.rc | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/init.gs101.rc b/conf/init.gs101.rc index 0edace57..2dfb64f7 100644 --- a/conf/init.gs101.rc +++ b/conf/init.gs101.rc @@ -794,6 +794,7 @@ service init_display /vendor/bin/init.display.sh group root system disabled oneshot + file /dev/kmsg w # bugreport is triggered by holding down volume down, volume up and power service bugreport /system/bin/dumpstate -d -p -z From 2c0ef869dffcb8f6b19eb921f6fa31027b5e9df6 Mon Sep 17 00:00:00 2001 From: Spade Lee Date: Fri, 27 Dec 2024 06:58:24 +0000 Subject: [PATCH 03/14] pixelstats: gs101: remove firmware update path Bug: 386187651 Test: local test pass Flag: EXEMPT refactor Change-Id: I2886e26186b12ffe34df6aa559bdf66e3e8f059d Signed-off-by: Spade Lee --- pixelstats/service.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index d8461466..94e15ca4 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -86,8 +86,7 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { const struct UeventListener::UeventPaths ueventPaths = { .AudioUevent = "/devices/virtual/amcs/amcs", - .TypeCPartnerUevent = "PRODUCT_TYPE=", - .FwUpdatePath = "" + .TypeCPartnerUevent = "PRODUCT_TYPE=" }; int main() { From 470aae4369627805feaa5922d1f34c27ce391541 Mon Sep 17 00:00:00 2001 From: Isaac Chiou Date: Thu, 14 Nov 2024 06:06:26 +0000 Subject: [PATCH 04/14] Enable open source multi akm for specific Broadcom project For cross akm roaming function, we have two ways in supplicant : 1. Open source way. 2. Broadcom specific way. Originally, Broadcom projects follow way 2 due to the limitation of the driver. For now, we plan to move all Broadcom projects to follow way 1 to make supplicant code clean and downsteam without conflict. For those projects which is ready for way 1, we control it to follow way 1 with WIFI_BRCM_OPEN_SOURCE_MULTI_AKM config. For the rest of Broadcom projects, we still follow way 2 until the multiple AKMs is fully supported by driver and verified. For ongoing Broadcom project, we also need to exercise the open source path in supplicant to do multiple AKM configuration to comply with WFA Wifi 7 AKM24 specification (b/331896542 ). Bug: 246871098 Test: AU drop test Test: Cross AKM roaming test Flag: EXEMPT enable control flag for aosp akms Change-Id: I2594e3741d5be1c055d364104639b3d55336a5a7 --- wifi/BoardConfig-wifi.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/wifi/BoardConfig-wifi.mk b/wifi/BoardConfig-wifi.mk index d484ad03..49245203 100644 --- a/wifi/BoardConfig-wifi.mk +++ b/wifi/BoardConfig-wifi.mk @@ -31,6 +31,7 @@ WIFI_AVOID_IFACE_RESET_MAC_CHANGE := true WIFI_FEATURE_HOSTAPD_11AX := true BOARD_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL := true WIFI_HIDL_UNIFIED_SUPPLICANT_SERVICE_RC_ENTRY := true +WIFI_BRCM_OPEN_SOURCE_MULTI_AKM := enabled # Add WIFI_FEATURE_IMU_DETECTION to soong_config $(call soong_config_set,wifi,feature_imu_detection,$(WIFI_FEATURE_IMU_DETECTION)) From 992d32e3182491d67aab8bb3175990f135e0a06e Mon Sep 17 00:00:00 2001 From: Piotr Klasa Date: Wed, 8 Jan 2025 17:42:39 +0100 Subject: [PATCH 05/14] move common init perf settings to gs_common MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: Verified if all values ​​of transferred settings are as they should be after rebooting the device, and and checked that there are no new selinux errors for hal_power_default Bug: 335874870 Flag: EXEMPT not supported by this component yet Change-Id: I7054fb3ab6f8fce9cf06c7691e8e1aea2453ca88 --- conf/init.gs101.rc | 59 ---------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/conf/init.gs101.rc b/conf/init.gs101.rc index 3870571b..d36b49a3 100644 --- a/conf/init.gs101.rc +++ b/conf/init.gs101.rc @@ -11,8 +11,6 @@ on init # CPU0 cannot be offline chmod 0444 /sys/devices/system/cpu/cpu0/online - # Set teo as cpu idle governor - write /sys/devices/system/cpu/cpuidle/current_governor teo # Disable util-awareness write /proc/vendor_sched/teo_util_threshold "1024 1024 1024" @@ -104,15 +102,6 @@ on init write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/memlat_cpuidle_state_aware 2 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware 2 - # RT uclamp setting - write /proc/sys/kernel/sched_util_clamp_min_rt_default 0 - - # change permissions and default values for camera-daemon cpu controller - chown system system /dev/cpuctl/camera-daemon/cpu.uclamp.min - chown system system /dev/cpuctl/camera-daemon/cpu.uclamp.max - chown root root /dev/cpuctl/camera-daemon/cpu.uclamp.latency_sensitive - chown system system /dev/cpuctl/camera-daemon/cgroup.procs - mkdir /dev/cpuset/camera-daemon-high-group write /dev/cpuset/camera-daemon-high-group/cpus 0-7 write /dev/cpuset/camera-daemon-high-group/mems 0 @@ -131,11 +120,6 @@ on init chown system system /dev/cpuset/camera-daemon-mid-high-group/tasks chmod 0664 /dev/cpuset/camera-daemon-mid-high-group/tasks - write /proc/vendor_sched/groups/cam/prefer_idle 1 - write /proc/vendor_sched/groups/cam/uclamp_min 1 - - chown system system /dev/cpuset/cgroup.procs - # nanohub sensor chmod 0664 /dev/nanohub chmod 0664 /dev/nanohub_comms @@ -251,10 +235,6 @@ on init # Power Stats HAL chown system system /dev/bbd_pwrstat - # Add a boost for NNAPI HAL - write /proc/vendor_sched/groups/nnapi/prefer_idle 0 - write /proc/vendor_sched/groups/nnapi/uclamp_min 512 - # Add memlat governor settings write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/polling_interval 10 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/polling_interval 10 @@ -636,27 +616,6 @@ on property:sys.boot_completed=1 write /dev/cpuset/camera-daemon/cpus ${persist.device_config.vendor_system_native.camera-daemon_cpuset:-0-7} setprop vendor.powerhal.init 1 - # Setup scheduler parameters - write /proc/vendor_sched/min_granularity_ns 1000000 - write /proc/vendor_sched/latency_ns 8000000 - write /proc/vendor_sched/max_load_balance_interval 1 - write /proc/vendor_sched/enable_hrtick 1 - - # Setup final cpu.uclamp - write /proc/vendor_sched/groups/ta/uclamp_min 1 - write /proc/vendor_sched/groups/fg/uclamp_min 0 - write /proc/vendor_sched/groups/sys/prefer_idle 0 - - # Set ug group - write /proc/vendor_sched/groups/bg/ug 0 - write /proc/vendor_sched/groups/sys_bg/ug 0 - write /proc/vendor_sched/groups/ota/ug 0 - write /proc/vendor_sched/groups/dex2oat/ug 1 - write /proc/vendor_sched/groups/ta/ug 1 - - # Set bg group throttle - write /proc/vendor_sched/ug_bg_group_throttle ${persist.device_config.vendor_system_native.ug_bg_group_throttle:-308} - # Set uclamp.max for some groups, which could indicate cpu importance used in scheduling write /proc/vendor_sched/groups/bg/uclamp_max 512 write /proc/vendor_sched/groups/sys_bg/uclamp_max 512 @@ -675,24 +634,6 @@ on property:sys.boot_completed=1 write /sys/devices/system/cpu/cpufreq/policy6/sched_pixel/limit_frequency 2507000 write /proc/vendor_sched/pmu_poll_time 10 - # Disable PMU freq limit - write /sys/devices/system/cpu/cpufreq/policy0/sched_pixel/pmu_limit_enable 1 - write /sys/devices/system/cpu/cpufreq/policy4/sched_pixel/pmu_limit_enable 1 - write /sys/devices/system/cpu/cpufreq/policy6/sched_pixel/pmu_limit_enable 1 - write /proc/vendor_sched/pmu_poll_enable 0 - - # Setup cpu.shares to throttle background groups (bg ~ 5% sysbg ~ 5% dex2oat ~2.5%) - write /dev/cpuctl/background/cpu.shares 1024 - write /dev/cpuctl/system-background/cpu.shares 1024 - write /dev/cpuctl/dex2oat/cpu.shares 512 - write /dev/cpuctl/system/cpu.shares 20480 - # We only have system and background groups holding tasks and the groups below are empty - write /dev/cpuctl/camera-daemon/cpu.shares 20480 - write /dev/cpuctl/foreground/cpu.shares 20480 - write /dev/cpuctl/nnapi-hal/cpu.shares 20480 - write /dev/cpuctl/rt/cpu.shares 20480 - write /dev/cpuctl/top-app/cpu.shares 20480 - # gvotables for dumpstate chown system system /sys/kernel/debug/gvotables From b60a6a9f8936ea105c57c5a656cce89c3958e041 Mon Sep 17 00:00:00 2001 From: Piotr Klasa Date: Fri, 17 Jan 2025 09:05:39 -0800 Subject: [PATCH 06/14] Revert "move common init perf settings to gs_common" Revert submission 31215196-move_common_init_perf_settings_to_gscommon Reason for revert: Power Regression Reverted changes: /q/submissionid:31215196-move_common_init_perf_settings_to_gscommon Bug: 390502171 Change-Id: I9e88aecf6ed56d1d2171d379f16f215b4a135547 --- conf/init.gs101.rc | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/conf/init.gs101.rc b/conf/init.gs101.rc index 6ab01ad2..677231cd 100644 --- a/conf/init.gs101.rc +++ b/conf/init.gs101.rc @@ -11,6 +11,8 @@ on init # CPU0 cannot be offline chmod 0444 /sys/devices/system/cpu/cpu0/online + # Set teo as cpu idle governor + write /sys/devices/system/cpu/cpuidle/current_governor teo # Disable util-awareness write /proc/vendor_sched/teo_util_threshold "1024 1024 1024" @@ -102,6 +104,15 @@ on init write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/memlat_cpuidle_state_aware 2 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware 2 + # RT uclamp setting + write /proc/sys/kernel/sched_util_clamp_min_rt_default 0 + + # change permissions and default values for camera-daemon cpu controller + chown system system /dev/cpuctl/camera-daemon/cpu.uclamp.min + chown system system /dev/cpuctl/camera-daemon/cpu.uclamp.max + chown root root /dev/cpuctl/camera-daemon/cpu.uclamp.latency_sensitive + chown system system /dev/cpuctl/camera-daemon/cgroup.procs + mkdir /dev/cpuset/camera-daemon-high-group write /dev/cpuset/camera-daemon-high-group/cpus 0-7 write /dev/cpuset/camera-daemon-high-group/mems 0 @@ -120,6 +131,11 @@ on init chown system system /dev/cpuset/camera-daemon-mid-high-group/tasks chmod 0664 /dev/cpuset/camera-daemon-mid-high-group/tasks + write /proc/vendor_sched/groups/cam/prefer_idle 1 + write /proc/vendor_sched/groups/cam/uclamp_min 1 + + chown system system /dev/cpuset/cgroup.procs + # nanohub sensor chmod 0664 /dev/nanohub chmod 0664 /dev/nanohub_comms @@ -235,6 +251,10 @@ on init # Power Stats HAL chown system system /dev/bbd_pwrstat + # Add a boost for NNAPI HAL + write /proc/vendor_sched/groups/nnapi/prefer_idle 0 + write /proc/vendor_sched/groups/nnapi/uclamp_min 512 + # Add memlat governor settings write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/polling_interval 10 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/polling_interval 10 @@ -616,6 +636,27 @@ on property:sys.boot_completed=1 write /dev/cpuset/camera-daemon/cpus ${persist.device_config.vendor_system_native.camera-daemon_cpuset:-0-7} setprop vendor.powerhal.init 1 + # Setup scheduler parameters + write /proc/vendor_sched/min_granularity_ns 1000000 + write /proc/vendor_sched/latency_ns 8000000 + write /proc/vendor_sched/max_load_balance_interval 1 + write /proc/vendor_sched/enable_hrtick 1 + + # Setup final cpu.uclamp + write /proc/vendor_sched/groups/ta/uclamp_min 1 + write /proc/vendor_sched/groups/fg/uclamp_min 0 + write /proc/vendor_sched/groups/sys/prefer_idle 0 + + # Set ug group + write /proc/vendor_sched/groups/bg/ug 0 + write /proc/vendor_sched/groups/sys_bg/ug 0 + write /proc/vendor_sched/groups/ota/ug 0 + write /proc/vendor_sched/groups/dex2oat/ug 1 + write /proc/vendor_sched/groups/ta/ug 1 + + # Set bg group throttle + write /proc/vendor_sched/ug_bg_group_throttle ${persist.device_config.vendor_system_native.ug_bg_group_throttle:-308} + # Set uclamp.max for some groups, which could indicate cpu importance used in scheduling write /proc/vendor_sched/groups/bg/uclamp_max 512 write /proc/vendor_sched/groups/sys_bg/uclamp_max 512 @@ -634,6 +675,24 @@ on property:sys.boot_completed=1 write /sys/devices/system/cpu/cpufreq/policy6/sched_pixel/limit_frequency 2507000 write /proc/vendor_sched/pmu_poll_time 10 + # Disable PMU freq limit + write /sys/devices/system/cpu/cpufreq/policy0/sched_pixel/pmu_limit_enable 1 + write /sys/devices/system/cpu/cpufreq/policy4/sched_pixel/pmu_limit_enable 1 + write /sys/devices/system/cpu/cpufreq/policy6/sched_pixel/pmu_limit_enable 1 + write /proc/vendor_sched/pmu_poll_enable 0 + + # Setup cpu.shares to throttle background groups (bg ~ 5% sysbg ~ 5% dex2oat ~2.5%) + write /dev/cpuctl/background/cpu.shares 1024 + write /dev/cpuctl/system-background/cpu.shares 1024 + write /dev/cpuctl/dex2oat/cpu.shares 512 + write /dev/cpuctl/system/cpu.shares 20480 + # We only have system and background groups holding tasks and the groups below are empty + write /dev/cpuctl/camera-daemon/cpu.shares 20480 + write /dev/cpuctl/foreground/cpu.shares 20480 + write /dev/cpuctl/nnapi-hal/cpu.shares 20480 + write /dev/cpuctl/rt/cpu.shares 20480 + write /dev/cpuctl/top-app/cpu.shares 20480 + # gvotables for dumpstate chown system system /sys/kernel/debug/gvotables From b2592019c9847ada0568a897c6a4dae51f571bc4 Mon Sep 17 00:00:00 2001 From: Piotr Klasa Date: Wed, 22 Jan 2025 11:26:04 +0000 Subject: [PATCH 07/14] move common init perf settings to gs_common MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit compared to ag/31352563 I did not transfer the settings for "write /sys/devices/system/cpu/cpuidle/current_governor teo", which caused the problem Test: Verified if all values ​​of transferred settings are as they should be after rebooting the device, and and checked that there are no new selinux errors for hal_power_default, verified all metrics that caused power regression in the previous commit on abtd Bug: 335874870 Flag: EXEMPT not supported by this component yet Change-Id: I7ad8dbd7fd2783017c5bae8181008db32b95e9b7 --- conf/init.gs101.rc | 57 ---------------------------------------------- 1 file changed, 57 deletions(-) diff --git a/conf/init.gs101.rc b/conf/init.gs101.rc index 677231cd..5da72b96 100644 --- a/conf/init.gs101.rc +++ b/conf/init.gs101.rc @@ -104,15 +104,6 @@ on init write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/memlat_cpuidle_state_aware 2 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware 2 - # RT uclamp setting - write /proc/sys/kernel/sched_util_clamp_min_rt_default 0 - - # change permissions and default values for camera-daemon cpu controller - chown system system /dev/cpuctl/camera-daemon/cpu.uclamp.min - chown system system /dev/cpuctl/camera-daemon/cpu.uclamp.max - chown root root /dev/cpuctl/camera-daemon/cpu.uclamp.latency_sensitive - chown system system /dev/cpuctl/camera-daemon/cgroup.procs - mkdir /dev/cpuset/camera-daemon-high-group write /dev/cpuset/camera-daemon-high-group/cpus 0-7 write /dev/cpuset/camera-daemon-high-group/mems 0 @@ -131,11 +122,6 @@ on init chown system system /dev/cpuset/camera-daemon-mid-high-group/tasks chmod 0664 /dev/cpuset/camera-daemon-mid-high-group/tasks - write /proc/vendor_sched/groups/cam/prefer_idle 1 - write /proc/vendor_sched/groups/cam/uclamp_min 1 - - chown system system /dev/cpuset/cgroup.procs - # nanohub sensor chmod 0664 /dev/nanohub chmod 0664 /dev/nanohub_comms @@ -251,10 +237,6 @@ on init # Power Stats HAL chown system system /dev/bbd_pwrstat - # Add a boost for NNAPI HAL - write /proc/vendor_sched/groups/nnapi/prefer_idle 0 - write /proc/vendor_sched/groups/nnapi/uclamp_min 512 - # Add memlat governor settings write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/polling_interval 10 write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010/polling_interval 10 @@ -636,27 +618,6 @@ on property:sys.boot_completed=1 write /dev/cpuset/camera-daemon/cpus ${persist.device_config.vendor_system_native.camera-daemon_cpuset:-0-7} setprop vendor.powerhal.init 1 - # Setup scheduler parameters - write /proc/vendor_sched/min_granularity_ns 1000000 - write /proc/vendor_sched/latency_ns 8000000 - write /proc/vendor_sched/max_load_balance_interval 1 - write /proc/vendor_sched/enable_hrtick 1 - - # Setup final cpu.uclamp - write /proc/vendor_sched/groups/ta/uclamp_min 1 - write /proc/vendor_sched/groups/fg/uclamp_min 0 - write /proc/vendor_sched/groups/sys/prefer_idle 0 - - # Set ug group - write /proc/vendor_sched/groups/bg/ug 0 - write /proc/vendor_sched/groups/sys_bg/ug 0 - write /proc/vendor_sched/groups/ota/ug 0 - write /proc/vendor_sched/groups/dex2oat/ug 1 - write /proc/vendor_sched/groups/ta/ug 1 - - # Set bg group throttle - write /proc/vendor_sched/ug_bg_group_throttle ${persist.device_config.vendor_system_native.ug_bg_group_throttle:-308} - # Set uclamp.max for some groups, which could indicate cpu importance used in scheduling write /proc/vendor_sched/groups/bg/uclamp_max 512 write /proc/vendor_sched/groups/sys_bg/uclamp_max 512 @@ -675,24 +636,6 @@ on property:sys.boot_completed=1 write /sys/devices/system/cpu/cpufreq/policy6/sched_pixel/limit_frequency 2507000 write /proc/vendor_sched/pmu_poll_time 10 - # Disable PMU freq limit - write /sys/devices/system/cpu/cpufreq/policy0/sched_pixel/pmu_limit_enable 1 - write /sys/devices/system/cpu/cpufreq/policy4/sched_pixel/pmu_limit_enable 1 - write /sys/devices/system/cpu/cpufreq/policy6/sched_pixel/pmu_limit_enable 1 - write /proc/vendor_sched/pmu_poll_enable 0 - - # Setup cpu.shares to throttle background groups (bg ~ 5% sysbg ~ 5% dex2oat ~2.5%) - write /dev/cpuctl/background/cpu.shares 1024 - write /dev/cpuctl/system-background/cpu.shares 1024 - write /dev/cpuctl/dex2oat/cpu.shares 512 - write /dev/cpuctl/system/cpu.shares 20480 - # We only have system and background groups holding tasks and the groups below are empty - write /dev/cpuctl/camera-daemon/cpu.shares 20480 - write /dev/cpuctl/foreground/cpu.shares 20480 - write /dev/cpuctl/nnapi-hal/cpu.shares 20480 - write /dev/cpuctl/rt/cpu.shares 20480 - write /dev/cpuctl/top-app/cpu.shares 20480 - # gvotables for dumpstate chown system system /sys/kernel/debug/gvotables From ada24418c9dbd39c22ef6cf2be24195b9926c41f Mon Sep 17 00:00:00 2001 From: Masha Chizhova Date: Tue, 28 Jan 2025 16:43:46 +0000 Subject: [PATCH 08/14] Use 2025-03-01 deqp levels for GLES and Vulkan Bug: 392805030 Flag: EXEMPT version updates Change-Id: Ib67709eee81a5519c3f0c0b42b4625472f54a881 --- device.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device.mk b/device.mk index 8d097bae..e22531d6 100644 --- a/device.mk +++ b/device.mk @@ -257,8 +257,8 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.vulkan.version-1_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \ frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \ 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.vulkan.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ - frameworks/native/data/etc/android.software.opengles.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml + frameworks/native/data/etc/android.software.vulkan.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ + frameworks/native/data/etc/android.software.opengles.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml ifeq ($(USE_SWIFTSHADER),true) PRODUCT_VENDOR_PROPERTIES += \ From 2306f2cd7f054a0392adf4acad0cffa94a56e191 Mon Sep 17 00:00:00 2001 From: "Priyanka Advani (xWF)" Date: Thu, 30 Jan 2025 10:53:05 -0800 Subject: [PATCH 09/14] Revert "Use 2025-03-01 deqp levels for GLES and Vulkan" Revert submission 31488081-deqp-2025-03-01 Reason for revert: Droidmonitor created revert due to b/393355394. Will be verifying through ABTD before submission. Reverted changes: /q/submissionid:31488081-deqp-2025-03-01 Change-Id: I054aaf0583ab9d4976514ac46917b661a494e186 --- device.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device.mk b/device.mk index e22531d6..8d097bae 100644 --- a/device.mk +++ b/device.mk @@ -257,8 +257,8 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.vulkan.version-1_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \ frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \ 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.vulkan.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ - frameworks/native/data/etc/android.software.opengles.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml + frameworks/native/data/etc/android.software.vulkan.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ + frameworks/native/data/etc/android.software.opengles.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml ifeq ($(USE_SWIFTSHADER),true) PRODUCT_VENDOR_PROPERTIES += \ From 9b7a38fb7b4591520359dbcb6f92171b4613a906 Mon Sep 17 00:00:00 2001 From: Masha Chizhova Date: Fri, 31 Jan 2025 10:48:15 +0000 Subject: [PATCH 10/14] Use 2025-03-01 deqp levels for Vulkan Bug: 392805030 Flag: EXEMPT version updates Change-Id: Ib63b918fd1c67d4bfd751624f435d8a02798c2ac --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 8d097bae..adb2b66c 100644 --- a/device.mk +++ b/device.mk @@ -257,7 +257,7 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.vulkan.version-1_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \ frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \ 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.vulkan.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ + frameworks/native/data/etc/android.software.vulkan.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ frameworks/native/data/etc/android.software.opengles.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml ifeq ($(USE_SWIFTSHADER),true) From b70d478bfbc67a333ccbedc3fe893353feb5c5f2 Mon Sep 17 00:00:00 2001 From: Masha Chizhova Date: Mon, 3 Feb 2025 11:24:38 +0000 Subject: [PATCH 11/14] Use 2025-03-01 deqp level for GLES Bug: 392805030 Flag: EXEMPT version updates Change-Id: I474efd47391012424cba1e3e3549da00b23a4753 --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index adb2b66c..e22531d6 100644 --- a/device.mk +++ b/device.mk @@ -258,7 +258,7 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \ 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.vulkan.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ - frameworks/native/data/etc/android.software.opengles.deqp.level-2024-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml + frameworks/native/data/etc/android.software.opengles.deqp.level-2025-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml ifeq ($(USE_SWIFTSHADER),true) PRODUCT_VENDOR_PROPERTIES += \ From e61b6804088a1556657fb608939e6f0eb5f56b5b Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Thu, 23 Jan 2025 05:22:58 +0000 Subject: [PATCH 12/14] usb: migrate UsbDataSessionMonitor to libpixelusb Use the libpixelusb version of UsbDataSessionMonitor. Bug: 388367091 Test: test on oriole Flag: EXEMPT CP Change-Id: I93b74fc9bb63c260e900ee5af73e66fb1559142d --- usb/usb/Android.bp | 10 +- usb/usb/Usb.cpp | 8 +- usb/usb/Usb.h | 5 +- usb/usb/UsbDataSessionMonitor.cpp | 508 ------------------------------ usb/usb/UsbDataSessionMonitor.h | 117 ------- 5 files changed, 9 insertions(+), 639 deletions(-) delete mode 100644 usb/usb/UsbDataSessionMonitor.cpp delete mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index fa7a07f7..6e64fe77 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -32,7 +32,6 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", - "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", @@ -56,18 +55,13 @@ cc_binary { ], static_libs: [ "libpixelusb", + "libpixelusb-datasession", "libpixelstats", "libthermalutils", - "android.hardware.usb.flags-aconfig-c-lib", + "android.hardware.usb.flags-aconfig-cc-lib", ], export_shared_lib_headers: [ "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", ], } - -cc_aconfig_library { - name: "android.hardware.usb.flags-aconfig-c-lib", - vendor: true, - aconfig_declarations: "android.hardware.usb.flags-aconfig", -} diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index ab7932ba..3650c5b5 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -533,9 +533,9 @@ Usb::Usb() mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), - mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, - kHost2UeventRegex, kHost2StatePath, kDataRolePath, - std::bind(&updatePortStatus, this)), + mUsbDataSessionMonitor(new UsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, + kHost1UeventRegex, kHost1StatePath, kHost2UeventRegex, + kHost2StatePath, kDataRolePath, std::bind(&updatePortStatus, this))), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -930,7 +930,7 @@ void queryUsbDataSession(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { std::vector warnings; - usb->mUsbDataSessionMonitor.getComplianceWarnings( + usb->mUsbDataSessionMonitor->getComplianceWarnings( (*currentPortStatus)[0].currentDataRole, &warnings); (*currentPortStatus)[0].complianceWarnings.insert( (*currentPortStatus)[0].complianceWarnings.end(), diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 15348af0..adab1951 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,9 +19,9 @@ #include #include #include +#include #include #include -#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -39,6 +39,7 @@ using ::aidl::android::hardware::usb::IUsbCallback; using ::aidl::android::hardware::usb::PortRole; using ::android::base::ReadFileToString; using ::android::base::WriteStringToFile; +using ::android::hardware::google::pixel::usb::UsbDataSessionMonitor; using ::android::hardware::google::pixel::usb::UsbOverheatEvent; using ::android::hardware::google::pixel::usb::ZoneInfo; using ::android::hardware::thermal::V2_0::TemperatureType; @@ -87,7 +88,7 @@ struct Usb : public BnUsb { bool mPartnerUp; // Report usb data session event and data incompliance warnings - UsbDataSessionMonitor mUsbDataSessionMonitor; + std::unique_ptr mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp deleted file mode 100644 index bff52f06..00000000 --- a/usb/usb/UsbDataSessionMonitor.cpp +++ /dev/null @@ -1,508 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" - -#include "UsbDataSessionMonitor.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace usb_flags = android::hardware::usb::flags; - -using aidl::android::frameworks::stats::IStats; -using android::base::ReadFileToString; -using android::hardware::google::pixel::getStatsService; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::usb::addEpollFd; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; - -namespace aidl { -namespace android { -namespace hardware { -namespace usb { - -#define UEVENT_MSG_LEN 2048 -#define USB_STATE_MAX_LEN 20 -#define DATA_ROLE_MAX_LEN 10 -#define WARNING_SURFACE_DELAY_SEC 5 -#define ENUM_FAIL_DEFAULT_COUNT_THRESHOLD 3 -#define DEVICE_FLAKY_CONNECTION_CONFIGURED_COUNT_THRESHOLD 5 - -constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; -constexpr char kNotAttachedState[] = "not attached\n"; -constexpr char kAttachedState[] = "attached\n"; -constexpr char kPoweredState[] = "powered\n"; -constexpr char kDefaultState[] = "default\n"; -constexpr char kAddressedState[] = "addressed\n"; -constexpr char kConfiguredState[] = "configured\n"; -constexpr char kSuspendedState[] = "suspended\n"; -const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, - kDefaultState, kAddressedState, kConfiguredState, - kSuspendedState}; - -static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { - struct epoll_event ev; - - unique_fd fd(open(filePath.c_str(), O_RDONLY)); - - if (fd.get() == -1) { - ALOGI("Cannot open %s", filePath.c_str()); - return -1; - } - - ev.data.fd = fd.get(); - ev.events = EPOLLPRI; - - if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - return -1; - } - - fileFd = std::move(fd); - ALOGI("epoll registered %s", filePath.c_str()); - return 0; -} - -static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { - epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); - fileFd.release(); - - ALOGI("epoll unregistered %s", filePath.c_str()); -} - -UsbDataSessionMonitor::UsbDataSessionMonitor( - const std::string &deviceUeventRegex, const std::string &deviceStatePath, - const std::string &host1UeventRegex, const std::string &host1StatePath, - const std::string &host2UeventRegex, const std::string &host2StatePath, - const std::string &dataRolePath, std::function updatePortStatusCb) { - struct epoll_event ev; - std::string udc; - - unique_fd epollFd(epoll_create(8)); - if (epollFd.get() == -1) { - ALOGE("epoll_create failed; errno=%d", errno); - abort(); - } - - unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); - if (ueventFd.get() == -1) { - ALOGE("uevent_open_socket failed"); - abort(); - } - fcntl(ueventFd, F_SETFL, O_NONBLOCK); - - if (addEpollFd(epollFd, ueventFd)) - abort(); - - unique_fd timerFd(timerfd_create(CLOCK_BOOTTIME, TFD_NONBLOCK)); - if (timerFd.get() == -1) { - ALOGE("create timerFd failed"); - abort(); - } - - if (addEpollFd(epollFd, timerFd)) - abort(); - - if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { - ALOGE("monitor data role failed"); - abort(); - } - - /* - * The device state file could be absent depending on the current data role - * and driver architecture. It's ok for addEpollFile to fail here, the file - * will be monitored later when its presence is detected by uevent. - */ - mDeviceState.filePath = deviceStatePath; - mDeviceState.ueventRegex = deviceUeventRegex; - addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); - - mHost1State.filePath = host1StatePath; - mHost1State.ueventRegex = host1UeventRegex; - addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); - - mHost2State.filePath = host2StatePath; - mHost2State.ueventRegex = host2UeventRegex; - addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); - - mEpollFd = std::move(epollFd); - mUeventFd = std::move(ueventFd); - mTimerFd = std::move(timerFd); - mUpdatePortStatusCb = updatePortStatusCb; - - if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) - mUdcBind = true; - else - mUdcBind = false; - - if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { - ALOGE("pthread creation failed %d", errno); - abort(); - } - - ALOGI("feature flag enable_report_usb_data_compliance_warning: %d", - usb_flags::enable_report_usb_data_compliance_warning()); -} - -UsbDataSessionMonitor::~UsbDataSessionMonitor() {} - -void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { - std::vector events; - - if (mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, - &mDeviceState.states, &mDeviceState.timestamps, &event); - events.push_back(event); - } else if (mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto e : {&mHost1State, &mHost2State}) { - /* - * Host port will at least get an not_attached event after enablement, - * skip upload if no additional state is added. - */ - if (e->states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), - mDataSessionStart, &e->states, &e->timestamps, - &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, - &mHost1State.states, &mHost1State.timestamps, &event); - events.push_back(event); - } - } else { - return; - } - - const std::shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - -void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, - std::vector *warnings) { - if (!usb_flags::enable_report_usb_data_compliance_warning()) - return; - - if (role != mDataRole || role == PortDataRole::NONE) - return; - - for (auto w : mWarningSet) { - warnings->push_back(w); - } -} - -void UsbDataSessionMonitor::notifyComplianceWarning() { - if (!usb_flags::enable_report_usb_data_compliance_warning()) - return; - - if (mUpdatePortStatusCb) - mUpdatePortStatusCb(); -} - -void UsbDataSessionMonitor::evaluateComplianceWarning() { - std::set newWarningSet; - int elapsedTimeSec; - - elapsedTimeSec = - std::chrono::duration_cast(boot_clock::now() - mDataSessionStart) - .count(); - - if (elapsedTimeSec >= WARNING_SURFACE_DELAY_SEC) { - if (mDataRole == PortDataRole::DEVICE && mUdcBind) { - int configuredCount = std::count(mDeviceState.states.begin(), - mDeviceState.states.end(), kConfiguredState); - int defaultCount = - std::count(mDeviceState.states.begin(), mDeviceState.states.end(), kDefaultState); - - if (configuredCount == 0 && defaultCount > ENUM_FAIL_DEFAULT_COUNT_THRESHOLD) - newWarningSet.insert(ComplianceWarning::ENUMERATION_FAIL); - - if (configuredCount > DEVICE_FLAKY_CONNECTION_CONFIGURED_COUNT_THRESHOLD) - newWarningSet.insert(ComplianceWarning::FLAKY_CONNECTION); - } else if (mDataRole == PortDataRole::HOST) { - int host1StateCount = mHost1State.states.size(); - int host1ConfiguredCount = - std::count(mHost1State.states.begin(), mHost1State.states.end(), kConfiguredState); - int host1DefaultCount = - std::count(mHost1State.states.begin(), mHost1State.states.end(), kDefaultState); - int host2StateCount = mHost2State.states.size(); - int host2ConfiguredCount = - std::count(mHost2State.states.begin(), mHost2State.states.end(), kConfiguredState); - int host2DefaultCount = - std::count(mHost2State.states.begin(), mHost2State.states.end(), kDefaultState); - - if (host1ConfiguredCount == 0 && host2ConfiguredCount == 0 && - (host1DefaultCount > ENUM_FAIL_DEFAULT_COUNT_THRESHOLD || - host2DefaultCount > ENUM_FAIL_DEFAULT_COUNT_THRESHOLD)) - newWarningSet.insert(ComplianceWarning::ENUMERATION_FAIL); - - if (host1StateCount == 1 && mHost1State.states.front() == kNotAttachedState && - host2StateCount == 1 && mHost2State.states.front() == kNotAttachedState) - newWarningSet.insert(ComplianceWarning::MISSING_DATA_LINES); - } - } - - if (newWarningSet != mWarningSet) { - std::string newWarningString; - - for (auto e : newWarningSet) { - newWarningString += toString(e) + " "; - } - ALOGI("Usb data compliance warning changed to: %s", newWarningString.c_str()); - - mWarningSet = newWarningSet; - notifyComplianceWarning(); - } -} - -void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { - deviceState->states.clear(); - deviceState->timestamps.clear(); -} - -void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(deviceState->fd.get(), 0, SEEK_SET); - n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); - - if (kValidStates.find(state) == kValidStates.end()) { - ALOGE("Invalid state %s", state); - return; - } - - ALOGI("Update USB device state: %s", state); - - deviceState->states.push_back(state); - deviceState->timestamps.push_back(boot_clock::now()); - evaluateComplianceWarning(); -} - -void UsbDataSessionMonitor::setupNewSession() { - mWarningSet.clear(); - mDataSessionStart = boot_clock::now(); - - if (mDataRole == PortDataRole::DEVICE) { - clearDeviceStateEvents(&mDeviceState); - } else if (mDataRole == PortDataRole::HOST) { - clearDeviceStateEvents(&mHost1State); - clearDeviceStateEvents(&mHost2State); - } - - if (mDataRole != PortDataRole::NONE) { - struct itimerspec delay = itimerspec(); - delay.it_value.tv_sec = WARNING_SURFACE_DELAY_SEC; - int ret = timerfd_settime(mTimerFd.get(), 0, &delay, NULL); - if (ret < 0) - ALOGE("timerfd_settime failed err:%d", errno); - } -} - -void UsbDataSessionMonitor::handleDataRoleEvent() { - int n; - PortDataRole newDataRole; - char role[DATA_ROLE_MAX_LEN] = {0}; - - lseek(mDataRoleFd.get(), 0, SEEK_SET); - n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); - - ALOGI("Update USB data role %s", role); - - if (!std::strcmp(role, "host")) { - newDataRole = PortDataRole::HOST; - } else if (!std::strcmp(role, "device")) { - newDataRole = PortDataRole::DEVICE; - } else { - newDataRole = PortDataRole::NONE; - } - - if (newDataRole != mDataRole) { - // Upload metrics for the last data session that has ended - if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { - reportUsbDataSessionMetrics(); - } - - mDataRole = newDataRole; - setupNewSession(); - } -} - -void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { - std::string function; - bool newUdcBind; - - /* - * /sys/class/udc//function prints out name of currently running USB gadget driver - * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc - * Empty name string means the udc device is not bound and gadget is pulldown. - */ - if (!ReadFileToString("/sys" + devname + "/function", &function)) - return; - - if (function == "") - newUdcBind = false; - else - newUdcBind = true; - - if (newUdcBind == mUdcBind) - return; - - if (mDataRole == PortDataRole::DEVICE) { - if (mUdcBind && !newUdcBind) { - /* - * Gadget soft pulldown: report metrics as the end of a data session and - * re-evaluate compliance warnings to clear existing warnings if any. - */ - reportUsbDataSessionMetrics(); - evaluateComplianceWarning(); - - } else if (!mUdcBind && newUdcBind) { - // Gadget soft pullup: reset and start accounting for a new data session. - setupNewSession(); - } - } - - ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); - mUdcBind = newUdcBind; -} - -void UsbDataSessionMonitor::handleUevent() { - char msg[UEVENT_MSG_LEN + 2]; - char *cp; - int n; - - n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); - if (n <= 0) - return; - if (n >= UEVENT_MSG_LEN) - return; - - msg[n] = '\0'; - msg[n + 1] = '\0'; - cp = msg; - - while (*cp) { - for (auto e : {&mHost1State, &mHost2State}) { - if (std::regex_search(cp, std::regex(e->ueventRegex))) { - if (!strncmp(cp, "bind@", strlen("bind@"))) { - addEpollFile(mEpollFd.get(), e->filePath, e->fd); - } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { - removeEpollFile(mEpollFd.get(), e->filePath, e->fd); - } - } - } - - // TODO: support bind@ unbind@ to detect dynamically allocated udc device - if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { - if (!strncmp(cp, "change@", strlen("change@"))) { - char *devname = cp + strlen("change@"); - /* - * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. - * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually - * executed. Add a short delay to get the correct state while working on a fix - * upstream. - */ - usleep(50000); - updateUdcBindStatus(devname); - } - } - /* advance to after the next \0 */ - while (*cp++) { - } - } -} - -void UsbDataSessionMonitor::handleTimerEvent() { - int byteRead; - uint64_t numExpiration; - - byteRead = read(mTimerFd.get(), &numExpiration, sizeof(numExpiration)); - - if (byteRead != sizeof(numExpiration)) { - ALOGE("incorrect read size"); - } - - if (numExpiration != 1) { - ALOGE("incorrect expiration count"); - } - - evaluateComplianceWarning(); -} - -void *UsbDataSessionMonitor::monitorThread(void *param) { - UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; - struct epoll_event events[64]; - int nevents = 0; - - while (true) { - nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); - if (nevents == -1) { - if (errno == EINTR) - continue; - ALOGE("usb epoll_wait failed; errno=%d", errno); - break; - } - - for (int n = 0; n < nevents; ++n) { - if (events[n].data.fd == monitor->mUeventFd.get()) { - monitor->handleUevent(); - } else if (events[n].data.fd == monitor->mTimerFd.get()) { - monitor->handleTimerEvent(); - } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { - monitor->handleDataRoleEvent(); - } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mDeviceState); - } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mHost1State); - } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mHost2State); - } - } - } - return NULL; -} - -} // namespace usb -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h deleted file mode 100644 index aced8a48..00000000 --- a/usb/usb/UsbDataSessionMonitor.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -namespace aidl { -namespace android { -namespace hardware { -namespace usb { - -using ::aidl::android::hardware::usb::ComplianceWarning; -using ::aidl::android::hardware::usb::PortDataRole; -using ::android::base::boot_clock; -using ::android::base::unique_fd; - -/* - * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices - * including device mode (udc), host mode high-speed port and host mode super-speed port. It - * reports Suez metrics for each data session and also provides API to query the compliance - * warnings detected in the current usb data session. - */ -class UsbDataSessionMonitor { - public: - /* - * The host mode high-speed port and super-speed port can be assigned to either host1 or - * host2 without affecting functionality. - * - * UeventRegex: name regex of the device that's being monitored. The regex is matched against - * uevent to detect dynamic creation/deletion/change of the device. - * StatePath: usb device state sysfs path of the device, monitored by epoll. - * dataRolePath: path to the usb data role sysfs, monitored by epoll. - * updatePortStatusCb: the callback is invoked when the compliance warings changes. - */ - UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, - const std::string &host1UeventRegex, const std::string &host1StatePath, - const std::string &host2UeventRegex, const std::string &host2StatePath, - const std::string &dataRolePath, - std::function updatePortStatusCb); - ~UsbDataSessionMonitor(); - // Returns the compliance warnings detected in the current data session. - void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); - - private: - struct usbDeviceState { - unique_fd fd; - std::string filePath; - std::string ueventRegex; - // Usb device states reported by state sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - }; - - static void *monitorThread(void *param); - void handleUevent(); - void handleTimerEvent(); - void handleDataRoleEvent(); - void handleDeviceStateEvent(struct usbDeviceState *deviceState); - void clearDeviceStateEvents(struct usbDeviceState *deviceState); - void setupNewSession(); - void reportUsbDataSessionMetrics(); - void evaluateComplianceWarning(); - void notifyComplianceWarning(); - void updateUdcBindStatus(const std::string &devname); - - pthread_t mMonitor; - unique_fd mEpollFd; - unique_fd mUeventFd; - unique_fd mTimerFd; - unique_fd mDataRoleFd; - struct usbDeviceState mDeviceState; - struct usbDeviceState mHost1State; - struct usbDeviceState mHost2State; - std::set mWarningSet; - // Callback function to notify the caller when there's a change in compliance warnings. - std::function mUpdatePortStatusCb; - /* - * Cache relevant info for a USB data session when one starts, including - * the data role and the time when the session starts. - */ - PortDataRole mDataRole; - boot_clock::time_point mDataSessionStart; - /* - * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which - * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, - * the gadget is in soft pulldown state and is expected not to enumerate. During gadget - * function switch, the udc device usually go through unbind and bind. - */ - bool mUdcBind; -}; - -} // namespace usb -} // namespace hardware -} // namespace android -} // namespace aidl From 7fb2864005b9a72b9153167a2992adaec394bbde Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Wed, 29 Jan 2025 01:58:44 +0000 Subject: [PATCH 13/14] usb: fix usb state path in host mode USB_DUMMY_HCD is disabled in kernel 6.1, modify the usb state path in host mode accordingly. Bug: 388367091 Test: test on oriole Flag: EXEMPT trivial bug fix Change-Id: If85077fddcadd25d15777d4b1ff5be2a0528c253 --- usb/usb/Usb.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 3650c5b5..1ce07ab3 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -90,11 +90,11 @@ constexpr char kUdcUeventRegex[] = constexpr char kUdcStatePath[] = "/sys/devices/platform/11110000.usb/11110000.dwc3/udc/11110000.dwc3/state"; constexpr char kHost1UeventRegex[] = - "/devices/platform/11110000.usb/11110000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; -constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; + "/devices/platform/11110000.usb/11110000.dwc3/xhci-hcd-exynos.[0-9].auto/usb1/1-0:1.0"; +constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb1/1-0:1.0/usb1-port1/state"; constexpr char kHost2UeventRegex[] = - "/devices/platform/11110000.usb/11110000.dwc3/xhci-hcd-exynos.[0-9].auto/usb3/3-0:1.0"; -constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb3/3-0:1.0/usb3-port1/state"; + "/devices/platform/11110000.usb/11110000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; +constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; constexpr char kDataRolePath[] = "/sys/devices/platform/11110000.usb/new_data_role"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, From 73ea462096e69c0d667bb1bd335c4e27cf0e25df Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Wed, 11 Dec 2024 15:45:02 +0000 Subject: [PATCH 14/14] Enable usb state update via udc sysfs Bug: 339241080 Test: tested on Oriole Flag: android.hardware.usb.flags.enable_udc_sysfs_usb_state_update Change-Id: Iab39cbc7d51f5598b70fb836b9c8863fa188f63f --- overlay/frameworks/base/core/res/res/values/config.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 6d4d0231..906e746e 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -311,4 +311,7 @@ 100% + + + true