Skip to content

Commit 2bae9a4

Browse files
committed
add arm64 support for clock frequency helpers
homa_clock() calls get_cycles(), whose backing source is arch-specific: RDTSC on x86 (frequency tsc_khz) and the generic timer on arm64 (frequency arch_timer_get_cntfrq()). Make homa_clock_khz() return the correct value per arch: - x86: tsc_khz (not cpu_khz -- the kernel tracks them separately and they can diverge) - arm64: arch_timer_get_cntfrq() / 1000 - other: 1000000 (fallback) Guard the tsc_khz-dependent scaling in homa_metrics_print() behind CONFIG_X86 and emit raw cycle counts on other arches where Linux and homa_clock() share the same counter. Replace bare tsc_khz references in timetrace.c with homa_clock_khz() so the emitted cpu_khz header is correct on all architectures. Signed-off-by: Serapheim Dimitropoulos <sdimitropoulos@coreweave.com>
1 parent 8f941bf commit 2bae9a4

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

homa_impl.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#ifndef __UPSTREAM__ /* See strip.py */
4747
#include "homa.h"
4848
#include <linux/version.h>
49+
#ifdef CONFIG_ARM64
50+
#include <clocksource/arm_arch_timer.h>
51+
#endif
4952
#include "homa_devel.h"
5053
#else /* See strip.py */
5154
#include <linux/homa.h>
@@ -842,7 +845,13 @@ static inline u64 homa_clock_khz(void)
842845
return 1000000;
843846
#else /* __UNIT_TEST__ */
844847
#ifndef __UPSTREAM__ /* See strip.py */
845-
return cpu_khz;
848+
#ifdef CONFIG_X86
849+
return tsc_khz;
850+
#elif defined(CONFIG_ARM64)
851+
return arch_timer_get_cntfrq() / 1000;
852+
#else
853+
return 1000000;
854+
#endif
846855
#else /* See strip.py */
847856
return 1000000;
848857
#endif /* See strip.py */

homa_metrics.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,26 @@ char *homa_metrics_print(void)
241241
M("bypass_softirq_cycles", m->bypass_softirq_cycles,
242242
"Time spent in homa_softirq during bypass from GRO\n");
243243

244-
/* Adjust stats gathered in Linux that use rdtsc. */
244+
/* Adjust stats gathered in Linux via get_cycles (RDTSC on
245+
* x86, arch timer on arm64). On x86 both Linux and
246+
* homa_clock() read the TSC, so the ratio is 1; the
247+
* explicit conversion is kept in case the sources ever
248+
* diverge. On non-x86 the counters are identical, so raw
249+
* values are emitted directly.
250+
*/
251+
#ifdef CONFIG_X86
245252
M("linux_softirq_cycles", m->linux_softirq_cycles *
246253
(homa_clock_khz() / 1000) / (tsc_khz / 1000),
247254
"Time spent in all Linux SoftIRQ\n");
248255
M("napi_cycles", m->napi_cycles * (homa_clock_khz() / 1000) /
249256
(tsc_khz / 1000),
250257
"Time spent in NAPI-level packet handling\n");
258+
#else
259+
M("linux_softirq_cycles", m->linux_softirq_cycles,
260+
"Time spent in all Linux SoftIRQ\n");
261+
M("napi_cycles", m->napi_cycles,
262+
"Time spent in NAPI-level packet handling\n");
263+
#endif
251264
M("linux_softirqd_actions", m->linux_softirqd_actions,
252265
"SoftIRQ actions taken in the background softirqd thread\n");
253266
M("send_cycles", m->send_cycles,

timetrace.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ int tt_proc_open(struct inode *inode, struct file *file)
390390

391391
if (!tt_test_no_khz) {
392392
pf->bytes_available = snprintf(pf->msg_storage, TT_PF_BUF_SIZE,
393-
"cpu_khz: %u\n", tsc_khz);
393+
"cpu_khz: %llu\n",
394+
homa_clock_khz());
394395
}
395396

396397
done:
@@ -631,7 +632,7 @@ void tt_print_file(char *path)
631632

632633
bytes_used += snprintf(buffer + bytes_used,
633634
sizeof(buffer) - bytes_used,
634-
"cpu_khz: %u\n", tsc_khz);
635+
"cpu_khz: %llu\n", homa_clock_khz());
635636

636637
/* Each iteration of this loop printk's one event. */
637638
while (true) {
@@ -758,7 +759,7 @@ void tt_printk(void)
758759
}
759760
#endif
760761

761-
pr_err("cpu_khz: %u, start: %llu\n", tsc_khz, start_time);
762+
pr_err("cpu_khz: %llu, start: %llu\n", homa_clock_khz(), start_time);
762763

763764
/* Each iteration of this loop printk's one event. */
764765
while (true) {

0 commit comments

Comments
 (0)