gem5  v20.1.0.0
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 
38 #ifndef __CPU_KVM_PERFEVENT_HH__
39 #define __CPU_KVM_PERFEVENT_HH__
40 
41 #include <linux/perf_event.h>
42 #include <sys/types.h>
43 
44 #include <inttypes.h>
45 
46 #include "config/have_perf_attr_exclude_host.hh"
47 
52 {
53  public:
74  PerfKvmCounterConfig(uint32_t type, uint64_t config);
76 
85  PerfKvmCounterConfig &samplePeriod(uint64_t period) {
86  attr.freq = 0;
87  attr.sample_period = period;
88  return *this;
89  }
90 
98  PerfKvmCounterConfig &wakeupEvents(uint32_t events) {
99  attr.watermark = 0;
100  attr.wakeup_events = events;
101  return *this;
102  }
103 
111  attr.disabled = val;
112  return *this;
113  }
114 
124  attr.pinned = val;
125  return *this;
126  }
127 
142 #if HAVE_PERF_ATTR_EXCLUDE_HOST == 1
143  attr.exclude_host = val;
144 #endif
145  return *this;
146  }
147 
157  attr.exclude_hv = val;
158  return *this;
159  }
160 
162  struct perf_event_attr attr;
163 };
164 
169 {
170 public:
177  PerfKvmCounter(PerfKvmCounterConfig &config, pid_t tid);
187  pid_t tid, const PerfKvmCounter &parent);
191  PerfKvmCounter();
192  ~PerfKvmCounter();
193 
194 
204  void attach(PerfKvmCounterConfig &config, pid_t tid) {
205  attach(config, tid, -1);
206  }
207 
220  pid_t tid, const PerfKvmCounter &parent) {
221  attach(config, tid, parent.fd);
222  }
223 
225  void detach();
226 
228  bool attached() const { return fd != -1; }
229 
236  void start();
237 
244  void stop();
245 
262  void period(uint64_t period);
263 
276  void refresh(int refresh);
277 
281  uint64_t read() const;
282 
289  void enableSignals(pid_t tid, int signal);
290 
298  void enableSignals(int signal) { enableSignals(sysGettid(), signal); }
299 
300 private:
301  // Disallow copying
302  PerfKvmCounter(const PerfKvmCounter &that);
303  // Disallow assignment
305 
306  void attach(PerfKvmCounterConfig &config, pid_t tid, int group_fd);
307 
313  pid_t sysGettid();
314 
327  void mmapPerf(int pages);
328 
339  int fcntl(int cmd, long p1);
340  int fcntl(int cmd, void *p1) { return fcntl(cmd, (long)p1); }
353  int ioctl(int request, long p1);
354  int ioctl(int request, void *p1) { return ioctl(request, (long)p1); }
355  int ioctl(int request) { return ioctl(request, 0L); }
364  void read(void *buf, size_t size) const;
365 
370  int fd;
371 
373  struct perf_event_mmap_page *ringBuffer;
376 
378  long pageSize;
379 };
380 
381 #endif
PerfKvmCounter
An instance of a performance counter.
Definition: perfevent.hh:168
X86ISA::L
Bitfield< 7, 0 > L
Definition: int.hh:57
PerfKvmCounter::operator=
PerfKvmCounter & operator=(const PerfKvmCounter &that)
PerfKvmCounterConfig::PerfKvmCounterConfig
PerfKvmCounterConfig(uint32_t type, uint64_t config)
Initialize PerfEvent counter configuration structure.
Definition: perfevent.cc:54
PerfKvmCounter::sysGettid
pid_t sysGettid()
Get the TID of the current thread.
Definition: perfevent.cc:187
PerfKvmCounterConfig::exclude_host
PerfKvmCounterConfig & exclude_host(bool val)
Exclude the events from the host (i.e., only include events from the guest system).
Definition: perfevent.hh:141
PerfKvmCounter::mmapPerf
void mmapPerf(int pages)
MMAP the PerfEvent file descriptor.
Definition: perfevent.cc:193
PerfKvmCounter::fd
int fd
PerfEvent file descriptor associated with counter.
Definition: perfevent.hh:370
PerfKvmCounterConfig::samplePeriod
PerfKvmCounterConfig & samplePeriod(uint64_t period)
Set the initial sample period (overflow count) of an event.
Definition: perfevent.hh:85
type
uint8_t type
Definition: inet.hh:421
PerfKvmCounterConfig::wakeupEvents
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:98
PerfKvmCounter::detach
void detach()
Detach a counter from PerfEvent.
Definition: perfevent.cc:93
PerfKvmCounterConfig::attr
struct perf_event_attr attr
Underlying perf_event_attr structure describing the counter.
Definition: perfevent.hh:162
PerfKvmCounter::fcntl
int fcntl(int cmd, long p1)
PerfEvent fnctl interface.
Definition: perfevent.cc:216
PerfKvmCounter::pageSize
long pageSize
Cached host page size.
Definition: perfevent.hh:378
PerfKvmCounter::ringBuffer
struct perf_event_mmap_page * ringBuffer
Memory mapped PerfEvent sample ring buffer.
Definition: perfevent.hh:373
PerfKvmCounterConfig
PerfEvent counter configuration.
Definition: perfevent.hh:51
PerfKvmCounter::period
void period(uint64_t period)
Update the period of an overflow counter.
Definition: perfevent.cc:121
PerfKvmCounter::enableSignals
void enableSignals(pid_t tid, int signal)
Enable signal delivery to a thread on counter overflow.
Definition: perfevent.cc:144
PerfKvmCounter::start
void start()
Start counting.
Definition: perfevent.cc:107
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
PerfKvmCounter::attach
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:219
PerfKvmCounter::ioctl
int ioctl(int request, void *p1)
Definition: perfevent.hh:354
PerfKvmCounter::stop
void stop()
Stop counting.
Definition: perfevent.cc:114
PerfKvmCounter::read
uint64_t read() const
Read the current value of a counter.
Definition: perfevent.cc:135
PerfKvmCounter::enableSignals
void enableSignals(int signal)
Enable signal delivery on counter overflow.
Definition: perfevent.hh:298
PerfKvmCounter::ioctl
int ioctl(int request)
Definition: perfevent.hh:355
PerfKvmCounterConfig::disabled
PerfKvmCounterConfig & disabled(bool val)
Don't start the performance counter automatically when attaching it.
Definition: perfevent.hh:110
PerfKvmCounter::PerfKvmCounter
PerfKvmCounter()
Create a new counter, but don't attach it.
Definition: perfevent.cc:81
PerfKvmCounter::attached
bool attached() const
Check if a counter is attached.
Definition: perfevent.hh:228
PerfKvmCounter::attach
void attach(PerfKvmCounterConfig &config, pid_t tid)
Attach a counter.
Definition: perfevent.hh:204
PerfKvmCounterConfig::~PerfKvmCounterConfig
~PerfKvmCounterConfig()
Definition: perfevent.cc:63
PerfKvmCounter::~PerfKvmCounter
~PerfKvmCounter()
Definition: perfevent.cc:86
PerfKvmCounterConfig::exclude_hv
PerfKvmCounterConfig & exclude_hv(bool val)
Exclude the hyper visor (i.e., only include events from the guest system).
Definition: perfevent.hh:156
PerfKvmCounter::ringNumPages
int ringNumPages
Total number of pages in ring buffer.
Definition: perfevent.hh:375
PerfKvmCounter::fcntl
int fcntl(int cmd, void *p1)
Definition: perfevent.hh:340
PerfKvmCounterConfig::pinned
PerfKvmCounterConfig & pinned(bool val)
Force the group to be on the active all the time (i.e., disallow multiplexing).
Definition: perfevent.hh:123
PerfKvmCounter::refresh
void refresh(int refresh)
Enable a counter for a fixed number of events.
Definition: perfevent.cc:128
PerfKvmCounter::ioctl
int ioctl(int request, long p1)
PerfEvent ioctl interface.
Definition: perfevent.cc:223

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17