1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
16 #include "ofproto-dpif-upcall.h"
25 #include "dynamic-string.h"
26 #include "fail-open.h"
27 #include "guarded-list.h"
32 #include "ofproto-dpif-ipfix.h"
33 #include "ofproto-dpif-sflow.h"
34 #include "ofproto-dpif-xlate.h"
36 #include "poll-loop.h"
41 #define MAX_QUEUE_LENGTH 512
42 #define FLOW_MISS_MAX_BATCH 50
43 #define REVALIDATE_MAX_BATCH 50
46 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_upcall);
48 COVERAGE_DEFINE(upcall_queue_overflow);
50 /* A thread that processes each upcall handed to it by the dispatcher thread,
51 * forwards the upcall's packet, and possibly sets up a kernel flow as a
54 struct udpif *udpif; /* Parent udpif. */
55 pthread_t thread; /* Thread ID. */
56 char *name; /* Thread name. */
58 struct ovs_mutex mutex; /* Mutex guarding the following. */
60 /* Atomic queue of unprocessed upcalls. */
61 struct list upcalls OVS_GUARDED;
62 size_t n_upcalls OVS_GUARDED;
64 bool need_signal; /* Only changed by the dispatcher. */
66 pthread_cond_t wake_cond; /* Wakes 'thread' while holding
70 /* A thread that processes each kernel flow handed to it by the flow_dumper
71 * thread, updates OpenFlow statistics, and updates or removes the kernel flow
74 struct udpif *udpif; /* Parent udpif. */
75 char *name; /* Thread name. */
77 pthread_t thread; /* Thread ID. */
78 struct hmap ukeys; /* Datapath flow keys. */
82 struct ovs_mutex mutex; /* Mutex guarding the following. */
83 pthread_cond_t wake_cond;
84 struct list udumps OVS_GUARDED; /* Unprocessed udumps. */
85 size_t n_udumps OVS_GUARDED; /* Number of unprocessed udumps. */
88 /* An upcall handler for ofproto_dpif.
90 * udpif has two logically separate pieces:
92 * - A "dispatcher" thread that reads upcalls from the kernel and dispatches
93 * them to one of several "handler" threads (see struct handler).
95 * - A "flow_dumper" thread that reads the kernel flow table and dispatches
96 * flows to one of several "revalidator" threads (see struct
99 struct list list_node; /* In all_udpifs list. */
101 struct dpif *dpif; /* Datapath handle. */
102 struct dpif_backer *backer; /* Opaque dpif_backer pointer. */
104 uint32_t secret; /* Random seed for upcall hash. */
106 pthread_t dispatcher; /* Dispatcher thread ID. */
107 pthread_t flow_dumper; /* Flow dumper thread ID. */
109 struct handler *handlers; /* Upcall handlers. */
112 struct revalidator *revalidators; /* Flow revalidators. */
113 size_t n_revalidators;
115 uint64_t last_reval_seq; /* 'reval_seq' at last revalidation. */
116 struct seq *reval_seq; /* Incremented to force revalidation. */
118 struct seq *dump_seq; /* Increments each dump iteration. */
120 struct latch exit_latch; /* Tells child threads to exit. */
122 long long int dump_duration; /* Duration of the last flow dump. */
124 /* Datapath flow statistics. */
125 unsigned int max_n_flows;
126 unsigned int avg_n_flows;
128 /* Following fields are accessed and modified by different threads. */
129 atomic_uint flow_limit; /* Datapath flow hard limit. */
131 /* n_flows_mutex prevents multiple threads updating these concurrently. */
132 atomic_uint64_t n_flows; /* Number of flows in the datapath. */
133 atomic_llong n_flows_timestamp; /* Last time n_flows was updated. */
134 struct ovs_mutex n_flows_mutex;
138 BAD_UPCALL, /* Some kind of bug somewhere. */
139 MISS_UPCALL, /* A flow miss. */
140 SFLOW_UPCALL, /* sFlow sample. */
141 FLOW_SAMPLE_UPCALL, /* Per-flow sampling. */
142 IPFIX_UPCALL /* Per-bridge sampling. */
146 struct list list_node; /* For queuing upcalls. */
147 struct flow_miss *flow_miss; /* This upcall's flow_miss. */
149 /* Raw upcall plus data for keeping track of the memory backing it. */
150 struct dpif_upcall dpif_upcall; /* As returned by dpif_recv() */
151 struct ofpbuf upcall_buf; /* Owns some data in 'dpif_upcall'. */
152 uint64_t upcall_stub[512 / 8]; /* Buffer to reduce need for malloc(). */
155 /* 'udpif_key's are responsible for tracking the little bit of state udpif
156 * needs to do flow expiration which can't be pulled directly from the
157 * datapath. They are owned, created by, maintained, and destroyed by a single
158 * revalidator making them easy to efficiently handle with multiple threads. */
160 struct hmap_node hmap_node; /* In parent revalidator 'ukeys' map. */
162 struct nlattr *key; /* Datapath flow key. */
163 size_t key_len; /* Length of 'key'. */
165 struct dpif_flow_stats stats; /* Stats at most recent flow dump. */
166 long long int created; /* Estimation of creation time. */
168 bool mark; /* Used by mark and sweep GC algorithm. */
170 struct odputil_keybuf key_buf; /* Memory for 'key'. */
173 /* 'udpif_flow_dump's hold the state associated with one iteration in a flow
174 * dump operation. This is created by the flow_dumper thread and handed to the
175 * appropriate revalidator thread to be processed. */
176 struct udpif_flow_dump {
177 struct list list_node;
179 struct nlattr *key; /* Datapath flow key. */
180 size_t key_len; /* Length of 'key'. */
181 uint32_t key_hash; /* Hash of 'key'. */
183 struct odputil_keybuf mask_buf;
184 struct nlattr *mask; /* Datapath mask for 'key'. */
185 size_t mask_len; /* Length of 'mask'. */
187 struct dpif_flow_stats stats; /* Stats pulled from the datapath. */
189 bool need_revalidate; /* Key needs revalidation? */
191 struct odputil_keybuf key_buf;
194 /* Flow miss batching.
196 * Some dpifs implement operations faster when you hand them off in a batch.
197 * To allow batching, "struct flow_miss" queues the dpif-related work needed
198 * for a given flow. Each "struct flow_miss" corresponds to sending one or
199 * more packets, plus possibly installing the flow in the dpif. */
201 struct hmap_node hmap_node;
202 struct ofproto_dpif *ofproto;
205 const struct nlattr *key;
207 enum dpif_upcall_type upcall_type;
208 struct dpif_flow_stats stats;
209 odp_port_t odp_in_port;
211 uint64_t slow_path_buf[128 / 8];
212 struct odputil_keybuf mask_buf;
214 struct xlate_out xout;
219 static void upcall_destroy(struct upcall *);
221 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
222 static struct list all_udpifs = LIST_INITIALIZER(&all_udpifs);
224 static void recv_upcalls(struct udpif *);
225 static void handle_upcalls(struct handler *handler, struct list *upcalls);
226 static void *udpif_flow_dumper(void *);
227 static void *udpif_dispatcher(void *);
228 static void *udpif_upcall_handler(void *);
229 static void *udpif_revalidator(void *);
230 static uint64_t udpif_get_n_flows(struct udpif *);
231 static void revalidate_udumps(struct revalidator *, struct list *udumps);
232 static void revalidator_sweep(struct revalidator *);
233 static void upcall_unixctl_show(struct unixctl_conn *conn, int argc,
234 const char *argv[], void *aux);
235 static void upcall_unixctl_disable_megaflows(struct unixctl_conn *, int argc,
236 const char *argv[], void *aux);
237 static void upcall_unixctl_enable_megaflows(struct unixctl_conn *, int argc,
238 const char *argv[], void *aux);
239 static void ukey_delete(struct revalidator *, struct udpif_key *);
241 static atomic_bool enable_megaflows = ATOMIC_VAR_INIT(true);
244 udpif_create(struct dpif_backer *backer, struct dpif *dpif)
246 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
247 struct udpif *udpif = xzalloc(sizeof *udpif);
249 if (ovsthread_once_start(&once)) {
250 unixctl_command_register("upcall/show", "", 0, 0, upcall_unixctl_show,
252 unixctl_command_register("upcall/disable-megaflows", "", 0, 0,
253 upcall_unixctl_disable_megaflows, NULL);
254 unixctl_command_register("upcall/enable-megaflows", "", 0, 0,
255 upcall_unixctl_enable_megaflows, NULL);
256 ovsthread_once_done(&once);
260 udpif->backer = backer;
261 atomic_init(&udpif->flow_limit, MIN(ofproto_flow_limit, 10000));
262 udpif->secret = random_uint32();
263 udpif->reval_seq = seq_create();
264 udpif->dump_seq = seq_create();
265 latch_init(&udpif->exit_latch);
266 list_push_back(&all_udpifs, &udpif->list_node);
267 atomic_init(&udpif->n_flows, 0);
268 atomic_init(&udpif->n_flows_timestamp, LLONG_MIN);
269 ovs_mutex_init(&udpif->n_flows_mutex);
275 udpif_destroy(struct udpif *udpif)
277 udpif_set_threads(udpif, 0, 0);
280 list_remove(&udpif->list_node);
281 latch_destroy(&udpif->exit_latch);
282 seq_destroy(udpif->reval_seq);
283 seq_destroy(udpif->dump_seq);
284 atomic_destroy(&udpif->flow_limit);
285 atomic_destroy(&udpif->n_flows);
286 atomic_destroy(&udpif->n_flows_timestamp);
287 ovs_mutex_destroy(&udpif->n_flows_mutex);
291 /* Tells 'udpif' how many threads it should use to handle upcalls. Disables
292 * all threads if 'n_handlers' and 'n_revalidators' is zero. 'udpif''s
293 * datapath handle must have packet reception enabled before starting threads.
296 udpif_set_threads(struct udpif *udpif, size_t n_handlers,
297 size_t n_revalidators)
299 /* Stop the old threads (if any). */
300 if (udpif->handlers &&
301 (udpif->n_handlers != n_handlers
302 || udpif->n_revalidators != n_revalidators)) {
305 latch_set(&udpif->exit_latch);
307 for (i = 0; i < udpif->n_handlers; i++) {
308 struct handler *handler = &udpif->handlers[i];
310 ovs_mutex_lock(&handler->mutex);
311 xpthread_cond_signal(&handler->wake_cond);
312 ovs_mutex_unlock(&handler->mutex);
313 xpthread_join(handler->thread, NULL);
316 for (i = 0; i < udpif->n_revalidators; i++) {
317 struct revalidator *revalidator = &udpif->revalidators[i];
319 ovs_mutex_lock(&revalidator->mutex);
320 xpthread_cond_signal(&revalidator->wake_cond);
321 ovs_mutex_unlock(&revalidator->mutex);
322 xpthread_join(revalidator->thread, NULL);
325 xpthread_join(udpif->flow_dumper, NULL);
326 xpthread_join(udpif->dispatcher, NULL);
328 for (i = 0; i < udpif->n_revalidators; i++) {
329 struct revalidator *revalidator = &udpif->revalidators[i];
330 struct udpif_flow_dump *udump, *next_udump;
331 struct udpif_key *ukey, *next_ukey;
333 LIST_FOR_EACH_SAFE (udump, next_udump, list_node,
334 &revalidator->udumps) {
335 list_remove(&udump->list_node);
339 HMAP_FOR_EACH_SAFE (ukey, next_ukey, hmap_node,
340 &revalidator->ukeys) {
341 ukey_delete(revalidator, ukey);
343 hmap_destroy(&revalidator->ukeys);
344 ovs_mutex_destroy(&revalidator->mutex);
346 free(revalidator->name);
349 for (i = 0; i < udpif->n_handlers; i++) {
350 struct handler *handler = &udpif->handlers[i];
351 struct upcall *miss, *next;
353 LIST_FOR_EACH_SAFE (miss, next, list_node, &handler->upcalls) {
354 list_remove(&miss->list_node);
355 upcall_destroy(miss);
357 ovs_mutex_destroy(&handler->mutex);
359 xpthread_cond_destroy(&handler->wake_cond);
362 latch_poll(&udpif->exit_latch);
364 free(udpif->revalidators);
365 udpif->revalidators = NULL;
366 udpif->n_revalidators = 0;
368 free(udpif->handlers);
369 udpif->handlers = NULL;
370 udpif->n_handlers = 0;
373 /* Start new threads (if necessary). */
374 if (!udpif->handlers && n_handlers) {
377 udpif->n_handlers = n_handlers;
378 udpif->n_revalidators = n_revalidators;
380 udpif->handlers = xzalloc(udpif->n_handlers * sizeof *udpif->handlers);
381 for (i = 0; i < udpif->n_handlers; i++) {
382 struct handler *handler = &udpif->handlers[i];
384 handler->udpif = udpif;
385 list_init(&handler->upcalls);
386 handler->need_signal = false;
387 xpthread_cond_init(&handler->wake_cond, NULL);
388 ovs_mutex_init(&handler->mutex);
389 xpthread_create(&handler->thread, NULL, udpif_upcall_handler,
393 udpif->revalidators = xzalloc(udpif->n_revalidators
394 * sizeof *udpif->revalidators);
395 for (i = 0; i < udpif->n_revalidators; i++) {
396 struct revalidator *revalidator = &udpif->revalidators[i];
398 revalidator->udpif = udpif;
399 list_init(&revalidator->udumps);
400 hmap_init(&revalidator->ukeys);
401 ovs_mutex_init(&revalidator->mutex);
402 xpthread_cond_init(&revalidator->wake_cond, NULL);
403 xpthread_create(&revalidator->thread, NULL, udpif_revalidator,
406 xpthread_create(&udpif->dispatcher, NULL, udpif_dispatcher, udpif);
407 xpthread_create(&udpif->flow_dumper, NULL, udpif_flow_dumper, udpif);
411 /* Notifies 'udpif' that something changed which may render previous
412 * xlate_actions() results invalid. */
414 udpif_revalidate(struct udpif *udpif)
416 seq_change(udpif->reval_seq);
419 /* Returns a seq which increments every time 'udpif' pulls stats from the
420 * datapath. Callers can use this to get a sense of when might be a good time
421 * to do periodic work which relies on relatively up to date statistics. */
423 udpif_dump_seq(struct udpif *udpif)
425 return udpif->dump_seq;
429 udpif_get_memory_usage(struct udpif *udpif, struct simap *usage)
433 simap_increase(usage, "dispatchers", 1);
434 simap_increase(usage, "flow_dumpers", 1);
436 simap_increase(usage, "handlers", udpif->n_handlers);
437 for (i = 0; i < udpif->n_handlers; i++) {
438 struct handler *handler = &udpif->handlers[i];
439 ovs_mutex_lock(&handler->mutex);
440 simap_increase(usage, "handler upcalls", handler->n_upcalls);
441 ovs_mutex_unlock(&handler->mutex);
444 simap_increase(usage, "revalidators", udpif->n_revalidators);
445 for (i = 0; i < udpif->n_revalidators; i++) {
446 struct revalidator *revalidator = &udpif->revalidators[i];
447 ovs_mutex_lock(&revalidator->mutex);
448 simap_increase(usage, "revalidator dumps", revalidator->n_udumps);
450 /* XXX: This isn't technically thread safe because the revalidator
451 * ukeys maps isn't protected by a mutex since it's per thread. */
452 simap_increase(usage, "revalidator keys",
453 hmap_count(&revalidator->ukeys));
454 ovs_mutex_unlock(&revalidator->mutex);
458 /* Removes all flows from all datapaths. */
464 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
465 dpif_flow_flush(udpif->dpif);
469 /* Destroys and deallocates 'upcall'. */
471 upcall_destroy(struct upcall *upcall)
474 ofpbuf_uninit(&upcall->dpif_upcall.packet);
475 ofpbuf_uninit(&upcall->upcall_buf);
481 udpif_get_n_flows(struct udpif *udpif)
483 long long int time, now;
487 atomic_read(&udpif->n_flows_timestamp, &time);
488 if (time < now - 100 && !ovs_mutex_trylock(&udpif->n_flows_mutex)) {
489 struct dpif_dp_stats stats;
491 atomic_store(&udpif->n_flows_timestamp, now);
492 dpif_get_dp_stats(udpif->dpif, &stats);
493 flow_count = stats.n_flows;
494 atomic_store(&udpif->n_flows, flow_count);
495 ovs_mutex_unlock(&udpif->n_flows_mutex);
497 atomic_read(&udpif->n_flows, &flow_count);
502 /* The dispatcher thread is responsible for receiving upcalls from the kernel,
503 * assigning them to a upcall_handler thread. */
505 udpif_dispatcher(void *arg)
507 struct udpif *udpif = arg;
509 set_subprogram_name("dispatcher");
510 while (!latch_is_set(&udpif->exit_latch)) {
512 dpif_recv_wait(udpif->dpif);
513 latch_wait(&udpif->exit_latch);
521 udpif_flow_dumper(void *arg)
523 struct udpif *udpif = arg;
525 set_subprogram_name("flow_dumper");
526 while (!latch_is_set(&udpif->exit_latch)) {
527 const struct dpif_flow_stats *stats;
528 long long int start_time, duration;
529 const struct nlattr *key, *mask;
530 struct dpif_flow_dump dump;
531 size_t key_len, mask_len;
532 unsigned int flow_limit;
533 bool need_revalidate;
537 reval_seq = seq_read(udpif->reval_seq);
538 need_revalidate = udpif->last_reval_seq != reval_seq;
539 udpif->last_reval_seq = reval_seq;
541 n_flows = udpif_get_n_flows(udpif);
542 udpif->max_n_flows = MAX(n_flows, udpif->max_n_flows);
543 udpif->avg_n_flows = (udpif->avg_n_flows + n_flows) / 2;
545 start_time = time_msec();
546 dpif_flow_dump_start(&dump, udpif->dpif);
547 while (dpif_flow_dump_next(&dump, &key, &key_len, &mask, &mask_len,
549 && !latch_is_set(&udpif->exit_latch)) {
550 struct udpif_flow_dump *udump = xmalloc(sizeof *udump);
551 struct revalidator *revalidator;
553 udump->key_hash = hash_bytes(key, key_len, udpif->secret);
554 memcpy(&udump->key_buf, key, key_len);
555 udump->key = (struct nlattr *) &udump->key_buf;
556 udump->key_len = key_len;
558 memcpy(&udump->mask_buf, mask, mask_len);
559 udump->mask = (struct nlattr *) &udump->mask_buf;
560 udump->mask_len = mask_len;
562 udump->stats = *stats;
563 udump->need_revalidate = need_revalidate;
565 revalidator = &udpif->revalidators[udump->key_hash
566 % udpif->n_revalidators];
568 ovs_mutex_lock(&revalidator->mutex);
569 while (revalidator->n_udumps >= REVALIDATE_MAX_BATCH * 3
570 && !latch_is_set(&udpif->exit_latch)) {
571 ovs_mutex_cond_wait(&revalidator->wake_cond,
572 &revalidator->mutex);
574 list_push_back(&revalidator->udumps, &udump->list_node);
575 revalidator->n_udumps++;
576 xpthread_cond_signal(&revalidator->wake_cond);
577 ovs_mutex_unlock(&revalidator->mutex);
579 dpif_flow_dump_done(&dump);
581 /* Let all the revalidators finish and garbage collect. */
582 seq_change(udpif->dump_seq);
583 for (i = 0; i < udpif->n_revalidators; i++) {
584 struct revalidator *revalidator = &udpif->revalidators[i];
585 ovs_mutex_lock(&revalidator->mutex);
586 xpthread_cond_signal(&revalidator->wake_cond);
587 ovs_mutex_unlock(&revalidator->mutex);
590 for (i = 0; i < udpif->n_revalidators; i++) {
591 struct revalidator *revalidator = &udpif->revalidators[i];
593 ovs_mutex_lock(&revalidator->mutex);
594 while (revalidator->dump_seq != seq_read(udpif->dump_seq)
595 && !latch_is_set(&udpif->exit_latch)) {
596 ovs_mutex_cond_wait(&revalidator->wake_cond,
597 &revalidator->mutex);
599 ovs_mutex_unlock(&revalidator->mutex);
602 duration = MAX(time_msec() - start_time, 1);
603 udpif->dump_duration = duration;
604 atomic_read(&udpif->flow_limit, &flow_limit);
605 if (duration > 2000) {
606 flow_limit /= duration / 1000;
607 } else if (duration > 1300) {
608 flow_limit = flow_limit * 3 / 4;
609 } else if (duration < 1000 && n_flows > 2000
610 && flow_limit < n_flows * 1000 / duration) {
613 flow_limit = MIN(ofproto_flow_limit, MAX(flow_limit, 1000));
614 atomic_store(&udpif->flow_limit, flow_limit);
616 if (duration > 2000) {
617 VLOG_INFO("Spent an unreasonably long %lldms dumping flows",
621 poll_timer_wait_until(start_time + MIN(MAX_IDLE, 500));
622 seq_wait(udpif->reval_seq, udpif->last_reval_seq);
623 latch_wait(&udpif->exit_latch);
630 /* The miss handler thread is responsible for processing miss upcalls retrieved
631 * by the dispatcher thread. Once finished it passes the processed miss
632 * upcalls to ofproto-dpif where they're installed in the datapath. */
634 udpif_upcall_handler(void *arg)
636 struct handler *handler = arg;
638 handler->name = xasprintf("handler_%u", ovsthread_id_self());
639 set_subprogram_name("%s", handler->name);
641 while (!latch_is_set(&handler->udpif->exit_latch)) {
642 struct list misses = LIST_INITIALIZER(&misses);
645 ovs_mutex_lock(&handler->mutex);
646 if (!handler->n_upcalls) {
647 ovs_mutex_cond_wait(&handler->wake_cond, &handler->mutex);
650 for (i = 0; i < FLOW_MISS_MAX_BATCH; i++) {
651 if (handler->n_upcalls) {
652 handler->n_upcalls--;
653 list_push_back(&misses, list_pop_front(&handler->upcalls));
658 ovs_mutex_unlock(&handler->mutex);
660 handle_upcalls(handler, &misses);
669 udpif_revalidator(void *arg)
671 struct revalidator *revalidator = arg;
673 revalidator->name = xasprintf("revalidator_%u", ovsthread_id_self());
674 set_subprogram_name("%s", revalidator->name);
676 struct list udumps = LIST_INITIALIZER(&udumps);
677 struct udpif *udpif = revalidator->udpif;
680 ovs_mutex_lock(&revalidator->mutex);
681 if (latch_is_set(&udpif->exit_latch)) {
682 ovs_mutex_unlock(&revalidator->mutex);
686 if (!revalidator->n_udumps) {
687 if (revalidator->dump_seq != seq_read(udpif->dump_seq)) {
688 revalidator->dump_seq = seq_read(udpif->dump_seq);
689 revalidator_sweep(revalidator);
691 ovs_mutex_cond_wait(&revalidator->wake_cond,
692 &revalidator->mutex);
696 for (i = 0; i < REVALIDATE_MAX_BATCH && revalidator->n_udumps; i++) {
697 list_push_back(&udumps, list_pop_front(&revalidator->udumps));
698 revalidator->n_udumps--;
701 /* Wake up the flow dumper. */
702 xpthread_cond_signal(&revalidator->wake_cond);
703 ovs_mutex_unlock(&revalidator->mutex);
705 if (!list_is_empty(&udumps)) {
706 revalidate_udumps(revalidator, &udumps);
713 static enum upcall_type
714 classify_upcall(const struct upcall *upcall)
716 const struct dpif_upcall *dpif_upcall = &upcall->dpif_upcall;
717 union user_action_cookie cookie;
720 /* First look at the upcall type. */
721 switch (dpif_upcall->type) {
728 case DPIF_N_UC_TYPES:
730 VLOG_WARN_RL(&rl, "upcall has unexpected type %"PRIu32,
735 /* "action" upcalls need a closer look. */
736 if (!dpif_upcall->userdata) {
737 VLOG_WARN_RL(&rl, "action upcall missing cookie");
740 userdata_len = nl_attr_get_size(dpif_upcall->userdata);
741 if (userdata_len < sizeof cookie.type
742 || userdata_len > sizeof cookie) {
743 VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %"PRIuSIZE,
747 memset(&cookie, 0, sizeof cookie);
748 memcpy(&cookie, nl_attr_get(dpif_upcall->userdata), userdata_len);
749 if (userdata_len == sizeof cookie.sflow
750 && cookie.type == USER_ACTION_COOKIE_SFLOW) {
752 } else if (userdata_len == sizeof cookie.slow_path
753 && cookie.type == USER_ACTION_COOKIE_SLOW_PATH) {
755 } else if (userdata_len == sizeof cookie.flow_sample
756 && cookie.type == USER_ACTION_COOKIE_FLOW_SAMPLE) {
757 return FLOW_SAMPLE_UPCALL;
758 } else if (userdata_len == sizeof cookie.ipfix
759 && cookie.type == USER_ACTION_COOKIE_IPFIX) {
762 VLOG_WARN_RL(&rl, "invalid user cookie of type %"PRIu16
763 " and size %"PRIuSIZE, cookie.type, userdata_len);
769 recv_upcalls(struct udpif *udpif)
774 uint32_t hash = udpif->secret;
775 struct handler *handler;
776 struct upcall *upcall;
777 size_t n_bytes, left;
781 upcall = xmalloc(sizeof *upcall);
782 ofpbuf_use_stub(&upcall->upcall_buf, upcall->upcall_stub,
783 sizeof upcall->upcall_stub);
784 error = dpif_recv(udpif->dpif, &upcall->dpif_upcall,
785 &upcall->upcall_buf);
787 /* upcall_destroy() can only be called on successfully received
789 ofpbuf_uninit(&upcall->upcall_buf);
795 NL_ATTR_FOR_EACH (nla, left, upcall->dpif_upcall.key,
796 upcall->dpif_upcall.key_len) {
797 enum ovs_key_attr type = nl_attr_type(nla);
798 if (type == OVS_KEY_ATTR_IN_PORT
799 || type == OVS_KEY_ATTR_TCP
800 || type == OVS_KEY_ATTR_UDP) {
801 if (nl_attr_get_size(nla) == 4) {
802 hash = mhash_add(hash, nl_attr_get_u32(nla));
806 "Netlink attribute with incorrect size.");
810 hash = mhash_finish(hash, n_bytes);
812 handler = &udpif->handlers[hash % udpif->n_handlers];
814 ovs_mutex_lock(&handler->mutex);
815 if (handler->n_upcalls < MAX_QUEUE_LENGTH) {
816 list_push_back(&handler->upcalls, &upcall->list_node);
817 if (handler->n_upcalls == 0) {
818 handler->need_signal = true;
820 handler->n_upcalls++;
821 if (handler->need_signal &&
822 handler->n_upcalls >= FLOW_MISS_MAX_BATCH) {
823 handler->need_signal = false;
824 xpthread_cond_signal(&handler->wake_cond);
826 ovs_mutex_unlock(&handler->mutex);
827 if (!VLOG_DROP_DBG(&rl)) {
828 struct ds ds = DS_EMPTY_INITIALIZER;
830 odp_flow_key_format(upcall->dpif_upcall.key,
831 upcall->dpif_upcall.key_len,
833 VLOG_DBG("dispatcher: enqueue (%s)", ds_cstr(&ds));
837 ovs_mutex_unlock(&handler->mutex);
838 COVERAGE_INC(upcall_queue_overflow);
839 upcall_destroy(upcall);
843 for (n = 0; n < udpif->n_handlers; ++n) {
844 struct handler *handler = &udpif->handlers[n];
846 if (handler->need_signal) {
847 handler->need_signal = false;
848 ovs_mutex_lock(&handler->mutex);
849 xpthread_cond_signal(&handler->wake_cond);
850 ovs_mutex_unlock(&handler->mutex);
855 /* Calculates slow path actions for 'xout'. 'buf' must statically be
856 * initialized with at least 128 bytes of space. */
858 compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
859 odp_port_t odp_in_port, struct ofpbuf *buf)
861 union user_action_cookie cookie;
865 cookie.type = USER_ACTION_COOKIE_SLOW_PATH;
866 cookie.slow_path.unused = 0;
867 cookie.slow_path.reason = xout->slow;
869 port = xout->slow & (SLOW_CFM | SLOW_BFD | SLOW_LACP | SLOW_STP)
872 pid = dpif_port_get_pid(udpif->dpif, port);
873 odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path, buf);
876 static struct flow_miss *
877 flow_miss_find(struct hmap *todo, const struct ofproto_dpif *ofproto,
878 const struct flow *flow, uint32_t hash)
880 struct flow_miss *miss;
882 HMAP_FOR_EACH_WITH_HASH (miss, hmap_node, hash, todo) {
883 if (miss->ofproto == ofproto && flow_equal(&miss->flow, flow)) {
892 handle_upcalls(struct handler *handler, struct list *upcalls)
894 struct hmap misses = HMAP_INITIALIZER(&misses);
895 struct udpif *udpif = handler->udpif;
897 struct flow_miss miss_buf[FLOW_MISS_MAX_BATCH];
898 struct dpif_op *opsp[FLOW_MISS_MAX_BATCH * 2];
899 struct dpif_op ops[FLOW_MISS_MAX_BATCH * 2];
900 struct flow_miss *miss, *next_miss;
901 struct upcall *upcall, *next;
902 size_t n_misses, n_ops, i;
903 unsigned int flow_limit;
904 bool fail_open, may_put;
905 enum upcall_type type;
907 atomic_read(&udpif->flow_limit, &flow_limit);
908 may_put = udpif_get_n_flows(udpif) < flow_limit;
910 /* Extract the flow from each upcall. Construct in 'misses' a hash table
911 * that maps each unique flow to a 'struct flow_miss'.
913 * Most commonly there is a single packet per flow_miss, but there are
914 * several reasons why there might be more than one, e.g.:
916 * - The dpif packet interface does not support TSO (or UFO, etc.), so a
917 * large packet sent to userspace is split into a sequence of smaller
920 * - A stream of quickly arriving packets in an established "slow-pathed"
923 * - Rarely, a stream of quickly arriving packets in a flow not yet
924 * established. (This is rare because most protocols do not send
925 * multiple back-to-back packets before receiving a reply from the
926 * other end of the connection, which gives OVS a chance to set up a
930 LIST_FOR_EACH_SAFE (upcall, next, list_node, upcalls) {
931 struct dpif_upcall *dupcall = &upcall->dpif_upcall;
932 struct flow_miss *miss = &miss_buf[n_misses];
933 struct ofpbuf *packet = &dupcall->packet;
934 struct flow_miss *existing_miss;
935 struct ofproto_dpif *ofproto;
936 struct dpif_sflow *sflow;
937 struct dpif_ipfix *ipfix;
938 odp_port_t odp_in_port;
942 error = xlate_receive(udpif->backer, packet, dupcall->key,
943 dupcall->key_len, &flow,
944 &ofproto, &ipfix, &sflow, NULL, &odp_in_port);
946 if (error == ENODEV) {
947 /* Received packet on datapath port for which we couldn't
948 * associate an ofproto. This can happen if a port is removed
949 * while traffic is being received. Print a rate-limited
950 * message in case it happens frequently. Install a drop flow
951 * so that future packets of the flow are inexpensively dropped
953 VLOG_INFO_RL(&rl, "received packet on unassociated datapath "
954 "port %"PRIu32, odp_in_port);
955 dpif_flow_put(udpif->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY,
956 dupcall->key, dupcall->key_len, NULL, 0, NULL, 0,
959 list_remove(&upcall->list_node);
960 upcall_destroy(upcall);
964 type = classify_upcall(upcall);
965 if (type == MISS_UPCALL) {
968 flow_extract(packet, flow.skb_priority, flow.pkt_mark,
969 &flow.tunnel, &flow.in_port, &miss->flow);
971 hash = flow_hash(&miss->flow, 0);
972 existing_miss = flow_miss_find(&misses, ofproto, &miss->flow,
974 if (!existing_miss) {
975 hmap_insert(&misses, &miss->hmap_node, hash);
976 miss->ofproto = ofproto;
977 miss->key = dupcall->key;
978 miss->key_len = dupcall->key_len;
979 miss->upcall_type = dupcall->type;
980 miss->stats.n_packets = 0;
981 miss->stats.n_bytes = 0;
982 miss->stats.used = time_msec();
983 miss->stats.tcp_flags = 0;
984 miss->odp_in_port = odp_in_port;
989 miss = existing_miss;
991 miss->stats.tcp_flags |= packet_get_tcp_flags(packet, &miss->flow);
992 miss->stats.n_bytes += packet->size;
993 miss->stats.n_packets++;
995 upcall->flow_miss = miss;
1002 union user_action_cookie cookie;
1004 memset(&cookie, 0, sizeof cookie);
1005 memcpy(&cookie, nl_attr_get(dupcall->userdata),
1006 sizeof cookie.sflow);
1007 dpif_sflow_received(sflow, packet, &flow, odp_in_port,
1013 dpif_ipfix_bridge_sample(ipfix, packet, &flow);
1016 case FLOW_SAMPLE_UPCALL:
1018 union user_action_cookie cookie;
1020 memset(&cookie, 0, sizeof cookie);
1021 memcpy(&cookie, nl_attr_get(dupcall->userdata),
1022 sizeof cookie.flow_sample);
1024 /* The flow reflects exactly the contents of the packet.
1025 * Sample the packet using it. */
1026 dpif_ipfix_flow_sample(ipfix, packet, &flow,
1027 cookie.flow_sample.collector_set_id,
1028 cookie.flow_sample.probability,
1029 cookie.flow_sample.obs_domain_id,
1030 cookie.flow_sample.obs_point_id);
1039 dpif_ipfix_unref(ipfix);
1040 dpif_sflow_unref(sflow);
1042 list_remove(&upcall->list_node);
1043 upcall_destroy(upcall);
1046 /* Initialize each 'struct flow_miss's ->xout.
1048 * We do this per-flow_miss rather than per-packet because, most commonly,
1049 * all the packets in a flow can use the same translation.
1051 * We can't do this in the previous loop because we need the TCP flags for
1052 * all the packets in each miss. */
1054 HMAP_FOR_EACH (miss, hmap_node, &misses) {
1055 struct xlate_in xin;
1057 xlate_in_init(&xin, miss->ofproto, &miss->flow, NULL,
1058 miss->stats.tcp_flags, NULL);
1059 xin.may_learn = true;
1061 if (miss->upcall_type == DPIF_UC_MISS) {
1062 xin.resubmit_stats = &miss->stats;
1064 /* For non-miss upcalls, there's a flow in the datapath which this
1065 * packet was accounted to. Presumably the revalidators will deal
1066 * with pushing its stats eventually. */
1069 xlate_actions(&xin, &miss->xout);
1070 fail_open = fail_open || miss->xout.fail_open;
1073 /* Now handle the packets individually in order of arrival. In the common
1074 * case each packet of a miss can share the same actions, but slow-pathed
1075 * packets need to be translated individually:
1077 * - For SLOW_CFM, SLOW_LACP, SLOW_STP, and SLOW_BFD, translation is what
1078 * processes received packets for these protocols.
1080 * - For SLOW_CONTROLLER, translation sends the packet to the OpenFlow
1083 * The loop fills 'ops' with an array of operations to execute in the
1086 LIST_FOR_EACH (upcall, list_node, upcalls) {
1087 struct flow_miss *miss = upcall->flow_miss;
1088 struct ofpbuf *packet = &upcall->dpif_upcall.packet;
1090 ovs_be16 flow_vlan_tci;
1092 /* Save a copy of flow.vlan_tci in case it is changed to
1093 * generate proper mega flow masks for VLAN splinter flows. */
1094 flow_vlan_tci = miss->flow.vlan_tci;
1096 if (miss->xout.slow) {
1097 struct xlate_in xin;
1099 xlate_in_init(&xin, miss->ofproto, &miss->flow, NULL, 0, packet);
1100 xlate_actions_for_side_effects(&xin);
1103 if (miss->flow.in_port.ofp_port
1104 != vsp_realdev_to_vlandev(miss->ofproto,
1105 miss->flow.in_port.ofp_port,
1106 miss->flow.vlan_tci)) {
1107 /* This packet was received on a VLAN splinter port. We
1108 * added a VLAN to the packet to make the packet resemble
1109 * the flow, but the actions were composed assuming that
1110 * the packet contained no VLAN. So, we must remove the
1111 * VLAN header from the packet before trying to execute the
1113 if (miss->xout.odp_actions.size) {
1114 eth_pop_vlan(packet);
1117 /* Remove the flow vlan tags inserted by vlan splinter logic
1118 * to ensure megaflow masks generated match the data path flow. */
1119 miss->flow.vlan_tci = 0;
1122 /* Do not install a flow into the datapath if:
1124 * - The datapath already has too many flows.
1126 * - An earlier iteration of this loop already put the same flow.
1128 * - We received this packet via some flow installed in the kernel
1132 && upcall->dpif_upcall.type == DPIF_UC_MISS) {
1138 atomic_read(&enable_megaflows, &megaflow);
1139 ofpbuf_use_stack(&mask, &miss->mask_buf, sizeof miss->mask_buf);
1143 max_mpls = ofproto_dpif_get_max_mpls_depth(miss->ofproto);
1144 odp_flow_key_from_mask(&mask, &miss->xout.wc.masks,
1145 &miss->flow, UINT32_MAX, max_mpls);
1149 op->type = DPIF_OP_FLOW_PUT;
1150 op->u.flow_put.flags = DPIF_FP_CREATE | DPIF_FP_MODIFY;
1151 op->u.flow_put.key = miss->key;
1152 op->u.flow_put.key_len = miss->key_len;
1153 op->u.flow_put.mask = mask.data;
1154 op->u.flow_put.mask_len = mask.size;
1155 op->u.flow_put.stats = NULL;
1157 if (!miss->xout.slow) {
1158 op->u.flow_put.actions = miss->xout.odp_actions.data;
1159 op->u.flow_put.actions_len = miss->xout.odp_actions.size;
1163 ofpbuf_use_stack(&buf, miss->slow_path_buf,
1164 sizeof miss->slow_path_buf);
1165 compose_slow_path(udpif, &miss->xout, miss->odp_in_port, &buf);
1166 op->u.flow_put.actions = buf.data;
1167 op->u.flow_put.actions_len = buf.size;
1172 * The 'miss' may be shared by multiple upcalls. Restore
1173 * the saved flow vlan_tci field before processing the next
1175 miss->flow.vlan_tci = flow_vlan_tci;
1177 if (miss->xout.odp_actions.size) {
1180 op->type = DPIF_OP_EXECUTE;
1181 op->u.execute.packet = packet;
1182 odp_key_to_pkt_metadata(miss->key, miss->key_len,
1184 op->u.execute.actions = miss->xout.odp_actions.data;
1185 op->u.execute.actions_len = miss->xout.odp_actions.size;
1186 op->u.execute.needs_help = (miss->xout.slow & SLOW_ACTION) != 0;
1190 /* Special case for fail-open mode.
1192 * If we are in fail-open mode, but we are connected to a controller too,
1193 * then we should send the packet up to the controller in the hope that it
1194 * will try to set up a flow and thereby allow us to exit fail-open.
1196 * See the top-level comment in fail-open.c for more information.
1198 * Copy packets before they are modified by execution. */
1200 LIST_FOR_EACH (upcall, list_node, upcalls) {
1201 struct flow_miss *miss = upcall->flow_miss;
1202 struct ofpbuf *packet = &upcall->dpif_upcall.packet;
1203 struct ofproto_packet_in *pin;
1205 pin = xmalloc(sizeof *pin);
1206 pin->up.packet = xmemdup(packet->data, packet->size);
1207 pin->up.packet_len = packet->size;
1208 pin->up.reason = OFPR_NO_MATCH;
1209 pin->up.table_id = 0;
1210 pin->up.cookie = OVS_BE64_MAX;
1211 flow_get_metadata(&miss->flow, &pin->up.fmd);
1212 pin->send_len = 0; /* Not used for flow table misses. */
1213 pin->generated_by_table_miss = false;
1214 ofproto_dpif_send_packet_in(miss->ofproto, pin);
1218 /* Execute batch. */
1219 for (i = 0; i < n_ops; i++) {
1222 dpif_operate(udpif->dpif, opsp, n_ops);
1224 HMAP_FOR_EACH_SAFE (miss, next_miss, hmap_node, &misses) {
1225 hmap_remove(&misses, &miss->hmap_node);
1226 xlate_out_uninit(&miss->xout);
1228 hmap_destroy(&misses);
1230 LIST_FOR_EACH_SAFE (upcall, next, list_node, upcalls) {
1231 list_remove(&upcall->list_node);
1232 upcall_destroy(upcall);
1236 static struct udpif_key *
1237 ukey_lookup(struct revalidator *revalidator, struct udpif_flow_dump *udump)
1239 struct udpif_key *ukey;
1241 HMAP_FOR_EACH_WITH_HASH (ukey, hmap_node, udump->key_hash,
1242 &revalidator->ukeys) {
1243 if (ukey->key_len == udump->key_len
1244 && !memcmp(ukey->key, udump->key, udump->key_len)) {
1252 ukey_delete(struct revalidator *revalidator, struct udpif_key *ukey)
1254 hmap_remove(&revalidator->ukeys, &ukey->hmap_node);
1259 revalidate_ukey(struct udpif *udpif, struct udpif_flow_dump *udump,
1260 struct udpif_key *ukey)
1262 struct ofpbuf xout_actions, *actions;
1263 uint64_t slow_path_buf[128 / 8];
1264 struct xlate_out xout, *xoutp;
1265 struct flow flow, udump_mask;
1266 struct ofproto_dpif *ofproto;
1267 struct dpif_flow_stats push;
1268 uint32_t *udump32, *xout32;
1269 odp_port_t odp_in_port;
1270 struct xlate_in xin;
1279 /* If we don't need to revalidate, we can simply push the stats contained
1280 * in the udump, otherwise we'll have to get the actions so we can check
1282 if (udump->need_revalidate) {
1283 if (dpif_flow_get(udpif->dpif, ukey->key, ukey->key_len, &actions,
1289 push.used = udump->stats.used;
1290 push.tcp_flags = udump->stats.tcp_flags;
1291 push.n_packets = udump->stats.n_packets > ukey->stats.n_packets
1292 ? udump->stats.n_packets - ukey->stats.n_packets
1294 push.n_bytes = udump->stats.n_bytes > ukey->stats.n_bytes
1295 ? udump->stats.n_bytes - ukey->stats.n_bytes
1297 ukey->stats = udump->stats;
1299 if (!push.n_packets && !udump->need_revalidate) {
1304 error = xlate_receive(udpif->backer, NULL, ukey->key, ukey->key_len, &flow,
1305 &ofproto, NULL, NULL, NULL, &odp_in_port);
1310 xlate_in_init(&xin, ofproto, &flow, NULL, push.tcp_flags, NULL);
1311 xin.resubmit_stats = push.n_packets ? &push : NULL;
1312 xin.may_learn = push.n_packets > 0;
1313 xin.skip_wildcards = !udump->need_revalidate;
1314 xlate_actions(&xin, &xout);
1317 if (!udump->need_revalidate) {
1323 ofpbuf_use_const(&xout_actions, xout.odp_actions.data,
1324 xout.odp_actions.size);
1326 ofpbuf_use_stack(&xout_actions, slow_path_buf, sizeof slow_path_buf);
1327 compose_slow_path(udpif, &xout, odp_in_port, &xout_actions);
1330 if (!ofpbuf_equal(&xout_actions, actions)) {
1334 if (odp_flow_key_to_mask(udump->mask, udump->mask_len, &udump_mask, &flow)
1339 /* Since the kernel is free to ignore wildcarded bits in the mask, we can't
1340 * directly check that the masks are the same. Instead we check that the
1341 * mask in the kernel is more specific i.e. less wildcarded, than what
1342 * we've calculated here. This guarantees we don't catch any packets we
1343 * shouldn't with the megaflow. */
1344 udump32 = (uint32_t *) &udump_mask;
1345 xout32 = (uint32_t *) &xout.wc.masks;
1346 for (i = 0; i < FLOW_U32S; i++) {
1347 if ((udump32[i] | xout32[i]) != udump32[i]) {
1354 ofpbuf_delete(actions);
1355 xlate_out_uninit(xoutp);
1360 revalidate_udumps(struct revalidator *revalidator, struct list *udumps)
1362 struct udpif *udpif = revalidator->udpif;
1365 struct dpif_flow_stats ukey_stats; /* Stats stored in the ukey. */
1366 struct dpif_flow_stats stats; /* Stats for 'op'. */
1367 struct dpif_op op; /* Flow del operation. */
1368 } ops[REVALIDATE_MAX_BATCH];
1370 struct dpif_op *opsp[REVALIDATE_MAX_BATCH];
1371 struct udpif_flow_dump *udump, *next_udump;
1372 size_t n_ops, i, n_flows;
1373 unsigned int flow_limit;
1374 long long int max_idle;
1377 atomic_read(&udpif->flow_limit, &flow_limit);
1379 n_flows = udpif_get_n_flows(udpif);
1382 max_idle = MAX_IDLE;
1383 if (n_flows > flow_limit) {
1384 must_del = n_flows > 2 * flow_limit;
1389 LIST_FOR_EACH_SAFE (udump, next_udump, list_node, udumps) {
1390 long long int used, now;
1391 struct udpif_key *ukey;
1394 ukey = ukey_lookup(revalidator, udump);
1396 used = udump->stats.used;
1397 if (!used && ukey) {
1398 used = ukey->created;
1401 if (must_del || (used && used < now - max_idle)) {
1402 struct dpif_flow_stats *ukey_stats = &ops[n_ops].ukey_stats;
1403 struct dpif_op *op = &ops[n_ops].op;
1405 op->type = DPIF_OP_FLOW_DEL;
1406 op->u.flow_del.key = udump->key;
1407 op->u.flow_del.key_len = udump->key_len;
1408 op->u.flow_del.stats = &ops[n_ops].stats;
1412 *ukey_stats = ukey->stats;
1413 ukey_delete(revalidator, ukey);
1415 memset(ukey_stats, 0, sizeof *ukey_stats);
1422 ukey = xmalloc(sizeof *ukey);
1424 ukey->key = (struct nlattr *) &ukey->key_buf;
1425 memcpy(ukey->key, udump->key, udump->key_len);
1426 ukey->key_len = udump->key_len;
1428 ukey->created = used ? used : now;
1429 memset(&ukey->stats, 0, sizeof ukey->stats);
1433 hmap_insert(&revalidator->ukeys, &ukey->hmap_node,
1438 if (!revalidate_ukey(udpif, udump, ukey)) {
1439 dpif_flow_del(udpif->dpif, udump->key, udump->key_len, NULL);
1440 ukey_delete(revalidator, ukey);
1443 list_remove(&udump->list_node);
1447 for (i = 0; i < n_ops; i++) {
1448 opsp[i] = &ops[i].op;
1450 dpif_operate(udpif->dpif, opsp, n_ops);
1452 for (i = 0; i < n_ops; i++) {
1453 struct dpif_flow_stats push, *stats, *ukey_stats;
1455 ukey_stats = &ops[i].ukey_stats;
1456 stats = ops[i].op.u.flow_del.stats;
1457 push.used = MAX(stats->used, ukey_stats->used);
1458 push.tcp_flags = stats->tcp_flags | ukey_stats->tcp_flags;
1459 push.n_packets = stats->n_packets - ukey_stats->n_packets;
1460 push.n_bytes = stats->n_bytes - ukey_stats->n_bytes;
1462 if (push.n_packets || netflow_exists()) {
1463 struct ofproto_dpif *ofproto;
1464 struct netflow *netflow;
1467 if (!xlate_receive(udpif->backer, NULL, ops[i].op.u.flow_del.key,
1468 ops[i].op.u.flow_del.key_len, &flow,
1469 &ofproto, NULL, NULL, &netflow, NULL)) {
1470 struct xlate_in xin;
1472 xlate_in_init(&xin, ofproto, &flow, NULL, push.tcp_flags,
1474 xin.resubmit_stats = push.n_packets ? &push : NULL;
1475 xin.may_learn = push.n_packets > 0;
1476 xin.skip_wildcards = true;
1477 xlate_actions_for_side_effects(&xin);
1480 netflow_expire(netflow, &flow);
1481 netflow_flow_clear(netflow, &flow);
1482 netflow_unref(netflow);
1488 LIST_FOR_EACH_SAFE (udump, next_udump, list_node, udumps) {
1489 list_remove(&udump->list_node);
1495 revalidator_sweep(struct revalidator *revalidator)
1497 struct udpif_key *ukey, *next;
1499 HMAP_FOR_EACH_SAFE (ukey, next, hmap_node, &revalidator->ukeys) {
1503 ukey_delete(revalidator, ukey);
1509 upcall_unixctl_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
1510 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
1512 struct ds ds = DS_EMPTY_INITIALIZER;
1513 struct udpif *udpif;
1515 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
1516 unsigned int flow_limit;
1519 atomic_read(&udpif->flow_limit, &flow_limit);
1521 ds_put_format(&ds, "%s:\n", dpif_name(udpif->dpif));
1522 ds_put_format(&ds, "\tflows : (current %"PRIu64")"
1523 " (avg %u) (max %u) (limit %u)\n", udpif_get_n_flows(udpif),
1524 udpif->avg_n_flows, udpif->max_n_flows, flow_limit);
1525 ds_put_format(&ds, "\tdump duration : %lldms\n", udpif->dump_duration);
1527 ds_put_char(&ds, '\n');
1528 for (i = 0; i < udpif->n_handlers; i++) {
1529 struct handler *handler = &udpif->handlers[i];
1531 ovs_mutex_lock(&handler->mutex);
1532 ds_put_format(&ds, "\t%s: (upcall queue %"PRIuSIZE")\n",
1533 handler->name, handler->n_upcalls);
1534 ovs_mutex_unlock(&handler->mutex);
1537 ds_put_char(&ds, '\n');
1538 for (i = 0; i < n_revalidators; i++) {
1539 struct revalidator *revalidator = &udpif->revalidators[i];
1541 /* XXX: The result of hmap_count(&revalidator->ukeys) may not be
1542 * accurate because it's not protected by the revalidator mutex. */
1543 ovs_mutex_lock(&revalidator->mutex);
1544 ds_put_format(&ds, "\t%s: (dump queue %"PRIuSIZE") (keys %"PRIuSIZE
1545 ")\n", revalidator->name, revalidator->n_udumps,
1546 hmap_count(&revalidator->ukeys));
1547 ovs_mutex_unlock(&revalidator->mutex);
1551 unixctl_command_reply(conn, ds_cstr(&ds));
1555 /* Disable using the megaflows.
1557 * This command is only needed for advanced debugging, so it's not
1558 * documented in the man page. */
1560 upcall_unixctl_disable_megaflows(struct unixctl_conn *conn,
1561 int argc OVS_UNUSED,
1562 const char *argv[] OVS_UNUSED,
1563 void *aux OVS_UNUSED)
1565 atomic_store(&enable_megaflows, false);
1567 unixctl_command_reply(conn, "megaflows disabled");
1570 /* Re-enable using megaflows.
1572 * This command is only needed for advanced debugging, so it's not
1573 * documented in the man page. */
1575 upcall_unixctl_enable_megaflows(struct unixctl_conn *conn,
1576 int argc OVS_UNUSED,
1577 const char *argv[] OVS_UNUSED,
1578 void *aux OVS_UNUSED)
1580 atomic_store(&enable_megaflows, true);
1582 unixctl_command_reply(conn, "megaflows enabled");