gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
perfevent.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Andreas Sandberg
38  */
39 
40 #ifndef __CPU_KVM_PERFEVENT_HH__
41 #define __CPU_KVM_PERFEVENT_HH__
42 
43 #include <linux/perf_event.h>
44 #include <sys/types.h>
45 
46 #include <inttypes.h>
47 
48 #include "config/have_perf_attr_exclude_host.hh"
49 
54 {
55  public:
76  PerfKvmCounterConfig(uint32_t type, uint64_t config);
78 
87  PerfKvmCounterConfig &samplePeriod(uint64_t period) {
88  attr.freq = 0;
89  attr.sample_period = period;
90  return *this;
91  }
92 
100  PerfKvmCounterConfig &wakeupEvents(uint32_t events) {
101  attr.watermark = 0;
102  attr.wakeup_events = events;
103  return *this;
104  }
105 
113  attr.disabled = val;
114  return *this;
115  }
116 
126  attr.pinned = val;
127  return *this;
128  }
129 
144 #if HAVE_PERF_ATTR_EXCLUDE_HOST == 1
145  attr.exclude_host = val;
146 #endif
147  return *this;
148  }
149 
159  attr.exclude_hv = val;
160  return *this;
161  }
162 
164  struct perf_event_attr attr;
165 };
166 
171 {
172 public:
179  PerfKvmCounter(PerfKvmCounterConfig &config, pid_t tid);
189  pid_t tid, const PerfKvmCounter &parent);
193  PerfKvmCounter();
194  ~PerfKvmCounter();
195 
196 
206  void attach(PerfKvmCounterConfig &config, pid_t tid) {
207  attach(config, tid, -1);
208  }
209 
222  pid_t tid, const PerfKvmCounter &parent) {
223  attach(config, tid, parent.fd);
224  }
225 
227  void detach();
228 
230  bool attached() const { return fd != -1; }
231 
238  void start();
239 
246  void stop();
247 
264  void period(uint64_t period);
265 
278  void refresh(int refresh);
279 
283  uint64_t read() const;
284 
291  void enableSignals(pid_t tid, int signal);
292 
300  void enableSignals(int signal) { enableSignals(gettid(), signal); }
301 
302 private:
303  // Disallow copying
304  PerfKvmCounter(const PerfKvmCounter &that);
305  // Disallow assignment
307 
308  void attach(PerfKvmCounterConfig &config, pid_t tid, int group_fd);
309 
315  pid_t gettid();
316 
329  void mmapPerf(int pages);
330 
341  int fcntl(int cmd, long p1);
342  int fcntl(int cmd, void *p1) { return fcntl(cmd, (long)p1); }
355  int ioctl(int request, long p1);
356  int ioctl(int request, void *p1) { return ioctl(request, (long)p1); }
357  int ioctl(int request) { return ioctl(request, 0L); }
366  void read(void *buf, size_t size) const;
367 
372  int fd;
373 
375  struct perf_event_mmap_page *ringBuffer;
378 
380  long pageSize;
381 };
382 
383 #endif
void detach()
Detach a counter from PerfEvent.
Definition: perfevent.cc:95
int ioctl(int request, void *p1)
Definition: perfevent.hh:356
PerfKvmCounterConfig & pinned(bool val)
Force the group to be on the active all the time (i.e., disallow multiplexing).
Definition: perfevent.hh:125
long pageSize
Cached host page size.
Definition: perfevent.hh:380
struct perf_event_attr attr
Underlying perf_event_attr structure describing the counter.
Definition: perfevent.hh:164
Bitfield< 7, 0 > L
Definition: int.hh:59
uint64_t read() const
Read the current value of a counter.
Definition: perfevent.cc:137
PerfKvmCounter()
Create a new counter, but don't attach it.
Definition: perfevent.cc:83
struct perf_event_mmap_page * ringBuffer
Memory mapped PerfEvent sample ring buffer.
Definition: perfevent.hh:375
int fcntl(int cmd, void *p1)
Definition: perfevent.hh:342
void enableSignals(pid_t tid, int signal)
Enable signal delivery to a thread on counter overflow.
Definition: perfevent.cc:146
int fd
PerfEvent file descriptor associated with counter.
Definition: perfevent.hh:372
Bitfield< 63 > val
Definition: misc.hh:770
pid_t gettid()
Get the TID of the current thread.
Definition: perfevent.cc:178
void attach(PerfKvmCounterConfig &config, pid_t tid, const PerfKvmCounter &parent)
Attach a counter and make it a member of an existing counter group.
Definition: perfevent.hh:221
PerfKvmCounterConfig & wakeupEvents(uint32_t events)
Set the number of samples that need to be triggered before reporting data as being available on the p...
Definition: perfevent.hh:100
PerfKvmCounter & operator=(const PerfKvmCounter &that)
void refresh(int refresh)
Enable a counter for a fixed number of events.
Definition: perfevent.cc:130
PerfKvmCounterConfig(uint32_t type, uint64_t config)
Initialize PerfEvent counter configuration structure.
Definition: perfevent.cc:56
void mmapPerf(int pages)
MMAP the PerfEvent file descriptor.
Definition: perfevent.cc:184
void period(uint64_t period)
Update the period of an overflow counter.
Definition: perfevent.cc:123
int ringNumPages
Total number of pages in ring buffer.
Definition: perfevent.hh:377
PerfKvmCounterConfig & samplePeriod(uint64_t period)
Set the initial sample period (overflow count) of an event.
Definition: perfevent.hh:87
An instance of a performance counter.
Definition: perfevent.hh:170
void attach(PerfKvmCounterConfig &config, pid_t tid)
Attach a counter.
Definition: perfevent.hh:206
int ioctl(int request)
Definition: perfevent.hh:357
PerfKvmCounterConfig & exclude_host(bool val)
Exclude the events from the host (i.e., only include events from the guest system).
Definition: perfevent.hh:143
type
Definition: misc.hh:728
PerfKvmCounterConfig & disabled(bool val)
Don't start the performance counter automatically when attaching it.
Definition: perfevent.hh:112
int size()
Definition: pagetable.hh:146
PerfKvmCounterConfig & exclude_hv(bool val)
Exclude the hyper visor (i.e., only include events from the guest system).
Definition: perfevent.hh:158
PerfEvent counter configuration.
Definition: perfevent.hh:53
int ioctl(int request, long p1)
PerfEvent ioctl interface.
Definition: perfevent.cc:214
void stop()
Stop counting.
Definition: perfevent.cc:116
void start()
Start counting.
Definition: perfevent.cc:109
bool attached() const
Check if a counter is attached.
Definition: perfevent.hh:230
int fcntl(int cmd, long p1)
PerfEvent fnctl interface.
Definition: perfevent.cc:207
void enableSignals(int signal)
Enable signal delivery on counter overflow.
Definition: perfevent.hh:300

Generated on Fri Jun 9 2017 13:03:42 for gem5 by doxygen 1.8.6