1bf215546Sopenharmony_ciUpreving Linux Kernel
2bf215546Sopenharmony_ci=====================
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_ciOccasionally, the Gitlab CI needs a Linux Kernel update to enable new kernel
5bf215546Sopenharmony_cifeatures, device drivers, bug fixes etc to CI jobs.
6bf215546Sopenharmony_ciKernel uprevs in Gitlab CI are relatively simple, but prone to lots of
7bf215546Sopenharmony_ciside-effects since many devices from different platforms are involved in the
8bf215546Sopenharmony_cipipeline.
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ciKernel repository
11bf215546Sopenharmony_ci-----------------
12bf215546Sopenharmony_ci
13bf215546Sopenharmony_ciThe Linux Kernel used in the Gitlab CI is stored at the following repository:
14bf215546Sopenharmony_cihttps://gitlab.freedesktop.org/gfx-ci/linux
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_ciIt is common that Mesa kernel brings some patches that were not merged on the
17bf215546Sopenharmony_ciLinux mainline, that is why Mesa has its own kernel version which should be used
18bf215546Sopenharmony_cias the base for newer kernels.
19bf215546Sopenharmony_ci
20bf215546Sopenharmony_ciSo, one should base the kernel uprev from the last tag used in the Mesa CI,
21bf215546Sopenharmony_ciplease refer to `.gitlab-ci/container/gitlab-ci.yml` `KERNEL_URL` variable.
22bf215546Sopenharmony_ciEvery tag has a standard naming: `vX.YZ-for-mesa-ci-<commit_short_SHA>`, which
23bf215546Sopenharmony_cican be created via the command:
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci:code:`git tag vX.YZ-for-mesa-ci-$(git rev-parse --short HEAD)`
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ciBuilding Kernel
28bf215546Sopenharmony_ci---------------
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ciWhen Mesa CI generates a new rootfs image, the Linux Kernel is built based on
31bf215546Sopenharmony_cithe script located at `.gitlab-ci/container/build-kernel.sh`.
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ciUpdating Kconfigs
34bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ciWhen a Kernel uprev happens, it is worth compiling and cross-compiling the
37bf215546Sopenharmony_ciKernel locally, in order to update the Kconfigs accordingly.  Remember that the
38bf215546Sopenharmony_ciresulting Kconfig is a merge between *Mesa CI Kconfig* and *Linux tree
39bf215546Sopenharmony_cidefconfig* made via `merge_config.sh` script located at Linux Kernel tree.
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ciKconfigs location
42bf215546Sopenharmony_ci"""""""""""""""""
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci+------------+--------------------------------------------+-------------------------------------+
45bf215546Sopenharmony_ci| Platform   | Mesa CI Kconfig location                   | Linux tree defconfig                |
46bf215546Sopenharmony_ci+============+============================================+=====================================+
47bf215546Sopenharmony_ci| arm        | .gitlab-ci/container/arm.config            | arch/arm/configs/multi_v7_defconfig |
48bf215546Sopenharmony_ci+------------+--------------------------------------------+-------------------------------------+
49bf215546Sopenharmony_ci| arm64      | .gitlab-ci/container/arm64.config          | arch/arm64/configs/defconfig        |
50bf215546Sopenharmony_ci+------------+--------------------------------------------+-------------------------------------+
51bf215546Sopenharmony_ci| x86-64     | .gitlab-ci/container/x86_64.config         | arch/x86/configs/x86_64_defconfig   |
52bf215546Sopenharmony_ci+------------+--------------------------------------------+-------------------------------------+
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ciUpdating image tags
55bf215546Sopenharmony_ci-------------------
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ciEvery kernel uprev should update 3 image tags, located at two files.
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci:code:`.gitlab-ci/container/gitlab-ci.yml` tag
60bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
61bf215546Sopenharmony_ci- **KERNEL_URL** for the location of the new kernel
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci:code:`.gitlab-ci/image-tags.yml` tags
64bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
65bf215546Sopenharmony_ci- **KERNEL_ROOTFS_TAG** to rebuild rootfs with the new kernel
66bf215546Sopenharmony_ci- **DEBIAN_X86_TEST_GL_TAG** to ensure that the new rootfs is being used by the Gitlab x86 jobs
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ciDevelopment routine
69bf215546Sopenharmony_ci-------------------
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci1. Compile the newer kernel locally for each platform.
72bf215546Sopenharmony_ci2. Compile device trees for ARM platforms
73bf215546Sopenharmony_ci3. Update Kconfigs. Are new Kconfigs necessary? Is CONFIG_XYZ_BLA deprecated? Does the `merge_config.sh` override an important config?
74bf215546Sopenharmony_ci4. Push a new development branch to `Kernel repository`_ based on the latest kernel tag used in Gitlab CI
75bf215546Sopenharmony_ci5. Hack `build-kernel.sh` script to clone kernel from your development branch
76bf215546Sopenharmony_ci6. Update image tags. See `Updating image tags`_
77bf215546Sopenharmony_ci7. Run the entire CI pipeline, all the automatic jobs should be green. If some job is red or taking too long, you will need to investigate it and probably ask for help.
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ciWhen the Kernel uprev is stable
80bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci1. Push a new tag to Mesa CI `Kernel repository`_
83bf215546Sopenharmony_ci2. Update KERNEL_URL `debian/x86_test-gl` job definition
84bf215546Sopenharmony_ci3. Open a merge request, if it is not opened yet
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ciTips and Tricks
87bf215546Sopenharmony_ci---------------
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ciCompare pipelines
90bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ciTo have the most confidence that a kernel uprev does not break anything in Mesa,
93bf215546Sopenharmony_ciit is suggested that one runs the entire CI pipeline to check if the update affected the manual CI jobs.
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ciStep-by-step
96bf215546Sopenharmony_ci""""""""""""
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci1. Create a local branch in the same git ref (should be the main branch) before branching to the kernel uprev kernel.
99bf215546Sopenharmony_ci2. Push this test branch
100bf215546Sopenharmony_ci3. Run the entire pipeline against the test branch, even the manual jobs
101bf215546Sopenharmony_ci4. Now do the same for the kernel uprev branch
102bf215546Sopenharmony_ci5. Compare the job results. If a CI job turned red on your uprev branch, it means that the kernel update broke the test. Otherwise, it should be fine.
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ciBare-metal custom kernels
105bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ciSome CI jobs have support to plug in a custom kernel by simply changing a variable.
108bf215546Sopenharmony_ciThis is great, since rebuilding the kernel and rootfs may takes dozens of minutes.
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ciFor example, freedreno jobs `gitlab.yml` manifest support a variable named
111bf215546Sopenharmony_ci`BM_KERNEL`. If one puts a gz-compressed kernel URL there, the job will use that
112bf215546Sopenharmony_cikernel to boot the freedreno bare-metal devices. The same works for `BM_DTB` in
113bf215546Sopenharmony_cithe case of device tree binaries.
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ciCareful reading of the job logs
116bf215546Sopenharmony_ci^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ciSometimes a job may turn to red for reasons unrelated to the kernel update, e.g.
119bf215546Sopenharmony_ciLAVA `tftp` timeout, problems with the freedesktop servers etc.
120bf215546Sopenharmony_ciSo it is important to see the reason why the job turned red, and retry it if an
121bf215546Sopenharmony_ciinfrastructure error has happened.
122