Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sound of Scheduling: Writing Linux Schedulers i...

Sound of Scheduling: Writing Linux Schedulers in Java with eBPF

eBPF is transforming Linux system capabilities, enabling the extension of the kernel with custom process schedulers, firewalls, and more. Thanks to Java's recent native integration and a bit of compiler magic, we can now create these extensions directly in Java — and that's exactly what this talk is all about.

We'll cover the fundamentals of eBPF and scheduling and how to implement a custom scheduler in Java. The session will showcase a scheduler that visualizes scheduling through sound — each process is mapped to a musical note, offering a fun and intuitive way to understand system activity. You’ll even get the chance to control the scheduling yourself using a MIDI keyboard.

Join us to learn how to craft small eBPF programs in Java that you'll really like the sound of.

Johannes Bechberger

February 05, 2025
Tweet

More Decks by Johannes Bechberger

Other Decks in Programming

Transcript

  1. The only way of disco- vering the limits of the

    possible is to venture a little way past them into the impossible. Clarke’s second law https://www.flickr.com/photos/itupictures/16636142906 “
  2. eBPF is a crazy technology, it’s like putting JavaScript into

    the Linux kernel Brendan Gregg “ https://www.youtube.com/watch?v=tDacjrSCeq4
  3. eBPF is a crazy technology, it’s like putting JavaScript into

    the Linux kernel Brendan Gregg “ https://www.facesofopensource.com/brendan-gregg/
  4. Task A CPU 1 Local Queue CPU 2 Local Queue

    Global Queue Scheduler ... ...
  5. @BPF(license = "GPL") public abstract class SampleScheduler extends BPFProgram implements

    Scheduler, Runnable { static final long SHARED_DSQ_ID = 0; @Type static class Stats { long global; long local; } @Override public int init() { return scx_bpf_create_dsq(SHARED_DSQ_ID, -1); } }
  6. @BPF(license = "GPL") public abstract class SampleScheduler { @BPFMapDefinition(maxEntries =

    100) BPFHashMap<Integer, Stats> statsPerCPU; @BPFMapDefinition(maxEntries = 100000) BPFLRUHashMap<@Unsigned Integer, @Unsigned Long> enqueuesPerProcess; }
  7. @BPF(license = "GPL") public abstract class SampleScheduler { @Override public

    int selectCPU(Ptr<task_struct> p, int prev_cpu, long wake_flags) { boolean is_idle = false; int cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, Ptr.of(is_idle)); if (is_idle) { !/* !!... / } return cpu; } } *
  8. @BPF(license = "GPL") public abstract class SampleScheduler { @Override public

    void enqueue(Ptr<task_struct> p, long enq_flags) { incrementStats(false); recordEnqueue(p); scx_bpf_dispatch(p, SHARED_DSQ_ID, SCX_SLICE_DFL.value(), enq_flags); } }
  9. @BPF(license = "GPL") public abstract class SampleScheduler { @Override public

    void dispatch(int cpu, Ptr<task_struct> prev) { scx_bpf_consume(SHARED_DSQ_ID); } }
  10. Task 1 CPU 1 CPU 2 Scheduling Queue treated as

    a lottery bowl ... ... Draw randomly from queue Ask for new task Return finished task Enqueue task for the first time Task 2 2 1 3 4 7 6 1