ADB 访问 Linux 内核接口 - Android 内核接口
0. Windows 启动 adb server
adb kill-server adb -a nodaemon server
Microsoft Windows [版本 10.0.19043.1645]
(c) Microsoft Corporation。保留所有权利。
C:\Users\cheng>adb kill-server
C:\Users\cheng>adb -a nodaemon server
adb I 05-02 08:24:44 14484 11020 auth.cpp:417] adb_auth_init...
adb I 05-02 08:24:44 14484 11020 auth.cpp:152] loaded new key from 'C:\Users\cheng\.android\adbkey' with fingerprint C003CF5AD89F690A49BB31A1FB606378F31F0772F9ED77D67B67921478710B0E
adb I 05-02 08:24:44 14484 16560 transport.cpp:325] FFKDU17A28006357: read thread spawning
adb I 05-02 08:24:44 14484 4532 transport.cpp:297] FFKDU17A28006357: write thread spawning
adb I 05-02 08:24:44 14484 11020 transport.cpp:1527] fetching keys for transport FFKDU17A28006357
adb I 05-02 08:24:44 14484 11020 auth.cpp:469] Calling send_auth_response
adb I 05-02 08:24:44 14484 11020 adb.cpp:124] FFKDU17A28006357: offline
...
1. Linux / Windows Subsystem for Linux (WSL) 连接 devices
adb devices [-l] - list connected devices (-l for long output) 列出所有连接的设备。
adb -H 192.168.0.109 devices adb -H 192.168.0.109 devices -l adb -H 192.168.0.109 shell
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 devices
List of devices attached
FFKDU17A28006357 device
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 devices -l
List of devices attached
FFKDU17A28006357 device product:DUK-AL20 model:DUK_AL20 device:HWDUK transport_id:1
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell
HWDUK:/ $ exit
(base) yongqiang@yongqiang:~$
2. /data/local/tmp/yongqiang/
/data/local/tmp/ 不需要 root 权限,有利于创建个人目录,放置个人文件。
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell
HWDUK:/ $ cd /data/local/tmp/
HWDUK:/data/local/tmp $ mkdir yongqiang
HWDUK:/data/local/tmp $ ls -l
total 3
drwxrwxrwx 2 shell shell 3488 2022-05-01 21:13 yongqiang
HWDUK:/data/local/tmp $ exit
(base) yongqiang@yongqiang:~$
3. adb -H 192.168.0.109 shell cat /proc/cpuinfo
Read-only file containing architecture-specific CPU details. 包含架构对应的 CPU 详细信息的只读文件。
查看 CPU 信息。
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /proc/cpuinfo
Processor : AArch64 Processor rev 4 (aarch64)
processor : 0
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 1
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 2
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 3
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 4
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 1
processor : 5
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 1
processor : 6
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 1
processor : 7
BogoMIPS : 3.84
Features : fp asimd evtstrm aes pmull crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd09
CPU revision : 1
(base) yongqiang@yongqiang:~$
adb -H 192.168.0.109 shell cat /proc/cpuinfo | grep Processor adb -H 192.168.0.109 shell cat /proc/cpuinfo | grep processor
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /proc/cpuinfo | grep Processor
Processor : AArch64 Processor rev 4 (aarch64)
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
(base) yongqiang@yongqiang:~$
4. adb -H 192.168.0.109 shell cat /proc/meminfo
Read-only file showing memory subsystem details. 显示内存子系统详细信息的只读文件。
查看 Memory 信息。
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /proc/meminfo
MemTotal: 5863120 kB
MemFree: 155604 kB
MemAvailable: 2934008 kB
Buffers: 5992 kB
Cached: 2248896 kB
SwapCached: 107072 kB
Active: 1950008 kB
Inactive: 1105928 kB
Active(anon): 628708 kB
Inactive(anon): 289416 kB
Active(file): 1321300 kB
Inactive(file): 816512 kB
Unevictable: 112916 kB
Mlocked: 112916 kB
SwapTotal: 2293756 kB
SwapFree: 1994616 kB
Dirty: 80 kB
Writeback: 0 kB
AnonPages: 913316 kB
Mapped: 501488 kB
Shmem: 5020 kB
Slab: 1312964 kB
SReclaimable: 781436 kB
SUnreclaim: 531528 kB
KernelStack: 43264 kB
PageTables: 57060 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 5225316 kB
Committed_AS: 79455156 kB
VmallocTotal: 263061440 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 1351680 kB
CmaFree: 70196 kB
IonTotalCache: 45056 kB
IonTotalUsed: 142004 kB
PActive(anon): 0 kB
PInactive(anon): 0 kB
PActive(file): 0 kB
PInactive(file): 0 kB
Isolate1Free: 4 kB
Isolate2Free: 2336 kB
RsvTotalUsed: 274436 kB
(base) yongqiang@yongqiang:~$
4.1 The /proc Filesystem
https://docs.kernel.org/filesystems/proc.html
Total usable RAM (i.e. physical RAM minus a few reserved bits and the kernel binary code)
The sum of LowFree + HighFree
Relatively temporary storage for raw disk blocks shouldn’t get tremendously large (20MB or so) raw disk blocks 的相对临时存储不应变得非常大 (20MB 左右)
tremendously [tr??m?nd?sli]:adv. 极大地,巨大,特别,非常地,极地
5. adb -H 192.168.0.109 shell cat /proc/version
Read-only file containing a string describing the kernel version. 包含描述内核版本的字符串的只读文件。
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /proc/version
Linux version 4.9.148 (android@localhost) (gcc version 4.9.x 20150123 (prerelease) (GCC) ) #1 SMP PREEMPT Wed Jul 24 06:26:03 CST 2019
(base) yongqiang@yongqiang:~$
6. adb -H 192.168.0.109 shell cat /proc/uptime
Read-only file that shows how long the system has been running. 显示系统运行时间的只读文件。
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /proc/uptime
132634.94 567607.17
(base) yongqiang@yongqiang:~$
7. /sys/devices/system/cpu/
Directory containing information about CPU configuration and frequency.
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell
HWDUK:/ $ cd /sys/devices/system/cpu/
HWDUK:/sys/devices/system/cpu $ ls -l
total 0
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu0
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu1
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu2
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu3
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu4
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu5
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu6
drwxr-xr-x 7 root root 0 2022-05-04 16:24 cpu7
drwxr-xr-x 4 root root 0 2022-05-04 16:24 cpufreq
drwxr-xr-x 2 root root 0 2022-05-04 16:24 cpuidle
drwxr-xr-x 2 root root 0 2022-05-04 16:24 hotplug
-r--r--r-- 1 root root 4096 2022-05-04 17:29 isolated
-r--r--r-- 1 root root 4096 2022-05-04 17:29 kernel_max
-r--r--r-- 1 root root 4096 2022-05-04 17:29 modalias
-r--r--r-- 1 root root 4096 2022-05-04 17:29 offline
-r--r--r-- 1 root root 4096 2022-05-04 16:24 online
-r--r--r-- 1 root root 4096 2022-05-04 17:29 possible
drwxr-xr-x 2 root root 0 2022-05-04 16:24 power
-r--r--r-- 1 root root 4096 2022-05-04 17:29 present
-rw-r--r-- 1 root root 4096 2022-05-04 16:24 uevent
HWDUK:/sys/devices/system/cpu $
HWDUK:/sys/devices/system/cpu $ cd cpu0/
HWDUK:/sys/devices/system/cpu/cpu0 $ ls -l
total 0
lrwxrwxrwx 1 root root 0 2022-05-04 16:24 cpufreq -> ../cpufreq/policy0
drwxr-xr-x 6 root root 0 2022-05-04 16:24 cpuidle
drwxr-xr-x 2 root root 0 2022-05-04 17:29 hotplug
lrwxrwxrwx 1 root root 0 2022-05-04 17:29 of_node -> ../../../../firmware/devicetree/base/cpus/cpu@0
-rw-r--r-- 1 root root 4096 2022-05-04 17:29 online
drwxr-xr-x 2 root root 0 2022-05-04 17:29 power
drwxr-xr-x 3 root root 0 2022-05-04 17:29 regs
lrwxrwxrwx 1 root root 0 2022-05-04 17:29 subsystem -> ../../../../bus/cpu
drwxr-xr-x 2 root root 0 2022-05-04 17:29 topology
-rw-r--r-- 1 root root 4096 2022-05-04 17:29 uevent
HWDUK:/sys/devices/system/cpu/cpu0 $
HWDUK:/sys/devices/system/cpu/cpu0 $ cd cpufreq/
HWDUK:/sys/devices/system/cpu/cpu0/cpufreq $ ls -l
total 0
-r--r--r-- 1 root root 4096 2022-05-04 17:30 affected_cpus
-r-------- 1 root root 4096 2022-05-04 17:30 cpuinfo_cur_freq
-r--r--r-- 1 root root 4096 2022-05-04 16:24 cpuinfo_max_freq
-r--r--r-- 1 root root 4096 2022-05-04 17:30 cpuinfo_min_freq
-r--r--r-- 1 root root 4096 2022-05-04 17:30 cpuinfo_transition_latency
drwxr-xr-x 2 root root 0 2022-05-04 16:24 interactive
-r--r--r-- 1 root root 4096 2022-05-04 17:30 related_cpus
-r--r--r-- 1 root root 4096 2022-05-04 16:24 scaling_available_frequencies
-r--r--r-- 1 root root 4096 2022-05-04 17:30 scaling_available_governors
-r--r--r-- 1 root root 4096 2022-05-04 16:24 scaling_cur_freq
-r--r--r-- 1 root root 4096 2022-05-04 17:30 scaling_driver
-rw-r--r-- 1 root root 4096 2022-05-04 16:24 scaling_governor
-rw-rw-r-- 1 system system 4096 2022-05-04 16:24 scaling_max_freq
-rw-rw-r-- 1 system system 4096 2022-05-04 16:24 scaling_min_freq
-rw-r--r-- 1 root root 4096 2022-05-04 17:30 scaling_setspeed
drwxr-xr-x 2 root root 0 2022-05-04 16:24 stats
HWDUK:/sys/devices/system/cpu/cpu0/cpufreq $
HWDUK:/sys/devices/system/cpu/cpu0/cpufreq $ exit
(base) yongqiang@yongqiang:~$
cpu0 - cpu7 表示有 8 个 CPU。
7.1 CPU Performance Scaling
https://docs.kernel.org/admin-guide/pm/cpufreq.html https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
Current frequency of the CPUs belonging to this policy as obtained from the hardware (in KHz ). 从硬件获得的属于此策略的 CPU 的当前频率,单位为 kHz 。
This is expected to be the frequency the hardware actually runs at. If that frequency cannot be determined, this attribute should not be present. 这将是硬件实际运行的频率。如果无法确定该频率,则该属性不应存在。
Maximum possible operating frequency the CPUs belonging to this policy can run at (in kHz ). 属于此策略的 CPU 可以运行的最高可能工作频率,单位为 kHz 。
Minimum possible operating frequency the CPUs belonging to this policy can run at (in kHz ). 属于此策略的 CPU 可以运行的最低可能工作频率,单位为 kHz 。
scaling_available_frequencies
List of available frequencies, in kHz .
scaling_max_freq Maximum frequency the CPUs belonging to this policy are allowed to be running at (in kHz ). 属于此策略的 CPU 允许运行的最高频率,单位为 kHz 。
This attribute is read-write and writing a string representing an integer to it will cause a new limit to be set (it must not be lower than the value of the scaling_min_freq attribute). 此属性是可读写的,向其写入表示整数的字符串将设置新的上限 (不得低于 scaling_min_freq 属性的值)。
scaling_min_freq Minimum frequency the CPUs belonging to this policy are allowed to be running at (in kHz ). 属于此策略的 CPU 允许运行的最低频率,单位为 kHz 。
This attribute is read-write and writing a string representing a non-negative integer to it will cause a new limit to be set (it must not be higher than the value of the scaling_max_freq attribute). 此属性是可读写的,向其写入表示非负整数的字符串将设置新的下限 (不得高于 scaling_max_freq 属性的值)。
adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
1844000
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
533000
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
533000 999000 1402000 1709000 1844000
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
1402000
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
533000
(base) yongqiang@yongqiang:~$
adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/online adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/offline
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/online
0-7
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ adb -H 192.168.0.109 shell cat /sys/devices/system/cpu/offline
(base) yongqiang@yongqiang:~$
References
https://yongqiang.blog.csdn.net/ AOSP Interface Requirements https://source.android.com/devices/architecture/kernel/reqs-interfaces
|