Skip to content

Commit

Permalink
Merge branch 'x86-topology-for-linus' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/linux/kernel/git/tip/tip

Pull x86 topology updates from Ingo Molnar:
 "Implement multi-die topology support on Intel CPUs and expose the die
  topology to user-space tooling, by Len Brown, Kan Liang and Zhang Rui.

  These changes should have no effect on the kernel's existing
  understanding of topologies, i.e. there should be no behavioral impact
  on cache, NUMA, scheduler, perf and other topologies and overall
  system performance"

* 'x86-topology-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  perf/x86/intel/rapl: Cosmetic rename internal variables in response to multi-die/pkg support
  perf/x86/intel/uncore: Cosmetic renames in response to multi-die/pkg support
  hwmon/coretemp: Cosmetic: Rename internal variables to zones from packages
  thermal/x86_pkg_temp_thermal: Cosmetic: Rename internal variables to zones from packages
  perf/x86/intel/cstate: Support multi-die/package
  perf/x86/intel/rapl: Support multi-die/package
  perf/x86/intel/uncore: Support multi-die/package
  topology: Create core_cpus and die_cpus sysfs attributes
  topology: Create package_cpus sysfs attribute
  hwmon/coretemp: Support multi-die/package
  powercap/intel_rapl: Update RAPL domain name and debug messages
  thermal/x86_pkg_temp_thermal: Support multi-die/package
  powercap/intel_rapl: Support multi-die/package
  powercap/intel_rapl: Simplify rapl_find_package()
  x86/topology: Define topology_logical_die_id()
  x86/topology: Define topology_die_id()
  cpu/topology: Export die_id
  x86/topology: Create topology_max_die_per_package()
  x86/topology: Add CPUID.1F multi-die/package support
  • Loading branch information
torvalds committed Jul 9, 2019
2 parents 8faef71 + eb876fb commit 222a21d
Show file tree
Hide file tree
Showing 19 changed files with 422 additions and 214 deletions.
48 changes: 33 additions & 15 deletions Documentation/cputopology.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ physical_package_id:
socket number, but the actual value is architecture and platform
dependent.

die_id:

the CPU die ID of cpuX. Typically it is the hardware platform's
identifier (rather than the kernel's). The actual value is
architecture and platform dependent.

core_id:

the CPU core ID of cpuX. Typically it is the hardware platform's
Expand All @@ -30,25 +36,33 @@ drawer_id:
identifier (rather than the kernel's). The actual value is
architecture and platform dependent.

thread_siblings:
core_cpus:

internal kernel map of cpuX's hardware threads within the same
core as cpuX.
internal kernel map of CPUs within the same core.
(deprecated name: "thread_siblings")

thread_siblings_list:
core_cpus_list:

human-readable list of cpuX's hardware threads within the same
core as cpuX.
human-readable list of CPUs within the same core.
(deprecated name: "thread_siblings_list");

core_siblings:
package_cpus:

internal kernel map of cpuX's hardware threads within the same
physical_package_id.
internal kernel map of the CPUs sharing the same physical_package_id.
(deprecated name: "core_siblings")

core_siblings_list:
package_cpus_list:

human-readable list of cpuX's hardware threads within the same
physical_package_id.
human-readable list of CPUs sharing the same physical_package_id.
(deprecated name: "core_siblings_list")

die_cpus:

internal kernel map of CPUs within the same die.

die_cpus_list:

human-readable list of CPUs within the same die.

book_siblings:

Expand Down Expand Up @@ -81,11 +95,13 @@ For an architecture to support this feature, it must define some of
these macros in include/asm-XXX/topology.h::

#define topology_physical_package_id(cpu)
#define topology_die_id(cpu)
#define topology_core_id(cpu)
#define topology_book_id(cpu)
#define topology_drawer_id(cpu)
#define topology_sibling_cpumask(cpu)
#define topology_core_cpumask(cpu)
#define topology_die_cpumask(cpu)
#define topology_book_cpumask(cpu)
#define topology_drawer_cpumask(cpu)

Expand All @@ -99,9 +115,11 @@ provides default definitions for any of the above macros that are
not defined by include/asm-XXX/topology.h:

1) topology_physical_package_id: -1
2) topology_core_id: 0
3) topology_sibling_cpumask: just the given CPU
4) topology_core_cpumask: just the given CPU
2) topology_die_id: -1
3) topology_core_id: 0
4) topology_sibling_cpumask: just the given CPU
5) topology_core_cpumask: just the given CPU
6) topology_die_cpumask: just the given CPU

For architectures that don't support books (CONFIG_SCHED_BOOK) there are no
default definitions for topology_book_id() and topology_book_cpumask().
Expand Down
4 changes: 4 additions & 0 deletions Documentation/x86/topology.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Package-related topology information in the kernel:

The number of cores in a package. This information is retrieved via CPUID.

- cpuinfo_x86.x86_max_dies:

The number of dies in a package. This information is retrieved via CPUID.

- cpuinfo_x86.phys_proc_id:

The physical ID of the package. This information is retrieved via CPUID
Expand Down
14 changes: 10 additions & 4 deletions arch/x86/events/intel/cstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static int cstate_pmu_event_init(struct perf_event *event)
return -EINVAL;
event->hw.event_base = pkg_msr[cfg].msr;
cpu = cpumask_any_and(&cstate_pkg_cpu_mask,
topology_core_cpumask(event->cpu));
topology_die_cpumask(event->cpu));
} else {
return -ENOENT;
}
Expand Down Expand Up @@ -385,7 +385,7 @@ static int cstate_cpu_exit(unsigned int cpu)
if (has_cstate_pkg &&
cpumask_test_and_clear_cpu(cpu, &cstate_pkg_cpu_mask)) {

target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
target = cpumask_any_but(topology_die_cpumask(cpu), cpu);
/* Migrate events if there is a valid target */
if (target < nr_cpu_ids) {
cpumask_set_cpu(target, &cstate_pkg_cpu_mask);
Expand Down Expand Up @@ -414,7 +414,7 @@ static int cstate_cpu_init(unsigned int cpu)
* in the package cpu mask as the designated reader.
*/
target = cpumask_any_and(&cstate_pkg_cpu_mask,
topology_core_cpumask(cpu));
topology_die_cpumask(cpu));
if (has_cstate_pkg && target >= nr_cpu_ids)
cpumask_set_cpu(cpu, &cstate_pkg_cpu_mask);

Expand Down Expand Up @@ -663,7 +663,13 @@ static int __init cstate_init(void)
}

if (has_cstate_pkg) {
err = perf_pmu_register(&cstate_pkg_pmu, cstate_pkg_pmu.name, -1);
if (topology_max_die_per_package() > 1) {
err = perf_pmu_register(&cstate_pkg_pmu,
"cstate_die", -1);
} else {
err = perf_pmu_register(&cstate_pkg_pmu,
cstate_pkg_pmu.name, -1);
}
if (err) {
has_cstate_pkg = false;
pr_info("Failed to register cstate pkg pmu\n");
Expand Down
20 changes: 10 additions & 10 deletions arch/x86/events/intel/rapl.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct rapl_pmu {

struct rapl_pmus {
struct pmu pmu;
unsigned int maxpkg;
unsigned int maxdie;
struct rapl_pmu *pmus[];
};

Expand All @@ -162,13 +162,13 @@ static u64 rapl_timer_ms;

static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu)
{
unsigned int pkgid = topology_logical_package_id(cpu);
unsigned int dieid = topology_logical_die_id(cpu);

/*
* The unsigned check also catches the '-1' return value for non
* existent mappings in the topology map.
*/
return pkgid < rapl_pmus->maxpkg ? rapl_pmus->pmus[pkgid] : NULL;
return dieid < rapl_pmus->maxdie ? rapl_pmus->pmus[dieid] : NULL;
}

static inline u64 rapl_read_counter(struct perf_event *event)
Expand Down Expand Up @@ -572,7 +572,7 @@ static int rapl_cpu_offline(unsigned int cpu)

pmu->cpu = -1;
/* Find a new cpu to collect rapl events */
target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
target = cpumask_any_but(topology_die_cpumask(cpu), cpu);

/* Migrate rapl events to the new target */
if (target < nr_cpu_ids) {
Expand All @@ -599,14 +599,14 @@ static int rapl_cpu_online(unsigned int cpu)
pmu->timer_interval = ms_to_ktime(rapl_timer_ms);
rapl_hrtimer_init(pmu);

rapl_pmus->pmus[topology_logical_package_id(cpu)] = pmu;
rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu;
}

/*
* Check if there is an online cpu in the package which collects rapl
* events already.
*/
target = cpumask_any_and(&rapl_cpu_mask, topology_core_cpumask(cpu));
target = cpumask_any_and(&rapl_cpu_mask, topology_die_cpumask(cpu));
if (target < nr_cpu_ids)
return 0;

Expand Down Expand Up @@ -669,22 +669,22 @@ static void cleanup_rapl_pmus(void)
{
int i;

for (i = 0; i < rapl_pmus->maxpkg; i++)
for (i = 0; i < rapl_pmus->maxdie; i++)
kfree(rapl_pmus->pmus[i]);
kfree(rapl_pmus);
}

static int __init init_rapl_pmus(void)
{
int maxpkg = topology_max_packages();
int maxdie = topology_max_packages() * topology_max_die_per_package();
size_t size;

size = sizeof(*rapl_pmus) + maxpkg * sizeof(struct rapl_pmu *);
size = sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *);
rapl_pmus = kzalloc(size, GFP_KERNEL);
if (!rapl_pmus)
return -ENOMEM;

rapl_pmus->maxpkg = maxpkg;
rapl_pmus->maxdie = maxdie;
rapl_pmus->pmu.attr_groups = rapl_attr_groups;
rapl_pmus->pmu.task_ctx_nr = perf_invalid_context;
rapl_pmus->pmu.event_init = rapl_pmu_event_init;
Expand Down
Loading

0 comments on commit 222a21d

Please sign in to comment.