2
votes

I am writing a Linux kernel module to read dump local APIC timer registers.
I am using Ubuntu 16.04 desktop on X86_64 platform.
X2APIC is disabled, and nohz=off in grub.cfg.

I am using following codes to read APIC timer registers.

#include <linux/slab.h>
#include <linux/time.h>
#include <asm/string.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/hrtimer.h>
#include <linux/ktime.h>
#include <asm/apic.h>

void read_apic_timer(void)
{
    printk("APIC_TDCR = 0x%x\n", apic_read(APIC_TDCR));
    printk("APIC_TMICT = 0x%x\n", apic_read(APIC_TMICT));
    printk("APIC_TMCCT = 0x%x\n", apic_read(APIC_TMCCT));
}

static int __init timer_init(void)
{
    read_apic_timer();
    return 0;
}

static void __exit timer_exit(void)
{
    printk("module uninstalling\n");
}

module_init(timer_init);
module_exit(timer_exit);
MODULE_LICENSE("GPL");

And I got these,

[ 5619.047497] APIC_TDCR = 0x0
[ 5619.047498] APIC_TMICT = 0x0
[ 5619.047499] APIC_TMCCT = 0x0

To my surprise, initial counter and current counter are all 0, is it correct?

Or did I miss something or make something wrong?

1
Just to be sure, is your kernel configured with CONFIG_X86_LOCAL_APIC? - Margaret Bloom
Sure, it is enabled, and kernel log shows, [ 0.000000] ACPI: Local APIC address 0xfee00000 - wangt13
I was asking because if that config is not enabled apic_read returns 0 unconditionally. Anyway, 0 is a valid value for all those register: 0 in TDCR means divide by 2 and 0 in the TMICT means "disable the timer". The TMCCT counts down from the TMICT to 0. If the timer is programmed in one-shot mode, once TMCCT is 0, it stays 0, - Margaret Bloom
I got your points. Then, I added a printk in local_apic_timer_interrupt(), to check if lapic timer is working in one-shot mode or periodic mode. And I found it is in periodic mode (nohz=off), like this " local_apic_timer_interrupt, 880, TMRINIT_CNT = 0, TMR_CUR_CNT = 0, TMR_DIV = 0". But the registers reading is all '0s'. I don't think it is correct. My intent is to figure out what/how hrtimer in Linux is supported, is it from HPET or CMOS/RTC, or lapic timer. If you can clarify, it is very great. - wangt13

1 Answers

2
votes

I think I get the answer. It is because the CPU supports TSC deadline feature/mode for LAPIC timer. In this mode, APIC_TDCR/TMICT/TMCCT are not being used. That is it.