X C Bindings
XCB 是应用与 X 服务器交互使用的 C 绑定函数集,它里面的一些 C 函数是通过 python3-xcbgen 工具生成的,不经过编译在它的源码库是找不到的。而且 XCB 古老到仍然使用 autotools 那套构建系统,想要看到某些函数的“真容”,你还得“千呼万唤”。
XCB 是应用与 X 服务器交互使用的 C 绑定函数集,它里面的一些 C 函数是通过 python3-xcbgen 工具生成的,不经过编译在它的源码库是找不到的。而且 XCB 古老到仍然使用 autotools 那套构建系统,想要看到某些函数的“真容”,你还得“千呼万唤”。
Vulkan 是一个低开销、跨平台的二维和三维图形与计算的应用程序接口,由 Khronos 在2015年在 GDC 上首次发布。它旨在提供高效能和更均衡的 CPU 和 GPU 占用,类似于 Direct3D 12 和 AMD Mantle。
本文主要记录一下在 llvmpipe 软渲染 Vulkan 驱动下, 一个 vulkan 应用程序 (demo) 的执行过程。
Linux 计算加速器子系统旨在以通用的方式向用户空间开放计算加速器的接口。这些计算加速器可以是独立的 ASIC, 也可以是 SoC/GPU 内的 IP 块。通常计算加速器包括以下几种类型:
高端硅片可以构建市场,但最终,软件支持往往决定了赢家和输家
-- Jack Huynh, AMD 高级副总裁兼计算和图形业务集团总经理
AMD 的通用计算平台 ROCm (Radeon Open Compute) 是在通用计算领域与 NVIDIA 的 CUDA (Compute Unified Device Architecture) 相抗衡的软件基础设施。ROCm 实现的其实是由 AMD 发起的 HSA (Heterogeneous System Architecture) 标准,所以它的运行时主要由 3 个部分组成:
OOC: ROCm 平台又叫 Boltzmann 平台,原因据说是为了纪念统计力学和热力学领域著名物理学家路德维希·玻尔兹曼,他的工作对理解物质的微观行为和能量分布有着深远的影响。AMD 选取这个名字,可能是为了强调该平台在高性能计算领域的强大计算力和科学计算的应用前景。
Hantro Products OY 是一家专注于视频编解码技术的芬兰公司,它的视频编码 IP (Hantro H1) 和解码 IP(Hantro G1) 被集成在瑞芯微 RK3288 SoC 上。其开源驱动在 drivers/media/platform/verisilicon
Perfetto 是一个用于 Linux 和 Android 系统上进行系统级和应用级的跟踪和性能分析的开源工具。Perfetto 捆绑了许多数据源,这些数据源能够从不同的系统接口收集详细的性能数据,包括 ftrace, /proc, /sys, native heap profiling 等。Perfetto 还提供了一个基于 Web 的用户界面,用于跟踪数据的可视化和分析。这里主要是对第一次使用 perfetto 做一下记录,方便以后继续学习和整理。
GLSL 是一种高级着色语言,语法接近 C 语言。它由 OpenGL ARB 创建,旨在让开发者能够更直接地控制图形管线,而无需使用 ARB 汇编语言或特定硬件语言。
实际上 GLSL 包括大概 6 种着色语言:
WSL (Windows Subsystem for Linux)是一个能够在 Windows 系统(Windows 10及以上版本)上原生运行 Linux 可执行文件的兼容层。目前有两个版本: WSL, WSL2
mesa/src/loader/loader_dri3_helper.c::dri3_alloc_render_buffer()
, 这个函数不长,但却涉及到了DRI框架的许多重要概念,buffer共享(DMABUF), GPU offload (PRIME), buffer同步(X client和server),送显(present), modifiers等等,所以非常值得深入分析。
同步原语(Synchronization Primitive)的确切定义没有一个官方的。但大体来说同步原语可能有以下几种:
升2级后的第一盘棋黑竟然下出了连续11手的AI一选(从黑97到黑121), 当然这也与白的应招有关系。不过 可惜最终黑123还是错失翻盘机会。局后复盘,看到连续11手的一选有点激动,故此记录
“Replacing NIR with SPIR_V?” 是mesa-dev maillist 上2022-01-20的一封邮件主题. 从邮件讨论中我了解到了许多知识,在此记录一下。
名词 | 全称 | 解释 |
---|---|---|
IR | Intermediate Representation | 编译器中使用的中间表示,一般是编译器优化 Pass 和后端的输入 |
NIR | New IR | Mesa 中专门为 Graphics shader 设计的一种 IR, 它可以作为特定后端的输入,如 LLVM AMDGPU 后端 |
SPIR | Standard Portable IR | 一种用于并行计算和图形的中间语言(interchage language), 由 Khronos Group 在 2012 年引入 |
SPIR-V | SPIR-Vulkan | 由 Khronos Group 在 2015 年引入,用来替代原来的 SPIR |
RISC | Reduced Instruction Set Computer | 精简指令集, 与 CISC 相对 |
RISC-V | RISC five | 由加州 Berkeley 大学开发的一种开放且模块化的 RISC 指令集架构 |
SIMD | Single Instruction Multiple Data | 费林分类法(Flynn’s Taxonomy) 中的一种,其它的还有 SISD, MIMD, MISD |
SIMT | Single Instruction Multi-Threads | SIMD 的一种子类型 |
在 Linux GPU 软件栈这块,大体包含 3 个 Pipelines
Boot-up Graphics 指在 Linux 系统启动时涉及到一些和图形显示相关的问题。
最近和朋友的孩子下了几盘棋,在惊叹现在孩子的聪慧和学习能力之余,也深感自己的“棋艺”着实有待提高。便又拣起荒废已久的弈城账号,想下几盘找找感觉,结果又一次应了那句,“业精于勤,荒于嬉”。失落之余,索性去 B 站,重看邱百瑞老师的带你零基础学围棋.
再看确实有不一样的感受。围棋的奥妙和那些千古流传的棋理自不必多说,我想自己学习下棋,试着了解棋理的原因,也是被围棋这种“方寸之间有天地,黑白之处显乾坤”的魅力所折服。
Communication is hard, especially with all the different personalities, languages, and
cultures involved in an international community like this.– Faith Ekstrand
It is rules and not our individual smarts that keep us from making mistakes.
– Faith Ekstrand
分别在 Windows 11 上安装 usbipd-win, 在 WSL2 上安装 user space tools for USB/IP
1 | Microsoft Windows [版本 10.0.22621.1702] |
1 | [Thu Jun 15 19:19:44 2023] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3) |
HiKey970 有两个 Type-C 接口,而且当板子被设置为 Recovery 模式时,两个接口均会被识别为“串口”。在左手边的 (J3101) 是用来访问 Debug UART 的,而在 HDMI 和 USB 中间的那个(J1801)是在 Recovery 模式下使用的。而且这两个接口是两个不同厂家提供的芯片,使用完全不同的内核驱动模块
Bus 001 Device 003: ID 04e2:1410 Exar Corp. XR21V1410 USB-UART IC
Bus 001 Device 002: ID 12d1:3609 Huawei Technologies Co., Ltd. USB SER
系统调用是Linux 用户态程序与内核通信的接口。 每个特定的文件系统都会在自己的 file_operations
里提供各种文件操作接口,这些接口包括像 open, close, ioctl 等等
Syscall signature | Function description |
---|---|
int dup(int oldfd); | |
int dup2(int oldfd, int newfd); | |
uid_t getuid(void); | |
uid_t geteuid(void); | |
pid_t getpid(void); | return process ID of calling process |
pid_t getppid(void); | return process ID of parent of calling process |
int ioctl(int fd, unsigned long request, …); | 操作底层设备参数,尤其像终端这种字符设备 |
ioctl 成功返回 0, 否则返回 -errno (有的 man ioctl 说ioctl不成功时返回 -1, 这种应该是过时的文档)。
Gamma LUT (Look-Up Table) is a property that is used to correct the color and brightness of an image or video. Gamma LUT is basically a table of values that is used to map input values to output values, for example, it may map low input values to higher output values to brighten the image.
Gamma LUT is used to adjust the gamma curve of an image or video, which means it can be used to correct the brightness and contrast of an image. This property is commonly used in image and video processing applications, such as photo editing software, video editing software, and color grading tools.
Gamma LUT can also be used to correct color shifts caused by different lighting conditions or camera settings. By adjusting the gamma curve of an image or video, it is possible to create a more natural and accurate representation of the original scene.
Linux 内核的 patch 是以纯文本的邮件形式进行提交和代码走查的,而且 patch 是先到内核子系统 maintainer 维护的 git tree, 再到 Linus Torvalds 的 main tree。本文主要是以一个 patch 提交的实例来记录一下整个过程中的一些具体操作要点,至于 kernel patch 提交的规范和操作细节内核文档 和各种博客文章有很多,这里不再赘述。
ACPI是一个开放标准,全称为Advanced Configuration and Power Interface(高级配置与电源接口)。它是一种用于电源管理和配置硬件设备的接口规范。
ACPI的主要目的是提供一种标准化的方法,使操作系统能够与计算机的固件(如BIOS)进行交互,管理电源管理、设备配置和系统资源的一致性。它定义了一组操作系统接口和数据结构,用于控制和监测硬件设备的电源状态、配置和事件。
通过ACPI,操作系统能够实现电源管理的功能,如系统的睡眠、休眠和唤醒,以及动态调整设备的功耗和性能。它还提供了高级功能,包括热插拔设备的支持、温度传感器的监测以及处理器性能的调整。
ACPI存在于大多数现代计算机系统中,并得到广泛支持。它在各种操作系统中广泛使用,包括Windows、Linux、Apple macOS等。通过ACPI,计算机系统能够更好地管理电源和硬件资源,实现能效和性能的平衡,提供更好的用户体验。
UEFI GOP 是 UEFI(统一可扩展固件接口)中的一个图形输出协议。它提供了在 UEFI 环境下进行图形输出的标准接口。
UEFI GOP 的主要功能包括:
提供图形模式设置、获取当前图形模式等图形初始化相关功能。
提供绘制像素、填充矩形、绘制线条等基本图形输出功能。
提供双缓冲区切换、视口管理等高级图形功能。
支持各种颜色格式如 RGB、YUV 等。
提供与硬件无关的抽象接口,通过 GOP 驱动与特定硬件交互。
支持全屏和窗口两种输出模式。
支持各种分辨率的图形输出。
通过使用 UEFI GOP,操作系统和应用可以在 UEFI 阶段实现图形界面和图形输出,如启动菜单、系统配置界面等。许多操作系统的启动器都会使用 GOP 进行图形化显示。
所以简单来说,UEFI GOP 为 UEFI 固件和操作系统提供了标准的图形输出接口,使其可以实现固件过程中的图形化显示和交互。它是实现 UEFI 图形环境的基础。
HSA(Heterogeneous System Architecture) 是一种异构系统架构,用于在CPU和GPU等异构处理器之间进行并行计算。其主要特点包括:
协处理器架构:HSA定义了主处理器(CPU)和协处理器(GPU等)之间的关系,协处理器协助CPU完成计算任务。
统一地址空间:CPU和协处理器共享同一个虚拟地址空间,可以直接访问对方的内存。
协作计算模型:支持CPU和协处理器之间的并行计算,任务可以自动在最合适的处理器上运行。
优化数据传输:通过DMA等机制优化CPU和协处理器之间的数据传输。
标准化程序接口:为开发人员提供标准化的程序接口,简化异构计算的软件设计。
HSA让CPU和GPU之间可以高效协作,优化系统整体的并行计算性能,被认为是未来异构计算架构的发展方向。AMD是HSA的主要推动者,其APU产品已经开始支持HSA。HSA也吸引了其他处理器厂商的广泛支持。
总而言之,HSA是一种创新的异构系统架构,通过处理器协作和优化提升整体计算性能,对高效并行计算有重要意义。
目前支持HSA标准的SoC产品不多,主要有:
AMD Kaveri APU:这是AMD于2014年发布的首款HSA 1.0兼容APU,集成CPU和GPU,支持共享虚拟内存。
AMD Carrizo APU:2015年发布,同样支持HSA 1.0,并进一步增强了CPU和GPU的协作计算能力。
AMD Ryzen APU:如Ryzen 5 2400G,集成Vega graphics,支持共享内存和异构计算。
AMD Raven Ridge APU:首款集成Vega图形的Ryzen移动APU,支持HSA。
Qualcomm Snapdragon 820:高通在Snapdragon 820平台增加了HSA 1.1支持。
领悟科技(HSA Foundation)Mustang-V100-A10:这是全球首块完全兼容HSA 1.0规范的独立heterogeneous SoC。
领悟科技(HSA Foundation)Mustang-F100-A10:进一步优化的heterogeneous SoC。
总体来说,AMD是目前最主要的HSA支持厂商,其多款APU产品都实现了HSA规范。高通也加入了HSA支持。此外,一些创业公司如领悟科技也推出了支持HSA的SoC。随着规范的逐步完善,预计未来将会有更多的异构SoC产品实现HSA兼容。
我:那么符合 HSA 标准的 APU 与普通的 SoC 有什么区别?
ChatGPT:
符合HSA标准的APU和普通SoC的主要区别有:
HSA APU采用统一地址空间,CPU和GPU可以直接访问对方的缓存和内存,简化数据传输。普通SoC的CPU和GPU存在独立的地址空间。
HSA APU支持CPU和GPU直接访问系统内存,无需数据复制,提高效率。普通SoC需要在内存空间之间进行数据复制。
HSA提供标准化的程序接口如HSAIL,简化异构编程的复杂ity。普通SoC缺乏统一的接口。
HSA APU通过协处理器等机制,可根据workload自动在CPU和GPU间分配任务,调度更优化。普通SoC无法做到如此灵活的协作计算。
HSA APU采用高速互联如AMD的Infinity Fabric,提升CPU和GPU之间的数据传输速度。
HSA APU通过硬件级的优化如内存控制器集成,实现更紧密的协作。
综上,HSA APU通过硬件架构和软件接口的优化,实现了CPU与GPU更加紧密、高效的异构计算,相比普通SoC有明显优势。这使其在并行计算性能上有显著提升。
mmu_notifier
vs. mmu_interval_notifier
M: please shed light on the distinction mmu_notifier from mmu_interval_notifier in the linux kernel
C: In the Linux kernel, both MMU notifier and MMU interval notifier are used to track changes in page tables and memory mappings. However, there are some differences between the two:
MMU notifier is used to track changes to page tables and memory mappings, and it is designed to be a general-purpose notifier. It is used by various subsystems in the kernel, such as memory management, file systems, and device drivers.
MMU interval notifier, on the other hand, is used specifically to track changes to a range of memory pages. It is used by subsystems that need to be notified of changes to a particular range of memory pages, such as virtualization subsystems.
In summary, MMU notifier is a more general-purpose notifier used to track changes to page tables and memory mappings, while MMU interval notifier is used specifically to track changes to a range of memory pages.
Vulkan ICD (Installable Client Driver) is a software component that enables the Vulkan API (Application Programming Interface) to interact with the hardware of a computer system. Vulkan is a low-level graphics API developed by the Khronos Group, which provides developers with more control over hardware resources, leading to improved performance and efficiency in graphics-intensive applications such as video games. The Vulkan ICD is responsible for managing the communication between the Vulkan API and the graphics hardware of a system. It is typically provided by the manufacturer of the graphics card as a driver for the system.
Light Display Manager 是一个轻量级的跨桌面环境的 Display Manager, 可以支持多种显示技术,如 X11, Mir, Wayland.
开发包依赖
构建工具依赖
安装
Lightdm 可执行程序路径 /usr/sbin/lightdm
, 日志默认路径 /var/log/lightdm/lightdm.log
. 所以构建时可以使用
--prefix
指定安装路径 (默认 /usr/local)--localstatedir
指定日志路径 (默认 $prefix/var/log/lightdm)--sysconfdir
指定 lightdm.conf
路径 (默认 $prefix/etc/lightdm)1 | ./autogen.sh --prefix=/usr --localstatedir=/var --sysconfdir=/etc --disable-tests |
Sanitizer 是一个动态 Bug 检测的工具,它可以检测的 Bug 有以下几类:
[1]Be wise, sanitize: Keeping your C++ code free from bugs
[2]An LLVM developer setup: Modern C++ development tools
make olddefconfig
configuration | version |
---|---|
distro | Ubuntu 22.04 Jammy Jellyfish |
gcc | 11.2.0 |
original kernel | 5.15.0-43-generic |
building kernel | v6.0 |
Errors | Resolution |
---|---|
gelf.h: No such file or directory | apt install libelf-dev |
<openssl/opensslv.h>: No such file or directory | apt install libssl-dev |
No rule to make target ‘debian/canonical-certs.pem’ | scripts/config –disable SYSTEM_TRUSTED_KEYS |
No rule to make target ‘debian/canonical-revoked-certs.pem’ | scripts/config –disable SYSTEM_REVOCATION_KEYS |
1 | make KCONFIG_CONFIG=Microsoft/config-wsl |
apt install -y dwarves
1 | LD vmlinux.o |
1 | AS arch/x86/boot/header.o |
mv arch/x86/boot/bzImage /mnt/c/Users/luc/
编辑 /mnt/c/Users/luc/.wslconfig, 添加下面两行
1 | [wsl2] |
NOTE: 如果以上两行添加进 /etc/wsl.conf 文件,不会有任何作用, 因为
/etc/wsl.conf
不支持wsl2
Section
wsl --terminate
.1 | wsl --shutdown Ubuntu-20.04 |
1 | make nconfig |
配置更改后重新 make
1 | ➜ tests git:(master) sudo ./kms_writeback --device "sys:/sys/devices/platform/vkms" |
1 | [10893.662944] [IGT] kms_writeback: executing |
1 | 6 |
LLVM 是 Low-Level Virtual Machine 的简写,但事实上它与虚拟机关系不大。我们更熟悉它是一套工具链,包括 clang /'klæŋ/
, lld, lldb 等等。接触 LLVM 是因为 Mesa llvmpipe 使用 LLVM, 还有 AMDGPU 和 Radeon 的编译器后端都使用 LLVM IR,所以要编译 Mesa 的 -Dgallium-drivers=llvmpipe,radeonsi
都依赖于 LLVM 的诸多组件, 构建 Linux 内核的 eBPF 程序也依赖 LLVM, 构建 perfetto 也依赖 LLVM。这里主要记录 LLVM 的构建和使用的一些问题。
POSIX Basic Regular Expression
POSIX Extended Regular Expression
shorthand | equivalence |
---|---|
\w |
[[:alnum:]_] |
\W |
[^[:alnum:]_] |
\s |
[[:space:]] |
\S |
[^[:space:]] |
shorthand | matches |
---|---|
\b |
position at a word boundary |
\B |
position not at a word boundary |
\< |
position at the start of a word |
\> |
position at the end of a word |
\` (backtick) |
position at the start of subject string |
\' (single quote) |
position at the end of subject string |
1 | ${var:+WORD} |
如果 var
没有设置或为空,则这个变量展开为 Nothing (注意:不是空 empty, 是 nothing), 如果被设置了(不包括被设置成空),它展开为 +
后面的 WORD.
如果冒号被省略,则 var
即使被设置为空,它也展开为 +
后面的 WORD
1 | ${!var} |
如果 var
的值是 MESA_DEBUG
, 那么这个形式展开后是变量 MESA_DEBUG
的值,例如 export MESA_DEBUG=1
, var=MESA_DEBUG
, 则最后的展开结果是 1
1 | ${var@Q} |
带 @Q
指变量展开后的值被单引号引起来,例如 export ABC=abc
, echo "ABC=${ABC@Q}"
的结果是 ABC='abc'
Linux 下的文本处理三剑客: grep, sed, awk, 除了它们其实还有一些小巧的命令,如 tr
, cut
也可以帮助我们快速处理和格式化文本。
下面以一个例子为例。
在 Linux 内核源码树里,搜索出目录 drivers/gpu/drm
下所有的 DRIVER_NAME
定义,并排序后格式化输出
命令如下:
1 | rg '#define DRIVER_NAME' drivers/gpu/drm --no-heading | tr -s '\t' | tr '\t' ' ' | tr -s ' ' | awk -F':' '{printf("%-52s%-40s\n",$1,$2)}' | sort -k4 | xclip -i |
rg
(ripgrep) 比 grep 更快,更强大tr
在不带任何选项时,默认执行替换,例子是中将 tab 替换成 空格, -s
表示 squeeze-repeats
, 就是去重awk
天生支持 C-Style printf输出结果:
1 | drivers/gpu/drm/solomon/ssd130x.c:#define DRIVER_NAME "ssd130x" |
1 | drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h #define DRIVER_NAME "amdgpu" |
Highly recommended 3 utilities:
eisvogel 要求一个完整的 TexLive 的安装环境,但通常像 CentOS 这样的 Linux 发行版自带的 TexLive 并不完整。
texlive.iso
将 TexLive 的镜像下载并挂载后,通过顶层目录下的 install-tl
这个 Perl 脚本程序安装,整个安装过程要注意以下几点。
假设在 Linux 下,通过 root 用户或 sudo
挂载镜像文件
1 | mkdir -p /mnt/iso |
TexLive 的 installer 是一个 perl script, 提供 text mode 和 GUI mode 两种安装模式.
1 | ======================> TeX Live installation procedure <===================== |
1 | Options customization: |
最好勾选此选项,避免使用 TexLive 时各种 Not Found
, 原因是 TexLive 默认安装路径并不是标准 Linux 可执行程序的路径(如 /usr/bin
), 而是 /usr/local/texlive
, 如在 x86_64 安装 texlive2022.iso
, 则可执行程序被安装在 /usr/local/texlive/2022/bin/x86_64-linux
. 假如不想因为该路径没有在 PATH
里,最好就是在安装时直接在 /usr/bin
下创建相应符号链接。
在使用 xelatex, pdflatex 等 latex 程序时,可以常常遇到类似
! LaTeX Error: File 'fontawesome.sty' not found
xxx.sty 这样的报错,一般是缺少某个 texlive 包,但 texlive 的包太多了,如果懒得一个一个安装,可以
sudo apt install texlive-full
find
命令find
命令用来在目录树里查找文件。本文主要介绍 GNU find. 它从每个 starting-point 开始递归搜索,通过求值 expression 的真值来确定输出结果。
find
的命令行组成只在当前目录搜索(不递归)不以 f 或 g 或 h 开头的目录
find . -maxdepth 1 -name '[^fgh]*' -type d
排除/proc 和 /tmp 这两个目录
find / -path /proc -prune -o -path /tmp -prune -o -name "README.md"
-prune
告诉 find 跳过前面的目录,也可以用 \( -o \)
将多个 -path
合并,只保留一个 -prune
只在当前目录查找除了指定及隐藏目录以外的所有目录,打印并删除
find -maxdepth 1 \( -path ./gh -o -path ./aaa -o -path ./mesa-install -o -path ./1.3.290.0 -o -path ./1.3.280.1 \) -prune -o -type d ! -name ".*" -print -exec rm -rf {} \;
.*
, .
在 shell 里不是通配符查找 ~/gh 目录下只有文件属主(u)有执行权限(x)的文件 (精确匹配文件的 permission bits)
find ~/gh -perm u=x -type f
查找 ~/gh 目录下文件属主(u)有执行权限(x) 的文件(组用户(g)或其它用户(o)可能有或没有执行权限)
find ~/gh -perm -u=x -type f
A language that doesn’t affect the way you think about programming, is not worth knowing.
– Alan J. Perlis, Recipient of 1966 Turing Award
最近在两个地方看到nightly这个词:
drm-tip或drm/drm-tip (我也不知道这两个仓库有什么区别,除了它们的Owner不同)
DRM current development and nightly trees
本文的标题来自Linux Kernel 5.6.0-rc4文档, dma-buf作为一个内核子系统,它的使用场景不局限于drm “PRIME“ multi-GPU支持,它主要由3个组件支撑:
本文翻译 Daniel Vetter 于 2015 年 8 月 5 日发表在 LWN.net 的文章 “Atomic mode setting design overview, part 1”. 文章主要阐述了为什么要引入一个全新的 Kernel Display Driver 接口以及新老实现的一些细节。
rustc
cargo
增加rand
crate包后再执行构建
cargo update
会做些什么首先要了解的是在安装rustup
后,在$HOME
下会创建一个.cargo
目录,它的目录结构大概如下
/home/luc/.cargo |-- bin | |-- cargo | |-- cargo-clippy | |-- cargo-fmt | |-- cargo-miri | |-- clippy-driver | |-- rls | |-- rust-gdb | |-- rust-lldb | |-- rustc | |-- rustdoc | |-- rustfmt | `-- rustup |-- env `-- registry |-- cache | `-- github.com-1ecc6299db9ec823 |-- index | `-- github.com-1ecc6299db9ec823 `-- src `-- github.com-1ecc6299db9ec823 8 directories, 13 files
cargo update
会根据工程目录下的Cargo.toml
中Dependencies
的版本信息下载相应版本的依赖以及依赖的依赖,cargo update
后的.cargo
目录结构大概如下
/home/luc/.cargo |-- bin | |-- cargo | |-- cargo-clippy | |-- cargo-fmt | |-- cargo-miri | |-- clippy-driver | |-- rls | |-- rust-gdb | |-- rust-lldb | |-- rustc | |-- rustdoc | |-- rustfmt | `-- rustup |-- env `-- registry |-- cache | `-- github.com-1ecc6299db9ec823 | |-- libc-0.2.98.crate | |-- rand-0.3.23.crate | `-- rand-0.4.6.crate |-- index | `-- github.com-1ecc6299db9ec823 `-- src `-- github.com-1ecc6299db9ec823 |-- libc-0.2.98 |-- rand-0.3.23 `-- rand-0.4.6 11 directories, 16 files
References:
如果先调用sched_setaffinity
将线程绑定到CPU1上,再将CPU1逻辑关闭(offline),会发生什么?在Linux系统中,要回答这个问题,先要搞清楚Linux下的3个机制:
CPU hotplug的意思是, Linux允许Logically Shutdown
和Bring Up
CPU, 用户可以通过sysfs
接口操作
1 | echo 0 > /sys/devices/system/cpu/cpu1/online |
1 | echo 1 > /sys/devices/system/cpu/cpu1/online |
/proc/interrupts
, /proc/cpuinfo
, top
都将看不到它
我只列出跟上面的疑问有关系的:
当关闭CPU1后,原来运行在CPU1上的进程将被移到新的CPU们上调度,具体哪个CPU是从这个进程当前的cpuset中选择,所以疑问转换成了“sched_setaffinity
对进程当前的cpuset做了什么?”
Transform Feedback首先是DirectX3D引入的,但在DirectX3D中它不叫TF, 而是叫Stream Output Stage. 它第一次被引入OpenGL是在2006年,但当时是以扩展的形式GL_EXT_transform_feedback引入的,它正式成为OpenGL Required Core Features是在OpenGL 3.0(2008), 在这之后,OpenGL 4.0, 4.2, 4.6又分别引入了一些TF相关的新特性。
除了安装 C++ 标准库实现 libstdc++-9
, g++-9
这些软件包外,还要安装 g++
dpkg-deb --contents /var/cache/apt/archives/g++_4%3a9.3.0-1ubuntu2_amd64.deb
1 | drwxr-xr-x root/root 0 2020-03-20 21:52 ./ |
使用GEM内存管理器,所有新的驱动都应该支持。
支持Kernel Modesetting Interfaces
支持专门的渲染节点, 即**/dev/dri/renderD**
支持所有的Atomic Modesetting用户空间API
支持drm_syncobj, 用于渲染命令提交的显式同步。
支持drm_syncobj的timeline特性
内核 DRM 子系统的代码仓库托管在cgit上,Upstream DRM Subsystem Repository, 这个仓库最主要的两个分支
drm-next
这个分支的补丁包括 DRM 核心和所有 GPU 驱动的新特性
drm-fixes
-Dgallium-drivers
与 -Ddri-drivers
的区别,以及它们与 -Degl
的关系从构建的角度看, -Dgallium-drivers
与 -Ddri-drivers
是无关的。
1 | DRI platform: drm |
1 | EGL: yes |
1 | Gallium drivers: swrast panfrost |
1 | build/src/gallium/targets/dri/libgallium_dri.so |
1 | @startuml |
1 | /** |
resource_copy_region 只能在 buffer 与 buffer 之间或 texture 与 texture 之间 memcpy, 而且源与目标的 format 必须相同。之所以不能做 buffers 与 textures 之间的 memcpy, 至少是因为缺少 stride 参数。一些硬件(如 nvidia) 可以通过专门的 copy engine 完成这些拷贝,但对于其它硬件可能需要一个 compute shader 去做这些拷贝。另一方面,那些专门的 copy engine 通常是比较慢的,所以只在那些带宽非常有限的 PCIe 传输场景下才有用。如果想利用全部的
VRAM 带宽(甚至 infinity cache bandwidth), 你很可能必须使用 compute shaders.
Direct Rendering Manager是Linux kernel中负责与GPU接口的子系统,但它不仅仅用在Linux, 它也会用在像OpenBSD的其它一些类UNIX系统。
Vulkan 是一个低开销、跨平台的二维和三维图形与计算的应用程序接口,由 Khronos 在2015年在 GDC 上首次发布。它旨在提供高效能和更均衡的 CPU 和 GPU 占用,类似于 Direct3D 12 和 AMD Mantle。
在这里主要收集一些与 Vulkan 强相关的一些项目,便于 Vulkan 的学习和使用。
示例:
1 | glmark2 -b desktop:nframes=1000000:show-fps=true -b build:duration=100 |
GLX (Initialism for “OpenGL Extension to the X Window System”) is an extension to the X Window System core protocol providing an interface between OpenGL and the X Window System as well as extensions to OpenGL itself. (From WiKi)
Mesa的 GLX 实现自从 Delete Mesa Classic 已经从原来的 3 种变成现在的 2 种:
flowchart TD A[xlib or gallium-xlib] A --> x11 A --> xext A --> xcb B[dri] B --> x11 B --> xext B --> xfixes B --> xcb-glx B --> xcb-shm
如果是xlib, 它的源码位于
如果是gallium-xlib, 它的源码位于
在 Linux 下 dri-based glx 实现我们只关注 3 个实现:
源文件 | 关键函数 |
---|---|
dri2_glx.c | dri2CreateScreen() |
dri3_glx.c | dri3_create_screen() |
drisw_glx.c | driswCreateScreenDriver() |
1 | 3772:00:00.0 0100: 1af4:1049 (rev 01) |
lspci -Dn
的输出格式是:
1 | <domain>:<bus>:<slot>.<func> |
这里的 slot
其实就是 device
, 而且只包含 2 位十六进制数字。我们可以从 lspci
的源码看到
1 | static void |
lspci 之所以只使用 2 位十六进制数字分别表示 bus
, slot
(dev
), 是因为它们被定义成 8 位位宽
1 | struct pci_dev { |
Device
Section1 | Section "Device" |
Device
Section 中 BusID
的格式是
1 | PCI:bus:device:func |
1 | xf86Msg(X_PROBED, "PCI:%s(%u@%u:%u:%u) %04x:%04x:%04x:%04x ", prim, |
日志中的 PCI BusID 格式是
1 | bus@domain:device:func |
最近看了一些关于Modern CMake(since 3.0.0)的教程,这里记录一下.
最近在看X11 Server的代码,顺手做下笔记。X11 Server的代码很古老了,有的是1993年写的,目前的X Server实现X.org是从最早的一个X Server实现XFree86 4.4 RC2版本(2004年)派生出来的。
FourCC format code是Linux内核DRM子系统用来描述framebuffer像素格式。它们被定义在内核源码include/uapi/drm/drm_fourcc.h. 基本上FourCC format code足以描述framebuffer中像素的内容了,但是随着GPU的更新,原来线性排列的buffers,为了获取更好的性能,可能会采取vendor specific的布局方式。另外,这些buffer也可能保存的是各种不同的压缩数据,这样一来,原来的FourCC format code就无法携带新的buffer
layout或compression format的信息,DRM format modifier就是用来解决这些问题的。
Given that a difficulty to add a custom X11 device driver or module or extension for Xserver, I try to find out how an Xserver is built and its dependent drivers and modules and extensions are orgnized together by building it from source.
smart pointer是C++11引入的,被包含在C++标准库中。smart pointer是为了管理对象的所属(object ownership)而设计的,smart pointer对象负责自动地销毁所关联对象。常见的smart pointer有:
选择 {}
(curly braces) 之间的行(包括 {}
)
v%
选择 {}
(curly braces) 之间的行(不包括 {}
)
vi{
注意:光标必须放在 {
或者 }
"+y
X11 window system 有 3 个 selections:
Vim 有两个专门的寄存器分别与 PRIMARY selection 和 CLIPBOARD selection 对应
"*
(quotestar) PRIMARY"+
(quoteplus) CLIPBOARD如果要在 Vim 内部剪贴,复制/粘贴就使用 quotestar, 如果要将内容剪贴,复制/粘贴到系统剪贴板,就使用 quoteplus
举个例子,在 WSL Ubuntu 里如果想粘贴 Windows 剪贴板里的内容到 vim (最好是 neovim, 因为 vim 可能未使能 clipboard)
1 | echo "Hello, world!" | clip.exe |
"+p
如果想粘贴 Ubuntu 剪贴板里的内容
1 | echo "Hello, world!" | xclip |
"*p
在 Insert 模式下
<ctrl-y>
copies the character from the line above<ctrl-e>
copies the character from the line below (本行就是这样输入的)s;/\*\_.\{-}\*/;;
;
因为要匹配 /
, 为了省去转义 /
的麻烦,将 search 命令的分隔符由 /
改为 ;
/\*
匹配开始的 /*
\_.
匹配任意字符,包括 \n
, 所以常用在多行匹配
\{-}
指非贪婪 (non-greedy) 匹配,即匹配最短的字串,默认是贪婪匹配,匹配最长的字串
\*/
匹配结尾的 */
;;
指使用空替换匹配结果,即删除
以下是 vim 中在单行中使用的通配符 (wildcard), 这些通配符一般不能匹配换行 \n
.
匹配除了 \n
的任意字符^
行首,即锚点 (anchor)$
行尾,即锚点\s
匹配 space, tab, 但不匹配 \n
以上通配符加上 \_
后可以在多行匹配中使用,即也可以匹配 \n
\_.
匹配任意字符,包括 \n
\_^
多行中第一行行首\_$
多行中最后一行行尾\_s
匹配 space, tab 和 \n
g/^\s*$/d
g
指所有行搜索,而不是默认的光标所在行^\s*$
匹配行首到行尾之间任意个空白字符,即空白行d
删除命令 (delete)/^\(\(^# .*$\)\@!.\)*$
/
查找命令 (search) 的提示符^\(\(The_Regex\)\@!.\)*$
反向查找的命令固定模式,本例中 The_Regex
是 ^# .*$
即以 #
开头的行,所以整个表达式匹配的就是不以 #
开头的所有行:v/^# .*$/p
s/\(^# .*$\)/\L\1/
\(The_Regex\)
为了向前索引,即后面 \1
所指的部分,本例中 The_Regex
是 ^# .*$
, 意思同上\L\1
\L
指 Lowercase, 即将 \1
匹配的结果中的所有字母都换成小写s/\(^# .*$\)/\U\1/
\1
匹配的结果中的所有字母都换成大写 (Uppercase)__attribute__
is a keyword introduced by GCC. It is regarded as an extension of a language. It helps the compiler optimize calls, check code more carefully for correctness, control memory placement and code generation options.
X11 is designed as client-server mode. The communication between the X client and server complies with TCP protocol. Recently I have a Windows X server VcXsrv installed on my Windows 10 and I debug an OpenGL demo glxgears on the WSL2 with tcpdump.
WSL2 is equipped with its own networking interface like a virtual machine.
1 | $ ifconfig |
1 | $ /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -C "ipconfig" |
After starting up the X server VcXsrv, you need to export the environmnet variable DISPLAY
on the WSL. In case of the vEthernet configuration changed after rebooting you’d better do it like this:
1 | export DISPLAY=$(grep 'nameserver' /etc/resolv.conf | awk '{print $2}'):0 |
NOTE: The Firewall between the host and WSL2 must be disabled or your X client can not connect VcXsrv.
I trace the demo glxgears using gdb and tcpdump at the same time.
1 | gdb -q -tui glxgears |
1 | sudo tcpdump -vvX not icmp and not arp and not udp and portrange 37900-37999 -w x110224.pcap |
1 | tcpdump -X -r x110224.pcap |
1 | reading from file /home/luc/github/x110224.pcap, link-type EN10MB (Ethernet) |
what codes sends and receives these packets? The first two twenty-byted segments are IP header (20 bytes without option) and TCP header (20 bytes without option) separately in these packets.
The source code snippet:
1 | Bool |
The gdb log:
1 | Starting program: /mnt/c/Users/lulu/Documents/github/demos/src/xdemos/glxgears |
$2
is Request packet content to VcXsrv, $3
is Reply packet content from VcXsrv. Even that we can notice the three-way handshake of TCP from the zero-lengthed packet in x110224.pcap.