Deleted Added
full compact
hwpmc_amd.c (177344) hwpmc_amd.c (183266)
1/*-
1/*-
2 * Copyright (c) 2003-2007 Joseph Koshy
2 * Copyright (c) 2003-2008 Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions

--- 14 unchanged lines hidden (view full) ---

25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32#include <sys/cdefs.h>
3 * Copyright (c) 2007 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions

--- 14 unchanged lines hidden (view full) ---

25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_amd.c 177344 2008-03-18 08:39:11Z adrian $");
33__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_amd.c 183266 2008-09-22 10:37:02Z jkoshy $");
34
35/* Support for the AMD K7 and later processors */
36
37#include <sys/param.h>
38#include <sys/lock.h>
39#include <sys/malloc.h>
40#include <sys/mutex.h>
41#include <sys/pmc.h>
34
35/* Support for the AMD K7 and later processors */
36
37#include <sys/param.h>
38#include <sys/lock.h>
39#include <sys/malloc.h>
40#include <sys/mutex.h>
41#include <sys/pmc.h>
42#include <sys/pmckern.h>
42#include <sys/smp.h>
43#include <sys/systm.h>
44
45#include <machine/cpu.h>
46#include <machine/cpufunc.h>
47#include <machine/md_var.h>
48#include <machine/specialreg.h>
49

--- 214 unchanged lines hidden (view full) ---

264amd_read_pmc(int cpu, int ri, pmc_value_t *v)
265{
266 enum pmc_mode mode;
267 const struct amd_descr *pd;
268 struct pmc *pm;
269 const struct pmc_hw *phw;
270 pmc_value_t tmp;
271
43#include <sys/smp.h>
44#include <sys/systm.h>
45
46#include <machine/cpu.h>
47#include <machine/cpufunc.h>
48#include <machine/md_var.h>
49#include <machine/specialreg.h>
50

--- 214 unchanged lines hidden (view full) ---

265amd_read_pmc(int cpu, int ri, pmc_value_t *v)
266{
267 enum pmc_mode mode;
268 const struct amd_descr *pd;
269 struct pmc *pm;
270 const struct pmc_hw *phw;
271 pmc_value_t tmp;
272
272 KASSERT(cpu >= 0 && cpu < mp_ncpus,
273 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
273 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
274 KASSERT(ri >= 0 && ri < AMD_NPMCS,
275 ("[amd,%d] illegal row-index %d", __LINE__, ri));
276
277 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
278 pd = &amd_pmcdesc[ri];
279 pm = phw->phw_pmc;
280

--- 41 unchanged lines hidden (view full) ---

322static int
323amd_write_pmc(int cpu, int ri, pmc_value_t v)
324{
325 const struct amd_descr *pd;
326 struct pmc *pm;
327 const struct pmc_hw *phw;
328 enum pmc_mode mode;
329
274 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
275 KASSERT(ri >= 0 && ri < AMD_NPMCS,
276 ("[amd,%d] illegal row-index %d", __LINE__, ri));
277
278 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
279 pd = &amd_pmcdesc[ri];
280 pm = phw->phw_pmc;
281

--- 41 unchanged lines hidden (view full) ---

323static int
324amd_write_pmc(int cpu, int ri, pmc_value_t v)
325{
326 const struct amd_descr *pd;
327 struct pmc *pm;
328 const struct pmc_hw *phw;
329 enum pmc_mode mode;
330
330 KASSERT(cpu >= 0 && cpu < mp_ncpus,
331 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
331 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
332 KASSERT(ri >= 0 && ri < AMD_NPMCS,
333 ("[amd,%d] illegal row-index %d", __LINE__, ri));
334
335 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
336 pd = &amd_pmcdesc[ri];
337 pm = phw->phw_pmc;
338

--- 30 unchanged lines hidden (view full) ---

369
370static int
371amd_config_pmc(int cpu, int ri, struct pmc *pm)
372{
373 struct pmc_hw *phw;
374
375 PMCDBG(MDP,CFG,1, "cpu=%d ri=%d pm=%p", cpu, ri, pm);
376
332 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
333 KASSERT(ri >= 0 && ri < AMD_NPMCS,
334 ("[amd,%d] illegal row-index %d", __LINE__, ri));
335
336 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
337 pd = &amd_pmcdesc[ri];
338 pm = phw->phw_pmc;
339

--- 30 unchanged lines hidden (view full) ---

370
371static int
372amd_config_pmc(int cpu, int ri, struct pmc *pm)
373{
374 struct pmc_hw *phw;
375
376 PMCDBG(MDP,CFG,1, "cpu=%d ri=%d pm=%p", cpu, ri, pm);
377
377 KASSERT(cpu >= 0 && cpu < mp_ncpus,
378 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
378 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
379 KASSERT(ri >= 0 && ri < AMD_NPMCS,
380 ("[amd,%d] illegal row-index %d", __LINE__, ri));
381
382 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
383
384 KASSERT(pm == NULL || phw->phw_pmc == NULL,
385 ("[amd,%d] pm=%p phw->pm=%p hwpmc not unconfigured",

--- 65 unchanged lines hidden (view full) ---

451{
452 int i;
453 uint32_t allowed_unitmask, caps, config, unitmask;
454 enum pmc_event pe;
455 const struct pmc_descr *pd;
456
457 (void) cpu;
458
379 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
380 KASSERT(ri >= 0 && ri < AMD_NPMCS,
381 ("[amd,%d] illegal row-index %d", __LINE__, ri));
382
383 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
384
385 KASSERT(pm == NULL || phw->phw_pmc == NULL,
386 ("[amd,%d] pm=%p phw->pm=%p hwpmc not unconfigured",

--- 65 unchanged lines hidden (view full) ---

452{
453 int i;
454 uint32_t allowed_unitmask, caps, config, unitmask;
455 enum pmc_event pe;
456 const struct pmc_descr *pd;
457
458 (void) cpu;
459
459 KASSERT(cpu >= 0 && cpu < mp_ncpus,
460 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
460 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
461 KASSERT(ri >= 0 && ri < AMD_NPMCS,
462 ("[amd,%d] illegal row index %d", __LINE__, ri));
463
464 pd = &amd_pmcdesc[ri].pm_descr;
465
466 /* check class match */
467 if (pd->pd_class != a->pm_class)

--- 77 unchanged lines hidden (view full) ---

545{
546#ifdef DEBUG
547 const struct amd_descr *pd;
548#endif
549 struct pmc_hw *phw;
550
551 (void) pmc;
552
461 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
462 KASSERT(ri >= 0 && ri < AMD_NPMCS,
463 ("[amd,%d] illegal row index %d", __LINE__, ri));
464
465 pd = &amd_pmcdesc[ri].pm_descr;
466
467 /* check class match */
468 if (pd->pd_class != a->pm_class)

--- 77 unchanged lines hidden (view full) ---

546{
547#ifdef DEBUG
548 const struct amd_descr *pd;
549#endif
550 struct pmc_hw *phw;
551
552 (void) pmc;
553
553 KASSERT(cpu >= 0 && cpu < mp_ncpus,
554 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
554 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
555 KASSERT(ri >= 0 && ri < AMD_NPMCS,
556 ("[amd,%d] illegal row-index %d", __LINE__, ri));
557
558 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
559
560 KASSERT(phw->phw_pmc == NULL,
561 ("[amd,%d] PHW pmc %p non-NULL", __LINE__, phw->phw_pmc));

--- 15 unchanged lines hidden (view full) ---

577static int
578amd_start_pmc(int cpu, int ri)
579{
580 uint32_t config;
581 struct pmc *pm;
582 struct pmc_hw *phw;
583 const struct amd_descr *pd;
584
555 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
556 KASSERT(ri >= 0 && ri < AMD_NPMCS,
557 ("[amd,%d] illegal row-index %d", __LINE__, ri));
558
559 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
560
561 KASSERT(phw->phw_pmc == NULL,
562 ("[amd,%d] PHW pmc %p non-NULL", __LINE__, phw->phw_pmc));

--- 15 unchanged lines hidden (view full) ---

578static int
579amd_start_pmc(int cpu, int ri)
580{
581 uint32_t config;
582 struct pmc *pm;
583 struct pmc_hw *phw;
584 const struct amd_descr *pd;
585
585 KASSERT(cpu >= 0 && cpu < mp_ncpus,
586 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
586 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
587 KASSERT(ri >= 0 && ri < AMD_NPMCS,
588 ("[amd,%d] illegal row-index %d", __LINE__, ri));
589
590 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
591 pm = phw->phw_pmc;
592 pd = &amd_pmcdesc[ri];
593

--- 32 unchanged lines hidden (view full) ---

626static int
627amd_stop_pmc(int cpu, int ri)
628{
629 struct pmc *pm;
630 struct pmc_hw *phw;
631 const struct amd_descr *pd;
632 uint64_t config;
633
587 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
588 KASSERT(ri >= 0 && ri < AMD_NPMCS,
589 ("[amd,%d] illegal row-index %d", __LINE__, ri));
590
591 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
592 pm = phw->phw_pmc;
593 pd = &amd_pmcdesc[ri];
594

--- 32 unchanged lines hidden (view full) ---

627static int
628amd_stop_pmc(int cpu, int ri)
629{
630 struct pmc *pm;
631 struct pmc_hw *phw;
632 const struct amd_descr *pd;
633 uint64_t config;
634
634 KASSERT(cpu >= 0 && cpu < mp_ncpus,
635 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
635 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
636 KASSERT(ri >= 0 && ri < AMD_NPMCS,
637 ("[amd,%d] illegal row-index %d", __LINE__, ri));
638
639 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
640 pm = phw->phw_pmc;
641 pd = &amd_pmcdesc[ri];
642

--- 35 unchanged lines hidden (view full) ---

678{
679 int i, error, retval, ri;
680 uint32_t config, evsel, perfctr;
681 struct pmc *pm;
682 struct pmc_cpu *pc;
683 struct pmc_hw *phw;
684 pmc_value_t v;
685
636 ("[amd,%d] illegal CPU value %d", __LINE__, cpu));
637 KASSERT(ri >= 0 && ri < AMD_NPMCS,
638 ("[amd,%d] illegal row-index %d", __LINE__, ri));
639
640 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
641 pm = phw->phw_pmc;
642 pd = &amd_pmcdesc[ri];
643

--- 35 unchanged lines hidden (view full) ---

679{
680 int i, error, retval, ri;
681 uint32_t config, evsel, perfctr;
682 struct pmc *pm;
683 struct pmc_cpu *pc;
684 struct pmc_hw *phw;
685 pmc_value_t v;
686
686 KASSERT(cpu >= 0 && cpu < mp_ncpus,
687 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
687 ("[amd,%d] out of range CPU %d", __LINE__, cpu));
688
689 PMCDBG(MDP,INT,1, "cpu=%d tf=%p um=%d", cpu, (void *) tf,
690 TRAPF_USERMODE(tf));
691
692 retval = 0;
693
694 pc = pmc_pcpu[cpu];

--- 63 unchanged lines hidden (view full) ---

758static int
759amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
760{
761 int error;
762 size_t copied;
763 const struct amd_descr *pd;
764 struct pmc_hw *phw;
765
688 ("[amd,%d] out of range CPU %d", __LINE__, cpu));
689
690 PMCDBG(MDP,INT,1, "cpu=%d tf=%p um=%d", cpu, (void *) tf,
691 TRAPF_USERMODE(tf));
692
693 retval = 0;
694
695 pc = pmc_pcpu[cpu];

--- 63 unchanged lines hidden (view full) ---

759static int
760amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
761{
762 int error;
763 size_t copied;
764 const struct amd_descr *pd;
765 struct pmc_hw *phw;
766
766 KASSERT(cpu >= 0 && cpu < mp_ncpus,
767 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
767 ("[amd,%d] illegal CPU %d", __LINE__, cpu));
768 KASSERT(ri >= 0 && ri < AMD_NPMCS,
769 ("[amd,%d] row-index %d out of range", __LINE__, ri));
770
771 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
772 pd = &amd_pmcdesc[ri];
773
774 if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,

--- 52 unchanged lines hidden (view full) ---

827
828static int
829amd_init(int cpu)
830{
831 int n;
832 struct amd_cpu *pcs;
833 struct pmc_hw *phw;
834
768 ("[amd,%d] illegal CPU %d", __LINE__, cpu));
769 KASSERT(ri >= 0 && ri < AMD_NPMCS,
770 ("[amd,%d] row-index %d out of range", __LINE__, ri));
771
772 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
773 pd = &amd_pmcdesc[ri];
774
775 if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,

--- 52 unchanged lines hidden (view full) ---

828
829static int
830amd_init(int cpu)
831{
832 int n;
833 struct amd_cpu *pcs;
834 struct pmc_hw *phw;
835
835 KASSERT(cpu >= 0 && cpu < mp_ncpus,
836 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
836 ("[amd,%d] insane cpu number %d", __LINE__, cpu));
837
838 PMCDBG(MDP,INI,1,"amd-init cpu=%d", cpu);
839
840 MALLOC(pcs, struct amd_cpu *, sizeof(struct amd_cpu), M_PMC,
841 M_WAITOK|M_ZERO);
842
843 phw = &pcs->pc_amdpmcs[0];

--- 26 unchanged lines hidden (view full) ---

870
871static int
872amd_cleanup(int cpu)
873{
874 int i;
875 uint32_t evsel;
876 struct pmc_cpu *pcs;
877
837 ("[amd,%d] insane cpu number %d", __LINE__, cpu));
838
839 PMCDBG(MDP,INI,1,"amd-init cpu=%d", cpu);
840
841 MALLOC(pcs, struct amd_cpu *, sizeof(struct amd_cpu), M_PMC,
842 M_WAITOK|M_ZERO);
843
844 phw = &pcs->pc_amdpmcs[0];

--- 26 unchanged lines hidden (view full) ---

871
872static int
873amd_cleanup(int cpu)
874{
875 int i;
876 uint32_t evsel;
877 struct pmc_cpu *pcs;
878
878 KASSERT(cpu >= 0 && cpu < mp_ncpus,
879 KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
879 ("[amd,%d] insane cpu number (%d)", __LINE__, cpu));
880
881 PMCDBG(MDP,INI,1,"amd-cleanup cpu=%d", cpu);
882
883 /*
884 * First, turn off all PMCs on this CPU.
885 */
886

--- 125 unchanged lines hidden ---
880 ("[amd,%d] insane cpu number (%d)", __LINE__, cpu));
881
882 PMCDBG(MDP,INI,1,"amd-cleanup cpu=%d", cpu);
883
884 /*
885 * First, turn off all PMCs on this CPU.
886 */
887

--- 125 unchanged lines hidden ---