gdunlap/sched-sim.hg

view options.c @ 17:03ad237559b4

Fix-up options, scheduler list
author George Dunlap <george.dunlap@eu.citrix.com>
date Fri Jul 16 11:58:53 2010 +0100 (2010-07-16)
parents 1d7310217c5a
children
line source
1 #define _XOPEN_SOURCE 600
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <argp.h>
7 #include "sim.h"
8 #include "workload.h"
9 #include "sched.h"
10 #include "options.h"
12 extern int default_scheduler;
14 struct options opt = {
15 .time_limit = 100000,
16 .pcpu_count = 2,
17 .workload = NULL,
18 .scheduler = NULL,
19 };
21 enum {
22 OPT_NULL = 0,
23 OPT_WORKLOAD,
24 OPT_SCHEDULER,
25 OPT_PCPU_COUNT,
26 OPT_TIME_LIMIT,
27 OPT_LIST_WORKLOADS,
28 OPT_LIST_SCHEDULERS
29 };
31 const struct argp_option cmd_opts[] = {
32 { .name = "workload",
33 .key = OPT_WORKLOAD,
34 .arg="workload-name",
35 .doc = "Synthetic workload to run.", },
36 { .name = "scheduler",
37 .arg="scheduler-name",
38 .key = OPT_SCHEDULER,
39 .doc = "Chose scheduler to run.", },
40 { .name = "pcpus",
41 .arg="n",
42 .key = OPT_PCPU_COUNT,
43 .doc = "Number of pcpus to simulate. Defaults to 2.", },
44 { .name = "time",
45 .arg="n",
46 .key = OPT_TIME_LIMIT,
47 .doc = "How long to simulate. Default 100000", },
48 { .name = "list-schedulers",
49 .key = OPT_LIST_SCHEDULERS,
50 .doc = "List available schedulers. Simulation won't run if this option is set.", },
51 { .name = "list-workloads",
52 .key = OPT_LIST_WORKLOADS,
53 .doc = "List available workloads. Simulation won't run if this option is set.", },
55 { 0 },
56 };
58 error_t cmd_parser(int key, char *arg, struct argp_state *state)
59 {
60 static int dont_run = 0;
62 switch (key)
63 {
64 case OPT_LIST_SCHEDULERS:
65 {
66 int i;
67 printf("Schedulers:\n");
68 for ( i=0; schedulers[i]; i++)
69 printf(" %15s: %s\n", schedulers[i]->name, schedulers[i]->desc);
70 dont_run=1;
71 break;
72 }
73 case OPT_LIST_WORKLOADS:
74 {
75 int i;
76 printf("Workloads:\n");
77 for ( i=0; builtin_workloads[i].name; i++)
78 printf(" %s\n", builtin_workloads[i].name);
79 dont_run=1;
80 break;
81 }
82 case OPT_WORKLOAD:
83 {
84 int i;
86 for ( i=0; builtin_workloads[i].name; i++)
87 {
88 if ( !strcmp(builtin_workloads[i].name, arg) )
89 break;
90 }
91 if ( !builtin_workloads[i].name )
92 {
93 fprintf(stderr, "Unknown workload: %s\n",
94 arg);
95 exit(1);
96 }
97 opt.workload = builtin_workloads + i;
98 }
99 break;
100 case OPT_SCHEDULER:
101 {
102 int i;
104 for ( i=0; schedulers[i]; i++)
105 {
106 if ( !strcmp(schedulers[i]->name, arg) )
107 break;
108 }
109 if ( !schedulers[i] )
110 {
111 fprintf(stderr, "Unknown scheduler: %s\n",
112 arg);
113 exit(1);
114 }
115 opt.scheduler = schedulers[i];
116 }
117 break;
118 case OPT_PCPU_COUNT:
119 {
120 char *inval;
122 opt.pcpu_count=(int)strtol(arg, &inval, 0);
123 if ( inval == arg )
124 argp_usage(state);
125 }
126 break;
127 case OPT_TIME_LIMIT:
128 {
129 char *inval;
131 opt.time_limit=(int)strtol(arg, &inval, 0);
132 if ( inval == arg )
133 argp_usage(state);
134 }
135 break;
136 case ARGP_KEY_ARG:
137 {
138 argp_usage(state);
139 }
140 break;
141 case ARGP_KEY_END:
142 {
143 if ( dont_run )
144 exit(0);
146 if ( !opt.workload )
147 opt.workload = builtin_workloads+default_workload;
149 if ( !opt.scheduler )
150 opt.scheduler = schedulers[default_scheduler];
151 }
152 break;
154 default:
155 return ARGP_ERR_UNKNOWN;
156 }
158 return 0;
159 }
161 const struct argp parser_def = {
162 .options = cmd_opts,
163 .parser = cmd_parser,
164 .args_doc = "",
165 .doc = "",
166 };
168 const char *argp_program_version = "Scheduler simulator";
169 const char *argp_program_bug_address = "George Dunlap <george.dunlap@eu.citrix.com>";
171 void parse_options(int argc, char * argv[]) {
172 argp_parse(&parser_def, argc, argv, 0, NULL, NULL);
173 }