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"
26 #include "dynamic-string.h"
27 #include "fail-open.h"
28 #include "guarded-list.h"
33 #include "ofproto-dpif-ipfix.h"
34 #include "ofproto-dpif-sflow.h"
35 #include "ofproto-dpif-xlate.h"
38 #include "poll-loop.h"
41 #include "openvswitch/vlog.h"
43 #define MAX_QUEUE_LENGTH 512
44 #define UPCALL_MAX_BATCH 64
45 #define REVALIDATE_MAX_BATCH 50
47 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_upcall);
49 COVERAGE_DEFINE(dumped_duplicate_flow);
50 COVERAGE_DEFINE(dumped_new_flow);
51 COVERAGE_DEFINE(handler_duplicate_upcall);
52 COVERAGE_DEFINE(upcall_ukey_contention);
53 COVERAGE_DEFINE(revalidate_missed_dp_flow);
55 /* A thread that reads upcalls from dpif, forwards each upcall's packet,
56 * and possibly sets up a kernel flow as a cache. */
58 struct udpif *udpif; /* Parent udpif. */
59 pthread_t thread; /* Thread ID. */
60 uint32_t handler_id; /* Handler id. */
63 /* In the absence of a multiple-writer multiple-reader datastructure for
64 * storing ukeys, we use a large number of cmaps, each with its own lock for
66 #define N_UMAPS 512 /* per udpif. */
68 struct ovs_mutex mutex; /* Take for writing to the following. */
69 struct cmap cmap; /* Datapath flow keys. */
72 /* A thread that processes datapath flows, updates OpenFlow statistics, and
73 * updates or removes them if necessary. */
75 struct udpif *udpif; /* Parent udpif. */
76 pthread_t thread; /* Thread ID. */
77 unsigned int id; /* ovsthread_id_self(). */
80 /* An upcall handler for ofproto_dpif.
82 * udpif keeps records of two kind of logically separate units:
87 * - An array of 'struct handler's for upcall handling and flow
93 * - Revalidation threads which read the datapath flow table and maintains
97 struct ovs_list list_node; /* In all_udpifs list. */
99 struct dpif *dpif; /* Datapath handle. */
100 struct dpif_backer *backer; /* Opaque dpif_backer pointer. */
102 struct handler *handlers; /* Upcall handlers. */
105 struct revalidator *revalidators; /* Flow revalidators. */
106 size_t n_revalidators;
108 struct latch exit_latch; /* Tells child threads to exit. */
111 struct seq *reval_seq; /* Incremented to force revalidation. */
112 bool reval_exit; /* Set by leader on 'exit_latch. */
113 struct ovs_barrier reval_barrier; /* Barrier used by revalidators. */
114 struct dpif_flow_dump *dump; /* DPIF flow dump state. */
115 long long int dump_duration; /* Duration of the last flow dump. */
116 struct seq *dump_seq; /* Increments each dump iteration. */
117 atomic_bool enable_ufid; /* If true, skip dumping flow attrs. */
119 /* There are 'N_UMAPS' maps containing 'struct udpif_key' elements.
121 * During the flow dump phase, revalidators insert into these with a random
122 * distribution. During the garbage collection phase, each revalidator
123 * takes care of garbage collecting a slice of these maps. */
126 /* Datapath flow statistics. */
127 unsigned int max_n_flows;
128 unsigned int avg_n_flows;
130 /* Following fields are accessed and modified by different threads. */
131 atomic_uint flow_limit; /* Datapath flow hard limit. */
133 /* n_flows_mutex prevents multiple threads updating these concurrently. */
134 atomic_uint n_flows; /* Number of flows in the datapath. */
135 atomic_llong n_flows_timestamp; /* Last time n_flows was updated. */
136 struct ovs_mutex n_flows_mutex;
138 /* Following fields are accessed and modified only from the main thread. */
139 struct unixctl_conn **conns; /* Connections waiting on dump_seq. */
140 uint64_t conn_seq; /* Corresponds to 'dump_seq' when
141 conns[n_conns-1] was stored. */
142 size_t n_conns; /* Number of connections waiting. */
146 BAD_UPCALL, /* Some kind of bug somewhere. */
147 MISS_UPCALL, /* A flow miss. */
148 SFLOW_UPCALL, /* sFlow sample. */
149 FLOW_SAMPLE_UPCALL, /* Per-flow sampling. */
150 IPFIX_UPCALL /* Per-bridge sampling. */
154 struct ofproto_dpif *ofproto; /* Parent ofproto. */
155 const struct recirc_id_node *recirc; /* Recirculation context. */
156 bool have_recirc_ref; /* Reference held on recirc ctx? */
158 /* The flow and packet are only required to be constant when using
159 * dpif-netdev. If a modification is absolutely necessary, a const cast
160 * may be used with other datapaths. */
161 const struct flow *flow; /* Parsed representation of the packet. */
162 const ovs_u128 *ufid; /* Unique identifier for 'flow'. */
163 unsigned pmd_id; /* Datapath poll mode driver id. */
164 const struct dp_packet *packet; /* Packet associated with this upcall. */
165 ofp_port_t in_port; /* OpenFlow in port, or OFPP_NONE. */
167 enum dpif_upcall_type type; /* Datapath type of the upcall. */
168 const struct nlattr *userdata; /* Userdata for DPIF_UC_ACTION Upcalls. */
170 bool xout_initialized; /* True if 'xout' must be uninitialized. */
171 struct xlate_out xout; /* Result of xlate_actions(). */
172 struct ofpbuf put_actions; /* Actions 'put' in the fastapath. */
174 struct dpif_ipfix *ipfix; /* IPFIX pointer or NULL. */
175 struct dpif_sflow *sflow; /* SFlow pointer or NULL. */
177 bool vsp_adjusted; /* 'packet' and 'flow' were adjusted for
178 VLAN splinters if true. */
180 struct udpif_key *ukey; /* Revalidator flow cache. */
181 bool ukey_persists; /* Set true to keep 'ukey' beyond the
182 lifetime of this upcall. */
184 uint64_t dump_seq; /* udpif->dump_seq at translation time. */
185 uint64_t reval_seq; /* udpif->reval_seq at translation time. */
187 /* Not used by the upcall callback interface. */
188 const struct nlattr *key; /* Datapath flow key. */
189 size_t key_len; /* Datapath flow key length. */
190 const struct nlattr *out_tun_key; /* Datapath output tunnel key. */
193 /* 'udpif_key's are responsible for tracking the little bit of state udpif
194 * needs to do flow expiration which can't be pulled directly from the
195 * datapath. They may be created by any handler or revalidator thread at any
196 * time, and read by any revalidator during the dump phase. They are however
197 * each owned by a single revalidator which takes care of destroying them
198 * during the garbage-collection phase.
200 * The mutex within the ukey protects some members of the ukey. The ukey
201 * itself is protected by RCU and is held within a umap in the parent udpif.
202 * Adding or removing a ukey from a umap is only safe when holding the
203 * corresponding umap lock. */
205 struct cmap_node cmap_node; /* In parent revalidator 'ukeys' map. */
207 /* These elements are read only once created, and therefore aren't
208 * protected by a mutex. */
209 const struct nlattr *key; /* Datapath flow key. */
210 size_t key_len; /* Length of 'key'. */
211 const struct nlattr *mask; /* Datapath flow mask. */
212 size_t mask_len; /* Length of 'mask'. */
213 struct ofpbuf *actions; /* Datapath flow actions as nlattrs. */
214 ovs_u128 ufid; /* Unique flow identifier. */
215 bool ufid_present; /* True if 'ufid' is in datapath. */
216 uint32_t hash; /* Pre-computed hash for 'key'. */
217 unsigned pmd_id; /* Datapath poll mode driver id. */
219 struct ovs_mutex mutex; /* Guards the following. */
220 struct dpif_flow_stats stats OVS_GUARDED; /* Last known stats.*/
221 long long int created OVS_GUARDED; /* Estimate of creation time. */
222 uint64_t dump_seq OVS_GUARDED; /* Tracks udpif->dump_seq. */
223 uint64_t reval_seq OVS_GUARDED; /* Tracks udpif->reval_seq. */
224 bool flow_exists OVS_GUARDED; /* Ensures flows are only deleted
227 struct xlate_cache *xcache OVS_GUARDED; /* Cache for xlate entries that
228 * are affected by this ukey.
229 * Used for stats and learning.*/
231 struct odputil_keybuf buf;
235 /* Recirculation IDs with references held by the ukey. */
237 uint32_t recircs[]; /* 'n_recircs' id's for which references are held. */
240 /* Datapath operation with optional ukey attached. */
242 struct udpif_key *ukey;
243 struct dpif_flow_stats stats; /* Stats for 'op'. */
244 struct dpif_op dop; /* Flow operation. */
247 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
248 static struct ovs_list all_udpifs = OVS_LIST_INITIALIZER(&all_udpifs);
250 static size_t recv_upcalls(struct handler *);
251 static int process_upcall(struct udpif *, struct upcall *,
252 struct ofpbuf *odp_actions);
253 static void handle_upcalls(struct udpif *, struct upcall *, size_t n_upcalls);
254 static void udpif_stop_threads(struct udpif *);
255 static void udpif_start_threads(struct udpif *, size_t n_handlers,
256 size_t n_revalidators);
257 static void *udpif_upcall_handler(void *);
258 static void *udpif_revalidator(void *);
259 static unsigned long udpif_get_n_flows(struct udpif *);
260 static void revalidate(struct revalidator *);
261 static void revalidator_sweep(struct revalidator *);
262 static void revalidator_purge(struct revalidator *);
263 static void upcall_unixctl_show(struct unixctl_conn *conn, int argc,
264 const char *argv[], void *aux);
265 static void upcall_unixctl_disable_megaflows(struct unixctl_conn *, int argc,
266 const char *argv[], void *aux);
267 static void upcall_unixctl_enable_megaflows(struct unixctl_conn *, int argc,
268 const char *argv[], void *aux);
269 static void upcall_unixctl_disable_ufid(struct unixctl_conn *, int argc,
270 const char *argv[], void *aux);
271 static void upcall_unixctl_enable_ufid(struct unixctl_conn *, int argc,
272 const char *argv[], void *aux);
273 static void upcall_unixctl_set_flow_limit(struct unixctl_conn *conn, int argc,
274 const char *argv[], void *aux);
275 static void upcall_unixctl_dump_wait(struct unixctl_conn *conn, int argc,
276 const char *argv[], void *aux);
277 static void upcall_unixctl_purge(struct unixctl_conn *conn, int argc,
278 const char *argv[], void *aux);
280 static struct udpif_key *ukey_create_from_upcall(struct upcall *);
281 static int ukey_create_from_dpif_flow(const struct udpif *,
282 const struct dpif_flow *,
283 struct udpif_key **);
284 static bool ukey_install_start(struct udpif *, struct udpif_key *ukey);
285 static bool ukey_install_finish(struct udpif_key *ukey, int error);
286 static bool ukey_install(struct udpif *udpif, struct udpif_key *ukey);
287 static struct udpif_key *ukey_lookup(struct udpif *udpif,
288 const ovs_u128 *ufid);
289 static int ukey_acquire(struct udpif *, const struct dpif_flow *,
290 struct udpif_key **result, int *error);
291 static void ukey_delete__(struct udpif_key *);
292 static void ukey_delete(struct umap *, struct udpif_key *);
293 static enum upcall_type classify_upcall(enum dpif_upcall_type type,
294 const struct nlattr *userdata);
296 static int upcall_receive(struct upcall *, const struct dpif_backer *,
297 const struct dp_packet *packet, enum dpif_upcall_type,
298 const struct nlattr *userdata, const struct flow *,
299 const ovs_u128 *ufid, const unsigned pmd_id);
300 static void upcall_uninit(struct upcall *);
302 static upcall_callback upcall_cb;
304 static atomic_bool enable_megaflows = ATOMIC_VAR_INIT(true);
305 static atomic_bool enable_ufid = ATOMIC_VAR_INIT(true);
308 udpif_create(struct dpif_backer *backer, struct dpif *dpif)
310 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
311 struct udpif *udpif = xzalloc(sizeof *udpif);
313 if (ovsthread_once_start(&once)) {
314 unixctl_command_register("upcall/show", "", 0, 0, upcall_unixctl_show,
316 unixctl_command_register("upcall/disable-megaflows", "", 0, 0,
317 upcall_unixctl_disable_megaflows, NULL);
318 unixctl_command_register("upcall/enable-megaflows", "", 0, 0,
319 upcall_unixctl_enable_megaflows, NULL);
320 unixctl_command_register("upcall/disable-ufid", "", 0, 0,
321 upcall_unixctl_disable_ufid, NULL);
322 unixctl_command_register("upcall/enable-ufid", "", 0, 0,
323 upcall_unixctl_enable_ufid, NULL);
324 unixctl_command_register("upcall/set-flow-limit", "", 1, 1,
325 upcall_unixctl_set_flow_limit, NULL);
326 unixctl_command_register("revalidator/wait", "", 0, 0,
327 upcall_unixctl_dump_wait, NULL);
328 unixctl_command_register("revalidator/purge", "", 0, 0,
329 upcall_unixctl_purge, NULL);
330 ovsthread_once_done(&once);
334 udpif->backer = backer;
335 atomic_init(&udpif->flow_limit, MIN(ofproto_flow_limit, 10000));
336 udpif->reval_seq = seq_create();
337 udpif->dump_seq = seq_create();
338 latch_init(&udpif->exit_latch);
339 list_push_back(&all_udpifs, &udpif->list_node);
340 atomic_init(&udpif->enable_ufid, false);
341 atomic_init(&udpif->n_flows, 0);
342 atomic_init(&udpif->n_flows_timestamp, LLONG_MIN);
343 ovs_mutex_init(&udpif->n_flows_mutex);
344 udpif->ukeys = xmalloc(N_UMAPS * sizeof *udpif->ukeys);
345 for (int i = 0; i < N_UMAPS; i++) {
346 cmap_init(&udpif->ukeys[i].cmap);
347 ovs_mutex_init(&udpif->ukeys[i].mutex);
350 dpif_register_upcall_cb(dpif, upcall_cb, udpif);
356 udpif_run(struct udpif *udpif)
358 if (udpif->conns && udpif->conn_seq != seq_read(udpif->dump_seq)) {
361 for (i = 0; i < udpif->n_conns; i++) {
362 unixctl_command_reply(udpif->conns[i], NULL);
371 udpif_destroy(struct udpif *udpif)
373 udpif_stop_threads(udpif);
375 for (int i = 0; i < N_UMAPS; i++) {
376 cmap_destroy(&udpif->ukeys[i].cmap);
377 ovs_mutex_destroy(&udpif->ukeys[i].mutex);
382 list_remove(&udpif->list_node);
383 latch_destroy(&udpif->exit_latch);
384 seq_destroy(udpif->reval_seq);
385 seq_destroy(udpif->dump_seq);
386 ovs_mutex_destroy(&udpif->n_flows_mutex);
390 /* Stops the handler and revalidator threads, must be enclosed in
391 * ovsrcu quiescent state unless when destroying udpif. */
393 udpif_stop_threads(struct udpif *udpif)
395 if (udpif && (udpif->n_handlers != 0 || udpif->n_revalidators != 0)) {
398 latch_set(&udpif->exit_latch);
400 for (i = 0; i < udpif->n_handlers; i++) {
401 struct handler *handler = &udpif->handlers[i];
403 xpthread_join(handler->thread, NULL);
406 for (i = 0; i < udpif->n_revalidators; i++) {
407 xpthread_join(udpif->revalidators[i].thread, NULL);
410 dpif_disable_upcall(udpif->dpif);
412 for (i = 0; i < udpif->n_revalidators; i++) {
413 struct revalidator *revalidator = &udpif->revalidators[i];
415 /* Delete ukeys, and delete all flows from the datapath to prevent
416 * double-counting stats. */
417 revalidator_purge(revalidator);
420 latch_poll(&udpif->exit_latch);
422 ovs_barrier_destroy(&udpif->reval_barrier);
424 free(udpif->revalidators);
425 udpif->revalidators = NULL;
426 udpif->n_revalidators = 0;
428 free(udpif->handlers);
429 udpif->handlers = NULL;
430 udpif->n_handlers = 0;
434 /* Starts the handler and revalidator threads, must be enclosed in
435 * ovsrcu quiescent state. */
437 udpif_start_threads(struct udpif *udpif, size_t n_handlers,
438 size_t n_revalidators)
440 if (udpif && n_handlers && n_revalidators) {
444 udpif->n_handlers = n_handlers;
445 udpif->n_revalidators = n_revalidators;
447 udpif->handlers = xzalloc(udpif->n_handlers * sizeof *udpif->handlers);
448 for (i = 0; i < udpif->n_handlers; i++) {
449 struct handler *handler = &udpif->handlers[i];
451 handler->udpif = udpif;
452 handler->handler_id = i;
453 handler->thread = ovs_thread_create(
454 "handler", udpif_upcall_handler, handler);
457 enable_ufid = ofproto_dpif_get_enable_ufid(udpif->backer);
458 atomic_init(&udpif->enable_ufid, enable_ufid);
459 dpif_enable_upcall(udpif->dpif);
461 ovs_barrier_init(&udpif->reval_barrier, udpif->n_revalidators);
462 udpif->reval_exit = false;
463 udpif->revalidators = xzalloc(udpif->n_revalidators
464 * sizeof *udpif->revalidators);
465 for (i = 0; i < udpif->n_revalidators; i++) {
466 struct revalidator *revalidator = &udpif->revalidators[i];
468 revalidator->udpif = udpif;
469 revalidator->thread = ovs_thread_create(
470 "revalidator", udpif_revalidator, revalidator);
475 /* Tells 'udpif' how many threads it should use to handle upcalls.
476 * 'n_handlers' and 'n_revalidators' can never be zero. 'udpif''s
477 * datapath handle must have packet reception enabled before starting
480 udpif_set_threads(struct udpif *udpif, size_t n_handlers,
481 size_t n_revalidators)
484 ovs_assert(n_handlers && n_revalidators);
486 ovsrcu_quiesce_start();
487 if (udpif->n_handlers != n_handlers
488 || udpif->n_revalidators != n_revalidators) {
489 udpif_stop_threads(udpif);
492 if (!udpif->handlers && !udpif->revalidators) {
495 error = dpif_handlers_set(udpif->dpif, n_handlers);
497 VLOG_ERR("failed to configure handlers in dpif %s: %s",
498 dpif_name(udpif->dpif), ovs_strerror(error));
502 udpif_start_threads(udpif, n_handlers, n_revalidators);
504 ovsrcu_quiesce_end();
507 /* Waits for all ongoing upcall translations to complete. This ensures that
508 * there are no transient references to any removed ofprotos (or other
509 * objects). In particular, this should be called after an ofproto is removed
510 * (e.g. via xlate_remove_ofproto()) but before it is destroyed. */
512 udpif_synchronize(struct udpif *udpif)
514 /* This is stronger than necessary. It would be sufficient to ensure
515 * (somehow) that each handler and revalidator thread had passed through
516 * its main loop once. */
517 size_t n_handlers = udpif->n_handlers;
518 size_t n_revalidators = udpif->n_revalidators;
520 ovsrcu_quiesce_start();
521 udpif_stop_threads(udpif);
522 udpif_start_threads(udpif, n_handlers, n_revalidators);
523 ovsrcu_quiesce_end();
526 /* Notifies 'udpif' that something changed which may render previous
527 * xlate_actions() results invalid. */
529 udpif_revalidate(struct udpif *udpif)
531 seq_change(udpif->reval_seq);
534 /* Returns a seq which increments every time 'udpif' pulls stats from the
535 * datapath. Callers can use this to get a sense of when might be a good time
536 * to do periodic work which relies on relatively up to date statistics. */
538 udpif_dump_seq(struct udpif *udpif)
540 return udpif->dump_seq;
544 udpif_get_memory_usage(struct udpif *udpif, struct simap *usage)
548 simap_increase(usage, "handlers", udpif->n_handlers);
550 simap_increase(usage, "revalidators", udpif->n_revalidators);
551 for (i = 0; i < N_UMAPS; i++) {
552 simap_increase(usage, "udpif keys", cmap_count(&udpif->ukeys[i].cmap));
556 /* Remove flows from a single datapath. */
558 udpif_flush(struct udpif *udpif)
560 size_t n_handlers, n_revalidators;
562 n_handlers = udpif->n_handlers;
563 n_revalidators = udpif->n_revalidators;
565 ovsrcu_quiesce_start();
567 udpif_stop_threads(udpif);
568 dpif_flow_flush(udpif->dpif);
569 udpif_start_threads(udpif, n_handlers, n_revalidators);
571 ovsrcu_quiesce_end();
574 /* Removes all flows from all datapaths. */
576 udpif_flush_all_datapaths(void)
580 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
586 udpif_use_ufid(struct udpif *udpif)
590 atomic_read_relaxed(&enable_ufid, &enable);
591 return enable && ofproto_dpif_get_enable_ufid(udpif->backer);
596 udpif_get_n_flows(struct udpif *udpif)
598 long long int time, now;
599 unsigned long flow_count;
602 atomic_read_relaxed(&udpif->n_flows_timestamp, &time);
603 if (time < now - 100 && !ovs_mutex_trylock(&udpif->n_flows_mutex)) {
604 struct dpif_dp_stats stats;
606 atomic_store_relaxed(&udpif->n_flows_timestamp, now);
607 dpif_get_dp_stats(udpif->dpif, &stats);
608 flow_count = stats.n_flows;
609 atomic_store_relaxed(&udpif->n_flows, flow_count);
610 ovs_mutex_unlock(&udpif->n_flows_mutex);
612 atomic_read_relaxed(&udpif->n_flows, &flow_count);
617 /* The upcall handler thread tries to read a batch of UPCALL_MAX_BATCH
618 * upcalls from dpif, processes the batch and installs corresponding flows
621 udpif_upcall_handler(void *arg)
623 struct handler *handler = arg;
624 struct udpif *udpif = handler->udpif;
626 while (!latch_is_set(&handler->udpif->exit_latch)) {
627 if (recv_upcalls(handler)) {
628 poll_immediate_wake();
630 dpif_recv_wait(udpif->dpif, handler->handler_id);
631 latch_wait(&udpif->exit_latch);
640 recv_upcalls(struct handler *handler)
642 struct udpif *udpif = handler->udpif;
643 uint64_t recv_stubs[UPCALL_MAX_BATCH][512 / 8];
644 struct ofpbuf recv_bufs[UPCALL_MAX_BATCH];
645 struct dpif_upcall dupcalls[UPCALL_MAX_BATCH];
646 struct upcall upcalls[UPCALL_MAX_BATCH];
647 struct flow flows[UPCALL_MAX_BATCH];
651 while (n_upcalls < UPCALL_MAX_BATCH) {
652 struct ofpbuf *recv_buf = &recv_bufs[n_upcalls];
653 struct dpif_upcall *dupcall = &dupcalls[n_upcalls];
654 struct upcall *upcall = &upcalls[n_upcalls];
655 struct flow *flow = &flows[n_upcalls];
658 ofpbuf_use_stub(recv_buf, recv_stubs[n_upcalls],
659 sizeof recv_stubs[n_upcalls]);
660 if (dpif_recv(udpif->dpif, handler->handler_id, dupcall, recv_buf)) {
661 ofpbuf_uninit(recv_buf);
665 if (odp_flow_key_to_flow(dupcall->key, dupcall->key_len, flow)
670 error = upcall_receive(upcall, udpif->backer, &dupcall->packet,
671 dupcall->type, dupcall->userdata, flow,
672 &dupcall->ufid, PMD_ID_NULL);
674 if (error == ENODEV) {
675 /* Received packet on datapath port for which we couldn't
676 * associate an ofproto. This can happen if a port is removed
677 * while traffic is being received. Print a rate-limited
678 * message in case it happens frequently. */
679 dpif_flow_put(udpif->dpif, DPIF_FP_CREATE, dupcall->key,
680 dupcall->key_len, NULL, 0, NULL, 0,
681 &dupcall->ufid, PMD_ID_NULL, NULL);
682 VLOG_INFO_RL(&rl, "received packet on unassociated datapath "
683 "port %"PRIu32, flow->in_port.odp_port);
688 upcall->key = dupcall->key;
689 upcall->key_len = dupcall->key_len;
690 upcall->ufid = &dupcall->ufid;
692 upcall->out_tun_key = dupcall->out_tun_key;
694 if (vsp_adjust_flow(upcall->ofproto, flow, &dupcall->packet)) {
695 upcall->vsp_adjusted = true;
698 pkt_metadata_from_flow(&dupcall->packet.md, flow);
699 flow_extract(&dupcall->packet, flow);
701 error = process_upcall(udpif, upcall, NULL);
710 upcall_uninit(upcall);
712 dp_packet_uninit(&dupcall->packet);
713 ofpbuf_uninit(recv_buf);
717 handle_upcalls(handler->udpif, upcalls, n_upcalls);
718 for (i = 0; i < n_upcalls; i++) {
719 dp_packet_uninit(&dupcalls[i].packet);
720 ofpbuf_uninit(&recv_bufs[i]);
721 upcall_uninit(&upcalls[i]);
729 udpif_revalidator(void *arg)
731 /* Used by all revalidators. */
732 struct revalidator *revalidator = arg;
733 struct udpif *udpif = revalidator->udpif;
734 bool leader = revalidator == &udpif->revalidators[0];
736 /* Used only by the leader. */
737 long long int start_time = 0;
738 uint64_t last_reval_seq = 0;
741 revalidator->id = ovsthread_id_self();
746 recirc_run(); /* Recirculation cleanup. */
748 reval_seq = seq_read(udpif->reval_seq);
749 last_reval_seq = reval_seq;
751 n_flows = udpif_get_n_flows(udpif);
752 udpif->max_n_flows = MAX(n_flows, udpif->max_n_flows);
753 udpif->avg_n_flows = (udpif->avg_n_flows + n_flows) / 2;
755 /* Only the leader checks the exit latch to prevent a race where
756 * some threads think it's true and exit and others think it's
757 * false and block indefinitely on the reval_barrier */
758 udpif->reval_exit = latch_is_set(&udpif->exit_latch);
760 start_time = time_msec();
761 if (!udpif->reval_exit) {
764 terse_dump = udpif_use_ufid(udpif);
765 udpif->dump = dpif_flow_dump_create(udpif->dpif, terse_dump);
769 /* Wait for the leader to start the flow dump. */
770 ovs_barrier_block(&udpif->reval_barrier);
771 if (udpif->reval_exit) {
774 revalidate(revalidator);
776 /* Wait for all flows to have been dumped before we garbage collect. */
777 ovs_barrier_block(&udpif->reval_barrier);
778 revalidator_sweep(revalidator);
780 /* Wait for all revalidators to finish garbage collection. */
781 ovs_barrier_block(&udpif->reval_barrier);
784 unsigned int flow_limit;
785 long long int duration;
787 atomic_read_relaxed(&udpif->flow_limit, &flow_limit);
789 dpif_flow_dump_destroy(udpif->dump);
790 seq_change(udpif->dump_seq);
792 duration = MAX(time_msec() - start_time, 1);
793 udpif->dump_duration = duration;
794 if (duration > 2000) {
795 flow_limit /= duration / 1000;
796 } else if (duration > 1300) {
797 flow_limit = flow_limit * 3 / 4;
798 } else if (duration < 1000 && n_flows > 2000
799 && flow_limit < n_flows * 1000 / duration) {
802 flow_limit = MIN(ofproto_flow_limit, MAX(flow_limit, 1000));
803 atomic_store_relaxed(&udpif->flow_limit, flow_limit);
805 if (duration > 2000) {
806 VLOG_INFO("Spent an unreasonably long %lldms dumping flows",
810 poll_timer_wait_until(start_time + MIN(ofproto_max_idle, 500));
811 seq_wait(udpif->reval_seq, last_reval_seq);
812 latch_wait(&udpif->exit_latch);
820 static enum upcall_type
821 classify_upcall(enum dpif_upcall_type type, const struct nlattr *userdata)
823 union user_action_cookie cookie;
826 /* First look at the upcall type. */
834 case DPIF_N_UC_TYPES:
836 VLOG_WARN_RL(&rl, "upcall has unexpected type %"PRIu32, type);
840 /* "action" upcalls need a closer look. */
842 VLOG_WARN_RL(&rl, "action upcall missing cookie");
845 userdata_len = nl_attr_get_size(userdata);
846 if (userdata_len < sizeof cookie.type
847 || userdata_len > sizeof cookie) {
848 VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %"PRIuSIZE,
852 memset(&cookie, 0, sizeof cookie);
853 memcpy(&cookie, nl_attr_get(userdata), userdata_len);
854 if (userdata_len == MAX(8, sizeof cookie.sflow)
855 && cookie.type == USER_ACTION_COOKIE_SFLOW) {
857 } else if (userdata_len == MAX(8, sizeof cookie.slow_path)
858 && cookie.type == USER_ACTION_COOKIE_SLOW_PATH) {
860 } else if (userdata_len == MAX(8, sizeof cookie.flow_sample)
861 && cookie.type == USER_ACTION_COOKIE_FLOW_SAMPLE) {
862 return FLOW_SAMPLE_UPCALL;
863 } else if (userdata_len == MAX(8, sizeof cookie.ipfix)
864 && cookie.type == USER_ACTION_COOKIE_IPFIX) {
867 VLOG_WARN_RL(&rl, "invalid user cookie of type %"PRIu16
868 " and size %"PRIuSIZE, cookie.type, userdata_len);
873 /* Calculates slow path actions for 'xout'. 'buf' must statically be
874 * initialized with at least 128 bytes of space. */
876 compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
877 const struct flow *flow, odp_port_t odp_in_port,
880 union user_action_cookie cookie;
884 cookie.type = USER_ACTION_COOKIE_SLOW_PATH;
885 cookie.slow_path.unused = 0;
886 cookie.slow_path.reason = xout->slow;
888 port = xout->slow & (SLOW_CFM | SLOW_BFD | SLOW_LACP | SLOW_STP)
891 pid = dpif_port_get_pid(udpif->dpif, port, flow_hash_5tuple(flow, 0));
892 odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path, ODPP_NONE,
896 /* If there is no error, the upcall must be destroyed with upcall_uninit()
897 * before quiescing, as the referred objects are guaranteed to exist only
898 * until the calling thread quiesces. Otherwise, do not call upcall_uninit()
899 * since the 'upcall->put_actions' remains uninitialized. */
901 upcall_receive(struct upcall *upcall, const struct dpif_backer *backer,
902 const struct dp_packet *packet, enum dpif_upcall_type type,
903 const struct nlattr *userdata, const struct flow *flow,
904 const ovs_u128 *ufid, const unsigned pmd_id)
908 error = xlate_lookup(backer, flow, &upcall->ofproto, &upcall->ipfix,
909 &upcall->sflow, NULL, &upcall->in_port);
914 upcall->recirc = NULL;
915 upcall->have_recirc_ref = false;
917 upcall->packet = packet;
919 upcall->pmd_id = pmd_id;
921 upcall->userdata = userdata;
922 ofpbuf_init(&upcall->put_actions, 0);
924 upcall->xout_initialized = false;
925 upcall->vsp_adjusted = false;
926 upcall->ukey_persists = false;
932 upcall->out_tun_key = NULL;
938 upcall_xlate(struct udpif *udpif, struct upcall *upcall,
939 struct ofpbuf *odp_actions)
941 struct dpif_flow_stats stats;
945 stats.n_bytes = dp_packet_size(upcall->packet);
946 stats.used = time_msec();
947 stats.tcp_flags = ntohs(upcall->flow->tcp_flags);
949 xlate_in_init(&xin, upcall->ofproto, upcall->flow, upcall->in_port, NULL,
950 stats.tcp_flags, upcall->packet);
951 xin.odp_actions = odp_actions;
953 if (upcall->type == DPIF_UC_MISS) {
954 xin.resubmit_stats = &stats;
957 /* We may install a datapath flow only if we get a reference to the
958 * recirculation context (otherwise we could have recirculation
959 * upcalls using recirculation ID for which no context can be
960 * found). We may still execute the flow's actions even if we
961 * don't install the flow. */
962 upcall->recirc = xin.recirc;
963 upcall->have_recirc_ref = recirc_id_node_try_ref_rcu(xin.recirc);
966 /* For non-miss upcalls, we are either executing actions (one of which
967 * is an userspace action) for an upcall, in which case the stats have
968 * already been taken care of, or there's a flow in the datapath which
969 * this packet was accounted to. Presumably the revalidators will deal
970 * with pushing its stats eventually. */
973 upcall->dump_seq = seq_read(udpif->dump_seq);
974 upcall->reval_seq = seq_read(udpif->reval_seq);
975 xlate_actions(&xin, &upcall->xout);
976 upcall->xout_initialized = true;
978 /* Special case for fail-open mode.
980 * If we are in fail-open mode, but we are connected to a controller too,
981 * then we should send the packet up to the controller in the hope that it
982 * will try to set up a flow and thereby allow us to exit fail-open.
984 * See the top-level comment in fail-open.c for more information.
986 * Copy packets before they are modified by execution. */
987 if (upcall->xout.fail_open) {
988 const struct dp_packet *packet = upcall->packet;
989 struct ofproto_packet_in *pin;
991 pin = xmalloc(sizeof *pin);
992 pin->up.packet = xmemdup(dp_packet_data(packet), dp_packet_size(packet));
993 pin->up.packet_len = dp_packet_size(packet);
994 pin->up.reason = OFPR_NO_MATCH;
995 pin->up.table_id = 0;
996 pin->up.cookie = OVS_BE64_MAX;
997 flow_get_metadata(upcall->flow, &pin->up.flow_metadata);
998 pin->send_len = 0; /* Not used for flow table misses. */
999 pin->miss_type = OFPROTO_PACKET_IN_NO_MISS;
1000 ofproto_dpif_send_packet_in(upcall->ofproto, pin);
1003 if (!upcall->xout.slow) {
1004 ofpbuf_use_const(&upcall->put_actions,
1005 upcall->xout.odp_actions->data,
1006 upcall->xout.odp_actions->size);
1008 ofpbuf_init(&upcall->put_actions, 0);
1009 compose_slow_path(udpif, &upcall->xout, upcall->flow,
1010 upcall->flow->in_port.odp_port,
1011 &upcall->put_actions);
1014 /* This function is also called for slow-pathed flows. As we are only
1015 * going to create new datapath flows for actual datapath misses, there is
1016 * no point in creating a ukey otherwise. */
1017 if (upcall->type == DPIF_UC_MISS) {
1018 upcall->ukey = ukey_create_from_upcall(upcall);
1023 upcall_uninit(struct upcall *upcall)
1026 if (upcall->xout_initialized) {
1027 xlate_out_uninit(&upcall->xout);
1029 ofpbuf_uninit(&upcall->put_actions);
1031 if (!upcall->ukey_persists) {
1032 ukey_delete__(upcall->ukey);
1034 } else if (upcall->have_recirc_ref) {
1035 /* The reference was transferred to the ukey if one was created. */
1036 recirc_id_node_unref(upcall->recirc);
1042 upcall_cb(const struct dp_packet *packet, const struct flow *flow, ovs_u128 *ufid,
1043 unsigned pmd_id, enum dpif_upcall_type type,
1044 const struct nlattr *userdata, struct ofpbuf *actions,
1045 struct flow_wildcards *wc, struct ofpbuf *put_actions, void *aux)
1047 struct udpif *udpif = aux;
1048 unsigned int flow_limit;
1049 struct upcall upcall;
1053 atomic_read_relaxed(&enable_megaflows, &megaflow);
1054 atomic_read_relaxed(&udpif->flow_limit, &flow_limit);
1056 error = upcall_receive(&upcall, udpif->backer, packet, type, userdata,
1057 flow, ufid, pmd_id);
1062 error = process_upcall(udpif, &upcall, actions);
1067 if (upcall.xout.slow && put_actions) {
1068 ofpbuf_put(put_actions, upcall.put_actions.data,
1069 upcall.put_actions.size);
1072 if (OVS_LIKELY(wc)) {
1074 /* XXX: This could be avoided with sufficient API changes. */
1075 *wc = upcall.xout.wc;
1077 flow_wildcards_init_for_packet(wc, flow);
1081 if (udpif_get_n_flows(udpif) >= flow_limit) {
1086 /* Prevent miss flow installation if the key has recirculation ID but we
1087 * were not able to get a reference on it. */
1088 if (type == DPIF_UC_MISS && upcall.recirc && !upcall.have_recirc_ref) {
1093 if (upcall.ukey && !ukey_install(udpif, upcall.ukey)) {
1098 upcall.ukey_persists = true;
1100 upcall_uninit(&upcall);
1105 process_upcall(struct udpif *udpif, struct upcall *upcall,
1106 struct ofpbuf *odp_actions)
1108 const struct nlattr *userdata = upcall->userdata;
1109 const struct dp_packet *packet = upcall->packet;
1110 const struct flow *flow = upcall->flow;
1112 switch (classify_upcall(upcall->type, userdata)) {
1114 upcall_xlate(udpif, upcall, odp_actions);
1118 if (upcall->sflow) {
1119 union user_action_cookie cookie;
1121 memset(&cookie, 0, sizeof cookie);
1122 memcpy(&cookie, nl_attr_get(userdata), sizeof cookie.sflow);
1123 dpif_sflow_received(upcall->sflow, packet, flow,
1124 flow->in_port.odp_port, &cookie);
1129 if (upcall->ipfix) {
1130 union user_action_cookie cookie;
1131 struct flow_tnl output_tunnel_key;
1133 memset(&cookie, 0, sizeof cookie);
1134 memcpy(&cookie, nl_attr_get(userdata), sizeof cookie.ipfix);
1136 if (upcall->out_tun_key) {
1137 odp_tun_key_from_attr(upcall->out_tun_key,
1138 &output_tunnel_key);
1140 dpif_ipfix_bridge_sample(upcall->ipfix, packet, flow,
1141 flow->in_port.odp_port,
1142 cookie.ipfix.output_odp_port,
1143 upcall->out_tun_key ?
1144 &output_tunnel_key : NULL);
1148 case FLOW_SAMPLE_UPCALL:
1149 if (upcall->ipfix) {
1150 union user_action_cookie cookie;
1152 memset(&cookie, 0, sizeof cookie);
1153 memcpy(&cookie, nl_attr_get(userdata), sizeof cookie.flow_sample);
1155 /* The flow reflects exactly the contents of the packet.
1156 * Sample the packet using it. */
1157 dpif_ipfix_flow_sample(upcall->ipfix, packet, flow,
1158 cookie.flow_sample.collector_set_id,
1159 cookie.flow_sample.probability,
1160 cookie.flow_sample.obs_domain_id,
1161 cookie.flow_sample.obs_point_id);
1173 handle_upcalls(struct udpif *udpif, struct upcall *upcalls,
1176 struct dpif_op *opsp[UPCALL_MAX_BATCH * 2];
1177 struct ukey_op ops[UPCALL_MAX_BATCH * 2];
1178 unsigned int flow_limit;
1179 size_t n_ops, n_opsp, i;
1183 atomic_read_relaxed(&udpif->flow_limit, &flow_limit);
1184 atomic_read_relaxed(&enable_megaflows, &megaflow);
1186 may_put = udpif_get_n_flows(udpif) < flow_limit;
1188 /* Handle the packets individually in order of arrival.
1190 * - For SLOW_CFM, SLOW_LACP, SLOW_STP, and SLOW_BFD, translation is what
1191 * processes received packets for these protocols.
1193 * - For SLOW_CONTROLLER, translation sends the packet to the OpenFlow
1196 * The loop fills 'ops' with an array of operations to execute in the
1199 for (i = 0; i < n_upcalls; i++) {
1200 struct upcall *upcall = &upcalls[i];
1201 const struct dp_packet *packet = upcall->packet;
1204 if (upcall->vsp_adjusted) {
1205 /* This packet was received on a VLAN splinter port. We added a
1206 * VLAN to the packet to make the packet resemble the flow, but the
1207 * actions were composed assuming that the packet contained no
1208 * VLAN. So, we must remove the VLAN header from the packet before
1209 * trying to execute the actions. */
1210 if (upcall->xout.odp_actions->size) {
1211 eth_pop_vlan(CONST_CAST(struct dp_packet *, upcall->packet));
1214 /* Remove the flow vlan tags inserted by vlan splinter logic
1215 * to ensure megaflow masks generated match the data path flow. */
1216 CONST_CAST(struct flow *, upcall->flow)->vlan_tci = 0;
1219 /* Do not install a flow into the datapath if:
1221 * - The datapath already has too many flows.
1223 * - We received this packet via some flow installed in the kernel
1226 * - Upcall was a recirculation but we do not have a reference to
1227 * to the recirculation ID. */
1228 if (may_put && upcall->type == DPIF_UC_MISS &&
1229 (!upcall->recirc || upcall->have_recirc_ref)) {
1230 struct udpif_key *ukey = upcall->ukey;
1232 upcall->ukey_persists = true;
1236 op->dop.type = DPIF_OP_FLOW_PUT;
1237 op->dop.u.flow_put.flags = DPIF_FP_CREATE;
1238 op->dop.u.flow_put.key = ukey->key;
1239 op->dop.u.flow_put.key_len = ukey->key_len;
1240 op->dop.u.flow_put.mask = ukey->mask;
1241 op->dop.u.flow_put.mask_len = ukey->mask_len;
1242 op->dop.u.flow_put.ufid = upcall->ufid;
1243 op->dop.u.flow_put.stats = NULL;
1244 op->dop.u.flow_put.actions = ukey->actions->data;
1245 op->dop.u.flow_put.actions_len = ukey->actions->size;
1248 if (upcall->xout.odp_actions->size) {
1251 op->dop.type = DPIF_OP_EXECUTE;
1252 op->dop.u.execute.packet = CONST_CAST(struct dp_packet *, packet);
1253 odp_key_to_pkt_metadata(upcall->key, upcall->key_len,
1254 &op->dop.u.execute.packet->md);
1255 op->dop.u.execute.actions = upcall->xout.odp_actions->data;
1256 op->dop.u.execute.actions_len = upcall->xout.odp_actions->size;
1257 op->dop.u.execute.needs_help = (upcall->xout.slow & SLOW_ACTION) != 0;
1258 op->dop.u.execute.probe = false;
1264 * We install ukeys before installing the flows, locking them for exclusive
1265 * access by this thread for the period of installation. This ensures that
1266 * other threads won't attempt to delete the flows as we are creating them.
1269 for (i = 0; i < n_ops; i++) {
1270 struct udpif_key *ukey = ops[i].ukey;
1273 /* If we can't install the ukey, don't install the flow. */
1274 if (!ukey_install_start(udpif, ukey)) {
1275 ukey_delete__(ukey);
1280 opsp[n_opsp++] = &ops[i].dop;
1282 dpif_operate(udpif->dpif, opsp, n_opsp);
1283 for (i = 0; i < n_ops; i++) {
1285 ukey_install_finish(ops[i].ukey, ops[i].dop.error);
1291 get_ufid_hash(const ovs_u128 *ufid)
1293 return ufid->u32[0];
1296 static struct udpif_key *
1297 ukey_lookup(struct udpif *udpif, const ovs_u128 *ufid)
1299 struct udpif_key *ukey;
1300 int idx = get_ufid_hash(ufid) % N_UMAPS;
1301 struct cmap *cmap = &udpif->ukeys[idx].cmap;
1303 CMAP_FOR_EACH_WITH_HASH (ukey, cmap_node, get_ufid_hash(ufid), cmap) {
1304 if (ovs_u128_equals(&ukey->ufid, ufid)) {
1311 static struct udpif_key *
1312 ukey_create__(const struct nlattr *key, size_t key_len,
1313 const struct nlattr *mask, size_t mask_len,
1314 bool ufid_present, const ovs_u128 *ufid,
1315 const unsigned pmd_id, const struct ofpbuf *actions,
1316 uint64_t dump_seq, uint64_t reval_seq, long long int used,
1317 const struct recirc_id_node *key_recirc, struct xlate_out *xout)
1318 OVS_NO_THREAD_SAFETY_ANALYSIS
1320 unsigned n_recircs = (key_recirc ? 1 : 0) + (xout ? xout->n_recircs : 0);
1321 struct udpif_key *ukey = xmalloc(sizeof *ukey +
1322 n_recircs * sizeof *ukey->recircs);
1324 memcpy(&ukey->keybuf, key, key_len);
1325 ukey->key = &ukey->keybuf.nla;
1326 ukey->key_len = key_len;
1327 memcpy(&ukey->maskbuf, mask, mask_len);
1328 ukey->mask = &ukey->maskbuf.nla;
1329 ukey->mask_len = mask_len;
1330 ukey->ufid_present = ufid_present;
1332 ukey->pmd_id = pmd_id;
1333 ukey->hash = get_ufid_hash(&ukey->ufid);
1334 ukey->actions = ofpbuf_clone(actions);
1336 ovs_mutex_init(&ukey->mutex);
1337 ukey->dump_seq = dump_seq;
1338 ukey->reval_seq = reval_seq;
1339 ukey->flow_exists = false;
1340 ukey->created = time_msec();
1341 memset(&ukey->stats, 0, sizeof ukey->stats);
1342 ukey->stats.used = used;
1343 ukey->xcache = NULL;
1345 ukey->n_recircs = n_recircs;
1347 ukey->recircs[0] = key_recirc->id;
1349 if (xout && xout->n_recircs) {
1350 const uint32_t *act_recircs = xlate_out_get_recircs(xout);
1352 memcpy(ukey->recircs + (key_recirc ? 1 : 0), act_recircs,
1353 xout->n_recircs * sizeof *ukey->recircs);
1354 xlate_out_take_recircs(xout);
1359 static struct udpif_key *
1360 ukey_create_from_upcall(struct upcall *upcall)
1362 struct odputil_keybuf keystub, maskstub;
1363 struct ofpbuf keybuf, maskbuf;
1364 bool recirc, megaflow;
1365 struct odp_flow_key_parms odp_parms = {
1366 .flow = upcall->flow,
1367 .mask = &upcall->xout.wc.masks,
1370 if (upcall->key_len) {
1371 ofpbuf_use_const(&keybuf, upcall->key, upcall->key_len);
1373 /* dpif-netdev doesn't provide a netlink-formatted flow key in the
1374 * upcall, so convert the upcall's flow here. */
1375 ofpbuf_use_stack(&keybuf, &keystub, sizeof keystub);
1376 odp_parms.odp_in_port = upcall->flow->in_port.odp_port;
1377 odp_parms.recirc = true;
1378 odp_flow_key_from_flow(&odp_parms, &keybuf);
1381 atomic_read_relaxed(&enable_megaflows, &megaflow);
1382 recirc = ofproto_dpif_get_enable_recirc(upcall->ofproto);
1383 ofpbuf_use_stack(&maskbuf, &maskstub, sizeof maskstub);
1385 odp_parms.odp_in_port = ODPP_NONE;
1386 odp_parms.max_mpls_depth = ofproto_dpif_get_max_mpls_depth(upcall->ofproto);
1387 odp_parms.recirc = recirc;
1388 odp_parms.key_buf = &keybuf;
1390 odp_flow_key_from_mask(&odp_parms, &maskbuf);
1393 return ukey_create__(keybuf.data, keybuf.size, maskbuf.data, maskbuf.size,
1394 true, upcall->ufid, upcall->pmd_id,
1395 &upcall->put_actions, upcall->dump_seq,
1396 upcall->reval_seq, 0,
1397 upcall->have_recirc_ref ? upcall->recirc : NULL,
1402 ukey_create_from_dpif_flow(const struct udpif *udpif,
1403 const struct dpif_flow *flow,
1404 struct udpif_key **ukey)
1406 struct dpif_flow full_flow;
1407 struct ofpbuf actions;
1408 uint64_t dump_seq, reval_seq;
1409 uint64_t stub[DPIF_FLOW_BUFSIZE / 8];
1410 const struct nlattr *a;
1413 if (!flow->key_len || !flow->actions_len) {
1417 /* If the key or actions were not provided by the datapath, fetch the
1419 ofpbuf_use_stack(&buf, &stub, sizeof stub);
1420 err = dpif_flow_get(udpif->dpif, NULL, 0, &flow->ufid,
1421 flow->pmd_id, &buf, &full_flow);
1428 /* Check the flow actions for recirculation action. As recirculation
1429 * relies on OVS userspace internal state, we need to delete all old
1430 * datapath flows with recirculation upon OVS restart. */
1431 NL_ATTR_FOR_EACH_UNSAFE (a, left, flow->actions, flow->actions_len) {
1432 if (nl_attr_type(a) == OVS_ACTION_ATTR_RECIRC) {
1437 dump_seq = seq_read(udpif->dump_seq);
1438 reval_seq = seq_read(udpif->reval_seq);
1439 ofpbuf_use_const(&actions, &flow->actions, flow->actions_len);
1440 *ukey = ukey_create__(flow->key, flow->key_len,
1441 flow->mask, flow->mask_len, flow->ufid_present,
1442 &flow->ufid, flow->pmd_id, &actions, dump_seq,
1443 reval_seq, flow->stats.used, NULL, NULL);
1448 /* Attempts to insert a ukey into the shared ukey maps.
1450 * On success, returns true, installs the ukey and returns it in a locked
1451 * state. Otherwise, returns false. */
1453 ukey_install_start(struct udpif *udpif, struct udpif_key *new_ukey)
1454 OVS_TRY_LOCK(true, new_ukey->mutex)
1457 struct udpif_key *old_ukey;
1459 bool locked = false;
1461 idx = new_ukey->hash % N_UMAPS;
1462 umap = &udpif->ukeys[idx];
1463 ovs_mutex_lock(&umap->mutex);
1464 old_ukey = ukey_lookup(udpif, &new_ukey->ufid);
1466 /* Uncommon case: A ukey is already installed with the same UFID. */
1467 if (old_ukey->key_len == new_ukey->key_len
1468 && !memcmp(old_ukey->key, new_ukey->key, new_ukey->key_len)) {
1469 COVERAGE_INC(handler_duplicate_upcall);
1471 struct ds ds = DS_EMPTY_INITIALIZER;
1473 odp_format_ufid(&old_ukey->ufid, &ds);
1474 ds_put_cstr(&ds, " ");
1475 odp_flow_key_format(old_ukey->key, old_ukey->key_len, &ds);
1476 ds_put_cstr(&ds, "\n");
1477 odp_format_ufid(&new_ukey->ufid, &ds);
1478 ds_put_cstr(&ds, " ");
1479 odp_flow_key_format(new_ukey->key, new_ukey->key_len, &ds);
1481 VLOG_WARN_RL(&rl, "Conflicting ukey for flows:\n%s", ds_cstr(&ds));
1485 ovs_mutex_lock(&new_ukey->mutex);
1486 cmap_insert(&umap->cmap, &new_ukey->cmap_node, new_ukey->hash);
1489 ovs_mutex_unlock(&umap->mutex);
1495 ukey_install_finish__(struct udpif_key *ukey) OVS_REQUIRES(ukey->mutex)
1497 ukey->flow_exists = true;
1501 ukey_install_finish(struct udpif_key *ukey, int error)
1502 OVS_RELEASES(ukey->mutex)
1505 ukey_install_finish__(ukey);
1507 ovs_mutex_unlock(&ukey->mutex);
1513 ukey_install(struct udpif *udpif, struct udpif_key *ukey)
1515 /* The usual way to keep 'ukey->flow_exists' in sync with the datapath is
1516 * to call ukey_install_start(), install the corresponding datapath flow,
1517 * then call ukey_install_finish(). The netdev interface using upcall_cb()
1518 * doesn't provide a function to separately finish the flow installation,
1519 * so we perform the operations together here.
1521 * This is fine currently, as revalidator threads will only delete this
1522 * ukey during revalidator_sweep() and only if the dump_seq is mismatched.
1523 * It is unlikely for a revalidator thread to advance dump_seq and reach
1524 * the next GC phase between ukey creation and flow installation. */
1525 return ukey_install_start(udpif, ukey) && ukey_install_finish(ukey, 0);
1528 /* Searches for a ukey in 'udpif->ukeys' that matches 'flow' and attempts to
1529 * lock the ukey. If the ukey does not exist, create it.
1531 * Returns 0 on success, setting *result to the matching ukey and returning it
1532 * in a locked state. Otherwise, returns an errno and clears *result. EBUSY
1533 * indicates that another thread is handling this flow. Other errors indicate
1534 * an unexpected condition creating a new ukey.
1536 * *error is an output parameter provided to appease the threadsafety analyser,
1537 * and its value matches the return value. */
1539 ukey_acquire(struct udpif *udpif, const struct dpif_flow *flow,
1540 struct udpif_key **result, int *error)
1541 OVS_TRY_LOCK(0, (*result)->mutex)
1543 struct udpif_key *ukey;
1546 ukey = ukey_lookup(udpif, &flow->ufid);
1548 retval = ovs_mutex_trylock(&ukey->mutex);
1550 /* Usually we try to avoid installing flows from revalidator threads,
1551 * because locking on a umap may cause handler threads to block.
1552 * However there are certain cases, like when ovs-vswitchd is
1553 * restarted, where it is desirable to handle flows that exist in the
1554 * datapath gracefully (ie, don't just clear the datapath). */
1557 retval = ukey_create_from_dpif_flow(udpif, flow, &ukey);
1561 install = ukey_install_start(udpif, ukey);
1563 ukey_install_finish__(ukey);
1566 ukey_delete__(ukey);
1582 ukey_delete__(struct udpif_key *ukey)
1583 OVS_NO_THREAD_SAFETY_ANALYSIS
1586 for (int i = 0; i < ukey->n_recircs; i++) {
1587 recirc_free_id(ukey->recircs[i]);
1589 xlate_cache_delete(ukey->xcache);
1590 ofpbuf_delete(ukey->actions);
1591 ovs_mutex_destroy(&ukey->mutex);
1597 ukey_delete(struct umap *umap, struct udpif_key *ukey)
1598 OVS_REQUIRES(umap->mutex)
1600 cmap_remove(&umap->cmap, &ukey->cmap_node, ukey->hash);
1601 ovsrcu_postpone(ukey_delete__, ukey);
1605 should_revalidate(const struct udpif *udpif, uint64_t packets,
1608 long long int metric, now, duration;
1610 if (udpif->dump_duration < 200) {
1611 /* We are likely to handle full revalidation for the flows. */
1615 /* Calculate the mean time between seeing these packets. If this
1616 * exceeds the threshold, then delete the flow rather than performing
1617 * costly revalidation for flows that aren't being hit frequently.
1619 * This is targeted at situations where the dump_duration is high (~1s),
1620 * and revalidation is triggered by a call to udpif_revalidate(). In
1621 * these situations, revalidation of all flows causes fluctuations in the
1622 * flow_limit due to the interaction with the dump_duration and max_idle.
1623 * This tends to result in deletion of low-throughput flows anyway, so
1624 * skip the revalidation and just delete those flows. */
1625 packets = MAX(packets, 1);
1626 now = MAX(used, time_msec());
1627 duration = now - used;
1628 metric = duration / packets;
1631 /* The flow is receiving more than ~5pps, so keep it. */
1638 revalidate_ukey(struct udpif *udpif, struct udpif_key *ukey,
1639 const struct dpif_flow_stats *stats, uint64_t reval_seq)
1640 OVS_REQUIRES(ukey->mutex)
1642 uint64_t slow_path_buf[128 / 8];
1643 struct xlate_out xout, *xoutp;
1644 struct netflow *netflow;
1645 struct ofproto_dpif *ofproto;
1646 struct dpif_flow_stats push;
1647 struct ofpbuf xout_actions;
1648 struct flow flow, dp_mask;
1649 uint64_t *dp64, *xout64;
1650 ofp_port_t ofp_in_port;
1651 struct xlate_in xin;
1652 long long int last_used;
1656 bool need_revalidate;
1662 need_revalidate = (ukey->reval_seq != reval_seq);
1663 last_used = ukey->stats.used;
1664 push.used = stats->used;
1665 push.tcp_flags = stats->tcp_flags;
1666 push.n_packets = (stats->n_packets > ukey->stats.n_packets
1667 ? stats->n_packets - ukey->stats.n_packets
1669 push.n_bytes = (stats->n_bytes > ukey->stats.n_bytes
1670 ? stats->n_bytes - ukey->stats.n_bytes
1673 if (need_revalidate && last_used
1674 && !should_revalidate(udpif, push.n_packets, last_used)) {
1679 /* We will push the stats, so update the ukey stats cache. */
1680 ukey->stats = *stats;
1681 if (!push.n_packets && !need_revalidate) {
1686 if (ukey->xcache && !need_revalidate) {
1687 xlate_push_stats(ukey->xcache, &push);
1692 if (odp_flow_key_to_flow(ukey->key, ukey->key_len, &flow)
1697 error = xlate_lookup(udpif->backer, &flow, &ofproto, NULL, NULL, &netflow,
1703 if (need_revalidate) {
1704 xlate_cache_clear(ukey->xcache);
1706 if (!ukey->xcache) {
1707 ukey->xcache = xlate_cache_new();
1710 xlate_in_init(&xin, ofproto, &flow, ofp_in_port, NULL, push.tcp_flags,
1712 if (push.n_packets) {
1713 xin.resubmit_stats = &push;
1714 xin.may_learn = true;
1716 xin.xcache = ukey->xcache;
1717 xin.skip_wildcards = !need_revalidate;
1718 xlate_actions(&xin, &xout);
1721 if (!need_revalidate) {
1727 ofpbuf_use_const(&xout_actions, xout.odp_actions->data,
1728 xout.odp_actions->size);
1730 ofpbuf_use_stack(&xout_actions, slow_path_buf, sizeof slow_path_buf);
1731 compose_slow_path(udpif, &xout, &flow, flow.in_port.odp_port,
1735 if (!ofpbuf_equal(&xout_actions, ukey->actions)) {
1739 if (odp_flow_key_to_mask(ukey->mask, ukey->mask_len, ukey->key,
1740 ukey->key_len, &dp_mask, &flow) == ODP_FIT_ERROR) {
1744 /* Since the kernel is free to ignore wildcarded bits in the mask, we can't
1745 * directly check that the masks are the same. Instead we check that the
1746 * mask in the kernel is more specific i.e. less wildcarded, than what
1747 * we've calculated here. This guarantees we don't catch any packets we
1748 * shouldn't with the megaflow. */
1749 dp64 = (uint64_t *) &dp_mask;
1750 xout64 = (uint64_t *) &xout.wc.masks;
1751 for (i = 0; i < FLOW_U64S; i++) {
1752 if ((dp64[i] | xout64[i]) != dp64[i]) {
1761 ukey->reval_seq = reval_seq;
1763 if (netflow && !ok) {
1764 netflow_flow_clear(netflow, &flow);
1766 xlate_out_uninit(xoutp);
1771 delete_op_init__(struct udpif *udpif, struct ukey_op *op,
1772 const struct dpif_flow *flow)
1775 op->dop.type = DPIF_OP_FLOW_DEL;
1776 op->dop.u.flow_del.key = flow->key;
1777 op->dop.u.flow_del.key_len = flow->key_len;
1778 op->dop.u.flow_del.ufid = flow->ufid_present ? &flow->ufid : NULL;
1779 op->dop.u.flow_del.pmd_id = flow->pmd_id;
1780 op->dop.u.flow_del.stats = &op->stats;
1781 op->dop.u.flow_del.terse = udpif_use_ufid(udpif);
1785 delete_op_init(struct udpif *udpif, struct ukey_op *op, struct udpif_key *ukey)
1788 op->dop.type = DPIF_OP_FLOW_DEL;
1789 op->dop.u.flow_del.key = ukey->key;
1790 op->dop.u.flow_del.key_len = ukey->key_len;
1791 op->dop.u.flow_del.ufid = ukey->ufid_present ? &ukey->ufid : NULL;
1792 op->dop.u.flow_del.pmd_id = ukey->pmd_id;
1793 op->dop.u.flow_del.stats = &op->stats;
1794 op->dop.u.flow_del.terse = udpif_use_ufid(udpif);
1798 push_ukey_ops__(struct udpif *udpif, struct ukey_op *ops, size_t n_ops)
1800 struct dpif_op *opsp[REVALIDATE_MAX_BATCH];
1803 ovs_assert(n_ops <= REVALIDATE_MAX_BATCH);
1804 for (i = 0; i < n_ops; i++) {
1805 opsp[i] = &ops[i].dop;
1807 dpif_operate(udpif->dpif, opsp, n_ops);
1809 for (i = 0; i < n_ops; i++) {
1810 struct ukey_op *op = &ops[i];
1811 struct dpif_flow_stats *push, *stats, push_buf;
1813 stats = op->dop.u.flow_del.stats;
1817 ovs_mutex_lock(&op->ukey->mutex);
1818 push->used = MAX(stats->used, op->ukey->stats.used);
1819 push->tcp_flags = stats->tcp_flags | op->ukey->stats.tcp_flags;
1820 push->n_packets = stats->n_packets - op->ukey->stats.n_packets;
1821 push->n_bytes = stats->n_bytes - op->ukey->stats.n_bytes;
1822 ovs_mutex_unlock(&op->ukey->mutex);
1827 if (push->n_packets || netflow_exists()) {
1828 const struct nlattr *key = op->dop.u.flow_del.key;
1829 size_t key_len = op->dop.u.flow_del.key_len;
1830 struct ofproto_dpif *ofproto;
1831 struct netflow *netflow;
1832 ofp_port_t ofp_in_port;
1837 ovs_mutex_lock(&op->ukey->mutex);
1838 if (op->ukey->xcache) {
1839 xlate_push_stats(op->ukey->xcache, push);
1840 ovs_mutex_unlock(&op->ukey->mutex);
1843 ovs_mutex_unlock(&op->ukey->mutex);
1844 key = op->ukey->key;
1845 key_len = op->ukey->key_len;
1848 if (odp_flow_key_to_flow(key, key_len, &flow)
1853 error = xlate_lookup(udpif->backer, &flow, &ofproto, NULL, NULL,
1854 &netflow, &ofp_in_port);
1856 struct xlate_in xin;
1858 xlate_in_init(&xin, ofproto, &flow, ofp_in_port, NULL,
1859 push->tcp_flags, NULL);
1860 xin.resubmit_stats = push->n_packets ? push : NULL;
1861 xin.may_learn = push->n_packets > 0;
1862 xin.skip_wildcards = true;
1863 xlate_actions_for_side_effects(&xin);
1866 netflow_flow_clear(netflow, &flow);
1874 push_ukey_ops(struct udpif *udpif, struct umap *umap,
1875 struct ukey_op *ops, size_t n_ops)
1879 push_ukey_ops__(udpif, ops, n_ops);
1880 ovs_mutex_lock(&umap->mutex);
1881 for (i = 0; i < n_ops; i++) {
1882 ukey_delete(umap, ops[i].ukey);
1884 ovs_mutex_unlock(&umap->mutex);
1888 log_unexpected_flow(const struct dpif_flow *flow, int error)
1890 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 60);
1891 struct ds ds = DS_EMPTY_INITIALIZER;
1893 ds_put_format(&ds, "Failed to acquire udpif_key corresponding to "
1894 "unexpected flow (%s): ", ovs_strerror(error));
1895 odp_format_ufid(&flow->ufid, &ds);
1896 VLOG_WARN_RL(&rl, "%s", ds_cstr(&ds));
1900 revalidate(struct revalidator *revalidator)
1902 struct udpif *udpif = revalidator->udpif;
1903 struct dpif_flow_dump_thread *dump_thread;
1904 uint64_t dump_seq, reval_seq;
1905 unsigned int flow_limit;
1907 dump_seq = seq_read(udpif->dump_seq);
1908 reval_seq = seq_read(udpif->reval_seq);
1909 atomic_read_relaxed(&udpif->flow_limit, &flow_limit);
1910 dump_thread = dpif_flow_dump_thread_create(udpif->dump);
1912 struct ukey_op ops[REVALIDATE_MAX_BATCH];
1915 struct dpif_flow flows[REVALIDATE_MAX_BATCH];
1916 const struct dpif_flow *f;
1919 long long int max_idle;
1924 n_dumped = dpif_flow_dump_next(dump_thread, flows, ARRAY_SIZE(flows));
1931 /* In normal operation we want to keep flows around until they have
1932 * been idle for 'ofproto_max_idle' milliseconds. However:
1934 * - If the number of datapath flows climbs above 'flow_limit',
1935 * drop that down to 100 ms to try to bring the flows down to
1938 * - If the number of datapath flows climbs above twice
1939 * 'flow_limit', delete all the datapath flows as an emergency
1940 * measure. (We reassess this condition for the next batch of
1941 * datapath flows, so we will recover before all the flows are
1943 n_dp_flows = udpif_get_n_flows(udpif);
1944 kill_them_all = n_dp_flows > flow_limit * 2;
1945 max_idle = n_dp_flows > flow_limit ? 100 : ofproto_max_idle;
1947 for (f = flows; f < &flows[n_dumped]; f++) {
1948 long long int used = f->stats.used;
1949 struct udpif_key *ukey;
1950 bool already_dumped, keep;
1953 if (ukey_acquire(udpif, f, &ukey, &error)) {
1954 if (error == EBUSY) {
1955 /* Another thread is processing this flow, so don't bother
1957 COVERAGE_INC(upcall_ukey_contention);
1959 log_unexpected_flow(f, error);
1960 if (error != ENOENT) {
1961 delete_op_init__(udpif, &ops[n_ops++], f);
1967 already_dumped = ukey->dump_seq == dump_seq;
1968 if (already_dumped) {
1969 /* The flow has already been handled during this flow dump
1970 * operation. Skip it. */
1972 COVERAGE_INC(dumped_duplicate_flow);
1974 COVERAGE_INC(dumped_new_flow);
1976 ovs_mutex_unlock(&ukey->mutex);
1981 used = ukey->created;
1983 if (kill_them_all || (used && used < now - max_idle)) {
1986 keep = revalidate_ukey(udpif, ukey, &f->stats, reval_seq);
1988 ukey->dump_seq = dump_seq;
1989 ukey->flow_exists = keep;
1992 delete_op_init(udpif, &ops[n_ops++], ukey);
1994 ovs_mutex_unlock(&ukey->mutex);
1998 push_ukey_ops__(udpif, ops, n_ops);
2002 dpif_flow_dump_thread_destroy(dump_thread);
2006 handle_missed_revalidation(struct udpif *udpif, uint64_t reval_seq,
2007 struct udpif_key *ukey)
2009 struct dpif_flow_stats stats;
2012 COVERAGE_INC(revalidate_missed_dp_flow);
2014 memset(&stats, 0, sizeof stats);
2015 ovs_mutex_lock(&ukey->mutex);
2016 keep = revalidate_ukey(udpif, ukey, &stats, reval_seq);
2017 ovs_mutex_unlock(&ukey->mutex);
2023 revalidator_sweep__(struct revalidator *revalidator, bool purge)
2025 struct udpif *udpif;
2026 uint64_t dump_seq, reval_seq;
2029 udpif = revalidator->udpif;
2030 dump_seq = seq_read(udpif->dump_seq);
2031 reval_seq = seq_read(udpif->reval_seq);
2032 slice = revalidator - udpif->revalidators;
2033 ovs_assert(slice < udpif->n_revalidators);
2035 for (int i = slice; i < N_UMAPS; i += udpif->n_revalidators) {
2036 struct ukey_op ops[REVALIDATE_MAX_BATCH];
2037 struct udpif_key *ukey;
2038 struct umap *umap = &udpif->ukeys[i];
2041 CMAP_FOR_EACH(ukey, cmap_node, &umap->cmap) {
2042 bool flow_exists, seq_mismatch;
2044 /* Handler threads could be holding a ukey lock while it installs a
2045 * new flow, so don't hang around waiting for access to it. */
2046 if (ovs_mutex_trylock(&ukey->mutex)) {
2049 flow_exists = ukey->flow_exists;
2050 seq_mismatch = (ukey->dump_seq != dump_seq
2051 && ukey->reval_seq != reval_seq);
2052 ovs_mutex_unlock(&ukey->mutex);
2057 && !handle_missed_revalidation(udpif, reval_seq,
2059 struct ukey_op *op = &ops[n_ops++];
2061 delete_op_init(udpif, op, ukey);
2062 if (n_ops == REVALIDATE_MAX_BATCH) {
2063 push_ukey_ops(udpif, umap, ops, n_ops);
2066 } else if (!flow_exists) {
2067 ovs_mutex_lock(&umap->mutex);
2068 ukey_delete(umap, ukey);
2069 ovs_mutex_unlock(&umap->mutex);
2074 push_ukey_ops(udpif, umap, ops, n_ops);
2081 revalidator_sweep(struct revalidator *revalidator)
2083 revalidator_sweep__(revalidator, false);
2087 revalidator_purge(struct revalidator *revalidator)
2089 revalidator_sweep__(revalidator, true);
2093 upcall_unixctl_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
2094 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
2096 struct ds ds = DS_EMPTY_INITIALIZER;
2097 struct udpif *udpif;
2099 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
2100 unsigned int flow_limit;
2104 atomic_read_relaxed(&udpif->flow_limit, &flow_limit);
2105 ufid_enabled = udpif_use_ufid(udpif);
2107 ds_put_format(&ds, "%s:\n", dpif_name(udpif->dpif));
2108 ds_put_format(&ds, "\tflows : (current %lu)"
2109 " (avg %u) (max %u) (limit %u)\n", udpif_get_n_flows(udpif),
2110 udpif->avg_n_flows, udpif->max_n_flows, flow_limit);
2111 ds_put_format(&ds, "\tdump duration : %lldms\n", udpif->dump_duration);
2112 ds_put_format(&ds, "\tufid enabled : ");
2114 ds_put_format(&ds, "true\n");
2116 ds_put_format(&ds, "false\n");
2118 ds_put_char(&ds, '\n');
2120 for (i = 0; i < n_revalidators; i++) {
2121 struct revalidator *revalidator = &udpif->revalidators[i];
2122 int j, elements = 0;
2124 for (j = i; j < N_UMAPS; j += n_revalidators) {
2125 elements += cmap_count(&udpif->ukeys[j].cmap);
2127 ds_put_format(&ds, "\t%u: (keys %d)\n", revalidator->id, elements);
2131 unixctl_command_reply(conn, ds_cstr(&ds));
2135 /* Disable using the megaflows.
2137 * This command is only needed for advanced debugging, so it's not
2138 * documented in the man page. */
2140 upcall_unixctl_disable_megaflows(struct unixctl_conn *conn,
2141 int argc OVS_UNUSED,
2142 const char *argv[] OVS_UNUSED,
2143 void *aux OVS_UNUSED)
2145 atomic_store_relaxed(&enable_megaflows, false);
2146 udpif_flush_all_datapaths();
2147 unixctl_command_reply(conn, "megaflows disabled");
2150 /* Re-enable using megaflows.
2152 * This command is only needed for advanced debugging, so it's not
2153 * documented in the man page. */
2155 upcall_unixctl_enable_megaflows(struct unixctl_conn *conn,
2156 int argc OVS_UNUSED,
2157 const char *argv[] OVS_UNUSED,
2158 void *aux OVS_UNUSED)
2160 atomic_store_relaxed(&enable_megaflows, true);
2161 udpif_flush_all_datapaths();
2162 unixctl_command_reply(conn, "megaflows enabled");
2165 /* Disable skipping flow attributes during flow dump.
2167 * This command is only needed for advanced debugging, so it's not
2168 * documented in the man page. */
2170 upcall_unixctl_disable_ufid(struct unixctl_conn *conn, int argc OVS_UNUSED,
2171 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
2173 atomic_store_relaxed(&enable_ufid, false);
2174 unixctl_command_reply(conn, "Datapath dumping tersely using UFID disabled");
2177 /* Re-enable skipping flow attributes during flow dump.
2179 * This command is only needed for advanced debugging, so it's not documented
2180 * in the man page. */
2182 upcall_unixctl_enable_ufid(struct unixctl_conn *conn, int argc OVS_UNUSED,
2183 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
2185 atomic_store_relaxed(&enable_ufid, true);
2186 unixctl_command_reply(conn, "Datapath dumping tersely using UFID enabled "
2187 "for supported datapaths");
2190 /* Set the flow limit.
2192 * This command is only needed for advanced debugging, so it's not
2193 * documented in the man page. */
2195 upcall_unixctl_set_flow_limit(struct unixctl_conn *conn,
2196 int argc OVS_UNUSED,
2197 const char *argv[] OVS_UNUSED,
2198 void *aux OVS_UNUSED)
2200 struct ds ds = DS_EMPTY_INITIALIZER;
2201 struct udpif *udpif;
2202 unsigned int flow_limit = atoi(argv[1]);
2204 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
2205 atomic_store_relaxed(&udpif->flow_limit, flow_limit);
2207 ds_put_format(&ds, "set flow_limit to %u\n", flow_limit);
2208 unixctl_command_reply(conn, ds_cstr(&ds));
2213 upcall_unixctl_dump_wait(struct unixctl_conn *conn,
2214 int argc OVS_UNUSED,
2215 const char *argv[] OVS_UNUSED,
2216 void *aux OVS_UNUSED)
2218 if (list_is_singleton(&all_udpifs)) {
2219 struct udpif *udpif = NULL;
2222 udpif = OBJECT_CONTAINING(list_front(&all_udpifs), udpif, list_node);
2223 len = (udpif->n_conns + 1) * sizeof *udpif->conns;
2224 udpif->conn_seq = seq_read(udpif->dump_seq);
2225 udpif->conns = xrealloc(udpif->conns, len);
2226 udpif->conns[udpif->n_conns++] = conn;
2228 unixctl_command_reply_error(conn, "can't wait on multiple udpifs.");
2233 upcall_unixctl_purge(struct unixctl_conn *conn, int argc OVS_UNUSED,
2234 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
2236 struct udpif *udpif;
2238 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
2241 for (n = 0; n < udpif->n_revalidators; n++) {
2242 revalidator_purge(&udpif->revalidators[n]);
2245 unixctl_command_reply(conn, "");