From 1ba7444e7b6f3840f46e04fd52db4ef820f56c41 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Thu, 24 Oct 2024 17:56:25 +0100 Subject: [PATCH] Rename 'scheduled_at' -> '[en/de]queued_at' --- base/task.jl | 36 ++++++++++++++++++------------------ base/timing.jl | 2 +- src/jltypes.c | 4 ++-- src/julia.h | 10 +++++----- src/task.c | 16 ++++++++-------- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/base/task.jl b/base/task.jl index 73bcf7a4374ee3..f5abec70cb9d0f 100644 --- a/base/task.jl +++ b/base/task.jl @@ -984,9 +984,9 @@ function enq_work(t::Task) end function schedule(t::Task) - # user_time -task-scheduled-> wait_time - if t.first_scheduled_at == 0 - t.first_scheduled_at = time_ns() + # user_time -task-(re)scheduled-> wait_time + if t.first_enqueued_at == 0 + t.first_enqueued_at = time_ns() end enq_work(t) end @@ -1035,9 +1035,9 @@ true function schedule(t::Task, @nospecialize(arg); error=false) # schedule a task to be (re)started with the given value or exception t._state === task_state_runnable || Base.error("schedule: Task not runnable") - # user_time -task-scheduled-> wait_time - if t.first_scheduled_at == 0 - t.first_scheduled_at = time_ns() + # user_time -task-(re)scheduled-> wait_time + if t.first_enqueued_at == 0 + t.first_enqueued_at = time_ns() end if error q = t.queue; q === nothing || Base.list_deletefirst!(q::IntrusiveLinkedList{Task}, t) @@ -1107,8 +1107,8 @@ function yieldto(t::Task, @nospecialize(x=nothing)) elseif t._state === task_state_failed throw(t.result) end - if t.first_scheduled_at == 0 - t.first_scheduled_at = time_ns() + if t.first_enqueued_at == 0 + t.first_enqueued_at = time_ns() end t.result = x set_next_task(t) @@ -1125,8 +1125,8 @@ function try_yieldto(undo) ct = current_task() # scheduler -task-started-> user # scheduler -task-resumed-> user - # @assert ct.last_scheduled_at == 0 - ct.last_scheduled_at = time_ns() + # @assert ct.last_dequeued_at == 0 + ct.last_dequeued_at = time_ns() if ct._isexception exc = ct.result ct.result = nothing @@ -1140,8 +1140,8 @@ end # yield to a task, throwing an exception in it function throwto(t::Task, @nospecialize exc) - if t.first_scheduled_at == 0 - t.first_scheduled_at = time_ns() + if t.first_enqueued_at == 0 + t.first_enqueued_at = time_ns() end t.result = exc t._isexception = true @@ -1210,15 +1210,15 @@ else pause() = ccall(:pause, Cvoid, ()) end -function record_cpu_time!(t::Task, done_at::UInt64=time_ns()) - @assert t.last_scheduled_at != 0 - t.cpu_time_ns += done_at - t.last_scheduled_at - t.last_scheduled_at = 0 +function record_cpu_time!(t::Task, stopped_at::UInt64=time_ns()) + @assert t.last_dequeued_at != 0 + t.cpu_time_ns += stopped_at - t.last_dequeued_at + t.last_dequeued_at = 0 return t end function record_wall_time!(t::Task, done_at::UInt64=time_ns()) - @assert t.first_scheduled_at != 0 - t.wall_time_ns = done_at - t.first_scheduled_at + @assert t.first_enqueued_at != 0 + t.wall_time_ns = done_at - t.first_enqueued_at return t end diff --git a/base/timing.jl b/base/timing.jl index 8e145a1523b366..d8679a12ffe6da 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -114,8 +114,8 @@ See also [`task_cpu_time_ns`](@ref). This method was added in Julia 1.12. """ function task_wall_time_ns(t::Task) + # return istaskdone(t) ? t.wall_time_ns : time_ns() - t.first_enqueued_at return t.wall_time_ns - # return istaskdone(t) ? t.wall_time_ns : time_ns() - t.first_scheduled_at end """ diff --git a/src/jltypes.c b/src/jltypes.c index 4a2b14e430c61e..a77b0add5672dd 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -3761,8 +3761,8 @@ void jl_init_types(void) JL_GC_DISABLED "sticky", "_isexception", "priority", - "first_scheduled_at", - "last_scheduled_at", + "first_enqueued_at", + "last_dequeued_at", "cpu_time_ns", "wall_time_ns"), jl_svec(20, diff --git a/src/julia.h b/src/julia.h index a8e6ea667ab1c8..175ca4517e8217 100644 --- a/src/julia.h +++ b/src/julia.h @@ -2274,13 +2274,13 @@ typedef struct _jl_task_t { // uint8_t padding1; // multiqueue priority uint16_t priority; - // timestamp this task became runnable (TODO: int32 of ms instead?) - uint64_t first_scheduled_at; // TODO: naming... first_enqueued_at? - // timestamp this task was last scheduled - uint64_t last_scheduled_at; // TODO: naming... last_dequeued_at? + // timestamp this task first entered the run queue (TODO: int32 of ms instead?) + uint64_t first_enqueued_at; + // timestamp this task was most recently scheduled to run + uint64_t last_dequeued_at; // time this task has spent running; updated when it yields uint64_t cpu_time_ns; - // time since this task was runnable + // time between first entering the run queue and being done/failed. uint64_t wall_time_ns; // hidden state: diff --git a/src/task.c b/src/task.c index 6fcea049318353..e0554627f56021 100644 --- a/src/task.c +++ b/src/task.c @@ -1146,8 +1146,8 @@ JL_DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, jl_value_t *completion t->ptls = NULL; t->world_age = ct->world_age; t->reentrant_timing = 0; - t->first_scheduled_at = 0; - t->last_scheduled_at = 0; + t->first_enqueued_at = 0; + t->last_dequeued_at = 0; t->cpu_time_ns = 0; t->wall_time_ns = 0; jl_timing_task_init(t); @@ -1248,10 +1248,10 @@ CFI_NORETURN #endif ct->ctx.started = 1; - /* // wait_time -task-started-> user_time */ - assert(ct->first_scheduled_at != 0); - assert(ct->last_scheduled_at == 0); - ct->last_scheduled_at = jl_hrtime(); + // wait_time -task-started-> user_time + assert(ct->first_enqueued_at != 0); + assert(ct->last_dequeued_at == 0); + ct->last_dequeued_at = jl_hrtime(); JL_PROBE_RT_START_TASK(ct); jl_timing_block_task_enter(ct, ptls, NULL); if (jl_atomic_load_relaxed(&ct->_isexception)) { @@ -1598,8 +1598,8 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi) ct->cpu_time_ns = 0; ct->wall_time_ns = 0; uint64_t now = jl_hrtime(); - ct->first_scheduled_at = now; - ct->last_scheduled_at = now; + ct->first_enqueued_at = now; + ct->last_dequeued_at = now; ptls->root_task = ct; jl_atomic_store_relaxed(&ptls->current_task, ct); JL_GC_PROMISE_ROOTED(ct);