AMD Linux Kernel Graphics Driver Closing In On 4 Million Lines
With the Linux 5.17 kernel likely to be released later today followed by the Linux 5.18 merge window then getting underway, I was curious about the current size of this massive AMD Linux kernel graphics driver.
Using cloc for counting the lines, as of this morning with Linux Git (v5.17) the modern AMD driver (linux/drivers/gpu/drm/amd/*; not counting the former "radeon" DRM driver for older GPUs), it's at 3.38 million lines. That's just for the kernel graphics driver and not counting the user-space portions within Mesa for RadeonSI Gallium3D and RADV or AMD's AMDVLK Vulkan driver and their other user-space components.
Those 3.38 million lines are from 2.91 lines of actual detected code, 339k lines of code comments, and 1.3 million blank lines between the code.
The 3.38 million lines is very significant and still easily the largest driver within the mainline Linux kernel. In comparison, the Intel i915 kernel graphics driver in DRM-Next at the moment is just 341k lines of code. That's the Intel kernel graphics driver for the latest DG2/Alchemist and Xe HP discrete graphics work back through the old i915 era integrated graphics.
Or when looking at the entire Linux kernel source tree with linux.git, the kernel and other contained code for tools and Kconfig, etc, amounts to 30.63 million lines as of this morning. In other words, the AMD kernel driver continues the trend that's been happening for a while of AMDGPU/AMKFD amounting to more than 10% of the entire Linux kernel code-base. That's quite a size achievement considering the plethora of Linux kernel drivers out there supporting a wide variety of hardware over multiple decades and a wide range of CPU architectures supported. That 30.63 million comes from 22.7 million lines of actual code, another 3.84 million lines of code comments, and 4.03 million blank lines.
While 3.38 million lines for the AMD driver is quite large, looking ahead to Linux 5.18 it's moving closer to 4 million. When measuring up DRM-Next this morning for the AMD code, it's now coming in at 3.82 million! That's from 3.29 million lines of detected code, 391k lines of comments, and 136k blank lines.
Much of the new code additions each cycle for the AMD driver though does come from auto-generated header files from internal documentation and register data. With all the header files introduced as part of each new GPU target supported, the driver only continues to get much larger. Thankfully the compiler eliminates the unused header data. These detailed headers though are important with AMD focusing less (or any aside from the shader ISA?) these days on providing public GPU documentation and instead on focusing on the official Linux driver code as their reference point and these header files for external parties to learn more about the GPU and the bits to play with.
For the AMD graphics driver in Linux 5.18 there is more work on new hardware support as part of their new strategy for IP-based discovery / bringing up new GPU support block-by-block. Additionally the AMDGPU driver with this next kernel version will have FreeSync video mode enabled by default and other changes.
Anyhow, that's how the AMD Linux kernel graphics driver code sizes up at the moment for thought and interesting weekend forum discussions.