Skip to content

Commit

Permalink
Rename 'scheduled_at' -> '[en/de]queued_at'
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrobinson251 committed Oct 24, 2024
1 parent 17c34a1 commit 1ba7444
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
36 changes: 18 additions & 18 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
4 changes: 2 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1ba7444

Please sign in to comment.