Lunatik

cpuModule

Lua interface to Linux CPU abstractions.

A possible CPU is one the system can ever bring up, a present one is plugged in, and an online one runs tasks. maxid() is the highest possible CPU id, one less than num_possible when those ids have no gaps.

Functions

maxid () Returns the highest possible CPU id, the kernel’s nr_cpu_ids - 1.
num_online () Returns the number of online CPUs.
num_possible () Returns the number of possible CPUs.
num_present () Returns the number of present CPUs.
online () Iterates over the online CPUs, in ascending order.
possible () Iterates over the possible CPUs, in ascending order.
present () Iterates over the present CPUs, in ascending order.
stats (cpu) Returns the time a CPU spent in each state since boot, in nanoseconds.

Functions in detail

maxid ()
Returns the highest possible CPU id, the kernel’s nr_cpu_ids - 1.

Returns

    integer the highest possible CPU id
num_online ()
Returns the number of online CPUs.

Returns

    integer number of online CPUs
num_possible ()
Returns the number of possible CPUs.

Returns

    integer number of possible CPUs
num_present ()
Returns the number of present CPUs.

Returns

    integer number of present CPUs
online ()
Iterates over the online CPUs, in ascending order.

Returns

    function iterator for the generic for, yielding each online CPU id

Usage

for id in cpu.online() do print(id) end
possible ()
Iterates over the possible CPUs, in ascending order.

Returns

    function iterator for the generic for, yielding each possible CPU id

Usage

for id in cpu.possible() do print(id) end
present ()
Iterates over the present CPUs, in ascending order.

Returns

    function iterator for the generic for, yielding each present CPU id

Usage

for id in cpu.present() do print(id) end
stats (cpu)
Returns the time a CPU spent in each state since boot, in nanoseconds. idle and iowait are what the tick accounts, which lags /proc/stat on a tickless CPU while it idles.

Parameters

  • cpu integer CPU number, from 0 to maxid()

Returns

    table fields: user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice, forceidle (if CONFIG_SCHED_CORE), or nil for a CPU that is not online, which hotplug can take away between online() and this call

Raises

“out of bounds” if cpu is outside that range