0%

应用层CPU亲和性控制

taskset使用介绍

1. 什么是taskset?

taskset是一个Linux系统命令行工具,主要用于管理进程与CPU核心之间的关系(CPU亲和性),可以指定进程在特定CPU核心上运行。

2. 为什么要用taskset?

  • 提升性能

    • 减少进程在不同核心间切换开销
    • 提高缓存命中率
    • 适用于计算密集型任务(如视频编码、科学计算)
  • 隔离资源

    • 保护重要进程不受干扰
    • 限制问题进程的影响范围

3. 使用方法

查看进程CPU亲和性

1
2
3
taskset -p [进程PID]
# 示例
taskset -p 1234 # 1234为进程ID

备注:输出结果会显示该进程当前绑定的CPU核心情况,格式类似“pid 1234’s current affinity mask: f”,这里的“f”是一个十六进制数,每一位对应一个CPU核心,1表示绑定,0表示未绑定。

设置进程CPU亲和性

1
2
3
4
5
6
7
8
9
# 新进程绑定
taskset -c [核心编号列表] [命令]
# 示例
taskset -c 0,1 ./video_encoder &

# 已运行进程绑定
taskset -cp [核心编号] [PID]
# 示例
taskset -cp 2 1234

备注:其中“-p”选项用于修改已有进程的CPU亲和性。

4. 注意事项

  • 需要root权限(使用sudo)
  • 核心编号需符合系统实际CPU核心数
  • 避免过度使用,防止系统负载不均衡

USB常用命令

  • 查看u盘工作模式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    cat /sys/kernel/debug/usb/devices | grep Manufacturer=Kingston -B4 -A7 
    输出如下:
    T: Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#= 5 Spd=480 MxCh= 0
    D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
    P: Vendor=3535 ProdID=6387 Rev= 1.00
    S: Manufacturer=aigo
    S: Product=U212
    S: SerialNumber=428A75BB
    C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
    I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
    E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
  • 查看插入的usb设备

    1
    2
    # cat /sys/kernel/debug/usb/devices | grep Manufacturer | grep -vE 'Linux|Љ'
    S: Manufacturer=Kingston

  • 获取设备支持的格式(–list-formats-ext)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    novauto@novauto:~/raw12/yuv422$ v4l2-ctl --list-formats-ext
    ioctl: VIDIOC_ENUM_FMT
    Index : 0
    Type : Video Capture
    Pixel Format: 'UYVY'
    Name : UYVY 4:2:2
    Size: Discrete 1920x1080
    Interval: Discrete 0.033s (30.000 fps)

    Index : 1
    Type : Video Capture
    Pixel Format: 'NV16'
    Name : Y/CbCr 4:2:2
    Size: Discrete 1920x1080
    Interval: Discrete 0.033s (30.000 fps)

    Index : 2
    Type : Video Capture
    Pixel Format: 'UYVY'
    Name : UYVY 4:2:2
    Size: Discrete 1920x1080
    Interval: Discrete 0.033s (30.000 fps)

  • 获取当前视频格式(–get-fmt-video)

    1
    v4l2-ctl --get-fmt-video
  • 采图命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    novauto@novauto:~/raw12/yuv422$ v4l2-ctl -d /dev/video2 --set-fmt-video=width=1920,height=1080,pixelformat=UYVY --stream-count=1 --stream-mmap --stream-to=csi.yuv --verbose
    VIDIOC_QUERYCAP: ok
    VIDIOC_G_FMT: ok
    VIDIOC_S_FMT: ok
    Format Video Capture:
    Width/Height : 1920/1080
    Pixel Format : 'UYVY'
    Field : None
    Bytes per Line : 3840
    Size Image : 4147200
    Colorspace : sRGB
    Transfer Function : Default (maps to sRGB)
    YCbCr/HSV Encoding: Default (maps to ITU-R 601)
    Quantization : Default (maps to Limited Range)
    Flags :
    VIDIOC_REQBUFS: ok
    VIDIOC_QUERYBUF: ok
    VIDIOC_QBUF: ok
    VIDIOC_QUERYBUF: ok
    VIDIOC_QBUF: ok
    VIDIOC_QUERYBUF: ok
    VIDIOC_QBUF: ok
    VIDIOC_QUERYBUF: ok
    VIDIOC_QBUF: ok
    VIDIOC_STREAMON: ok
    Index : 0
    Type : Video Capture
    Flags : mapped
    Field : None
    Sequence : 0
    Length : 4147200
    Bytesused: 4147200
    Timestamp: 1626894853.303928s (Monotonic, End-of-Frame)

    VIDIOC_STREAMOFF: ok
  • 如果抓不到数据会返回错误 (–stream-poll的参数)

    1
    v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV12' --stream-mmap=3 --stream-skip=4 --stream-to=/data/1920x1080_nv12.yuv --stream-count=5 --stream-poll

常用命令链接:https://blog.csdn.net/qq_34341546/article/details/129015346

  1. 更新系统apt源,修改/etc/apt/sources.list文件内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
    #deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

    deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
    #deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

    deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
    #deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

    deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
    #deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

    deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
    #deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  2. 执行sudo apt-get update命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    admin@ub20:/etc/apt$ sudo apt-get update 
    Get:1 http://mirrors.aliyun.com/ubuntu focal InRelease [265 kB]
    Get:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease [114 kB]
    Get:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB]
    Get:4 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease [267 kB]
    Get:5 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [108 kB]
    Ign:6 http://mirrors.aliyun.com/ubuntu focal/main arm64 Packages
    Get:7 http://mirrors.aliyun.com/ubuntu focal/main Translation-en [506 kB]
    Get:8 http://mirrors.aliyun.com/ubuntu focal/main arm64 DEP-11 Metadata [489 kB]
    Get:9 http://mirrors.aliyun.com/ubuntu focal/main DEP-11 48x48 Icons [98.4 kB]
    Get:10 http://mirrors.aliyun.com/ubuntu focal/main DEP-11 64x64 Icons [163 kB]
    Get:11 http://mirrors.aliyun.com/ubuntu focal/main DEP-11 64x64@2 Icons [15.8 kB]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Get:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages [1300 B]
    Ign:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages
    Ign:24 http://mirrors.aliyun.com/ubuntu focal/universe arm64 Packages
    Ign:25 http://mirrors.aliyun.com/ubuntu focal/multiverse arm64 Packages
    Ign:6 http://mirrors.aliyun.com/ubuntu focal/main arm64 Packages
    Ign:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages
    Ign:24 http://mirrors.aliyun.com/ubuntu focal/universe arm64 Packages
    Ign:25 http://mirrors.aliyun.com/ubuntu focal/multiverse arm64 Packages
    Ign:6 http://mirrors.aliyun.com/ubuntu focal/main arm64 Packages
    Ign:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages
    Ign:24 http://mirrors.aliyun.com/ubuntu focal/universe arm64 Packages
    Ign:25 http://mirrors.aliyun.com/ubuntu focal/multiverse arm64 Packages
    Ign:6 http://mirrors.aliyun.com/ubuntu focal/main arm64 Packages
    Ign:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages
    Ign:24 http://mirrors.aliyun.com/ubuntu focal/universe arm64 Packages
    Ign:25 http://mirrors.aliyun.com/ubuntu focal/multiverse arm64 Packages
    Ign:6 http://mirrors.aliyun.com/ubuntu focal/main arm64 Packages
    Ign:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages
    Ign:24 http://mirrors.aliyun.com/ubuntu focal/universe arm64 Packages
    Ign:25 http://mirrors.aliyun.com/ubuntu focal/multiverse arm64 Packages
    Err:6 http://mirrors.aliyun.com/ubuntu focal/main arm64 Packages
    404 Not Found [IP: 182.40.61.237 80]
    Ign:12 http://mirrors.aliyun.com/ubuntu focal/restricted arm64 Packages
    Ign:24 http://mirrors.aliyun.com/ubuntu focal/universe arm64 Packages
    Ign:25 http://mirrors.aliyun.com/ubuntu focal/multiverse arm64 Packages
    Reading package lists... Done
    E: Release file for http://mirrors.aliyun.com/ubuntu/dists/focal-security/InRelease is not valid yet (invalid for another 628d 4h 16min 47s). Updates for this repository will not be applied.
    E: Release file for http://mirrors.aliyun.com/ubuntu/dists/focal-updates/InRelease is not valid yet (invalid for another 628d 16h 29min 47s). Updates for this repository will not be applied.
    E: Release file for http://mirrors.aliyun.com/ubuntu/dists/focal-proposed/InRelease is not valid yet (invalid for another 628d 12h 18min 41s). Updates for this repository will not be applied.
    E: Release file for http://mirrors.aliyun.com/ubuntu/dists/focal-backports/InRelease is not valid yet (invalid for another 430d 13h 47min 7s). Updates for this repository will not be applied.

    问题原因:

    1. 查看服务器是否能ping通

      1
      2
      3
      4
      admin@ub20:/etc/apt$ ping mirrors.aliyun.com
      PING mirrors.aliyun.com.w.alikunlun.com (182.40.61.239) 56(84) bytes of data.
      64 bytes from 182.40.61.239: icmp_seq=1 ttl=45 time=20.5 ms
      64 bytes from 182.40.61.239: icmp_seq=2 ttl=45 time=19.8 ms
    2. 将sources.list中的ubuntu都替换为ubuntu-ports

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      deb http://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse
      #deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse

      deb http://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse
      #deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse

      deb http://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse
      #deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse

      deb http://mirrors.aliyun.com/ubuntu-ports/ focal-proposed main restricted universe multiverse
      #deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-proposed main restricted universe multiverse

      deb http://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
      #deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse

      执行sudo apt-get update结果如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      admin@ub20:/etc/apt$ sudo apt update 
      Get:1 http://mirrors.aliyun.com/ubuntu-ports focal InRelease [265 kB]
      Get:2 http://mirrors.aliyun.com/ubuntu-ports focal-security InRelease [114 kB]
      Get:3 http://mirrors.aliyun.com/ubuntu-ports focal-updates InRelease [114 kB]
      Get:4 http://mirrors.aliyun.com/ubuntu-ports focal-proposed InRelease [267 kB]
      Get:5 http://mirrors.aliyun.com/ubuntu-ports focal-backports InRelease [108 kB]
      Get:6 http://mirrors.aliyun.com/ubuntu-ports focal/main arm64 Packages [940 kB]
      Get:7 http://mirrors.aliyun.com/ubuntu-ports focal/main Translation-en [506 kB]
      Get:8 http://mirrors.aliyun.com/ubuntu-ports focal/main arm64 DEP-11 Metadata [489 kB]
      Get:9 http://mirrors.aliyun.com/ubuntu-ports focal/main DEP-11 48x48 Icons [98.4 kB]
      Get:10 http://mirrors.aliyun.com/ubuntu-ports focal/main DEP-11 64x64 Icons [163 kB]
      Get:11 http://mirrors.aliyun.com/ubuntu-ports focal/main DEP-11 64x64@2 Icons [15.8 kB]
      Get:12 http://mirrors.aliyun.com/ubuntu-ports focal/restricted arm64 Packages [1300 B]
      Get:13 http://mirrors.aliyun.com/ubuntu-ports focal/restricted Translation-en [6212 B]
      Get:14 http://mirrors.aliyun.com/ubuntu-ports focal/universe arm64 Packages [8458 kB]
      Get:15 http://mirrors.aliyun.com/ubuntu-ports focal/universe Translation-en [5124 kB]
      Get:16 http://mirrors.aliyun.com/ubuntu-ports focal/universe arm64 DEP-11 Metadata [3587 kB]
      Get:17 http://mirrors.aliyun.com/ubuntu-ports focal/universe DEP-11 48x48 Icons [3016 kB]
      Get:18 http://mirrors.aliyun.com/ubuntu-ports focal/universe DEP-11 64x64 Icons [7794 kB]
      Get:19 http://mirrors.aliyun.com/ubuntu-ports focal/universe DEP-11 64x64@2 Icons [44.3 kB]
      Get:20 http://mirrors.aliyun.com/ubuntu-ports focal/multiverse arm64 Packages [114 kB]
      Get:21 http://mirrors.aliyun.com/ubuntu-ports focal/multiverse Translation-en [104 kB]
      Get:22 http://mirrors.aliyun.com/ubuntu-ports focal/multiverse arm64 DEP-11 Metadata [44.9 kB]
      Get:23 http://mirrors.aliyun.com/ubuntu-ports focal/multiverse DEP-11 48x48 Icons [23.1 kB]
      Get:24 http://mirrors.aliyun.com/ubuntu-ports focal/multiverse DEP-11 64x64 Icons [192 kB]
      Get:25 http://mirrors.aliyun.com/ubuntu-ports focal/multiverse DEP-11 64x64@2 Icons [214 B]
      Reading package lists... Done
      E: Release file for http://mirrors.aliyun.com/ubuntu-ports/dists/focal-security/InRelease is not valid yet (invalid for another 628d 4h 10min 36s). Updates for this repository will not be applied.
      E: Release file for http://mirrors.aliyun.com/ubuntu-ports/dists/focal-updates/InRelease is not valid yet (invalid for another 628d 10h 32min 57s). Updates for this repository will not be applied.
      E: Release file for http://mirrors.aliyun.com/ubuntu-ports/dists/focal-proposed/InRelease is not valid yet (invalid for another 628d 4h 50min 42s). Updates for this repository will not be applied.
      E: Release file for http://mirrors.aliyun.com/ubuntu-ports/dists/focal-backports/InRelease is not valid yet (invalid for another 430d 13h 40min 54s). Updates for this repository will not be applied.
    3. 通过上网查资料,出现Updates for this repository will not be applied可能是系统时间不对,然后使用date查看时间不同步,如下:

      1
      2
      admin@ub20:/etc/apt$ date -R
      Thu, 08 Sep 2022 18:59:29 +0800

      使用timedatectl命令更新系统时间后,执行sudo apt-get update成功。

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      admin@ub20:/etc/apt$ timedatectl
      Local time: Thu 2022-09-08 19:09:25 CST
      Universal time: Thu 2022-09-08 11:09:25 UTC
      RTC time: Thu 1970-01-01 01:11:27
      Time zone: Asia/Shanghai (CST, +0800)
      System clock synchronized: no
      NTP service: inactive
      RTC in local TZ: no
      admin@ub20:/etc/apt$ E: Release file for http://mirrors.aliyun.com/ubuntu-ports/dists/focal-security/InRelease is not valid yet (invalid for another 628d 4h 2min 55s). Updates for this repository will not be applied.^C
      admin@ub20:/etc/apt$ timedatectl list-timezones
      Africa/Abidjan
      Africa/Accra
      America/North_Dakota/Beulah
      America/North_Dakota/Center
      America/North_Dakota/New_Salem
      ...
      Asia/Seoul
      Asia/Shanghai
      admin@ub20:/etc/apt$ sudo timedatectl set-timezone Asia/Shanghai
      admin@ub20:/etc/apt$ sudo timedatectl set-ntp true
      admin@ub20:/etc/apt$ date
      Wed May 29 16:05:07 CST 2024
      admin@ub20:/etc/apt$
      admin@ub20:/etc/apt$ sudo apt-get update
      [sudo] password for admin:
      Hit:1 http://mirrors.aliyun.com/ubuntu-ports focal InRelease
      Get:2 http://mirrors.aliyun.com/ubuntu-ports focal-security InRelease [114 kB]
      Get:3 http://mirrors.aliyun.com/ubuntu-ports focal-updates InRelease [114 kB]
      Get:4 http://mirrors.aliyun.com/ubuntu-ports focal-proposed InRelease [267 kB]
      Get:5 http://mirrors.aliyun.com/ubuntu-ports focal-backports InRelease [108 kB]
      Get:6 http://mirrors.aliyun.com/ubuntu-ports focal-security/main arm64 Packages [2243 kB]
      Get:7 http://mirrors.aliyun.com/ubuntu-ports focal-security/main Translation-en [443 kB] ...
      Get:71 http://mirrors.aliyun.com/ubuntu-ports focal-backports/universe DEP-11 48x48 Icons [13.3 kB]
      Get:72 http://mirrors.aliyun.com/ubuntu-ports focal-backports/universe DEP-11 64x64 Icons [22.7 kB]
      Get:73 http://mirrors.aliyun.com/ubuntu-ports focal-backports/universe DEP-11 64x64@2 Icons [29 B]
      Fetched 12.3 MB in 57s (216 kB/s)
      Reading package lists... Done
      admin@ub20:/etc/apt$

  1. bandizip

    以前用7z,因为它免费,一般我尽量找能够替代收费软件的替代品,毕竟用破解版总感觉对作者不尊重似的,后来用上bandizip主要是因为同样也是免费的,另外支持直接查看压缩包里面的图片.

介绍

devres(Device resource)设备管理资源,是一个内核设施,通过自动释放驱动程序中分配的资源来帮助开发人员。它简化了init/probe/open函数中的错误处理。使用Devres,每个资源分配器都有自己的托管版本,负责资源的 release 和 free。Devres由一个与struct设备相关联的任意大小内存区域的链表组成。每个devres资源分配器将已分配的资源插入到列表中。资源一直是可用的,直到代码手动释放它,或当设备从系统中分离,或当驱动程序被卸载。每个devres条目都与一个release函数相关联。释放devres有不同的方法。无论如何,所有devres条目在驱动分离时被释放。在释放时,将调用相关的release函数,然后释放devres条目。

下面是驱动程序可用的资源列表:

  • 用于私有数据结构的内存
  • 中断(IRQs)
  • 内存区域分配(request_mem_region())
  • 内存区域I/O映射(ioremap())
  • 缓冲内存(可能带有DMA映射)
  • 不同的框架数据结构: clocks,GPIOs, PWMs, USB phy, regulators, DMA等等

devres函数接口描述

devres结构体

1
2
3
4
5
struct devres {
struct devres_node node;
/* -- 3 pointers */
unsigned long long data[]; /* guarantee ull alignment */
};

API - devres_alloc函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp) 
{
return devres_alloc_node(release, size, gfp, NUMA_NO_NODE);
}


/**
* devres_alloc - Allocate device resource data
* @release: Release function devres will be associated with
* @size: Allocation size
* @gfp: Allocation flags
* @nid: NUMA node
*
* Allocate devres of @size bytes. The allocated area is zeroed, then
* associated with @release. The returned pointer can be passed to
* other devres_*() functions.
*
* RETURNS:
* Pointer to allocated devres on success, NULL on failure.
*/
void * devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid)
{
struct devres *dr;

dr = alloc_dr(release, size, gfp | __GFP_ZERO, nid);
if (unlikely(!dr))
return NULL;
return dr->data;
}
EXPORT_SYMBOL_GPL(devres_alloc_node);

API

Thermal框架

一、设备树配置

  1. 设备树添加温度传感器

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    &i2c3 {
    status = "okay";
    #address-cells = <1>;
    #size-cells = <0>;

    tmp451_0: thermal@4c {
    compatible = "ti,tmp451";
    #thermal-sensor-cells = <1>; /*必现添加该属性,thermal中才能使用*/
    reg = <0x4c>;
    };
    }
  2. 设备树cooling_device pwm风扇

    1
    2
    3
    4
    5
    6
    7
    8
    fan0: pwm-fan-0 {
    compatible = "pwm-fan";
    pwms = <&pwm0 0 101>;
    cooling-min_state = <0>;
    cooling-max_state = <3>;
    #cooling-cells = <2>; /*必现添加该属性,thermal中才能使用*/
    cooling-levels = <50 128 192 255>;
    };
  3. 软件将tsensor和NTC(热敏电阻)等可以获取温度的设备描述为thermal zone, 在代码中以dts的形式来描述。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    /*thermal_zones 下每一个子节点都是一个 thermal, 在 /sys/class/thermal 下对应一个 thermal_zoneX 目录,ntc的也在里面*/
    thermal_zones: thermal-zones {
    ...
    soc_max {
    polling-delay = <0>; /* /* 温控未发生时(超过阈值时)轮询周期(ms) */ */
    polling-delay-passive = <0>; /* 温控发生时(未超过阈值时)的轮询周期(ms) 配置为0,代表不使用轮询方式,通过tsensor中断触发温控。*/
    thermal-governor = "step_wise"; /* 补充的,该温区发生温控时所使用的算法*/
    thermal-sensors = <&lvts 0>; /* 对应的sensor,表示使用 lvts 这个温度传感器的通道0 */

    trips { /* 温控触发点 */
    soc_max_crit: soc_max_crit@0 {
    /* 触发温度为(116500)/1000 = 116.5 度发生温控,对应 trip_point_0_temp 文件 */
    temperature = <116500>;
    /* 滞后温度,表示当下降到(116.5 – 2000/1000) = 114.5 度时解除温控,对应 trip_point_0_hyst 文件 */
    hysteresis = <2000>;
    /*
    * "critical"表示触发温控后立刻重启,若配置为”passive”,表示当温控发生后由governor控制,
    * 轮询周期改为使用 polling-delay-passive,对应 trip_point_0_type 文件
    */
    type = "critical";
    };
    };
    };
    ...
    }

    备注:trips 即触发点,每个 thermal zone 可以维护多个 trip point,其 type 为 trip point类型,沿袭PC散热方式,分为四种类型:

    • passive — 由 governor 的温控策略来降温
    • active — 由 governor 的温控策略来降温
    • hot— 由 governor 的温控策略来降温
    • critical — 温度触发后直接触发重启

    示例:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    thermal_zones: thermal-zones {
    cpu_thermal: cpu {
    polling-delay-passive = <100>;
    polling-delay = <1000>;

    thermal-sensors = <&tmp451_0 0>;

    trips {
    cpu_alert0: cpu_alert0 {
    temperature = <36000>;
    hysteresis = <2000>;
    type = "passive";
    };
    };

    cooling-maps {
    map0 {
    trip = <&cpu_alert0>;
    cooling-device = <&fan0 1 2>;
    };
    };
    };

二、文件接口

  • /sys/class/thermal/thermal_zoneX/sys/class/thermal/thermal_zone0

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    -r--r--r-- available_policies //可选的温控governor,如 power_allocator user_space step_wise
    --w------- emul_temp //模拟设置thermal的温度,单位毫摄氏度,设置后 update_temperature()中可获取到这个温度,和实际达到这个温度同效果。只有其为0,读取的才是真正的温度值,否则就是echo的模拟值
    -rw-r--r-- integral_cutoff
    -rw-r--r-- k_d
    -rw-r--r-- k_i
    -rw-r--r-- k_po
    -rw-r--r-- k_pu
    -rw-r--r-- mode //此thermalzone是否使能了,若是为disabled,对其sys文件的操作不生效,可以echo enabled使能
    -rw-r--r-- offset
    -rw-r--r-- passive
    -rw-r--r-- policy //当前使用的governor是哪个
    -rw-r--r-- slope
    -rw-r--r-- sustainable_power
    -r--r--r-- temp //该温区的当前温度,测试时往 emul_temp 中写的值也会体现在这里。
    -rw-r--r-- trip_point_0_hyst //滞后温度,来自设备树 hysteresis 字段,此例中为 2000。有 trips 节点才会有此文件。
    -rw-r--r-- trip_point_0_temp //触发温度,来自设备树 temperature字段,此例中为 116500,可以通过sysfs更改。
    -r--r--r-- trip_point_0_type //触发点0的类型,来自设备树 type 字段,此例中为"critical"
    -r--r--r-- type //该温区的名称,对应于设备树 thermal_zones 下子节点的名字,此例中为"soc_max"
    -rw-r--r-- uevent
  • /sys/class/thermal/cooling_deviceX

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    /sys/class/thermal/cooling_device0 # ls -l
    -rw-r--r-- cur_state //该 cooling_device 的当前 cooling state
    -r--r--r-- max_state //该 cooling_device 的最大 cooling state
    drwxr-xr-x stats
    -r--r--r-- type //该cooling device的名称
    -rw-r--r-- uevent

    /sys/class/thermal/cooling_device0 # ls -l stats/
    --w------- reset //对统计状态进行复位
    -r--r--r-- time_in_state_ms //在每个state下停留的时间
    -r--r--r-- total_trans //不同state之间转换的次数
    -r--r--r-- trans_table //各个state状态转换表,最大只能显示1个页的内容

    备注:type 为 thermal-cpufreq-X 的 cool device 控制 CPU ClusterX 的频点,比如向 cur_state 中写入 max_state 的值,对应Cluster的 scaling_max_freq 文件将显示被限制到了最小频点。
    type 为 thermal-cpufreq-X 的是通过 cpufreq_cooling.c 注册的 cool device,type 为 thermal-devfreq-X 的是通过 devfreq_cooling.c 注册的 cool device。

    示例:

    通过sys节点控制风扇转速:

    1
    2
    root@ub20:/sys/devices/virtual/thermal/cooling_device0
    echo 2 > cur_state

为了能更好的了解芯片,现对芯片设计中用到的总线知识进行归类总结。

一、概述

​ AMBA (Advanced Microcontroller Bus Architecture) 高级微处理器总线架构:AMBA总线在连接和管理IP核方面发挥着至关重要的作用,它就像一种高效的“数 字胶”,能够将不同的IP核紧密地连接在一起,形成一个功能强大的集成电路系统。

​ 主要包括:

AHB (Advanced High-performance Bus) 高级高性能总线

​ AHB主要是针对高效率、高频宽及快速系统模块所设计的总线,它可以连接如微处理器、芯片上或芯片外的内存模块和DMA等高效率模块

ASB (Advanced System Bus) 高级系统总线—-用的很少

APB (Advanced Peripheral Bus) 高级外围总线

​ APB主要用在低速且低功率的外围,可针对外围设备作功率消耗及复杂接口的最佳化;APB在AHB和低带宽的外围设备之间提供了通信的桥梁

AXI (Advanced eXtensible Interface) 高级可拓展接口

​ APB主要用在低速且低功率的外围,可针对外围设备作功率消耗及复杂接口的最佳化;APB在AHB和低带宽的外围设备之间提供了通信的桥梁

总线区别

二、总线之间关联

AHB2APB同步桥:可以将AHB的信号转换为APB的信号