*/
#include <kern/thread.h>
-#include <kern/thread_act.h>
#include <ppc/exception.h>
#include <ppc/savearea.h>
#include <ppc/hw_perfmon.h>
return retval;
}
-int perfmon_enable(thread_act_t thr_act)
+int perfmon_enable(thread_t thread)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t kr;
kern_return_t retval = KERN_SUCCESS;
int curPMC;
- if(thr_act->mact.specFlags & perfMonitor) {
+ if(thread->machine.specFlags & perfMonitor) {
return KERN_SUCCESS; /* already enabled */
} else if(perfmon_acquire_facility(kernel_task)!=KERN_SUCCESS) {
return KERN_RESOURCE_SHORTAGE; /* facility is in use */
sv->save_mmcr1 = 0;
sv->save_mmcr2 = 0;
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
case CPU_SUBTYPE_POWERPC_7450:
if(retval==KERN_SUCCESS) {
for(curPMC=0; curPMC<MAX_CPUPMC_COUNT; curPMC++) {
sv->save_pmc[curPMC] = 0;
- thr_act->mact.pmcovfl[curPMC] = 0;
+ thread->machine.pmcovfl[curPMC] = 0;
}
- thr_act->mact.perfmonFlags = 0;
- thr_act->mact.specFlags |= perfMonitor; /* enable perf monitor facility for this thread */
- if(thr_act==current_act()) {
- per_proc_info[cpu_number()].spcFlags |= perfMonitor; /* update per_proc */
+ thread->machine.perfmonFlags = 0;
+ thread->machine.specFlags |= perfMonitor; /* enable perf monitor facility for this thread */
+ if(thread==current_thread()) {
+ getPerProc()->spcFlags |= perfMonitor; /* update per_proc */
}
}
return retval;
}
-int perfmon_disable(thread_act_t thr_act)
+int perfmon_disable(thread_t thread)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
int curPMC;
- if(!(thr_act->mact.specFlags & perfMonitor)) {
+ if(!(thread->machine.specFlags & perfMonitor)) {
return KERN_NO_ACCESS; /* not enabled */
} else {
simple_lock(&hw_perfmon_lock);
perfmon_release_facility(kernel_task); /* will release if hw_perfmon_thread_count is 0 */
}
- thr_act->mact.specFlags &= ~perfMonitor; /* disable perf monitor facility for this thread */
- if(thr_act==current_act()) {
- per_proc_info[cpu_number()].spcFlags &= ~perfMonitor; /* update per_proc */
+ thread->machine.specFlags &= ~perfMonitor; /* disable perf monitor facility for this thread */
+ if(thread==current_thread()) {
+ PerProcTable[cpu_number()].ppe_vaddr->spcFlags &= ~perfMonitor; /* update per_proc */
}
sv->save_mmcr0 = 0;
sv->save_mmcr1 = 0;
for(curPMC=0; curPMC<MAX_CPUPMC_COUNT; curPMC++) {
sv->save_pmc[curPMC] = 0;
- thr_act->mact.pmcovfl[curPMC] = 0;
- thr_act->mact.perfmonFlags = 0;
+ thread->machine.pmcovfl[curPMC] = 0;
+ thread->machine.perfmonFlags = 0;
}
#ifdef HWPERFMON_DEBUG
return KERN_SUCCESS;
}
-int perfmon_clear_counters(thread_act_t thr_act)
+int perfmon_clear_counters(thread_t thread)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
int curPMC;
#ifdef HWPERFMON_DEBUG
/* clear thread copy */
for(curPMC=0; curPMC<MAX_CPUPMC_COUNT; curPMC++) {
sv->save_pmc[curPMC] = 0;
- thr_act->mact.pmcovfl[curPMC] = 0;
+ thread->machine.pmcovfl[curPMC] = 0;
}
return KERN_SUCCESS;
}
-int perfmon_write_counters(thread_act_t thr_act, uint64_t *pmcs)
+int perfmon_write_counters(thread_t thread, uint64_t *pmcs)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
int curPMC;
#ifdef HWPERFMON_DEBUG
/* update thread copy */
for(curPMC=0; curPMC<MAX_CPUPMC_COUNT; curPMC++) {
sv->save_pmc[curPMC] = pmcs[curPMC] & 0x7FFFFFFF;
- thr_act->mact.pmcovfl[curPMC] = (pmcs[curPMC]>>31) & 0xFFFFFFFF;
+ thread->machine.pmcovfl[curPMC] = (pmcs[curPMC]>>31) & 0xFFFFFFFF;
}
return KERN_SUCCESS;
}
-int perfmon_read_counters(thread_act_t thr_act, uint64_t *pmcs)
+int perfmon_read_counters(thread_t thread, uint64_t *pmcs)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
int curPMC;
/* retrieve from thread copy */
for(curPMC=0; curPMC<MAX_CPUPMC_COUNT; curPMC++) {
- pmcs[curPMC] = thr_act->mact.pmcovfl[curPMC];
+ pmcs[curPMC] = thread->machine.pmcovfl[curPMC];
pmcs[curPMC] = pmcs[curPMC]<<31;
pmcs[curPMC] |= (sv->save_pmc[curPMC] & 0x7FFFFFFF);
}
/* zero any unused counters on this platform */
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
case CPU_SUBTYPE_POWERPC_7450:
return KERN_SUCCESS;
}
-int perfmon_start_counters(thread_act_t thr_act)
+int perfmon_start_counters(thread_t thread)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t retval = KERN_SUCCESS;
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
{
return retval;
}
-int perfmon_stop_counters(thread_act_t thr_act)
+int perfmon_stop_counters(thread_t thread)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t retval = KERN_SUCCESS;
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
case CPU_SUBTYPE_POWERPC_7450:
return retval;
}
-int perfmon_set_event(thread_act_t thr_act, int pmc, int event)
+int perfmon_set_event(thread_t thread, int pmc, int event)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t retval = KERN_SUCCESS;
#ifdef HWPERFMON_DEBUG
kprintf("perfmon_set_event b4 (CPU%d) - pmc=%d, event=%d - mmcr0=0x%llx mmcr1=0x%llx mmcr2=0x%llx\n", cpu_number(), pmc, event, sv->save_mmcr0, sv->save_mmcr1, sv->save_mmcr2);
#endif
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
{
return retval;
}
-int perfmon_set_event_func(thread_act_t thr_act, uint32_t f)
+int perfmon_set_event_func(thread_t thread, uint32_t f)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t retval = KERN_SUCCESS;
#ifdef HWPERFMON_DEBUG
"UNKNOWN");
#endif /* HWPERFMON_DEBUG */
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
case CPU_SUBTYPE_POWERPC_7450:
return retval;
}
-int perfmon_set_threshold(thread_act_t thr_act, int threshold)
+int perfmon_set_threshold(thread_t thread, int threshold)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t retval = KERN_SUCCESS;
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
{
ppc32_mmcr0_reg_t mmcr0_reg;
return retval;
}
-int perfmon_set_tbsel(thread_act_t thr_act, int tbsel)
+int perfmon_set_tbsel(thread_t thread, int tbsel)
{
- struct savearea *sv = thr_act->mact.pcb;
+ struct savearea *sv = thread->machine.pcb;
kern_return_t retval = KERN_SUCCESS;
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_750:
case CPU_SUBTYPE_POWERPC_7400:
case CPU_SUBTYPE_POWERPC_7450:
int pmc = (int)ssp->save_r5;
int val = (int)ssp->save_r6;
uint64_t *usr_pmcs_p = CAST_DOWN(uint64_t *, ssp->save_r7);
- thread_act_t thr_act = THREAD_NULL;
+ thread_t thread = THREAD_NULL;
uint64_t kern_pmcs[MAX_CPUPMC_COUNT];
kern_return_t retval = KERN_SUCCESS;
int error;
boolean_t oldlevel;
- thr_act = (thread_act_t) port_name_to_act(thr_port); // convert user space thread port name to a thread_act_t
- if(!thr_act) {
+ thread = (thread_t) port_name_to_thread(thr_port); // convert user space thread port name to a thread_t
+ if(!thread) {
ssp->save_r3 = KERN_INVALID_ARGUMENT;
return 1; /* Return and check for ASTs... */
}
- if(thr_act!=current_act()) {
- thread_suspend(thr_act);
+ if(thread!=current_thread()) {
+ thread_suspend(thread);
}
#ifdef HWPERFMON_DEBUG
/* individual actions which do not require perfmon facility to be enabled */
if(action==PPC_PERFMON_DISABLE) {
- retval = perfmon_disable(thr_act);
+ retval = perfmon_disable(thread);
}
else if(action==PPC_PERFMON_ENABLE) {
- retval = perfmon_enable(thr_act);
+ retval = perfmon_enable(thread);
}
else { /* individual actions which do require perfmon facility to be enabled */
- if(!(thr_act->mact.specFlags & perfMonitor)) { /* perfmon not enabled */
+ if(!(thread->machine.specFlags & perfMonitor)) { /* perfmon not enabled */
#ifdef HWPERFMON_DEBUG
kprintf("perfmon_control: ERROR - perfmon not enabled for this thread\n");
#endif
}
if(action==PPC_PERFMON_SET_EVENT) {
- retval = perfmon_set_event(thr_act, pmc, val);
+ retval = perfmon_set_event(thread, pmc, val);
}
else if(action==PPC_PERFMON_SET_THRESHOLD) {
- retval = perfmon_set_threshold(thr_act, val);
+ retval = perfmon_set_threshold(thread, val);
}
else if(action==PPC_PERFMON_SET_TBSEL) {
- retval = perfmon_set_tbsel(thr_act, val);
+ retval = perfmon_set_tbsel(thread, val);
}
else if(action==PPC_PERFMON_SET_EVENT_FUNC) {
- retval = perfmon_set_event_func(thr_act, val);
+ retval = perfmon_set_event_func(thread, val);
}
else if(action==PPC_PERFMON_ENABLE_PMI_BRKPT) {
if(val) {
- thr_act->mact.perfmonFlags |= PERFMONFLAG_BREAKPOINT_FOR_PMI;
+ thread->machine.perfmonFlags |= PERFMONFLAG_BREAKPOINT_FOR_PMI;
} else {
- thr_act->mact.perfmonFlags &= ~PERFMONFLAG_BREAKPOINT_FOR_PMI;
+ thread->machine.perfmonFlags &= ~PERFMONFLAG_BREAKPOINT_FOR_PMI;
}
retval = KERN_SUCCESS;
}
/* combinable actions */
else {
if(action & PPC_PERFMON_STOP_COUNTERS) {
- error = perfmon_stop_counters(thr_act);
+ error = perfmon_stop_counters(thread);
if(error!=KERN_SUCCESS) {
retval = error;
goto perfmon_return;
}
}
if(action & PPC_PERFMON_CLEAR_COUNTERS) {
- error = perfmon_clear_counters(thr_act);
+ error = perfmon_clear_counters(thread);
if(error!=KERN_SUCCESS) {
retval = error;
goto perfmon_return;
}
}
if(action & PPC_PERFMON_WRITE_COUNTERS) {
- if(error = copyin((void *)usr_pmcs_p, (void *)kern_pmcs, MAX_CPUPMC_COUNT*sizeof(uint64_t))) {
+ if(error = copyin(CAST_USER_ADDR_T(usr_pmcs_p), (void *)kern_pmcs, MAX_CPUPMC_COUNT*sizeof(uint64_t))) {
retval = error;
goto perfmon_return;
}
- error = perfmon_write_counters(thr_act, kern_pmcs);
+ error = perfmon_write_counters(thread, kern_pmcs);
if(error!=KERN_SUCCESS) {
retval = error;
goto perfmon_return;
}
}
if(action & PPC_PERFMON_READ_COUNTERS) {
- error = perfmon_read_counters(thr_act, kern_pmcs);
+ error = perfmon_read_counters(thread, kern_pmcs);
if(error!=KERN_SUCCESS) {
retval = error;
goto perfmon_return;
}
- if(error = copyout((void *)kern_pmcs, (void *)usr_pmcs_p, MAX_CPUPMC_COUNT*sizeof(uint64_t))) {
+ if(error = copyout((void *)kern_pmcs, CAST_USER_ADDR_T(usr_pmcs_p), MAX_CPUPMC_COUNT*sizeof(uint64_t))) {
retval = error;
goto perfmon_return;
}
}
if(action & PPC_PERFMON_START_COUNTERS) {
- error = perfmon_start_counters(thr_act);
+ error = perfmon_start_counters(thread);
if(error!=KERN_SUCCESS) {
retval = error;
goto perfmon_return;
kprintf("perfmon_control (CPU%d): mmcr0 = %016llX, pmc1=%X pmc2=%X pmc3=%X pmc4=%X pmc5=%X pmc6=%X pmc7=%X pmc8=%X\n", cpu_number(), ssp->save_mmcr0, ssp->save_pmc[PMC_1], ssp->save_pmc[PMC_2], ssp->save_pmc[PMC_3], ssp->save_pmc[PMC_4], ssp->save_pmc[PMC_5], ssp->save_pmc[PMC_6], ssp->save_pmc[PMC_7], ssp->save_pmc[PMC_8]);
#endif
- if(thr_act!=current_act()) {
- thread_resume(thr_act);
+ if(thread!=current_thread()) {
+ thread_resume(thread);
}
#ifdef HWPERFMON_DEBUG
{
int curPMC;
kern_return_t retval = KERN_SUCCESS;
- thread_act_t thr_act = current_act();
+ thread_t thread = current_thread();
#ifdef HWPERFMON_DEBUG
kprintf("perfmon_handle_pmi: got rupt\n");
#endif
- if(!(thr_act->mact.specFlags & perfMonitor)) { /* perfmon not enabled */
+ if(!(thread->machine.specFlags & perfMonitor)) { /* perfmon not enabled */
#ifdef HWPERFMON_DEBUG
kprintf("perfmon_handle_pmi: ERROR - perfmon not enabled for this thread\n");
#endif
}
for(curPMC=0; curPMC<MAX_CPUPMC_COUNT; curPMC++) {
- if(thr_act->mact.pcb->save_pmc[curPMC] & 0x80000000) {
- if(thr_act->mact.pmcovfl[curPMC]==0xFFFFFFFF && (thr_act->mact.perfmonFlags & PERFMONFLAG_BREAKPOINT_FOR_PMI)) {
+ if(thread->machine.pcb->save_pmc[curPMC] & 0x80000000) {
+ if(thread->machine.pmcovfl[curPMC]==0xFFFFFFFF && (thread->machine.perfmonFlags & PERFMONFLAG_BREAKPOINT_FOR_PMI)) {
doexception(EXC_BREAKPOINT, EXC_PPC_PERFMON, (unsigned int)ssp->save_srr0); // pass up a breakpoint exception
return KERN_SUCCESS;
} else {
- thr_act->mact.pmcovfl[curPMC]++;
- thr_act->mact.pcb->save_pmc[curPMC] = 0;
+ thread->machine.pmcovfl[curPMC]++;
+ thread->machine.pcb->save_pmc[curPMC] = 0;
}
}
}
if(retval==KERN_SUCCESS) {
- switch(machine_slot[0].cpu_subtype) {
+ switch(PerProcTable[0].ppe_vaddr->cpu_subtype) {
case CPU_SUBTYPE_POWERPC_7450:
{
ppc32_mmcr0_reg_t mmcr0_reg;
- mmcr0_reg.value = thr_act->mact.pcb->save_mmcr0;
+ mmcr0_reg.value = thread->machine.pcb->save_mmcr0;
mmcr0_reg.field.disable_counters_always = FALSE;
mmcr0_reg.field.enable_pmi = TRUE;
- thr_act->mact.pcb->save_mmcr0 = mmcr0_reg.value;
+ thread->machine.pcb->save_mmcr0 = mmcr0_reg.value;
}
retval = KERN_SUCCESS;
break;
{
ppc64_mmcr0_reg_t mmcr0_reg;
- mmcr0_reg.value = thr_act->mact.pcb->save_mmcr0;
+ mmcr0_reg.value = thread->machine.pcb->save_mmcr0;
mmcr0_reg.field.disable_counters_always = FALSE;
mmcr0_reg.field.enable_pmi = TRUE;
- thr_act->mact.pcb->save_mmcr0 = mmcr0_reg.value;
+ thread->machine.pcb->save_mmcr0 = mmcr0_reg.value;
}
retval = KERN_SUCCESS;
break;