Skip to content

Commit af1bf51

Browse files
committed
Revert "Convert task timestamps to UInt32 delta-times since system boot."
This reverts commit d23a96f.
1 parent a403d50 commit af1bf51

File tree

7 files changed

+19
-56
lines changed

7 files changed

+19
-56
lines changed

base/Base_compiler.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,6 @@ between two moments in time.
163163
"""
164164
time_ns() = ccall(:jl_hrtime, UInt64, ())
165165

166-
"""
167-
delta_time_ns() -> UInt32
168-
169-
Get the amount of nanoseconds since system boot.
170-
To convert to a time matching `time_ns()`, call `delta_ns_to_time_ns(dt)`.
171-
"""
172-
delta_time_ns() = ccall(:jl_delta_time_now, UInt32, ())
173-
174-
"""
175-
delta_ns_to_time_ns(dt::UInt32) -> UInt64
176-
177-
Convert the return value of `delta_time_ns()` to a time matching `time_ns()`.
178-
"""
179-
delta_ns_to_time_ns(dt) = ccall(:jl_hrtime_from_delta, UInt64, (UInt32,), dt)
180-
181166
# A warning to be interpolated in the docstring of every dangerous mutating function in Base, see PR #50824
182167
const _DOCS_ALIASING_WARNING = """
183168
!!! warning

base/experimental.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ function task_metrics(b::Bool)
517517
end
518518

519519
"""
520-
Base.Experimental.task_cpu_time_ns(t::Task) -> Union{UInt32, Nothing}
520+
Base.Experimental.task_cpu_time_ns(t::Task) -> Union{UInt64, Nothing}
521521
522522
Return the total nanoseconds that the task `t` has spent running.
523523
This metric is only updated when `t` yields or completes unless `t` is the current task, in
@@ -539,14 +539,14 @@ function task_cpu_time_ns(t::Task=current_task())
539539
if t == current_task()
540540
# These metrics fields can't update while we're running.
541541
# But since we're running we need to include the time since we last started running!
542-
return t.cpu_time_ns + (delta_time_ns() - t.last_started_running_at)
542+
return t.cpu_time_ns + (time_ns() - t.last_started_running_at)
543543
else
544544
return t.cpu_time_ns
545545
end
546546
end
547547

548548
"""
549-
Base.Experimental.task_wall_time_ns(t::Task) -> Union{UInt32, Nothing}
549+
Base.Experimental.task_wall_time_ns(t::Task) -> Union{UInt64, Nothing}
550550
551551
Return the total nanoseconds that the task `t` was runnable.
552552
This is the time since the task first entered the run queue until the time at which it
@@ -562,9 +562,9 @@ See [`Base.Experimental.task_metrics`](@ref).
562562
function task_wall_time_ns(t::Task=current_task())
563563
t.metrics_enabled || return nothing
564564
start_at = t.first_enqueued_at
565-
start_at == 0 && return UInt32(0)
565+
start_at == 0 && return UInt64(0)
566566
end_at = t.finished_at
567-
end_at == 0 && return delta_time_ns() - start_at
567+
end_at == 0 && return time_ns() - start_at
568568
return end_at - start_at
569569
end
570570

base/task.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ function try_yieldto(undo)
11181118
ct = current_task()
11191119
# [task] wait_time -(re)started-> user_time
11201120
if ct.metrics_enabled
1121-
@atomic :monotonic ct.last_started_running_at = delta_time_ns()
1121+
@atomic :monotonic ct.last_started_running_at = time_ns()
11221122
end
11231123
if ct._isexception
11241124
exc = ct.result
@@ -1209,7 +1209,7 @@ end
12091209
# update the `cpu_time_ns` field of `t` to include the time since it last started running.
12101210
function record_cpu_time!(t::Task)
12111211
if t.metrics_enabled && !istaskdone(t)
1212-
@atomic :monotonic t.cpu_time_ns += delta_time_ns() - t.last_started_running_at
1212+
@atomic :monotonic t.cpu_time_ns += time_ns() - t.last_started_running_at
12131213
end
12141214
return t
12151215
end
@@ -1219,7 +1219,7 @@ end
12191219
# then set the `first_enqueued_at` field to the current time.
12201220
function maybe_record_enqueued!(t::Task)
12211221
if t.metrics_enabled && t.first_enqueued_at == 0
1222-
@atomic :monotonic t.first_enqueued_at = delta_time_ns()
1222+
@atomic :monotonic t.first_enqueued_at = time_ns()
12231223
end
12241224
return t
12251225
end

src/init.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,8 @@ extern BOOL (WINAPI *hSymRefreshModuleList)(HANDLE);
4646
jl_array_t *jl_module_init_order;
4747
arraylist_t *jl_entrypoint_mis;
4848

49-
JL_DLLEXPORT uint64_t jl_system_boot_time = 0;
5049
JL_DLLEXPORT size_t jl_page_size;
5150

52-
JL_DLLEXPORT delta_timestamp jl_delta_time_now(void) {
53-
return jl_delta_timestamp(jl_hrtime() - jl_system_boot_time);
54-
}
55-
JL_DLLEXPORT delta_timestamp jl_delta_timestamp(uint64_t t) {
56-
return (t - jl_system_boot_time);
57-
}
58-
JL_DLLEXPORT uint64_t jl_hrtime_from_delta(delta_timestamp t) {
59-
return t + jl_system_boot_time;
60-
}
61-
6251
void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
6352
{
6453
#ifdef _OS_WINDOWS_
@@ -746,8 +735,6 @@ static void init_global_mutexes(void) {
746735

747736
JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
748737
{
749-
jl_system_boot_time = jl_hrtime();
750-
751738
// initialize many things, in no particular order
752739
// but generally running from simple platform things to optional
753740
// configuration features

src/jltypes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,10 +3786,10 @@ void jl_init_types(void) JL_GC_DISABLED
37863786
jl_bool_type,
37873787
jl_uint16_type,
37883788
jl_bool_type,
3789-
jl_uint32_type,
3790-
jl_uint32_type,
3791-
jl_uint32_type,
3792-
jl_uint32_type),
3789+
jl_uint64_type,
3790+
jl_uint64_type,
3791+
jl_uint64_type,
3792+
jl_uint64_type),
37933793
jl_emptysvec,
37943794
0, 1, 6);
37953795
XX(task);

src/julia.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,15 +2274,6 @@ typedef struct _jl_handler_t {
22742274

22752275
#define JL_RNG_SIZE 5 // xoshiro 4 + splitmix 1
22762276

2277-
// delta_timestamp values are nanoseconds since the boot-time of the julia runtime system.
2278-
// To convert to a real time, use jl_dt2hrtime(dt) and jl_hrtime2ns(hrt).
2279-
typedef uint32_t delta_timestamp;
2280-
2281-
extern JL_DLLEXPORT uint64_t jl_system_boot_time;
2282-
JL_DLLEXPORT delta_timestamp jl_delta_time_now(void);
2283-
JL_DLLEXPORT delta_timestamp jl_delta_timestamp(uint64_t t);
2284-
JL_DLLEXPORT uint64_t jl_hrtime_from_delta(delta_timestamp t);
2285-
22862277
typedef struct _jl_task_t {
22872278
JL_DATA_TYPE
22882279
jl_value_t *next; // invasive linked list for scheduler
@@ -2305,13 +2296,13 @@ typedef struct _jl_task_t {
23052296
// flag indicating whether or not to record timing metrics for this task
23062297
uint8_t metrics_enabled;
23072298
// timestamp this task first entered the run queue
2308-
_Atomic(uint32_t) first_enqueued_at;
2299+
_Atomic(uint64_t) first_enqueued_at;
23092300
// timestamp this task was most recently scheduled to run
2310-
_Atomic(uint32_t) last_started_running_at;
2301+
_Atomic(uint64_t) last_started_running_at;
23112302
// time this task has spent running; updated when it yields or finishes.
2312-
_Atomic(uint32_t) cpu_time_ns;
2303+
_Atomic(uint64_t) cpu_time_ns;
23132304
// timestamp this task finished (i.e. entered state DONE or FAILED).
2314-
_Atomic(uint32_t) finished_at;
2305+
_Atomic(uint64_t) finished_at;
23152306

23162307
// hidden state:
23172308
// cached floating point environment

src/task.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void JL_NORETURN jl_finish_task(jl_task_t *ct)
316316
if (ct->metrics_enabled) {
317317
// [task] user_time -finished-> wait_time
318318
assert(jl_atomic_load_relaxed(&ct->first_enqueued_at) != 0);
319-
delta_timestamp now = jl_delta_time_now();
319+
uint64_t now = jl_hrtime();
320320
jl_atomic_store_relaxed(&ct->finished_at, now);
321321
jl_atomic_fetch_add_relaxed(&ct->cpu_time_ns, now - jl_atomic_load_relaxed(&ct->last_started_running_at));
322322
}
@@ -1261,7 +1261,7 @@ CFI_NORETURN
12611261
// [task] wait_time -started-> user_time
12621262
assert(jl_atomic_load_relaxed(&ct->first_enqueued_at) != 0);
12631263
assert(jl_atomic_load_relaxed(&ct->last_started_running_at) == 0);
1264-
jl_atomic_store_relaxed(&ct->last_started_running_at, jl_delta_time_now());
1264+
jl_atomic_store_relaxed(&ct->last_started_running_at, jl_hrtime());
12651265
}
12661266
JL_PROBE_RT_START_TASK(ct);
12671267
jl_timing_block_task_enter(ct, ptls, NULL);
@@ -1619,7 +1619,7 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
16191619
ct->metrics_enabled = jl_atomic_load_relaxed(&jl_task_metrics_enabled) != 0;
16201620
if (ct->metrics_enabled) {
16211621
// [task] created -started-> user_time
1622-
delta_timestamp now = jl_delta_time_now();
1622+
uint64_t now = jl_hrtime();
16231623
jl_atomic_store_relaxed(&ct->first_enqueued_at, now);
16241624
jl_atomic_store_relaxed(&ct->last_started_running_at, now);
16251625
}

0 commit comments

Comments
 (0)