OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [pcu/] [pcu.c] - Blame information for rev 581

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 556 julius
/* pcu.c -- Simulation of OR1k performance counters
2
 
3
   Copyright (C) 2011 Julius Baxter, julius@opencores.org
4
 
5
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
6
 
7
   This program is free software; you can redistribute it and/or modify it
8
   under the terms of the GNU General Public License as published by the Free
9
   Software Foundation; either version 3 of the License, or (at your option)
10
   any later version.
11
 
12
   This program is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15
   more details.
16
 
17
   You should have received a copy of the GNU General Public License along
18
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
 
20
/* This program is commented throughout in a fashion suitable for processing
21
   with Doxygen. */
22
 
23
#include "config.h"
24
#include "sim-config.h"
25
#include "execute.h"
26
 
27
#include "pcu.h"
28
 
29
/*---------------------------------------------------------------------------*/
30
/*!Increment a PCCR depending on the event
31
 
32
   Check the event, see if any PCMRs are set to increment, and permissions and
33
   increment the corresponding PCCR.
34
 
35
   The performance counters unit relies on a call to pcu_count_event()
36
   being placed a the appropriate place elsewhere in the simulator code.
37
   At present only instruction fetch, LSU accesses, MMU and cache misses are
38
   logged. Counts for other things such as stalls for LSU or fetch can
39
   probably be done but haven't been, yet.
40
   The function expects to receive the bit of the PCMR to check against for
41
   incrementing. See the existing use of the function in the
42
   cpu/common/abstract.c file which is where LSU accesses and instruction
43
   fetches are logged.
44
 
45
   @param[in] event  The event that has occurred (PCMR bit)                  */
46
/*---------------------------------------------------------------------------*/
47
void
48
pcu_count_event(unsigned event)
49
{
50
 
51
  int i;
52
 
53
  // Look through each PCMR, check if this event should be logged
54
  for(i=0;i<8;i++)
55
    if ((event & cpu_state.sprs[SPR_PCMR(i)]) &&
56
        // Count in SM, and SR[SM] set
57
        (((cpu_state.sprs[SPR_PCMR(i)] & SPR_PCMR_CISM) &&
58
          (cpu_state.sprs[SPR_SR] & SPR_SR_SM)) ||
59
         // Count in UM and SR[SM] cleared
60
         ((cpu_state.sprs[SPR_PCMR(i)] & SPR_PCMR_CIUM) &&
61
          !(cpu_state.sprs[SPR_SR] & SPR_SR_SM))))
62
      {
63
        cpu_state.sprs[SPR_PCCR(i)]++;
64
      }
65
 
66
}
67
 
68
 
69
/*---------------------------------------------------------------------------*/
70
/*!Enable or disable the performance counters unit
71
 
72
   Set the corresponding field in the UPR, set present bit in all PCMRs
73
 
74
   @param[in] val  The value to use
75
   @param[in] dat  The config data structure (not used here)                 */
76
/*---------------------------------------------------------------------------*/
77
static void
78
pcu_enabled (union param_val val, void *dat)
79
{
80
  if (val.int_val)
81
    {
82
      cpu_state.sprs[SPR_UPR] |= SPR_UPR_PCUP;
83
      cpu_state.sprs[SPR_PCMR(0)] = SPR_PCMR_CP;
84
      cpu_state.sprs[SPR_PCMR(1)] = SPR_PCMR_CP;
85
      cpu_state.sprs[SPR_PCMR(2)] = SPR_PCMR_CP;
86
      cpu_state.sprs[SPR_PCMR(3)] = SPR_PCMR_CP;
87
      cpu_state.sprs[SPR_PCMR(4)] = SPR_PCMR_CP;
88
      cpu_state.sprs[SPR_PCMR(5)] = SPR_PCMR_CP;
89
      cpu_state.sprs[SPR_PCMR(6)] = SPR_PCMR_CP;
90
      cpu_state.sprs[SPR_PCMR(7)] = SPR_PCMR_CP;
91
    }
92
  else
93
    {
94
      cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_PCUP;
95
    }
96
 
97
 
98
 
99
  config.pcu.enabled = val.int_val;
100
 
101
}       /* pcu_enabled() */
102
 
103
 
104
/*---------------------------------------------------------------------------*/
105
/*!Register the configuration functions for the performance counters unit    */
106
/*---------------------------------------------------------------------------*/
107
void
108
reg_pcu_sec ()
109
{
110
  struct config_section *sec = reg_config_sec ("pcu", NULL, NULL);
111
 
112
  reg_config_param (sec, "enabled",     PARAMT_INT, pcu_enabled);
113
 
114
}       /* reg_pcu_sec () */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.