297
|
1 #!/usr/bin/perl -w
|
|
2
|
|
3 use strict;
|
|
4
|
329
|
5 use XML::LibXML;
|
|
6
|
297
|
7 my $command = shift;
|
|
8 my $main = "main.cc";
|
|
9 my $task_config = "tasks.xml";
|
330
|
10 my $cerium_path = "/Users/e065746/Works/lab/hg/Cerium";
|
297
|
11
|
|
12 if ($command =~ /init/) {
|
|
13 &init;
|
|
14 } elsif ($command =~ /make/) {
|
|
15 &make;
|
|
16 } elsif ($command =~ /help/) {
|
|
17 &help;
|
|
18 } else {
|
|
19 &help;
|
|
20 }
|
|
21 exit 0;
|
|
22
|
|
23 sub help {
|
|
24 print "$0 init ... initialize cerium application\n";
|
|
25 }
|
|
26
|
|
27 sub init {
|
|
28 # setup initial cerium configuration
|
|
29 mkdir "Task";
|
330
|
30 if (! -e $main ) { &make_main; }
|
|
31 if (! -e $task_config ) { &make_task_config; }
|
297
|
32 }
|
|
33
|
|
34 sub make_main {
|
|
35 open(F,">$main") or die("Can't write $main\n");
|
330
|
36 print F <<'EOFEOF';
|
297
|
37 #include <stdio.h>
|
|
38 #include <stdlib.h>
|
|
39 #include <string.h>
|
|
40 #include "TaskManager.h"
|
|
41 #include "Func.h"
|
|
42
|
|
43 extern void task_init(void);
|
|
44
|
|
45 const char *usr_help_str = "Usage: ./main [-cpu spe_num] [-count N]\n\
|
330
|
46 -cpu Number of SPE (default 1) \n\"";
|
297
|
47
|
|
48 int
|
|
49 init(int argc, char **argv)
|
|
50 {
|
|
51 for (int i = 1; argv[i]; ++i) {
|
|
52 if (strcmp(argv[i], "-count") == 0) {
|
|
53 count = atoi(argv[++i]);
|
|
54 }
|
|
55
|
|
56 }
|
|
57
|
|
58 return 0;
|
|
59 }
|
|
60
|
|
61 void
|
|
62 hello_init(void)
|
|
63 {
|
|
64 HTask *hello;
|
|
65
|
|
66 for (int i = 0; i < count; i++) {
|
|
67 /**
|
|
68 * Create Task
|
|
69 * create_task(Task ID);
|
|
70 */
|
|
71 hello = manager->create_task(HELLO_TASK);
|
|
72
|
|
73 /**
|
|
74 * Select CPU
|
|
75 * SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY
|
|
76 * if you do not call this, execute PPE.
|
|
77 */
|
|
78 hello->set_cpu(SPE_ANY);
|
|
79
|
|
80 /**
|
|
81 * Set 32bits parameter
|
|
82 * add_param(32bit parameter);
|
|
83 */
|
|
84 hello->add_param(i);
|
|
85
|
|
86 hello->spawn();
|
|
87 }
|
|
88 }
|
|
89
|
|
90 int
|
|
91 TMmain(int argc, char *argv[])
|
|
92 {
|
|
93 if (init(argc, argv) < 0) {
|
|
94 return -1;
|
|
95 }
|
|
96 task_init();
|
|
97 init();
|
|
98
|
|
99 return 0;
|
|
100 }
|
|
101 EOFEOF
|
|
102 }
|
|
103
|
|
104
|
|
105
|
|
106 sub make {
|
329
|
107
|
|
108 return if ( ! -e $task_config );
|
330
|
109
|
331
|
110 my $parser = XML::LibXML->new();
|
330
|
111 my $doc = $parser->parse_file("$cerium_path/lib/tasks.xml");
|
|
112 my $root = $doc->documentElement();
|
332
|
113 my $ccs = {};
|
330
|
114 for my $e ($root->childNodes) {
|
332
|
115 if ( $e->nodeName eq "cc" ) {
|
|
116 my $cc = {};
|
|
117 my @att = $e->attributes;
|
|
118 print $e->nodeName, "\n";
|
|
119
|
|
120 for my $a (@att) {
|
|
121 if ( $a->nodeName eq "name" ) {
|
|
122 print $a->value, "\n";
|
|
123 $cc->{"name"} = $a->value;
|
|
124 }
|
|
125 }
|
|
126
|
|
127 for my $child ( $e->childNodes ) {
|
|
128 &compiler($cc, $child);
|
|
129 }
|
|
130
|
|
131 $ccs->{$cc->{"name"}} = $cc;
|
|
132 }
|
|
133 }
|
|
134 &printcc($ccs);
|
|
135 }
|
|
136
|
|
137 sub compiler{
|
|
138 my ($cc, $e) = @_;
|
|
139
|
|
140 my $type = $e->nodeName;
|
|
141 my $c = {};
|
|
142 for my $child ( $e->childNodes ) {
|
|
143 my $node = $child->nodeName;
|
|
144 if ( $node eq "command" ) {
|
|
145 $c->{"command"} = $child->textContent;
|
|
146 } elsif ( $node eq "flag" ) {
|
|
147 $c->{"flag"} .= $child->textContent . " ";
|
|
148 }
|
|
149 }
|
|
150
|
|
151 $cc->{$type} = $c;
|
|
152 }
|
|
153
|
|
154 sub printcc{
|
|
155 my ($ccs) = @_;
|
|
156
|
|
157 for my $cc (keys %$ccs) {
|
|
158 print "$cc", "\n";
|
|
159 for my $s (keys %{$ccs->{$cc}}) {
|
|
160 #print "$s : $cc->{$s}" , "\n";
|
|
161 print " $s ";
|
|
162 my %h = %{$ccs->{$cc}->{$s}};
|
|
163 for my $t (keys %h) {
|
|
164 print " $t : $h{$t}\n";
|
|
165 }
|
|
166 }
|
330
|
167 }
|
297
|
168 }
|
|
169
|
331
|
170
|
332
|
171
|
297
|
172 __END__
|
|
173
|
|
174 =head1 NAME
|
|
175
|
|
176 cerium -- Cerium task manager configuration manager
|
|
177
|
|
178 =head1 SYNOPSIS
|
|
179
|
|
180 cerium init
|
|
181 cerium make
|
|
182 cerium help
|
|
183
|
|
184 =head1 DESCRIPTION
|
|
185
|
|
186 cerium init
|
|
187
|
|
188 =cut
|
|
189
|