Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f12e32f authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar
Browse files

x86/topology: Create logical package id



For per package oriented services we must be able to rely on the number of CPU
packages to be within bounds. Create a tracking facility, which

- calculates the number of possible packages depending on nr_cpu_ids after boot

- makes sure that the package id is within the number of possible packages. If
  the apic id is outside we map it to a logical package id if there is enough
  space available.

Provide interfaces for drivers to query the mapping and do translations from
physcial to logical ids.

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andi Kleen <andi.kleen@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Harish Chegondi <harish.chegondi@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Toshi Kani <toshi.kani@hp.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160222221011.541071755@linutronix.de


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 1f2569fa
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -129,6 +129,8 @@ struct cpuinfo_x86 {
	u16			booted_cores;
	u16			booted_cores;
	/* Physical processor id: */
	/* Physical processor id: */
	u16			phys_proc_id;
	u16			phys_proc_id;
	/* Logical processor id: */
	u16			logical_proc_id;
	/* Core id: */
	/* Core id: */
	u16			cpu_core_id;
	u16			cpu_core_id;
	/* Compute unit id */
	/* Compute unit id */
+11 −0
Original line number Original line Diff line number Diff line
@@ -119,12 +119,23 @@ static inline void setup_node_to_cpumask_map(void) { }


extern const struct cpumask *cpu_coregroup_mask(int cpu);
extern const struct cpumask *cpu_coregroup_mask(int cpu);


#define topology_logical_package_id(cpu)	(cpu_data(cpu).logical_proc_id)
#define topology_physical_package_id(cpu)	(cpu_data(cpu).phys_proc_id)
#define topology_physical_package_id(cpu)	(cpu_data(cpu).phys_proc_id)
#define topology_core_id(cpu)			(cpu_data(cpu).cpu_core_id)
#define topology_core_id(cpu)			(cpu_data(cpu).cpu_core_id)


#ifdef ENABLE_TOPO_DEFINES
#ifdef ENABLE_TOPO_DEFINES
#define topology_core_cpumask(cpu)		(per_cpu(cpu_core_map, cpu))
#define topology_core_cpumask(cpu)		(per_cpu(cpu_core_map, cpu))
#define topology_sibling_cpumask(cpu)		(per_cpu(cpu_sibling_map, cpu))
#define topology_sibling_cpumask(cpu)		(per_cpu(cpu_sibling_map, cpu))

extern unsigned int __max_logical_packages;
#define topology_max_packages()			(__max_logical_packages)
int topology_update_package_map(unsigned int apicid, unsigned int cpu);
extern int topology_phys_to_logical_pkg(unsigned int pkg);
#else
#define topology_max_packages()			(1)
static inline int
topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
#endif
#endif


static inline void arch_fix_phys_package_id(int num, u32 slot)
static inline void arch_fix_phys_package_id(int num, u32 slot)
+14 −0
Original line number Original line Diff line number Diff line
@@ -2077,6 +2077,20 @@ int generic_processor_info(int apicid, int version)
	} else
	} else
		cpu = cpumask_next_zero(-1, cpu_present_mask);
		cpu = cpumask_next_zero(-1, cpu_present_mask);


	/*
	 * This can happen on physical hotplug. The sanity check at boot time
	 * is done from native_smp_prepare_cpus() after num_possible_cpus() is
	 * established.
	 */
	if (topology_update_package_map(apicid, cpu) < 0) {
		int thiscpu = max + disabled_cpus;

		pr_warning("ACPI: Package limit reached. Processor %d/0x%x ignored.\n",
			   thiscpu, apicid);
		disabled_cpus++;
		return -ENOSPC;
	}

	/*
	/*
	 * Validate version
	 * Validate version
	 */
	 */
+2 −0
Original line number Original line Diff line number Diff line
@@ -975,6 +975,8 @@ static void identify_cpu(struct cpuinfo_x86 *c)
#ifdef CONFIG_NUMA
#ifdef CONFIG_NUMA
	numa_add_cpu(smp_processor_id());
	numa_add_cpu(smp_processor_id());
#endif
#endif
	/* The boot/hotplug time assigment got cleared, restore it */
	c->logical_proc_id = topology_phys_to_logical_pkg(c->phys_proc_id);
}
}


/*
/*
+13 −0
Original line number Original line Diff line number Diff line
@@ -160,6 +160,19 @@ static void early_init_intel(struct cpuinfo_x86 *c)
		pr_info("Disabling PGE capability bit\n");
		pr_info("Disabling PGE capability bit\n");
		setup_clear_cpu_cap(X86_FEATURE_PGE);
		setup_clear_cpu_cap(X86_FEATURE_PGE);
	}
	}

	if (c->cpuid_level >= 0x00000001) {
		u32 eax, ebx, ecx, edx;

		cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
		/*
		 * If HTT (EDX[28]) is set EBX[16:23] contain the number of
		 * apicids which are reserved per package. Store the resulting
		 * shift value for the package management code.
		 */
		if (edx & (1U << 28))
			c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
	}
}
}


#ifdef CONFIG_X86_32
#ifdef CONFIG_X86_32
Loading