gem5  v21.1.0.2
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 
48 namespace gem5
49 {
50 
55 {
56  public:
77  PerfKvmCounterConfig(uint32_t type, uint64_t config);
79 
88  PerfKvmCounterConfig &samplePeriod(uint64_t period) {
89  attr.freq = 0;
90  attr.sample_period = period;
91  return *this;
92  }
93 
101  PerfKvmCounterConfig &wakeupEvents(uint32_t events) {
102  attr.watermark = 0;
103  attr.wakeup_events = events;
104  return *this;
105  }
106 
114  attr.disabled = val;
115  return *this;
116  }
117 
127  attr.pinned = val;
128  return *this;
129  }
130 
145 #if HAVE_PERF_ATTR_EXCLUDE_HOST == 1
146  attr.exclude_host = val;
147 #endif
148  return *this;
149  }
150 
160  attr.exclude_hv = val;
161  return *this;
162  }
163 
165  struct perf_event_attr attr;
166 };
167 
172 {
173 public:
180  PerfKvmCounter(PerfKvmCounterConfig &config, pid_t tid);
190  pid_t tid, const PerfKvmCounter &parent);
194  PerfKvmCounter();
195  ~PerfKvmCounter();
196 
197 
207  void attach(PerfKvmCounterConfig &config, pid_t tid) {
208  attach(config, tid, -1);
209  }
210 
223  pid_t tid, const PerfKvmCounter &parent) {
224  attach(config, tid, parent.fd);
225  }
226 
228  void detach();
229 
231  bool attached() const { return fd != -1; }
232 
239  void start();
240 
247  void stop();
248 
265  void period(uint64_t period);
266 
279  void refresh(int refresh);
280 
284  uint64_t read() const;
285 
292  void enableSignals(pid_t tid, int signal);
293 
301  void enableSignals(int signal) { enableSignals(sysGettid(), signal); }
302 
303 private:
304  // Disallow copying
305  PerfKvmCounter(const PerfKvmCounter &that);
306  // Disallow assignment
308 
309  void attach(PerfKvmCounterConfig &config, pid_t tid, int group_fd);
310 
316  pid_t sysGettid();
317 
330  void mmapPerf(int pages);
331 
342  int fcntl(int cmd, long p1);
343  int fcntl(int cmd, void *p1) { return fcntl(cmd, (long)p1); }
356  int ioctl(int request, long p1);
357  int ioctl(int request, void *p1) { return ioctl(request, (long)p1); }
358  int ioctl(int request) { return ioctl(request, 0L); }
367  void read(void *buf, size_t size) const;
368 
373  int fd;
374 
376  struct perf_event_mmap_page *ringBuffer;
379 
381  long pageSize;
382 };
383 
384 } // namespace gem5
385 
386 #endif
gem5::PerfKvmCounter::period
void period(uint64_t period)
Update the period of an overflow counter.
Definition: perfevent.cc:124
gem5::PerfKvmCounterConfig::attr
struct perf_event_attr attr
Underlying perf_event_attr structure describing the counter.
Definition: perfevent.hh:165
gem5::PerfKvmCounter::PerfKvmCounter
PerfKvmCounter()
Create a new counter, but don't attach it.
Definition: perfevent.cc:84
gem5::X86ISA::L
Bitfield< 7, 0 > L
Definition: int.hh:59
gem5::PerfKvmCounterConfig::PerfKvmCounterConfig
PerfKvmCounterConfig(uint32_t type, uint64_t config)
Initialize PerfEvent counter configuration structure.
Definition: perfevent.cc:57
gem5::PerfKvmCounter::attached
bool attached() const
Check if a counter is attached.
Definition: perfevent.hh:231
gem5::PerfKvmCounterConfig::pinned
PerfKvmCounterConfig & pinned(bool val)
Force the group to be on the active all the time (i.e., disallow multiplexing).
Definition: perfevent.hh:126
gem5::PerfKvmCounter
An instance of a performance counter.
Definition: perfevent.hh:171
gem5::PerfKvmCounter::~PerfKvmCounter
~PerfKvmCounter()
Definition: perfevent.cc:89
gem5::PerfKvmCounter::fcntl
int fcntl(int cmd, long p1)
PerfEvent fnctl interface.
Definition: perfevent.cc:219
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:775
gem5::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:222
gem5::PerfKvmCounter::refresh
void refresh(int refresh)
Enable a counter for a fixed number of events.
Definition: perfevent.cc:131
gem5::PerfKvmCounter::detach
void detach()
Detach a counter from PerfEvent.
Definition: perfevent.cc:96
gem5::PerfKvmCounter::stop
void stop()
Stop counting.
Definition: perfevent.cc:117
gem5::PerfKvmCounter::ringNumPages
int ringNumPages
Total number of pages in ring buffer.
Definition: perfevent.hh:378
gem5::PerfKvmCounter::ioctl
int ioctl(int request)
Definition: perfevent.hh:358
gem5::PerfKvmCounter::enableSignals
void enableSignals(pid_t tid, int signal)
Enable signal delivery to a thread on counter overflow.
Definition: perfevent.cc:147
gem5::PerfKvmCounter::ioctl
int ioctl(int request, long p1)
PerfEvent ioctl interface.
Definition: perfevent.cc:226
gem5::PerfKvmCounter::mmapPerf
void mmapPerf(int pages)
MMAP the PerfEvent file descriptor.
Definition: perfevent.cc:196
gem5::X86ISA::type
type
Definition: misc.hh:733
gem5::PerfKvmCounter::attach
void attach(PerfKvmCounterConfig &config, pid_t tid)
Attach a counter.
Definition: perfevent.hh:207
gem5::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:101
gem5::PerfKvmCounterConfig::~PerfKvmCounterConfig
~PerfKvmCounterConfig()
Definition: perfevent.cc:66
gem5::PerfKvmCounter::sysGettid
pid_t sysGettid()
Get the TID of the current thread.
Definition: perfevent.cc:190
gem5::PerfKvmCounter::operator=
PerfKvmCounter & operator=(const PerfKvmCounter &that)
gem5::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:144
gem5::PerfKvmCounter::fd
int fd
PerfEvent file descriptor associated with counter.
Definition: perfevent.hh:373
gem5::PerfKvmCounterConfig::exclude_hv
PerfKvmCounterConfig & exclude_hv(bool val)
Exclude the hyper visor (i.e., only include events from the guest system).
Definition: perfevent.hh:159
gem5::PerfKvmCounter::read
uint64_t read() const
Read the current value of a counter.
Definition: perfevent.cc:138
gem5::PerfKvmCounter::fcntl
int fcntl(int cmd, void *p1)
Definition: perfevent.hh:343
gem5::PerfKvmCounterConfig::samplePeriod
PerfKvmCounterConfig & samplePeriod(uint64_t period)
Set the initial sample period (overflow count) of an event.
Definition: perfevent.hh:88
gem5::PerfKvmCounter::ioctl
int ioctl(int request, void *p1)
Definition: perfevent.hh:357
gem5::PerfKvmCounterConfig
PerfEvent counter configuration.
Definition: perfevent.hh:54
gem5::PerfKvmCounter::enableSignals
void enableSignals(int signal)
Enable signal delivery on counter overflow.
Definition: perfevent.hh:301
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::PerfKvmCounter::start
void start()
Start counting.
Definition: perfevent.cc:110
gem5::PerfKvmCounter::pageSize
long pageSize
Cached host page size.
Definition: perfevent.hh:381
gem5::PerfKvmCounterConfig::disabled
PerfKvmCounterConfig & disabled(bool val)
Don't start the performance counter automatically when attaching it.
Definition: perfevent.hh:113
gem5::PerfKvmCounter::ringBuffer
struct perf_event_mmap_page * ringBuffer
Memory mapped PerfEvent sample ring buffer.
Definition: perfevent.hh:376

Generated on Tue Sep 21 2021 12:25:00 for gem5 by doxygen 1.8.17