On 6 November 2014 16:14, Vincent Guittot <vincent.guit...@linaro.org> wrote: > On 22 October 2014 03:39, pi-cheng.chen <pi-cheng.c...@linaro.org> wrote: >> 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 > > The period unit seems to be 10ms which is quite long, please use a > more fine grained value; at least ms or even us > >> >> 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 > > What about a defined but unaligned period ? it doesn't seems to be possible > >> --- >> 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 > > the [10:50]ms range for the random period is quite arbitrary, we > should be able to specify a range for the random value > >> + if aligned == False: # add a period offset randomly from 1 of >> [300, 500, 700] >> + period_ns += (3000, 5000, 7000)[random.randrange(0, 3)] > > yous should not specify a restricted list of random offset > >> + >> + 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) > > you should use a different timer id for each task instead of sharing > the tick timer between tasks > >> + f.write("\t\t},\n") >> + >> + f.write("\t},\n") >> + f.write("}\n") > > As discussed, I still think that it's not straight forward to > understand what the script is doing or to reuse it for another use > case. But I haven't found a better way so far. IMO, the use of a model > that is then modifed according parameters is a bit easier to use or > reuse but i also agree that it's more complex to parse and modify a > model than creating a json file from scratch > > Regards, > Vincent >
Hi Vincent, I just realized though it's easier to generate a json file then to parse and modify it, it might be difficult to make the script flexible and reusable. Therefore I think it will be better to go back the way you proposed to write a base json file for a type of workload, and then a script to parse and modify the parameters in the base json file. I will do it and send the patch later. Best Regards, Pi-Cheng >> + 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