gem5  v22.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 
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
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
PerfEvent counter configuration.
Definition: perfevent.hh:55
PerfKvmCounterConfig & disabled(bool val)
Don't start the performance counter automatically when attaching it.
Definition: perfevent.hh:113
struct perf_event_attr attr
Underlying perf_event_attr structure describing the counter.
Definition: perfevent.hh:165
PerfKvmCounterConfig & samplePeriod(uint64_t period)
Set the initial sample period (overflow count) of an event.
Definition: perfevent.hh:88
PerfKvmCounterConfig & exclude_hv(bool val)
Exclude the hyper visor (i.e., only include events from the guest system).
Definition: perfevent.hh:159
PerfKvmCounterConfig & pinned(bool val)
Force the group to be on the active all the time (i.e., disallow multiplexing).
Definition: perfevent.hh:126
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
PerfKvmCounterConfig & exclude_host(bool val)
Exclude the events from the host (i.e., only include events from the guest system).
Definition: perfevent.hh:144
PerfKvmCounterConfig(uint32_t type, uint64_t config)
Initialize PerfEvent counter configuration structure.
Definition: perfevent.cc:57
An instance of a performance counter.
Definition: perfevent.hh:172
int ringNumPages
Total number of pages in ring buffer.
Definition: perfevent.hh:378
pid_t sysGettid()
Get the TID of the current thread.
Definition: perfevent.cc:190
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
int fcntl(int cmd, long p1)
PerfEvent fnctl interface.
Definition: perfevent.cc:219
void enableSignals(int signal)
Enable signal delivery on counter overflow.
Definition: perfevent.hh:301
void mmapPerf(int pages)
MMAP the PerfEvent file descriptor.
Definition: perfevent.cc:196
PerfKvmCounter()
Create a new counter, but don't attach it.
Definition: perfevent.cc:84
struct perf_event_mmap_page * ringBuffer
Memory mapped PerfEvent sample ring buffer.
Definition: perfevent.hh:376
long pageSize
Cached host page size.
Definition: perfevent.hh:381
void period(uint64_t period)
Update the period of an overflow counter.
Definition: perfevent.cc:124
uint64_t read() const
Read the current value of a counter.
Definition: perfevent.cc:138
int ioctl(int request, void *p1)
Definition: perfevent.hh:357
PerfKvmCounter & operator=(const PerfKvmCounter &that)
void attach(PerfKvmCounterConfig &config, pid_t tid)
Attach a counter.
Definition: perfevent.hh:207
int fd
PerfEvent file descriptor associated with counter.
Definition: perfevent.hh:373
void detach()
Detach a counter from PerfEvent.
Definition: perfevent.cc:96
int ioctl(int request, long p1)
PerfEvent ioctl interface.
Definition: perfevent.cc:226
int ioctl(int request)
Definition: perfevent.hh:358
bool attached() const
Check if a counter is attached.
Definition: perfevent.hh:231
PerfKvmCounter(const PerfKvmCounter &that)
void refresh(int refresh)
Enable a counter for a fixed number of events.
Definition: perfevent.cc:131
int fcntl(int cmd, void *p1)
Definition: perfevent.hh:343
void enableSignals(pid_t tid, int signal)
Enable signal delivery to a thread on counter overflow.
Definition: perfevent.cc:147
void start()
Start counting.
Definition: perfevent.cc:110
void stop()
Stop counting.
Definition: perfevent.cc:117
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 7, 0 > L
Definition: int.hh:62
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1