Add the cpuset_t conversion for mips.

This commit is contained in:
attilio 2011-05-13 16:42:05 +00:00
parent a0db972f62
commit dcae8c9626
9 changed files with 96 additions and 42 deletions

View File

@ -102,10 +102,20 @@ platform_init_ap(int cpuid)
mips_wbflush();
}
cpumask_t
cpuset_t
platform_cpu_mask(void)
{
return (octeon_bootinfo->core_mask);
cpuset_t cpumask;
CPU_ZERO(&cpumask);
/*
* XXX: hack in order to simplify CPU set building, assuming that
* core_mask is 32-bits.
*/
memcpy(&cpumask, &octeon_bootinfo->core_mask,
sizeof(octeon_bootinfo->core_mask));
return (cpumask);
}
struct cpu_group *

View File

@ -73,7 +73,6 @@ typedef unsigned long long __uint64_t;
* Standard type definitions.
*/
typedef __int32_t __clock_t; /* clock()... */
typedef unsigned int __cpumask_t;
typedef double __double_t;
typedef double __float_t;
#ifdef __mips_n64

View File

@ -28,6 +28,8 @@
#ifndef _MACHINE_HWFUNC_H_
#define _MACHINE_HWFUNC_H_
#include <sys/_cpuset.h>
struct trapframe;
struct timecounter;
/*
@ -91,7 +93,7 @@ extern int platform_processor_id(void);
/*
* Return the cpumask of available processors.
*/
extern cpumask_t platform_cpu_mask(void);
extern cpuset_t platform_cpu_mask(void);
/*
* Return the topology of processors on this platform

View File

@ -58,6 +58,7 @@
#ifndef LOCORE
#include <sys/queue.h>
#include <sys/_cpuset.h>
#include <sys/_lock.h>
#include <sys/_mutex.h>
@ -83,7 +84,7 @@ struct pmap {
pd_entry_t *pm_segtab; /* KVA of segment table */
TAILQ_HEAD(, pv_entry) pm_pvlist; /* list of mappings in
* pmap */
cpumask_t pm_active; /* active on cpus */
cpuset_t pm_active; /* active on cpus */
struct {
u_int32_t asid:ASID_BITS; /* TLB address space tag */
u_int32_t gen:ASIDGEN_BITS; /* its generation number */

View File

@ -17,6 +17,8 @@
#ifdef _KERNEL
#include <sys/_cpuset.h>
#include <machine/pcb.h>
/*
@ -33,7 +35,7 @@
void ipi_all_but_self(int ipi);
void ipi_cpu(int cpu, u_int ipi);
void ipi_selected(cpumask_t cpus, int ipi);
void ipi_selected(cpuset_t cpus, int ipi);
void smp_init_secondary(u_int32_t cpuid);
void mpentry(void);

View File

@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/cpuset.h>
#include <sys/ktr.h>
#include <sys/proc.h>
#include <sys/lock.h>
@ -80,15 +81,16 @@ ipi_all_but_self(int ipi)
/* Send an IPI to a set of cpus. */
void
ipi_selected(cpumask_t cpus, int ipi)
ipi_selected(cpuset_t cpus, int ipi)
{
struct pcpu *pc;
CTR3(KTR_SMP, "%s: cpus: %x, ipi: %x\n", __func__, cpus, ipi);
SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
if ((cpus & pc->pc_cpumask) != 0)
if (CPU_OVERLAP(&cpus, &pc->pc_cpumask)) {
CTR3(KTR_SMP, "%s: pc: %p, ipi: %x\n", __func__, pc,
ipi);
ipi_send(pc, ipi);
}
}
}
@ -108,7 +110,7 @@ static int
mips_ipi_handler(void *arg)
{
int cpu;
cpumask_t cpumask;
cpuset_t cpumask;
u_int ipi, ipi_bitmap;
int bit;
@ -148,14 +150,14 @@ mips_ipi_handler(void *arg)
tlb_save();
/* Indicate we are stopped */
atomic_set_int(&stopped_cpus, cpumask);
CPU_OR_ATOMIC(&stopped_cpus, &cpumask);
/* Wait for restart */
while ((started_cpus & cpumask) == 0)
while (!CPU_OVERLAP(&started_cpus, &cpumask))
cpu_spinwait();
atomic_clear_int(&started_cpus, cpumask);
atomic_clear_int(&stopped_cpus, cpumask);
CPU_NAND_ATOMIC(&started_cpus, &cpumask);
CPU_NAND_ATOMIC(&stopped_cpus, &cpumask);
CTR0(KTR_SMP, "IPI_STOP (restart)");
break;
case IPI_PREEMPT:
@ -200,14 +202,21 @@ start_ap(int cpuid)
void
cpu_mp_setmaxid(void)
{
cpumask_t cpumask;
cpuset_t cpumask;
int cpu, last;
cpumask = platform_cpu_mask();
mp_ncpus = bitcount32(cpumask);
mp_ncpus = 0;
last = 1;
while ((cpu = cpusetobj_ffs(&cpumask)) != 0) {
last = cpu;
mp_ncpus++;
CPU_CLR(cpu, &cpumask);
}
if (mp_ncpus <= 0)
mp_ncpus = 1;
mp_maxid = min(fls(cpumask), MAXCPU) - 1;
mp_maxid = min(last, MAXCPU) - 1;
}
void
@ -233,16 +242,16 @@ void
cpu_mp_start(void)
{
int error, cpuid;
cpumask_t cpumask;
cpuset_t cpumask, ocpus;
mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
all_cpus = 0;
CPU_ZERO(&all_cpus);
cpumask = platform_cpu_mask();
while (cpumask != 0) {
cpuid = ffs(cpumask) - 1;
cpumask &= ~(1 << cpuid);
while (!CPU_EMPTY(&cpumask)) {
cpuid = cpusetobj_ffs(&cpumask) - 1;
CPU_CLR(cpuid, &cpumask);
if (cpuid >= MAXCPU) {
printf("cpu_mp_start: ignoring AP #%d.\n", cpuid);
@ -257,15 +266,19 @@ cpu_mp_start(void)
if (bootverbose)
printf("AP #%d started!\n", cpuid);
}
all_cpus |= 1 << cpuid;
CPU_SET(cpuid, &all_cpus);
}
PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
ocpus = all_cpus;
CPU_CLR(PCPU_GET(cpuid), &ocpus);
PCPU_SET(other_cpus, ocpus);
}
void
smp_init_secondary(u_int32_t cpuid)
{
cpuset_t ocpus;
/* TLB */
mips_wr_wired(0);
tlb_invalidate_all();
@ -303,7 +316,9 @@ smp_init_secondary(u_int32_t cpuid)
CTR1(KTR_SMP, "SMP: AP CPU #%d launched", PCPU_GET(cpuid));
/* Build our map of 'other' CPUs. */
PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
ocpus = all_cpus;
CPU_CLR(PCPU_GET(cpuid), &ocpus);
PCPU_SET(other_cpus, ocpus);
if (bootverbose)
printf("SMP: AP CPU #%d launched.\n", PCPU_GET(cpuid));

View File

@ -471,7 +471,7 @@ pmap_create_kernel_pagetable(void)
PMAP_LOCK_INIT(kernel_pmap);
kernel_pmap->pm_segtab = kernel_segmap;
kernel_pmap->pm_active = ~0;
CPU_FILL(&kernel_pmap->pm_active);
TAILQ_INIT(&kernel_pmap->pm_pvlist);
kernel_pmap->pm_asid[0].asid = PMAP_ASID_RESERVED;
kernel_pmap->pm_asid[0].gen = 0;
@ -630,10 +630,14 @@ pmap_invalidate_all_local(pmap_t pmap)
tlb_invalidate_all();
return;
}
if (pmap->pm_active & PCPU_GET(cpumask))
sched_pin();
if (CPU_OVERLAP(&pmap->pm_active, PCPU_PTR(cpumask))) {
sched_unpin();
tlb_invalidate_all_user(pmap);
else
} else {
sched_unpin();
pmap->pm_asid[PCPU_GET(cpuid)].gen = 0;
}
}
#ifdef SMP
@ -667,12 +671,16 @@ pmap_invalidate_page_local(pmap_t pmap, vm_offset_t va)
tlb_invalidate_address(pmap, va);
return;
}
if (pmap->pm_asid[PCPU_GET(cpuid)].gen != PCPU_GET(asid_generation))
sched_pin();
if (pmap->pm_asid[PCPU_GET(cpuid)].gen != PCPU_GET(asid_generation)) {
sched_unpin();
return;
else if (!(pmap->pm_active & PCPU_GET(cpumask))) {
} else if (!CPU_OVERLAP(&pmap->pm_active, PCPU_PTR(cpumask))) {
pmap->pm_asid[PCPU_GET(cpuid)].gen = 0;
sched_unpin();
return;
}
sched_unpin();
tlb_invalidate_address(pmap, va);
}
@ -716,12 +724,16 @@ pmap_update_page_local(pmap_t pmap, vm_offset_t va, pt_entry_t pte)
tlb_update(pmap, va, pte);
return;
}
if (pmap->pm_asid[PCPU_GET(cpuid)].gen != PCPU_GET(asid_generation))
sched_pin();
if (pmap->pm_asid[PCPU_GET(cpuid)].gen != PCPU_GET(asid_generation)) {
sched_unpin();
return;
else if (!(pmap->pm_active & PCPU_GET(cpumask))) {
} else if (!CPU_OVERLAP(&pmap->pm_active, PCPU_PTR(cpumask))) {
pmap->pm_asid[PCPU_GET(cpuid)].gen = 0;
sched_unpin();
return;
}
sched_unpin();
tlb_update(pmap, va, pte);
}
@ -1041,7 +1053,7 @@ pmap_pinit0(pmap_t pmap)
PMAP_LOCK_INIT(pmap);
pmap->pm_segtab = kernel_segmap;
pmap->pm_active = 0;
CPU_ZERO(&pmap->pm_active);
pmap->pm_ptphint = NULL;
for (i = 0; i < MAXCPU; i++) {
pmap->pm_asid[i].asid = PMAP_ASID_RESERVED;
@ -1102,7 +1114,7 @@ pmap_pinit(pmap_t pmap)
ptdva = MIPS_PHYS_TO_DIRECT(VM_PAGE_TO_PHYS(ptdpg));
pmap->pm_segtab = (pd_entry_t *)ptdva;
pmap->pm_active = 0;
CPU_ZERO(&pmap->pm_active);
pmap->pm_ptphint = NULL;
for (i = 0; i < MAXCPU; i++) {
pmap->pm_asid[i].asid = PMAP_ASID_RESERVED;
@ -2948,8 +2960,8 @@ pmap_activate(struct thread *td)
oldpmap = PCPU_GET(curpmap);
if (oldpmap)
atomic_clear_32(&oldpmap->pm_active, PCPU_GET(cpumask));
atomic_set_32(&pmap->pm_active, PCPU_GET(cpumask));
CPU_NAND_ATOMIC(&oldpmap->pm_active, PCPU_PTR(cpumask));
CPU_OR_ATOMIC(&pmap->pm_active, PCPU_PTR(cpumask));
pmap_asid_alloc(pmap);
if (td == curthread) {
PCPU_SET(segbase, pmap->pm_segtab);
@ -3283,7 +3295,7 @@ pmap_kextract(vm_offset_t va)
pt_entry_t *ptep;
/* Is the kernel pmap initialized? */
if (kernel_pmap->pm_active) {
if (!CPU_EMPTY(&kernel_pmap->pm_active)) {
/* It's inside the virtual address range */
ptep = pmap_pte(kernel_pmap, va);
if (ptep) {

View File

@ -614,11 +614,17 @@ platform_processor_id(void)
return (xlr_hwtid_to_cpuid[xlr_cpu_id()]);
}
cpumask_t
cpuset_t
platform_cpu_mask(void)
{
cpuset_t cpumask;
int i, s;
return (~0U >> (32 - (xlr_ncores * xlr_threads_per_core)));
CPU_ZERO(&cpumask);
s = xlr_ncores * xlr_threads_per_core;
for (i = 0; i < s; i++)
CPU_SET(i, &cpumask);
return (cpumask);
}
struct cpu_group *

View File

@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/cpuset.h>
#include <machine/resource.h>
#include <machine/hwfunc.h>
@ -242,11 +243,17 @@ sb_clear_mailbox(int cpu, uint64_t val)
sb_store64(regaddr, val);
}
cpumask_t
cpuset_t
platform_cpu_mask(void)
{
cpuset_t cpumask;
int i, s;
return (~0U >> (32 - SYSREV_NUM_PROCESSORS(sb_read_sysrev())));
CPU_ZERO(&cpumask);
s = SYSREV_NUM_PROCESSORS(sb_read_sysrev());
for (i = 0; i < s; i++)
CPU_SET(i, &cpumask);
return (cpumask);
}
#endif /* SMP */