16 KiB
likwid
collector
The likwid
collector is probably the most complicated collector. The LIKWID library is included as static library with direct access mode. The direct access mode is suitable if the daemon is executed by a root user. The static library does not contain the performance groups, so all information needs to be provided in the configuration.
"likwid": {
"force_overwrite" : false,
"invalid_to_zero" : false,
"liblikwid_path" : "/path/to/liblikwid.so",
"accessdaemon_path" : "/folder/that/contains/likwid-accessD",
"access_mode" : "direct or accessdaemon or perf_event",
"lockfile_path" : "/var/run/likwid.lock",
"eventsets": [
{
"events" : {
"COUNTER0": "EVENT0",
"COUNTER1": "EVENT1",
},
"metrics" : [
{
"name": "sum_01",
"calc": "COUNTER0 + COUNTER1",
"publish": false,
"unit": "myunit",
"type": "hwthread"
}
]
}
]
"globalmetrics" : [
{
"name": "global_sum",
"calc": "sum_01",
"publish": true,
"unit": "myunit",
"type": "hwthread"
}
]
}
The likwid
configuration consists of two parts, the eventsets
and globalmetrics
:
- An event set list itself has two parts, the
events
and a set of derivablemetrics
. Each of theevents
is acounter:event
pair in LIKWID's syntax. Themetrics
are a list of formulas to derive the metric value from the measurements of theevents
' values. Each metric has a name, the formula, a type and a publish flag. There is an optionalunit
field. Counter names can be used like variables in the formulas, soPMC0+PMC1
sums the measurements for the both events configured in the countersPMC0
andPMC1
. You can optionally usetime
for the measurement time andinverseClock
for1.0/baseCpuFrequency
. The type tells the LikwidCollector whether it is a metric for each hardware thread (cpu
) or each CPU socket (socket
). You may specify a unit for the metric withunit
. The last one is the publishing flag. It tells the LikwidCollector whether a metric should be sent to the router or is only used internally to compute a global metric. - The
globalmetrics
are metrics which require data from multiple event set measurements to be derived. The inputs are the metrics in the event sets. Similar to the metrics in the event sets, the global metrics are defined by a name, a formula, a type and a publish flag. See event set metrics for details. The only difference is that there is no access to the raw event measurements anymore but only to the metrics. Alsotime
andinverseClock
cannot be used anymore. So, the idea is to derive a metric in theeventsets
section and reuse it in theglobalmetrics
part. If you need a metric only for deriving the global metrics, disable forwarding of the event set metrics ("publish": false
). Be aware that the combination might be misleading because the "behavior" of a metric changes over time and the multiple measurements might count different computing phases. Similar to the metrics in the eventset, you can specify a metric unit with theunit
field.
Additional options:
force_overwrite
: Same as settingLIKWID_FORCE=1
. In case counters are already in-use, LIKWID overwrites their configuration to do its measurementsinvalid_to_zero
: In some cases, the calculations result inNaN
orInf
. With this option, allNaN
andInf
values are replaces with0.0
. See below in seperate sectionaccess_mode
: Specify LIKWID access mode:direct
for direct register access as root user oraccessdaemon
. The access modeperf_event
is current untested.accessdaemon_path
: Folder of the accessDaemonlikwid-accessD
(like/usr/local/sbin
)liblikwid_path
: Location ofliblikwid.so
including file name like/usr/local/lib/liblikwid.so
lockfile_path
: Location of LIKWID's lock file if multiple tools should access the hardware counters. Default/var/run/likwid.lock
Available metric types
Hardware performance counters are scattered all over the system nowadays. A counter coveres a specific part of the system. While there are hardware thread specific counter for CPU cycles, instructions and so on, some others are specific for a whole CPU socket/package. To address that, the LikwidCollector provides the specification of a type
for each metric.
hwthread
: One metric per CPU hardware thread with the tags"type" : "hwthread"
and"type-id" : "$hwthread_id"
socket
: One metric per CPU socket/package with the tags"type" : "socket"
and"type-id" : "$socket_id"
Note: You cannot specify socket
type for a metric that is measured at hwthread
type, so some kind of expert knowledge or lookup work in the Likwid Wiki is required. Get the type of each counter from the Architecture pages and as soon as one counter in a metric is socket-specific, the whole metric is socket-specific.
As a guideline:
- All counters
FIXCx
,PMCy
andTMAz
have the typehwthread
- All counters names containing
BOX
have the typesocket
- All
PWRx
counters have typesocket
, except"PWR1" : "RAPL_CORE_ENERGY"
hashwthread
type - All
DFCx
counters have typesocket
Help with the configuration
The configuration for the likwid
collector is quite complicated. Most users don't use LIKWID with the event:counter notation but rely on the performance groups defined by the LIKWID team for each architecture. In order to help with the likwid
collector configuration, we included a script scripts/likwid_perfgroup_to_cc_config.py
that creates the configuration of an eventset
from a performance group (using a LIKWID installation in $PATH
):
$ likwid-perfctr -i
[...]
short name: ICX
[...]
$ likwid-perfctr -a
[...]
MEM_DP
MEM
FLOPS_SP
CLOCK
[...]
$ scripts/likwid_perfgroup_to_cc_config.py ICX MEM_DP
{
"events": {
"FIXC0": "INSTR_RETIRED_ANY",
"FIXC1": "CPU_CLK_UNHALTED_CORE",
"..." : "..."
},
"metrics" : [
{
"calc": "time",
"name": "Runtime (RDTSC) [s]",
"publish": true,
"unit": "seconds"
"type": "hwthread"
},
{
"..." : "..."
}
]
}
You can copy this JSON and add it to the eventsets
list. If you specify multiple event sets, you can add globally derived metrics in the extra global_metrics
section with the metric names as variables.
Mixed usage between daemon and users
LIKWID checks the file /var/run/likwid.lock
before performing any interfering operations. Who is allowed to access the counters is determined by the owner of the file. If it does not exist, it is created for the current user. So, if you want to temporarly allow counter access to a user (e.g. in a job):
Before (SLURM prolog, ...)
chown $JOBUSER /var/run/likwid.lock
After (SLURM epilog, ...)
chown $CCUSER /var/run/likwid.lock
invalid_to_zero
option
In some cases LIKWID returns 0.0
for some events that are further used in processing and maybe used as divisor in a calculation. After evaluation of a metric, the result might be NaN
or +-Inf
. These resulting metrics are commonly not created and forwarded to the router because the InfluxDB line protocol does not support these special floating-point values. If you want to have them sent, this option forces these metric values to be 0.0
instead.
One might think this does not happen often but often used metrics in the world of performance engineering like Instructions-per-Cycle (IPC) or more frequently the actual CPU clock are derived with events like CPU_CLK_UNHALTED_CORE
(Intel) which do not increment in halted state (as the name implies). In there are different power management systems in a chip which can cause a hardware thread to go in such a state. Moreover, if no cycles are executed by the core, also many other events are not incremented as well (like INSTR_RETIRED_ANY
for retired instructions and part of IPC).
send_*_total values
option
send_core_total_values
: Metrics, which are usually collected on a per hardware thread basis, are additionally summed up per CPU core.send_socket_total_values
Metrics, which are usually collected on a per hardware thread basis, are additionally summed up per CPU socket.send_node_total_values
Metrics, which are usually collected on a per hardware thread basis, are additionally summed up per node.
Example configuration
AMD Zen3
"likwid": {
"force_overwrite" : false,
"invalid_to_zero" : false,
"eventsets": [
{
"events": {
"FIXC1": "ACTUAL_CPU_CLOCK",
"FIXC2": "MAX_CPU_CLOCK",
"PMC0": "RETIRED_INSTRUCTIONS",
"PMC1": "CPU_CLOCKS_UNHALTED",
"PMC2": "RETIRED_SSE_AVX_FLOPS_ALL",
"PMC3": "MERGE",
"DFC0": "DRAM_CHANNEL_0",
"DFC1": "DRAM_CHANNEL_1",
"DFC2": "DRAM_CHANNEL_2",
"DFC3": "DRAM_CHANNEL_3"
},
"metrics": [
{
"name": "ipc",
"calc": "PMC0/PMC1",
"type": "hwthread",
"publish": true
},
{
"name": "flops_any",
"calc": "0.000001*PMC2/time",
"unit": "MFlops/s",
"type": "hwthread",
"publish": true
},
{
"name": "clock",
"calc": "0.000001*(FIXC1/FIXC2)/inverseClock",
"type": "hwthread",
"unit": "MHz",
"publish": true
},
{
"name": "mem1",
"calc": "0.000001*(DFC0+DFC1+DFC2+DFC3)*64.0/time",
"unit": "Mbyte/s",
"type": "socket",
"publish": false
}
]
},
{
"events": {
"DFC0": "DRAM_CHANNEL_4",
"DFC1": "DRAM_CHANNEL_5",
"DFC2": "DRAM_CHANNEL_6",
"DFC3": "DRAM_CHANNEL_7",
"PWR0": "RAPL_CORE_ENERGY",
"PWR1": "RAPL_PKG_ENERGY"
},
"metrics": [
{
"name": "pwr_core",
"calc": "PWR0/time",
"unit": "Watt"
"type": "socket",
"publish": true
},
{
"name": "pwr_pkg",
"calc": "PWR1/time",
"type": "socket",
"unit": "Watt"
"publish": true
},
{
"name": "mem2",
"calc": "0.000001*(DFC0+DFC1+DFC2+DFC3)*64.0/time",
"unit": "Mbyte/s",
"type": "socket",
"publish": false
}
]
}
],
"globalmetrics": [
{
"name": "mem_bw",
"calc": "mem1+mem2",
"type": "socket",
"unit": "Mbyte/s",
"publish": true
}
]
}
How to get the eventsets and metrics from LIKWID
The likwid
collector reads hardware performance counters at a hwthread and socket level. The configuration looks quite complicated but it is basically copy&paste from LIKWID's performance groups. The collector made multiple iterations and tried to use the performance groups but it lacked flexibility. The current way of configuration provides most flexibility.
The logic is as following: There are multiple eventsets, each consisting of a list of counters+events and a list of metrics. If you compare a common performance group with the example setting above, there is not much difference:
EVENTSET -> "events": {
FIXC1 ACTUAL_CPU_CLOCK -> "FIXC1": "ACTUAL_CPU_CLOCK",
FIXC2 MAX_CPU_CLOCK -> "FIXC2": "MAX_CPU_CLOCK",
PMC0 RETIRED_INSTRUCTIONS -> "PMC0" : "RETIRED_INSTRUCTIONS",
PMC1 CPU_CLOCKS_UNHALTED -> "PMC1" : "CPU_CLOCKS_UNHALTED",
PMC2 RETIRED_SSE_AVX_FLOPS_ALL -> "PMC2": "RETIRED_SSE_AVX_FLOPS_ALL",
PMC3 MERGE -> "PMC3": "MERGE",
-> }
The metrics are following the same procedure:
METRICS -> "metrics": [
IPC PMC0/PMC1 -> {
-> "name" : "IPC",
-> "calc" : "PMC0/PMC1",
-> "type": "hwthread",
-> "publish": true
-> }
-> ]
The script scripts/likwid_perfgroup_to_cc_config.py
might help you.
Internal structure
This section describes the internal structure of the likwid
collector.
At initialization
After setting the defaults, the configuration is read.
Based on the configuration, the library is searched using dlopen
to see whether it makes sense to proceed.
Next, the user-given metrics are tested to ensure they can be evaluated. For this, it creates a list of all user-given events/counters with the value 1.0
which is provided to the metric evaluator. The same is done for the global metrics by using the metric names with value 1.0
. If the evaluator does not fail, the metric can be evaluated and the collector initialization can proceed.
A separate thread is started to do the measurement. This is not done using a common goroutine but a real application thread with full control. This is required because LIKWID's access system tracks the processes of the using application and the PID should not change between measurements because that would require teardown and reopening of the access system.
With the separate thread, the access system is initialized by setting the user-given access mode and adding all hardware threads.
LIKWID measures per hardware thread in general but only some HW threads read the counters available only e.g. per CPU socket (often memory traffic). For this, the collector gets the system topology through LIKWID and creates different mappings like 'hwthread to list offset' and others. With this, the hardware threads responsible for a topological entity can be determined because those read the counters of the per CPU socket units. These mappings are later used in the measurement phase.
In the end, we read the base CPU frequency of the system. It may be used in the metric evaluation.
Measurements
The reading of events is done by the separate application thread.
It traverses over all configured event sets, creates valid LIKWID eventstrings out of them and pass them to take a measurement. This could be done only once but when the LIKWID lock changes, LIKWID has to be completely reopened to provide access again. With this reopening, the already added event sets are gone.
LIKWID has it's own locking mechanism using a lock file. But not the content of the file is of interest but the owner. In order to track changes of the file, a fsnotify
watcher is installed on the file. If the file does not exist, it is created and consequently is owned by the same user as cc-metric-collector
. The LikwidCollector has to watch the file on it's own because LIKWID does not provide proper error handling for this.
Each call to the LIKWID library for loading the event set, setting up the counting facilities as well as starting and stopping of the counters is wrapped into lockfile checks to ensure no state change happens. If the file owner changed, the LikwidCollector cannot access the counters anymore, so no further operation can be done and measurment stops.
Although start/stop would be sufficient, the LikwidCollector performs start, read, wait, read, getLastResult
, stop. Reason might be "historic" but is not 100% clear anymore. The author failed to document ;)
Metric evaluation
After each meaurement, the metrics of the event set are directly evaluated. It updates the counter->result mapping with the new measurements, calls the evaluator and generates the CCMetric
with the user-given settings if it should be published. Each metric name to result calculation is stored for the global metric evaluation, which is done as a final step.
Shutdown
Since each measurment involves a complete initialize to finalize cycle of the LIKWID library, only the topology module needs to be closed.
Moreover, the separate application thread is stopped.