• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{
2 "cells": [
3  {
4   "cell_type": "markdown",
5   "metadata": {},
6   "source": [
7    "# Energy Meter Examples\n",
8    "\n",
9    "## Linux Kernel HWMon\n",
10    "\n",
11    "More details can be found at https://github.com/ARM-software/lisa/wiki/Energy-Meters-Requirements#linux-hwmon."
12   ]
13  },
14  {
15   "cell_type": "code",
16   "execution_count": 1,
17   "metadata": {
18    "collapsed": false
19   },
20   "outputs": [
21    {
22     "name": "stderr",
23     "output_type": "stream",
24     "text": [
25      "2016-12-08 12:40:25,090 INFO    : root         : Using LISA logging configuration:\n",
26      "2016-12-08 12:40:25,091 INFO    : root         :   /home/vagrant/lisa/logging.conf\n"
27     ]
28    }
29   ],
30   "source": [
31    "import logging\n",
32    "from conf import LisaLogging\n",
33    "LisaLogging.setup()"
34   ]
35  },
36  {
37   "cell_type": "markdown",
38   "metadata": {},
39   "source": [
40    "#### Import required modules"
41   ]
42  },
43  {
44   "cell_type": "code",
45   "execution_count": 2,
46   "metadata": {
47    "collapsed": false
48   },
49   "outputs": [],
50   "source": [
51    "# Generate plots inline\n",
52    "%matplotlib inline\n",
53    "\n",
54    "import os\n",
55    "\n",
56    "# Support to access the remote target\n",
57    "import devlib\n",
58    "from env import TestEnv\n",
59    "\n",
60    "# RTApp configurator for generation of PERIODIC tasks\n",
61    "from wlgen import RTA, Ramp"
62   ]
63  },
64  {
65   "cell_type": "markdown",
66   "metadata": {},
67   "source": [
68    "## Target Configuration\n",
69    "The target configuration is used to describe and configure your test environment.\n",
70    "You can find more details in **examples/utils/testenv_example.ipynb**."
71   ]
72  },
73  {
74   "cell_type": "code",
75   "execution_count": 3,
76   "metadata": {
77    "collapsed": false
78   },
79   "outputs": [],
80   "source": [
81    "# Setup target configuration\n",
82    "my_conf = {\n",
83    "\n",
84    "    # Target platform and board\n",
85    "    \"platform\"    : 'linux',\n",
86    "    \"board\"       : 'juno',\n",
87    "    \"host\"        : '192.168.0.1',\n",
88    "\n",
89    "    # Devlib modules to load\n",
90    "    \"modules\" : [\"cpufreq\"], # Required by rt-app calibration\n",
91    "    \n",
92    "    # Folder where all the results will be collected\n",
93    "    \"results_dir\" : \"EnergyMeter_HWMON\",\n",
94    "\n",
95    "    # Energy Meters Configuration for BayLibre's ACME Cape\n",
96    "    \"emeter\" : {\n",
97    "        \"instrument\" : \"hwmon\",\n",
98    "        \"conf\" : {\n",
99    "            # Prefixes of the HWMon labels\n",
100    "            'sites' : ['a53', 'a57'],\n",
101    "            # Type of hardware monitor to be used\n",
102    "            'kinds' : ['energy']\n",
103    "        },\n",
104    "        'channel_map' : {\n",
105    "            'LITTLE' : 'a53',\n",
106    "            'big' : 'a57',\n",
107    "        }\n",
108    "    },\n",
109    "    \n",
110    "    # Tools required by the experiments\n",
111    "    \"tools\"   : [ 'trace-cmd', 'rt-app' ],\n",
112    "    \n",
113    "    # Comment this line to calibrate RTApp in your own platform\n",
114    "    # \"rtapp-calib\" :  {\"0\": 360, \"1\": 142, \"2\": 138, \"3\": 352, \"4\": 352, \"5\": 353},\n",
115    "}"
116   ]
117  },
118  {
119   "cell_type": "code",
120   "execution_count": 4,
121   "metadata": {
122    "collapsed": false,
123    "scrolled": false
124   },
125   "outputs": [
126    {
127     "name": "stderr",
128     "output_type": "stream",
129     "text": [
130      "03:59:42  INFO    :         Target - Using base path: /data/lisa\n",
131      "03:59:42  INFO    :         Target - Loading custom (inline) target configuration\n",
132      "03:59:42  INFO    :         Target - Devlib modules to load: ['bl', 'hwmon', 'cpufreq']\n",
133      "03:59:42  INFO    :         Target - Connecting linux target:\n",
134      "03:59:42  INFO    :         Target -   username : root\n",
135      "03:59:42  INFO    :         Target -       host : 192.168.0.1\n",
136      "03:59:42  INFO    :         Target -   password : \n",
137      "03:59:42  INFO    :         Target - Connection settings:\n",
138      "03:59:42  INFO    :         Target -    {'username': 'root', 'host': '192.168.0.1', 'password': ''}\n",
139      "04:00:23  INFO    :         Target - Initializing target workdir:\n",
140      "04:00:23  INFO    :         Target -    /root/devlib-target\n",
141      "04:00:28  INFO    :         Target - Topology:\n",
142      "04:00:28  INFO    :         Target -    [[0, 3, 4, 5], [1, 2]]\n",
143      "04:00:30  INFO    :       Platform - Loading default EM:\n",
144      "04:00:30  INFO    :       Platform -    /data/lisa/libs/utils/platforms/juno.json\n",
145      "04:00:30  WARNING :         Target - Using configuration provided RTApp calibration\n",
146      "04:00:30  INFO    :         Target - Using RT-App calibration values:\n",
147      "04:00:30  INFO    :         Target -    {\"0\": 360, \"1\": 142, \"2\": 138, \"3\": 352, \"4\": 352, \"5\": 353}\n",
148      "04:00:30  INFO    :          HWMon - Scanning for HWMON channels, may take some time...\n",
149      "04:00:30  INFO    :          HWMon - Channels selected for energy sampling:\n",
150      "04:00:30  INFO    :          HWMon -    a57_energy\n",
151      "04:00:30  INFO    :          HWMon -    a53_energy\n",
152      "04:00:30  INFO    :        TestEnv - Set results folder to:\n",
153      "04:00:30  INFO    :        TestEnv -    /data/lisa/results/EnergyMeter_HWMON\n",
154      "04:00:30  INFO    :        TestEnv - Experiment results available also in:\n",
155      "04:00:30  INFO    :        TestEnv -    /data/lisa/results_latest\n"
156     ]
157    }
158   ],
159   "source": [
160    "# Initialize a test environment using:\n",
161    "te = TestEnv(my_conf, wipe=False, force_new=True)\n",
162    "target = te.target"
163   ]
164  },
165  {
166   "cell_type": "markdown",
167   "metadata": {},
168   "source": [
169    "## Workload Execution and Power Consumptions Samping\n",
170    "\n",
171    "Detailed information on RTApp can be found in **examples/wlgen/rtapp_example.ipynb**.\n",
172    "\n",
173    "Each **EnergyMeter** derived class has two main methods: **reset** and **report**.\n",
174    " - The **reset** method will reset the energy meter and start sampling from channels specified in the target configuration. <br>\n",
175    " - The **report** method will stop capture and will retrieve the energy consumption data. This returns an EnergyReport composed of the measured channels energy and the report file. Each of the samples can also be obtained, as you can see below."
176   ]
177  },
178  {
179   "cell_type": "code",
180   "execution_count": 5,
181   "metadata": {
182    "collapsed": false
183   },
184   "outputs": [
185    {
186     "name": "stderr",
187     "output_type": "stream",
188     "text": [
189      "04:00:30  INFO    :          WlGen - Setup new workload ramp\n",
190      "04:00:30  INFO    :          RTApp - Workload duration defined by longest task\n",
191      "04:00:30  INFO    :          RTApp - Default policy: SCHED_OTHER\n",
192      "04:00:30  INFO    :          RTApp - ------------------------\n",
193      "04:00:30  INFO    :          RTApp - task [ramp], sched: using default policy\n",
194      "04:00:30  INFO    :          RTApp -  | calibration CPU: 1\n",
195      "04:00:30  INFO    :          RTApp -  | loops count: 1\n",
196      "04:00:30  INFO    :          RTApp - + phase_000001: duration 0.500000 [s] (5 loops)\n",
197      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  60 %\n",
198      "04:00:30  INFO    :          RTApp - |  run_time  60000 [us], sleep_time  40000 [us]\n",
199      "04:00:30  INFO    :          RTApp - + phase_000002: duration 0.500000 [s] (5 loops)\n",
200      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  55 %\n",
201      "04:00:30  INFO    :          RTApp - |  run_time  55000 [us], sleep_time  45000 [us]\n",
202      "04:00:30  INFO    :          RTApp - + phase_000003: duration 0.500000 [s] (5 loops)\n",
203      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  50 %\n",
204      "04:00:30  INFO    :          RTApp - |  run_time  50000 [us], sleep_time  50000 [us]\n",
205      "04:00:30  INFO    :          RTApp - + phase_000004: duration 0.500000 [s] (5 loops)\n",
206      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  45 %\n",
207      "04:00:30  INFO    :          RTApp - |  run_time  45000 [us], sleep_time  55000 [us]\n",
208      "04:00:30  INFO    :          RTApp - + phase_000005: duration 0.500000 [s] (5 loops)\n",
209      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  40 %\n",
210      "04:00:30  INFO    :          RTApp - |  run_time  40000 [us], sleep_time  60000 [us]\n",
211      "04:00:30  INFO    :          RTApp - + phase_000006: duration 0.500000 [s] (5 loops)\n",
212      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  35 %\n",
213      "04:00:30  INFO    :          RTApp - |  run_time  35000 [us], sleep_time  65000 [us]\n",
214      "04:00:30  INFO    :          RTApp - + phase_000007: duration 0.500000 [s] (5 loops)\n",
215      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  30 %\n",
216      "04:00:30  INFO    :          RTApp - |  run_time  30000 [us], sleep_time  70000 [us]\n",
217      "04:00:30  INFO    :          RTApp - + phase_000008: duration 0.500000 [s] (5 loops)\n",
218      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  25 %\n",
219      "04:00:30  INFO    :          RTApp - |  run_time  25000 [us], sleep_time  75000 [us]\n",
220      "04:00:30  INFO    :          RTApp - + phase_000009: duration 0.500000 [s] (5 loops)\n",
221      "04:00:30  INFO    :          RTApp - |  period   100000 [us], duty_cycle  20 %\n",
222      "04:00:30  INFO    :          RTApp - |  run_time  20000 [us], sleep_time  80000 [us]\n",
223      "04:00:35  INFO    :          WlGen - Workload execution START:\n",
224      "04:00:35  INFO    :          WlGen -    /root/devlib-target/bin/rt-app /root/devlib-target/ramp_00.json 2>&1\n"
225     ]
226    }
227   ],
228   "source": [
229    "# Create and RTApp RAMP task\n",
230    "rtapp = RTA(te.target, 'ramp', calibration=te.calibration())\n",
231    "rtapp.conf(kind='profile',\n",
232    "           params={\n",
233    "                'ramp' : Ramp(\n",
234    "                    start_pct =  60,\n",
235    "                    end_pct   =  20,\n",
236    "                    delta_pct =   5,\n",
237    "                    time_s    =   0.5).get()\n",
238    "          })\n",
239    "\n",
240    "# EnergyMeter Start\n",
241    "te.emeter.reset()\n",
242    "\n",
243    "rtapp.run(out_dir=te.res_dir)\n",
244    "\n",
245    "# EnergyMeter Stop and samples collection\n",
246    "nrg_report = te.emeter.report(te.res_dir)"
247   ]
248  },
249  {
250   "cell_type": "code",
251   "execution_count": 6,
252   "metadata": {
253    "collapsed": false
254   },
255   "outputs": [
256    {
257     "name": "stderr",
258     "output_type": "stream",
259     "text": [
260      "04:00:41  INFO    : Collected data:\n"
261     ]
262    },
263    {
264     "name": "stdout",
265     "output_type": "stream",
266     "text": [
267      "\u001b[01;34m/data/lisa/results/EnergyMeter_HWMON\u001b[00m\r\n",
268      "├── energy.json\r\n",
269      "├── output.log\r\n",
270      "├── ramp_00.json\r\n",
271      "├── rt-app-ramp-0.log\r\n",
272      "├── trace.dat\r\n",
273      "├── trace.raw.txt\r\n",
274      "└── trace.txt\r\n",
275      "\r\n",
276      "0 directories, 7 files\r\n"
277     ]
278    }
279   ],
280   "source": [
281    "logging.info(\"Collected data:\")\n",
282    "!tree $te.res_dir"
283   ]
284  },
285  {
286   "cell_type": "markdown",
287   "metadata": {},
288   "source": [
289    "## Power Measurements Data"
290   ]
291  },
292  {
293   "cell_type": "code",
294   "execution_count": 7,
295   "metadata": {
296    "collapsed": false
297   },
298   "outputs": [
299    {
300     "name": "stderr",
301     "output_type": "stream",
302     "text": [
303      "04:00:41  INFO    : Measured channels energy:\n",
304      "04:00:41  INFO    : {'big': 14.410717999999179, 'LITTLE': 1.1058980000016163}\n"
305     ]
306    }
307   ],
308   "source": [
309    "logging.info(\"Measured channels energy:\")\n",
310    "logging.info(\"%s\", nrg_report.channels)"
311   ]
312  },
313  {
314   "cell_type": "code",
315   "execution_count": 8,
316   "metadata": {
317    "collapsed": false
318   },
319   "outputs": [
320    {
321     "name": "stderr",
322     "output_type": "stream",
323     "text": [
324      "04:00:41  INFO    : Generated energy file:\n",
325      "04:00:41  INFO    :   /data/lisa/results/EnergyMeter_HWMON/energy.json\n"
326     ]
327    },
328    {
329     "name": "stdout",
330     "output_type": "stream",
331     "text": [
332      "{\r\n",
333      "    \"LITTLE\": 1.1058980000016163, \r\n",
334      "    \"big\": 14.410717999999179\r\n",
335      "}"
336     ]
337    }
338   ],
339   "source": [
340    "logging.info(\"Generated energy file:\")\n",
341    "logging.info(\"  %s\", nrg_report.report_file)\n",
342    "!cat $nrg_report.report_file"
343   ]
344  }
345 ],
346 "metadata": {
347  "kernelspec": {
348   "display_name": "Python 2",
349   "language": "python",
350   "name": "python2"
351  },
352  "language_info": {
353   "codemirror_mode": {
354    "name": "ipython",
355    "version": 2
356   },
357   "file_extension": ".py",
358   "mimetype": "text/x-python",
359   "name": "python",
360   "nbconvert_exporter": "python",
361   "pygments_lexer": "ipython2",
362   "version": "2.7.6"
363  },
364  "toc": {
365   "toc_cell": false,
366   "toc_number_sections": true,
367   "toc_threshold": 6,
368   "toc_window_display": false
369  }
370 },
371 "nbformat": 4,
372 "nbformat_minor": 0
373}
374