static void init_clock(struct clock *c, clockid_t id) { memset(c, 0, sizeof *c); c->id = id; ovs_mutex_init(&c->mutex); atomic_init(&c->slow_path, false); xclock_gettime(c->id, &c->cache); }
static void init_clock(struct clock *c, clockid_t id) { memset(c, 0, sizeof *c); c->id = id; ovs_mutex_init(&c->mutex); atomic_init(&c->slow_path, false); xclock_gettime(c->id, &c->cache); timewarp_seq = seq_create(); memset(&c->large_warp, 0, sizeof(c->large_warp)); }
/* Starts a Netlink "dump" operation, by sending 'request' to the kernel on a * Netlink socket created with the given 'protocol', and initializes 'dump' to * reflect the state of the operation. * * 'request' must contain a Netlink message. Before sending the message, * nlmsg_len will be finalized to match request->size, and nlmsg_pid will be * set to the Netlink socket's pid. NLM_F_DUMP and NLM_F_ACK will be set in * nlmsg_flags. * * The design of this Netlink socket library ensures that the dump is reliable. * * This function provides no status indication. nl_dump_done() provides an * error status for the entire dump operation. * * The caller must eventually destroy 'request'. */ void nl_dump_start(struct nl_dump *dump, int protocol, const struct ofpbuf *request) { nl_msg_nlmsghdr(request)->nlmsg_flags |= NLM_F_DUMP | NLM_F_ACK; ovs_mutex_init(&dump->mutex); ovs_mutex_lock(&dump->mutex); dump->status = nl_pool_alloc(protocol, &dump->sock); if (!dump->status) { dump->status = nl_sock_send__(dump->sock, request, nl_sock_allocate_seq(dump->sock, 1), true); } dump->nl_seq = nl_msg_nlmsghdr(request)->nlmsg_seq; ovs_mutex_unlock(&dump->mutex); }
static void benchmark_ccmap(void) { struct ccmap ccmap; struct timeval start; pthread_t *threads; struct ccmap_aux aux; size_t i; /* Insertions. */ xgettimeofday(&start); ccmap_init(&ccmap); for (i = 0; i < n_elems; i++) { ccmap_inc(&ccmap, hash_int(i, 0)); } printf("ccmap insert: %5d ms\n", elapsed(&start)); /* Search and mutation. */ xgettimeofday(&start); aux.ccmap = &ccmap; ovs_mutex_init(&aux.mutex); threads = xmalloc(n_threads * sizeof *threads); for (i = 0; i < n_threads; i++) { threads[i] = ovs_thread_create("search", search_ccmap, &aux); } for (i = 0; i < n_threads; i++) { xpthread_join(threads[i], NULL); } free(threads); printf("ccmap search: %5d ms\n", elapsed(&start)); /* Destruction. */ xgettimeofday(&start); for (i = 0; i < n_elems; i++) { uint32_t hash = hash_int(i, 0); if (ccmap_find(&ccmap, hash)) { /* Also remove any colliding hashes. */ while (ccmap_dec(&ccmap, hash)) { ; } } } ccmap_destroy(&ccmap); printf("ccmap destroy: %5d ms\n", elapsed(&start)); }
/* Creates and returns a new rconn. * * 'probe_interval' is a number of seconds. If the interval passes once * without an OpenFlow message being received from the peer, the rconn sends * out an "echo request" message. If the interval passes again without a * message being received, the rconn disconnects and re-connects to the peer. * Setting 'probe_interval' to 0 disables this behavior. * * 'max_backoff' is the maximum number of seconds between attempts to connect * to the peer. The actual interval starts at 1 second and doubles on each * failure until it reaches 'max_backoff'. If 0 is specified, the default of * 8 seconds is used. * * The new rconn is initially unconnected. Use rconn_connect() or * rconn_connect_unreliably() to connect it. * * Connections made by the rconn will automatically negotiate an OpenFlow * protocol version acceptable to both peers on the connection. The version * negotiated will be one of those in the 'allowed_versions' bitmap: version * 'x' is allowed if allowed_versions & (1 << x) is nonzero. (The underlying * vconn will treat an 'allowed_versions' of 0 as OFPUTIL_DEFAULT_VERSIONS.) */ struct rconn * rconn_create(int probe_interval, int max_backoff, uint8_t dscp, uint32_t allowed_versions) { struct rconn *rc = xzalloc(sizeof *rc); ovs_mutex_init(&rc->mutex); rc->state = S_VOID; rc->state_entered = time_now(); rc->vconn = NULL; rc->name = xstrdup("void"); rc->target = xstrdup("void"); rc->reliable = false; list_init(&rc->txq); rc->backoff = 0; rc->max_backoff = max_backoff ? max_backoff : 8; rc->backoff_deadline = TIME_MIN; rc->last_connected = TIME_MIN; rc->last_disconnected = TIME_MIN; rc->seqno = 0; rc->packets_sent = 0; rc->probably_admitted = false; rc->last_admitted = time_now(); rc->packets_received = 0; rc->n_attempted_connections = 0; rc->n_successful_connections = 0; rc->creation_time = time_now(); rc->total_time_connected = 0; rc->last_activity = time_now(); rconn_set_probe_interval(rc, probe_interval); rconn_set_dscp(rc, dscp); rc->n_monitors = 0; rc->allowed_versions = allowed_versions; return rc; }