Comment

Comment by tptacek

No, ChatGPT is way cooler than that. It's already read every line of kernel code ever written. I start with a subsystem: the device mapper is a good recent example. I ask things like "explain the linux device mapper. if it was a class in an object-oriented language, what would its interface look like?" and "give me dm_target as a python class". I get stuff like:

    def linear_ctr(target, argc, argv):
        print("Constructor called with args:", argc, argv)
        # Initialize target-specific data here
        return 0
     
    def linear_dtr(target):
        print("Destructor called")
        # Clean up target-specific data here
     
    def linear_map(target, bio):
        print("Mapping I/O request")
        # Perform mapping here
        return 0
     
    linear_target = DmTarget(name="linear", version=(1, 0, 0), module="dm_mod")
    linear_target.set_ctr(linear_ctr)
    linear_target.set_dtr(linear_dtr)
    linear_target.set_map(linear_map)
     
    info = linear_target.get_info()
    print(info)
(A bunch of stuff elided). I don't care at all about the correctness of this code, because I'm just using it as a roadmap for the real Linux kernel code. The example use case code is an example of something GPT 4o provides that I didn't even know I wanted.
parent tptacek 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton