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

Subversion Repositories sudoku

[/] [sudoku/] [branches/] [zynq/] [sw/] [counters.cc] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 dsheffie
 
2
#include "counters.h"
3
 
4
static void initCounter(hwCounter_t &x, uint64_t counterConfig)
5
{
6
  if(!x.init)
7
    {
8
      memset(&(x.attr), 0, sizeof(x.attr));
9
      x.attr.disabled = 0;
10
      x.attr.type = PERF_TYPE_HARDWARE;
11
      x.attr.config =  counterConfig;
12
      pid_t pid = 0;
13
      int cpu = -1;
14
      int group_fd = -1;
15
      unsigned long flags = 0;
16
      x.fd = syscall(__NR_perf_event_open, &(x.attr), pid,
17
                     cpu, group_fd, flags);
18
      assert(x.fd >= 0);
19
      x.init = true;
20
    }
21
}
22
 
23
void initTicks(hwCounter_t &x)
24
{
25
  initCounter(x,PERF_COUNT_HW_CPU_CYCLES);
26
}
27
void initInsns(hwCounter_t &x)
28
{
29
  initCounter(x,PERF_COUNT_HW_INSTRUCTIONS);
30
}
31
 
32
uint64_t getTicks(hwCounter_t &x)
33
{
34
  int rc;
35
 
36
  if(!x.init)
37
    {
38
      initTicks(x);
39
    }
40
 
41
  rc = read(x.fd,&(x.buffer),sizeof(x.buffer));
42
  assert(rc == sizeof(x.buffer));
43
  return x.buffer;
44
}
45
 
46
 
47
 
48
uint64_t getInsns(hwCounter_t &x)
49
{
50
  int rc;
51
 
52
  if(!x.init)
53
    {
54
      initInsns(x);
55
    }
56
 
57
  rc = read(x.fd,&(x.buffer),sizeof(x.buffer));
58
  assert(rc == sizeof(x.buffer));
59
  return x.buffer;
60
}

powered by: WebSVN 2.1.0

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