Skip to content

salad: complete rewrite to be thread-based rather than select-based

Martin Roukala requested to merge mupuf/ci-tron:salad_rewrite into main

The first version of SALAD was using a single thread to do all the routing between the different consoles and clients. This was done through heavy use of select() which led to the following issues:

  • high CPU load due to the high setup cost of select, both on salad's side by computing the list of fds to wait on and on the kernel side which needs to monitor all these fds.

  • hard to maintain: by having to deal with fds, we are at risk of fd leaks, and race conditions.

This commit brings a complete rewrite of SALAD to be thread-based, where every console, server, and client have their own thread. The SALAD class is now mostly used as a database for the routing and polling for the list of serial consoles.

Other notable changes are:

  • Consoles:

    • Improve performance by:
      • Using bytes.split() to split the consoles' lines
      • Using re.search for both ping/machine_id
    • Use os.read/write directly
    • Use serial.VTIMESerial rather than serial.Serial so that read() could be blocking... for up to 200ms
  • TCPServer: Deduplicate the 3 instances of TCP servers we had

Merge request reports