gem5  v22.1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
gem5::PerfKvmCounter Class Reference

An instance of a performance counter. More...

#include <perfevent.hh>

Public Member Functions

 PerfKvmCounter (PerfKvmCounterConfig &config, pid_t tid)
 Create and attach a new counter group. More...
 
 PerfKvmCounter (PerfKvmCounterConfig &config, pid_t tid, const PerfKvmCounter &parent)
 Create and attach a new counter and make it a member of an exist counter group. More...
 
 PerfKvmCounter ()
 Create a new counter, but don't attach it. More...
 
 ~PerfKvmCounter ()
 
void attach (PerfKvmCounterConfig &config, pid_t tid)
 Attach a counter. More...
 
void attach (PerfKvmCounterConfig &config, pid_t tid, const PerfKvmCounter &parent)
 Attach a counter and make it a member of an existing counter group. More...
 
void detach ()
 Detach a counter from PerfEvent. More...
 
bool attached () const
 Check if a counter is attached. More...
 
void start ()
 Start counting. More...
 
void stop ()
 Stop counting. More...
 
void period (uint64_t period)
 Update the period of an overflow counter. More...
 
void refresh (int refresh)
 Enable a counter for a fixed number of events. More...
 
uint64_t read () const
 Read the current value of a counter. More...
 
void enableSignals (pid_t tid, int signal)
 Enable signal delivery to a thread on counter overflow. More...
 
void enableSignals (int signal)
 Enable signal delivery on counter overflow. More...
 

Private Member Functions

 PerfKvmCounter (const PerfKvmCounter &that)
 
PerfKvmCounteroperator= (const PerfKvmCounter &that)
 
void attach (PerfKvmCounterConfig &config, pid_t tid, int group_fd)
 
pid_t sysGettid ()
 Get the TID of the current thread. More...
 
void mmapPerf (int pages)
 MMAP the PerfEvent file descriptor. More...
 
void read (void *buf, size_t size) const
 Perform a read from the counter file descriptor. More...
 
int fcntl (int cmd, long p1)
 PerfEvent fnctl interface. More...
 
int fcntl (int cmd, void *p1)
 
int ioctl (int request, long p1)
 PerfEvent ioctl interface. More...
 
int ioctl (int request, void *p1)
 
int ioctl (int request)
 

Private Attributes

int fd
 PerfEvent file descriptor associated with counter. More...
 
struct perf_event_mmap_page * ringBuffer
 Memory mapped PerfEvent sample ring buffer. More...
 
int ringNumPages
 Total number of pages in ring buffer. More...
 
long pageSize
 Cached host page size. More...
 

Detailed Description

An instance of a performance counter.

Definition at line 171 of file perfevent.hh.

Constructor & Destructor Documentation

◆ PerfKvmCounter() [1/4]

gem5::PerfKvmCounter::PerfKvmCounter ( PerfKvmCounterConfig config,
pid_t  tid 
)

Create and attach a new counter group.

Parameters
configCounter configuration
tidThread to sample (0 indicates current thread)

Definition at line 71 of file perfevent.cc.

References attach().

◆ PerfKvmCounter() [2/4]

gem5::PerfKvmCounter::PerfKvmCounter ( PerfKvmCounterConfig config,
pid_t  tid,
const PerfKvmCounter parent 
)

Create and attach a new counter and make it a member of an exist counter group.

Parameters
configCounter configuration
tidThread to sample (0 indicates current thread)
parentGroup leader

Definition at line 77 of file perfevent.cc.

References attach().

◆ PerfKvmCounter() [3/4]

gem5::PerfKvmCounter::PerfKvmCounter ( )

Create a new counter, but don't attach it.

Definition at line 84 of file perfevent.cc.

◆ ~PerfKvmCounter()

gem5::PerfKvmCounter::~PerfKvmCounter ( )

Definition at line 89 of file perfevent.cc.

References attached(), and detach().

◆ PerfKvmCounter() [4/4]

gem5::PerfKvmCounter::PerfKvmCounter ( const PerfKvmCounter that)
private

Member Function Documentation

◆ attach() [1/3]

void gem5::PerfKvmCounter::attach ( PerfKvmCounterConfig config,
pid_t  tid 
)
inline

Attach a counter.

Note
This operation is only supported if the counter isn't already attached.
Parameters
configCounter configuration
tidThread to sample (0 indicates current thread)

Definition at line 207 of file perfevent.hh.

Referenced by attach(), PerfKvmCounter(), gem5::BaseKvmCPU::setupCounters(), and gem5::BaseKvmCPU::setupInstCounter().

◆ attach() [2/3]

void gem5::PerfKvmCounter::attach ( PerfKvmCounterConfig config,
pid_t  tid,
const PerfKvmCounter parent 
)
inline

Attach a counter and make it a member of an existing counter group.

Note
This operation is only supported if the counter isn't already attached.
Parameters
configCounter configuration
tidThread to sample (0 indicates current thread)
parentGroup leader

Definition at line 222 of file perfevent.hh.

References attach(), and fd.

◆ attach() [3/3]

void gem5::PerfKvmCounter::attach ( PerfKvmCounterConfig config,
pid_t  tid,
int  group_fd 
)
private

Definition at line 162 of file perfevent.cc.

References attached(), gem5::PerfKvmCounterConfig::attr, fd, mmapPerf(), and panic.

◆ attached()

bool gem5::PerfKvmCounter::attached ( ) const
inline

Check if a counter is attached.

Definition at line 231 of file perfevent.hh.

References fd.

Referenced by attach(), detach(), fcntl(), ioctl(), mmapPerf(), read(), gem5::BaseKvmCPU::setupCounters(), gem5::BaseKvmCPU::setupInstCounter(), and ~PerfKvmCounter().

◆ detach()

void gem5::PerfKvmCounter::detach ( )

◆ enableSignals() [1/2]

void gem5::PerfKvmCounter::enableSignals ( int  signal)
inline

Enable signal delivery on counter overflow.

Identical to enableSignals(pid_t) when called with the current TID as its parameter.

Parameters
signalSignal to send upon overflow

Definition at line 301 of file perfevent.hh.

References enableSignals(), and sysGettid().

Referenced by enableSignals().

◆ enableSignals() [2/2]

void gem5::PerfKvmCounter::enableSignals ( pid_t  tid,
int  signal 
)

Enable signal delivery to a thread on counter overflow.

Parameters
tidThread to deliver signal to
signalSignal to send upon overflow

Definition at line 147 of file perfevent.cc.

References fcntl(), and panic.

Referenced by gem5::PerfKvmTimer::PerfKvmTimer(), and gem5::BaseKvmCPU::setupInstCounter().

◆ fcntl() [1/2]

int gem5::PerfKvmCounter::fcntl ( int  cmd,
long  p1 
)
private

PerfEvent fnctl interface.

Parameters
cmdfcntl command
p1Request parameter
Returns
-1 on error (error number in errno), ioctl dependent value otherwise.

Definition at line 219 of file perfevent.cc.

References attached(), and fd.

Referenced by enableSignals().

◆ fcntl() [2/2]

int gem5::PerfKvmCounter::fcntl ( int  cmd,
void *  p1 
)
inlineprivate

Definition at line 343 of file perfevent.hh.

References fcntl().

Referenced by fcntl().

◆ ioctl() [1/3]

int gem5::PerfKvmCounter::ioctl ( int  request)
inlineprivate

Definition at line 358 of file perfevent.hh.

References ioctl(), and gem5::X86ISA::L.

Referenced by ioctl().

◆ ioctl() [2/3]

int gem5::PerfKvmCounter::ioctl ( int  request,
long  p1 
)
private

PerfEvent ioctl interface.

Parameters
requestPerfEvent request
p1Optional request parameter
Returns
-1 on error (error number in errno), ioctl dependent value otherwise.

Definition at line 226 of file perfevent.cc.

References attached(), and fd.

Referenced by period(), refresh(), start(), and stop().

◆ ioctl() [3/3]

int gem5::PerfKvmCounter::ioctl ( int  request,
void *  p1 
)
inlineprivate

Definition at line 357 of file perfevent.hh.

References ioctl().

Referenced by ioctl().

◆ mmapPerf()

void gem5::PerfKvmCounter::mmapPerf ( int  pages)
private

MMAP the PerfEvent file descriptor.

Note
We currently don't use the ring buffer, but PerfEvent requires this to be mapped for overflow handling to work.
Overflow handling requires at least one buf_page to be mapped.
Parameters
pagesnumber of pages in circular sample buffer. Must be an even power of 2.

Definition at line 196 of file perfevent.cc.

References attached(), fd, pageSize, panic, ringBuffer, and ringNumPages.

Referenced by attach().

◆ operator=()

PerfKvmCounter& gem5::PerfKvmCounter::operator= ( const PerfKvmCounter that)
private

◆ period()

void gem5::PerfKvmCounter::period ( uint64_t  period)

Update the period of an overflow counter.

Warning
This ioctl has some pretty bizarre semantics. It seems like the new period isn't effective until after the next counter overflow. If you use this method to change the sample period, you will see one sample with the old period and then start sampling with the new period. This problem was fixed for ARM in version 3.7 of the kernel.
This method doesn't work at all on some 2.6.3x kernels since it has inverted check for the return value when copying parameters from userspace.
Parameters
periodOverflow period in events

Definition at line 124 of file perfevent.cc.

References ioctl(), and panic.

Referenced by gem5::PerfKvmTimer::arm().

◆ read() [1/2]

uint64_t gem5::PerfKvmCounter::read ( ) const

Read the current value of a counter.

Definition at line 138 of file perfevent.cc.

Referenced by gem5::BaseKvmCPU::getHostCycles(), gem5::BaseKvmCPU::kvmRun(), and read().

◆ read() [2/2]

void gem5::PerfKvmCounter::read ( void *  buf,
size_t  size 
) const
private

Perform a read from the counter file descriptor.

Parameters
bufDestination buffer
sizeAmount of data to read

Definition at line 233 of file perfevent.cc.

References attached(), fd, panic, and read().

◆ refresh()

void gem5::PerfKvmCounter::refresh ( int  refresh)

Enable a counter for a fixed number of events.

When this method is called, perf event enables the counter if it was disabled. It then leaves the counter enabled until it has overflowed a refresh times.

Note
This does not update the period of the counter.
Parameters
refreshNumber of overflows before disabling the counter.

Definition at line 131 of file perfevent.cc.

References ioctl(), and panic.

Referenced by gem5::PerfKvmTimer::arm().

◆ start()

void gem5::PerfKvmCounter::start ( )

Start counting.

Note
If this counter is a group leader, it will start the entire group.

Definition at line 110 of file perfevent.cc.

References ioctl(), and panic.

Referenced by gem5::BaseKvmCPU::kvmRun().

◆ stop()

void gem5::PerfKvmCounter::stop ( )

Stop counting.

Note
If this counter is a group leader, it will stop the entire group.

Definition at line 117 of file perfevent.cc.

References ioctl(), and panic.

Referenced by gem5::PerfKvmTimer::disarm(), and gem5::BaseKvmCPU::kvmRun().

◆ sysGettid()

pid_t gem5::PerfKvmCounter::sysGettid ( )
private

Get the TID of the current thread.

Returns
Current thread's TID

Definition at line 190 of file perfevent.cc.

Referenced by enableSignals().

Member Data Documentation

◆ fd

int gem5::PerfKvmCounter::fd
private

PerfEvent file descriptor associated with counter.

-1 if not attached to PerfEvent.

Definition at line 373 of file perfevent.hh.

Referenced by attach(), attached(), detach(), fcntl(), ioctl(), mmapPerf(), and read().

◆ pageSize

long gem5::PerfKvmCounter::pageSize
private

Cached host page size.

Definition at line 381 of file perfevent.hh.

Referenced by detach(), and mmapPerf().

◆ ringBuffer

struct perf_event_mmap_page* gem5::PerfKvmCounter::ringBuffer
private

Memory mapped PerfEvent sample ring buffer.

Definition at line 376 of file perfevent.hh.

Referenced by detach(), and mmapPerf().

◆ ringNumPages

int gem5::PerfKvmCounter::ringNumPages
private

Total number of pages in ring buffer.

Definition at line 378 of file perfevent.hh.

Referenced by detach(), and mmapPerf().


The documentation for this class was generated from the following files:

Generated on Wed Dec 21 2022 10:23:13 for gem5 by doxygen 1.9.1