gem5 v25.0.0.1
Loading...
Searching...
No Matches
pmu.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2014, 2017-2019, 2022-2023, 2025 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#include "arch/arm/pmu.hh"
39
40#include "arch/arm/isa.hh"
41#include "arch/arm/utility.hh"
42#include "base/trace.hh"
43#include "cpu/base.hh"
44#include "debug/Checkpoint.hh"
45#include "debug/PMUVerbose.hh"
46#include "dev/arm/base_gic.hh"
48#include "params/ArmPMU.hh"
49#include "sim/sim_exit.hh"
50
51namespace gem5
52{
53
54namespace ArmISA {
55
56const RegVal PMU::reg_pmcr_wr_mask = 0x39;
57
58PMU::PMU(const ArmPMUParams &p)
61 reg_pmcnten(0), reg_pmcr(0),
65 maximumCounterCount(p.eventCounters),
67 cycleCounterEventId(p.cycleEventId),
68 swIncrementEvent(nullptr),
70 interrupt(nullptr),
73 stats(this)
74{
75 DPRINTF(PMUVerbose, "Initializing the PMU.\n");
76
77 if (maximumCounterCount > 31) {
78 fatal("The PMU can only accept 31 counters, %d counters requested.\n",
80 }
81
82 for (const auto& [key, value] : p.statCounters) {
83 statCounters.insert(key);
84 }
85
86 warn_if(!p.interrupt, "ARM PMU: No interrupt specified, interrupt " \
87 "delivery disabled.\n");
88
89 /* Setup the performance counter ID registers */
90 reg_pmcr_conf.imp = 0x41; // ARM Ltd.
91 reg_pmcr_conf.idcode = 0x00;
92 reg_pmcr_conf.n = p.eventCounters;
93
94 // Setup the hard-coded cycle counter, which is equivalent to
95 // architected counter event type 0x11.
96 cycleCounter.eventId = enums::EventTypeId::CPU_CYCLES;
97}
98
100{
101}
102
103void
105{
106 DPRINTF(PMUVerbose, "Assigning PMU to ContextID %i.\n", tc->contextId());
107 const auto &pmu_params = static_cast<const ArmPMUParams &>(params());
108
109 if (pmu_params.interrupt)
110 interrupt = pmu_params.interrupt->get(tc);
111}
112
113void
115{
116 auto old_event = eventMap.find(id);
117 DPRINTF(PMUVerbose, "PMU: Adding SW increment event with id '0x%x'\n", id);
118
119 if (swIncrementEvent) {
120 fatal_if(old_event == eventMap.end() ||
121 old_event->second != swIncrementEvent,
122 "Trying to add a software increment event with multiple"
123 "IDs. This is not supported.\n");
124 return;
125 }
126
127 fatal_if(old_event != eventMap.end(), "An event with id %d has "
128 "been previously defined\n", id);
129
130 auto pmu_stats = statCounters.find(id) != statCounters.end() ?
131 &stats : nullptr;
132 swIncrementEvent = std::make_shared<SWIncrementEvent>(id, pmu_stats);
134 registerEvent(id);
135}
136
137void
138PMU::addEventProbe(EventTypeId id, SimObject *obj, const char *probe_name)
139{
140
141 DPRINTF(PMUVerbose, "PMU: Adding Probe Driven event with id '0x%x'"
142 "as probe %s:%s\n", id, obj->name(), probe_name);
143
144 std::shared_ptr<RegularEvent> event;
145 auto event_entry = eventMap.find(id);
146 if (event_entry == eventMap.end()) {
147 auto pmu_stats = statCounters.find(id) != statCounters.end() ?
148 &stats : nullptr;
149 event = std::make_shared<RegularEvent>(id, pmu_stats);
150 eventMap[id] = event;
151 } else {
152 event = std::dynamic_pointer_cast<RegularEvent>(event_entry->second);
153 fatal_if(!event, "Event with id %d is not probe driven\n", id);
154 }
155 event->addMicroarchitectureProbe(obj, probe_name);
156
157 registerEvent(id);
158}
159
160void
162{
163 // Flag the event as available in the corresponding PMCEID register if it
164 // is an architected event.
165 if (id < 0x20) {
166 reg_pmceid0 |= ((uint64_t)1) << id;
167 } else if (id > 0x20 && id < 0x40) {
168 reg_pmceid1 |= ((uint64_t)1) << (id - 0x20);
169 } else if (id >= 0x4000 && id < 0x4020) {
170 reg_pmceid0 |= ((uint64_t)1) << (id - 0x4000 + 32);
171 } else if (id >= 0x4020 && id < 0x4040) {
172 reg_pmceid1 |= ((uint64_t)1) << (id - 0x4020 + 32);
173 }
174}
175
176void
178{
179 // Re-attach enabled counters after a resume in case they changed.
181}
182
183void
185{
186
187 // at this stage all probe configurations are done
188 // counters can be configured
189 for (uint32_t index = 0; index < maximumCounterCount; index++) {
190 counters.emplace_back(*this, index, use64bitCounters);
191 }
192
193 std::shared_ptr<PMUEvent> event = getEvent(cycleCounterEventId);
194 panic_if(!event, "core cycle event is not present\n");
195 cycleCounter.enabled = true;
196 cycleCounter.attach(event);
197
198 // By enabling the event we are actually connecting the
199 // listener (See PMU::RegularEvent::enable)
200 for (auto event_id : statCounters) {
201 if (auto stat_event = getEvent(event_id); stat_event) {
202 stat_event->enable();
203 }
204 }
205}
206
207void
209{
210 DPRINTF(PMUVerbose, "setMiscReg(%s, 0x%x)\n",
212
213 switch (unflattenMiscReg(misc_reg)) {
214 case MISCREG_PMCR_EL0:
215 case MISCREG_PMCR:
217 return;
218
221 reg_pmcnten |= val;
223 return;
224
227 reg_pmcnten &= ~val;
229 return;
230
232 case MISCREG_PMOVSR:
234 return;
235
237 case MISCREG_PMSWINC:
238 if (swIncrementEvent) {
239 swIncrementEvent->write(val);
240 }
241 return;
242
244 case MISCREG_PMCCNTR:
245 cycleCounter.setValue(val);
246 return;
247
249 case MISCREG_PMSELR:
250 reg_pmselr = val;
251 return;
252 //TODO: implement MISCREF_PMCEID{2,3}
254 case MISCREG_PMCEID0:
256 case MISCREG_PMCEID1:
257 // Ignore writes
258 return;
259
260 case MISCREG_PMEVTYPER0_EL0...MISCREG_PMEVTYPER5_EL0:
262 return;
263 case MISCREG_PMEVTYPER0...MISCREG_PMEVTYPER5:
265 return;
266
269 DPRINTF(PMUVerbose, "Setting PMCCFILTR: 0x%x\n", val);
271 return;
272
276 DPRINTF(PMUVerbose, "Setting counter type: "
277 "[PMSELR: 0x%x, PMSELER.sel: 0x%x, EVTYPER: 0x%x]\n",
280 return;
281
282 case MISCREG_PMEVCNTR0_EL0...MISCREG_PMEVCNTR5_EL0:
284 return;
285 case MISCREG_PMEVCNTR0...MISCREG_PMEVCNTR5:
287 return;
288
292 return;
293
296 // TODO
297 break;
298
301 reg_pminten |= val;
302 return;
303
306 reg_pminten &= ~val;
307 return;
308
310 case MISCREG_PMOVSSET:
312 return;
313
314 default:
315 panic("Unexpected PMU register: %i\n", miscRegName[misc_reg]);
316 }
317
318 warn("Not doing anything for write to miscreg %s\n",
320}
321
322RegVal
324{
326 DPRINTF(PMUVerbose, "readMiscReg(%s): 0x%x\n",
328 return val;
329}
330
331RegVal
333{
335 switch (misc_reg) {
336 case MISCREG_PMCR_EL0:
337 case MISCREG_PMCR:
339
344 return reg_pmcnten;
345
348 case MISCREG_PMOVSR: // Overflow Status Register
349 case MISCREG_PMOVSSET:
350 return reg_pmovsr;
351
353 case MISCREG_PMSWINC: // Software Increment Register (RAZ)
354 return 0;
355
357 case MISCREG_PMSELR:
358 return reg_pmselr;
359
361 return reg_pmceid0;
362
364 return reg_pmceid1;
365
366 //TODO: implement MISCREF_PMCEID{2,3}
367 case MISCREG_PMCEID0: // Common Event ID register
368 return reg_pmceid0 & 0xFFFFFFFF;
369
370 case MISCREG_PMCEID1: // Common Event ID register
371 return reg_pmceid1 & 0xFFFFFFFF;
372
374 case MISCREG_PMCCNTR:
375 return cycleCounter.getValue();
376
377 case MISCREG_PMEVTYPER0_EL0...MISCREG_PMEVTYPER5_EL0:
379 case MISCREG_PMEVTYPER0...MISCREG_PMEVTYPER5:
381
385
390
391 case MISCREG_PMEVCNTR0_EL0...MISCREG_PMEVCNTR5_EL0:
392 return getCounterValue(misc_reg - MISCREG_PMEVCNTR0_EL0) & 0xFFFFFFFF;
393 case MISCREG_PMEVCNTR0...MISCREG_PMEVCNTR5:
394 return getCounterValue(misc_reg - MISCREG_PMEVCNTR0) & 0xFFFFFFFF;
395
398 return getCounterValue(reg_pmselr.sel) & 0xFFFFFFFF;
399
402 // TODO
403 return 0;
404
409 return reg_pminten;
410
411 default:
412 panic("Unexpected PMU register: %i\n", miscRegName[misc_reg]);
413 }
414
415 warn("Not doing anything for read from miscreg %s\n",
417 return 0;
418}
419
420void
422{
423 DPRINTF(PMUVerbose, "Set Control Reg 0x%08x.\n", val);
424
425 if (val.p) {
426 DPRINTF(PMUVerbose, "PMU reset all events to zero.\n");
428 }
429
430 if (val.c) {
431 DPRINTF(PMUVerbose, "PMU reset cycle counter to zero.\n");
432 cycleCounter.setValue(0);
433 }
434
435 // Reset the clock remainder if divide by 64-mode is toggled.
436 if (reg_pmcr.d != val.d)
437 clock_remainder = 0;
438
439 // Optionally exit the simulation on various PMU control events.
440 // Exit on enable/disable takes precedence over exit on reset.
441 if (exitOnPMUControl) {
442 if (!reg_pmcr.e && val.e) {
443 inform("Exiting simulation: PMU enable detected");
444 exitSimLoop("performance counter enabled", 0);
445 } else if (reg_pmcr.e && !val.e) {
446 inform("Exiting simulation: PMU disable detected");
447 exitSimLoop("performance counter disabled", 0);
448 } else if (val.p) {
449 inform("Exiting simulation: PMU reset detected");
450 exitSimLoop("performance counter reset", 0);
451 }
452 }
453
456}
457
458void
460{
461 const bool global_enable(reg_pmcr.e);
462
463 for (int i = 0; i < counters.size(); ++i) {
464 CounterState &ctr(counters[i]);
465 const bool enable(global_enable && (reg_pmcnten & (1 << i)));
466 if (ctr.enabled != enable) {
467 ctr.enabled = enable;
468 updateCounter(ctr);
469 }
470 }
471
472 const bool ccntr_enable(global_enable && (reg_pmcnten & (1 << PMCCNTR)));
473 if (cycleCounter.enabled != ccntr_enable) {
474 cycleCounter.enabled = ccntr_enable;
476 }
477}
478
479void
481{
482 // Check if there is already a probe (either non-empty
483 // userCounters list, or pmuStats enabled)
484 if (userCounters.empty() && !pmuStats) {
485 enable();
486 }
487 userCounters.insert(user);
489}
490
491void
493{
494 for (auto& counter: userCounters) {
495 counter->add(val);
496 }
497
498 if (pmuStats) {
499 pmuStats->add(id, val);
500 }
501}
502
503void
505{
506 userCounters.erase(user);
507
508 // Do not destroy the probe if pmuStats are listening
509 // to the event
510 if (userCounters.empty() && !pmuStats) {
511 disable();
512 }
513}
514
515void
517{
518 parentEvent->increment(val);
519}
520
521void
523{
524 for (auto& subEvents: microArchitectureEventSet) {
525 ProbeManager *pm = subEvents.first->getProbeManager();
526 ProbePoint *probe = pm->getFirstProbePoint(subEvents.second);
527 // The PMU currently handles explicit PMU probes as well as
528 // cache events. For any further types of events we will need
529 // to handle them in this function.
530 if (dynamic_cast<probing::PMU *>(probe)) {
531 attachedProbePointList.push_back(
532 pm->connect<RegularProbe>(this, subEvents.second));
533 } else if (dynamic_cast<ProbePointArg<CacheAccessProbeArg> *>(probe)) {
534 attachedProbePointList.push_back(
535 pm->connect<CacheProbe>(this, subEvents.second));
536 } else {
537 panic("Unsupported probe kind for event %s", probe->getName());
538 }
539 }
540}
541
542void
547
548bool
550{
551 assert(pmu.isa);
552
553 const PMEVTYPER_t filter(this->filter);
554 const ExceptionLevel el(pmu.isa->currEL());
555 const bool secure(pmu.isa->inSecureState());
556
557 switch (el) {
558 case EL0:
559 return secure ? filter.u : (filter.u != filter.nsu);
560
561 case EL1:
562 return secure ? filter.p : (filter.p != filter.nsk);
563
564 case EL2:
565 return !filter.nsh;
566
567 case EL3:
568 return filter.p != filter.m;
569
570 default:
571 panic("Unexpected execution level in PMU::isFiltered.\n");
572 }
573}
574
575void
577{
578 if (sourceEvent) {
579 sourceEvent->detachEvent(this);
580 sourceEvent = nullptr;
581 } else {
582 DPRINTFS(PMUVerbose, &pmu,
583 "detaching event %d not currently attached to any event"
584 " [counterId = %d]\n", eventId, counterId);
585 }
586}
587
588void
589PMU::CounterState::attach(const std::shared_ptr<PMUEvent> &event)
590{
591 if (!resetValue) {
592 value = 0;
593 resetValue = true;
594 }
596 sourceEvent->attachEvent(this);
597}
598
599uint64_t
601{
602 if (sourceEvent) {
603 sourceEvent->updateAttachedCounters();
604 } else {
605 debugCounter("attempted to get value from a counter without"
606 " an associated event\n");
607 }
608 return value;
609}
610
611void
613{
614 value = val;
615 resetValue = true;
616
617 if (sourceEvent) {
618 sourceEvent->updateAttachedCounters();
619 } else {
620 debugCounter("attempted to set value from a counter without"
621 " an associated event\n");
622 }
623}
624
625void
627{
628 if (!ctr.enabled) {
629 DPRINTF(PMUVerbose, "updateCounter(%i): Disabling counter\n",
630 ctr.getCounterId());
631 ctr.detach();
632
633 } else {
634 DPRINTF(PMUVerbose, "updateCounter(%i): Enable event id 0x%x\n",
635 ctr.getCounterId(), ctr.eventId);
636
637 auto sourceEvent = eventMap.find(ctr.eventId);
638 if (sourceEvent == eventMap.end()) {
639 warn("Can't enable PMU counter of type '0x%x': "
640 "No such event type.\n", ctr.eventId);
641 ctr.detach();
642 } else {
643 ctr.attach(sourceEvent->second);
644 }
645 }
646}
647
648
649void
651{
652 for (CounterState &ctr : counters)
653 ctr.setValue(0);
654}
655
656void
657PMU::setCounterValue(CounterId id, uint64_t val)
658{
659 if (!isValidCounter(id)) {
660 warn_once("Can't change counter value: Counter %i does not exist.\n",
661 id);
662 return;
663 }
664
665 CounterState &ctr(getCounter(id));
666 ctr.setValue(val);
667}
668
669PMU::PMEVTYPER_t
671{
672 if (!isValidCounter(id))
673 return 0;
674
675 const CounterState &cs(getCounter(id));
676 PMEVTYPER_t type(cs.filter);
677
678 type.evtCount = cs.eventId;
679
680 return type;
681}
682
683void
684PMU::setCounterTypeRegister(CounterId id, PMEVTYPER_t val)
685{
686 DPRINTF(PMUVerbose, "Set Event [%d] = 0x%08x\n", id, val);
687 if (!isValidCounter(id)) {
688 warn_once("Can't change counter type: Counter %i does not exist.\n",
689 id);
690 return;
691 }
692
693 CounterState &ctr(getCounter(id));
694 const EventTypeId old_event_id(ctr.eventId);
695
696 ctr.filter = val;
697
698 // If PMCCNTR Register, do not change event type. PMCCNTR can
699 // count processor cycles only. If we change the event type, we
700 // need to update the probes the counter is using.
701 if (id != PMCCNTR && old_event_id != val.evtCount) {
702 ctr.eventId = val.evtCount;
703 updateCounter(ctr);
704 }
705}
706
707void
709{
710 const bool int_old = reg_pmovsr != 0;
711 const bool int_new = new_val != 0;
712
713 reg_pmovsr = new_val;
714 if (int_old && !int_new) {
716 } else if (!int_old && int_new && (reg_pminten & reg_pmovsr)) {
718 }
719}
720
721void
723{
724 if (exitOnPMUInterrupt) {
725 inform("Exiting simulation: PMU interrupt detected");
726 exitSimLoop("performance counter interrupt", 0);
727 }
728 if (interrupt) {
729 DPRINTF(PMUVerbose, "Delivering PMU interrupt.\n");
730 interrupt->raise();
731 } else {
732 warn_once("Dropping PMU interrupt as no interrupt has "
733 "been specified\n");
734 }
735}
736
737void
739{
740 if (interrupt) {
741 DPRINTF(PMUVerbose, "Clearing PMU interrupt.\n");
742 interrupt->clear();
743 } else {
744 warn_once("Dropping PMU interrupt as no interrupt has "
745 "been specified\n");
746 }
747}
748
749void
751{
752 DPRINTF(Checkpoint, "Serializing Arm PMU\n");
753
763
764 for (size_t i = 0; i < counters.size(); ++i)
765 counters[i].serializeSection(cp, csprintf("counters.%i", i));
766
767 cycleCounter.serializeSection(cp, "cycleCounter");
768}
769
770void
772{
773 DPRINTF(Checkpoint, "Unserializing Arm PMU\n");
774
781
782 // Old checkpoints used to store the entire PMCEID value in a
783 // single 64-bit entry (reg_pmceid). The register was extended in
784 // ARMv8.1, so we now need to store it as two 64-bit registers.
786 paramIn(cp, "reg_pmceid", reg_pmceid0);
787
789 reg_pmceid1 = 0;
790
792
793 for (size_t i = 0; i < counters.size(); ++i)
794 counters[i].unserializeSection(cp, csprintf("counters.%i", i));
795
796 cycleCounter.unserializeSection(cp, "cycleCounter");
797}
798
799std::shared_ptr<PMU::PMUEvent>
801{
802 auto entry = eventMap.find(eventId);
803
804 if (entry == eventMap.end()) {
805 warn("event %d does not exist\n", eventId);
806 return nullptr;
807 } else {
808 return entry->second;
809 }
810}
811
812void
819
820void
827
828uint64_t
830{
831 uint64_t value_until_overflow;
832 if (overflow64) {
833 value_until_overflow = UINT64_MAX - value;
834 } else {
835 value_until_overflow = UINT32_MAX - (uint32_t)value;
836 }
837
838 if (isFiltered())
839 return value_until_overflow;
840
841 if (resetValue) {
842 delta = 0;
843 resetValue = false;
844 } else {
845 value += delta;
846 }
847
848 if (delta > value_until_overflow) {
849
850 // overflow situation detected
851 // flag the overflow occurence
852 pmu.reg_pmovsr |= (1 << counterId);
853
854 // Deliver a PMU interrupt if interrupt delivery is enabled
855 // for this counter.
856 if (pmu.reg_pminten & (1 << counterId)) {
857 pmu.raiseInterrupt();
858 }
859 return overflow64 ? UINT64_MAX : UINT32_MAX;
860 }
861 return value_until_overflow - delta + 1;
862}
863
864void
866{
867 for (auto& counter: userCounters) {
868 if (val & (0x1 << counter->getCounterId())) {
869 counter->add(1);
870 }
871 }
872}
873
875 : statistics::Group(parent), pmu(parent)
876{
877 auto params = static_cast<const ArmPMUParams&>(pmu->params());
878 for (const auto& [key, val] : params.statCounters) {
879 registerEvent(key, val.c_str());
880 }
881}
882
883void
884PMU::Stats::registerEvent(EventTypeId id, const char *stat_name)
885{
886 map.emplace(std::piecewise_construct,
887 std::forward_as_tuple(id),
888 std::forward_as_tuple(
889 this, stat_name,
891 stat_name));
892 map[id]
893 .precision(0);
894}
895
896void
897PMU::Stats::add(EventTypeId id, uint64_t value)
898{
899 if (auto it = map.find(id); it != map.end()) {
900 it->second += value;
901 } else {
902 panic("Couldn't increment event %d stat counter", id);
903 }
904}
905
906} // namespace ArmISA
907} // namespace gem5
#define DPRINTFS(x, s,...)
Definition trace.hh:216
#define DPRINTF(x,...)
Definition trace.hh:209
Base class for ARM GIC implementations.
void write(uint64_t val)
write on the sw increment register inducing an increment of the counters with this event selected acc...
Definition pmu.cc:865
std::shared_ptr< PMUEvent > getEvent(EventTypeId eventId)
Obtain the event of a given id.
Definition pmu.cc:800
void regProbeListeners() override
Register probe listeners for this object.
Definition pmu.cc:184
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition pmu.cc:771
void setControlReg(PMCR_t val)
PMCR write handling.
Definition pmu.cc:421
void raiseInterrupt()
Deliver a PMU interrupt to the GIC.
Definition pmu.cc:722
void addEventProbe(EventTypeId id, SimObject *obj, const char *name)
Definition pmu.cc:138
PMCR_t reg_pmcr_conf
Constant (configuration-dependent) part of the PMCR.
Definition pmu.hh:659
RegVal readMiscReg(int misc_reg) override
Read a register within the PMU.
Definition pmu.cc:323
RegVal reg_pmcnten
Performance Monitor Count Enable Register.
Definition pmu.hh:616
void clearInterrupt()
Clear a PMU interrupt.
Definition pmu.cc:738
uint64_t maximumCounterCount
The number of regular event counters.
Definition pmu.hh:643
static const RegVal reg_pmcr_wr_mask
PMCR write mask when accessed from the guest.
Definition pmu.hh:662
bool isFiltered(const CounterState &ctr) const
Check if a counter's settings allow it to be counted.
PMEVTYPER_t getCounterTypeRegister(CounterId id) const
Get the type and filter settings of a counter (PMEVTYPER)
Definition pmu.cc:670
unsigned clock_remainder
Remainder part when the clock counter is divided by 64.
Definition pmu.hh:640
uint64_t reg_pmceid1
Definition pmu.hh:637
void updateAllCounters()
Call updateCounter() for each counter in the PMU if the counter's state has changed.
Definition pmu.cc:459
void resetEventCounts()
Reset all event counters excluding the cycle counter to zero.
Definition pmu.cc:650
void setOverflowStatus(RegVal new_val)
Used for writing the Overflow Flag Status Register (SET/CLR)
Definition pmu.cc:708
PMSELR_t reg_pmselr
Performance Monitor Selection Register.
Definition pmu.hh:622
std::map< EventTypeId, std::shared_ptr< PMUEvent > > eventMap
List of event types supported by this PMU.
Definition pmu.hh:670
void addSoftwareIncrementEvent(EventTypeId id)
Definition pmu.cc:114
static const CounterId PMCCNTR
Cycle Count Register Number.
Definition pmu.hh:192
void setThreadContext(ThreadContext *tc) override
Definition pmu.cc:104
std::vector< CounterState > counters
State of all general-purpose counters supported by PMU.
Definition pmu.hh:646
void setCounterTypeRegister(CounterId id, PMEVTYPER_t type)
Set the type and filter settings of a performance counter (PMEVTYPER)
Definition pmu.cc:684
void drainResume() override
Resume execution after a successful drain.
Definition pmu.cc:177
PMU(const ArmPMUParams &p)
Definition pmu.cc:58
RegVal readMiscRegInt(int misc_reg)
Definition pmu.cc:332
std::set< EventTypeId > statCounters
Determine whether we merge event counting with the stats framework.
Definition pmu.hh:613
void setMiscReg(int misc_reg, RegVal val) override
Set a register within the PMU.
Definition pmu.cc:208
CounterState cycleCounter
State of the cycle counter.
Definition pmu.hh:649
uint64_t reg_pmceid0
Performance counter ID register.
Definition pmu.hh:636
const EventTypeId cycleCounterEventId
The id of the counter hardwired to the cpu cycle counter.
Definition pmu.hh:652
bool isValidCounter(CounterId id) const
Is this a valid counter ID?
Definition pmu.hh:548
PMCR_t reg_pmcr
Performance Monitor Control Register.
Definition pmu.hh:619
Bitfield< 1 > p
Definition pmu.hh:141
RegVal reg_pmovsr
Performance Monitor Overflow Status Register.
Definition pmu.hh:628
std::underlying_type_t< enums::EventTypeId > EventTypeId
Definition pmu.hh:101
ArmInterruptPin * interrupt
Performance monitor interrupt number.
Definition pmu.hh:665
void registerEvent(EventTypeId id)
Definition pmu.cc:161
CounterState & getCounter(CounterId id)
Return the state of a counter.
Definition pmu.hh:559
bool use64bitCounters
Determine whether to use 64-bit or 32-bit counters.
Definition pmu.hh:607
std::shared_ptr< SWIncrementEvent > swIncrementEvent
The event that implements the software increment.
Definition pmu.hh:655
uint64_t getCounterValue(CounterId id) const
Get the value of a performance counter.
Definition pmu.hh:232
bool exitOnPMUInterrupt
Exit simloop on PMU interrupt.
Definition pmu.hh:680
gem5::ArmISA::PMU::Stats stats
void setCounterValue(CounterId id, uint64_t val)
Set the value of a performance counter.
Definition pmu.cc:657
RegVal reg_pminten
Performance Monitor Interrupt Enable Register.
Definition pmu.hh:625
void updateCounter(CounterState &ctr)
Depending on counter configuration, add or remove the probes driving the counter.
Definition pmu.cc:626
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition pmu.cc:750
const bool exitOnPMUControl
Exit simloop on PMU reset or disable.
Definition pmu.hh:675
virtual std::string name() const
Definition named.hh:60
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition probe.hh:162
ProbeListenerPtr< Listener > connect(Args &&...args)
Definition probe.hh:198
ProbePoint * getFirstProbePoint(std::string_view point_name) const
Definition probe.cc:110
ProbePointArg generates a point for the class of Arg.
Definition probe.hh:273
ProbePoint base class; again used to simplify use of ProbePoints in containers and used as to define ...
Definition probe.hh:123
const std::string & getName() const
Definition probe.hh:132
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual ContextID contextId() const =0
This module implements the global system counter and the local per-CPU architected timers as specifie...
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:268
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:232
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:246
#define UNSERIALIZE_OPT_SCALAR(scalar)
Definition serialize.hh:582
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition serialize.cc:74
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition serialize.cc:81
const Params & params() const
SimObject(const Params &p)
Definition sim_object.cc:58
#define warn(...)
Definition logging.hh:288
#define warn_once(...)
Definition logging.hh:292
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition logging.hh:315
#define inform(...)
Definition logging.hh:289
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 33 > id
@ MISCREG_PMXEVTYPER_EL0
Definition misc.hh:805
@ MISCREG_PMEVTYPER0
Definition misc.hh:385
@ MISCREG_PMUSERENR
Definition misc.hh:393
@ MISCREG_PMSELR_EL0
Definition misc.hh:801
@ MISCREG_PMOVSSET
Definition misc.hh:396
@ MISCREG_PMXEVCNTR_EL0
Definition misc.hh:807
@ MISCREG_PMCCNTR_EL0
Definition misc.hh:804
@ MISCREG_PMINTENSET
Definition misc.hh:394
@ MISCREG_PMXEVTYPER
Definition misc.hh:378
@ MISCREG_PMEVTYPER0_EL0
Definition misc.hh:880
@ MISCREG_PMUSERENR_EL0
Definition misc.hh:808
@ MISCREG_PMCR
Definition misc.hh:369
@ MISCREG_PMEVCNTR0_EL0
Definition misc.hh:874
@ MISCREG_PMOVSR
Definition misc.hh:372
@ MISCREG_PMCNTENCLR
Definition misc.hh:371
@ MISCREG_PMCCFILTR_EL0
Definition misc.hh:806
@ MISCREG_PMSWINC_EL0
Definition misc.hh:800
@ MISCREG_PMINTENSET_EL1
Definition misc.hh:794
@ MISCREG_PMINTENCLR_EL1
Definition misc.hh:795
@ MISCREG_PMCCFILTR
Definition misc.hh:391
@ MISCREG_PMCEID1
Definition misc.hh:376
@ MISCREG_PMCNTENSET
Definition misc.hh:370
@ MISCREG_PMCEID0_EL0
Definition misc.hh:802
@ MISCREG_PMSELR
Definition misc.hh:374
@ MISCREG_PMXEVCNTR
Definition misc.hh:392
@ MISCREG_PMCEID0
Definition misc.hh:375
@ MISCREG_PMINTENCLR
Definition misc.hh:395
@ MISCREG_PMCNTENCLR_EL0
Definition misc.hh:798
@ MISCREG_PMSWINC
Definition misc.hh:373
@ MISCREG_PMCNTENSET_EL0
Definition misc.hh:797
@ MISCREG_PMEVCNTR0
Definition misc.hh:379
@ MISCREG_PMOVSCLR_EL0
Definition misc.hh:799
@ MISCREG_PMCCNTR
Definition misc.hh:377
@ MISCREG_PMCR_EL0
Definition misc.hh:796
@ MISCREG_PMCEID1_EL0
Definition misc.hh:803
@ MISCREG_PMXEVTYPER_PMCCFILTR
Definition misc.hh:108
@ MISCREG_PMOVSSET_EL0
Definition misc.hh:809
Bitfield< 3, 2 > el
Definition misc_types.hh:73
int unflattenMiscReg(int reg)
Definition misc.cc:738
const char *const miscRegName[]
Definition misc.hh:1849
Bitfield< 10, 5 > event
Bitfield< 30, 0 > index
Bitfield< 11 > enable
Definition misc.hh:1086
Bitfield< 63 > val
Definition misc.hh:804
ProbePointArg< uint64_t > PMU
PMU probe point.
Definition pmu.hh:59
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t RegVal
Definition types.hh:173
std::ostream CheckpointOut
Definition serialize.hh:66
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition types.cc:72
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
The "old style" exitSimLoop functions.
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568
State of a counter within the PMU.
Definition pmu.hh:445
bool resetValue
Flag keeping track if the counter has been reset.
Definition pmu.hh:525
void attach(const std::shared_ptr< PMUEvent > &event)
Attach this counter to an event.
Definition pmu.cc:589
PMEVTYPER_t filter
Filtering settings (evtCount is unused)
Definition pmu.hh:506
uint64_t value
Current value of the counter.
Definition pmu.hh:522
bool overflow64
Is this a 64-bit counter?
Definition pmu.hh:512
uint64_t counterId
id of the counter instance
Definition pmu.hh:519
void detach()
Detach the counter from its event.
Definition pmu.cc:576
EventTypeId eventId
Counter event ID.
Definition pmu.hh:503
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition pmu.cc:821
uint64_t getCounterId() const
Obtain the counter id.
Definition pmu.hh:483
uint64_t getValue() const
rReturn the counter value
Definition pmu.cc:600
std::shared_ptr< PMUEvent > sourceEvent
PmuEvent currently in use (if any)
Definition pmu.hh:516
bool enabled
Is the counter enabled?
Definition pmu.hh:509
uint64_t add(uint64_t delta)
Add an event count to the counter and check for overflow.
Definition pmu.cc:829
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition pmu.cc:813
void debugCounter(const char *mainString, Args &...args) const
Definition pmu.hh:530
void setValue(uint64_t val)
overwrite the value of the counter
Definition pmu.cc:612
void attachEvent(PMU::CounterState *user)
attach this event to a given counter
Definition pmu.cc:480
virtual void enable()=0
Enable the current event.
virtual void disable()=0
Disable the current event.
Stats *const pmuStats
True is event is reported as a stat.
Definition pmu.hh:352
std::set< PMU::CounterState * > userCounters
set of counters using this event
Definition pmu.hh:355
virtual void updateAttachedCounters()
Method called immediately before a counter access in order for the associated event to update its sta...
Definition pmu.hh:345
void detachEvent(PMU::CounterState *user)
detach this event from a given counter
Definition pmu.cc:504
virtual void increment(const uint64_t val)
notify an event increment of val units, all the attached counters' value is incremented by val units.
Definition pmu.cc:492
void notify(const uint64_t &val) override
Definition pmu.cc:516
std::set< EventTypeEntry > microArchitectureEventSet
The set of events driving the event value.
Definition pmu.hh:404
void enable() override
Enable the current event.
Definition pmu.cc:522
void disable() override
Disable the current event.
Definition pmu.cc:543
std::vector< ProbeListenerPtr<> > attachedProbePointList
Set of probe listeners tapping onto each of the input micro-arch events which compose this pmu event.
Definition pmu.hh:409
void registerEvent(EventTypeId id, const char *stat_name)
Definition pmu.cc:884
void add(EventTypeId id, uint64_t value)
Increment the map[id] stat by value.
Definition pmu.cc:897
Stats(PMU *parent)
Definition pmu.cc:874
std::unordered_map< EventTypeId, statistics::Scalar > map
Definition pmu.hh:695

Generated on Sat Oct 18 2025 08:06:37 for gem5 by doxygen 1.14.0