Skip to content

Commit fe3cbfa

Browse files
committed
Separate into denki.rapl.sysfs and denki.rapl.msr, manpage fixes
1 parent db910f2 commit fe3cbfa

File tree

4 files changed

+80
-81
lines changed

4 files changed

+80
-81
lines changed

src/pmdas/denki/denki.c

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Denki (電気, Japanese for 'electricity'), PMDA for electricity related
33
* metrics
44
*
5-
* Copyright (c) 2012-2014,2017,2021-2024 Red Hat.
5+
* Copyright (c) 2012-2014,2017,2021-2025 Red Hat.
66
* Copyright (c) 1995,2004 Silicon Graphics, Inc. All Rights Reserved.
77
*
88
* This program is free software; you can redistribute it and/or modify it
@@ -842,8 +842,8 @@ static int read_batteries(void) {
842842
/*
843843
* Denki PMDA metrics
844844
*
845-
* denki.raplsysfs - energy counter from RAPL, read from sysfs
846-
* denki.raplmsr - energy counter from RAPL, read from msr registers
845+
* denki.rapl.sysfs - energy counter from RAPL, read from sysfs
846+
* denki.rapl.msr - energy counter from RAPL, read from msr registers
847847
* denki.bat.energy_now - <battery>/energy_now raw reading,
848848
* current battery charge in Wh
849849
* denki.bat.power_now - <battery>/power_now raw reading
@@ -858,49 +858,49 @@ static int read_batteries(void) {
858858
*/
859859

860860
static pmdaIndom indomtab[] = {
861-
#define RAPL_SYSFS_INDOM 0 /* serial number for RAPL sysfs instance domain */
861+
#define RAPL_SYSFS_INDOM 0 /* serial number for rapl.sysfs instance domain */
862862
{ RAPL_SYSFS_INDOM, 0, NULL },
863-
#define RAPL_MSR_INDOM 1 /* serial number for RAPL msr instance domain */
863+
#define RAPL_MSR_INDOM 1 /* serial number for rapl.msr instance domain */
864864
{ RAPL_MSR_INDOM, 0, NULL },
865-
#define ENERGYNOW_INDOM 2 /* serial number for energy_now instance domain */
866-
{ ENERGYNOW_INDOM, 0, NULL },
867-
#define POWERNOW_INDOM 3 /* serial number for power_now instance domain */
868-
{ POWERNOW_INDOM, 0, NULL },
869-
#define CAPACITY_INDOM 4 /* serial number for capacity instance domain */
870-
{ CAPACITY_INDOM, 0, NULL }
865+
#define BAT_ENERGYNOW_INDOM 2 /* serial number for bat.energy_now instance domain */
866+
{ BAT_ENERGYNOW_INDOM, 0, NULL },
867+
#define BAT_POWERNOW_INDOM 3 /* serial number for bat.power_now instance domain */
868+
{ BAT_POWERNOW_INDOM, 0, NULL },
869+
#define BAT_CAPACITY_INDOM 4 /* serial number for bat.capacity instance domain */
870+
{ BAT_CAPACITY_INDOM, 0, NULL }
871871
};
872872

873873
/* this is merely a convenience */
874874
static pmInDom *rapl_sysfs_indom = &indomtab[RAPL_SYSFS_INDOM].it_indom;
875875
static pmInDom *rapl_msr_indom = &indomtab[RAPL_MSR_INDOM].it_indom;
876-
static pmInDom *energynow_indom = &indomtab[ENERGYNOW_INDOM].it_indom;
877-
static pmInDom *powernow_indom = &indomtab[POWERNOW_INDOM].it_indom;
878-
static pmInDom *capacity_indom = &indomtab[CAPACITY_INDOM].it_indom;
876+
static pmInDom *bat_energynow_indom = &indomtab[BAT_ENERGYNOW_INDOM].it_indom;
877+
static pmInDom *bat_powernow_indom = &indomtab[BAT_POWERNOW_INDOM].it_indom;
878+
static pmInDom *bat_capacity_indom = &indomtab[BAT_CAPACITY_INDOM].it_indom;
879879

880880
/*
881881
* All metrics supported in this PMDA - one table entry for each.
882882
*/
883883

884884
static pmdaMetric metrictab[] = {
885-
/* rapl sysfs */
885+
/* rapl.sysfs */
886886
{ NULL,
887887
{ PMDA_PMID(0,0), PM_TYPE_U64, RAPL_SYSFS_INDOM, PM_SEM_COUNTER,
888888
PMDA_PMUNITS(0,0,0,0,0,0) }, },
889-
/* rapl msr */
889+
/* rapl.msr */
890890
{ NULL,
891-
{ PMDA_PMID(1,0), PM_TYPE_U64, RAPL_MSR_INDOM, PM_SEM_COUNTER,
891+
{ PMDA_PMID(0,1), PM_TYPE_U64, RAPL_MSR_INDOM, PM_SEM_COUNTER,
892892
PMDA_PMUNITS(0,0,0,0,0,0) }, },
893893
/* bat.energy_now */
894894
{ NULL,
895-
{ PMDA_PMID(2,0), PM_TYPE_DOUBLE, ENERGYNOW_INDOM, PM_SEM_INSTANT,
895+
{ PMDA_PMID(1,0), PM_TYPE_DOUBLE, BAT_ENERGYNOW_INDOM, PM_SEM_INSTANT,
896896
PMDA_PMUNITS(0,0,0,0,0,0) }, },
897897
/* bat.power_now */
898898
{ NULL,
899-
{ PMDA_PMID(2,1), PM_TYPE_DOUBLE, POWERNOW_INDOM, PM_SEM_INSTANT,
899+
{ PMDA_PMID(1,1), PM_TYPE_DOUBLE, BAT_POWERNOW_INDOM, PM_SEM_INSTANT,
900900
PMDA_PMUNITS(0,0,0,0,0,0) }, },
901901
/* bat.capacity */
902902
{ NULL,
903-
{ PMDA_PMID(2,2), PM_TYPE_32, CAPACITY_INDOM, PM_SEM_INSTANT,
903+
{ PMDA_PMID(1,2), PM_TYPE_32, BAT_CAPACITY_INDOM, PM_SEM_INSTANT,
904904
PMDA_PMUNITS(0,0,0,0,0,0) }, }
905905
};
906906

@@ -972,21 +972,15 @@ denki_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
972972

973973
if (cluster == 0) {
974974
switch (item) {
975-
case 0: /* rapl sysfs */
975+
case 0: /* rapl.sysfs */
976976
if ((sts = pmdaCacheLookup(*rapl_sysfs_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
977977
if (sts < 0)
978978
pmNotifyErr(LOG_ERR, "pmdaCacheLookup failed: inst=%d: %s", inst, pmErrStr(sts));
979979
return PM_ERR_INST;
980980
}
981981
atom->ull = lookup_rapl_dom(inst)/1000000;
982982
break;
983-
default:
984-
return PM_ERR_PMID;
985-
}
986-
}
987-
else if (cluster == 1) {
988-
switch (item) {
989-
case 0: /* rapl msr */
983+
case 1: /* rapl.msr */
990984
if ((sts = pmdaCacheLookup(*rapl_msr_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
991985
if (sts < 0)
992986
pmNotifyErr(LOG_ERR, "pmdaCacheLookup failed: inst=%d: %s", inst, pmErrStr(sts));
@@ -1013,26 +1007,26 @@ denki_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
10131007
return PM_ERR_PMID;
10141008
}
10151009
}
1016-
else if (cluster == 2) {
1010+
else if (cluster == 1) {
10171011
switch (item) {
10181012
case 0: /* denki.bat.energy_now */
1019-
if ((sts = pmdaCacheLookup(*energynow_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
1013+
if ((sts = pmdaCacheLookup(*bat_energynow_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
10201014
if (sts < 0)
10211015
pmNotifyErr(LOG_ERR, "pmdaCacheLookup failed: inst=%d: %s", inst, pmErrStr(sts));
10221016
return PM_ERR_INST;
10231017
}
10241018
atom->d = energy_now[inst]/energy_convert_factor[inst];
10251019
break;
10261020
case 1: /* denki.bat.power_now */
1027-
if ((sts = pmdaCacheLookup(*powernow_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
1021+
if ((sts = pmdaCacheLookup(*bat_powernow_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
10281022
if (sts < 0)
10291023
pmNotifyErr(LOG_ERR, "pmdaCacheLookup failed: inst=%d: %s", inst, pmErrStr(sts));
10301024
return PM_ERR_INST;
10311025
}
10321026
atom->d = power_now[inst]/1000000.0;
10331027
break;
10341028
case 2: /* denki.bat.capacity */
1035-
if ((sts = pmdaCacheLookup(*capacity_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
1029+
if ((sts = pmdaCacheLookup(*bat_capacity_indom, inst, NULL, NULL)) != PMDA_CACHE_ACTIVE) {
10361030
if (sts < 0)
10371031
pmNotifyErr(LOG_ERR, "pmdaCacheLookup failed: inst=%d: %s", inst, pmErrStr(sts));
10381032
return PM_ERR_INST;
@@ -1244,21 +1238,21 @@ denki_bat_init(void)
12441238
pmsprintf(tmp,sizeof(tmp),"battery-%d",battery);
12451239

12461240
/* bat.energy_now */
1247-
sts = pmdaCacheStore(*energynow_indom, PMDA_CACHE_ADD, tmp, NULL);
1241+
sts = pmdaCacheStore(*bat_energynow_indom, PMDA_CACHE_ADD, tmp, NULL);
12481242
if (sts < 0) {
12491243
pmNotifyErr(LOG_ERR, "pmdaCacheStore failed: %s", pmErrStr(sts));
12501244
return;
12511245
}
12521246

12531247
/* bat.power_now */
1254-
sts = pmdaCacheStore(*powernow_indom, PMDA_CACHE_ADD, tmp, NULL);
1248+
sts = pmdaCacheStore(*bat_powernow_indom, PMDA_CACHE_ADD, tmp, NULL);
12551249
if (sts < 0) {
12561250
pmNotifyErr(LOG_ERR, "pmdaCacheStore failed: %s", pmErrStr(sts));
12571251
return;
12581252
}
12591253

12601254
/* bat.capacity */
1261-
sts = pmdaCacheStore(*capacity_indom, PMDA_CACHE_ADD, tmp, NULL);
1255+
sts = pmdaCacheStore(*bat_capacity_indom, PMDA_CACHE_ADD, tmp, NULL);
12621256
if (sts < 0) {
12631257
pmNotifyErr(LOG_ERR, "pmdaCacheStore failed: %s", pmErrStr(sts));
12641258
return;
@@ -1282,13 +1276,13 @@ denki_label(int ident, int type, pmLabelSet **lpp, pmdaExt *pmda)
12821276
case RAPL_MSR_INDOM:
12831277
pmdaAddLabels(lpp, "{\"indom_name\":\"raplmsr\"}");
12841278
break;
1285-
case ENERGYNOW_INDOM:
1279+
case BAT_ENERGYNOW_INDOM:
12861280
pmdaAddLabels(lpp, "{\"units\":\"watt hours\"}");
12871281
break;
1288-
case POWERNOW_INDOM:
1282+
case BAT_POWERNOW_INDOM:
12891283
pmdaAddLabels(lpp, "{\"units\":\"watt\"}");
12901284
break;
1291-
case CAPACITY_INDOM:
1285+
case BAT_CAPACITY_INDOM:
12921286
pmdaAddLabels(lpp, "{\"units\":\"percent\"}");
12931287
break;
12941288
}
@@ -1310,26 +1304,26 @@ __PMDA_INIT_CALL
13101304
denki_init(pmdaInterface *dp)
13111305
{
13121306
if (isDSO) {
1313-
int sep = pmPathSeparator();
1314-
1315-
if (strcmp(rootpath, "/") == 0) {
1316-
/*
1317-
* no -r ROOTPATH on the command line ... check for
1318-
* DENKI_SYSPATH in the environment
1319-
*/
1320-
char *envpath = getenv("DENKI_SYSPATH");
1321-
if (envpath)
1322-
pmsprintf(rootpath, sizeof(rootpath), "%s", envpath);
1323-
}
1324-
pmsprintf(mypath, sizeof(mypath), "%s%c" "denki" "%c" "help",
1325-
pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
1326-
pmdaDSO(dp, PMDA_INTERFACE_7, "denki DSO", mypath);
1307+
int sep = pmPathSeparator();
1308+
1309+
if (strcmp(rootpath, "/") == 0) {
1310+
/*
1311+
* no -r ROOTPATH on the command line ... check for
1312+
* DENKI_SYSPATH in the environment
1313+
*/
1314+
char *envpath = getenv("DENKI_SYSPATH");
1315+
if (envpath)
1316+
pmsprintf(rootpath, sizeof(rootpath), "%s", envpath);
1317+
}
1318+
pmsprintf(mypath, sizeof(mypath), "%s%c" "denki" "%c" "help",
1319+
pmGetConfig("PCP_PMDAS_DIR"), sep, sep);
1320+
pmdaDSO(dp, PMDA_INTERFACE_7, "denki DSO", mypath);
13271321
} else {
1328-
pmSetProcessIdentity(username);
1322+
pmSetProcessIdentity(username);
13291323
}
13301324

13311325
if (dp->status != 0)
1332-
return;
1326+
return;
13331327

13341328
dp->version.any.fetch = denki_fetch;
13351329
dp->version.any.instance = denki_instance;

src/pmdas/denki/help

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
@ 156.4 set of all batteries reporting capacity
3939

40-
@ denki.raplsysfs cummulative energy consumption of RAPL components
40+
@ denki.rapl.sysfs cummulative energy consumption of RAPL components
4141
Cummulative electrical power consumption of x86 hardware components
4242
in units of Joules.
4343

@@ -47,7 +47,7 @@ Joules / second, or Watts.
4747
The RAPL modules offered by the system are available as metric
4848
instances.
4949

50-
@ denki.raplmsr cummulative energy consumption of RAPL components
50+
@ denki.rapl.msr cummulative energy consumption of RAPL components
5151
Cummulative electrical power consumption of x86 hardware components
5252
in units of Joules.
5353

src/pmdas/denki/pmdadenki.1

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
.\"
2-
.\" Copyright (c) 2021-2024 Red Hat.
3-
.\"
1+
'\"macro stdmacro
2+
.\"
3+
.\" Copyright (c) 2021-2025 Red Hat.
4+
.\"
45
.\" This program is free software; you can redistribute it and/or modify it
56
.\" under the terms of the GNU General Public License as published by the
67
.\" Free Software Foundation; either version 2 of the License, or (at your
78
.\" option) any later version.
8-
.\"
9+
.\"
910
.\" This program is distributed in the hope that it will be useful, but
1011
.\" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1112
.\" or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1213
.\" for more details.
13-
.\"
14-
.TH "PMDADENKI" "1" "PCP" "Performance Co-Pilot" ""
15-
.SH "NAME"
14+
.\"
15+
.TH PMDADENKI 1 "PCP" "Performance Co-Pilot"
16+
.SH NAME
1617
\f3pmdadenki\f1 \- metrics related to the systems electrical consumption
17-
.SH "SYNOPSIS"
18+
.SH SYNOPSIS
1819
\f3$PCP_PMDAS_DIR/denki/pmdadenki\f1
1920
[\f3\-d\f1 \f2domain\f1]
2021
[\f3\-l\f1 \f2logfile\f1]
21-
.SH "DESCRIPTION"
22+
.SH DESCRIPTION
2223
.B pmdadenki
2324
is a Performance Metrics Domain Agent (PMDA) which extracts
2425
electricity related performance metrics.
25-
.PP
26+
.PP
2627
Currently, metrics from RAPL (on Intel cpus) and battery
2728
charge values are available, if supported by the hardware.
28-
.PP
29+
.PP
2930
.B \-l
3031
Location of the log file. By default, a log file named
3132
.I denki.log
@@ -42,28 +43,28 @@ The
4243
.B denki
4344
PMDA is installed and available by default on Linux.
4445
If you want to undo the installation, do the following as root:
45-
.PP
46+
.PP
4647
.ft CR
47-
.nf
48+
.nf
4849
.in +0.5i
4950
# cd $PCP_PMDAS_DIR/denki
5051
# ./Remove
5152
.in
52-
.fi
53+
.fi
5354
.ft 1
54-
.PP
55+
.PP
5556
If you want to establish access to the names, help text and values for the
5657
denki metrics once more, after removal, do the following as root:
57-
.PP
58+
.PP
5859
.ft CR
59-
.nf
60+
.nf
6061
.in +0.5i
6162
# cd $PCP_PMDAS_DIR/denki
6263
# ./Install
6364
.in
64-
.fi
65+
.fi
6566
.ft 1
66-
.PP
67+
.PP
6768
.B pmdadenki
6869
is launched by
6970
.BR pmcd (1)
@@ -117,5 +118,5 @@ as described in
117118
and
118119
.BR pcp.env (5).
119120

120-
.\" control lines for scripts/man\-spell
121+
.\" control lines for scripts/man-spell
121122
.\" +ok+ pmdadenki denki RAPL cpus

src/pmdas/denki/pmns

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
*/
1616

1717
denki {
18-
raplsysfs DENKI:0:0
19-
raplmsr DENKI:1:0
18+
rapl
2019
bat
2120
}
2221

22+
denki.rapl {
23+
sysfs DENKI:0:0
24+
msr DENKI:0:1
25+
}
26+
2327
denki.bat {
24-
energy_now DENKI:2:0
25-
power_now DENKI:2:1
26-
capacity DENKI:2:2
28+
energy_now DENKI:1:0
29+
power_now DENKI:1:1
30+
capacity DENKI:1:2
2731
}

0 commit comments

Comments
 (0)