Some examples to use the script to generate small tasks workloads:
1. to generate a workload with 4 threads, 10% load and 30ms period
$ ./small_task_gen -t 4 -l 10 -p 3

2. to generate a workload with 3 threads, 15% load and random tick-aligned 
   period
$ ./small_task_gen -t 3 -l 15 -r --aligned

3. to generate a workload with 5 threads, 20% load and random non-tick-aligned
   period
$ ./small_task_gen -t 5 -l 20 -r --unaligned
---
 doc/examples/small_task_gen | 117 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100755 doc/examples/small_task_gen

diff --git a/doc/examples/small_task_gen b/doc/examples/small_task_gen
new file mode 100755
index 0000000..ba74753
--- /dev/null
+++ b/doc/examples/small_task_gen
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+
+import sys
+import getopt
+import random
+
+outfile = "small_tasks.json"
+tasks = None
+loading = None
+period = None
+randomized = None
+aligned = None
+
+
+def usage():
+    print "Usage:"
+    print sys.argv[0] + " -t <number of tasks>"
+    print "\t\t -l <percentage of task loading> (1 - 100)"
+    print "\t\t -p <fixed period in ms>"
+    print "\t\t -r [--aligned | --unaligned] (randomize periods of tasks)"
+    print "\t\t -o <output JSON file name> (default: small_tasks.json)"
+    return
+
+
+def parse_options():
+    global outfile
+    global tasks
+    global loading
+    global period
+    global randomized
+    global aligned
+
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "t:l:o:p:rh", 
+                                   ["aligned", "unaligned"])
+    except getopt.GetoptError:
+        usage()
+        sys.exit(2)
+
+    for o, a in opts:
+        if o == "-t":
+            tasks = int(a)
+            print "number of tasks: %d" % tasks
+        if o == "-l":
+            loading = int(a)
+            print "task loading: %d" % loading
+        if o == "-o":
+            outfile = a;
+            print "output workload JSON file: " + outfile
+        if o == "-p":
+            period = int(a)
+            print "period of tasks: %d" % period
+        if o == "-r":
+            randomized = True
+            print "randomized: %r" % randomized
+        if o == "--aligned":
+            if aligned == False:
+                usage()
+                sys.exit(2)
+            aligned = True
+            print "aligned: %r" % aligned
+        if o in "--unaligned":
+            if aligned == True:
+                usage()
+                sys.exit(2)
+            aligned = False
+            print "aligned: %r" % aligned
+        if o == "-h":
+            usage()
+            sys.exit(2)
+
+    if not period is None and not randomized is None:
+        usage()
+        sys.exit(2)
+
+    if tasks is None or (period is None and randomized is None):
+        usage()
+        sys.exit(2)
+
+    return
+
+
+def generate_workload():
+    try:
+        f = open(outfile, "w")
+    except IOError:
+        print "WARN: Unable to open " + infile
+        sys.exit(2)
+
+    f.write("{\n")
+    f.write("\t\"tasks\" : {\n")
+
+    for i in range(0, tasks):
+
+        if randomized is None:
+            period_ns = period * 1000
+        else:
+            period_ns = random.randrange(1, 6) * 10000 # random tick-aligned 
period from 10ms~50ms
+            if aligned == False: # add a period offset randomly from 1 of 
[300, 500, 700]
+                period_ns += (3000, 5000, 7000)[random.randrange(0, 3)]
+
+        run_ns = period_ns * loading / 100
+
+        f.write("\t\t\"thread%d\" : {\n" % i)
+        f.write("\t\t\t\"loop\" : -1,\n")
+        f.write("\t\t\t\"run\" : %d,\n" % run_ns)
+        f.write("\t\t\t\"timer\" : { \"ref\" : \"tick\", \"period\" : %d },\n" 
% period_ns)
+        f.write("\t\t},\n")
+
+    f.write("\t},\n")
+    f.write("}\n")
+    return
+
+
+if __name__ == '__main__':
+    parse_options()
+    generate_workload()
-- 
1.9.1


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to