Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_pmc.c
Show All 29 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "opt_hwpmc_hooks.h" | #include "opt_hwpmc_hooks.h" | ||||
#include <sys/types.h> | #include <sys/param.h> | ||||
#include <sys/ctype.h> | #include <sys/ctype.h> | ||||
#include <sys/domainset.h> | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/pmc.h> | #include <sys/pmc.h> | ||||
#include <sys/pmckern.h> | #include <sys/pmckern.h> | ||||
#include <sys/smp.h> | #include <sys/smp.h> | ||||
▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | |||||
void | void | ||||
pmc_soft_ev_release(struct pmc_soft *ps) | pmc_soft_ev_release(struct pmc_soft *ps) | ||||
{ | { | ||||
mtx_unlock_spin(&pmc_softs_mtx); | mtx_unlock_spin(&pmc_softs_mtx); | ||||
} | } | ||||
#ifdef NUMA | |||||
#define NDOMAINS vm_ndomains | |||||
static int | |||||
getdomain(int cpu) | |||||
{ | |||||
struct pcpu *pc; | |||||
pc = pcpu_find(cpu); | |||||
return (pc->pc_domain); | |||||
} | |||||
#else | |||||
#define NDOMAINS 1 | |||||
#define malloc_domain(size, type, domain, flags) malloc((size), (type), (flags)) | |||||
#define getdomain(cpu) 0 | |||||
#endif | |||||
/* | /* | ||||
* Initialise hwpmc. | * Initialise hwpmc. | ||||
*/ | */ | ||||
static void | static void | ||||
init_hwpmc(void *dummy __unused) | init_hwpmc(void *dummy __unused) | ||||
{ | { | ||||
int domain, cpu; | int domain, cpu; | ||||
if (pmc_softevents <= 0 || | if (pmc_softevents <= 0 || | ||||
pmc_softevents > PMC_EV_DYN_COUNT) { | pmc_softevents > PMC_EV_DYN_COUNT) { | ||||
(void) printf("hwpmc: tunable \"softevents\"=%d out of " | (void) printf("hwpmc: tunable \"softevents\"=%d out of " | ||||
"range.\n", pmc_softevents); | "range.\n", pmc_softevents); | ||||
pmc_softevents = PMC_EV_DYN_COUNT; | pmc_softevents = PMC_EV_DYN_COUNT; | ||||
} | } | ||||
pmc_softs = malloc(pmc_softevents * sizeof(struct pmc_soft *), M_PMCHOOKS, M_NOWAIT|M_ZERO); | pmc_softs = malloc(pmc_softevents * sizeof(struct pmc_soft *), M_PMCHOOKS, M_NOWAIT|M_ZERO); | ||||
KASSERT(pmc_softs != NULL, ("cannot allocate soft events table")); | KASSERT(pmc_softs != NULL, ("cannot allocate soft events table")); | ||||
for (domain = 0; domain < NDOMAINS; domain++) { | for (domain = 0; domain < vm_ndomains; domain++) { | ||||
pmc_dom_hdrs[domain] = malloc_domain(sizeof(struct pmc_domain_buffer_header), M_PMC, domain, | pmc_dom_hdrs[domain] = malloc_domainset( | ||||
M_WAITOK|M_ZERO); | sizeof(struct pmc_domain_buffer_header), M_PMC, | ||||
DOMAINSET_PREF(domain), M_WAITOK | M_ZERO); | |||||
mtx_init(&pmc_dom_hdrs[domain]->pdbh_mtx, "pmc_bufferlist_mtx", "pmc-leaf", MTX_SPIN); | mtx_init(&pmc_dom_hdrs[domain]->pdbh_mtx, "pmc_bufferlist_mtx", "pmc-leaf", MTX_SPIN); | ||||
TAILQ_INIT(&pmc_dom_hdrs[domain]->pdbh_head); | TAILQ_INIT(&pmc_dom_hdrs[domain]->pdbh_head); | ||||
} | } | ||||
CPU_FOREACH(cpu) { | CPU_FOREACH(cpu) { | ||||
domain = getdomain(cpu); | domain = pcpu_find(cpu)->pc_domain; | ||||
KASSERT(pmc_dom_hdrs[domain] != NULL, ("no mem allocated for domain: %d", domain)); | KASSERT(pmc_dom_hdrs[domain] != NULL, ("no mem allocated for domain: %d", domain)); | ||||
pmc_dom_hdrs[domain]->pdbh_ncpus++; | pmc_dom_hdrs[domain]->pdbh_ncpus++; | ||||
} | } | ||||
} | } | ||||
SYSINIT(hwpmc, SI_SUB_KDTRACE, SI_ORDER_FIRST, init_hwpmc, NULL); | SYSINIT(hwpmc, SI_SUB_KDTRACE, SI_ORDER_FIRST, init_hwpmc, NULL); | ||||