Beispiel #1
0
void profile_end(const char *title, long start_time) {
    struct timespec t;
    get_nanotime(&t);
    long end_time = t.tv_nsec;
    if( end_time < start_time ) {
        end_time += 1000000000L;
    }
    fprintf(stdout, "%s: %ld ns\n", title, (end_time-start_time));
}
Beispiel #2
0
void throttler_endtick(int cpucyclesexecuted) {
    get_nanotime(&end);

    struct timespec* timediff = timespecdiff(&start, &end);
    long timetaken = (timediff->tv_sec * SIM_ONENANOSECOND) + timediff->tv_nsec;
    long target = SIM_CPUCLOCKDURATION * cpucyclesexecuted;

    double currentspeed = (float) target / (float) timetaken;

    long emulationtime = cputime;
    for (int i = 0; i < G_N_ELEMENTS(executiontimes); i++)
        emulationtime += executiontimes[i];
    double currentoverhead = (float) 1
                             - ((float) emulationtime / (float) timetaken);

    speeds[count % G_N_ELEMENTS(speeds)] = currentspeed;
    overheads[count % G_N_ELEMENTS(speeds)] = currentoverhead;
    count++;

    // This clamps the time taken to a max of twice the
    // expected time so things don't get out of hand
    // trying to catch up
    long clamp = target * 2;
    timetaken = MIN(clamp, timetaken);

    long diff = target - timetaken;
    if (diff > 0)
        owed -= diff; // we were ahead this tick, so take some off of our balance
    else
        owed += labs(diff); // we were behind this tick, so add to our balance;

#if !PROFILINGBUILD
    // if throttling is enabled and we're far enough ahead sleep for a little while to let realtime catch up
    if (enabled && (owed < -AHEADTHRESHOLD)) {
        static struct timespec nanosleepreq, r;
        nanosleepreq.tv_nsec = labs(owed);
        nanosleep(&nanosleepreq, &r);
        owed = -r.tv_nsec;
    }
#endif
}
Beispiel #3
0
void throttler_endcardtick(int slot) {
    get_nanotime(&cardend);
    struct timespec* diff = timespecdiff(&cardstart, &cardend);
    long time = (diff->tv_sec * SIM_ONENANOSECOND) + diff->tv_nsec;
    executiontimes[slot] = time;
}
Beispiel #4
0
void throttler_startcardtick(int slot) {
    get_nanotime(&cardstart);
}
Beispiel #5
0
void throttler_endcputick() {
    get_nanotime(&cpuend);
    struct timespec* diff = timespecdiff(&cpustart, &cpuend);
    cputime = (diff->tv_sec * SIM_ONENANOSECOND) + diff->tv_nsec;
}
Beispiel #6
0
void throttler_startcputick() {
    get_nanotime(&cpustart);
}
Beispiel #7
0
void throttler_starttick() {
    get_nanotime(&start);
}
Beispiel #8
0
long profile_start() {
    struct timespec t;
    get_nanotime(&t);
    return t.tv_nsec;
}