Skip to content
This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Commit 2f985b2

Browse files
committed
refactor(LibpfmHelper): adds methods to detects the PMU, the number of generic counters and the events available on the targeted CPU
We are now able to detect automatically the PMU with their number of counters that we can open simultaneously. This number is very useful to know exactly how many events that we can monitored at a the same time. feature(Libpfm): creates a generic formula for Libpfm and builds modules upon this generic formula This formula can be configured with a map of coefficients for each event which forms the formula. It represents the entire processor's consumption with several events.
1 parent 173c0fd commit 2f985b2

23 files changed

+866
-50
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ We all stand on the shoulders of giants and get by with a little help from our f
5050
* [Apache log4j2](http://logging.apache.org/log4j/2.x) (version 2.3 under [Apache 2 license](http://www.apache.org/licenses/LICENSE-2.0)), for logging outside actors.
5151
* [powerspy.scala](https://github.com/Spirals-Team/powerspy.scala) (version 1.2 under [AGPL license](http://www.gnu.org/licenses/agpl-3.0.html)), for using the [PowerSpy powermeter](http://www.alciom.com/en/products/powerspy2-en-gb-2.html).
5252
* [BridJ](https://code.google.com/p/bridj/) (version 0.7.0 under [3-clause BSD license](https://github.com/ochafik/nativelibs4java/blob/master/libraries/BridJ/LICENSE)), for system or C calls.
53+
* [JNA](https://github.com/twall/jna) (version 4.1.0 under [LGPL 2.1 license](https://github.com/twall/jna/blob/master/LGPL2.1)), for system or C calls.
5354
* [perfmon2](http://sourceforge.net/p/perfmon2/libpfm4/ci/master/tree) (version 4.6.0 under [MIT license](http://sourceforge.net/p/perfmon2/libpfm4/ci/master/tree/COPYING)), for accessing hardware performance counters.
5455
* [JFreeChart](http://www.jfree.org/jfreechart/) (version 1.0.19 under [LGPL license](https://www.gnu.org/licenses/lgpl.html)), for creation of interactive and animated charts.
5556
* [Scala IO](http://jesseeichar.github.io/scala-io-doc/0.4.3/index.html#!/overview) (version 0.4.3 under [3-clause BSD license](http://www.scala-lang.org/license.html)), for an extensions of IO.

powerapi-cli/src/main/scala/org/powerapi/app/PowerAPI.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.powerapi.{PowerMonitoring, PowerMeter}
3030
import org.powerapi.core.power._
3131
import org.powerapi.module.cpu.dvfs.CpuDvfsModule
3232
import org.powerapi.module.cpu.simple.{SigarCpuSimpleModule, ProcFSCpuSimpleModule}
33-
import org.powerapi.module.libpfm.{LibpfmHelper, LibpfmCoreProcessModule, LibpfmCoreModule}
33+
import org.powerapi.module.libpfm.{LibpfmModule, LibpfmHelper, LibpfmCoreProcessModule, LibpfmCoreModule, LibpfmProcessModule}
3434
import org.powerapi.module.powerspy.PowerSpyModule
3535
import scala.concurrent.duration.DurationInt
3636
import scala.sys
@@ -43,7 +43,7 @@ import scala.sys.process.stringSeqToProcess
4343
* @author <a href="mailto:l.huertas.pro@gmail.com">Loïc Huertas</a>
4444
*/
4545
object PowerAPI extends App {
46-
val modulesR = """(procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm-core|libpfm-core-process|powerspy|rapl)(,(procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm-core|libpfm-core-process|powerspy|rapl))*""".r
46+
val modulesR = """(procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm|libpfm-process|libpfm-core|libpfm-core-process|powerspy|rapl)(,(procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm|libpfm-process|libpfm-core|libpfm-core-process|powerspy|rapl))*""".r
4747
val aggR = """max|min|geomean|logsum|mean|median|stdev|sum|variance""".r
4848
val durationR = """\d+""".r
4949
val pidR = """(\d+)""".r
@@ -113,7 +113,7 @@ object PowerAPI extends App {
113113
|You can use different settings per software-defined power meter for some modules by using the optional prefix option.
114114
|Please, refer to the documentation inside the GitHub wiki for further details.
115115
|
116-
|usage: ./powerapi modules [procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm-core|libpfm-core-proces|powerspy|rapl,...] *--prefix [name]* \
116+
|usage: ./powerapi modules [procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm|libpfm-process|libpfm-core|libpfm-core-proces|powerspy|rapl,...] *--prefix [name]* \
117117
| monitor --frequency [ms] --targets [pid, ..., app, ...|all] --agg [max|min|geomean|logsum|mean|median|stdev|sum|variance] --[console,file [filepath],chart] \
118118
| duration [s]
119119
|
@@ -176,6 +176,8 @@ object PowerAPI extends App {
176176
case "procfs-cpu-simple" => ProcFSCpuSimpleModule()
177177
case "sigar-cpu-simple" => SigarCpuSimpleModule()
178178
case "cpu-dvfs" => CpuDvfsModule()
179+
case "libpfm" => LibpfmModule(powerMeterConf('prefix).asInstanceOf[Option[String]], libpfmHelper.get)
180+
case "libpfm-process" => LibpfmProcessModule(powerMeterConf('prefix).asInstanceOf[Option[String]], libpfmHelper.get)
179181
case "libpfm-core" => LibpfmCoreModule(powerMeterConf('prefix).asInstanceOf[Option[String]], libpfmHelper.get)
180182
case "libpfm-core-process" => LibpfmCoreProcessModule(powerMeterConf('prefix).asInstanceOf[Option[String]], libpfmHelper.get)
181183
case "powerspy" => PowerSpyModule()

powerapi-core/build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ libraryDependencies ++= Seq(
2121
"io.spray" %% "spray-client" % "1.3.3",
2222
"io.spray" %% "spray-routing" % "1.3.3",
2323
"io.spray" %% "spray-json" % "1.3.2",
24-
"com.github.nscala-time" %% "nscala-time" % "2.0.0"
24+
"com.github.nscala-time" %% "nscala-time" % "2.0.0",
25+
"net.java.dev.jna" % "jna" % "4.1.0"
2526
)
2627

2728
// Tests

powerapi-core/lib/libpfm.jar

0 Bytes
Binary file not shown.

powerapi-core/src/main/java/org/powerapi/module/libpfm/CUtils.java renamed to powerapi-core/src/main/java/org/powerapi/module/libpfm/CUtilsBridJ.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
import perfmon2.libpfm.perf_event_attr;
3232

3333
/**
34-
* This class is used for binding several functions available on the system or in C.
34+
* This class is used for binding several functions available in C by using BridJ.
35+
* There is a problem when trying to bind the syscall function with JNA.
3536
*
3637
* @author <a href="mailto:maxime.colmant@gmail.com">Maxime Colmant</a>
3738
*/
3839
@Library("c")
3940
@Runtime(CRuntime.class)
40-
public class CUtils {
41+
public class CUtilsBridJ {
4142
static {
4243
BridJ.register();
4344
}
@@ -48,23 +49,6 @@ public class CUtils {
4849
public static int perf_event_open(int __nrPerfEventOpen, Pointer<perf_event_attr> __hw, int __pid, int __cpu, int __gr, @CLong long __flags) {
4950
return syscall(__nrPerfEventOpen, Pointer.getPeer(__hw), __pid, __cpu, __gr, __flags);
5051
}
51-
private native static int syscall(int __code, Object... varArgs1);
52-
53-
/**
54-
* Interact with a given file descriptor. In this case, we use it to enable, disable and reset a file descriptor (so, a counter).
55-
*/
56-
public static native int ioctl(int __fd, @CLong long __request, Object... varArgs1);
5752

58-
/**
59-
* Allow to read values from a file descriptor.
60-
*/
61-
public static long read(int __fd, Pointer<? > __buf, @CLong long __nbytes) {
62-
return read(__fd, Pointer.getPeer(__buf), __nbytes);
63-
}
64-
private native static long read(int __fd, @CLong long __buf, @CLong long __nbytes);
65-
66-
/**
67-
* Close a file descriptor
68-
*/
69-
public static native int close(int __fd);
70-
}
53+
private native static int syscall(int __code, Object... varArgs1);
54+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This software is licensed under the GNU Affero General Public License, quoted below.
3+
*
4+
* This file is a part of PowerAPI.
5+
*
6+
* Copyright (C) 2011-2015 Inria, University of Lille 1.
7+
*
8+
* PowerAPI is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of
11+
* the License, or (at your option) any later version.
12+
*
13+
* PowerAPI is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with PowerAPI.
20+
*
21+
* If not, please consult http://www.gnu.org/licenses/agpl-3.0.html.
22+
*/
23+
package org.powerapi.module.libpfm;
24+
25+
import com.sun.jna.Library;
26+
27+
/**
28+
* This class is used for binding several functions available in C by using JNA.
29+
*
30+
* @author <a href="mailto:maxime.colmant@gmail.com">Maxime Colmant</a>
31+
*/
32+
public interface CUtilsJNA extends Library {
33+
int ioctl(int fd, int request, Object... args);
34+
long read(int fd, byte[] buf, long nbytes);
35+
int close(int fd);
36+
}

powerapi-core/src/main/scala/org/powerapi/PowerMeter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import akka.util.Timeout
3131
import java.util.concurrent.TimeUnit
3232
import org.powerapi.PowerMeterMessages.StopAll
3333
import org.powerapi.core.{ActorComponent, Clocks, ConfigValue, Configuration, APIComponent, Monitor, Monitors, MessageBus}
34-
import org.powerapi.core.MonitorChannel.{ GetMonitoredProcesses, MonitorStart }
35-
import org.powerapi.core.MonitorChannel.stopMonitor
34+
import org.powerapi.core.MonitorChannel.{GetMonitoredProcesses, MonitorStart}
3635
import org.powerapi.core.target.Target
3736
import org.powerapi.core.power._
3837
import scala.concurrent.{ Await, Future }

powerapi-core/src/main/scala/org/powerapi/core/MonitorActors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import org.powerapi.module.PowerChannel.{AggregatePowerReport, RawPowerReport, r
4040
import org.powerapi.module.SensorChannel.{monitorAllStopped, monitorStopped}
4141
import org.powerapi.reporter.ReporterComponent
4242
import scala.concurrent.duration.{ DurationLong, FiniteDuration }
43-
import scala.concurrent.{ Await, Future }
43+
import scala.concurrent.Future
4444
import scala.concurrent.ExecutionContext.Implicits.global
4545
import scala.util.{ Failure, Success }
4646

powerapi-core/src/main/scala/org/powerapi/core/MonitorChannel.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,3 @@ object MonitorChannel extends Channel {
162162
s"monitor-$muid"
163163
}
164164
}
165-

powerapi-core/src/main/scala/org/powerapi/module/libpfm/LibpfmCoreProcessModule.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class LibpfmCoreProcessModule(osHelper: OSHelper, libpfmHelper: LibpfmHelper, ti
3737
}
3838

3939
object LibpfmCoreProcessModule {
40-
def apply(configPrefix: Option[String] = None, libpfmHelper: LibpfmHelper): LibpfmCoreProcessModule = {
40+
def apply(prefixConfig: Option[String] = None, libpfmHelper: LibpfmHelper): LibpfmCoreProcessModule = {
4141
val linuxHelper = new LinuxHelper
4242

43-
val coreProcessSensorConf = new LibpfmCoreProcessSensorConfiguration(configPrefix)
44-
val coreCyclesFormulaConf = new LibpfmCoreCyclesFormulaConfiguration(configPrefix)
43+
val coreProcessSensorConf = new LibpfmCoreProcessSensorConfiguration(prefixConfig)
44+
val coreCyclesFormulaConf = new LibpfmCoreCyclesFormulaConfiguration(prefixConfig)
4545

4646
new LibpfmCoreProcessModule(linuxHelper, libpfmHelper, coreProcessSensorConf.timeout, coreProcessSensorConf.topology, coreProcessSensorConf.configuration, coreProcessSensorConf.events,
4747
coreProcessSensorConf.inDepth, coreCyclesFormulaConf.cyclesThreadName, coreCyclesFormulaConf.cyclesRefName, coreCyclesFormulaConf.formulae, coreCyclesFormulaConf.samplingInterval)

0 commit comments

Comments
 (0)