diff options
-rw-r--r-- | sys/dev/hwpmc/hwpmc_amd.c | 25 | ||||
-rw-r--r-- | sys/dev/hwpmc/hwpmc_mod.c | 81 | ||||
-rw-r--r-- | sys/dev/hwpmc/hwpmc_piv.c | 26 | ||||
-rw-r--r-- | sys/dev/hwpmc/hwpmc_ppro.c | 16 | ||||
-rw-r--r-- | sys/kern/kern_pmc.c | 91 | ||||
-rw-r--r-- | sys/sys/pmckern.h | 15 |
6 files changed, 173 insertions, 81 deletions
diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c index 8f8641e..4477173 100644 --- a/sys/dev/hwpmc/hwpmc_amd.c +++ b/sys/dev/hwpmc/hwpmc_amd.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Joseph Koshy + * Copyright (c) 2003-2008 Joseph Koshy * Copyright (c) 2007 The FreeBSD Foundation * All rights reserved. * @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/mutex.h> #include <sys/pmc.h> +#include <sys/pmckern.h> #include <sys/smp.h> #include <sys/systm.h> @@ -269,7 +270,7 @@ amd_read_pmc(int cpu, int ri, pmc_value_t *v) const struct pmc_hw *phw; pmc_value_t tmp; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -327,7 +328,7 @@ amd_write_pmc(int cpu, int ri, pmc_value_t v) const struct pmc_hw *phw; enum pmc_mode mode; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -374,7 +375,7 @@ amd_config_pmc(int cpu, int ri, struct pmc *pm) PMCDBG(MDP,CFG,1, "cpu=%d ri=%d pm=%p", cpu, ri, pm); - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -456,7 +457,7 @@ amd_allocate_pmc(int cpu, int ri, struct pmc *pm, (void) cpu; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row index %d", __LINE__, ri)); @@ -550,7 +551,7 @@ amd_release_pmc(int cpu, int ri, struct pmc *pmc) (void) pmc; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -582,7 +583,7 @@ amd_start_pmc(int cpu, int ri) struct pmc_hw *phw; const struct amd_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -631,7 +632,7 @@ amd_stop_pmc(int cpu, int ri) const struct amd_descr *pd; uint64_t config; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -683,7 +684,7 @@ amd_intr(int cpu, struct trapframe *tf) struct pmc_hw *phw; pmc_value_t v; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] out of range CPU %d", __LINE__, cpu)); PMCDBG(MDP,INT,1, "cpu=%d tf=%p um=%d", cpu, (void *) tf, @@ -763,7 +764,7 @@ amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc) const struct amd_descr *pd; struct pmc_hw *phw; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] row-index %d out of range", __LINE__, ri)); @@ -832,7 +833,7 @@ amd_init(int cpu) struct amd_cpu *pcs; struct pmc_hw *phw; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] insane cpu number %d", __LINE__, cpu)); PMCDBG(MDP,INI,1,"amd-init cpu=%d", cpu); @@ -875,7 +876,7 @@ amd_cleanup(int cpu) uint32_t evsel; struct pmc_cpu *pcs; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] insane cpu number (%d)", __LINE__, cpu)); PMCDBG(MDP,INI,1,"amd-cleanup cpu=%d", cpu); diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index 62a1c8f..dbf732b 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Joseph Koshy + * Copyright (c) 2003-2008 Joseph Koshy * Copyright (c) 2007 The FreeBSD Foundation * All rights reserved. * @@ -98,8 +98,8 @@ static int *pmc_pmcdisp; /* PMC row dispositions */ KASSERT(pmc_pmcdisp[(R)] <= 0, ("[pmc,%d] row disposition error", \ __LINE__)); \ atomic_add_int(&pmc_pmcdisp[(R)], -1); \ - KASSERT(pmc_pmcdisp[(R)] >= (-mp_ncpus), ("[pmc,%d] row " \ - "disposition error", __LINE__)); \ + KASSERT(pmc_pmcdisp[(R)] >= (-pmc_cpu_max_active()), \ + ("[pmc,%d] row disposition error", __LINE__)); \ } while (0) #define PMC_UNMARK_ROW_STANDALONE(R) do { \ @@ -637,12 +637,12 @@ pmc_restore_cpu_binding(struct pmc_binding *pb) static void pmc_select_cpu(int cpu) { - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[pmc,%d] bad cpu number %d", __LINE__, cpu)); - /* never move to a disabled CPU */ - KASSERT(pmc_cpu_is_disabled(cpu) == 0, ("[pmc,%d] selecting " - "disabled CPU %d", __LINE__, cpu)); + /* Never move to an inactive CPU. */ + KASSERT(pmc_cpu_is_active(cpu), ("[pmc,%d] selecting inactive " + "CPU %d", __LINE__, cpu)); PMCDBG(CPU,SEL,2, "select-cpu cpu=%d", cpu); thread_lock(curthread); @@ -1186,7 +1186,7 @@ pmc_process_csw_in(struct thread *td) PMCDBG(CSW,SWI,1, "cpu=%d proc=%p (%d, %s) pp=%p", cpu, p, p->p_pid, p->p_comm, pp); - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[pmc,%d] wierd CPU id %d", __LINE__, cpu)); pc = pmc_pcpu[cpu]; @@ -1311,7 +1311,7 @@ pmc_process_csw_out(struct thread *td) PMCDBG(CSW,SWO,1, "cpu=%d proc=%p (%d, %s) pp=%p", cpu, p, p->p_pid, p->p_comm, pp); - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[pmc,%d wierd CPU id %d", __LINE__, cpu)); pc = pmc_pcpu[cpu]; @@ -2038,7 +2038,7 @@ pmc_wait_for_pmc_idle(struct pmc *pm) #ifdef DEBUG volatile int maxloop; - maxloop = 100 * mp_ncpus; + maxloop = 100 * pmc_cpu_max(); #endif /* @@ -2499,7 +2499,7 @@ pmc_start(struct pmc *pm) cpu = PMC_TO_CPU(pm); - if (pmc_cpu_is_disabled(cpu)) + if (!pmc_cpu_is_active(cpu)) return ENXIO; pmc_select_cpu(cpu); @@ -2566,10 +2566,10 @@ pmc_stop(struct pmc *pm) cpu = PMC_TO_CPU(pm); - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[pmc,%d] illegal cpu=%d", __LINE__, cpu)); - if (pmc_cpu_is_disabled(cpu)) + if (!pmc_cpu_is_active(cpu)) return ENXIO; pmc_select_cpu(cpu); @@ -2734,7 +2734,7 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) struct pmc_op_getcpuinfo gci; gci.pm_cputype = md->pmd_cputype; - gci.pm_ncpu = mp_ncpus; + gci.pm_ncpu = pmc_cpu_max(); gci.pm_npmc = md->pmd_npmc; gci.pm_nclass = md->pmd_nclass; bcopy(md->pmd_classes, &gci.pm_classes, @@ -2802,12 +2802,12 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) if ((error = copyin(&gpi->pm_cpu, &cpu, sizeof(cpu))) != 0) break; - if (cpu >= (unsigned int) mp_ncpus) { + if (cpu >= pmc_cpu_max()) { error = EINVAL; break; } - if (pmc_cpu_is_disabled(cpu)) { + if (!pmc_cpu_is_active(cpu)) { error = ENXIO; break; } @@ -2896,12 +2896,12 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) cpu = pma.pm_cpu; - if (cpu < 0 || cpu >= mp_ncpus) { + if (cpu < 0 || cpu >= (int) pmc_cpu_max()) { error = EINVAL; break; } - if (pmc_cpu_is_disabled(cpu)) { + if (!pmc_cpu_is_active(cpu)) { error = ENXIO; break; } @@ -2989,7 +2989,7 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) if ((mode != PMC_MODE_SS && mode != PMC_MODE_SC && mode != PMC_MODE_TS && mode != PMC_MODE_TC) || - (cpu != (u_int) PMC_CPU_ANY && cpu >= (u_int) mp_ncpus)) { + (cpu != (u_int) PMC_CPU_ANY && cpu >= pmc_cpu_max())) { error = EINVAL; break; } @@ -3006,10 +3006,10 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) } /* - * Check that a disabled CPU is not being asked for. + * Check that an inactive CPU is not being asked for. */ - if (PMC_IS_SYSTEM_MODE(mode) && pmc_cpu_is_disabled(cpu)) { + if (PMC_IS_SYSTEM_MODE(mode) && !pmc_cpu_is_active(cpu)) { error = ENXIO; break; } @@ -3522,7 +3522,7 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) cpu = PMC_TO_CPU(pm); ri = PMC_TO_ROWINDEX(pm); - if (pmc_cpu_is_disabled(cpu)) { + if (!pmc_cpu_is_active(cpu)) { error = ENXIO; break; } @@ -4292,6 +4292,7 @@ static int pmc_initialize(void) { int cpu, error, n; + unsigned int maxcpu; struct pmc_binding pb; struct pmc_sample *ps; struct pmc_samplebuffer *sb; @@ -4349,18 +4350,20 @@ pmc_initialize(void) if (md == NULL || md->pmd_init == NULL) return ENOSYS; + maxcpu = pmc_cpu_max(); + /* allocate space for the per-cpu array */ - MALLOC(pmc_pcpu, struct pmc_cpu **, mp_ncpus * sizeof(struct pmc_cpu *), + MALLOC(pmc_pcpu, struct pmc_cpu **, maxcpu * sizeof(struct pmc_cpu *), M_PMC, M_WAITOK|M_ZERO); /* per-cpu 'saved values' for managing process-mode PMCs */ MALLOC(pmc_pcpu_saved, pmc_value_t *, - sizeof(pmc_value_t) * mp_ncpus * md->pmd_npmc, M_PMC, M_WAITOK); + sizeof(pmc_value_t) * maxcpu * md->pmd_npmc, M_PMC, M_WAITOK); - /* perform cpu dependent initialization */ + /* Perform CPU-dependent initialization. */ pmc_save_cpu_binding(&pb); - for (cpu = 0; cpu < mp_ncpus; cpu++) { - if (pmc_cpu_is_disabled(cpu)) + for (cpu = 0; cpu < maxcpu; cpu++) { + if (!pmc_cpu_is_active(cpu)) continue; pmc_select_cpu(cpu); if ((error = md->pmd_init(cpu)) != 0) @@ -4372,8 +4375,8 @@ pmc_initialize(void) return error; /* allocate space for the sample array */ - for (cpu = 0; cpu < mp_ncpus; cpu++) { - if (pmc_cpu_is_disabled(cpu)) + for (cpu = 0; cpu < maxcpu; cpu++) { + if (!pmc_cpu_is_active(cpu)) continue; MALLOC(sb, struct pmc_samplebuffer *, sizeof(struct pmc_samplebuffer) + @@ -4463,6 +4466,7 @@ static void pmc_cleanup(void) { int cpu; + unsigned int maxcpu; struct pmc_ownerhash *ph; struct pmc_owner *po, *tmp; struct pmc_binding pb; @@ -4542,9 +4546,10 @@ pmc_cleanup(void) KASSERT(pmc_ss_count == 0, ("[pmc,%d] Global SS count not empty", __LINE__)); - /* free the per-cpu sample buffers */ - for (cpu = 0; cpu < mp_ncpus; cpu++) { - if (pmc_cpu_is_disabled(cpu)) + /* Free the per-cpu sample buffers. */ + maxcpu = pmc_cpu_max(); + for (cpu = 0; cpu < maxcpu; cpu++) { + if (!pmc_cpu_is_active(cpu)) continue; KASSERT(pmc_pcpu[cpu]->pc_sb != NULL, ("[pmc,%d] Null cpu sample buffer cpu=%d", __LINE__, @@ -4558,14 +4563,14 @@ pmc_cleanup(void) PMCDBG(MOD,INI,3, "%s", "md cleanup"); if (md) { pmc_save_cpu_binding(&pb); - for (cpu = 0; cpu < mp_ncpus; cpu++) { + for (cpu = 0; cpu < maxcpu; cpu++) { PMCDBG(MOD,INI,1,"pmc-cleanup cpu=%d pcs=%p", cpu, pmc_pcpu[cpu]); - if (pmc_cpu_is_disabled(cpu)) + if (!pmc_cpu_is_active(cpu) || pmc_pcpu[cpu] == NULL) continue; pmc_select_cpu(cpu); - if (pmc_pcpu[cpu]) - (void) md->pmd_cleanup(cpu); + if (md->pmd_cleanup) + md->pmd_cleanup(cpu); } FREE(md, M_PMC); md = NULL; @@ -4606,8 +4611,8 @@ load (struct module *module __unused, int cmd, void *arg __unused) error = pmc_initialize(); if (error != 0) break; - PMCDBG(MOD,INI,1, "syscall=%d ncpus=%d", - pmc_syscall_num, mp_ncpus); + PMCDBG(MOD,INI,1, "syscall=%d maxcpu=%d", + pmc_syscall_num, pmc_cpu_max()); break; diff --git a/sys/dev/hwpmc/hwpmc_piv.c b/sys/dev/hwpmc/hwpmc_piv.c index 7994330..5a22cc9 100644 --- a/sys/dev/hwpmc/hwpmc_piv.c +++ b/sys/dev/hwpmc/hwpmc_piv.c @@ -532,8 +532,8 @@ static int p4_escrdisp[P4_NESCR]; KASSERT(p4_escrdisp[(E)] <= 0, ("[p4,%d] row disposition error",\ __LINE__)); \ atomic_add_int(&p4_escrdisp[(E)], -1); \ - KASSERT(p4_escrdisp[(E)] >= (-mp_ncpus), ("[p4,%d] row " \ - "disposition error", __LINE__)); \ + KASSERT(p4_escrdisp[(E)] >= (-pmc_cpu_max_active()), \ + ("[p4,%d] row disposition error", __LINE__)); \ } while (0) #define P4_ESCR_UNMARK_ROW_STANDALONE(E) do { \ @@ -596,11 +596,11 @@ p4_init(int cpu) struct p4_logicalcpu *plcs; struct pmc_hw *phw; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] insane cpu number %d", __LINE__, cpu)); - PMCDBG(MDP,INI,0, "p4-init cpu=%d logical=%d", cpu, - pmc_cpu_is_logical(cpu) != 0); + PMCDBG(MDP,INI,0, "p4-init cpu=%d is-primary=%d", cpu, + pmc_cpu_is_primary(cpu) != 0); /* * The two CPUs in an HT pair share their per-cpu state. @@ -614,7 +614,7 @@ p4_init(int cpu) * secondary. */ - if (pmc_cpu_is_logical(cpu) && (cpu & 1)) { + if (!pmc_cpu_is_primary(cpu) && (cpu & 1)) { p4_system_has_htt = 1; @@ -761,7 +761,7 @@ p4_read_pmc(int cpu, int ri, pmc_value_t *v) struct pmc_hw *phw; pmc_value_t tmp; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[p4,%d] illegal row-index %d", __LINE__, ri)); @@ -839,7 +839,7 @@ p4_write_pmc(int cpu, int ri, pmc_value_t v) const struct pmc_hw *phw; const struct p4pmc_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); @@ -913,7 +913,7 @@ p4_config_pmc(int cpu, int ri, struct pmc *pm) struct p4_cpu *pc; int cfgflags, cpuflag; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[p4,%d] illegal row-index %d", __LINE__, ri)); @@ -1050,7 +1050,7 @@ p4_allocate_pmc(int cpu, int ri, struct pmc *pm, struct p4_event_descr *pevent; const struct p4pmc_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[p4,%d] illegal row-index value %d", __LINE__, ri)); @@ -1297,7 +1297,7 @@ p4_start_pmc(int cpu, int ri) struct pmc_hw *phw; struct p4pmc_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[p4,%d] illegal row-index %d", __LINE__, ri)); @@ -1449,7 +1449,7 @@ p4_stop_pmc(int cpu, int ri) struct p4pmc_descr *pd; pmc_value_t tmp; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[p4,%d] illegal row index %d", __LINE__, ri)); @@ -1722,7 +1722,7 @@ p4_describe(int cpu, int ri, struct pmc_info *pi, struct pmc_hw *phw; const struct p4pmc_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P4_NPMCS, ("[p4,%d] row-index %d out of range", __LINE__, ri)); diff --git a/sys/dev/hwpmc/hwpmc_ppro.c b/sys/dev/hwpmc/hwpmc_ppro.c index 979c04e..1107c59 100644 --- a/sys/dev/hwpmc/hwpmc_ppro.c +++ b/sys/dev/hwpmc/hwpmc_ppro.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2005 Joseph Koshy + * Copyright (c) 2003-2005,2008 Joseph Koshy * Copyright (c) 2007 The FreeBSD Foundation * All rights reserved. * @@ -336,7 +336,7 @@ p6_init(int cpu) struct p6_cpu *pcs; struct pmc_hw *phw; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p6,%d] bad cpu %d", __LINE__, cpu)); PMCDBG(MDP,INI,0,"p6-init cpu=%d", cpu); @@ -366,7 +366,7 @@ p6_cleanup(int cpu) { struct pmc_cpu *pcs; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p6,%d] bad cpu %d", __LINE__, cpu)); PMCDBG(MDP,INI,0,"p6-cleanup cpu=%d", cpu); @@ -512,7 +512,7 @@ p6_allocate_pmc(int cpu, int ri, struct pmc *pm, (void) cpu; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p4,%d] illegal CPU %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P6_NPMCS, ("[p4,%d] illegal row-index value %d", __LINE__, ri)); @@ -616,7 +616,7 @@ p6_release_pmc(int cpu, int ri, struct pmc *pm) PMCDBG(MDP,REL,1, "p6-release cpu=%d ri=%d pm=%p", cpu, ri, pm); - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p6,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P6_NPMCS, ("[p6,%d] illegal row-index %d", __LINE__, ri)); @@ -638,7 +638,7 @@ p6_start_pmc(int cpu, int ri) struct pmc_hw *phw; const struct p6pmc_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p6,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P6_NPMCS, ("[p6,%d] illegal row-index %d", __LINE__, ri)); @@ -682,7 +682,7 @@ p6_stop_pmc(int cpu, int ri) struct pmc_hw *phw; struct p6pmc_descr *pd; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p6,%d] illegal cpu value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < P6_NPMCS, ("[p6,%d] illegal row index %d", __LINE__, ri)); @@ -724,7 +724,7 @@ p6_intr(int cpu, struct trapframe *tf) struct pmc_hw *phw; pmc_value_t v; - KASSERT(cpu >= 0 && cpu < mp_ncpus, + KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[p6,%d] CPU %d out of range", __LINE__, cpu)); retval = 0; diff --git a/sys/kern/kern_pmc.c b/sys/kern/kern_pmc.c index da331ca..4e3fe75 100644 --- a/sys/kern/kern_pmc.c +++ b/sys/kern/kern_pmc.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Joseph Koshy + * Copyright (c) 2003-2008 Joseph Koshy * Copyright (c) 2007 The FreeBSD Foundation * All rights reserved. * @@ -81,25 +81,102 @@ pmc_init_sx(void) SYSINIT(pmcsx, SI_SUB_LOCK, SI_ORDER_MIDDLE, pmc_init_sx, NULL); /* - * Helper functions + * Helper functions. + */ + +/* + * A note on the CPU numbering scheme used by the hwpmc(4) driver. + * + * CPUs are denoted using numbers in the range 0..[pmc_cpu_max()-1]. + * CPUs could be numbered "sparsely" in this range; the predicate + * `pmc_cpu_is_present()' is used to test whether a given CPU is + * physically present. + * + * Further, a CPU that is physically present may be administratively + * disabled or otherwise unavailable for use by hwpmc(4). The + * `pmc_cpu_is_active()' predicate tests for CPU usability. An + * "active" CPU participates in thread scheduling and can field + * interrupts raised by PMC hardware. + * + * On systems with hyperthreaded CPUs, multiple logical CPUs may share + * PMC hardware resources. For such processors one logical CPU is + * denoted as the primary owner of the in-CPU PMC resources. The + * pmc_cpu_is_primary() predicate is used to distinguish this primary + * CPU from the others. */ int +pmc_cpu_is_active(int cpu) +{ +#ifdef SMP + return (pmc_cpu_is_present(cpu) && + (hlt_cpus_mask & (1 << cpu)) == 0); +#else + return (1); +#endif +} + +/* Deprecated. */ +int pmc_cpu_is_disabled(int cpu) { + return (!pmc_cpu_is_active(cpu)); +} + +int +pmc_cpu_is_present(int cpu) +{ +#ifdef SMP + return (!CPU_ABSENT(cpu)); +#else + return (1); +#endif +} + +int +pmc_cpu_is_primary(int cpu) +{ #ifdef SMP - return ((hlt_cpus_mask & (1 << cpu)) != 0); + return ((logical_cpus_mask & (1 << cpu)) == 0); #else - return 0; + return (1); #endif } + +/* + * Return the maximum CPU number supported by the system. The return + * value is used for scaling internal data structures and for runtime + * checks. + */ +unsigned int +pmc_cpu_max(void) +{ +#ifdef SMP + return (mp_maxid+1); +#else + return (1); +#endif +} + +#ifdef INVARIANTS + +/* + * Return the count of CPUs in the `active' state in the system. + */ int -pmc_cpu_is_logical(int cpu) +pmc_cpu_max_active(void) { #ifdef SMP - return ((logical_cpus_mask & (1 << cpu)) != 0); + /* + * When support for CPU hot-plugging is added to the kernel, + * this function would change to return the current number + * of "active" CPUs. + */ + return (mp_ncpus); #else - return 0; + return (1); #endif } + +#endif diff --git a/sys/sys/pmckern.h b/sys/sys/pmckern.h index 50911b2..3e8c1ef 100644 --- a/sys/sys/pmckern.h +++ b/sys/sys/pmckern.h @@ -124,8 +124,17 @@ do { \ /* Check if a CPU has recorded samples. */ #define PMC_CPU_HAS_SAMPLES(C) (__predict_false(pmc_cpumask & (1 << (C)))) -/* helper functions */ -int pmc_cpu_is_disabled(int _cpu); -int pmc_cpu_is_logical(int _cpu); +/* + * Helper functions. + */ +int pmc_cpu_is_disabled(int _cpu); /* deprecated */ +int pmc_cpu_is_active(int _cpu); +int pmc_cpu_is_present(int _cpu); +int pmc_cpu_is_primary(int _cpu); +unsigned int pmc_cpu_max(void); + +#ifdef INVARIANTS +int pmc_cpu_max_active(void); +#endif #endif /* _SYS_PMCKERN_H_ */ |