• Kan Liang's avatar
    perf: Generic hotplug support for a PMU with a scope · 4ba4f1af
    Kan Liang authored
    The perf subsystem assumes that the counters of a PMU are per-CPU. So
    the user space tool reads a counter from each CPU in the system wide
    mode. However, many PMUs don't have a per-CPU counter. The counter is
    effective for a scope, e.g., a die or a socket. To address this, a
    cpumask is exposed by the kernel driver to restrict to one CPU to stand
    for a specific scope. In case the given CPU is removed,
    the hotplug support has to be implemented for each such driver.
    
    The codes to support the cpumask and hotplug are very similar.
    - Expose a cpumask into sysfs
    - Pickup another CPU in the same scope if the given CPU is removed.
    - Invoke the perf_pmu_migrate_context() to migrate to a new CPU.
    - In event init, always set the CPU in the cpumask to event->cpu
    
    Similar duplicated codes are implemented for each such PMU driver. It
    would be good to introduce a generic infrastructure to avoid such
    duplication.
    
    5 popular scopes are implemented here, core, die, cluster, pkg, and
    the system-wide. The scope can be set when a PMU is registered. If so, a
    "cpumask" is automatically exposed for the PMU.
    
    The "cpumask" is from the perf_online_<scope>_mask, which is to track
    the active CPU for each scope. They are set when the first CPU of the
    scope is online via the generic perf hotplug support. When a
    corresponding CPU is removed, the perf_online_<scope>_mask is updated
    accordingly and the PMU will be moved to a new CPU from the same scope
    if possible.
    Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20240802151643.1691631-2-kan.liang@linux.intel.com
    4ba4f1af
core.c 343 KB