I wrote a kernel module to print IDTR value to see if each CPU (hyper-threads) running on each core have their own separate IDT or share the same one for a particular Core. But, I am getting same base and limit value for IDTR on each CPU, which makes it seem like that there is a global IDT that is shared by all the CPUs.
To run on different CPUs, I wrote a script that inserts my module using a particular CPU using 'taskset'.
This is my module:
#include <linux/init.h>
#include <linux/module.h>
struct idt {
u16 length;
u64 base;
} __attribute__((packed)) idt;
void my_store_idt(struct idt *idt)
{
asm volatile ("sidt %0" : "=m"(*idt));
}
static int __init mod_init(void) {
my_store_idt(&idt);
printk("cpu = %d, idtr.length = %u, idtr.base = %llu\n"
,get_cpu(), idt.length, idt.base);
return 0;
}
static void __exit mod_exit(void)
{
printk("byeee\n");
}
module_init(mod_init);
module_exit(mod_exit);
MODULE_LICENSE("GPL");
And this is the output I get:
[Sep15 00:52] cpu = 0, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001625] byeee
[ +0.016648] cpu = 1, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001234] byeee
[ +0.012360] cpu = 2, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001140] byeee
[ +0.007094] cpu = 3, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001182] byeee
[ +0.010665] cpu = 4, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001136] byeee
[ +0.007931] cpu = 5, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001141] byeee
[ +0.012969] cpu = 6, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001189] byeee
[ +0.019079] cpu = 7, idtr.length = 4095, idtr.base = 18446741874686296064
[ +0.001226] byeee
This is the scrpt I used to run it on different CPUs:
#!/bin/bash for i in {0..7} do taskset -c $i insmod read_idtr.ko rmmod read_idtr done
I have read that each processor has its own IDT. So, either it should show different IDTR value for each CPU or for atleast each Core. Why I am getting the same for each CPU?