2017-11-24 14:00:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-04-17 05:46:12 +00:00
|
|
|
/*
|
2012-07-20 09:15:04 +00:00
|
|
|
* Copyright IBM Corp. 2007, 2011
|
2008-04-17 05:46:12 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-25 12:39:50 +00:00
|
|
|
#define KMSG_COMPONENT "cpu"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2011-12-27 10:27:09 +00:00
|
|
|
#include <linux/workqueue.h>
|
2018-10-30 22:09:49 +00:00
|
|
|
#include <linux/memblock.h>
|
2017-09-14 12:42:32 +00:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/sysctl.h>
|
2011-12-27 10:27:09 +00:00
|
|
|
#include <linux/cpuset.h>
|
|
|
|
#include <linux/device.h>
|
2013-01-07 12:58:38 +00:00
|
|
|
#include <linux/export.h>
|
2011-12-27 10:27:09 +00:00
|
|
|
#include <linux/kernel.h>
|
2008-04-17 05:46:12 +00:00
|
|
|
#include <linux/sched.h>
|
2017-02-01 15:36:40 +00:00
|
|
|
#include <linux/sched/topology.h>
|
2011-12-27 10:27:09 +00:00
|
|
|
#include <linux/delay.h>
|
2015-02-04 13:21:31 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
2008-04-17 05:46:12 +00:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/smp.h>
|
2011-12-27 10:27:09 +00:00
|
|
|
#include <linux/mm.h>
|
2014-03-06 17:25:13 +00:00
|
|
|
#include <linux/nodemask.h>
|
|
|
|
#include <linux/node.h>
|
2012-09-03 12:11:32 +00:00
|
|
|
#include <asm/sysinfo.h>
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2008-04-17 05:46:13 +00:00
|
|
|
#define PTF_HORIZONTAL (0UL)
|
|
|
|
#define PTF_VERTICAL (1UL)
|
|
|
|
#define PTF_CHECK (2UL)
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2017-09-19 10:52:22 +00:00
|
|
|
enum {
|
|
|
|
TOPOLOGY_MODE_HW,
|
|
|
|
TOPOLOGY_MODE_SINGLE,
|
|
|
|
TOPOLOGY_MODE_PACKAGE,
|
|
|
|
TOPOLOGY_MODE_UNINITIALIZED
|
|
|
|
};
|
|
|
|
|
2010-08-31 08:28:18 +00:00
|
|
|
struct mask_info {
|
|
|
|
struct mask_info *next;
|
2010-05-17 08:00:12 +00:00
|
|
|
unsigned char id;
|
2008-04-17 05:46:12 +00:00
|
|
|
cpumask_t mask;
|
|
|
|
};
|
|
|
|
|
2017-09-19 10:52:22 +00:00
|
|
|
static int topology_mode = TOPOLOGY_MODE_UNINITIALIZED;
|
2012-11-12 09:03:25 +00:00
|
|
|
static void set_topology_timer(void);
|
2008-04-17 05:46:12 +00:00
|
|
|
static void topology_work_fn(struct work_struct *work);
|
2010-10-25 14:10:53 +00:00
|
|
|
static struct sysinfo_15_1_x *tl_info;
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2012-11-12 09:03:25 +00:00
|
|
|
static DECLARE_WORK(topology_work, topology_work_fn);
|
2008-04-30 11:38:40 +00:00
|
|
|
|
2015-08-01 16:12:41 +00:00
|
|
|
/*
|
2016-12-02 09:38:37 +00:00
|
|
|
* Socket/Book linked lists and cpu_topology updates are
|
2015-08-01 16:12:41 +00:00
|
|
|
* protected by "sched_domains_mutex".
|
|
|
|
*/
|
2012-11-12 09:03:25 +00:00
|
|
|
static struct mask_info socket_info;
|
2010-08-31 08:28:18 +00:00
|
|
|
static struct mask_info book_info;
|
2016-05-25 08:25:50 +00:00
|
|
|
static struct mask_info drawer_info;
|
2012-11-12 09:03:25 +00:00
|
|
|
|
2016-12-02 09:38:37 +00:00
|
|
|
struct cpu_topology_s390 cpu_topology[NR_CPUS];
|
|
|
|
EXPORT_SYMBOL_GPL(cpu_topology);
|
2011-12-27 10:27:09 +00:00
|
|
|
|
2021-02-17 07:15:00 +00:00
|
|
|
static void cpu_group_map(cpumask_t *dst, struct mask_info *info, unsigned int cpu)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2021-02-17 07:15:00 +00:00
|
|
|
static cpumask_t mask;
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2021-06-15 13:05:22 +00:00
|
|
|
cpumask_clear(&mask);
|
2021-08-27 18:21:05 +00:00
|
|
|
if (!cpumask_test_cpu(cpu, &cpu_setup_mask))
|
2021-06-15 13:05:22 +00:00
|
|
|
goto out;
|
|
|
|
cpumask_set_cpu(cpu, &mask);
|
2017-09-19 10:52:22 +00:00
|
|
|
switch (topology_mode) {
|
|
|
|
case TOPOLOGY_MODE_HW:
|
|
|
|
while (info) {
|
|
|
|
if (cpumask_test_cpu(cpu, &info->mask)) {
|
2021-02-17 07:15:00 +00:00
|
|
|
cpumask_copy(&mask, &info->mask);
|
2017-09-19 10:52:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
info = info->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TOPOLOGY_MODE_PACKAGE:
|
|
|
|
cpumask_copy(&mask, cpu_present_mask);
|
|
|
|
break;
|
|
|
|
default:
|
2020-03-10 20:47:30 +00:00
|
|
|
fallthrough;
|
2017-09-19 10:52:22 +00:00
|
|
|
case TOPOLOGY_MODE_SINGLE:
|
|
|
|
break;
|
2010-10-29 14:50:38 +00:00
|
|
|
}
|
2021-08-27 18:21:05 +00:00
|
|
|
cpumask_and(&mask, &mask, &cpu_setup_mask);
|
2021-06-15 13:05:22 +00:00
|
|
|
out:
|
2021-02-17 07:15:00 +00:00
|
|
|
cpumask_copy(dst, &mask);
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 07:15:00 +00:00
|
|
|
static void cpu_thread_map(cpumask_t *dst, unsigned int cpu)
|
2015-01-14 16:52:10 +00:00
|
|
|
{
|
2021-02-17 07:15:00 +00:00
|
|
|
static cpumask_t mask;
|
2015-01-14 16:52:10 +00:00
|
|
|
int i;
|
|
|
|
|
2021-06-15 13:05:22 +00:00
|
|
|
cpumask_clear(&mask);
|
2021-08-27 18:21:05 +00:00
|
|
|
if (!cpumask_test_cpu(cpu, &cpu_setup_mask))
|
2021-06-15 13:05:22 +00:00
|
|
|
goto out;
|
|
|
|
cpumask_set_cpu(cpu, &mask);
|
2017-09-19 10:52:22 +00:00
|
|
|
if (topology_mode != TOPOLOGY_MODE_HW)
|
2021-02-17 07:15:00 +00:00
|
|
|
goto out;
|
2015-01-14 16:52:10 +00:00
|
|
|
cpu -= cpu % (smp_cpu_mtid + 1);
|
2021-08-27 18:21:05 +00:00
|
|
|
for (i = 0; i <= smp_cpu_mtid; i++) {
|
|
|
|
if (cpumask_test_cpu(cpu + i, &cpu_setup_mask))
|
2015-01-14 16:52:10 +00:00
|
|
|
cpumask_set_cpu(cpu + i, &mask);
|
2021-08-27 18:21:05 +00:00
|
|
|
}
|
2021-02-17 07:15:00 +00:00
|
|
|
out:
|
|
|
|
cpumask_copy(dst, &mask);
|
2015-01-14 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 09:02:28 +00:00
|
|
|
#define TOPOLOGY_CORE_BITS 64
|
|
|
|
|
2016-05-25 07:53:07 +00:00
|
|
|
static void add_cpus_to_mask(struct topology_core *tl_core,
|
|
|
|
struct mask_info *drawer,
|
|
|
|
struct mask_info *book,
|
|
|
|
struct mask_info *socket)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2015-10-15 11:40:55 +00:00
|
|
|
struct cpu_topology_s390 *topo;
|
2015-01-14 16:52:10 +00:00
|
|
|
unsigned int core;
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2017-03-09 09:02:28 +00:00
|
|
|
for_each_set_bit(core, &tl_core->mask, TOPOLOGY_CORE_BITS) {
|
2015-01-14 16:52:10 +00:00
|
|
|
unsigned int rcore;
|
|
|
|
int lcpu, i;
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2015-01-14 16:52:10 +00:00
|
|
|
rcore = TOPOLOGY_CORE_BITS - 1 - core + tl_core->origin;
|
|
|
|
lcpu = smp_find_processor_id(rcore << smp_cpu_mt_shift);
|
2012-11-12 09:03:25 +00:00
|
|
|
if (lcpu < 0)
|
|
|
|
continue;
|
2015-01-14 16:52:10 +00:00
|
|
|
for (i = 0; i <= smp_cpu_mtid; i++) {
|
2016-12-02 09:38:37 +00:00
|
|
|
topo = &cpu_topology[lcpu + i];
|
2016-05-25 08:25:50 +00:00
|
|
|
topo->drawer_id = drawer->id;
|
2015-10-15 11:40:55 +00:00
|
|
|
topo->book_id = book->id;
|
2016-05-25 07:53:07 +00:00
|
|
|
topo->socket_id = socket->id;
|
2015-10-15 11:40:55 +00:00
|
|
|
topo->core_id = rcore;
|
|
|
|
topo->thread_id = lcpu + i;
|
2017-09-22 12:17:41 +00:00
|
|
|
topo->dedicated = tl_core->d;
|
2016-05-25 08:25:50 +00:00
|
|
|
cpumask_set_cpu(lcpu + i, &drawer->mask);
|
2015-01-14 16:52:10 +00:00
|
|
|
cpumask_set_cpu(lcpu + i, &book->mask);
|
|
|
|
cpumask_set_cpu(lcpu + i, &socket->mask);
|
|
|
|
smp_cpu_set_polarization(lcpu + i, tl_core->pp);
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-31 08:28:18 +00:00
|
|
|
static void clear_masks(void)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2010-08-31 08:28:18 +00:00
|
|
|
struct mask_info *info;
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2012-11-12 09:03:25 +00:00
|
|
|
info = &socket_info;
|
2010-08-31 08:28:18 +00:00
|
|
|
while (info) {
|
2011-05-23 08:24:36 +00:00
|
|
|
cpumask_clear(&info->mask);
|
2010-08-31 08:28:18 +00:00
|
|
|
info = info->next;
|
|
|
|
}
|
|
|
|
info = &book_info;
|
|
|
|
while (info) {
|
2011-05-23 08:24:36 +00:00
|
|
|
cpumask_clear(&info->mask);
|
2010-08-31 08:28:18 +00:00
|
|
|
info = info->next;
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
2016-05-25 08:25:50 +00:00
|
|
|
info = &drawer_info;
|
|
|
|
while (info) {
|
|
|
|
cpumask_clear(&info->mask);
|
|
|
|
info = info->next;
|
|
|
|
}
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 14:10:53 +00:00
|
|
|
static union topology_entry *next_tle(union topology_entry *tle)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2010-10-25 14:10:53 +00:00
|
|
|
if (!tle->nl)
|
2015-01-14 16:52:10 +00:00
|
|
|
return (union topology_entry *)((struct topology_core *)tle + 1);
|
2010-10-25 14:10:53 +00:00
|
|
|
return (union topology_entry *)((struct topology_container *)tle + 1);
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 07:53:07 +00:00
|
|
|
static void tl_to_masks(struct sysinfo_15_1_x *info)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2012-11-12 09:03:25 +00:00
|
|
|
struct mask_info *socket = &socket_info;
|
2011-12-27 10:27:09 +00:00
|
|
|
struct mask_info *book = &book_info;
|
2016-05-25 08:25:50 +00:00
|
|
|
struct mask_info *drawer = &drawer_info;
|
2010-10-25 14:10:53 +00:00
|
|
|
union topology_entry *tle, *end;
|
2010-08-31 08:28:18 +00:00
|
|
|
|
2016-05-25 07:53:07 +00:00
|
|
|
clear_masks();
|
2008-04-17 05:46:13 +00:00
|
|
|
tle = info->tle;
|
2010-10-25 14:10:53 +00:00
|
|
|
end = (union topology_entry *)((unsigned long)info + info->length);
|
2008-04-17 05:46:12 +00:00
|
|
|
while (tle < end) {
|
|
|
|
switch (tle->nl) {
|
2016-05-25 08:25:50 +00:00
|
|
|
case 3:
|
|
|
|
drawer = drawer->next;
|
|
|
|
drawer->id = tle->container.id;
|
|
|
|
break;
|
2008-04-17 05:46:12 +00:00
|
|
|
case 2:
|
2010-08-31 08:28:18 +00:00
|
|
|
book = book->next;
|
|
|
|
book->id = tle->container.id;
|
2008-04-17 05:46:12 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-11-12 09:03:25 +00:00
|
|
|
socket = socket->next;
|
|
|
|
socket->id = tle->container.id;
|
2008-04-17 05:46:12 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
2016-05-25 07:53:07 +00:00
|
|
|
add_cpus_to_mask(&tle->cpu, drawer, book, socket);
|
2011-12-27 10:27:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
clear_masks();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tle = next_tle(tle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 05:46:13 +00:00
|
|
|
static void topology_update_polarization_simple(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2008-12-25 12:37:57 +00:00
|
|
|
for_each_possible_cpu(cpu)
|
2012-09-04 15:36:16 +00:00
|
|
|
smp_cpu_set_polarization(cpu, POLARIZATION_HRZ);
|
2008-04-17 05:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ptf(unsigned long fc)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" .insn rre,0xb9a20000,%1,%1\n"
|
|
|
|
" ipm %0\n"
|
|
|
|
" srl %0,28\n"
|
|
|
|
: "=d" (rc)
|
2008-04-17 05:46:13 +00:00
|
|
|
: "d" (fc) : "cc");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int topology_set_cpu_management(int fc)
|
|
|
|
{
|
2011-12-27 10:27:09 +00:00
|
|
|
int cpu, rc;
|
2008-04-17 05:46:13 +00:00
|
|
|
|
2010-10-25 14:10:52 +00:00
|
|
|
if (!MACHINE_HAS_TOPOLOGY)
|
2008-04-17 05:46:13 +00:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
if (fc)
|
|
|
|
rc = ptf(PTF_VERTICAL);
|
|
|
|
else
|
|
|
|
rc = ptf(PTF_HORIZONTAL);
|
|
|
|
if (rc)
|
|
|
|
return -EBUSY;
|
2008-12-25 12:37:57 +00:00
|
|
|
for_each_possible_cpu(cpu)
|
2012-09-04 15:36:16 +00:00
|
|
|
smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
|
2008-04-17 05:46:12 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-03-12 10:32:23 +00:00
|
|
|
void update_cpu_masks(void)
|
2008-04-30 11:38:40 +00:00
|
|
|
{
|
2020-03-13 15:52:44 +00:00
|
|
|
struct cpu_topology_s390 *topo, *topo_package, *topo_sibling;
|
|
|
|
int cpu, sibling, pkg_first, smt_first, id;
|
2008-04-30 11:38:40 +00:00
|
|
|
|
2010-08-31 08:28:18 +00:00
|
|
|
for_each_possible_cpu(cpu) {
|
2016-12-02 09:38:37 +00:00
|
|
|
topo = &cpu_topology[cpu];
|
2021-02-17 07:15:00 +00:00
|
|
|
cpu_thread_map(&topo->thread_mask, cpu);
|
|
|
|
cpu_group_map(&topo->core_mask, &socket_info, cpu);
|
|
|
|
cpu_group_map(&topo->book_mask, &book_info, cpu);
|
|
|
|
cpu_group_map(&topo->drawer_mask, &drawer_info, cpu);
|
2020-03-13 15:52:44 +00:00
|
|
|
topo->booted_cores = 0;
|
2017-09-19 10:52:22 +00:00
|
|
|
if (topology_mode != TOPOLOGY_MODE_HW) {
|
|
|
|
id = topology_mode == TOPOLOGY_MODE_PACKAGE ? 0 : cpu;
|
2015-10-15 11:40:55 +00:00
|
|
|
topo->thread_id = cpu;
|
|
|
|
topo->core_id = cpu;
|
2017-09-19 10:52:22 +00:00
|
|
|
topo->socket_id = id;
|
|
|
|
topo->book_id = id;
|
|
|
|
topo->drawer_id = id;
|
2012-11-12 09:03:25 +00:00
|
|
|
}
|
2010-08-31 08:28:18 +00:00
|
|
|
}
|
2020-03-13 15:52:44 +00:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
topo = &cpu_topology[cpu];
|
|
|
|
pkg_first = cpumask_first(&topo->core_mask);
|
|
|
|
topo_package = &cpu_topology[pkg_first];
|
|
|
|
if (cpu == pkg_first) {
|
|
|
|
for_each_cpu(sibling, &topo->core_mask) {
|
|
|
|
topo_sibling = &cpu_topology[sibling];
|
|
|
|
smt_first = cpumask_first(&topo_sibling->thread_mask);
|
|
|
|
if (sibling == smt_first)
|
|
|
|
topo_package->booted_cores++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
topo->booted_cores = topo_package->booted_cores;
|
|
|
|
}
|
|
|
|
}
|
2010-08-31 08:28:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 14:10:54 +00:00
|
|
|
void store_topology(struct sysinfo_15_1_x *info)
|
2010-08-31 08:28:18 +00:00
|
|
|
{
|
2017-03-13 14:58:59 +00:00
|
|
|
stsi(info, 15, 1, topology_mnest_limit());
|
2008-04-30 11:38:40 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:17:41 +00:00
|
|
|
static void __arch_update_dedicated_flag(void *arg)
|
|
|
|
{
|
|
|
|
if (topology_cpu_dedicated(smp_processor_id()))
|
|
|
|
set_cpu_flag(CIF_DEDICATED_CPU);
|
|
|
|
else
|
|
|
|
clear_cpu_flag(CIF_DEDICATED_CPU);
|
|
|
|
}
|
|
|
|
|
2016-12-03 08:50:21 +00:00
|
|
|
static int __arch_update_cpu_topology(void)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2010-10-25 14:10:53 +00:00
|
|
|
struct sysinfo_15_1_x *info = tl_info;
|
2016-12-03 08:50:21 +00:00
|
|
|
int rc = 0;
|
2008-04-17 05:46:12 +00:00
|
|
|
|
2017-09-14 12:42:32 +00:00
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2014-03-06 17:25:13 +00:00
|
|
|
if (MACHINE_HAS_TOPOLOGY) {
|
|
|
|
rc = 1;
|
|
|
|
store_topology(info);
|
|
|
|
tl_to_masks(info);
|
2008-04-17 05:46:13 +00:00
|
|
|
}
|
2012-11-12 09:03:25 +00:00
|
|
|
update_cpu_masks();
|
2014-03-06 17:25:13 +00:00
|
|
|
if (!MACHINE_HAS_TOPOLOGY)
|
|
|
|
topology_update_polarization_simple();
|
2017-09-14 12:42:32 +00:00
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
2016-12-03 08:50:21 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int arch_update_cpu_topology(void)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
int cpu, rc;
|
|
|
|
|
|
|
|
rc = __arch_update_cpu_topology();
|
2017-09-22 12:17:41 +00:00
|
|
|
on_each_cpu(__arch_update_dedicated_flag, NULL, 0);
|
2008-04-17 05:46:12 +00:00
|
|
|
for_each_online_cpu(cpu) {
|
2011-12-21 22:29:42 +00:00
|
|
|
dev = get_cpu_device(cpu);
|
2019-09-17 20:59:03 +00:00
|
|
|
if (dev)
|
|
|
|
kobject_uevent(&dev->kobj, KOBJ_CHANGE);
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
2014-03-06 17:25:13 +00:00
|
|
|
return rc;
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
|
2008-04-30 11:38:41 +00:00
|
|
|
static void topology_work_fn(struct work_struct *work)
|
|
|
|
{
|
2008-12-25 12:37:59 +00:00
|
|
|
rebuild_sched_domains();
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 05:46:13 +00:00
|
|
|
void topology_schedule_update(void)
|
|
|
|
{
|
|
|
|
schedule_work(&topology_work);
|
|
|
|
}
|
|
|
|
|
2017-09-14 12:42:32 +00:00
|
|
|
static void topology_flush_work(void)
|
|
|
|
{
|
|
|
|
flush_work(&topology_work);
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:27:00 +00:00
|
|
|
static void topology_timer_fn(struct timer_list *unused)
|
2008-04-17 05:46:12 +00:00
|
|
|
{
|
2008-04-17 05:46:13 +00:00
|
|
|
if (ptf(PTF_CHECK))
|
|
|
|
topology_schedule_update();
|
2008-04-17 05:46:12 +00:00
|
|
|
set_topology_timer();
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:27:00 +00:00
|
|
|
static struct timer_list topology_timer;
|
2011-12-27 10:27:16 +00:00
|
|
|
|
|
|
|
static atomic_t topology_poll = ATOMIC_INIT(0);
|
|
|
|
|
2008-04-17 05:46:12 +00:00
|
|
|
static void set_topology_timer(void)
|
|
|
|
{
|
2011-12-27 10:27:16 +00:00
|
|
|
if (atomic_add_unless(&topology_poll, -1, 0))
|
2020-06-12 11:06:07 +00:00
|
|
|
mod_timer(&topology_timer, jiffies + msecs_to_jiffies(100));
|
2011-12-27 10:27:16 +00:00
|
|
|
else
|
2020-06-12 11:06:07 +00:00
|
|
|
mod_timer(&topology_timer, jiffies + msecs_to_jiffies(60 * MSEC_PER_SEC));
|
2011-12-27 10:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void topology_expect_change(void)
|
|
|
|
{
|
|
|
|
if (!MACHINE_HAS_TOPOLOGY)
|
|
|
|
return;
|
|
|
|
/* This is racy, but it doesn't matter since it is just a heuristic.
|
|
|
|
* Worst case is that we poll in a higher frequency for a bit longer.
|
|
|
|
*/
|
|
|
|
if (atomic_read(&topology_poll) > 60)
|
|
|
|
return;
|
|
|
|
atomic_add(60, &topology_poll);
|
|
|
|
set_topology_timer();
|
2008-04-17 05:46:12 +00:00
|
|
|
}
|
|
|
|
|
2011-12-27 10:27:09 +00:00
|
|
|
static int cpu_management;
|
|
|
|
|
2012-01-09 16:11:13 +00:00
|
|
|
static ssize_t dispatching_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2011-12-27 10:27:09 +00:00
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
|
|
|
count = sprintf(buf, "%d\n", cpu_management);
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-01-09 16:11:13 +00:00
|
|
|
static ssize_t dispatching_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2011-12-27 10:27:09 +00:00
|
|
|
const char *buf,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
int val, rc;
|
|
|
|
char delim;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%d %c", &val, &delim) != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
if (val != 0 && val != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
rc = 0;
|
2021-08-03 14:15:47 +00:00
|
|
|
cpus_read_lock();
|
2011-12-27 10:27:09 +00:00
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
|
|
|
if (cpu_management == val)
|
|
|
|
goto out;
|
|
|
|
rc = topology_set_cpu_management(val);
|
2011-12-27 10:27:16 +00:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
cpu_management = val;
|
|
|
|
topology_expect_change();
|
2011-12-27 10:27:09 +00:00
|
|
|
out:
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
2021-08-03 14:15:47 +00:00
|
|
|
cpus_read_unlock();
|
2011-12-27 10:27:09 +00:00
|
|
|
return rc ? rc : count;
|
|
|
|
}
|
2017-12-19 18:15:07 +00:00
|
|
|
static DEVICE_ATTR_RW(dispatching);
|
2011-12-27 10:27:09 +00:00
|
|
|
|
2012-01-09 16:11:13 +00:00
|
|
|
static ssize_t cpu_polarization_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2011-12-27 10:27:09 +00:00
|
|
|
{
|
|
|
|
int cpu = dev->id;
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2012-09-04 15:36:16 +00:00
|
|
|
switch (smp_cpu_get_polarization(cpu)) {
|
2011-12-27 10:27:09 +00:00
|
|
|
case POLARIZATION_HRZ:
|
|
|
|
count = sprintf(buf, "horizontal\n");
|
|
|
|
break;
|
|
|
|
case POLARIZATION_VL:
|
|
|
|
count = sprintf(buf, "vertical:low\n");
|
|
|
|
break;
|
|
|
|
case POLARIZATION_VM:
|
|
|
|
count = sprintf(buf, "vertical:medium\n");
|
|
|
|
break;
|
|
|
|
case POLARIZATION_VH:
|
|
|
|
count = sprintf(buf, "vertical:high\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
count = sprintf(buf, "unknown\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
return count;
|
|
|
|
}
|
2012-01-09 16:11:13 +00:00
|
|
|
static DEVICE_ATTR(polarization, 0444, cpu_polarization_show, NULL);
|
2011-12-27 10:27:09 +00:00
|
|
|
|
|
|
|
static struct attribute *topology_cpu_attrs[] = {
|
2012-01-09 16:11:13 +00:00
|
|
|
&dev_attr_polarization.attr,
|
2011-12-27 10:27:09 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group topology_cpu_attr_group = {
|
|
|
|
.attrs = topology_cpu_attrs,
|
|
|
|
};
|
|
|
|
|
2017-09-22 12:17:41 +00:00
|
|
|
static ssize_t cpu_dedicated_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
int cpu = dev->id;
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
|
|
|
count = sprintf(buf, "%d\n", topology_cpu_dedicated(cpu));
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(dedicated, 0444, cpu_dedicated_show, NULL);
|
|
|
|
|
|
|
|
static struct attribute *topology_extra_cpu_attrs[] = {
|
|
|
|
&dev_attr_dedicated.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group topology_extra_cpu_attr_group = {
|
|
|
|
.attrs = topology_extra_cpu_attrs,
|
|
|
|
};
|
|
|
|
|
2011-12-27 10:27:09 +00:00
|
|
|
int topology_cpu_init(struct cpu *cpu)
|
|
|
|
{
|
2017-09-22 12:17:41 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = sysfs_create_group(&cpu->dev.kobj, &topology_cpu_attr_group);
|
|
|
|
if (rc || !MACHINE_HAS_TOPOLOGY)
|
|
|
|
return rc;
|
|
|
|
rc = sysfs_create_group(&cpu->dev.kobj, &topology_extra_cpu_attr_group);
|
|
|
|
if (rc)
|
|
|
|
sysfs_remove_group(&cpu->dev.kobj, &topology_cpu_attr_group);
|
|
|
|
return rc;
|
2011-12-27 10:27:09 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 11:44:10 +00:00
|
|
|
static const struct cpumask *cpu_thread_mask(int cpu)
|
2015-01-14 16:52:10 +00:00
|
|
|
{
|
2016-12-02 09:38:37 +00:00
|
|
|
return &cpu_topology[cpu].thread_mask;
|
2015-01-14 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 09:44:38 +00:00
|
|
|
const struct cpumask *cpu_coregroup_mask(int cpu)
|
|
|
|
{
|
2016-12-02 09:38:37 +00:00
|
|
|
return &cpu_topology[cpu].core_mask;
|
2014-04-11 09:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct cpumask *cpu_book_mask(int cpu)
|
|
|
|
{
|
2016-12-02 09:38:37 +00:00
|
|
|
return &cpu_topology[cpu].book_mask;
|
2014-04-11 09:44:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 08:25:50 +00:00
|
|
|
static const struct cpumask *cpu_drawer_mask(int cpu)
|
|
|
|
{
|
2016-12-02 09:38:37 +00:00
|
|
|
return &cpu_topology[cpu].drawer_mask;
|
2016-05-25 08:25:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 09:44:38 +00:00
|
|
|
static struct sched_domain_topology_level s390_topology[] = {
|
2015-01-14 16:52:10 +00:00
|
|
|
{ cpu_thread_mask, cpu_smt_flags, SD_INIT_NAME(SMT) },
|
2014-04-11 09:44:38 +00:00
|
|
|
{ cpu_coregroup_mask, cpu_core_flags, SD_INIT_NAME(MC) },
|
|
|
|
{ cpu_book_mask, SD_INIT_NAME(BOOK) },
|
2016-05-25 08:25:50 +00:00
|
|
|
{ cpu_drawer_mask, SD_INIT_NAME(DRAWER) },
|
2015-08-13 08:35:11 +00:00
|
|
|
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
|
2014-04-11 09:44:38 +00:00
|
|
|
{ NULL, },
|
|
|
|
};
|
|
|
|
|
2015-02-04 13:21:31 +00:00
|
|
|
static void __init alloc_masks(struct sysinfo_15_1_x *info,
|
|
|
|
struct mask_info *mask, int offset)
|
|
|
|
{
|
|
|
|
int i, nr_masks;
|
|
|
|
|
|
|
|
nr_masks = info->mag[TOPOLOGY_NR_MAG - offset];
|
|
|
|
for (i = 0; i < info->mnest - offset; i++)
|
|
|
|
nr_masks *= info->mag[TOPOLOGY_NR_MAG - offset - 1 - i];
|
|
|
|
nr_masks = max(nr_masks, 1);
|
|
|
|
for (i = 0; i < nr_masks; i++) {
|
2018-10-30 22:08:04 +00:00
|
|
|
mask->next = memblock_alloc(sizeof(*mask->next), 8);
|
2019-03-12 06:30:31 +00:00
|
|
|
if (!mask->next)
|
|
|
|
panic("%s: Failed to allocate %zu bytes align=0x%x\n",
|
|
|
|
__func__, sizeof(*mask->next), 8);
|
2015-02-04 13:21:31 +00:00
|
|
|
mask = mask->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-03 08:50:21 +00:00
|
|
|
void __init topology_init_early(void)
|
2015-02-04 13:21:31 +00:00
|
|
|
{
|
|
|
|
struct sysinfo_15_1_x *info;
|
|
|
|
|
2016-12-03 08:50:16 +00:00
|
|
|
set_sched_topology(s390_topology);
|
2017-09-19 10:52:22 +00:00
|
|
|
if (topology_mode == TOPOLOGY_MODE_UNINITIALIZED) {
|
|
|
|
if (MACHINE_HAS_TOPOLOGY)
|
|
|
|
topology_mode = TOPOLOGY_MODE_HW;
|
|
|
|
else
|
|
|
|
topology_mode = TOPOLOGY_MODE_SINGLE;
|
|
|
|
}
|
2015-02-04 13:21:31 +00:00
|
|
|
if (!MACHINE_HAS_TOPOLOGY)
|
2016-12-03 08:50:21 +00:00
|
|
|
goto out;
|
2018-10-30 22:08:04 +00:00
|
|
|
tl_info = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
|
2019-03-12 06:30:31 +00:00
|
|
|
if (!tl_info)
|
|
|
|
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
|
|
|
|
__func__, PAGE_SIZE, PAGE_SIZE);
|
2015-02-04 13:21:31 +00:00
|
|
|
info = tl_info;
|
|
|
|
store_topology(info);
|
2017-01-02 07:15:07 +00:00
|
|
|
pr_info("The CPU configuration topology of the machine is: %d %d %d %d %d %d / %d\n",
|
|
|
|
info->mag[0], info->mag[1], info->mag[2], info->mag[3],
|
|
|
|
info->mag[4], info->mag[5], info->mnest);
|
2015-02-04 13:21:31 +00:00
|
|
|
alloc_masks(info, &socket_info, 1);
|
|
|
|
alloc_masks(info, &book_info, 2);
|
2016-05-25 08:25:50 +00:00
|
|
|
alloc_masks(info, &drawer_info, 3);
|
2016-12-03 08:50:21 +00:00
|
|
|
out:
|
2021-08-27 18:21:05 +00:00
|
|
|
cpumask_set_cpu(0, &cpu_setup_mask);
|
2016-12-03 08:50:21 +00:00
|
|
|
__arch_update_cpu_topology();
|
2017-09-22 12:17:41 +00:00
|
|
|
__arch_update_dedicated_flag(NULL);
|
2015-02-04 13:21:31 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 10:52:22 +00:00
|
|
|
static inline int topology_get_mode(int enabled)
|
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
return TOPOLOGY_MODE_SINGLE;
|
|
|
|
return MACHINE_HAS_TOPOLOGY ? TOPOLOGY_MODE_HW : TOPOLOGY_MODE_PACKAGE;
|
|
|
|
}
|
|
|
|
|
2017-09-14 12:42:32 +00:00
|
|
|
static inline int topology_is_enabled(void)
|
|
|
|
{
|
|
|
|
return topology_mode != TOPOLOGY_MODE_SINGLE;
|
|
|
|
}
|
|
|
|
|
2017-09-19 10:52:22 +00:00
|
|
|
static int __init topology_setup(char *str)
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = kstrtobool(str, &enabled);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
topology_mode = topology_get_mode(enabled);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("topology", topology_setup);
|
|
|
|
|
2017-09-14 12:42:32 +00:00
|
|
|
static int topology_ctl_handler(struct ctl_table *ctl, int write,
|
2020-04-24 06:43:38 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
2017-09-14 12:42:32 +00:00
|
|
|
{
|
2018-06-24 10:28:46 +00:00
|
|
|
int enabled = topology_is_enabled();
|
2017-09-14 12:42:32 +00:00
|
|
|
int new_mode;
|
2018-06-24 10:28:46 +00:00
|
|
|
int rc;
|
|
|
|
struct ctl_table ctl_entry = {
|
|
|
|
.procname = ctl->procname,
|
|
|
|
.data = &enabled,
|
|
|
|
.maxlen = sizeof(int),
|
proc/sysctl: add shared variables for range check
In the sysctl code the proc_dointvec_minmax() function is often used to
validate the user supplied value between an allowed range. This
function uses the extra1 and extra2 members from struct ctl_table as
minimum and maximum allowed value.
On sysctl handler declaration, in every source file there are some
readonly variables containing just an integer which address is assigned
to the extra1 and extra2 members, so the sysctl range is enforced.
The special values 0, 1 and INT_MAX are very often used as range
boundary, leading duplication of variables like zero=0, one=1,
int_max=INT_MAX in different source files:
$ git grep -E '\.extra[12].*&(zero|one|int_max)' |wc -l
248
Add a const int array containing the most commonly used values, some
macros to refer more easily to the correct array member, and use them
instead of creating a local one for every object file.
This is the bloat-o-meter output comparing the old and new binary
compiled with the default Fedora config:
# scripts/bloat-o-meter -d vmlinux.o.old vmlinux.o
add/remove: 2/2 grow/shrink: 0/2 up/down: 24/-188 (-164)
Data old new delta
sysctl_vals - 12 +12
__kstrtab_sysctl_vals - 12 +12
max 14 10 -4
int_max 16 - -16
one 68 - -68
zero 128 28 -100
Total: Before=20583249, After=20583085, chg -0.00%
[mcroce@redhat.com: tipc: remove two unused variables]
Link: http://lkml.kernel.org/r/20190530091952.4108-1-mcroce@redhat.com
[akpm@linux-foundation.org: fix net/ipv6/sysctl_net_ipv6.c]
[arnd@arndb.de: proc/sysctl: make firmware loader table conditional]
Link: http://lkml.kernel.org/r/20190617130014.1713870-1-arnd@arndb.de
[akpm@linux-foundation.org: fix fs/eventpoll.c]
Link: http://lkml.kernel.org/r/20190430180111.10688-1-mcroce@redhat.com
Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Aaron Tomlin <atomlin@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-07-18 22:58:50 +00:00
|
|
|
.extra1 = SYSCTL_ZERO,
|
|
|
|
.extra2 = SYSCTL_ONE,
|
2018-06-24 10:28:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
|
|
|
|
if (rc < 0 || !write)
|
|
|
|
return rc;
|
2017-09-14 12:42:32 +00:00
|
|
|
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2018-06-24 10:28:46 +00:00
|
|
|
new_mode = topology_get_mode(enabled);
|
2017-09-14 12:42:32 +00:00
|
|
|
if (topology_mode != new_mode) {
|
|
|
|
topology_mode = new_mode;
|
|
|
|
topology_schedule_update();
|
|
|
|
}
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
topology_flush_work();
|
2018-06-24 10:28:46 +00:00
|
|
|
|
|
|
|
return rc;
|
2017-09-14 12:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ctl_table topology_ctl_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "topology",
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = topology_ctl_handler,
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ctl_table topology_dir_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "s390",
|
|
|
|
.maxlen = 0,
|
|
|
|
.mode = 0555,
|
|
|
|
.child = topology_ctl_table,
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2011-12-27 10:27:09 +00:00
|
|
|
static int __init topology_init(void)
|
|
|
|
{
|
2017-10-04 23:27:00 +00:00
|
|
|
timer_setup(&topology_timer, topology_timer_fn, TIMER_DEFERRABLE);
|
2014-09-24 14:37:20 +00:00
|
|
|
if (MACHINE_HAS_TOPOLOGY)
|
|
|
|
set_topology_timer();
|
|
|
|
else
|
2011-12-27 10:27:09 +00:00
|
|
|
topology_update_polarization_simple();
|
2017-09-14 12:42:32 +00:00
|
|
|
register_sysctl_table(topology_dir_table);
|
2012-01-09 16:11:13 +00:00
|
|
|
return device_create_file(cpu_subsys.dev_root, &dev_attr_dispatching);
|
2011-12-27 10:27:09 +00:00
|
|
|
}
|
|
|
|
device_initcall(topology_init);
|