⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profiler.c

📁 老外的一个开源项目
💻 C
字号:
// Copyright (c) David Vescovi.  All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  File:  profiler.c
//
//  This file contains implementation of profiler module suitable for the
//  Intel PXA255 CPU/SoC with count/compare timer.  The routines
//  use match register 2 (M2) for the profiling timer.
//
#include <windows.h>
#include <nkintr.h>
#include <oal.h>
#include <intr.h>
#include <pxa255.h>

//------------------------------------------------------------------------------
// Local Variables 

static volatile OST_REG_T  *g_pOSTRegs  = NULL;
static volatile INTC_REG_T *g_pINTCRegs = NULL;

static struct
{
    BOOL enabled;                               // is profiler active?
    UINT32 countsPerHit;                        // counts per profiler interrupt
} g_profiler;

//------------------------------------------------------------------------------
// External Variables 
extern PFN_PROFILER_ISR g_pProfilerISR;

//------------------------------------------------------------------------------
// Local Functions 
UINT32 OALProfileIntrHandler(UINT32 ra);
    
//------------------------------------------------------------------------------
//
//  Function:  OEMProfileTimerEnable
//
//  This function is called by kernel to start kernel profiling timer.
//
VOID OEMProfileTimerEnable(DWORD interval)
{
    BOOL enabled;
    UINT32 irq;
    
    OALMSG(TRUE, (L"+OEMProfileTimerEnable(%d)\r\n", interval));
    
    // We can't enable timer second time
    if (g_profiler.enabled) return;
   
    // How many hi-res ticks per profiler hit
    g_profiler.countsPerHit = (g_oalTimer.countsPerMSec * interval)/1000;

    // Following code should not be interrupted
    enabled = INTERRUPTS_ENABLE(FALSE);

    // Configure profiling ISR callback function.
    g_pProfilerISR = OALProfileIntrHandler;

    // Obtain pointers to OST and INTC registers.
    //
	g_pOSTRegs  = (volatile OST_REG_T *)  OALPAtoVA(PXA255_BASE_REG_PA_OST, FALSE);
	g_pINTCRegs = (volatile INTC_REG_T *) OALPAtoVA(PXA255_BASE_REG_PA_INTC, FALSE);

    // XLLI initializes oier and rtsr to zeroes, so no further
    // initialization needs to be done.  Match timers and
    // alarms are disabled.
    //
    // Current usage of Match registers:
    //  M0 - Scheduler
    //  M1 - Touch Panel
    //  M2 - Profiler

    // Update the compare register for the next profile hit.
    //
    // Disable interrupts on the specified Match register
    g_pOSTRegs->OIER &= ~(OIER_E2 | OIER_RESERVED_BITS);
    // Clear any interrupt on the specified Match register
    g_pOSTRegs->OSSR = OSSR_M2; 
	// Set up the match register to expire when the oscr reaches
    // the next match interval.
	g_pOSTRegs->OSMR2 = g_pOSTRegs->OSCR + g_profiler.countsPerHit;
    // Enable the Match register interrupt on OS timer 
    g_pOSTRegs->OIER |= OIER_E2;
    // Enable the Match interrupt at the interrupt controller
    g_pINTCRegs->ICMR |= INTC_OSMR2; 

    // Enable interrupts
    INTERRUPTS_ENABLE(enabled);
    irq = IRQ_OSMR2;
    OALIntrDoneIrqs(1, &irq);

    // Set flag
    g_profiler.enabled = TRUE;

    OALMSG(TRUE, (L"-OEMProfileTimerEnable\r\n"));
}


//------------------------------------------------------------------------------
//
//  Function:  OEMProfileTimerDisable
//
//  This function is called by kernel to stop kernel profiling timer.
//

VOID OEMProfileTimerDisable() 
{
    BOOL enabled;
    UINT32 irq;

    OALMSG(TRUE, (L"+OEMProfileTimerDisable()\r\n"));

    // No disable without enable
    if (!g_profiler.enabled) goto cleanUp;

    // Following code should not be interrupted
    enabled = INTERRUPTS_ENABLE(FALSE);

    // Disable the profile timer interrupt
    irq = IRQ_OSMR2;
    OALIntrDisableIrqs(1, &irq);

    // Deconfigure profiling ISR callback function.
    g_pProfilerISR = NULL;

    // Reset flag
    g_profiler.enabled = FALSE;

    // Enable interrupts
    INTERRUPTS_ENABLE(enabled);

cleanUp:
    OALMSG(TRUE, (L"-OEMProfileTimerDisable\r\n"));
}


//------------------------------------------------------------------------------
//
//  Function:  OALProfileIntrHandler
//
//  This is timer interrupt handler which replace default handler in time when
//  kernel profiling is active. It calls original interrupt handler in
//  appropriate times.
//
UINT32 OALProfileIntrHandler(UINT32 ra)
{
    UINT32 irq;

    // Update the compare register for the next profile hit.
    //
    // Disable interrupts on the specified Match register
    g_pOSTRegs->OIER &= ~(OIER_E2 | OIER_RESERVED_BITS);
    // Clear any interrupt on the specified Match register
    g_pOSTRegs->OSSR = OSSR_M2; 
	// Set up the match register to expire when the oscr reaches
    // the next match interval.
	g_pOSTRegs->OSMR2 = g_pOSTRegs->OSCR + g_profiler.countsPerHit;
    // Enable the Match register interrupt on OS timer 
    g_pOSTRegs->OIER |= OIER_E2;
    // Enable the Match interrupt at the interrupt controller
    g_pINTCRegs->ICMR |= INTC_OSMR2; 

    // First call profiler
    ProfilerHit(ra);

    // Enable interrupts
    irq = IRQ_OSMR2;
    OALIntrDoneIrqs(1, &irq);

    return SYSINTR_NOP; 
}

//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -