void sigint_handler(int signum)
{
    int i, domain;
    uint64_t freq;

    fprintf(stdout, "end_time=%f\n", measurement_end_time);
    fprintf(stdout, "duration=%f\n", measurement_end_time - measurement_start_time);

    if (cum_energy_J != NULL) {
        for (i = 0; i < num_node; i++) {
            if (cum_energy_J[i] == NULL) {
                continue;
            }

            for (domain = 0; domain < RAPL_NR_DOMAIN; ++domain) {
                if (is_supported_domain(domain)) {
                    char *domain_string = RAPL_DOMAIN_STRINGS[domain];
                    fprintf(stdout, "cpu%d_%s_Joules=%f\n", i, domain_string, cum_energy_J[i][domain]);
                }
            }
        }
    }

    terminate_rapl();
    exit(0);
}
void
do_print_energy_info()
{
    int i = 0;
    int domain = 0;
    uint64_t node = 0;
    double new_sample;
    double delta;
    double power;

    double prev_sample[num_node][RAPL_NR_DOMAIN];
    double power_watt[num_node][RAPL_NR_DOMAIN];
    cum_energy_J = malloc(num_node * sizeof(double*));
    for (i = 0; i < num_node; i++) {
        cum_energy_J[i] = malloc(RAPL_NR_DOMAIN * sizeof(double));
    }

    char time_buffer[32];
    struct timeval tv;
    int msec;
    uint64_t tsc;
    uint64_t freq;

    /* don't buffer if piped */
    setbuf(stdout, NULL);

    fprintf(stdout, "cpu_count=%lu\n", num_node);

    /* Read initial values */
    for (i = node; i < num_node; i++) {
        for (domain = 0; domain < RAPL_NR_DOMAIN; ++domain) {
            if(is_supported_domain(domain)) {
                prev_sample[i][domain] = get_rapl_energy_info(domain, i);
            }
        }
    }

    gettimeofday(&tv, NULL);
    measurement_start_time = convert_time_to_sec(tv);
    measurement_end_time = measurement_start_time;

    fprintf(stdout, "start_time=%f\n", measurement_start_time);

    /* Begin sampling */
    while (1) {

        usleep(delay_us);

        for (i = node; i < num_node; i++) {
            for (domain = 0; domain < RAPL_NR_DOMAIN; ++domain) {
                if(is_supported_domain(domain)) {
                    new_sample = get_rapl_energy_info(domain, i);
                    delta = new_sample - prev_sample[i][domain];

                    /* Handle wraparound */
                    if (delta < 0) {
                        delta += MAX_ENERGY_STATUS_JOULES;
                    }

                    prev_sample[i][domain] = new_sample;

                    cum_energy_J[i][domain] += delta;
                }
            }
        }

        gettimeofday(&tv, NULL);
        measurement_end_time = convert_time_to_sec(tv);
    }
}
Example #3
0
void
do_print_energy_info()
{
    int i = 0;
    int domain = 0;
    uint64_t node = 0;
    double new_sample;
    double delta;
    double power;

    double prev_sample[num_node][RAPL_NR_DOMAIN];
    double power_watt[num_node][RAPL_NR_DOMAIN];
    double cum_energy_J[num_node][RAPL_NR_DOMAIN];
    double cum_energy_mWh[num_node][RAPL_NR_DOMAIN];

    char time_buffer[32];
    struct timeval tv;
    int msec;
    uint64_t tsc;
    uint64_t freq;
    double start, end, interval_start;
    double total_elapsed_time;
    double interval_elapsed_time;

    /* don't buffer if piped */
    setbuf(stdout, NULL);

    /* Print header */
    fprintf(stdout, "System Time,RDTSC,Elapsed Time (sec),");
    for (i = node; i < num_node; i++) {
        fprintf(stdout, "IA Frequency_%d (MHz),",i);
        if(is_supported_domain(RAPL_PKG))
            fprintf(stdout,"Processor Power_%d (Watt),Cumulative Processor Energy_%d (Joules),Cumulative Processor Energy_%d (mWh),", i,i,i);
        if(is_supported_domain(RAPL_PP0))
            fprintf(stdout, "IA Power_%d (Watt),Cumulative IA Energy_%d (Joules),Cumulative IA Energy_%d(mWh),", i,i,i);
        if(is_supported_domain(RAPL_PP1))
            fprintf(stdout, "GT Power_%d (Watt),Cumulative GT Energy_%d (Joules),Cumulative GT Energy_%d(mWh)", i,i,i);
        if(is_supported_domain(RAPL_DRAM))
            fprintf(stdout, "DRAM Power_%d (Watt),Cumulative DRAM Energy_%d (Joules),Cumulative DRAM Energy_%d(mWh),", i,i,i);
    }
    fprintf(stdout, "\n");

    /* Read initial values */
    for (i = node; i < num_node; i++) {
        for (domain = 0; domain < RAPL_NR_DOMAIN; ++domain) {
            if(is_supported_domain(domain)) {
                prev_sample[i][domain] = get_rapl_energy_info(domain, i);
            }
        }
    }

    gettimeofday(&tv, NULL);
    start = convert_time_to_sec(tv);
    end = start;

    /* Begin sampling */
    while (1) {

        usleep(delay_us);

        gettimeofday(&tv, NULL);
        interval_start = convert_time_to_sec(tv);
        interval_elapsed_time = interval_start - end;

        for (i = node; i < num_node; i++) {
            for (domain = 0; domain < RAPL_NR_DOMAIN; ++domain) {
                if(is_supported_domain(domain)) {
                    new_sample = get_rapl_energy_info(domain, i);
                    delta = new_sample - prev_sample[i][domain];

                    /* Handle wraparound */
                    if (delta < 0) {
                        delta += MAX_ENERGY_STATUS_JOULES;
                    }

                    prev_sample[i][domain] = new_sample;

                    // Use the computed elapsed time between samples (and not
                    // just the sleep delay, in order to more accourately account for
                    // the delay between samples
                    power_watt[i][domain] = delta / interval_elapsed_time;
                    cum_energy_J[i][domain] += delta;
                    cum_energy_mWh[i][domain] = cum_energy_J[i][domain] / 3.6; // mWh
                }
            }
        }

        gettimeofday(&tv, NULL);
        end = convert_time_to_sec(tv);
        total_elapsed_time = end - start;
        convert_time_to_string(tv, time_buffer);

        read_tsc(&tsc);
        fprintf(stdout,"%s,%lu,%.4lf,", time_buffer, tsc, total_elapsed_time);
        for (i = node; i < num_node; i++) {
            get_pp0_freq_mhz(i, &freq);
            fprintf(stdout, "%lu,", freq);
            for (domain = 0; domain < RAPL_NR_DOMAIN; ++domain) {
                if(is_supported_domain(domain)) {
                    fprintf(stdout, "%.4lf,%.4lf,%.4lf,",
                            power_watt[i][domain], cum_energy_J[i][domain], cum_energy_mWh[i][domain]);
                }
            }
        }
        fprintf(stdout, "\n");

        // check to see if we are done
        if(total_elapsed_time >= duration)
            break;
    }

    end = clock();

    /* Print summary */
    fprintf(stdout, "\nTotal Elapsed Time(sec)=%.4lf\n\n", total_elapsed_time);
    for (i = node; i < num_node; i++) {
        if(is_supported_domain(RAPL_PKG)){
            fprintf(stdout, "Total Processor Energy_%d(Joules)=%.4lf\n", i, cum_energy_J[i][RAPL_PKG]);
            fprintf(stdout, "Total Processor Energy_%d(mWh)=%.4lf\n", i, cum_energy_mWh[i][RAPL_PKG]);
            fprintf(stdout, "Average Processor Power_%d(Watt)=%.4lf\n\n", i, cum_energy_J[i][RAPL_PKG]/total_elapsed_time);
        }
        if(is_supported_domain(RAPL_PP0)){
            fprintf(stdout, "Total IA Energy_%d(Joules)=%.4lf\n", i, cum_energy_J[i][RAPL_PP0]);
            fprintf(stdout, "Total IA Energy_%d(mWh)=%.4lf\n", i, cum_energy_mWh[i][RAPL_PP0]);
            fprintf(stdout, "Average IA Power_%d(Watt)=%.4lf\n\n", i, cum_energy_J[i][RAPL_PP0]/total_elapsed_time);
        }
        if(is_supported_domain(RAPL_PP1)){
            fprintf(stdout, "Total GT Energy_%d(Joules)=%.4lf\n", i, cum_energy_J[i][RAPL_PP1]);
            fprintf(stdout, "Total GT Energy_%d(mWh)=%.4lf\n", i, cum_energy_mWh[i][RAPL_PP1]);
            fprintf(stdout, "Average GT Power_%d(Watt)=%.4lf\n\n", i, cum_energy_J[i][RAPL_PP1]/total_elapsed_time);
        }
        if(is_supported_domain(RAPL_DRAM)){
            fprintf(stdout, "Total DRAM Energy_%d(Joules)=%.4lf\n", i, cum_energy_J[i][RAPL_DRAM]);
            fprintf(stdout, "Total DRAM Energy_%d(mWh)=%.4lf\n", i, cum_energy_mWh[i][RAPL_DRAM]);
            fprintf(stdout, "Average DRAM Power_%d(Watt)=%.4lf\n\n", i, cum_energy_J[i][RAPL_DRAM]/total_elapsed_time);
        }
    }
    read_tsc(&tsc);
    fprintf(stdout,"TSC=%lu\n", tsc);
}