当前位置:网站首页>使用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系统了,是不是极致性能了呢?
边栏推荐
- The C programming language (version 2) notes / 8 UNIX system interface / 8.1 file descriptor
- (五)输出和输出
- 怎么在公司里面做好测试工作(做好测试工作)
- [MySQL] Cartesian product - multi table query (detailed explanation)
- Qcustomplot notes (I): qcustomplot adding data and curves
- The C programming language (2nd Edition) notes / 7 input and output / 7.8 other functions
- Concurrent trichromatic marking
- 并发包和AQS
- Daily question -890 Find and replace mode
- Joint recruitment notice of ganfei research group of Wuhan University and xuzhenjiang research group of Nanchang University
猜你喜欢

Overview of webrtc's audio network Countermeasures

Contract awarding and AQS

Unit sshd. service could not be found

Extract the new Chinese cross modal benchmark zero from 5billion pictures and texts, and Qihoo 360's new pre training framework surpasses many SOTAS

Doctor application | National University of Singapore, Xinchao Wang, teacher recruitment, doctor / postdoctoral candidate in the direction of graph neural network
![[Hunan University] information sharing of the first and second postgraduate entrance examinations](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Hunan University] information sharing of the first and second postgraduate entrance examinations

ISCC-2022 部分wp

Swin transformer code explanation

Mongodb learning and sorting (basic command learning of users, databases, collections and documents)

Demande de doctorat | xinchao Wang, Université nationale de Singapour
随机推荐
Leetcode 2194. Excel 表中某个范围内的单元格(可以,已解决)
Exception assertion of assertj
[research] reading English papers -- the welfare of researchers in English poor
Analysis of Nacos config dynamic refresh source code
[BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
并发包和AQS
Qcustomplot notes (I): qcustomplot adding data and curves
How to base on CCS_ V11 new tms320f28035 project
Why is your next computer a computer? Explore different remote operations
Programmers broke the news: 3 job hopping in 4 years, and the salary has tripled! Netizen: the fist is hard
JS monitors whether the user opens the screen focus
The C programming language (2nd Edition) notes / 7 input and output / 7.8 other functions
Idea displays services on the console to uniformly manage all jetty services,
Uniapp壁纸小程序源码/双端微信抖音小程序源码
Pat class a 1139 first contact
博士申请 | 新加坡国立大学Xinchao Wang老师招收图神经网络方向博士/博后
key为断言的map是怎么玩的
Google浏览器调试技巧
Leetcode 2194. Cellules dans une plage dans un tableau Excel (OK, résolu)
Iscc-2022 part WP