Deleted Added
full compact
hwpmc_mod.c (147708) hwpmc_mod.c (147867)
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_mod.c 147708 2005-06-30 19:01:26Z jkoshy $");
29__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_mod.c 147867 2005-07-09 17:29:36Z jkoshy $");
30
31#include <sys/param.h>
32#include <sys/eventhandler.h>
33#include <sys/jail.h>
34#include <sys/kernel.h>
35#include <sys/kthread.h>
36#include <sys/limits.h>
37#include <sys/lock.h>

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

1319 if (!PMC_IS_VIRTUAL_MODE(mode))
1320 continue; /* not a process virtual PMC */
1321
1322 KASSERT(PMC_TO_ROWINDEX(pm) == ri,
1323 ("[pmc,%d] ri mismatch pmc(%d) ri(%d)",
1324 __LINE__, PMC_TO_ROWINDEX(pm), ri));
1325
1326 /* Stop hardware if not already stopped */
30
31#include <sys/param.h>
32#include <sys/eventhandler.h>
33#include <sys/jail.h>
34#include <sys/kernel.h>
35#include <sys/kthread.h>
36#include <sys/limits.h>
37#include <sys/lock.h>

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

1319 if (!PMC_IS_VIRTUAL_MODE(mode))
1320 continue; /* not a process virtual PMC */
1321
1322 KASSERT(PMC_TO_ROWINDEX(pm) == ri,
1323 ("[pmc,%d] ri mismatch pmc(%d) ri(%d)",
1324 __LINE__, PMC_TO_ROWINDEX(pm), ri));
1325
1326 /* Stop hardware if not already stopped */
1327 if ((pm->pm_flags & PMC_F_IS_STALLED) == 0)
1327 if (pm->pm_stalled == 0)
1328 md->pmd_stop_pmc(cpu, ri);
1329
1330 /* reduce this PMC's runcount */
1331 atomic_subtract_rel_32(&pm->pm_runcount, 1);
1332
1333 /*
1334 * If this PMC is associated with this process,
1335 * save the reading.

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

1850 pmc_save_cpu_binding(&pb);
1851
1852 cpu = PMC_TO_CPU(pm);
1853
1854 pmc_select_cpu(cpu);
1855
1856 /* switch off non-stalled CPUs */
1857 if (pm->pm_state == PMC_STATE_RUNNING &&
1328 md->pmd_stop_pmc(cpu, ri);
1329
1330 /* reduce this PMC's runcount */
1331 atomic_subtract_rel_32(&pm->pm_runcount, 1);
1332
1333 /*
1334 * If this PMC is associated with this process,
1335 * save the reading.

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

1850 pmc_save_cpu_binding(&pb);
1851
1852 cpu = PMC_TO_CPU(pm);
1853
1854 pmc_select_cpu(cpu);
1855
1856 /* switch off non-stalled CPUs */
1857 if (pm->pm_state == PMC_STATE_RUNNING &&
1858 (pm->pm_flags & PMC_F_IS_STALLED) == 0) {
1858 pm->pm_stalled == 0) {
1859
1860 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
1861
1862 KASSERT(phw->phw_pmc == pm,
1863 ("[pmc, %d] pmc ptr ri(%d) hw(%p) pm(%p)",
1864 __LINE__, ri, phw->phw_pmc, pm));
1865 PMCDBG(PMC,REL,2, "stopping cpu=%d ri=%d", cpu, ri);
1866

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

3390 }
3391
3392 error = pmc_stop(pm);
3393 }
3394 break;
3395
3396
3397 /*
1859
1860 phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
1861
1862 KASSERT(phw->phw_pmc == pm,
1863 ("[pmc, %d] pmc ptr ri(%d) hw(%p) pm(%p)",
1864 __LINE__, ri, phw->phw_pmc, pm));
1865 PMCDBG(PMC,REL,2, "stopping cpu=%d ri=%d", cpu, ri);
1866

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

3390 }
3391
3392 error = pmc_stop(pm);
3393 }
3394 break;
3395
3396
3397 /*
3398 * Flush the per-owner log file and Write a user-entry to the
3399 * log file.
3398 * Write a user supplied value to the log file.
3400 */
3401
3402 case PMC_OP_WRITELOG:
3403 {
3404 struct pmc_op_writelog wl;
3405 struct pmc_owner *po;
3406
3407 PMC_DOWNGRADE_SX();

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

3469
3470 error = 0;
3471 ri = PMC_TO_ROWINDEX(pm);
3472
3473 psb = pmc_pcpu[cpu]->pc_sb;
3474
3475 ps = psb->ps_write;
3476 if (ps->ps_pc) { /* in use, reader hasn't caught up */
3399 */
3400
3401 case PMC_OP_WRITELOG:
3402 {
3403 struct pmc_op_writelog wl;
3404 struct pmc_owner *po;
3405
3406 PMC_DOWNGRADE_SX();

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

3468
3469 error = 0;
3470 ri = PMC_TO_ROWINDEX(pm);
3471
3472 psb = pmc_pcpu[cpu]->pc_sb;
3473
3474 ps = psb->ps_write;
3475 if (ps->ps_pc) { /* in use, reader hasn't caught up */
3476 pm->pm_stalled = 1;
3477 atomic_add_int(&pmc_stats.pm_intr_bufferfull, 1);
3477 atomic_add_int(&pmc_stats.pm_intr_bufferfull, 1);
3478 atomic_set_int(&pm->pm_flags, PMC_F_IS_STALLED);
3479 PMCDBG(SAM,INT,1,"(spc) cpu=%d pm=%p pc=%jx um=%d wr=%d rd=%d",
3480 cpu, pm, (uint64_t) pc, usermode,
3481 (int) (psb->ps_write - psb->ps_samples),
3482 (int) (psb->ps_read - psb->ps_samples));
3483 error = ENOMEM;
3484 goto done;
3485 }
3486

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

3594
3595 /* Do not re-enable stalled PMCs if we failed to process any samples */
3596 if (n == 0)
3597 return;
3598
3599 /*
3600 * Restart any stalled sampling PMCs on this CPU.
3601 *
3478 PMCDBG(SAM,INT,1,"(spc) cpu=%d pm=%p pc=%jx um=%d wr=%d rd=%d",
3479 cpu, pm, (uint64_t) pc, usermode,
3480 (int) (psb->ps_write - psb->ps_samples),
3481 (int) (psb->ps_read - psb->ps_samples));
3482 error = ENOMEM;
3483 goto done;
3484 }
3485

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

3593
3594 /* Do not re-enable stalled PMCs if we failed to process any samples */
3595 if (n == 0)
3596 return;
3597
3598 /*
3599 * Restart any stalled sampling PMCs on this CPU.
3600 *
3602 * If the NMI handler sets PMC_F_IS_STALLED on a PMC after the
3603 * check below, we'll end up processing the stalled PMC at the
3604 * next hardclock tick.
3601 * If the NMI handler sets the pm_stalled field of a PMC after
3602 * the check below, we'll end up processing the stalled PMC at
3603 * the next hardclock tick.
3605 */
3606 for (n = 0; n < md->pmd_npmc; n++) {
3607 (void) (*md->pmd_get_config)(cpu,n,&pm);
3608 if (pm == NULL || /* !cfg'ed */
3609 pm->pm_state != PMC_STATE_RUNNING || /* !active */
3610 !PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)) || /* !sampling */
3604 */
3605 for (n = 0; n < md->pmd_npmc; n++) {
3606 (void) (*md->pmd_get_config)(cpu,n,&pm);
3607 if (pm == NULL || /* !cfg'ed */
3608 pm->pm_state != PMC_STATE_RUNNING || /* !active */
3609 !PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)) || /* !sampling */
3611 (pm->pm_flags & PMC_F_IS_STALLED) == 0) /* !stalled */
3610 pm->pm_stalled == 0) /* !stalled */
3612 continue;
3613
3611 continue;
3612
3614 pm->pm_flags &= ~PMC_F_IS_STALLED;
3613 pm->pm_stalled = 0;
3615 ri = PMC_TO_ROWINDEX(pm);
3616 (*md->pmd_start_pmc)(cpu, ri);
3617 }
3618}
3619
3620/*
3621 * Event handlers.
3622 */

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

3728 __LINE__, pm, ri, pp->pp_pmcs[ri].pp_pmc));
3729
3730 (void) md->pmd_stop_pmc(cpu, ri);
3731
3732 KASSERT(pm->pm_runcount > 0,
3733 ("[pmc,%d] bad runcount ri %d rc %d",
3734 __LINE__, ri, pm->pm_runcount));
3735
3614 ri = PMC_TO_ROWINDEX(pm);
3615 (*md->pmd_start_pmc)(cpu, ri);
3616 }
3617}
3618
3619/*
3620 * Event handlers.
3621 */

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

3727 __LINE__, pm, ri, pp->pp_pmcs[ri].pp_pmc));
3728
3729 (void) md->pmd_stop_pmc(cpu, ri);
3730
3731 KASSERT(pm->pm_runcount > 0,
3732 ("[pmc,%d] bad runcount ri %d rc %d",
3733 __LINE__, ri, pm->pm_runcount));
3734
3736 /* Stopped the hardware only if it is actually on */
3735 /* Stop hardware only if it is actually running */
3737 if (pm->pm_state == PMC_STATE_RUNNING &&
3736 if (pm->pm_state == PMC_STATE_RUNNING &&
3738 (pm->pm_flags & PMC_F_IS_STALLED) == 0) {
3737 pm->pm_stalled == 0) {
3739 md->pmd_read_pmc(cpu, ri, &newvalue);
3740 tmp = newvalue -
3741 PMC_PCPU_SAVED(cpu,ri);
3742
3743 mtx_pool_lock_spin(pmc_mtxpool, pm);
3744 pm->pm_gv.pm_savedvalue += tmp;
3745 pp->pp_pmcs[ri].pp_pmcval += tmp;
3746 mtx_pool_unlock_spin(pmc_mtxpool, pm);

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

3766 * Unlink this process from the PMCs that are
3767 * targetting it. This will send a signal to
3768 * all PMC owner's whose PMCs are orphaned.
3769 *
3770 * Log PMC value at exit time if requested.
3771 */
3772 for (ri = 0; ri < md->pmd_npmc; ri++)
3773 if ((pm = pp->pp_pmcs[ri].pp_pmc) != NULL) {
3738 md->pmd_read_pmc(cpu, ri, &newvalue);
3739 tmp = newvalue -
3740 PMC_PCPU_SAVED(cpu,ri);
3741
3742 mtx_pool_lock_spin(pmc_mtxpool, pm);
3743 pm->pm_gv.pm_savedvalue += tmp;
3744 pp->pp_pmcs[ri].pp_pmcval += tmp;
3745 mtx_pool_unlock_spin(pmc_mtxpool, pm);

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

3765 * Unlink this process from the PMCs that are
3766 * targetting it. This will send a signal to
3767 * all PMC owner's whose PMCs are orphaned.
3768 *
3769 * Log PMC value at exit time if requested.
3770 */
3771 for (ri = 0; ri < md->pmd_npmc; ri++)
3772 if ((pm = pp->pp_pmcs[ri].pp_pmc) != NULL) {
3774 if (pm->pm_flags & PMC_F_NEEDS_LOGFILE)
3773 if (pm->pm_flags & PMC_F_NEEDS_LOGFILE &&
3774 PMC_IS_COUNTING_MODE(PMC_TO_MODE(pm)))
3775 pmclog_process_procexit(pm, pp);
3776 pmc_unlink_target_process(pm, pp);
3777 }
3778 FREE(pp, M_PMC);
3779
3780 } else
3781 critical_exit(); /* pp == NULL */
3782

--- 407 unchanged lines hidden ---
3775 pmclog_process_procexit(pm, pp);
3776 pmc_unlink_target_process(pm, pp);
3777 }
3778 FREE(pp, M_PMC);
3779
3780 } else
3781 critical_exit(); /* pp == NULL */
3782

--- 407 unchanged lines hidden ---