Esempio n. 1
0
static void
benchmark(struct classifier *cls)
{
    struct timespec before, after;
    struct rusage rbefore, rafter;
    struct flow_wildcards wc;
    struct match match_wc_str;
    struct flow flow;
    size_t i;

    memset(&flow, 0, sizeof flow);
    flow.in_port.ofp_port = OFPP_LOCAL;
    flow.dl_type = htons(ETH_TYPE_IP);
    flow.nw_proto = IPPROTO_TCP;

    fat_rwlock_rdlock(&cls->rwlock);
    clock_gettime(CLOCK_MONOTONIC_RAW, &before);
    getrusage(RUSAGE_SELF, &rbefore);
    for (i = 0; i < 10000000; i++) {
        eth_addr_random(flow.dl_src);
        eth_addr_random(flow.dl_dst);
        flow.nw_src = htonl(random_uint32());
        flow.nw_dst = htonl(random_uint32());
        flow.tp_src = htons(random_uint16());
        flow.tp_dst = htons(random_uint16());
        flow.tp_dst = htons(i);
        flow_wildcards_init_catchall(&wc);
        //VLOG_DBG("Finding relevant wc's for flow: tp_dst=%d (0x%04x)",
        //         ntohs(flow.tp_dst), ntohs(flow.tp_dst));
        classifier_lookup(cls, &flow, &wc);
        match_init(&match_wc_str, &flow, &wc);
        //VLOG_DBG("Relevant fields: %s", match_to_string(&match_wc_str, 0));
    }
    getrusage(RUSAGE_SELF, &rafter);
    clock_gettime(CLOCK_MONOTONIC_RAW, &after);
    fat_rwlock_unlock(&cls->rwlock);

    printf("real        %lldms\n"
           "user        %lldms\n"
           "sys         %lldms\n"
           "soft faults %ld\n"
           "hard faults %ld\n",
           timespec_to_msec(&after) - timespec_to_msec(&before),
           timeval_to_msec(&rafter.ru_utime)
               - timeval_to_msec(&rbefore.ru_utime),
           timeval_to_msec(&rafter.ru_stime)
               - timeval_to_msec(&rbefore.ru_stime),
            rafter.ru_minflt - rbefore.ru_minflt,
            rafter.ru_majflt - rbefore.ru_majflt);
}
Esempio n. 2
0
static long long int
time_msec__(struct clock *c)
{
    struct timespec ts;

    time_timespec__(c, &ts);
    return timespec_to_msec(&ts);
}
Esempio n. 3
0
static void
do_init_time(void)
{
    struct timespec ts;

    coverage_init();

    init_clock(&monotonic_clock, (!clock_gettime(CLOCK_MONOTONIC, &ts)
                                  ? CLOCK_MONOTONIC
                                  : CLOCK_REALTIME));
    init_clock(&wall_clock, CLOCK_REALTIME);
    boot_time = timespec_to_msec(&monotonic_clock.cache);
}
Esempio n. 4
0
static void
do_init_time(void)
{
    struct timespec ts;

#ifdef _WIN32
    /* Calculate number of 100-nanosecond intervals till 01/01/1970. */
    SYSTEMTIME unix_epoch_st = { 1970, 1, 0, 1, 0, 0, 0, 0};
    FILETIME unix_epoch_ft;

    SystemTimeToFileTime(&unix_epoch_st, &unix_epoch_ft);
    unix_epoch.LowPart = unix_epoch_ft.dwLowDateTime;
    unix_epoch.HighPart = unix_epoch_ft.dwHighDateTime;
#endif

    coverage_init();

    init_clock(&monotonic_clock, (!clock_gettime(CLOCK_MONOTONIC, &ts)
                                  ? CLOCK_MONOTONIC
                                  : CLOCK_REALTIME));
    init_clock(&wall_clock, CLOCK_REALTIME);
    boot_time = timespec_to_msec(&monotonic_clock.cache);
}