Skip to content

Commit d7afcd1

Browse files
committed
add arm64 support for clock frequency helpers
On arm64, `cpu_khz` and `tsc_khz` do not exist -- they are x86-only globals tied to the TSC. Replace them with arch-appropriate alternatives: - homa_clock_khz(): use `arch_timer_get_cntfrq() / 1000` on arm64, which returns the ARM generic timer frequency matching get_cycles(). - timetrace.c: replace tsc_khz with homa_clock_khz() in the three places that print "cpu_khz:" for trace output. - homa_metrics.c: guard the tsc_khz-based cycle conversion with CONFIG_X86; on arm64 both homa_clock() and Linux timekeeping use the same arch timer so no conversion is needed. Without this patch, building HomaModule on arm64 fails with: error: 'cpu_khz' undeclared (first use in this function) Signed-off-by: Serapheim Dimitropoulos <sdimitropoulos@coreweave.com>
1 parent 8f941bf commit d7afcd1

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

homa_impl.h

Lines changed: 9 additions & 0 deletions
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 */
848+
#ifdef CONFIG_X86
845849
return cpu_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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,24 @@ 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 that use rdtsc.
245+
* On x86 the Linux timekeeping clock (tsc) may differ from
246+
* homa_clock(); on arm64 both use the arch timer so the
247+
* ratio is 1.
248+
*/
249+
#ifdef CONFIG_X86
245250
M("linux_softirq_cycles", m->linux_softirq_cycles *
246251
(homa_clock_khz() / 1000) / (tsc_khz / 1000),
247252
"Time spent in all Linux SoftIRQ\n");
248253
M("napi_cycles", m->napi_cycles * (homa_clock_khz() / 1000) /
249254
(tsc_khz / 1000),
250255
"Time spent in NAPI-level packet handling\n");
256+
#else
257+
M("linux_softirq_cycles", m->linux_softirq_cycles,
258+
"Time spent in all Linux SoftIRQ\n");
259+
M("napi_cycles", m->napi_cycles,
260+
"Time spent in NAPI-level packet handling\n");
261+
#endif
251262
M("linux_softirqd_actions", m->linux_softirqd_actions,
252263
"SoftIRQ actions taken in the background softirqd thread\n");
253264
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)