linux – 内核构建缓存/非确定性

前端之家收集整理的这篇文章主要介绍了linux – 内核构建缓存/非确定性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_1@我运行一个CI服务器,用于构建自定义Linux内核. CI服务器功能不强,每个构建的时间限制为3h.为了在这个限制内工作,我有了使用ccache缓存内核构建的想法.我希望我可以在每个次要版本发布时创建一个缓存,并将其重新用于补丁版本,例如:我有一个我为4.18制作的缓存,我想用于所有4.18.x内核.

@H_404_1@删除构建时间戳后,这适用于我正在构建的确切内核版本.对于上面引用的4.18内核,在CI上构建它会提供以下统计信息:

@H_404_1@

$ccache -s
cache directory                     
primary config                      
secondary config      (readonly)    /etc/ccache.conf
stats zero time                     Thu Aug 16 14:36:22 2018
cache hit (direct)                 17812
cache hit (preprocessed)              38
cache miss                             0
cache hit rate                    100.00 %
called for link                        3
called for preprocessing           29039
unsupported code directive             4
no input file                       2207
cleanups performed                     0
files in cache                     53652
cache size                           1.4 GB
max cache size                       5.0 GB
@H_404_1@缓存命中率100%和一小时完成构建,梦幻般的统计数据和预期.

@H_404_1@不幸的是,当我尝试构建4.18.1时,我得到了

@H_404_1@

cache directory                     
primary config                      
secondary config      (readonly)    /etc/ccache.conf
stats zero time                     Thu Aug 16 10:36:22 2018
cache hit (direct)                     0
cache hit (preprocessed)             233
cache miss                         17658
cache hit rate                      1.30 %
called for link                        3
called for preprocessing           29039
unsupported code directive             4
no input file                       2207
cleanups performed                     0
files in cache                     90418
cache size                           2.4 GB
max cache size                       5.0 GB
@H_404_1@这是1.30%的命中率,而构建时间反映了这种糟糕的表现.从仅一个补丁版本改变.

@H_404_1@我原本预计缓存性能会随着时间的推移而降低,但不会达到这种程度,所以我唯一的想法就是有更多的非确定性而不仅仅是时间戳.例如,大多数/所有源文件是否包括完整的内核版本字符串?我的理解是,像这样的东西会彻底打破缓存.有没有办法让缓存按照我的意愿工作或者不可能?

最佳答案
有include / generated / uapi / linux / version.h头文件(在顶级Makefile https://elixir.bootlin.com/linux/v4.16.18/source/Makefile生成)

@H_404_1@其中包括精确的内核版本作为宏:

@H_404_1@

version_h := include/generated/uapi/linux/version.h
old_version_h := include/linux/version.h

define filechk_version.h
    (echo \#define LINUX_VERSION_CODE $(shell                         \
    expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \
    echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
endef

$(version_h): $(srctree)/Makefile FORCE
    $(call filechk,version.h)
    $(Q)rm -f $(old_version_h)
@H_404_1@因此,将生成用于linux 4.16.18的version.h(266258是(4<<< 16)(16<<<< 8)18 = 0x41012)

#define LINUX_VERSION_CODE 266258
#define KERNEL_VERSION(a,c) (((a) << 16) + ((b) << 8) + (c))
@H_404_1@稍后,例如在模块构建中,应该有方法来读取LINUX_VERSION_CODE宏值https://www.tldp.org/LDP/lkmpg/2.4/html/lkmpg.html(4.1.6.为多个内核版本编写模块)

@H_404_1@

@H_404_1@The way to do this to compare the macro LINUX_VERSION_CODE to the macro KERNEL_VERSION. In version a.b.c of the kernel,the value of this macro would be 2^{16}a+2^{8}b+c. Be aware that this macro is not defined for kernel 2.0.35 and earlier,so if you want to write modules that support really old kernels

@H_404_1@如何包含version.h?示例模块包括< linux / kernel.h> < LINUX /&module.h中GT;和< linux / modversions.h>,其中一个文件可能间接包含全局version.h.大多数甚至所有内核源代码都包含version.h.

@H_404_1@比较构建时间戳时,可能会重新生成version.h并禁用ccache.当忽略时间戳时,LINUX_VERSION_CODE仅对完全相同的Linux内核版本相同,并且对于下一个补丁级别进行更改.

@H_404_1@更新:检查一些内核对象编译的gcc -H输出,会有另一个带有完整内核版本宏定义的头.例如:include / generated / utsrelease.h(UTS_RELEASE宏),include / generated / autoconf.h(CONFIG_VERSION_SIGNATURE).

@H_404_1@或者甚至在两个补丁级别之间进行相同内核对象编译的gcc -E预处理,并比较生成的文本.使用最简单的linux模块,我直接在gcc命令行中包含./include/linux/kconfig.h,它包含include / generated / autoconf.h(但这在-H输出中不可见,是bug还是功能GCC?).

@H_404_1@https://patchwork.kernel.org/patch/9326051/

@H_404_1@

@H_404_1@… because the top Makefile forces to include it with:

@H_404_1@06002

@H_404_1@它实际上是:https://elixir.bootlin.com/linux/v4.16.18/source/Makefile

@H_404_1@

# Use USERINCLUDE when you must reference the UAPI directories only.
USERINCLUDE    := \
        -I$(srctree)/arch/$(SRCARCH)/include/uapi \
        -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
        -I$(srctree)/include/uapi \
        -I$(objtree)/include/generated/uapi \
                -include $(srctree)/include/linux/kconfig.h

# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
LINUXINCLUDE    := \
        -I$(srctree)/arch/$(SRCARCH)/include \
        -I$(objtree)/arch/$(SRCARCH)/include/generated \
        $(if $(KBUILD_SRC),-I$(srctree)/include) \
        -I$(objtree)/include \
        $(USERINCLUDE)
@H_404_1@LINUXINCLUDE导出到env并在source / scripts / Makefile.lib中用于定义编译器标志https://elixir.bootlin.com/linux/v4.16.18/source/scripts/Makefile.lib

@H_404_1@

  c_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)    
原文链接:https://www.f2er.com/linux/440987.html

猜你在找的Linux相关文章