int
main(int argc, char **argv)
{
    struct okl4_libmutex rm;
    L4_ThreadId_t tid;
    int i, max_iteration, eg_num, server_on;
    L4_Word_t me;
    L4_MsgTag_t tag = L4_Niltag;

    /*** Initialisation ***/
    pi_main = thread_l4tid(env_thread(iguana_getenv("MAIN")));
    me = pi_main.raw;
    eg_num = max_iteration = server_on = 0;
    if (argc == 3) {
        eg_num = atoi(argv[0]);
        max_iteration = atoi(argv[1]);
        server_on = atoi(argv[2]);
    } else {
        printf("(%s 0x%lx) Error: Argument(s) missing!\n", test_name, me);
        return 1;
    }
    resource_mutex = &rm;
    okl4_libmutex_init(resource_mutex);
    high_prio_thread = medium1_prio_thread = medium2_prio_thread = medium3_prio_thread = low_prio_thread = L4_nilthread;

    high_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_HIGH")));
    medium3_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_INTERMEDIATE_2")));
    medium2_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_MEDIUM")));
    medium1_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_INTERMEDIATE_1")));
    low_prio_thread = thread_l4tid(env_thread(iguana_getenv("MIXED_PI_LOW")));

    // Tell other threads that it is safe to use libraries
    libs_ready = 1;

    if (!server_on)
        printf("Start %s test #%d(0x%lx)\n", test_name, eg_num, me);
    /*** Start test ***/
    scenario1 = 1;
    for (i = 0; i < 2 * max_iteration; i++) {
        // Wait for threads to be ready
        tag = L4_Wait(&tid);
        // If one thread had a problem while initialisation, then stop the test and notify
        // server that the test is dead.
        if (L4_Label(tag) == 0xdead) {
            rtos_init();
            test_died(test_name, eg_num);
            rtos_cleanup();
            return 1;
        }
        // Tell high prio thread to start the next iteration.
        L4_LoadMR(0, 0);
        tag = L4_Send(high_prio_thread);
        stop_spinning = 0;
        // Wait for the iteration to finish.
        L4_Receive(high_prio_thread);
        stop_spinning = 1;
        // If end of iterations for scenario1, then report results to RTOS server if server is on.
        if (i == (max_iteration - 1)) {
            if (server_on) {
                rtos_init();
                mixed_priority_inversion_results(eg_num, 1, max_iteration, cnt_h, cnt_m1, cnt_m2, cnt_l, cnt_i1, cnt_i2);
            } else 
                print_metrics(max_iteration);
            // Start scenario2
            cnt_h = cnt_m1 = cnt_m2 = cnt_l = cnt_i1 = cnt_i2 = 0;
            scenario1 = 0;
            scenario2 = 1;
        }
    }
    /*** Test finished ***/
    thread_delete(medium1_prio_thread);
    thread_delete(medium3_prio_thread);
    thread_delete(high_prio_thread);
    thread_delete(medium2_prio_thread);
    thread_delete(low_prio_thread);

    /* Clean up allocated mutexes. */
    okl4_libmutex_free(resource_mutex);

    // If RTOS server is on, report results to it.
    if (server_on) {
        mixed_priority_inversion_results(eg_num, 2, max_iteration, cnt_h, cnt_m1, cnt_m2, cnt_l, cnt_i1, cnt_i2);
        rtos_cleanup();
    } else {
        print_metrics(max_iteration);
        printf("%s test #%d(0x%lx) finished\n", test_name, eg_num, me);
    }

    return 0;
}
Esempio n. 2
0
/**
 * Program entry point.
 */
int main(int argc, char** argv)
{
    /* Global data pointer */
    fixedgrid_t* G = &G_GLOBAL;

    /* Iterators */
    int iter;

    /* Start wall clock timer */
    timer_start(&G->metrics.wallclock);

    /* Set number of processes */
    G->nprocs = 1;
    printf("\nRunning %d thread.\n", G->nprocs);

    /* Initialize the model parameters */
    init_model(G);

    /* Add emissions */
    process_emissions(G);

    /* Print startup banner */
    print_start_banner(G);

    /* Store initial concentration */
    printf("Writing initial concentration...");
    write_conc(G, 0, 0);
    printf(" done.\n");

    /* BEGIN CALCULATIONS */
    for(iter=1, G->time = G->tstart; G->time < G->tend; G->time += G->dt, ++iter)
    {
        /* Chemistry */
        saprc99_chem(G);

        discretize_all_x(G, G->dt*0.5);

        discretize_all_y(G, G->dt*0.5);

        discretize_all_z(G, G->dt);

        discretize_all_y(G, G->dt*05);

        discretize_all_x(G, G->dt*05);

        /*
         * Could update wind field here...
         */

        /*
         * Could update diffusion tensor here...
         */

        /*
         * Could update environment here...
         */

        /* Store concentration */
#if WRITE_EACH_ITER == 1
        write_conc(G, iter, 0);
#endif

        /* Indicate progress */
        printf("  After iteration %02d: Model time = %07.2f sec.\n", iter, iter*G->dt);
    }
    /* END CALCULATIONS */

    /* Store concentration */
#if WRITE_EACH_ITER != 1
    write_conc(G, iter-1, 0);
#endif

    /* Show final time */
    printf("Final time: %f seconds.\n", (iter-1)*G->dt);

    timer_stop(&G->metrics.wallclock);

    /* Print metrics */
    print_metrics(&G->metrics);

    /* Write metrics to CSV file */
    write_metrics_as_csv(G, "Serial");

    /* Cleanup and exit */
    return 0;
}