{ "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" }, "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Setup" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from trappy.stats.Topology import Topology\n", "from bart.sched.SchedMultiAssert import SchedMultiAssert\n", "from bart.sched.SchedAssert import SchedAssert\n", "import trappy\n", "import os\n", "import operator\n", "import json\n", "\n", "#Define a CPU Topology (for multi-cluster systems)\n", "BIG = [1, 2]\n", "LITTLE = [0, 3, 4, 5]\n", "CLUSTERS = [BIG, LITTLE]\n", "topology = Topology(clusters=CLUSTERS)\n", "\n", "BASE_PATH = \"/Users/kapileshwarsingh/AnalysisRawData/LPC/sched_deadline/\"\n", "\n", "THRESHOLD = 10.0\n", "def between_threshold(a, b):\n", " return abs(((a - b) * 100.0) / b) < THRESHOLD" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Periodic Yield" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The thread periodic_yeild is woken up at 30ms intervals where it calls sched_yield and relinquishes its time-slice.\n", "The expectation is that the task will have a duty cycle < 1% and a period of 30ms.\n", "\n", "There are two threads, and the rank=1 conveys that the condition is true for one of the threads with the name \"periodic_yeild\"\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "TRACE_FILE = os.path.join(BASE_PATH, \"yield\")\n", "ftrace = trappy.FTrace(TRACE_FILE, \"cpuhog\")\n", "\n", "# Assert Period\n", "s = SchedMultiAssert(ftrace, topology, execnames=\"periodic_yield\")\n", "if s.assertPeriod(30, between_threshold, rank=1):\n", " print \"PASS: Period\"\n", " print json.dumps(s.getPeriod(), indent=3)\n", "\n", "print \"\"\n", " \n", "# Assert DutyCycle \n", "if s.assertDutyCycle(1, operator.lt, window=(0,4), rank=2):\n", " print \"PASS: DutyCycle\"\n", " print json.dumps(s.getDutyCycle(window=(0,4)), indent=3)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "PASS: Period\n", "{\n", " \"1844\": {\n", " \"period\": 1.0085000000401578, \n", " \"task_name\": \"periodic_yield\"\n", " }, \n", " \"1845\": {\n", " \"period\": 29.822017857142669, \n", " \"task_name\": \"periodic_yield\"\n", " }\n", "}\n", "\n", "PASS: DutyCycle\n", "{\n", " \"1844\": {\n", " \"task_name\": \"periodic_yield\", \n", " \"dutycycle\": 0.074749999998857675\n", " }, \n", " \"1845\": {\n", " \"task_name\": \"periodic_yield\", \n", " \"dutycycle\": 0.03862499999343072\n", " }\n", "}\n" ] } ], "prompt_number": 10 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "CPU Hog" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The reservation of a CPU hogging task is set to 10ms for every 100ms. The assertion ensures a duty cycle of 10%" ] }, { "cell_type": "code", "collapsed": false, "input": [ "TRACE_FILE = os.path.join(BASE_PATH, \"cpuhog\")\n", "ftrace = trappy.FTrace(TRACE_FILE, \"cpuhog\")\n", "s = SchedMultiAssert(ftrace, topology, execnames=\"cpuhog\")\n", "s.plot().view()\n", "\n", "# Assert DutyCycle\n", "if s.assertDutyCycle(10, between_threshold, window=(0, 5), rank=1):\n", " print \"PASS: DutyCycle\"\n", " print json.dumps(s.getDutyCycle(window=(0, 5)), indent=3)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "
\n", " \n", "
" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "PASS: DutyCycle\n", "{\n", " \"1852\": {\n", " \"task_name\": \"cpuhog\", \n", " \"dutycycle\": 10.050119999991693\n", " }\n", "}\n" ] } ], "prompt_number": 11 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Changing Reservations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A CPU hogging task has reservations set in the increasing order starting from 10% followed by a 2s period of normal execution" ] }, { "cell_type": "code", "collapsed": false, "input": [ "TRACE_FILE = os.path.join(BASE_PATH, \"cancel_dl_timer\")\n", "ftrace = trappy.FTrace(TRACE_FILE, \"cpuhog\")\n", "s = SchedAssert(ftrace, topology, execname=\"cpuhog\")\n", "s.plot().view()\n", "\n", "NUM_PHASES = 10\n", "PHASE_DURATION = 2\n", "start = s.getStartTime()\n", "DUTY_CYCLE_FACTOR = 10\n", "\n", "\n", "for phase in range(NUM_PHASES + 1):\n", " window = (start + (phase * PHASE_DURATION),\n", " start + ((phase + 1) * PHASE_DURATION))\n", " \n", " if phase % 2 == 0:\n", " DUTY_CYCLE = (phase + 2) * DUTY_CYCLE_FACTOR / 2\n", " else:\n", " DUTY_CYCLE = 100\n", "\n", "\n", " print \"WINDOW -> [{:.2f}, {:.2f}]\".format(window[0],\n", " window[1])\n", " \n", " \n", " \n", " if s.assertDutyCycle(DUTY_CYCLE, between_threshold, window=window):\n", " print \"PASS: Expected={} Actual={:.2f} THRESHOLD={}\".format(DUTY_CYCLE,\n", " s.getDutyCycle(window=window),\n", " THRESHOLD)\n", " else:\n", " print \"FAIL: Expected={} Actual={:.2f} THRESHOLD={}\".format(DUTY_CYCLE,\n", " s.getDutyCycle(window=window),\n", " THRESHOLD)\n", " \n", " print \"\"" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "
\n", " \n", "
" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "WINDOW -> [0.00, 2.00]\n", "PASS: Expected=10 Actual=10.38 THRESHOLD=10.0\n", "\n", "WINDOW -> [2.00, 4.00]\n", "PASS: Expected=100 Actual=99.60 THRESHOLD=10.0\n", "\n", "WINDOW -> [4.00, 6.00]\n", "PASS: Expected=20 Actual=21.06 THRESHOLD=10.0\n", "\n", "WINDOW -> [6.00, 8.00]\n", "PASS: Expected=100 Actual=95.69 THRESHOLD=10.0\n", "\n", "WINDOW -> [8.00, 10.00]\n", "PASS: Expected=30 Actual=31.78 THRESHOLD=10.0\n", "\n", "WINDOW -> [10.00, 12.00]\n", "PASS: Expected=100 Actual=98.23 THRESHOLD=10.0\n", "\n", "WINDOW -> [12.00, 14.00]\n", "PASS: Expected=40 Actual=40.74 THRESHOLD=10.0\n", "\n", "WINDOW -> [14.00, 16.00]\n", "PASS: Expected=100 Actual=97.58 THRESHOLD=10.0\n", "\n", "WINDOW -> [16.00, 18.00]\n", "PASS: Expected=50 Actual=52.51 THRESHOLD=10.0\n", "\n", "WINDOW -> [18.00, 20.00]\n", "PASS: Expected=100 Actual=96.38 THRESHOLD=10.0\n", "\n", "WINDOW -> [20.00, 22.00]\n", "PASS: Expected=60 Actual=60.71 THRESHOLD=10.0\n", "\n" ] } ], "prompt_number": 4 } ], "metadata": {} } ] }