view bin/cerium @ 0:04e28d8d3c6f

first commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 08 Nov 2010 01:23:25 +0900
parents
children
line wrap: on
line source

#!/usr/bin/perl -w

use strict;

use XML::LibXML;

my $command = shift;
my $main = "main.cc";
my $task_config = "tasks.xml";
my $cerium_path = "/Users/e065746/Works/lab/hg/Cerium";

if ($command =~ /init/) {
    &init;
} elsif ($command =~ /make/) {
    &make; 
} elsif ($command =~ /help/) {
    &help; 
} else {
    &help;
}
exit 0;

sub help {
    print "$0 init ... initialize cerium application\n";
}

sub init {
# setup initial cerium configuration
    mkdir "Task";
    if (! -e $main ) { &make_main; }
    if (! -e $task_config ) { &make_task_config; }
}

sub make_main {
    open(F,">$main") or die("Can't write $main\n");
    print F <<'EOFEOF';
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "TaskManager.h"
#include "Func.h"

extern void task_init(void);

const char *usr_help_str = "Usage: ./main [-cpu spe_num] [-count N]\n\
  -cpu    Number of SPE (default 1) \n\"";

int
init(int argc, char **argv)
{
    for (int i = 1; argv[i]; ++i) {
	if (strcmp(argv[i], "-count") == 0) {
            count = atoi(argv[++i]);
        }

    }

    return 0;
}

void
hello_init(void)
{
    HTask *hello;

    for (int i = 0; i < count; i++) {
	/**
	 * Create Task
	 *   create_task(Task ID);
	 */
	hello = manager->create_task(HELLO_TASK);

	/**
	 * Select CPU
	 *   SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY
	 *   if you do not call this, execute PPE.
	 */
	hello->set_cpu(SPE_ANY);

	/**
	 * Set 32bits parameter
	 *   add_param(32bit parameter);
	 */
	hello->add_param(i);

	hello->spawn();
    }
}

int
TMmain(int argc, char *argv[])
{
    if (init(argc, argv) < 0) {
	return -1;
    }
    task_init();
    init();

    return 0;
}
EOFEOF
}



sub make {

    return if ( ! -e $task_config );

    my $parser = XML::LibXML->new();
    my $doc = $parser->parse_file("$cerium_path/lib/tasks.xml");
    my $root = $doc->documentElement();
    my $ccs = {};
    for my $e ($root->childNodes) {
	if ( $e->nodeName eq "cc" ) {
	    my $cc = {};
	    my @att = $e->attributes;
	    print $e->nodeName, "\n";
	    
	    for my $a (@att) {
		if ( $a->nodeName eq "name" ) {
		    print $a->value, "\n";		   
		    $cc->{"name"} = $a->value;
		}
	    }
	    
	    for my $child ( $e->childNodes ) {
		&compiler($cc, $child);
	    }

	    $ccs->{$cc->{"name"}} = $cc;
	}
    }
    &printcc($ccs); 
}

sub compiler{
    my ($cc, $e) = @_;
    
    my $type = $e->nodeName;
    my $c = {};
    for my $child ( $e->childNodes ) {
	my $node = $child->nodeName;
	if ( $node eq "command" ) {
	    $c->{"command"} = $child->textContent;
	} elsif ( $node eq "flag" ) {
	    $c->{"flag"} .= $child->textContent . " ";
	}
    }
    
    $cc->{$type} = $c;
}

sub printcc{
    my ($ccs) = @_;

    for my $cc (keys %$ccs) {
	print "$cc", "\n";
	for my $s (keys %{$ccs->{$cc}}) {
	    #print "$s : $cc->{$s}" , "\n"; 
	    print "  $s "; 
	    my %h = %{$ccs->{$cc}->{$s}};
	    for my $t (keys %h) {
		print "    $t : $h{$t}\n";
	    }
	}
    }
}



__END__

=head1 NAME

cerium -- Cerium task manager configuration manager

=head1 SYNOPSIS

    cerium init
    cerium make
    cerium help

=head1 DESCRIPTION

cerium init

=cut