How Linux measure CPU utilization with Hyper-Threading enabled?

There's no explicit definition of CPU utilization. Usually, we see CPU time as CPU utilization. The %id, %us, %sy etc seen in vmstat/iostat are CPU time.
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

So how CPU time is calculated? Is it accurate?

There's a timer interrupt occurs every 10ms, and when the interrupt occurs, system would look at what CPUs are doing at that moment. If in that moment, the system sees a CPU is doing user space instructions, then the system would assume this 10ms the CPU is doing user space job. The same apply to %sy and %id.

With HT enabled, the system would see 2 CPUs per core, so the CPU number is doubled. No matter HT or not, the system accounts CPU time in the same manner. For example, without HT, the system sees one CPU, in 1000ms, the system see 10 samples of idle and 90 samples of us in this CPU, then system would report 10%idle and 90%us. For another example, with HT, the system now sees two CPU, in 1000ms, the system see 20 samples of idle and 80 samples of us in CPU0, 30 samples of idle and 70 samples of us in CPU1, then system would report (20+30)/(100*2)=25%idle, and (80+70)/(100*2)=75%us.


[ CPU time accounting ]

[ CPU time ]

[ CPU load vs CPU utilization ]

[ Hyper-Threading Technology Architecture and Microarchitecture ]

[ intel performance counter monitor ]

[ Monitor CPU utilization under HT ]

[ HT-aware Scheduler ]