hwpmc_mod.c (145338) | hwpmc_mod.c (145615) |
---|---|
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 145338 2005-04-20 20:26:39Z marcel $"); | 29__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_mod.c 145615 2005-04-28 08:13:19Z 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/limits.h> 36#include <sys/lock.h> 37#include <sys/malloc.h> --- 696 unchanged lines hidden (view full) --- 734 M_PMC, M_ZERO|M_WAITOK); 735 736 pt->pt_process = pp; 737 738 LIST_INSERT_HEAD(&pm->pm_targets, pt, pt_next); 739 740 atomic_store_rel_ptr(&pp->pp_pmcs[ri].pp_pmc, pm); 741 | 30 31#include <sys/param.h> 32#include <sys/eventhandler.h> 33#include <sys/jail.h> 34#include <sys/kernel.h> 35#include <sys/limits.h> 36#include <sys/lock.h> 37#include <sys/malloc.h> --- 696 unchanged lines hidden (view full) --- 734 M_PMC, M_ZERO|M_WAITOK); 735 736 pt->pt_process = pp; 737 738 LIST_INSERT_HEAD(&pm->pm_targets, pt, pt_next); 739 740 atomic_store_rel_ptr(&pp->pp_pmcs[ri].pp_pmc, pm); 741 |
742 if (pm->pm_owner->po_owner == pp->pp_proc) 743 pp->pp_flags |= PMC_FLAG_ENABLE_MSR_ACCESS; 744 |
|
742 pp->pp_refcnt++; 743 | 745 pp->pp_refcnt++; 746 |
747 PMCDBG(PRC,TLK,2, "enable-msr %d", 748 (pp->pp_flags & PMC_FLAG_ENABLE_MSR_ACCESS) != 0); |
|
744} 745 746/* 747 * Removes the association between a target process and a PMC. 748 */ 749 750static void 751pmc_unlink_target_process(struct pmc *pm, struct pmc_process *pp) --- 17 unchanged lines hidden (view full) --- 769 770 KASSERT(pp->pp_pmcs[ri].pp_pmc == pm, 771 ("[pmc,%d] PMC ri %d mismatch pmc %p pp->[ri] %p", __LINE__, 772 ri, pm, pp->pp_pmcs[ri].pp_pmc)); 773 774 pp->pp_pmcs[ri].pp_pmc = NULL; 775 pp->pp_pmcs[ri].pp_pmcval = (pmc_value_t) 0; 776 | 749} 750 751/* 752 * Removes the association between a target process and a PMC. 753 */ 754 755static void 756pmc_unlink_target_process(struct pmc *pm, struct pmc_process *pp) --- 17 unchanged lines hidden (view full) --- 774 775 KASSERT(pp->pp_pmcs[ri].pp_pmc == pm, 776 ("[pmc,%d] PMC ri %d mismatch pmc %p pp->[ri] %p", __LINE__, 777 ri, pm, pp->pp_pmcs[ri].pp_pmc)); 778 779 pp->pp_pmcs[ri].pp_pmc = NULL; 780 pp->pp_pmcs[ri].pp_pmcval = (pmc_value_t) 0; 781 |
782 if (pm->pm_owner->po_owner == pp->pp_proc) 783 pp->pp_flags &= ~PMC_FLAG_ENABLE_MSR_ACCESS; 784 |
|
777 pp->pp_refcnt--; 778 779 /* Remove the target process from the PMC structure */ 780 LIST_FOREACH(ptgt, &pm->pm_targets, pt_next) 781 if (ptgt->pt_process == pp) 782 break; 783 784 KASSERT(ptgt != NULL, ("[pmc,%d] process %p (pp: %p) not found " 785 "in pmc %p", __LINE__, pp->pp_proc, pp, pm)); 786 | 785 pp->pp_refcnt--; 786 787 /* Remove the target process from the PMC structure */ 788 LIST_FOREACH(ptgt, &pm->pm_targets, pt_next) 789 if (ptgt->pt_process == pp) 790 break; 791 792 KASSERT(ptgt != NULL, ("[pmc,%d] process %p (pp: %p) not found " 793 "in pmc %p", __LINE__, pp->pp_proc, pp, pm)); 794 |
787 PMCDBG(PRC,TUL,4, "unlink ptgt=%p", ptgt); | 795 PMCDBG(PRC,TUL,4, "unlink ptgt=%p, enable-msr=%d", ptgt, 796 (pp->pp_flags & PMC_FLAG_ENABLE_MSR_ACCESS) != 0); |
788 789 LIST_REMOVE(ptgt, pt_next); 790 FREE(ptgt, M_PMC); 791} 792 793/* 794 * Remove PMC descriptor 'pmc' from the owner descriptor. 795 */ --- 358 unchanged lines hidden (view full) --- 1154 1155 if ((pp = pmc_find_process_descriptor(p, 1156 PMC_FLAG_REMOVE)) != NULL) { 1157 1158 PMCDBG(PRC,EXT,2, 1159 "process-exit proc=%p pmc-process=%p", p, pp); 1160 1161 /* | 797 798 LIST_REMOVE(ptgt, pt_next); 799 FREE(ptgt, M_PMC); 800} 801 802/* 803 * Remove PMC descriptor 'pmc' from the owner descriptor. 804 */ --- 358 unchanged lines hidden (view full) --- 1163 1164 if ((pp = pmc_find_process_descriptor(p, 1165 PMC_FLAG_REMOVE)) != NULL) { 1166 1167 PMCDBG(PRC,EXT,2, 1168 "process-exit proc=%p pmc-process=%p", p, pp); 1169 1170 /* |
1162 * This process could the target of some PMCs. 1163 * Such PMCs will thus be running on currently 1164 * executing CPU at this point in the code 1165 * since we've disallowed context switches. | 1171 * The exiting process could the target of 1172 * some PMCs which will be running on 1173 * currently executing CPU. 1174 * |
1166 * We need to turn these PMCs off like we 1167 * would do at context switch OUT time. 1168 */ 1169 1170 for (ri = 0; ri < md->pmd_npmc; ri++) { 1171 1172 /* 1173 * Pick up the pmc pointer from hardware --- 40 unchanged lines hidden (view full) --- 1214 } 1215 1216 KASSERT((int) pm->pm_runcount >= 0, 1217 ("[pmc,%d] runcount is %d", __LINE__, ri)); 1218 1219 atomic_subtract_rel_32(&pm->pm_runcount,1); 1220 (void) md->pmd_config_pmc(cpu, ri, NULL); 1221 } | 1175 * We need to turn these PMCs off like we 1176 * would do at context switch OUT time. 1177 */ 1178 1179 for (ri = 0; ri < md->pmd_npmc; ri++) { 1180 1181 /* 1182 * Pick up the pmc pointer from hardware --- 40 unchanged lines hidden (view full) --- 1223 } 1224 1225 KASSERT((int) pm->pm_runcount >= 0, 1226 ("[pmc,%d] runcount is %d", __LINE__, ri)); 1227 1228 atomic_subtract_rel_32(&pm->pm_runcount,1); 1229 (void) md->pmd_config_pmc(cpu, ri, NULL); 1230 } |
1231 1232 /* 1233 * Inform the MD layer of this pseudo "context switch 1234 * out" 1235 */ 1236 1237 (void) md->pmd_switch_out(pmc_pcpu[cpu], pp); 1238 |
|
1222 critical_exit(); /* ok to be pre-empted now */ 1223 1224 /* 1225 * Unlink this process from the PMCs that are 1226 * targetting it. Log value at exit() time if 1227 * requested. 1228 */ 1229 --- 240 unchanged lines hidden (view full) --- 1470 1471 } 1472 1473 /* 1474 * perform any other architecture/cpu dependent thread 1475 * switch-in actions. 1476 */ 1477 | 1239 critical_exit(); /* ok to be pre-empted now */ 1240 1241 /* 1242 * Unlink this process from the PMCs that are 1243 * targetting it. Log value at exit() time if 1244 * requested. 1245 */ 1246 --- 240 unchanged lines hidden (view full) --- 1487 1488 } 1489 1490 /* 1491 * perform any other architecture/cpu dependent thread 1492 * switch-in actions. 1493 */ 1494 |
1478 (void) (*md->pmd_switch_in)(pc); | 1495 (void) (*md->pmd_switch_in)(pc, pp); |
1479 1480 critical_exit(); 1481 1482 } 1483 break; 1484 1485 /* 1486 * Thread context switch OUT. --- 122 unchanged lines hidden (view full) --- 1609 md->pmd_config_pmc(cpu, ri, NULL); 1610 } 1611 1612 /* 1613 * perform any other architecture/cpu dependent thread 1614 * switch out functions. 1615 */ 1616 | 1496 1497 critical_exit(); 1498 1499 } 1500 break; 1501 1502 /* 1503 * Thread context switch OUT. --- 122 unchanged lines hidden (view full) --- 1626 md->pmd_config_pmc(cpu, ri, NULL); 1627 } 1628 1629 /* 1630 * perform any other architecture/cpu dependent thread 1631 * switch out functions. 1632 */ 1633 |
1617 (void) (*md->pmd_switch_out)(pc); | 1634 (void) (*md->pmd_switch_out)(pc, pp); |
1618 1619 critical_exit(); 1620 1621 } 1622 break; 1623 1624 default: 1625#if DEBUG --- 2045 unchanged lines hidden --- | 1635 1636 critical_exit(); 1637 1638 } 1639 break; 1640 1641 default: 1642#if DEBUG --- 2045 unchanged lines hidden --- |