Skip to content

Commit

Permalink
smp: Dynamically allocate the stoppcbs array
Browse files Browse the repository at this point in the history
This avoids bloating the kernel image when MAXCPU is large.

A follow-up patch for kgdb and other kernel debuggers is needed since
the stoppcbs symbol is now a pointer.  Bump __FreeBSD_version so that
debuggers can use osreldate to figure out how to handle stoppcbs.

PR:		269572
MFC after:	never
Reviewed by:	mjg, emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39806
  • Loading branch information
markjdb committed May 25, 2023
1 parent fed0361 commit 9fb6718
Show file tree
Hide file tree
Showing 19 changed files with 14 additions and 32 deletions.
2 changes: 0 additions & 2 deletions sys/amd64/include/kdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include <machine/frame.h>
#include <machine/psl.h>

#define KDB_STOPPEDPCB(pc) &stoppcbs[pc->pc_cpuid]

int kdb_cpu_set_watchpoint(vm_offset_t addr, vm_size_t size, int access);
int kdb_cpu_clr_watchpoint(vm_offset_t addr, vm_size_t size);

Expand Down
1 change: 0 additions & 1 deletion sys/arm/arm/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$");

/* used to hold the AP's until we are ready to release them */
struct mtx ap_boot_mtx;
struct pcb stoppcbs[MAXCPU];

/* # of Applications processors */
volatile int mp_naps;
Expand Down
2 changes: 0 additions & 2 deletions sys/arm/include/kdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <machine/frame.h>
#include <machine/psl.h>

#define KDB_STOPPEDPCB(pc) &stoppcbs[pc->pc_cpuid]

extern void kdb_cpu_clear_singlestep(void);
extern void kdb_cpu_set_singlestep(void);
boolean_t kdb_cpu_pc_is_singlestep(db_addr_t);
Expand Down
3 changes: 0 additions & 3 deletions sys/arm/include/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ void ipi_selected(cpuset_t cpus, u_int ipi);
void platform_mp_setmaxid(void);
void platform_mp_start_ap(void);

/* global data in mp_machdep.c */
extern struct pcb stoppcbs[];

#endif /* !_MACHINE_SMP_H_ */
2 changes: 0 additions & 2 deletions sys/arm64/arm64/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ static void ipi_preempt(void *);
static void ipi_rendezvous(void *);
static void ipi_stop(void *);

struct pcb stoppcbs[MAXCPU];

#ifdef FDT
static u_int fdt_cpuid;
#endif
Expand Down
3 changes: 0 additions & 3 deletions sys/arm64/include/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,4 @@ void ipi_all_but_self(u_int ipi);
void ipi_cpu(int cpu, u_int ipi);
void ipi_selected(cpuset_t cpus, u_int ipi);

/* global data in mp_machdep.c */
extern struct pcb stoppcbs[];

#endif /* !_MACHINE_SMP_H_ */
2 changes: 0 additions & 2 deletions sys/i386/include/kdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include <machine/frame.h>
#include <machine/psl.h>

#define KDB_STOPPEDPCB(pc) &stoppcbs[pc->pc_cpuid]

int kdb_cpu_set_watchpoint(vm_offset_t addr, vm_size_t size, int access);
int kdb_cpu_clr_watchpoint(vm_offset_t addr, vm_size_t size);

Expand Down
6 changes: 3 additions & 3 deletions sys/kern/subr_kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,18 +627,18 @@ kdb_reenter_silent(void)
struct pcb *
kdb_thr_ctx(struct thread *thr)
{
#if defined(SMP) && defined(KDB_STOPPEDPCB)
#ifdef SMP
struct pcpu *pc;
#endif

if (thr == curthread)
return (&kdb_pcb);

#if defined(SMP) && defined(KDB_STOPPEDPCB)
#ifdef SMP
STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
if (pc->pc_curthread == thr &&
CPU_ISSET(pc->pc_cpuid, &stopped_cpus))
return (KDB_STOPPEDPCB(pc));
return (&stoppcbs[pc->pc_cpuid]);
}
#endif
return (thr->td_pcb);
Expand Down
7 changes: 7 additions & 0 deletions sys/kern/subr_smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>

#include <machine/cpu.h>
#include <machine/pcb.h>
#include <machine/smp.h>

#include "opt_sched.h"
Expand Down Expand Up @@ -76,6 +77,9 @@ int mp_maxcpus = MAXCPU;
volatile int smp_started;
u_int mp_maxid;

/* Array of CPU contexts saved during a panic. */
struct pcb *stoppcbs;

static SYSCTL_NODE(_kern, OID_AUTO, smp,
CTLFLAG_RD | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL,
"Kernel SMP");
Expand Down Expand Up @@ -178,6 +182,9 @@ mp_start(void *dummy)
if (mp_ncores < 0)
mp_ncores = mp_ncpus;

stoppcbs = mallocarray(mp_maxid + 1, sizeof(struct pcb), M_DEVBUF,
M_WAITOK | M_ZERO);

cpu_mp_announce();
}
SYSINIT(cpu_mp, SI_SUB_CPU, SI_ORDER_THIRD, mp_start, NULL);
Expand Down
2 changes: 0 additions & 2 deletions sys/powerpc/include/kdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
void kdb_cpu_clear_singlestep(void);
void kdb_cpu_set_singlestep(void);

#define KDB_STOPPEDPCB(pc) &stoppcbs[pc->pc_cpuid]

static __inline void
kdb_cpu_sync_icache(unsigned char *addr, size_t size)
{
Expand Down
2 changes: 0 additions & 2 deletions sys/powerpc/include/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ uintptr_t cpudep_ap_bootstrap(void);
void cpudep_ap_setup(void);
void machdep_ap_bootstrap(void);

extern struct pcb stoppcbs[];

#endif /* !LOCORE */
#endif /* _KERNEL */
#endif /* !_MACHINE_SMP_H */
1 change: 0 additions & 1 deletion sys/powerpc/powerpc/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ volatile static int ap_awake;
volatile static u_int ap_letgo;
volatile static u_quad_t ap_timebase;
static struct mtx ap_boot_mtx;
struct pcb stoppcbs[MAXCPU];

void
machdep_ap_bootstrap(void)
Expand Down
2 changes: 0 additions & 2 deletions sys/riscv/include/kdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#include <machine/cpufunc.h>

#define KDB_STOPPEDPCB(pc) &stoppcbs[pc->pc_cpuid]

static __inline void
kdb_cpu_clear_singlestep(void)
{
Expand Down
2 changes: 0 additions & 2 deletions sys/riscv/include/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ void ipi_all_but_self(u_int ipi);
void ipi_cpu(int cpu, u_int ipi);
void ipi_selected(cpuset_t cpus, u_int ipi);

extern struct pcb stoppcbs[];

#endif /* !_MACHINE_SMP_H_ */
2 changes: 0 additions & 2 deletions sys/riscv/riscv/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ static device_attach_t riscv64_cpu_attach;

static int ipi_handler(void *);

struct pcb stoppcbs[MAXCPU];

extern uint32_t boot_hart;
extern cpuset_t all_harts;

Expand Down
2 changes: 1 addition & 1 deletion sys/sys/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1400088
#define __FreeBSD_version 1400089

/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
Expand Down
3 changes: 3 additions & 0 deletions sys/sys/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ extern int smp_threads_per_core;
extern cpuset_t all_cpus;
extern cpuset_t cpuset_domain[MAXMEMDOM]; /* CPUs in each NUMA domain. */

struct pcb;
extern struct pcb *stoppcbs;

/*
* Macro allowing us to determine whether a CPU is absent at any given
* time, thus permitting us to configure sparse maps of cpuid-dependent
Expand Down
1 change: 0 additions & 1 deletion sys/x86/include/x86_smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ extern unsigned int boot_address;
/* global data in mp_x86.c */
extern int mp_naps;
extern int boot_cpu_id;
extern struct pcb stoppcbs[];
extern int cpu_apic_ids[];
extern int bootAP;
extern void *dpcpu;
Expand Down
1 change: 0 additions & 1 deletion sys/x86/x86/mp_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ int bootAP;
void *bootstacks[MAXCPU];
void *dpcpu;

struct pcb stoppcbs[MAXCPU];
struct susppcb **susppcbs;

#ifdef COUNT_IPIS
Expand Down

0 comments on commit 9fb6718

Please sign in to comment.