当前位置:网站首页>使用GCC的PGO(Profile-guided Optimization)优化整个系统
使用GCC的PGO(Profile-guided Optimization)优化整个系统
2022-06-12 16:43:00 【天涯路linux】
启发
来自于巨硬在自家服务器上做的实验,废话不多直接上图

微软的方法

微软的方法

可以看到使用PGO优化的内核还是有一些性能提升的
零、前提
想要使用PGO编译优化,你的gcc编译器需要开启支持pgo特性,gentoo系统如下
sudo vim /etc/portage/make.conf:
USE="pgo"
sudo emerge gcc一、内核kernel的优化
cd /usr/src/linux
sudo make clean
sudo make menuconfig:
CONFIG_DEBUG_FS=y
CONFIG_GCOV_KERNEL=y
CONFIG_GCOV_PROFILE_ALL=y
sudo make KCFLAGS=“-fprofile-dir=/kernel-pgo/”
最后安装kernel并更新grub
sudo make install
sudo grub-config -o /boot/grub/grub.cfg
重启系统
sudo reboot然后在新内核下运行系统一段时间,打开各种软件如浏览器、mpv播放器、cmus、办公、编译软件、下载、游戏、steam等等(即将日常用系统的各个软件和场景全部跑一遍),以让内核收集足够全面的profile数据(gcov数据)
#注:开启了CONFIG_DEBUG_FS=y、CONFIG_GCOV_KERNEL=y特性的kernel性能会明显下降,但这对收集用于PGO优化的profile数据是必要的
内核PGO优化的profile数据就储存在/sys/kernel/debug/gcov/kernel-pgo/目录下,有很多小文件,格式类似为"#usr#src#linux#arch#x86#crypto#aesni-intel_glue.gcda"
sudo cp -r /sys/kernel/debug/gcov/kernel-pgo/ /
cd /usr/src/linux
sudo make clean
sudo make menuconfig:
CONFIG_DEBUG_FS=n
CONFIG_GCOV_KERNEL=n
CONFIG_GCOV_PROFILE_ALL=n
sudo make KCFLAGS=“-fprofile-use -fprofile-dir=/kernel-pgo/ -fprofile-correction -Wno-coverage-mismatch -Wno-error=coverage-mismatch”
最后安装kernel并更新grub
sudo make install
sudo grub-config -o /boot/grub/grub.cfg
重启系统
sudo reboot好了,现在你可以体验经过PGO编译优化的内核是个什么性能了,打开游戏去测试下fps吧,是不是比原来的内核帧数高了些呢?
补充:使用Clang的LTO优化编译内核
自kernel 5.12开始内核允许进行lto优化了,但目前仅限于支持clang+llvm编译器,不支持gcc,所以你得先安装好clang和llvm,以及lld链接器。步骤很简单——
sudo make LLVM=1 LLVM_IAS=1 menuconfig:
CONFIG_DEBUG_FS=n
CONFIG_GCOV_KERNEL=n
CONFIG_GCOV_PROFILE_ALL=n
CONFIG_LTO_CLANG_FULL=y
然后
sudo make LLVM=1 LLVM_IAS=1即可。
#注:目前clang并不支持内核的gcov优化,因此以上gcc的pgo和clang的lto两种优化方案你只能二选一。
如果你觉得常规的内核满足不了你,还可以试试自己编译xanmod内核这个项目,相较于常规内核做了很多更新进的优化(比如开启O3级别的编译优化)——
https://www.xanmod.org/www.xanmod.org/
#点击网页里的“tarball”即可下载xanmod内核源码包。
二、整个系统内所有程序软件的PGO优化
首先需要关闭portage构建系统的两个安全特性
sudo vim /etc/portage/make.conf:
FEATURES="-sandbox -usersandbox"然后先添加以下gcc编译参数
sudo vim /etc/portage/make.conf:
COMMON_FLAGS="$(你自己原有的编译优化参数) -fprofile-generate -fprofile-dir=/portage-pgo/"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
LDFLAGS="${COMMON_FLAGS} -Wl,-O3 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -Wl,--strip-all -ljemalloc -Wl,-ljemalloc"
EMERGE_DEFAULT_OPTS="--with-bdeps=y --ask --deep --verbose=y --load-average --keep-going"
sudo mkdir /portage-pgo/现在开始编译整个系统
sudo emerge -e @world编译结束后重启系统
sudo reboot然后在新系统下运行系统一段时间,打开各种软件如浏览器、mpv播放器、cmus、办公、编译软件、下载、游戏、steam等等(即将日常用系统的各个软件和场景全部跑一遍,建议用上1-2天),以收集足够全面的profile数据(gcov数据),各个程序PGO优化的profile数据就储存在/portage-pgo/目录下
#注:开启了-fprofile-generate特性的程序性能会明显下降,但这对收集用于PGO优化的profile数据是必要的
重启系统
sudo reboot然后修改gcc编译参数
sudo vim /etc/portage/make.conf:
COMMON_FLAGS="$(你自己原有的编译优化参数) -fprofile-use -fprofile-dir=/portage-pgo/ -fprofile-correction -Wno-error=missing-profile"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
LDFLAGS="${COMMON_FLAGS} -Wl,-O3 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -Wl,--strip-all -ljemalloc -Wl,-ljemalloc"再次编译整个系统以使用PGO优化(开启pgo优化后编译速度会大大提高,时间不会像上一次那么久了)
sudo emerge -e @world编译结束后重启系统
sudo reboot好了,现在你可以体验经过PGO全面编译优化的gentoo系统了,是不是极致性能了呢?
边栏推荐
- uabntu的sudo
- canvas 高级功能(下)
- 【湖南大学】考研初试复试资料分享
- [DSP video tutorial] DSP video tutorial Issue 8: performance comparison of DSP library trigonometric function, C library trigonometric function and hardware trigonometric function, and accuracy compar
- 890. 查找和替换模式 / 剑指 Offer II 080. 含有 k 个元素的组合
- Play kubernetes every 5 minutes summary
- 有哪些特容易考上的院校?
- [MySQL] internal connection, external connection and self connection (detailed explanation)
- CVPR 2022 | 元学习在图像回归任务的表现
- Leetcode 2194. Excel 表中某个范围内的单元格(可以,已解决)
猜你喜欢

程序员爆料:4年3次跳槽,薪资翻了3倍!网友:拳头硬了......

Programmers broke the news: 3 job hopping in 4 years, and the salary has tripled! Netizen: the fist is hard

软件工程 学生信息管理系统 结构化的需求分析

JVM内存模型与本地内存

Preprocessing command section 3

Qt开发高级进阶:初探qt + opengl

Demande de doctorat | xinchao Wang, Université nationale de Singapour
![[MySQL] internal connection, external connection and self connection (detailed explanation)](/img/3f/9b88c2f27455f2ddd73808fbb44f8e.jpg)
[MySQL] internal connection, external connection and self connection (detailed explanation)

Cookies and sessions

Anyone who watches "Meng Hua Lu" should try this Tiktok effect
随机推荐
What's the matter with pbootcms' if judgment failure and direct display of labels?
calibration of sth
MySQL interview arrangement
[MySQL] Cartesian product - multi table query (detailed explanation)
Canvas advanced functions (Part 2)
收藏 | 22个短视频学习Adobe Illustrator论文图形编辑和排版
丁总路由器设置以及401联网
Information outline recording tool: omnioutliner 5 Pro Chinese version
[MySQL] internal connection, external connection and self connection (detailed explanation)
'virtue and art' in the field of recurrent+transformer video recovery
1.delete
\begin{algorithm} 笔记
启牛开的证券账户安全吗?合法吗?
The safety of link 01 was questioned, and "ultra high strength" became "high strength"_ Publicity_ Steel_ problem
STL -- function object
mysql语句
Unit sshd. service could not be found
Idea displays services on the console to uniformly manage all jetty services,
Preprocessing command section 3
Leetcode 2194. Cellules dans une plage dans un tableau Excel (OK, résolu)