A fortnight with Codex

A Linux Kernel Enablement team has to produce at least one Linux Kernel. It turns out our team needs to produce 6. The two variables are page size and distribution. We support 4K, 16K, and 64 K page sizeds for internal testing, and people need to test both Fedora and Ubuntu based builds. When I started this project, we only supported Fedora; the Ubuntu support was one of the driving factors.

This project is called Ampack. I can thank Don Becker for showing me this style of naming back at Penguin.

I spent a good portion of last year reworking our build system from a series of bash scripts into a Python based system using plumbum and a lot of system utilities. Meanwhile, my native coding interest has been shifting to Rust, as we can use it in the Linux Kernel, in Qemu, and a bunch of other places. I was also getting frustrated with the lack of type support in Python…my code could be annotated with MyPy compliant types, but the same was not true for all the libraries I wanted to use.

So, as for the past couple weeks, I have been running a long-ish coding experiment: what would it mean if I used our officially blessed codex deployment to aid the conversion to Rust, and to continue development that way.

This is actually the third of three internal projects I have converted to Rust this way, so it is not really a ground-zero approach. However, the other two projects were both significantly simpler, and were even less of an impact to our team: no one uses them but me and now a couple other developers. The build process, on the other hand, produces artifacts that my team needs to share with other teams in the company, and thus if it goes awry will have consequences.

I do not trust an agent with my ssh keys to access our central git repositories. I run codex in a virtual machine, and have a separate ssh session for pushing and pulling to the git repositories. I plan on improving on this by one more step: run the VM with a shared directory from my hardware-os and perform all of the ssh-based git operations outside the vm.

I gave codex this rule for creating commits: keep the title to shorter than 52 characters. I added in the guidance to be explicit and keep the lines of the commit to under 72 characters.

Here are most of the git commit titles.

Port ampack workflow to Rust

This was the first one, and it was a big one. About 2400 Lines of Rust were generated, with none of the Python code touched. The only shared files modified were things like .gitignore.

Remove unused Rust code

Much of the python code was dead code, and not used. This commit removed about 230 lines of unusued code.


Add production ref sync command

This was the first new feature added: I wanted to make it possible to build using a private repository instead of going to the production git repository. While the python code supported this, the branches we were working with would often get out of sync, and thus testing changes stopped happening. This change used our existing logic to sync the branches over to the private repo, so the next build could be run against the private repo.


Parallelize kernel RPM rebuilds

We had 3 different pages sizes. We could builtd the RPMs for each one in parallel, potentially cutting down the overall wait time, even respecting Amdahl’s law.


Add Debian kernel package publishing

This was the first attempt to build Debian Kernels. It worked, but still required multiple manual steps.


Rebuild Debian packages in parallel

The way we build and rebuild our Kernel is dictated by groups outside oure team: they wan to apply the patches to a Kernel git tree and build that. We have automation, in the form of a shell script, that does this work. So, at the heart of our rust code there still exists some bash. This bash needed to be updated for the Debian steps. We also needed to start tweaking the Rut code to pass the right information to the build script.


Add workspace layout model

I had been working with the assumption that the Linux kernel was in the same tree as the ampack repository. THere were a lot of other assumptions about directory layout, too, getting in the way. At this p[oint, I decided to move all of the directories used for this work to ~/ampack. I have used that pattern for all of the internal projects.


Use a bare kernel repository

Because each of the builds potentially morph the state of the Linux Kernel git repo, I had each of the builds work with its own sandbox, but had each of the sandboxes point to a single naked git repo.

At this point, I had fully committed to the approach. I have not yet removed the python code from the repo, but the Rust code far outstrips it.

I am going to start skipping the explanation for some of the commits, and focus on the most interesting ones.


Add distro build containers

Up to this point, Fedora builds happened on Fedora machines, and we follwed suit for Ubuntu builds. Containerizing the build was a huge benefit, in that we could now build all Kernels on a single machine.


Replace Rust argh integration
argh is a bash script that handles our use of git rerere for dealing with conflicts in a repeatable manner. I merged that functionality into the rust code.


Add Rust architecture diagrams

I wanted to start documenting the code better. A little poking around showed that I could use mermaid, and have codex generate architecture diagrams based on our code. The repo now contains an architecture.md document with component, class, and swimlane diagrams.


Merge branch ‘rust-parallel-build’ into ‘main’

I stopped keeping the rust code in its own branch. The die was cast.


ctag_get.sh generates rust tags

More of the commitment to Rust over Python.

build.sh generates for both Fedora and Ubuntu


Allow full to reuse prepared releases
Allow build to select latest release

These last two commits are the latest: helper flags to make it simpler to deal with partial builds. The generate step only generates the git tree and tags it: it does not product the RPMs etc. With these changes, I can take an old build, or look up the last build_id, and generate the artifacts, potentially posting them to our internal repo.

It is now December 1st. I made my first commit to this process on Nov 18. In the past two-ish weeks we have not only ported the code to a new language, but added a bunch of features that I have wanted for a long time.

Have I reviewed every line of code? Well, I have read them all, but probably not at the depth I would call a code review. I wrote the original python, and I understood the changes that were made to convert it to Rust, so I have been tracking with the general trend of the changes. I feel confident that it is doing what I told it to do, although I have found a few checks to be overly cautious, and that we have had to remove in later iterations. Not a big deal, but a little unnerving that I did not realize that codex had added them on its own.

Since I have not written the Rust code, my Rust coding skills have not really improved all that much. My Rust comprehension has returned to where it was back when I was studying the language. The code is pretty, clean, and simple to understand. I do run each change manually, and confirm that the output either produces what I expect, or use the error reporting to create additional updates.

I tried making a manual change for the last feature, and ended up breaking the build. Codex was able to determine what I had missed, and few fixed the build immediately.

I think this has been a step forward. I have not produced a mess of slop that I could not understand: the code is basically organized as I originally had it. I have made numerous tweaks and cleanups that would have been too expensive to perform in the past, as they would have displaced the business-value-work I needed to get done. The risk is low and the payoff is relatively high.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.