Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ebpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ const volatile u64 slice_lag = 40ULL * NSEC_PER_MSEC;
*/
static u64 vtime_now;

const volatile bool max_time_watchdog = true;

#define THRESHOLD 500000000 /* 500ms */

/*
* Allocate/re-allocate a new cpumask.
*/
Expand Down Expand Up @@ -1961,13 +1965,28 @@ void BPF_STRUCT_OPS(goland_update_idle, s32 cpu, bool idle)
}
}

void BPF_STRUCT_OPS(goland_tick, struct task_struct *p)
{
if (max_time_watchdog && (kernel_mode || !is_usersched_task(p))) {
struct task_ctx *tctx = try_lookup_task_ctx(p);
if (!tctx)
return;
u64 now = scx_bpf_now();
u64 run_time = now - tctx->start_ts;
if (unlikely(run_time > THRESHOLD)) {
scx_bpf_kick_cpu(bpf_get_smp_processor_id(), SCX_KICK_PREEMPT);
bpf_printk("pid: %d exceed the threshold", p->pid);
}
}
}
/*
* Scheduling class declaration.
*/
SCX_OPS_DEFINE(goland,
.select_cpu = (void *)goland_select_cpu,
.enqueue = (void *)goland_enqueue,
.dispatch = (void *)goland_dispatch,
.tick = (void *)goland_tick,
.update_idle = (void *)goland_update_idle,
.runnable = (void *)goland_runnable,
.running = (void *)goland_running,
Expand Down
4 changes: 4 additions & 0 deletions goland_core/rodata.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func (s *Sched) EnableKernelMode() {
C.enable_kernel_mode()
}

func (s *Sched) DisableMaxTimeWatchdog() {
C.disable_max_time_watchdog()
}

func (s *Sched) SetEarlyProcessing(enabled bool) {
C.set_early_processing(C.bool(enabled))
}
Expand Down
4 changes: 4 additions & 0 deletions wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void enable_kernel_mode() {
global_obj->rodata->kernel_mode = true;
}

void disable_max_time_watchdog() {
global_obj->rodata->max_time_watchdog = false;
}

u64 get_nr_scheduled() {
return global_obj->bss->nr_scheduled;
}
Expand Down
2 changes: 2 additions & 0 deletions wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void set_builtin_idle(bool enabled);

void enable_kernel_mode();

void disable_max_time_watchdog();

void set_early_processing(bool enabled);

void set_default_slice(u64 t);
Expand Down
Loading