日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android TV开机优化

發布時間:2023/12/14 Android 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android TV开机优化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android開機優化相關點

1 關鍵路徑

bootloader > kernel > init > zygote > system server > launcher


2 打印優化

2.1 關閉bootloader打印

2.2 關閉 kernel打印

2.3 提高Android log打印等級
system/core/logd/LogBuffer.cpp

int get_log_level() {char buf[PROPERTY_VALUE_MAX];memset(buf, 0, PROPERTY_VALUE_MAX);property_get("persist.xxx.level", buf, "");return buf[0]; } ? int loglevl = get_log_level();int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,pid_t tid, const char* msg, uint16_t len) {if (log_id >= LOG_ID_MAX) {return -EINVAL;}// 通過屬性控制log輸出if (length > 0 && loglevl < log_id) {return -EINVAL;} ? }

3 uboot

1 修改emmc速度提升讀寫速度加快uboot啟動時間

2 提高uboot cpu的頻率


4 kernel

如果不是非常緊急的驅動延遲初始化,可以等zygote啟動后,在early-boot或boot階段去加載ko, 讓zygote早點起來,zygote 在late-init階段后面起來

比如wifi和藍牙驅動

on bootchown bluetooth bluetooth /proc/bluetooth/sleep/btwritechown bluetooth bluetooth /proc/bluetooth/sleep/lpmchmod 0660 /proc/bluetooth/sleep/btwritechmod 0660 /proc/bluetooth/sleep/lpminsmod /vendor/lib/modules/btusb.ko

5 init

SecondStageMain 觸發的各個階段


zygote在late-init稍后的階段啟動

# Mount filesystems and start core system services. on late-inittrigger early-fs# Mount fstab in init.{$device}.rc by mount_all command. Optional parameter# '--early' can be specified to skip entries with 'latemount'.# /system and /vendor must be mounted by the end of the fs stage,# while /data is optional.trigger fstrigger post-fs# Mount fstab in init.{$device}.rc by mount_all with '--late' parameter# to only mount entries with 'latemount'. This is needed if '--early' is# specified in the previous mount_all command on the fs stage.# With /system mounted and properties form /system + /factory available,# some services can be started.trigger late-fs# Now we can mount /data. File encryption requires keymaster to decrypt# /data, which in turn can only be loaded when system properties are present.trigger post-fs-data# Load persist properties and override properties (if enabled) from /data.trigger load_persist_props_action# Should be before netd, but after apex, properties and logging is available.trigger load_bpf_programs# Now we can start zygote for devices with file based encryption# 觸發zygote啟動trigger zygote-start# Remove a file to wake up anything waiting for firmware.trigger firmware_mounts_completetrigger early-boottrigger boot

5.1 并行執行uevent(enable_parallel_restorecon)

vendor/ueventd.rc中加入parallel_restorecon enable

parallel_restorecon enable

5.2 CPU開啟性能模式

1 開機的時候,cpu開啟性能模式

on early-initwrite /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor performance# 查看當前頻率 # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

2 開機完成后,CPU頻率變成自適應

on property:sys.boot_completed=1write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor schedutil

5.3 讀寫IO調整

read_ahead_kb: 事先預讀數據的Kb數

nr_requests: 默認IO請求隊列的長度

加大read_ahead_kb和nr_requests 大小,優化時間不明顯

on late-fs# boot time fs tunewrite /sys/block/mmcblk0/queue/iostats 0write /sys/block/mmcblk0/queue/read_ahead_kb 2048write /sys/block/mmcblk0/queue/nr_requests 256on property:sys.boot_completed=1# end boot time fs tunewrite /sys/block/mmcblk0/queue/read_ahead_kb 128

5.4 移除沒有用到的模塊

如CI模塊

on post-fs-datainsmod /vendor/lib/modules/cimax-usb.koinsmod /vendor/lib/modules/ci.ko

5.5 延遲vendor/etc/init下的非關鍵服務,放在early-boot或者boot階段執行,加快zygote的啟動

// 放在early-boot或者boot階段執行 on bootstart xxxservice xxx /system/bin/xxxuser rootgroup system

6 zygote

6.1 lazy-preload

classloader懶加載,懶加載會比直接加載更耗內存,懶加載是通過system-server發送指令給zygote做加載相關動作,在發送指令前,system-server會加載一部分自己使用的類,會和zygote中存在相同的一部分備份

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server --enable-lazy-preload

6.2 zygote 添加 task_profiles ProcessCapacityHigh MaxPerformance

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server --enable-lazy-preloadclass mainpriority -20user rootgroup root readproc reserved_disksocket zygote stream 660 root systemsocket usap_pool_primary stream 660 root systemonrestart exec_background - system system -- /system/bin/vdc volume abort_fuseonrestart write /sys/power/state ononrestart restart audioserveronrestart restart cameraserveronrestart restart mediaonrestart restart netdonrestart restart wificondtask_profiles ProcessCapacityHigh MaxPerformance

6.3 精簡preload的classes , TV系統可以去掉如下class

如果需要再做一些大的裁剪,可以使用frameworks\base\config\generate-preloaded-classes.sh下的腳本來生成preloaded-classes

// 生物識別 android.hardware.biometrics// 人臉識別 android.hardware.face// 打印服務 android.hardware.fingerprint android.print.// 部分定位相關, 還有GPS定位相關 android.hardware.location com.android.internal.location.GpsNetInitiatedHandler android.location.Gnss*// 手機通話相關 android.telephony. android.telecom. com.android.i18n.phonenumbers. com.android.ims android.hardware.radio// nfc相關 android.nfc.

6.4 關閉 systemServer虛擬機實列的 ClassVerify

確認是否需要Disable_verify,不建議關閉

/** Turn off the verifier. */ public static final int DISABLE_VERIFIER = 1 << 9; parsedArgs.mRuntimeFlags |= Zygote.DISABLE_VERIFIER;/* Request to fork the system server process */pid = Zygote.forkSystemServer(parsedArgs.mUid, parsedArgs.mGid,parsedArgs.mGids,parsedArgs.mRuntimeFlags,null,parsedArgs.mPermittedCapabilities,parsedArgs.mEffectiveCapabilities);

7 systemServer

7.1 調整systemServer進程,線程優先級

android.os.Process.setThreadPriority(-19); android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_FOREGROUND); Process.setProcessGroup(pid, Process.THREAD_GROUP_TOP_APP); private void run() {android.os.Process.setThreadPriority(-19);int defaultGroup = getProcessGroup(Process.myPid());Process.setProcessGroup(Process.myPid(), Process.THREAD_GROUP_TOP_APP);// Start services.try {t.traceBegin("StartServices");startBootstrapServices(t);startCoreServices(t);startOtherServices(t);} catch (Throwable ex) {Slog.e("System", "******************************************");Slog.e("System", "************ Failure starting system services", ex);throw ex;} finally {t.traceEnd(); // StartServices}android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_FOREGROUND);Process.setProcessGroup(Process.myPid(), defaultGroup);// Loop forever.Looper.loop();}

7.2 調整SystemServerInitThreadPool線程池相關優先級

private SystemServerInitThreadPool() {final int size = Runtime.getRuntime().availableProcessors();Slog.i(TAG, "Creating instance with " + size + " threads");mService = ConcurrentUtils.newFixedThreadPool(size,"system-server-init-thread", -18);//Process.THREAD_PRIORITY_FOREGROUND); }

7.3 裁剪TV系統中沒有用到的服務,可以用feture的形式來控制開關

if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_xxx)) { mSystemServiceManager.startService(xxx_SERVICE_CLASS); }

查看systemServer中的服務

service list

可以裁剪的服務

TelecomLoaderService TelephonyRegistry StatusBarManagerService SearchManagerService SerialService FingerprintService CameraService MmsService

7.4 延時啟動presist app

void startPersistentApps(int matchFlags) {if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL) return;synchronized (this) {try {final List<ApplicationInfo> apps = AppGlobals.getPackageManager().getPersistentApplications(STOCK_PM_FLAGS | matchFlags).getList();for (ApplicationInfo app : apps) {if (!"android".equals(app.packageName)) {mHandler.postDelayed(() -> {addAppLocked(app, null, false, null /* ABI override */,ZYGOTE_POLICY_FLAG_BATCH_LAUNCH);}, 1000);}}} catch (RemoteException ex) {}} }

8 Laucher

1 Laucher APK的編譯方式改為 speed-profile

LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed-profile// debug pm compile -m speed -f package dumpsys package package

2 如果是內置的launch,可以將launch設置為presist apk


9 調試方法

9.1 打開init log

1 init中的log會輸出到kernel log中,打開init log查看耗時的時間點,不同平臺方法可能不一樣,需要將kernel log輸出等級設置為7

2 rc中設置如下參數

vendor/etc/init/hw/init.xxx.rc

on early-initloglevel 7

9.2 通過logcat -b events,過濾出啟動階段的主要事件

logcat -b events |grep "boot_p" boot_progress_start: 6466 01-18 11:28:13.935 647 647 I boot_progress_system_run: 10467 01-18 11:28:15.368 647 647 I boot_progress_pms_start: 11900 01-18 11:28:15.748 647 647 I boot_progress_pms_system_scan_start: 12280 01-18 11:28:16.338 647 647 I boot_progress_pms_data_scan_start: 12870 01-18 11:28:16.350 647 647 I boot_progress_pms_scan_end: 12881 01-18 11:28:16.642 647 647 I boot_progress_pms_ready: 13174 01-18 11:28:18.973 647 647 I boot_progress_ams_ready: 15505 01-18 11:28:24.131 647 722 I boot_progress_enable_screen: 20663 01-18 11:28:24.143 392 767 I sf_stop_bootanim: 20675 01-18 11:28:24.144 647 722 I wm_boot_animation_done: 20676

9.3 通過 logcat -b system查看系統中一些流程的耗時點, 結合trace一起分析

Zygote32Timing: ZygoteInit took to complete: 1454ms SystemServerInitThreadPool: Creating instance with 4 threads [20220127_12:10:10:054]01-18 12:04:51.352 667 667 D SystemServerTiming: InitBeforeStartServices took to complete: 745ms **Zygote32Timing: ZygoteInit took to complete: 1454ms** SystemServerTiming: InitBeforeStartServices took to complete: 745ms SystemConfig: readAllPermissions took to complete: 160ms SystemServerTimingAsync: InitThreadPoolExec:ReadingSystemConfig took to complete: 161ms SystemServerTiming: StartActivityManager took to complete: 364ms **PackageManagerTiming: read user settings took to complete: 313ms** SystemServerTimingAsync: AppDataFixup took to complete: 177ms PackageManagerTiming: GC took to complete: 106ms **PackageManagerTiming: create package manager took to complete: 1411ms** **SystemServerTiming: StartPackageManagerService took to complete: 1425ms** SystemServerTiming: startBootstrapServices took to complete: 2129ms SystemServerTimingAsync: InitThreadPoolExec:PersistentDataBlockService.onStart took to complete: 80ms SystemServerTiming: OnBootPhase_500 took to complete: 204ms SystemServerTiming: StartBootPhaseSystemServicesReady took to complete: 204ms SystemServerTiming: MakePowerManagerServiceReady took to complete: 105ms ZygoteInitTiming_lazy: PreloadClasses took to complete: 1737ms ZygoteInitTiming_lazy: PreloadResources took to complete: 124ms SystemServerTimingAsync: SecondaryZygotePreload took to complete: 1960ms SystemServerTiming: OnBootPhase_550 took to complete: 212ms SystemServerTiming: StartActivityManagerReadyPhase took to complete: 213ms OnBootPhase_600 took to complete: 122ms SystemServerTiming: PhaseThirdPartyAppsCanStart took to complete: 122ms SystemServerTiming: ssm.StartUser-0 took to complete: 165ms SystemServerTiming: showSystemReadyErrorDialogs took to complete: 119ms SystemServerTiming: ActivityManagerStartApps took to complete: 537ms** SystemServerTiming: PhaseActivityManagerReady took to complete: 1129ms SystemServerTiming: startOtherServices took to complete: 3032ms SystemServerTiming: StartServices took to complete: 5217ms **SystemUIBootTiming: StartServicescom.android.systemui.volume.VolumeUI took to complete: 255ms** **SystemUIBootTiming: StartServices took to complete: 429ms** **WindowManager: Keyguard drawn timeout. Setting mKeyguardDrawComplete** ActivityManagerTiming: OnBootPhase_1000 took to complete: 109ms ActivityManagerTiming: TotalBootTime took to complete: 9939ms **ActivityManagerTiming: FinishBooting took to complete: 134ms** **SystemServerTiming: SystemUserUnlock took to complete: 611ms

9.4 抓取trace

atrace -z -b 65536 gfx input view wm am sm audio video hal res dalvik rs power pm ss database aidl sched irq freq idle disk mmc sync workq memreclaim binder_driver binder_lock pagecache gfx -t 20 > /data/trace

9.5 bootchart

啟用 bootchart

adb shell 'touch /data/bootchart/enabled' adb reboot

9.6 perfboot

代碼位置在system/core/init/perfboot.py,腳本執行結束后,可以在Excel里直接打開文件進行分析

./perfboot.py --iterations=2 --interval=30 -v --output=/tmp/J5D_UE.tsv

https://source.android.google.cn/devices/tech/perf/boot-times?hl=zh-cn
https://source.android.google.cn/security/verifiedboot/dm-verity?hl=zh-cn

總結

以上是生活随笔為你收集整理的Android TV开机优化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。