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

Writing a Linux scheduler in Java with eBPF

Writing a Linux scheduler in Java with eBPF

Keynote at eBPF Summit 2024.

Johannes Bechberger

September 10, 2024
Tweet

More Decks by Johannes Bechberger

Other Decks in Programming

Transcript

  1. @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); } }
  2. @BPF(license = "GPL") public abstract class SampleScheduler { @BPFMapDefinition(maxEntries =

    100) BPFHashMap<Integer, Stats> statsPerCPU; @BPFMapDefinition(maxEntries = 100000) BPFLRUHashMap<@Unsigned Integer, @Unsigned Long> enqueuesPerProcess; }
  3. @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; } } *
  4. @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); } }
  5. @BPF(license = "GPL") public abstract class SampleScheduler { @Override public

    void dispatch(int cpu, Ptr<task_struct> prev) { scx_bpf_consume(SHARED_DSQ_ID); } }
  6. When will sched-ext be merged? I will knock wood, because

    I was sure it was going to be in 6.11, but yes it looks like we're now looking at 6.12. https://www.youtube.com/watch?v=nJMEuBwMD18 https://www.facesofopensource.com/linus-torvalds/ “