@@ -810,6 +810,7 @@ class PCM_API PCM
810810 std::vector<std::shared_ptr<CounterWidthExtender> > energy_status;
811811 std::vector<std::shared_ptr<CounterWidthExtender> > dram_energy_status;
812812 std::vector<std::shared_ptr<CounterWidthExtender> > pp_energy_status;
813+ std::shared_ptr<CounterWidthExtender> system_energy_status;
813814 std::vector<std::vector<std::pair<UncorePMU, UncorePMU>>> cxlPMUs; // socket X CXL ports X UNIT {0,1}
814815
815816 std::vector<std::shared_ptr<CounterWidthExtender> > memory_bw_local;
@@ -2510,6 +2511,25 @@ class PCM_API PCM
25102511 );
25112512 }
25122513
2514+ bool systemEnergyMetricAvailable () const
2515+ {
2516+ return (
2517+ useSKLPath ()
2518+ || cpu_family_model == PCM::SKX
2519+ || cpu_family_model == PCM::ICX
2520+ || cpu_family_model == PCM::ADL
2521+ || cpu_family_model == PCM::RPL
2522+ || cpu_family_model == PCM::MTL
2523+ || cpu_family_model == PCM::LNL
2524+ || cpu_family_model == PCM::ARL
2525+ || cpu_family_model == PCM::SPR
2526+ || cpu_family_model == PCM::EMR
2527+ || cpu_family_model == PCM::GNR
2528+ || cpu_family_model == PCM::SRF
2529+ || cpu_family_model == PCM::GRR
2530+ );
2531+ }
2532+
25132533 bool packageThermalMetricsAvailable () const
25142534 {
25152535 return packageEnergyMetricsAvailable ();
@@ -3368,6 +3388,25 @@ uint64 getConsumedEnergy(const int powerPlane, const CounterStateType& before, c
33683388 return after.PPEnergyStatus [powerPlane] - before.PPEnergyStatus [powerPlane];
33693389}
33703390
3391+ /* ! \brief Returns energy consumed by system
3392+ \param before CPU counter state before the experiment
3393+ \param after CPU counter state after the experiment
3394+ */
3395+ template <class CounterStateType >
3396+ uint64 getSystemConsumedEnergy (const CounterStateType& before, const CounterStateType& after)
3397+ {
3398+ return after.systemEnergyStatus - before.systemEnergyStatus ;
3399+ }
3400+
3401+ /* ! \brief Checks is systemEnergyStatusValid is valid in the state
3402+ * \param s CPU counter state
3403+ */
3404+ template <class CounterStateType >
3405+ bool systemEnergyStatusValid (const CounterStateType& s)
3406+ {
3407+ return s.systemEnergyStatus != 0 ;
3408+ }
3409+
33713410/* ! \brief Returns energy consumed by DRAM (measured in internal units)
33723411 \param before CPU counter state before the experiment
33733412 \param after CPU counter state after the experiment
@@ -3435,6 +3474,31 @@ double getConsumedJoules(const int powerPlane, const CounterStateType& before, c
34353474 return double (getConsumedEnergy (powerPlane, before, after)) * m->getJoulesPerEnergyUnit ();
34363475}
34373476
3477+ /* ! \brief Returns Joules consumed by system
3478+ \param before CPU counter state before the experiment
3479+ \param after CPU counter state after the experiment
3480+ */
3481+ template <class CounterStateType >
3482+ double getSystemConsumedJoules (const CounterStateType& before, const CounterStateType& after)
3483+ {
3484+ PCM* m = PCM::getInstance ();
3485+ if (!m) return -1 .;
3486+
3487+ auto unit = m->getJoulesPerEnergyUnit ();
3488+
3489+ switch (m->getCPUFamilyModel ())
3490+ {
3491+ case PCM::SPR:
3492+ case PCM::EMR:
3493+ case PCM::GNR:
3494+ case PCM::SRF:
3495+ unit = 1.0 ;
3496+ break ;
3497+ }
3498+
3499+ return double (getSystemConsumedEnergy (before, after)) * unit;
3500+ }
3501+
34383502/* ! \brief Returns Joules consumed by DRAM
34393503 \param before CPU counter state before the experiment
34403504 \param after CPU counter state after the experiment
@@ -3860,11 +3924,14 @@ class SystemCounterState : public SocketCounterState
38603924 friend std::vector<uint64> getPCICFGEvent (const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
38613925 friend std::vector<uint64> getMMIOEvent (const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
38623926 friend std::vector<uint64> getPMTEvent (const PCM::RawEventEncoding& eventEnc, const SystemCounterState& before, const SystemCounterState& after);
3927+ template <class CounterStateType > friend bool systemEnergyStatusValid (const CounterStateType& s);
3928+ template <class CounterStateType > friend uint64 getSystemConsumedEnergy (const CounterStateType& before, const CounterStateType& after);
38633929
38643930 std::vector<std::vector<uint64> > incomingQPIPackets; // each 64 byte
38653931 std::vector<std::vector<uint64> > outgoingQPIFlits; // idle or data/non-data flits depending on the architecture
38663932 std::vector<std::vector<uint64> > TxL0Cycles;
38673933 uint64 uncoreTSC;
3934+ uint64 systemEnergyStatus;
38683935 std::unordered_map<PCM::RawEventEncoding, std::vector<uint64> , PCM::PCICFGRegisterEncodingHash, PCM::PCICFGRegisterEncodingCmp> PCICFGValues{};
38693936 std::unordered_map<PCM::RawEventEncoding, std::vector<uint64>, PCM::MMIORegisterEncodingHash, PCM::MMIORegisterEncodingCmp> MMIOValues{};
38703937 std::unordered_map<PCM::RawEventEncoding, std::vector<uint64>, PCM::PMTRegisterEncodingHash2> PMTValues{};
@@ -3890,7 +3957,8 @@ class SystemCounterState : public SocketCounterState
38903957 friend uint64 getOutgoingQPILinkBytes (uint32 socketNr, uint32 linkNr, const SystemCounterState & now);
38913958
38923959 SystemCounterState () :
3893- uncoreTSC (0 )
3960+ uncoreTSC (0 ),
3961+ systemEnergyStatus (0 )
38943962 {
38953963 PCM * m = PCM::getInstance ();
38963964 accel_counters.resize (m->getNumberofAccelCounters ());
@@ -3922,6 +3990,7 @@ class SystemCounterState : public SocketCounterState
39223990
39233991 return *this ;
39243992 }
3993+
39253994 virtual ~ SystemCounterState() {}
39263995};
39273996
0 commit comments