Skip to content

Commit 7df1bfe

Browse files
committed
8354811: clock_tics_per_sec code duplication between os_linux and os_posix
Reviewed-by: lucy, clanger, asteiner
1 parent 40e7986 commit 7df1bfe

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/hotspot/os/aix/os_perf_aix.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ static OSReturn get_lcpu_ticks(perfstat_id_t* lcpu_name, cpu_tick_store_t* ptick
118118
* Return CPU load caused by the currently executing process (the jvm).
119119
*/
120120
static OSReturn get_jvm_load(double* jvm_uload, double* jvm_sload) {
121-
static clock_t ticks_per_sec = sysconf(_SC_CLK_TCK);
122121
static u_longlong_t last_timebase = 0;
123122

124123
perfstat_process_t jvm_stats;
@@ -204,8 +203,6 @@ static bool populate_lcpu_names(int ncpus, perfstat_id_t* lcpu_names) {
204203
* (Context Switches / Tick) * (Tick / s) = Context Switches per second
205204
*/
206205
static OSReturn perf_context_switch_rate(double* rate) {
207-
static clock_t ticks_per_sec = sysconf(_SC_CLK_TCK);
208-
209206
u_longlong_t ticks;
210207
perfstat_cpu_total_t cpu_stats;
211208

@@ -214,7 +211,7 @@ static OSReturn perf_context_switch_rate(double* rate) {
214211
}
215212

216213
ticks = cpu_stats.user + cpu_stats.sys + cpu_stats.idle + cpu_stats.wait;
217-
*rate = (cpu_stats.pswitch / ticks) * ticks_per_sec;
214+
*rate = (cpu_stats.pswitch / ticks) * os::Posix::clock_tics_per_second();
218215

219216
return OS_OK;
220217
}

src/hotspot/os/linux/os_linux.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ typedef int (*malloc_info_func_t)(int options, FILE *stream);
210210
static malloc_info_func_t g_malloc_info = nullptr;
211211
#endif // __GLIBC__
212212

213-
static int clock_tics_per_sec = 100;
214-
215213
// If the VM might have been created on the primordial thread, we need to resolve the
216214
// primordial thread stack bounds and check if the current thread might be the
217215
// primordial thread in places. If we know that the primordial thread is never used,
@@ -4378,8 +4376,6 @@ static void check_pax(void) {
43784376
// this is called _before_ most of the global arguments have been parsed
43794377
void os::init(void) {
43804378
char dummy; // used to get a guess on initial stack address
4381-
4382-
clock_tics_per_sec = checked_cast<int>(sysconf(_SC_CLK_TCK));
43834379
int sys_pg_size = checked_cast<int>(sysconf(_SC_PAGESIZE));
43844380
if (sys_pg_size < 0) {
43854381
fatal("os_linux.cpp: os::init: sysconf failed (%s)",
@@ -5132,9 +5128,9 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
51325128
&user_time, &sys_time);
51335129
if (count != 13) return -1;
51345130
if (user_sys_cpu_time) {
5135-
return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
5131+
return ((jlong)sys_time + (jlong)user_time) * (1000000000 / os::Posix::clock_tics_per_second());
51365132
} else {
5137-
return (jlong)user_time * (1000000000 / clock_tics_per_sec);
5133+
return (jlong)user_time * (1000000000 / os::Posix::clock_tics_per_second());
51385134
}
51395135
}
51405136

src/hotspot/os/posix/os_posix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,10 @@ void os::Posix::init_2(void) {
13261326
_use_clock_monotonic_condattr ? "CLOCK_MONOTONIC" : "the default clock");
13271327
}
13281328

1329+
int os::Posix::clock_tics_per_second() {
1330+
return clock_tics_per_sec;
1331+
}
1332+
13291333
// Utility to convert the given timeout to an absolute timespec
13301334
// (based on the appropriate clock) to use with pthread_cond_timewait,
13311335
// and sem_timedwait().

src/hotspot/os/posix/os_posix.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -91,6 +91,9 @@ class os::Posix {
9191

9292
static void to_RTC_abstime(timespec* abstime, int64_t millis);
9393

94+
// clock ticks per second of the system
95+
static int clock_tics_per_second();
96+
9497
static bool handle_stack_overflow(JavaThread* thread, address addr, address pc,
9598
const void* ucVoid,
9699
address* stub);

0 commit comments

Comments
 (0)