日常技能/踩坑合集
持续更新
tmux
安装tmux
apt-get install tmux查看当前tmux server情况:
tmux ls启动tmux
tmux new -s roclinux创建新的窗口:
第一步:按 Ctrl+B 组合键,然后松开。 第二步:再单独按一下 c 键。
切换到bash 1
第一步:按 Ctrl+B 组合键,然后松开。 第二步:再单独按一个1
右下角的*代表当前所在窗口
暂离tmux,但让tmux继续运行:
第一步:按 Ctrl+B 组合键,然后松开。 第二步:再单独按一下 d 键。
回到tmux server
[root@roclinux ~]# tmux ls roclinux: 2 windows (created Fri Jan 22 16:30:13 2016) [130x36] [root@roclinux ~]# tmux a -t roclinux关闭当前窗口
第一步:按 Ctrl+B 组合键,然后松开。 第二步:再单独按一下 x 键。
彻底关闭tmux
Ctrl + d或输入exit命令
docker
由于dockerhub国内镜像源关闭了,暂存一个可用的配置 (2024.11.23时可用)
root@VM-20-9-ubuntu:/home/ubuntu/tmp_docker# cat /etc/docker/daemon.json
{
"registry-mirrors":
[
"https://docker.m.daocloud.io",
"https://noohub.ru",
"https://huecker.io",
"https://dockerhub.timeweb.cloud"
]
}llvm
llvm 安装:
apt install lsb-release wget software-properties-common gnupg
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh <version number>
# if number is 18
ln -s /usr/bin/clang-18 /usr/bin/clang
ln -s /usr/bin/clang++-18 /usr/bin/clang++torch
实验室cuda11.7环境适配的版本安装
https://pytorch.org/get-started/locally/
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117newlib编译
写这个是想从newlib里抓出benchmark,我们的目标是得到aarch64的.o文件。
注意newlib是服务于嵌入式系统的,--target用什么aarch64-linux-gnu是没有任何作用的,于是我们使用--target=aarch64-none-elf
newlib官网:https://sourceware.org/newlib/
首先下载newlib
wget ftp://sourceware.org/pub/newlib/newlib-4.4.0.20231231.tar.gz需要安装一个aarch64-none-elf的交叉编译工具,在该网站获得:https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
假设下载的是gcc-arm-11.2-2022.02-aarch64-aarch64-none-elf.tar.xz,解压后:
vim ~/.bashrc
export PATH=$PATH:/usr/local/software/gcc-arm-11.2-2022.02-aarch64-aarch64-none-elf/bin
source ~/.bashrc接下来可以编译了,编译必须在一个和newlib-xxx完全不同的一个文件夹中
在那个文件夹中:
../newlib-4.4.0.20231231/configure --prefix=`pwd` --target=aarch64-none-elf
apt-get install texinfo然后再`make`就可以了。
如果用arm-gnu的话,应该用的就是这个下载的gcc的版本;如果是用clang的话,用本身主机服务器上的版本
默认的给host和target的编译选项是-O2 -g
gcc加O2或O3选项:../newlib-4.4.0.20231231/configure --prefix=`pwd` --target=aarch64-none-elf CFLAGS_FOR_TARGET="-O3 -g"。(似乎不能CFLAGS也加,CFLAGS_FOR_TARGET也加?这个不确定)
用clang编译:../newlib-4.4.0.20231231/configure --prefix=`pwd` --target=aarch64-none-elf CC_FOR_TARGET="clang" CFLAGS_FOR_TARGET="-target aarch64-none-elf -O2 -g",如果想用别的版本的话,比如`CC_FOR_TARGET="clang-14"`;这里不加-O2就不会优化
然后就拿到了libc.a:
得到全部的函数名:nm -A ./newlib/libc.a | grep ' T '
拿到每个函数的汇编程序:objdump -d ./newlib/libc.a | awk '/<{func_name}>:/,/^$/ && !/<{func_name}>:/'
可以用链接器链接每个函数是否有效来判断这个函数有没有外部符号跳转。
misc : 如果需要改newlib代码的话,是用的autoconf工具,newlib4.4.0的版本必须用autoconf 2.71版本
apt remove autoconf
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
./configure
make && make allbenchexec
BenchExec 是一个用于 可靠资源测量 和 基准测试(Benchmarking) 的框架,主要用于在 受控环境 中运行程序,并精确测量其 CPU时间、内存使用、I/O、返回值 等指标。它广泛应用于 程序分析工具评测(如静态分析器、验证工具) 和 性能测试 领域。
安装直接使用命令安装:
pip install benchexec # Python 3.6+如果只想用runexec命令,可以直接使用如下命令,并且会把执行的命令输出到output.log
runexec -- ./wcslen.s.out注意如果是在/tmp命令,可能会出现容器相关错误,需要用命令:
runexec --no-container -- ./wcslen.s.out注意会报警告:LXCFS is not available, some host information like the uptime and the total number of CPU cores leaks into the container.
可以简单用命令解决:
sudo apt install lxcfs然后会报错:
2025-04-01 12:16:27,426 - CRITICAL - Failed to configure container with operation 'raise OSError(': [Errno 22] Failed to create overlay mount for '/': Invalid argument. Please either install version 1.10 or higher of fuse-overlayfs, or use a different directory mode such as '--read-only-dir /'.
2025-04-01 12:16:27,428 - CRITICAL - Cannot execute './main': execution in container failed, check log for details.即需要安装`fuse-overlayfs`,但是直接apt安装的版本太低,需要手动编译安装
git clone https://github.com/containers/fuse-overlayfs.git
cd fuse-overlayfs
sudo ./autogen.sh
sudo apt install -y fuse3 libfuse3-dev
sudo ./configure
sudo make
sudo make install