AMD Linux Kernel Graphics Driver Closes in on 4 Million Lines
For some time now, the modern AMD Linux kernel graphics driver (code AMDGPU/AMDKFD) has been the most important driver in the core Linux kernel code base. It has been much larger than other upstream kernel drivers given the complexity of modern GPUs and is only getting even larger.
With the Linux 5.17 kernel likely to be released later today, followed by the Linux 5.18 fusion window, I was curious to know the current size of this massive AMD Linux kernel graphics driver.
Using clock to count the lines, since this morning with Linux Git (v5.17) the modern AMD driver (linux/drivers/gpu/drm/amd/*; not counting the old “radeon” DRM driver for older GPUs), c is at 3.38 million lines. That’s just for the kernel graphics driver and not including the userspace portions in Mesa for RadeonSI Gallium3D and RADV or AMD’s AMDVLK Vulkan driver and their other userspace components.
These 3.38 million lines come from 2.91 lines of actually detected code, 339,000 lines of code comments, and 1.3 million blank lines between code.
The 3.38 million lines are very large and easily remain the largest driver in the main Linux kernel. In comparison, the Intel i915 kernel graphics driver in DRM-Next is currently fair 341k lines of code. This is the Intel kernel graphics driver for the latest HP DG2/Alchemist and Xe discrete graphics cards dating back through older i915 era integrated graphics cards.
Or when looking at the whole Linux kernel source tree with linux.git, kernel and other contained code for tools and Kconfig etc. is 30.63 million lines as of this morning. In other words, the AMD kernel driver continues the trend that has been happening for some time of AMDGPU/AMKFD accounting for over 10% of the entire Linux kernel code base. This is quite a significant achievement considering the plethora of Linux kernel drivers supporting a wide variety of hardware over several decades and a wide range of supported processor architectures. These 30.63 million come from 22.7 million lines of actual code, 3.84 million additional lines of code comments, and 4.03 million empty lines.
While 3.38 million lines for the AMD driver is quite significant, looking ahead to Linux 5.18, it’s closer to 4 million. By measuring DRM-Next this morning for the AMD code, it now comes to 3.82 million! This comes from 3.29 million detected lines of code, 391,000 comment lines and 136,000 empty lines.
Much of the new code added each cycle for the AMD driver, however, comes from auto-generated header files from internal documentation and registry data. With all the header files introduced as part of each new supported GPU target, the driver only gets a lot bigger. Fortunately, the compiler eliminates unused header data. Those detailed headers are important though, with AMD focusing less (or any other than the ISA shader?) these days on providing public GPU documentation and more on the official Linux driver code as a point of reference and these header files for external parties to learn more about the GPU and which 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 IP-based discovery strategy / implementation of new block-by-block GPU support. Also, the AMDGPU driver with this next kernel version will have FreeSync video mode enabled by default and other changes.
Anyway, that’s how the AMD Linux kernel graphics driver code is sized at the moment for thought and interesting weekend forum discussions.