Deleted Added
full compact
hwpmc_amd.c (149527) hwpmc_amd.c (150050)
1/*-
2 * Copyright (c) 2003-2005 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003-2005 Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_amd.c 149527 2005-08-27 16:07:12Z jkoshy $");
29__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_amd.c 150050 2005-09-12 15:55:44Z jkoshy $");
30
31/* Support for the AMD K7 and later processors */
32
33#include <sys/param.h>
34#include <sys/lock.h>
35#include <sys/malloc.h>
36#include <sys/mutex.h>
37#include <sys/pmc.h>

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

688
689 /*
690 * look for all PMCs that have interrupted:
691 * - skip over the TSC [PMC#0]
692 * - look for a running, sampling PMC which has overflowed
693 * and which has a valid 'struct pmc' association
694 *
695 * If found, we call a helper to process the interrupt.
30
31/* Support for the AMD K7 and later processors */
32
33#include <sys/param.h>
34#include <sys/lock.h>
35#include <sys/malloc.h>
36#include <sys/mutex.h>
37#include <sys/pmc.h>

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

688
689 /*
690 * look for all PMCs that have interrupted:
691 * - skip over the TSC [PMC#0]
692 * - look for a running, sampling PMC which has overflowed
693 * and which has a valid 'struct pmc' association
694 *
695 * If found, we call a helper to process the interrupt.
696 *
697 * If multiple PMCs interrupt at the same time, the AMD64
698 * processor appears to deliver as many NMIs as there are
699 * outstanding PMC interrupts. Thus we need to only process
700 * one interrupt at a time.
696 */
697
701 */
702
698 for (i = 0; i < AMD_NPMCS-1; i++) {
703 for (i = 0; retval == 0 && i < AMD_NPMCS-1; i++) {
699
700 ri = i + 1; /* row index; TSC is at ri == 0 */
701
702 if (!AMD_PMC_HAS_OVERFLOWED(i))
703 continue;
704
705 phw = pc->pc_hwpmcs[ri];
706
707 KASSERT(phw != NULL, ("[amd,%d] null PHW pointer", __LINE__));
708
709 if ((pm = phw->phw_pmc) == NULL ||
710 pm->pm_state != PMC_STATE_RUNNING ||
711 !PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) {
712 continue;
713 }
714
704
705 ri = i + 1; /* row index; TSC is at ri == 0 */
706
707 if (!AMD_PMC_HAS_OVERFLOWED(i))
708 continue;
709
710 phw = pc->pc_hwpmcs[ri];
711
712 KASSERT(phw != NULL, ("[amd,%d] null PHW pointer", __LINE__));
713
714 if ((pm = phw->phw_pmc) == NULL ||
715 pm->pm_state != PMC_STATE_RUNNING ||
716 !PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) {
717 continue;
718 }
719
720 retval = 1; /* found an interrupting PMC */
721
715 /* stop the PMC, reload count */
716 evsel = AMD_PMC_EVSEL_0 + i;
717 perfctr = AMD_PMC_PERFCTR_0 + i;
718 v = pm->pm_sc.pm_reloadcount;
719 config = rdmsr(evsel);
720
721 KASSERT((config & ~AMD_PMC_ENABLE) ==
722 (pm->pm_md.pm_amd.pm_amd_evsel & ~AMD_PMC_ENABLE),
723 ("[amd,%d] config mismatch reg=0x%x pm=0x%x", __LINE__,
724 config, pm->pm_md.pm_amd.pm_amd_evsel));
725
726 wrmsr(evsel, config & ~AMD_PMC_ENABLE);
727 wrmsr(perfctr, AMD_RELOAD_COUNT_TO_PERFCTR_VALUE(v));
728
722 /* stop the PMC, reload count */
723 evsel = AMD_PMC_EVSEL_0 + i;
724 perfctr = AMD_PMC_PERFCTR_0 + i;
725 v = pm->pm_sc.pm_reloadcount;
726 config = rdmsr(evsel);
727
728 KASSERT((config & ~AMD_PMC_ENABLE) ==
729 (pm->pm_md.pm_amd.pm_amd_evsel & ~AMD_PMC_ENABLE),
730 ("[amd,%d] config mismatch reg=0x%x pm=0x%x", __LINE__,
731 config, pm->pm_md.pm_amd.pm_amd_evsel));
732
733 wrmsr(evsel, config & ~AMD_PMC_ENABLE);
734 wrmsr(perfctr, AMD_RELOAD_COUNT_TO_PERFCTR_VALUE(v));
735
729 /* restart if there was no error during logging */
736 /* restart the counter if there was no error during logging */
730 error = pmc_process_interrupt(cpu, pm, eip, usermode);
731 if (error == 0)
732 wrmsr(evsel, config | AMD_PMC_ENABLE);
737 error = pmc_process_interrupt(cpu, pm, eip, usermode);
738 if (error == 0)
739 wrmsr(evsel, config | AMD_PMC_ENABLE);
733
734 retval = 1; /* found an interrupting PMC */
735 }
736
737 atomic_add_int(retval ? &pmc_stats.pm_intr_processed :
738 &pmc_stats.pm_intr_ignored, 1);
739
740 return retval;
741}
742

--- 257 unchanged lines hidden ---
740 }
741
742 atomic_add_int(retval ? &pmc_stats.pm_intr_processed :
743 &pmc_stats.pm_intr_ignored, 1);
744
745 return retval;
746}
747

--- 257 unchanged lines hidden ---