/** * Update the row with the given nodeinfo. If row is -1 the row number * is determined by the node_id contained in the gnet_node_info_t. */ static void nodes_gui_update_node_info(gnet_node_info_t *n, gint row) { GtkCList *clist = GTK_CLIST(gui_main_window_lookup("clist_nodes")); g_assert(n != NULL); if (row == -1) { row = gtk_clist_find_row_from_data(clist, deconstify_gpointer(n->node_id)); } if (row != -1) { gchar ver_buf[64]; gnet_node_status_t status; time_t now = tm_time(); if (guc_node_get_status(n->node_id, &status)) { gtk_clist_set_text(clist, row, c_gnet_user_agent, n->vendor ? lazy_utf8_to_locale(n->vendor) : "..."); gtk_clist_set_text(clist, row, c_gnet_loc, deconstify_gchar(iso3166_country_cc(n->country))); gm_snprintf(ver_buf, sizeof ver_buf, "%d.%d", n->proto_major, n->proto_minor); gtk_clist_set_text(clist, row, c_gnet_version, ver_buf); if (status.status == GTA_NODE_CONNECTED) gtk_clist_set_text(clist, row, c_gnet_connected, short_uptime(delta_time(now, status.connect_date))); if (status.up_date) gtk_clist_set_text(clist, row, c_gnet_uptime, status.up_date ? short_uptime(delta_time(now, status.up_date)) : "..."); gtk_clist_set_text(clist, row, c_gnet_info, nodes_gui_common_status_str(&status)); } } else { g_warning("%s: no matching row found", G_GNUC_PRETTY_FUNCTION); } }
static int write_note_event (note_event *event, midi_spec *spec) { int len; len = delta_time(event->dtime, spec->nticks, spec->fp); putc(MIDI_NOTE_ON + event->channel, spec->fp); putc(event->pitch, spec->fp); putc(event->force, spec->fp); len += 3; /* use "running status" */ len += delta_time(event->duration, spec->nticks, spec->fp); putc(event->pitch, spec->fp); putc(0, spec->fp); len += 2; return len; }
void hal_waitUntil (u8_t time) { u4_t delta = delta_time(time); // From delayMicroseconds docs: Currently, the largest value that // will produce an accurate delay is 16383. while (delta > (16000 / US_PER_OSTICK)) { delay(16); delta -= (16000 / US_PER_OSTICK); } if (delta > 0) delayMicroseconds(delta * US_PER_OSTICK); }
static void search_stats_gui_timer(time_t now) { static time_t last_update; time_delta_t interval = GUI_PROPERTY(search_stats_update_interval); if (!last_update || delta_time(now, last_update) > interval) { last_update = now; search_stats_gui_update_display(); } }
/** * Return entry age in seconds, (time_delta_t) -1 if not found. */ time_delta_t aging_age(const aging_table_t *ag, gconstpointer key) { struct aging_value *aval; aging_check(ag); aval = g_hash_table_lookup(ag->table, key); return aval == NULL ? (time_delta_t) -1 : delta_time(tm_time(), aval->last_insert); }
/** * Given a node which was first seen at ``first_seen'' and last seen at * ``last_seen'', return probability that node still be alive now. * * @param first_seen first time node was seen / created * @param last_seen last time node was seen * * @return the probability that the node be still alive now. */ double stable_still_alive_probability(time_t first_seen, time_t last_seen) { time_delta_t life; time_delta_t elapsed; life = delta_time(last_seen, first_seen); if (life <= 0) return 0.0; elapsed = delta_time(tm_time(), last_seen); /* * Safety precaution: regardless of the past lifetime of the node, if * we have not heard from it for more than STABLE_UPPER_THRESH, then * consider it dead. */ return elapsed < STABLE_UPPER_THRESH ? stable_alive_probability(life, elapsed) : 0.0; }
/** * Add value to the table. * * If it was already present, its lifetime is augmented by the aging delay. * * The key argument is freed immediately if there is a free routine for * keys and the key was present in the table. * * The previous value is freed and replaced by the new one if there is * an insertion conflict and the value pointers are different. */ void aging_insert(aging_table_t *ag, const void *key, void *value) { gboolean found; void *okey, *ovalue; time_t now = tm_time(); struct aging_value *aval; g_assert(ag->magic == AGING_MAGIC); found = g_hash_table_lookup_extended(ag->table, key, &okey, &ovalue); if (found) { aval = ovalue; g_assert(aval->key == okey); if (aval->key != key && ag->kvfree != NULL) { /* * We discard the new and keep the old key instead. * That way, we don't have to update the hash table. */ (*ag->kvfree)(deconstify_gpointer(key), aval->value); } g_assert(aval->cq_ev != NULL); /* * Value existed for this key, prolonge its life. */ aval->value = value; aval->ttl -= delta_time(now, aval->last_insert); aval->ttl += ag->delay; aval->ttl = MAX(aval->ttl, 1); aval->ttl = MIN(aval->ttl, INT_MAX / 1000); aval->last_insert = now; cq_resched(aval->cq_ev, 1000 * aval->ttl); } else { WALLOC(aval); aval->value = value; aval->key = deconstify_gpointer(key); aval->ttl = ag->delay; aval->ttl = MAX(aval->ttl, 1); aval->ttl = MIN(aval->ttl, INT_MAX / 1000); aval->last_insert = now; aval->ag = ag; aval->cq_ev = cq_insert(aging_cq, 1000 * aval->ttl, aging_expire, aval); gm_hash_table_insert_const(ag->table, key, aval); } }
/** * @return NULL on error, a newly allocated string via halloc() otherwise. */ static char * uhc_get_next(void) { struct uhc *uhc; char *host; time_t now; size_t n; g_return_val_if_fail(uhc_list, NULL); now = tm_time(); n = hash_list_count(uhc_list); if (0 == n) return NULL; /* * Wait UHC_RETRY_AFTER secs before contacting the UHC again. * Can't be too long because the UDP reply may get lost if the * requesting host already has a saturated b/w. * If we come here, it's because we're lacking hosts for establishing * a Gnutella connection, after we exhausted our caches. */ while (n-- != 0) { uhc = hash_list_head(uhc_list); g_assert(uhc != NULL); /* We computed count on entry */ if (delta_time(now, uhc->stamp) >= UHC_RETRY_AFTER) goto found; hash_list_moveto_tail(uhc_list, uhc); } return NULL; found: uhc->stamp = now; host = h_strdup(uhc->host); if (uhc->used < UHC_MAX_ATTEMPTS) { uhc->used++; hash_list_moveto_tail(uhc_list, uhc); } else { hash_list_remove(uhc_list, uhc); uhc_free(&uhc); } return host; }
/* * Avoid nodes being stuck helplessly due to completely stale caches. * @return TRUE if an UHC may be contact, FALSE if it's not permissable. */ static gboolean host_cache_allow_bypass(void) { static time_t last_try; if (node_count() > 0) return FALSE; /* Wait at least 2 minutes after starting up */ if (delta_time(tm_time(), GNET_PROPERTY(start_stamp)) < 2 * 60) return FALSE; /* * Allow again after 12 hours, useful after unexpected network outage * or downtime. */ if (last_try && delta_time(tm_time(), last_try) < 12 * 3600) return FALSE; last_try = tm_time(); return TRUE; }
/** * Comparison of two knodes based on their probability of being dead. */ int knode_dead_probability_cmp(const void *a, const void *b) { const knode_t *k1 = a; const knode_t *k2 = b; double p1, p2; double e; p1 = knode_still_alive_probability(k1); p2 = knode_still_alive_probability(k2); /* Higher alive chances => lower dead probability */ e = p2 - p1; if (e < 0.0) e = -e; if (e < 1e-15) { time_delta_t d; /* * Probabilities of presence are comparable. * The more ancient node is more likely to be alive. * Otherwise, the one we heard from last is more likely to be alive. */ d = delta_time(k1->first_seen, k2->first_seen); if (0 == d) { d = delta_time(k1->last_seen, k2->last_seen); return 0 == d ? 0 : d > 0 ? -1 : +1; } else { return d > 0 ? +1 : -1; } } else { return p2 > p1 ? +1 : -1; } }
int main(int argc, char **argv) { FILE *file_in = fopen(argv[1], "r"); char buff[256]; int i, serial_fd; int waittime; serial_fd = initiate_serial_port("/dev/ttyUSB0"); if (!file_in) { fprintf(stderr, "Unable to open input file %s\n", argv[1]); return -1; } gettimeofday(&time_d, NULL); for (i = 0; i < 63; i++) { fread(buff, 1, PACKET_SIZE, file_in); write(serial_fd, buff, PACKET_SIZE); if((waittime = ((1000000 / (8000 / PACKET_SIZE)) - delta_time())) > 0) usleep(waittime); fprintf(stderr, "sending some data\n"); } for (;;) { fread(buff, 1, PACKET_SIZE, file_in); write(serial_fd, buff, PACKET_SIZE); read(serial_fd, buff, PACKET_SIZE); fwrite(buff, 1, PACKET_SIZE, stdout); fflush(stdout); if((waittime = ((1000000 / (8000 / PACKET_SIZE)) - delta_time())) > 0) usleep(waittime); } return 0; }
/** * Can the node which timed-out in the past be considered again as the * target of an RPC, and therefore returned in k-closest lookups? */ bool knode_can_recontact(const knode_t *kn) { time_t grace; time_delta_t elapsed; knode_check(kn); if (!kn->rpc_timeouts) return TRUE; /* Timeout condition was cleared */ grace = 1 << kn->rpc_timeouts; elapsed = delta_time(tm_time(), kn->last_sent); return elapsed > grace; }
/** * DBMW foreach iterator to remove expired DB keys. * @return TRUE if entry must be deleted. */ static bool publisher_remove_expired(void *u_key, void *value, size_t u_len, void *u_data) { const struct pubdata *pd = value; (void) u_key; (void) u_len; (void) u_data; /* * Entries for which we should re-enqueue a publish request now * have expired and can be deleted. */ return delta_time(tm_time(), pd->next_enqueue) >= 0; }
void hal_waitUntil (u8_t time) { #ifdef ARDUINO u4_t delta = delta_time(time); // From delayMicroseconds docs: Currently, the largest value that // will produce an accurate delay is 16383. while (delta > (16000 / US_PER_OSTICK)) { delay(16); delta -= (16000 / US_PER_OSTICK); } if (delta > 0) delayMicroseconds(delta * US_PER_OSTICK); #else fprintf(stderr, "Waiting until %u\n", time); while(micros() < (((uint64_t) time) * US_PER_OSTICK)); #endif }
/** * Return entry age in seconds, (time_delta_t) -1 if not found. */ time_delta_t aging_age(const aging_table_t *ag, const void *key) { struct aging_value *aval; time_delta_t age; aging_check(ag); aging_synchronize(ag); aval = hikset_lookup(ag->table, key); age = aval == NULL ? (time_delta_t) -1 : delta_time(tm_time(), aval->last_insert); aging_return(ag, age); }
void * finalize (void *hnd, c4snet_data_t * fltiles, int bs, int p) { struct timespec end; tile * tiles = *((tile **) C4SNetGetData (fltiles)); if (clock_gettime(CLOCK_REALTIME, &end)) { pexit("clock_gettime"); } printf("Time for size %d x %d : %lf sec\n", bs * p, bs * p, delta_time(begin, end)); write_matrix(tiles, p, bs); C4SNetOut (hnd, 1, C4SNetCreate (CTYPE_char, 5, "Done.")); C4SNetFree (fltiles); return hnd; }
/** * Estimate probability of presence for a value published to some roots in * a given time frame. * * @param d how many seconds in the future? * @param rs the STORE lookup path, giving root candidates * @param status the array of STORE status for each entry in the path * * @return an estimated probability of presence of the value in the network. */ double stable_store_presence(time_delta_t d, const lookup_rs_t *rs, const guint16 *status) { double q = 1.0; size_t i; size_t count = lookup_result_path_length(rs); /* * We may be called by publish callbacks invoked to clean up because * the operation was cancelled. Maybe the DHT was disabled during the * operation, meaning our data structures have been cleaned up? In that * case, abort immediately. * * NOTE: this is not an assertion, it can happen in practice and needs to * be explicitly checked for. */ if (NULL == db_lifedata) /* DHT disabled dynamically */ return 0.0; /* * The probability of presence is (1 - q) where q is the probability * that the value be lost by all the nodes, i.e. that all the nodes * to which the value was published to be gone in "d" seconds. */ for (i = 0; i < count; i++) { if (status[i] == STORE_SC_OK) { const knode_t *kn = lookup_result_nth_node(rs, i); struct lifedata *ld = get_lifedata(kn->id); if (NULL == ld) { return 0.0; /* Cannot compute a suitable probability */ } else { time_delta_t alive = delta_time(ld->last_seen, ld->first_seen); double p = stable_alive_probability(alive, d); q *= (1.0 - p); /* (1 - p) is proba this node will be gone */ } } } return 1.0 - q; }
/** * Check the given IP against the entries in the bogus IP database. * * @returns TRUE if found, and FALSE if not. */ bool bogons_check(const host_addr_t ha) { if G_UNLIKELY(NULL == bogons_db) return FALSE; /* * If the bogons file is too ancient, there is a risk it may flag an * IP as bogus whereas it is no longer reserved. IPv4 address shortage * makes that likely. * --RAM, 2010-11-07 */ if (delta_time(tm_time(), bogons_mtime) > 15552000) /* ~6 months */ return !host_addr_is_routable(ha); return 0 != iprange_get_addr(bogons_db, ha); }
/** * @return whether the entry for the upload `ul' should be removed * from the UI with respect to the configured behaviour. */ gboolean upload_should_remove(time_t now, const upload_row_data_t *ul) { property_t prop = 0; g_assert(NULL != ul); switch (ul->status) { case GTA_UL_COMPLETE: prop = PROP_AUTOCLEAR_COMPLETED_UPLOADS; break; case GTA_UL_CLOSED: case GTA_UL_ABORTED: prop = PROP_AUTOCLEAR_FAILED_UPLOADS; break; case GTA_UL_PUSH_RECEIVED: case GTA_UL_SENDING: case GTA_UL_HEADERS: case GTA_UL_WAITING: case GTA_UL_EXPECTING: case GTA_UL_QUEUED: case GTA_UL_QUEUE: case GTA_UL_QUEUE_WAITING: break; } if (0 != prop) { guint32 val; time_delta_t grace; gnet_prop_get_guint32_val(PROP_ENTRY_REMOVAL_TIMEOUT, &val); grace = val; if (delta_time(now, ul->last_update) > grace) { gboolean auto_remove; gui_prop_get_boolean_val(prop, &auto_remove); return auto_remove; } } return FALSE; }
/** * Add the servent update as a "UP" child to the root. */ static void g2_build_add_uptime(g2_tree_t *t) { time_delta_t uptime; char payload[8]; int n; g2_tree_t *c; /* * The uptime will typically be small, hence it is encoded as a variable * length little-endian value, with trailing zeros removed. Usually * only 2 or 3 bytes will be necesssary to encode the uptime (in seconds). */ uptime = delta_time(tm_time(), GNET_PROPERTY(start_stamp)); n = vlint_encode(uptime, payload); c = g2_tree_alloc_copy("UP", payload, n); /* No trailing 0s */ g2_tree_add_child(t, c); }
gboolean uploads_gui_update_required(time_t now) { static time_t last_update; time_delta_t delta; /* * Usually don't perform updates if nobody is watching. However, * we do need to perform periodic cleanup of dead entries or the * memory usage will grow. Perform an update every UPDATE_MIN minutes * at least. * --RAM, 28/12/2003 */ delta = last_update ? delta_time(now, last_update) : UPDATE_MIN; if (0 == delta || (delta < UPDATE_MIN && !uploads_gui_is_visible())) return FALSE; last_update = now; return TRUE; }
/** * Remove expired messages (eslist iterator). * * @return TRUE if message has expired and was freed up. */ static bool udp_tx_desc_expired(void *data, void *udata) { struct udp_tx_desc *txd = data; udp_sched_t *us = udata; udp_sched_check(us); udp_tx_desc_check(txd); if (delta_time(tm_time(), txd->expire) > 0) { udp_sched_log(1, "%p: expiring mb=%p (%d bytes) prio=%u", us, txd->mb, pmsg_size(txd->mb), pmsg_prio(txd->mb)); if (txd->cb->add_tx_dropped != NULL) (*txd->cb->add_tx_dropped)(txd->tx->owner, 1); /* Dropped in TX */ return udp_tx_desc_drop(data, udata); /* Returns TRUE */ } return FALSE; }
/** * Periodic garbage collecting routine. */ static bool aging_gc(void *obj) { aging_table_t *ag = obj; time_t now = tm_time(); struct aging_value *aval; aging_check(ag); aging_synchronize(ag); g_assert(elist_count(&ag->list) == hikset_count(ag->table)); while (NULL != (aval = elist_head(&ag->list))) { if (delta_time(now, aval->last_insert) <= ag->delay) break; /* List is sorted, oldest items first */ hikset_remove(ag->table, aval->key); aging_free(aval, ag); } aging_return(ag, TRUE); /* Keep calling */ }
/** * Update internal information about the NAT-PMP gateway upon reception * of an RPC reply. */ static void natpmp_update(natpmp_t *np, unsigned sssoe) { time_delta_t d; unsigned conservative_sssoe; natpmp_check(np); d = delta_time(tm_time(), np->last_update); conservative_sssoe = uint_saturate_add(np->sssoe, 7 * d / 8); if (sssoe < conservative_sssoe && conservative_sssoe - sssoe > 1) { np->rebooted = TRUE; if (GNET_PROPERTY(natpmp_debug) > 1) { g_debug("NATPMP new SSSOE=%u < conservative SSSOE=%u, %s rebooted", sssoe, conservative_sssoe, host_addr_to_string(np->gateway)); } } np->last_update = tm_time(); np->sssoe = sssoe; }
/** * Looks for ``hostname'' in ``cache'' wrt to cache->timeout. If * ``hostname'' is not found or the entry is expired, FALSE will be * returned. Expired entries will be removed! ``addr'' is allowed to * be NULL, otherwise the cached IP will be stored into the variable * ``addr'' points to. * * @param addrs An array of host_addr_t items. If not NULL, up to * ``n'' items will be copied from the cache. * @param n The number of items "addrs" can hold. * @return The number of cached addresses for the given hostname. */ static size_t adns_cache_lookup(adns_cache_t *cache, time_t now, const char *hostname, host_addr_t *addrs, size_t n) { adns_cache_entry_t *entry; g_assert(NULL != cache); g_assert(NULL != hostname); g_assert(0 == n || NULL != addrs); entry = hikset_lookup(cache->ht, hostname); if (entry) { if (delta_time(now, entry->timestamp) < cache->timeout) { size_t i; for (i = 0; i < n; i++) { if (i < entry->n) { addrs[i] = entry->addrs[i]; if (common_dbg > 0) g_debug("%s: \"%s\" cached (addr=%s)", G_STRFUNC, entry->hostname, host_addr_to_string(addrs[i])); } else { addrs[i] = zero_host_addr; } } } else { if (common_dbg > 0) { g_debug("%s: removing \"%s\" from cache", G_STRFUNC, entry->hostname); } hikset_remove(cache->ht, hostname); adns_cache_free_entry(cache, entry->id); entry = NULL; } } return entry ? entry->n : 0; }
void sdl_Throttle(void) { if (sdl_LockSpeed) { #if 0 static Uint32 next_tick = 0; Uint32 this_tick; /* Wait for the next frame */ this_tick = SDL_GetTicks(); if ( this_tick < next_tick ) { SDL_Delay(next_tick-this_tick); } next_tick = this_tick + (1000/FRAMES_PER_SEC); #endif long delay; delay = 10000/FRAMES_PER_SEC - delta_time(); if (delay>0 && audio_waterlevel > AUDIO_WATERMARK ) usleep(delay); // FIXME } CPC_UpdateAudio(); }
/** * Watchdog timer has expired. */ static void wd_expired(cqueue_t *cq, void *arg) { watchdog_t *wd = arg; watchdog_check(wd); wd->ev = NULL; /* * If no kicks have happened, fire the registered callback. Otherwise, * reset the callout queue event, so that the sliding window is starting * when the last tick happened. */ if (0 == wd->last_kick) { wd_trigger(wd); } else { time_t now = tm_time(); time_delta_t elapsed = delta_time(now, wd->last_kick); /* * If for some reason the callout queue heartbeat got delayed, more * than ``period'' seconds may have elapsed since the last kick, in * which case we also need to trigger the callback. * * Note that watchdog ``period'' is expressed in seconds. */ if (elapsed >= wd->period) { wd_trigger(wd); } else { time_delta_t delay = wd->period - elapsed; wd->ev = cq_insert(cq, delay * 1000, wd_expired, wd); } } }
void nodes_gui_timer(time_t now) { static time_t last_update; if (last_update == now) return; /* * Usually don't perform updates if nobody is watching. However, * we do need to perform periodic cleanup of dead entries or the * memory usage will grow. Perform an update every UPDATE_MIN minutes * at least. * --RAM, 28/12/2003 */ if ( nodes_gui_is_visible() || delta_time(now, last_update) >= UPDATE_MIN ) { last_update = now; nodes_gui_update_display(now); } }
/** * Delay the nagle timer when more data is coming. */ static void deflate_nagle_delay(txdrv_t *tx) { struct attr *attr = tx->opaque; g_assert(attr->flags & DF_NAGLE); g_assert(NULL != attr->tm_ev); g_assert(attr->nagle); /* Nagle is allowed */ /* * We push back the initial delay a little while when more data comes, * hoping that enough will be output so that we end up sending the TX * buffer without having to trigger a flush too soon, since that would * degrade compression performance. * * If too much time elapsed since the Nagle timer started, do not * postpone the flush otherwise we might delay time-sensitive messages. */ if (delta_time(tm_time(), attr->nagle_start) < BUFFER_DELAY) { int delay = cq_remaining(attr->tm_ev); cq_resched(attr->tm_ev, MAX(delay, BUFFER_NAGLE / 2)); } }
int main(int argc, char* argv[]) { pfring *pd; char *device, *buffer; u_int buffer_len, num_runs, test_len, i, test_id, j; struct timeval startTime, endTime; double deltaUsec, call_per_sec, thpt, call_duration_usec; device = "eth0"; pd = pfring_open(device, 128, PF_RING_PROMISC); if(pd == NULL) { printf("pfring_open error(%s) [%s]\n", device, strerror(errno)); return(-1); } else { u_int32_t version; pfring_set_application_name(pd, "pfsystest"); pfring_version(pd, &version); printf("Using PF_RING v.%d.%d.%d\n", (version & 0xFFFF0000) >> 16, (version & 0x0000FF00) >> 8, version & 0x000000FF); } if(0) { test_id = 64; buffer_len = test_id*1024; buffer = malloc(buffer_len); if(buffer == NULL) { /* oops, couldn't allocate memory */ fprintf(stderr, "Unable to allocate memory requested (%s)\n", strerror(errno)); return (-1); } num_runs = 10000; for(j=0; j<=test_id; j++) { test_len = j*1024; gettimeofday(&startTime, NULL); for(i=0; i<num_runs; i++) pfring_loopback_test(pd, buffer, buffer_len, test_len); gettimeofday(&endTime, NULL); deltaUsec = delta_time(&endTime, &startTime); call_duration_usec = deltaUsec/((double)num_runs); call_per_sec = ((double)num_runs*1000000)/deltaUsec; thpt = (double)(call_per_sec * test_len * 8) / (double)1000000000; printf("%02d [Test len=%d KB][%.2f calls/sec][%.1f usec/call][Thpt: %.2f Gbps][%s]\n", j, test_len/1024, call_per_sec, call_duration_usec, thpt, (thpt > (double)10) ? "10 Gbit Wire rate" : "No Wire rate"); } free(buffer); /* ************************************** */ test_id = 4; buffer_len = test_id*1024*1024; buffer = malloc(buffer_len); if(buffer == NULL) { /* oops, couldn't allocate memory */ fprintf(stderr, "Unable to allocate memory requested (%s)\n", strerror(errno)); return (-1); } num_runs = 1000; for(j=1; j<=test_id; j++) { test_len = j*1024*1024; gettimeofday(&startTime, NULL); for(i=0; i<num_runs; i++) pfring_loopback_test(pd, buffer, buffer_len, test_len); gettimeofday(&endTime, NULL); deltaUsec = delta_time(&endTime, &startTime); call_duration_usec = deltaUsec/((double)num_runs); call_per_sec = ((double)num_runs*1000000)/deltaUsec; thpt = (double)(call_per_sec * test_len * 8) / (double)1000000000; printf("%02d [Test len=%d KB][%.2f calls/sec][%.1f usec/call][Thpt: %.2f Gbps][%s]\n", j, test_len/1024, call_per_sec, call_duration_usec, thpt, (thpt > (double)10) ? "10 Gbit Wire rate" : "No Wire rate"); } free(buffer); } /* ******************************************** */ test_id = 8; buffer_len = test_id*1024*1024; buffer = malloc(buffer_len); if(buffer == NULL) { /* oops, couldn't allocate memory */ fprintf(stderr, "Unable to allocate memory requested (%s)\n", strerror(errno)); return (-1); } num_runs = 1000; for(j=0; j<=test_id; j++) { test_len = j*1024*1024; gettimeofday(&startTime, NULL); for(i=0; i<num_runs; i++) pfring_loopback_test(pd, buffer, buffer_len, test_len); gettimeofday(&endTime, NULL); deltaUsec = delta_time(&endTime, &startTime); printf("%02d Test len=%d, %.2f calls/sec [%.1f usec/call]\n", j, test_len, ((double)num_runs*1000)/deltaUsec, deltaUsec/num_runs); } free(buffer); pfring_close(pd); return(0); }