当前位置: 首页 > 工具软件 > ccache > 使用案例 >

ccache 加速Kernel 编译

刁俊人
2023-12-01

启动 Docker Script.


# docker   run  -it -v  /home/pyuan/works:/home/build --privileged  registry.redhat.io/ubi8:build    /bin/bash

配置Proxy

[pyuan@workstation works]$ cat http-proxy.conf
#[Service]
#Environment="HTTP_PROXY=http://127.0.0.1:1080" HTTPS_PROXY="http://127.0.0.1:1080"

#export http_proxy="http://127.0.0.1:1080"
#export https_proxy="http://127.0.0.1:1080"



#[Service]
#Environment="HTTPS_PROXY=https://proxy.example.com:443/"

  1. 安装ccache Install Ccache

RHEL:

Install OKey repository:
#dnf install http://repo.okay.com.mx/centos/8/x86_64/release/okay-release-1-2.el8.noarch.rpm
Install okay-release rpm package:
#dnf install okay-release

Install libbabeltrace-devel rpm package:

# dnf install libbabeltrace-devel
# dnf install binutils-devel dwarves elfutils-devel kabi-dw libcap-devel libcap-ng-devel llvm-toolset numactl-devel python3-devel  python3-docutils perl-devel
# dnf install binutils-devel dwarves elfutils-devel kabi-dw libcap-devel libcap-ng-devel  numactl-devel python3-devel  python3-docutils perl-devel

# dnf install https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/c/ccache-3.7.7-1.el8.x86_64.rpm

RHEL 8在编译时需要安装libbpf 和devel rpm
解决方法: 下载 fedora libbpf source code ,build it for rhel8.
https://koji.fedoraproject.org/koji/buildinfo?buildID=1505753

#rpm -ivh https://kojipkgs.fedoraproject.org//packages/libbpf/0.0.7/1.fc32/src/libbpf-0.0.7-1.fc32.src.rpm
#rpmbuild -bb SPEC/libbpf.spec

Another very good repo to install the dependency packages:

```bash
sudo dnf -y install dnf-plugins-core
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

# Enable PowerTools Repository on CentOS 8 / RHEL 8:

sudo dnf config-manager --set-enabled PowerTools
# OR
sudo dnf config-manager --set-enabled powertools

#cat ~/.bashrc

User specific aliases and functions

alias gs=“git status”
alias gd=“git diff”
alias gp=“grep -rsn”
alias gc=“git checkout”
export CCACHE_DIR="/home/pyuan/.ccache"
export CC=“ccache gcc”
export cc1=“ccache cc1”
export ccp1lus=“ccache cc1plus”
export CXX=“ccache g++”
export PATH="/usr/lib/ccache:$PATH"

--------------------------------------------------------------------------------------------------
Ubuntu:
```bash
#sudo apt install ccache
  1. 配置ccache
#vim ~/.bashrc 

#user is the user directory, this directory is used to save compilation information, you can use other directories.
    export CCACHE_DIR="/home/perry/.ccache" 
    export CC="ccache gcc"
    export CXX="ccache g++"
    export PATH="/usr/lib/ccache:$PATH"
  1. 让配置生效, #source ~/.bashrc
  2. 配置ccache 大小为10GB #ccache -M 10G
  3. 编译kernel fakeroot make-kpkg --append-to-version -sof-dev --revision 20201023.2 --initrd kernel-image -j16
  4. 查看ccache 状态
#ccache -s 

perry@perry-Precision-5550:~/work/sof/linux_github_sof$ ccache  -s
cache directory                     /home/perry/.ccache
primary config                      /home/perry/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
stats updated                       Fri Oct 23 08:19:04 2020
stats zeroed                        Fri Oct 23 08:03:48 2020
cache hit (direct)                  3344
cache hit (preprocessed)               1
cache miss                           258
cache hit rate                     92.84 %
called for link                       25
called for preprocessing             121
compiler produced empty output       110
preprocessor error                   342
unsupported code directive             2
no input file                       1443
cleanups performed                     0
files in cache                       663
cache size                          40.4 MB
max cache size                       9.0 GB
perry@perry-Precision-5550:~/work/sof/linux_github_sof$ ccache  -s
cache directory                     /home/perry/.ccache
primary config                      /home/perry/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
stats updated                       Fri Oct 23 08:23:04 2020
stats zeroed                        Fri Oct 23 08:03:48 2020
cache hit (direct)                  3424
cache hit (preprocessed)               1
cache miss                          3556
cache hit rate                     49.06 %
called for link                       31
called for preprocessing             132
compiler produced empty output       110
preprocessor error                   354
unsupported code directive             5
no input file                       1476
cleanups performed                     0
files in cache                     10535
cache size                           1.3 GB
max cache size                       9.0 GB

 类似资料: