1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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 "openvswitch/dynamic-string.h"
27 #include "fail-open.h"
28 #include "guarded-list.h"
30 #include "openvswitch/list.h"
32 #include "openvswitch/ofpbuf.h"
33 #include "ofproto-dpif-ipfix.h"
34 #include "ofproto-dpif-sflow.h"
35 #include "ofproto-dpif-xlate.h"
36 #include "ofproto-dpif-xlate-cache.h"
39 #include "poll-loop.h"
42 #include "openvswitch/vlog.h"
44 #define MAX_QUEUE_LENGTH 512
45 #define UPCALL_MAX_BATCH 64
46 #define REVALIDATE_MAX_BATCH 50
48 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_upcall
);
50 COVERAGE_DEFINE(dumped_duplicate_flow
);
51 COVERAGE_DEFINE(dumped_new_flow
);
52 COVERAGE_DEFINE(handler_duplicate_upcall
);
53 COVERAGE_DEFINE(upcall_ukey_contention
);
54 COVERAGE_DEFINE(upcall_ukey_replace
);
55 COVERAGE_DEFINE(revalidate_missed_dp_flow
);
57 /* A thread that reads upcalls from dpif, forwards each upcall's packet,
58 * and possibly sets up a kernel flow as a cache. */
60 struct udpif
*udpif
; /* Parent udpif. */
61 pthread_t thread
; /* Thread ID. */
62 uint32_t handler_id
; /* Handler id. */
65 /* In the absence of a multiple-writer multiple-reader datastructure for
66 * storing udpif_keys ("ukeys"), we use a large number of cmaps, each with its
67 * own lock for writing. */
68 #define N_UMAPS 512 /* per udpif. */
70 struct ovs_mutex mutex
; /* Take for writing to the following. */
71 struct cmap cmap
; /* Datapath flow keys. */
74 /* A thread that processes datapath flows, updates OpenFlow statistics, and
75 * updates or removes them if necessary.
77 * Revalidator threads operate in two phases: "dump" and "sweep". In between
78 * each phase, all revalidators sync up so that all revalidator threads are
79 * either in one phase or the other, but not a combination.
81 * During the dump phase, revalidators fetch flows from the datapath and
82 * attribute the statistics to OpenFlow rules. Each datapath flow has a
83 * corresponding ukey which caches the most recently seen statistics. If
84 * a flow needs to be deleted (for example, because it is unused over a
85 * period of time), revalidator threads may delete the flow during the
86 * dump phase. The datapath is not guaranteed to reliably dump all flows
87 * from the datapath, and there is no mapping between datapath flows to
88 * revalidators, so a particular flow may be handled by zero or more
89 * revalidators during a single dump phase. To avoid duplicate attribution
90 * of statistics, ukeys are never deleted during this phase.
92 * During the sweep phase, each revalidator takes ownership of a different
93 * slice of umaps and sweeps through all ukeys in those umaps to figure out
94 * whether they need to be deleted. During this phase, revalidators may
95 * fetch individual flows which were not dumped during the dump phase to
96 * validate them and attribute statistics.
99 struct udpif
*udpif
; /* Parent udpif. */
100 pthread_t thread
; /* Thread ID. */
101 unsigned int id
; /* ovsthread_id_self(). */
104 /* An upcall handler for ofproto_dpif.
106 * udpif keeps records of two kind of logically separate units:
111 * - An array of 'struct handler's for upcall handling and flow
117 * - Revalidation threads which read the datapath flow table and maintains
121 struct ovs_list list_node
; /* In all_udpifs list. */
123 struct dpif
*dpif
; /* Datapath handle. */
124 struct dpif_backer
*backer
; /* Opaque dpif_backer pointer. */
126 struct handler
*handlers
; /* Upcall handlers. */
129 struct revalidator
*revalidators
; /* Flow revalidators. */
130 size_t n_revalidators
;
132 struct latch exit_latch
; /* Tells child threads to exit. */
135 struct seq
*reval_seq
; /* Incremented to force revalidation. */
136 bool reval_exit
; /* Set by leader on 'exit_latch. */
137 struct ovs_barrier reval_barrier
; /* Barrier used by revalidators. */
138 struct dpif_flow_dump
*dump
; /* DPIF flow dump state. */
139 long long int dump_duration
; /* Duration of the last flow dump. */
140 struct seq
*dump_seq
; /* Increments each dump iteration. */
141 atomic_bool enable_ufid
; /* If true, skip dumping flow attrs. */
143 /* These variables provide a mechanism for the main thread to pause
144 * all revalidation without having to completely shut the threads down.
145 * 'pause_latch' is shared between the main thread and the lead
146 * revalidator thread, so when it is desirable to halt revalidation, the
147 * main thread will set the latch. 'pause' and 'pause_barrier' are shared
148 * by revalidator threads. The lead revalidator will set 'pause' when it
149 * observes the latch has been set, and this will cause all revalidator
150 * threads to wait on 'pause_barrier' at the beginning of the next
151 * revalidation round. */
152 bool pause
; /* Set by leader on 'pause_latch. */
153 struct latch pause_latch
; /* Set to force revalidators pause. */
154 struct ovs_barrier pause_barrier
; /* Barrier used to pause all */
155 /* revalidators by main thread. */
157 /* There are 'N_UMAPS' maps containing 'struct udpif_key' elements.
159 * During the flow dump phase, revalidators insert into these with a random
160 * distribution. During the garbage collection phase, each revalidator
161 * takes care of garbage collecting a slice of these maps. */
164 /* Datapath flow statistics. */
165 unsigned int max_n_flows
;
166 unsigned int avg_n_flows
;
168 /* Following fields are accessed and modified by different threads. */
169 atomic_uint flow_limit
; /* Datapath flow hard limit. */
171 /* n_flows_mutex prevents multiple threads updating these concurrently. */
172 atomic_uint n_flows
; /* Number of flows in the datapath. */
173 atomic_llong n_flows_timestamp
; /* Last time n_flows was updated. */
174 struct ovs_mutex n_flows_mutex
;
176 /* Following fields are accessed and modified only from the main thread. */
177 struct unixctl_conn
**conns
; /* Connections waiting on dump_seq. */
178 uint64_t conn_seq
; /* Corresponds to 'dump_seq' when
179 conns[n_conns-1] was stored. */
180 size_t n_conns
; /* Number of connections waiting. */
184 BAD_UPCALL
, /* Some kind of bug somewhere. */
185 MISS_UPCALL
, /* A flow miss. */
186 SFLOW_UPCALL
, /* sFlow sample. */
187 FLOW_SAMPLE_UPCALL
, /* Per-flow sampling. */
188 IPFIX_UPCALL
/* Per-bridge sampling. */
198 struct ofproto_dpif
*ofproto
; /* Parent ofproto. */
199 const struct recirc_id_node
*recirc
; /* Recirculation context. */
200 bool have_recirc_ref
; /* Reference held on recirc ctx? */
202 /* The flow and packet are only required to be constant when using
203 * dpif-netdev. If a modification is absolutely necessary, a const cast
204 * may be used with other datapaths. */
205 const struct flow
*flow
; /* Parsed representation of the packet. */
206 const ovs_u128
*ufid
; /* Unique identifier for 'flow'. */
207 unsigned pmd_id
; /* Datapath poll mode driver id. */
208 const struct dp_packet
*packet
; /* Packet associated with this upcall. */
209 ofp_port_t in_port
; /* OpenFlow in port, or OFPP_NONE. */
210 uint16_t mru
; /* If !0, Maximum receive unit of
211 fragmented IP packet */
213 enum dpif_upcall_type type
; /* Datapath type of the upcall. */
214 const struct nlattr
*userdata
; /* Userdata for DPIF_UC_ACTION Upcalls. */
215 const struct nlattr
*actions
; /* Flow actions in DPIF_UC_ACTION Upcalls. */
217 bool xout_initialized
; /* True if 'xout' must be uninitialized. */
218 struct xlate_out xout
; /* Result of xlate_actions(). */
219 struct ofpbuf odp_actions
; /* Datapath actions from xlate_actions(). */
220 struct flow_wildcards wc
; /* Dependencies that megaflow must match. */
221 struct ofpbuf put_actions
; /* Actions 'put' in the fastpath. */
223 struct dpif_ipfix
*ipfix
; /* IPFIX pointer or NULL. */
224 struct dpif_sflow
*sflow
; /* SFlow pointer or NULL. */
226 struct udpif_key
*ukey
; /* Revalidator flow cache. */
227 bool ukey_persists
; /* Set true to keep 'ukey' beyond the
228 lifetime of this upcall. */
230 uint64_t dump_seq
; /* udpif->dump_seq at translation time. */
231 uint64_t reval_seq
; /* udpif->reval_seq at translation time. */
233 /* Not used by the upcall callback interface. */
234 const struct nlattr
*key
; /* Datapath flow key. */
235 size_t key_len
; /* Datapath flow key length. */
236 const struct nlattr
*out_tun_key
; /* Datapath output tunnel key. */
238 uint64_t odp_actions_stub
[1024 / 8]; /* Stub for odp_actions. */
241 /* Ukeys must transition through these states using transition_ukey(). */
244 UKEY_VISIBLE
, /* Ukey is in umap, datapath flow install is queued. */
245 UKEY_OPERATIONAL
, /* Ukey is in umap, datapath flow is installed. */
246 UKEY_EVICTING
, /* Ukey is in umap, datapath flow delete is queued. */
247 UKEY_EVICTED
, /* Ukey is in umap, datapath flow is deleted. */
248 UKEY_DELETED
, /* Ukey removed from umap, ukey free is deferred. */
250 #define N_UKEY_STATES (UKEY_DELETED + 1)
252 /* 'udpif_key's are responsible for tracking the little bit of state udpif
253 * needs to do flow expiration which can't be pulled directly from the
254 * datapath. They may be created by any handler or revalidator thread at any
255 * time, and read by any revalidator during the dump phase. They are however
256 * each owned by a single revalidator which takes care of destroying them
257 * during the garbage-collection phase.
259 * The mutex within the ukey protects some members of the ukey. The ukey
260 * itself is protected by RCU and is held within a umap in the parent udpif.
261 * Adding or removing a ukey from a umap is only safe when holding the
262 * corresponding umap lock. */
264 struct cmap_node cmap_node
; /* In parent revalidator 'ukeys' map. */
266 /* These elements are read only once created, and therefore aren't
267 * protected by a mutex. */
268 const struct nlattr
*key
; /* Datapath flow key. */
269 size_t key_len
; /* Length of 'key'. */
270 const struct nlattr
*mask
; /* Datapath flow mask. */
271 size_t mask_len
; /* Length of 'mask'. */
272 ovs_u128 ufid
; /* Unique flow identifier. */
273 bool ufid_present
; /* True if 'ufid' is in datapath. */
274 uint32_t hash
; /* Pre-computed hash for 'key'. */
275 unsigned pmd_id
; /* Datapath poll mode driver id. */
277 struct ovs_mutex mutex
; /* Guards the following. */
278 struct dpif_flow_stats stats OVS_GUARDED
; /* Last known stats.*/
279 long long int created OVS_GUARDED
; /* Estimate of creation time. */
280 uint64_t dump_seq OVS_GUARDED
; /* Tracks udpif->dump_seq. */
281 uint64_t reval_seq OVS_GUARDED
; /* Tracks udpif->reval_seq. */
282 enum ukey_state state OVS_GUARDED
; /* Tracks ukey lifetime. */
284 /* 'state' debug information. */
285 unsigned int state_thread OVS_GUARDED
; /* Thread that transitions. */
286 const char *state_where OVS_GUARDED
; /* transition_ukey() locator. */
288 /* Datapath flow actions as nlattrs. Protected by RCU. Read with
289 * ukey_get_actions(), and write with ukey_set_actions(). */
290 OVSRCU_TYPE(struct ofpbuf
*) actions
;
292 struct xlate_cache
*xcache OVS_GUARDED
; /* Cache for xlate entries that
293 * are affected by this ukey.
294 * Used for stats and learning.*/
296 struct odputil_keybuf buf
;
300 uint32_t key_recirc_id
; /* Non-zero if reference is held by the ukey. */
301 struct recirc_refs recircs
; /* Action recirc IDs with references held. */
304 /* Datapath operation with optional ukey attached. */
306 struct udpif_key
*ukey
;
307 struct dpif_flow_stats stats
; /* Stats for 'op'. */
308 struct dpif_op dop
; /* Flow operation. */
311 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
312 static struct ovs_list all_udpifs
= OVS_LIST_INITIALIZER(&all_udpifs
);
314 static size_t recv_upcalls(struct handler
*);
315 static int process_upcall(struct udpif
*, struct upcall
*,
316 struct ofpbuf
*odp_actions
, struct flow_wildcards
*);
317 static void handle_upcalls(struct udpif
*, struct upcall
*, size_t n_upcalls
);
318 static void udpif_stop_threads(struct udpif
*);
319 static void udpif_start_threads(struct udpif
*, size_t n_handlers
,
320 size_t n_revalidators
);
321 static void udpif_pause_revalidators(struct udpif
*);
322 static void udpif_resume_revalidators(struct udpif
*);
323 static void *udpif_upcall_handler(void *);
324 static void *udpif_revalidator(void *);
325 static unsigned long udpif_get_n_flows(struct udpif
*);
326 static void revalidate(struct revalidator
*);
327 static void revalidator_pause(struct revalidator
*);
328 static void revalidator_sweep(struct revalidator
*);
329 static void revalidator_purge(struct revalidator
*);
330 static void upcall_unixctl_show(struct unixctl_conn
*conn
, int argc
,
331 const char *argv
[], void *aux
);
332 static void upcall_unixctl_disable_megaflows(struct unixctl_conn
*, int argc
,
333 const char *argv
[], void *aux
);
334 static void upcall_unixctl_enable_megaflows(struct unixctl_conn
*, int argc
,
335 const char *argv
[], void *aux
);
336 static void upcall_unixctl_disable_ufid(struct unixctl_conn
*, int argc
,
337 const char *argv
[], void *aux
);
338 static void upcall_unixctl_enable_ufid(struct unixctl_conn
*, int argc
,
339 const char *argv
[], void *aux
);
340 static void upcall_unixctl_set_flow_limit(struct unixctl_conn
*conn
, int argc
,
341 const char *argv
[], void *aux
);
342 static void upcall_unixctl_dump_wait(struct unixctl_conn
*conn
, int argc
,
343 const char *argv
[], void *aux
);
344 static void upcall_unixctl_purge(struct unixctl_conn
*conn
, int argc
,
345 const char *argv
[], void *aux
);
347 static struct udpif_key
*ukey_create_from_upcall(struct upcall
*,
348 struct flow_wildcards
*);
349 static int ukey_create_from_dpif_flow(const struct udpif
*,
350 const struct dpif_flow
*,
351 struct udpif_key
**);
352 static void ukey_get_actions(struct udpif_key
*, const struct nlattr
**actions
,
354 static bool ukey_install__(struct udpif
*, struct udpif_key
*ukey
)
355 OVS_TRY_LOCK(true, ukey
->mutex
);
356 static bool ukey_install(struct udpif
*udpif
, struct udpif_key
*ukey
);
357 static void transition_ukey_at(struct udpif_key
*ukey
, enum ukey_state dst
,
359 OVS_REQUIRES(ukey
->mutex
);
360 #define transition_ukey(UKEY, DST) \
361 transition_ukey_at(UKEY, DST, OVS_SOURCE_LOCATOR)
362 static struct udpif_key
*ukey_lookup(struct udpif
*udpif
,
363 const ovs_u128
*ufid
,
364 const unsigned pmd_id
);
365 static int ukey_acquire(struct udpif
*, const struct dpif_flow
*,
366 struct udpif_key
**result
, int *error
);
367 static void ukey_delete__(struct udpif_key
*);
368 static void ukey_delete(struct umap
*, struct udpif_key
*);
369 static enum upcall_type
classify_upcall(enum dpif_upcall_type type
,
370 const struct nlattr
*userdata
);
372 static void put_op_init(struct ukey_op
*op
, struct udpif_key
*ukey
,
373 enum dpif_flow_put_flags flags
);
374 static void delete_op_init(struct udpif
*udpif
, struct ukey_op
*op
,
375 struct udpif_key
*ukey
);
377 static int upcall_receive(struct upcall
*, const struct dpif_backer
*,
378 const struct dp_packet
*packet
, enum dpif_upcall_type
,
379 const struct nlattr
*userdata
, const struct flow
*,
380 const unsigned int mru
,
381 const ovs_u128
*ufid
, const unsigned pmd_id
);
382 static void upcall_uninit(struct upcall
*);
384 static upcall_callback upcall_cb
;
385 static dp_purge_callback dp_purge_cb
;
387 static atomic_bool enable_megaflows
= ATOMIC_VAR_INIT(true);
388 static atomic_bool enable_ufid
= ATOMIC_VAR_INIT(true);
393 static struct ovsthread_once once
= OVSTHREAD_ONCE_INITIALIZER
;
394 if (ovsthread_once_start(&once
)) {
395 unixctl_command_register("upcall/show", "", 0, 0, upcall_unixctl_show
,
397 unixctl_command_register("upcall/disable-megaflows", "", 0, 0,
398 upcall_unixctl_disable_megaflows
, NULL
);
399 unixctl_command_register("upcall/enable-megaflows", "", 0, 0,
400 upcall_unixctl_enable_megaflows
, NULL
);
401 unixctl_command_register("upcall/disable-ufid", "", 0, 0,
402 upcall_unixctl_disable_ufid
, NULL
);
403 unixctl_command_register("upcall/enable-ufid", "", 0, 0,
404 upcall_unixctl_enable_ufid
, NULL
);
405 unixctl_command_register("upcall/set-flow-limit", "flow-limit-number",
406 1, 1, upcall_unixctl_set_flow_limit
, NULL
);
407 unixctl_command_register("revalidator/wait", "", 0, 0,
408 upcall_unixctl_dump_wait
, NULL
);
409 unixctl_command_register("revalidator/purge", "", 0, 0,
410 upcall_unixctl_purge
, NULL
);
411 ovsthread_once_done(&once
);
416 udpif_create(struct dpif_backer
*backer
, struct dpif
*dpif
)
418 struct udpif
*udpif
= xzalloc(sizeof *udpif
);
421 udpif
->backer
= backer
;
422 atomic_init(&udpif
->flow_limit
, MIN(ofproto_flow_limit
, 10000));
423 udpif
->reval_seq
= seq_create();
424 udpif
->dump_seq
= seq_create();
425 latch_init(&udpif
->exit_latch
);
426 latch_init(&udpif
->pause_latch
);
427 ovs_list_push_back(&all_udpifs
, &udpif
->list_node
);
428 atomic_init(&udpif
->enable_ufid
, false);
429 atomic_init(&udpif
->n_flows
, 0);
430 atomic_init(&udpif
->n_flows_timestamp
, LLONG_MIN
);
431 ovs_mutex_init(&udpif
->n_flows_mutex
);
432 udpif
->ukeys
= xmalloc(N_UMAPS
* sizeof *udpif
->ukeys
);
433 for (int i
= 0; i
< N_UMAPS
; i
++) {
434 cmap_init(&udpif
->ukeys
[i
].cmap
);
435 ovs_mutex_init(&udpif
->ukeys
[i
].mutex
);
438 dpif_register_upcall_cb(dpif
, upcall_cb
, udpif
);
439 dpif_register_dp_purge_cb(dpif
, dp_purge_cb
, udpif
);
445 udpif_run(struct udpif
*udpif
)
447 if (udpif
->conns
&& udpif
->conn_seq
!= seq_read(udpif
->dump_seq
)) {
450 for (i
= 0; i
< udpif
->n_conns
; i
++) {
451 unixctl_command_reply(udpif
->conns
[i
], NULL
);
460 udpif_destroy(struct udpif
*udpif
)
462 udpif_stop_threads(udpif
);
464 dpif_register_dp_purge_cb(udpif
->dpif
, NULL
, udpif
);
465 dpif_register_upcall_cb(udpif
->dpif
, NULL
, udpif
);
467 for (int i
= 0; i
< N_UMAPS
; i
++) {
468 cmap_destroy(&udpif
->ukeys
[i
].cmap
);
469 ovs_mutex_destroy(&udpif
->ukeys
[i
].mutex
);
474 ovs_list_remove(&udpif
->list_node
);
475 latch_destroy(&udpif
->exit_latch
);
476 latch_destroy(&udpif
->pause_latch
);
477 seq_destroy(udpif
->reval_seq
);
478 seq_destroy(udpif
->dump_seq
);
479 ovs_mutex_destroy(&udpif
->n_flows_mutex
);
483 /* Stops the handler and revalidator threads, must be enclosed in
484 * ovsrcu quiescent state unless when destroying udpif. */
486 udpif_stop_threads(struct udpif
*udpif
)
488 if (udpif
&& (udpif
->n_handlers
!= 0 || udpif
->n_revalidators
!= 0)) {
491 latch_set(&udpif
->exit_latch
);
493 for (i
= 0; i
< udpif
->n_handlers
; i
++) {
494 struct handler
*handler
= &udpif
->handlers
[i
];
496 xpthread_join(handler
->thread
, NULL
);
499 for (i
= 0; i
< udpif
->n_revalidators
; i
++) {
500 xpthread_join(udpif
->revalidators
[i
].thread
, NULL
);
503 dpif_disable_upcall(udpif
->dpif
);
505 for (i
= 0; i
< udpif
->n_revalidators
; i
++) {
506 struct revalidator
*revalidator
= &udpif
->revalidators
[i
];
508 /* Delete ukeys, and delete all flows from the datapath to prevent
509 * double-counting stats. */
510 revalidator_purge(revalidator
);
513 latch_poll(&udpif
->exit_latch
);
515 ovs_barrier_destroy(&udpif
->reval_barrier
);
516 ovs_barrier_destroy(&udpif
->pause_barrier
);
518 free(udpif
->revalidators
);
519 udpif
->revalidators
= NULL
;
520 udpif
->n_revalidators
= 0;
522 free(udpif
->handlers
);
523 udpif
->handlers
= NULL
;
524 udpif
->n_handlers
= 0;
528 /* Starts the handler and revalidator threads, must be enclosed in
529 * ovsrcu quiescent state. */
531 udpif_start_threads(struct udpif
*udpif
, size_t n_handlers
,
532 size_t n_revalidators
)
534 if (udpif
&& n_handlers
&& n_revalidators
) {
538 udpif
->n_handlers
= n_handlers
;
539 udpif
->n_revalidators
= n_revalidators
;
541 udpif
->handlers
= xzalloc(udpif
->n_handlers
* sizeof *udpif
->handlers
);
542 for (i
= 0; i
< udpif
->n_handlers
; i
++) {
543 struct handler
*handler
= &udpif
->handlers
[i
];
545 handler
->udpif
= udpif
;
546 handler
->handler_id
= i
;
547 handler
->thread
= ovs_thread_create(
548 "handler", udpif_upcall_handler
, handler
);
551 enable_ufid
= udpif
->backer
->support
.ufid
;
552 atomic_init(&udpif
->enable_ufid
, enable_ufid
);
553 dpif_enable_upcall(udpif
->dpif
);
555 ovs_barrier_init(&udpif
->reval_barrier
, udpif
->n_revalidators
);
556 ovs_barrier_init(&udpif
->pause_barrier
, udpif
->n_revalidators
+ 1);
557 udpif
->reval_exit
= false;
558 udpif
->pause
= false;
559 udpif
->revalidators
= xzalloc(udpif
->n_revalidators
560 * sizeof *udpif
->revalidators
);
561 for (i
= 0; i
< udpif
->n_revalidators
; i
++) {
562 struct revalidator
*revalidator
= &udpif
->revalidators
[i
];
564 revalidator
->udpif
= udpif
;
565 revalidator
->thread
= ovs_thread_create(
566 "revalidator", udpif_revalidator
, revalidator
);
571 /* Pauses all revalidators. Should only be called by the main thread.
572 * When function returns, all revalidators are paused and will proceed
573 * only after udpif_resume_revalidators() is called. */
575 udpif_pause_revalidators(struct udpif
*udpif
)
577 if (udpif
->backer
->recv_set_enable
) {
578 latch_set(&udpif
->pause_latch
);
579 ovs_barrier_block(&udpif
->pause_barrier
);
583 /* Resumes the pausing of revalidators. Should only be called by the
586 udpif_resume_revalidators(struct udpif
*udpif
)
588 if (udpif
->backer
->recv_set_enable
) {
589 latch_poll(&udpif
->pause_latch
);
590 ovs_barrier_block(&udpif
->pause_barrier
);
594 /* Tells 'udpif' how many threads it should use to handle upcalls.
595 * 'n_handlers' and 'n_revalidators' can never be zero. 'udpif''s
596 * datapath handle must have packet reception enabled before starting
599 udpif_set_threads(struct udpif
*udpif
, size_t n_handlers
,
600 size_t n_revalidators
)
603 ovs_assert(n_handlers
&& n_revalidators
);
605 ovsrcu_quiesce_start();
606 if (udpif
->n_handlers
!= n_handlers
607 || udpif
->n_revalidators
!= n_revalidators
) {
608 udpif_stop_threads(udpif
);
611 if (!udpif
->handlers
&& !udpif
->revalidators
) {
614 error
= dpif_handlers_set(udpif
->dpif
, n_handlers
);
616 VLOG_ERR("failed to configure handlers in dpif %s: %s",
617 dpif_name(udpif
->dpif
), ovs_strerror(error
));
621 udpif_start_threads(udpif
, n_handlers
, n_revalidators
);
623 ovsrcu_quiesce_end();
626 /* Waits for all ongoing upcall translations to complete. This ensures that
627 * there are no transient references to any removed ofprotos (or other
628 * objects). In particular, this should be called after an ofproto is removed
629 * (e.g. via xlate_remove_ofproto()) but before it is destroyed. */
631 udpif_synchronize(struct udpif
*udpif
)
633 /* This is stronger than necessary. It would be sufficient to ensure
634 * (somehow) that each handler and revalidator thread had passed through
635 * its main loop once. */
636 size_t n_handlers
= udpif
->n_handlers
;
637 size_t n_revalidators
= udpif
->n_revalidators
;
639 ovsrcu_quiesce_start();
640 udpif_stop_threads(udpif
);
641 udpif_start_threads(udpif
, n_handlers
, n_revalidators
);
642 ovsrcu_quiesce_end();
645 /* Notifies 'udpif' that something changed which may render previous
646 * xlate_actions() results invalid. */
648 udpif_revalidate(struct udpif
*udpif
)
650 seq_change(udpif
->reval_seq
);
653 /* Returns a seq which increments every time 'udpif' pulls stats from the
654 * datapath. Callers can use this to get a sense of when might be a good time
655 * to do periodic work which relies on relatively up to date statistics. */
657 udpif_dump_seq(struct udpif
*udpif
)
659 return udpif
->dump_seq
;
663 udpif_get_memory_usage(struct udpif
*udpif
, struct simap
*usage
)
667 simap_increase(usage
, "handlers", udpif
->n_handlers
);
669 simap_increase(usage
, "revalidators", udpif
->n_revalidators
);
670 for (i
= 0; i
< N_UMAPS
; i
++) {
671 simap_increase(usage
, "udpif keys", cmap_count(&udpif
->ukeys
[i
].cmap
));
675 /* Remove flows from a single datapath. */
677 udpif_flush(struct udpif
*udpif
)
679 size_t n_handlers
, n_revalidators
;
681 n_handlers
= udpif
->n_handlers
;
682 n_revalidators
= udpif
->n_revalidators
;
684 ovsrcu_quiesce_start();
686 udpif_stop_threads(udpif
);
687 dpif_flow_flush(udpif
->dpif
);
688 udpif_start_threads(udpif
, n_handlers
, n_revalidators
);
690 ovsrcu_quiesce_end();
693 /* Removes all flows from all datapaths. */
695 udpif_flush_all_datapaths(void)
699 LIST_FOR_EACH (udpif
, list_node
, &all_udpifs
) {
705 udpif_use_ufid(struct udpif
*udpif
)
709 atomic_read_relaxed(&enable_ufid
, &enable
);
710 return enable
&& udpif
->backer
->support
.ufid
;
715 udpif_get_n_flows(struct udpif
*udpif
)
717 long long int time
, now
;
718 unsigned long flow_count
;
721 atomic_read_relaxed(&udpif
->n_flows_timestamp
, &time
);
722 if (time
< now
- 100 && !ovs_mutex_trylock(&udpif
->n_flows_mutex
)) {
723 struct dpif_dp_stats stats
;
725 atomic_store_relaxed(&udpif
->n_flows_timestamp
, now
);
726 dpif_get_dp_stats(udpif
->dpif
, &stats
);
727 flow_count
= stats
.n_flows
;
728 atomic_store_relaxed(&udpif
->n_flows
, flow_count
);
729 ovs_mutex_unlock(&udpif
->n_flows_mutex
);
731 atomic_read_relaxed(&udpif
->n_flows
, &flow_count
);
736 /* The upcall handler thread tries to read a batch of UPCALL_MAX_BATCH
737 * upcalls from dpif, processes the batch and installs corresponding flows
740 udpif_upcall_handler(void *arg
)
742 struct handler
*handler
= arg
;
743 struct udpif
*udpif
= handler
->udpif
;
745 while (!latch_is_set(&handler
->udpif
->exit_latch
)) {
746 if (recv_upcalls(handler
)) {
747 poll_immediate_wake();
749 dpif_recv_wait(udpif
->dpif
, handler
->handler_id
);
750 latch_wait(&udpif
->exit_latch
);
759 recv_upcalls(struct handler
*handler
)
761 struct udpif
*udpif
= handler
->udpif
;
762 uint64_t recv_stubs
[UPCALL_MAX_BATCH
][512 / 8];
763 struct ofpbuf recv_bufs
[UPCALL_MAX_BATCH
];
764 struct dpif_upcall dupcalls
[UPCALL_MAX_BATCH
];
765 struct upcall upcalls
[UPCALL_MAX_BATCH
];
766 struct flow flows
[UPCALL_MAX_BATCH
];
770 while (n_upcalls
< UPCALL_MAX_BATCH
) {
771 struct ofpbuf
*recv_buf
= &recv_bufs
[n_upcalls
];
772 struct dpif_upcall
*dupcall
= &dupcalls
[n_upcalls
];
773 struct upcall
*upcall
= &upcalls
[n_upcalls
];
774 struct flow
*flow
= &flows
[n_upcalls
];
778 ofpbuf_use_stub(recv_buf
, recv_stubs
[n_upcalls
],
779 sizeof recv_stubs
[n_upcalls
]);
780 if (dpif_recv(udpif
->dpif
, handler
->handler_id
, dupcall
, recv_buf
)) {
781 ofpbuf_uninit(recv_buf
);
785 if (odp_flow_key_to_flow(dupcall
->key
, dupcall
->key_len
, flow
)
791 mru
= nl_attr_get_u16(dupcall
->mru
);
796 error
= upcall_receive(upcall
, udpif
->backer
, &dupcall
->packet
,
797 dupcall
->type
, dupcall
->userdata
, flow
, mru
,
798 &dupcall
->ufid
, PMD_ID_NULL
);
800 if (error
== ENODEV
) {
801 /* Received packet on datapath port for which we couldn't
802 * associate an ofproto. This can happen if a port is removed
803 * while traffic is being received. Print a rate-limited
804 * message in case it happens frequently. */
805 dpif_flow_put(udpif
->dpif
, DPIF_FP_CREATE
, dupcall
->key
,
806 dupcall
->key_len
, NULL
, 0, NULL
, 0,
807 &dupcall
->ufid
, PMD_ID_NULL
, NULL
);
808 VLOG_INFO_RL(&rl
, "received packet on unassociated datapath "
809 "port %"PRIu32
, flow
->in_port
.odp_port
);
814 upcall
->key
= dupcall
->key
;
815 upcall
->key_len
= dupcall
->key_len
;
816 upcall
->ufid
= &dupcall
->ufid
;
818 upcall
->out_tun_key
= dupcall
->out_tun_key
;
819 upcall
->actions
= dupcall
->actions
;
821 pkt_metadata_from_flow(&dupcall
->packet
.md
, flow
);
822 flow_extract(&dupcall
->packet
, flow
);
824 error
= process_upcall(udpif
, upcall
,
825 &upcall
->odp_actions
, &upcall
->wc
);
834 upcall_uninit(upcall
);
836 dp_packet_uninit(&dupcall
->packet
);
837 ofpbuf_uninit(recv_buf
);
841 handle_upcalls(handler
->udpif
, upcalls
, n_upcalls
);
842 for (i
= 0; i
< n_upcalls
; i
++) {
843 dp_packet_uninit(&dupcalls
[i
].packet
);
844 ofpbuf_uninit(&recv_bufs
[i
]);
845 upcall_uninit(&upcalls
[i
]);
853 udpif_revalidator(void *arg
)
855 /* Used by all revalidators. */
856 struct revalidator
*revalidator
= arg
;
857 struct udpif
*udpif
= revalidator
->udpif
;
858 bool leader
= revalidator
== &udpif
->revalidators
[0];
860 /* Used only by the leader. */
861 long long int start_time
= 0;
862 uint64_t last_reval_seq
= 0;
865 revalidator
->id
= ovsthread_id_self();
870 recirc_run(); /* Recirculation cleanup. */
872 reval_seq
= seq_read(udpif
->reval_seq
);
873 last_reval_seq
= reval_seq
;
875 n_flows
= udpif_get_n_flows(udpif
);
876 udpif
->max_n_flows
= MAX(n_flows
, udpif
->max_n_flows
);
877 udpif
->avg_n_flows
= (udpif
->avg_n_flows
+ n_flows
) / 2;
879 /* Only the leader checks the pause latch to prevent a race where
880 * some threads think it's false and proceed to block on
881 * reval_barrier and others think it's true and block indefinitely
882 * on the pause_barrier */
883 udpif
->pause
= latch_is_set(&udpif
->pause_latch
);
885 /* Only the leader checks the exit latch to prevent a race where
886 * some threads think it's true and exit and others think it's
887 * false and block indefinitely on the reval_barrier */
888 udpif
->reval_exit
= latch_is_set(&udpif
->exit_latch
);
890 start_time
= time_msec();
891 if (!udpif
->reval_exit
) {
894 terse_dump
= udpif_use_ufid(udpif
);
895 udpif
->dump
= dpif_flow_dump_create(udpif
->dpif
, terse_dump
);
899 /* Wait for the leader to start the flow dump. */
900 ovs_barrier_block(&udpif
->reval_barrier
);
902 revalidator_pause(revalidator
);
905 if (udpif
->reval_exit
) {
908 revalidate(revalidator
);
910 /* Wait for all flows to have been dumped before we garbage collect. */
911 ovs_barrier_block(&udpif
->reval_barrier
);
912 revalidator_sweep(revalidator
);
914 /* Wait for all revalidators to finish garbage collection. */
915 ovs_barrier_block(&udpif
->reval_barrier
);
918 unsigned int flow_limit
;
919 long long int duration
;
921 atomic_read_relaxed(&udpif
->flow_limit
, &flow_limit
);
923 dpif_flow_dump_destroy(udpif
->dump
);
924 seq_change(udpif
->dump_seq
);
926 duration
= MAX(time_msec() - start_time
, 1);
927 udpif
->dump_duration
= duration
;
928 if (duration
> 2000) {
929 flow_limit
/= duration
/ 1000;
930 } else if (duration
> 1300) {
931 flow_limit
= flow_limit
* 3 / 4;
932 } else if (duration
< 1000 && n_flows
> 2000
933 && flow_limit
< n_flows
* 1000 / duration
) {
936 flow_limit
= MIN(ofproto_flow_limit
, MAX(flow_limit
, 1000));
937 atomic_store_relaxed(&udpif
->flow_limit
, flow_limit
);
939 if (duration
> 2000) {
940 VLOG_INFO("Spent an unreasonably long %lldms dumping flows",
944 poll_timer_wait_until(start_time
+ MIN(ofproto_max_idle
, 500));
945 seq_wait(udpif
->reval_seq
, last_reval_seq
);
946 latch_wait(&udpif
->exit_latch
);
947 latch_wait(&udpif
->pause_latch
);
950 if (!latch_is_set(&udpif
->pause_latch
) &&
951 !latch_is_set(&udpif
->exit_latch
)) {
952 long long int now
= time_msec();
953 /* Block again if we are woken up within 5ms of the last start
957 if (now
< start_time
) {
958 poll_timer_wait_until(start_time
);
959 latch_wait(&udpif
->exit_latch
);
960 latch_wait(&udpif
->pause_latch
);
970 static enum upcall_type
971 classify_upcall(enum dpif_upcall_type type
, const struct nlattr
*userdata
)
973 union user_action_cookie cookie
;
976 /* First look at the upcall type. */
984 case DPIF_N_UC_TYPES
:
986 VLOG_WARN_RL(&rl
, "upcall has unexpected type %"PRIu32
, type
);
990 /* "action" upcalls need a closer look. */
992 VLOG_WARN_RL(&rl
, "action upcall missing cookie");
995 userdata_len
= nl_attr_get_size(userdata
);
996 if (userdata_len
< sizeof cookie
.type
997 || userdata_len
> sizeof cookie
) {
998 VLOG_WARN_RL(&rl
, "action upcall cookie has unexpected size %"PRIuSIZE
,
1002 memset(&cookie
, 0, sizeof cookie
);
1003 memcpy(&cookie
, nl_attr_get(userdata
), userdata_len
);
1004 if (userdata_len
== MAX(8, sizeof cookie
.sflow
)
1005 && cookie
.type
== USER_ACTION_COOKIE_SFLOW
) {
1006 return SFLOW_UPCALL
;
1007 } else if (userdata_len
== MAX(8, sizeof cookie
.slow_path
)
1008 && cookie
.type
== USER_ACTION_COOKIE_SLOW_PATH
) {
1010 } else if (userdata_len
== MAX(8, sizeof cookie
.flow_sample
)
1011 && cookie
.type
== USER_ACTION_COOKIE_FLOW_SAMPLE
) {
1012 return FLOW_SAMPLE_UPCALL
;
1013 } else if (userdata_len
== MAX(8, sizeof cookie
.ipfix
)
1014 && cookie
.type
== USER_ACTION_COOKIE_IPFIX
) {
1015 return IPFIX_UPCALL
;
1017 VLOG_WARN_RL(&rl
, "invalid user cookie of type %"PRIu16
1018 " and size %"PRIuSIZE
, cookie
.type
, userdata_len
);
1023 /* Calculates slow path actions for 'xout'. 'buf' must statically be
1024 * initialized with at least 128 bytes of space. */
1026 compose_slow_path(struct udpif
*udpif
, struct xlate_out
*xout
,
1027 const struct flow
*flow
, odp_port_t odp_in_port
,
1030 union user_action_cookie cookie
;
1034 cookie
.type
= USER_ACTION_COOKIE_SLOW_PATH
;
1035 cookie
.slow_path
.unused
= 0;
1036 cookie
.slow_path
.reason
= xout
->slow
;
1038 port
= xout
->slow
& (SLOW_CFM
| SLOW_BFD
| SLOW_LACP
| SLOW_STP
)
1041 pid
= dpif_port_get_pid(udpif
->dpif
, port
, flow_hash_5tuple(flow
, 0));
1042 odp_put_userspace_action(pid
, &cookie
, sizeof cookie
.slow_path
,
1043 ODPP_NONE
, false, buf
);
1046 /* If there is no error, the upcall must be destroyed with upcall_uninit()
1047 * before quiescing, as the referred objects are guaranteed to exist only
1048 * until the calling thread quiesces. Otherwise, do not call upcall_uninit()
1049 * since the 'upcall->put_actions' remains uninitialized. */
1051 upcall_receive(struct upcall
*upcall
, const struct dpif_backer
*backer
,
1052 const struct dp_packet
*packet
, enum dpif_upcall_type type
,
1053 const struct nlattr
*userdata
, const struct flow
*flow
,
1054 const unsigned int mru
,
1055 const ovs_u128
*ufid
, const unsigned pmd_id
)
1059 error
= xlate_lookup(backer
, flow
, &upcall
->ofproto
, &upcall
->ipfix
,
1060 &upcall
->sflow
, NULL
, &upcall
->in_port
);
1065 upcall
->recirc
= NULL
;
1066 upcall
->have_recirc_ref
= false;
1067 upcall
->flow
= flow
;
1068 upcall
->packet
= packet
;
1069 upcall
->ufid
= ufid
;
1070 upcall
->pmd_id
= pmd_id
;
1071 upcall
->type
= type
;
1072 upcall
->userdata
= userdata
;
1073 ofpbuf_use_stub(&upcall
->odp_actions
, upcall
->odp_actions_stub
,
1074 sizeof upcall
->odp_actions_stub
);
1075 ofpbuf_init(&upcall
->put_actions
, 0);
1077 upcall
->xout_initialized
= false;
1078 upcall
->ukey_persists
= false;
1080 upcall
->ukey
= NULL
;
1082 upcall
->key_len
= 0;
1085 upcall
->out_tun_key
= NULL
;
1086 upcall
->actions
= NULL
;
1092 upcall_xlate(struct udpif
*udpif
, struct upcall
*upcall
,
1093 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
1095 struct dpif_flow_stats stats
;
1096 struct xlate_in xin
;
1098 stats
.n_packets
= 1;
1099 stats
.n_bytes
= dp_packet_size(upcall
->packet
);
1100 stats
.used
= time_msec();
1101 stats
.tcp_flags
= ntohs(upcall
->flow
->tcp_flags
);
1103 xlate_in_init(&xin
, upcall
->ofproto
,
1104 ofproto_dpif_get_tables_version(upcall
->ofproto
),
1105 upcall
->flow
, upcall
->in_port
, NULL
,
1106 stats
.tcp_flags
, upcall
->packet
, wc
, odp_actions
);
1108 if (upcall
->type
== DPIF_UC_MISS
) {
1109 xin
.resubmit_stats
= &stats
;
1111 if (xin
.frozen_state
) {
1112 /* We may install a datapath flow only if we get a reference to the
1113 * recirculation context (otherwise we could have recirculation
1114 * upcalls using recirculation ID for which no context can be
1115 * found). We may still execute the flow's actions even if we
1116 * don't install the flow. */
1117 upcall
->recirc
= recirc_id_node_from_state(xin
.frozen_state
);
1118 upcall
->have_recirc_ref
= recirc_id_node_try_ref_rcu(upcall
->recirc
);
1121 /* For non-miss upcalls, we are either executing actions (one of which
1122 * is an userspace action) for an upcall, in which case the stats have
1123 * already been taken care of, or there's a flow in the datapath which
1124 * this packet was accounted to. Presumably the revalidators will deal
1125 * with pushing its stats eventually. */
1128 upcall
->dump_seq
= seq_read(udpif
->dump_seq
);
1129 upcall
->reval_seq
= seq_read(udpif
->reval_seq
);
1131 xlate_actions(&xin
, &upcall
->xout
);
1133 /* Convert the input port wildcard from OFP to ODP format. There's no
1134 * real way to do this for arbitrary bitmasks since the numbering spaces
1135 * aren't the same. However, flow translation always exact matches the
1136 * whole thing, so we can do the same here. */
1137 WC_MASK_FIELD(wc
, in_port
.odp_port
);
1140 upcall
->xout_initialized
= true;
1142 if (!upcall
->xout
.slow
) {
1143 ofpbuf_use_const(&upcall
->put_actions
,
1144 odp_actions
->data
, odp_actions
->size
);
1146 /* upcall->put_actions already initialized by upcall_receive(). */
1147 compose_slow_path(udpif
, &upcall
->xout
, upcall
->flow
,
1148 upcall
->flow
->in_port
.odp_port
,
1149 &upcall
->put_actions
);
1152 /* This function is also called for slow-pathed flows. As we are only
1153 * going to create new datapath flows for actual datapath misses, there is
1154 * no point in creating a ukey otherwise. */
1155 if (upcall
->type
== DPIF_UC_MISS
) {
1156 upcall
->ukey
= ukey_create_from_upcall(upcall
, wc
);
1161 upcall_uninit(struct upcall
*upcall
)
1164 if (upcall
->xout_initialized
) {
1165 xlate_out_uninit(&upcall
->xout
);
1167 ofpbuf_uninit(&upcall
->odp_actions
);
1168 ofpbuf_uninit(&upcall
->put_actions
);
1170 if (!upcall
->ukey_persists
) {
1171 ukey_delete__(upcall
->ukey
);
1173 } else if (upcall
->have_recirc_ref
) {
1174 /* The reference was transferred to the ukey if one was created. */
1175 recirc_id_node_unref(upcall
->recirc
);
1180 /* If there are less flows than the limit, and this is a miss upcall which
1182 * - Has no recirc_id, OR
1183 * - Has a recirc_id and we can get a reference on the recirc ctx,
1185 * Then we should install the flow (true). Otherwise, return false. */
1187 should_install_flow(struct udpif
*udpif
, struct upcall
*upcall
)
1189 unsigned int flow_limit
;
1191 if (upcall
->type
!= DPIF_UC_MISS
) {
1193 } else if (upcall
->recirc
&& !upcall
->have_recirc_ref
) {
1194 VLOG_DBG_RL(&rl
, "upcall: no reference for recirc flow");
1198 atomic_read_relaxed(&udpif
->flow_limit
, &flow_limit
);
1199 if (udpif_get_n_flows(udpif
) >= flow_limit
) {
1200 VLOG_WARN_RL(&rl
, "upcall: datapath flow limit reached");
1208 upcall_cb(const struct dp_packet
*packet
, const struct flow
*flow
, ovs_u128
*ufid
,
1209 unsigned pmd_id
, enum dpif_upcall_type type
,
1210 const struct nlattr
*userdata
, struct ofpbuf
*actions
,
1211 struct flow_wildcards
*wc
, struct ofpbuf
*put_actions
, void *aux
)
1213 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
1214 struct udpif
*udpif
= aux
;
1215 struct upcall upcall
;
1219 atomic_read_relaxed(&enable_megaflows
, &megaflow
);
1221 error
= upcall_receive(&upcall
, udpif
->backer
, packet
, type
, userdata
,
1222 flow
, 0, ufid
, pmd_id
);
1227 error
= process_upcall(udpif
, &upcall
, actions
, wc
);
1232 if (upcall
.xout
.slow
&& put_actions
) {
1233 ofpbuf_put(put_actions
, upcall
.put_actions
.data
,
1234 upcall
.put_actions
.size
);
1237 if (OVS_UNLIKELY(!megaflow
&& wc
)) {
1238 flow_wildcards_init_for_packet(wc
, flow
);
1241 if (!should_install_flow(udpif
, &upcall
)) {
1246 if (upcall
.ukey
&& !ukey_install(udpif
, upcall
.ukey
)) {
1247 VLOG_WARN_RL(&rl
, "upcall_cb failure: ukey installation fails");
1252 upcall
.ukey_persists
= true;
1254 upcall_uninit(&upcall
);
1259 process_upcall(struct udpif
*udpif
, struct upcall
*upcall
,
1260 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
1262 const struct nlattr
*userdata
= upcall
->userdata
;
1263 const struct dp_packet
*packet
= upcall
->packet
;
1264 const struct flow
*flow
= upcall
->flow
;
1266 switch (classify_upcall(upcall
->type
, userdata
)) {
1268 upcall_xlate(udpif
, upcall
, odp_actions
, wc
);
1272 if (upcall
->sflow
) {
1273 union user_action_cookie cookie
;
1274 const struct nlattr
*actions
;
1275 size_t actions_len
= 0;
1276 struct dpif_sflow_actions sflow_actions
;
1277 memset(&sflow_actions
, 0, sizeof sflow_actions
);
1278 memset(&cookie
, 0, sizeof cookie
);
1279 memcpy(&cookie
, nl_attr_get(userdata
), sizeof cookie
.sflow
);
1280 if (upcall
->actions
) {
1281 /* Actions were passed up from datapath. */
1282 actions
= nl_attr_get(upcall
->actions
);
1283 actions_len
= nl_attr_get_size(upcall
->actions
);
1284 if (actions
&& actions_len
) {
1285 dpif_sflow_read_actions(flow
, actions
, actions_len
,
1289 if (actions_len
== 0) {
1290 /* Lookup actions in userspace cache. */
1291 struct udpif_key
*ukey
= ukey_lookup(udpif
, upcall
->ufid
,
1294 ukey_get_actions(ukey
, &actions
, &actions_len
);
1295 dpif_sflow_read_actions(flow
, actions
, actions_len
,
1299 dpif_sflow_received(upcall
->sflow
, packet
, flow
,
1300 flow
->in_port
.odp_port
, &cookie
,
1301 actions_len
> 0 ? &sflow_actions
: NULL
);
1306 if (upcall
->ipfix
) {
1307 union user_action_cookie cookie
;
1308 struct flow_tnl output_tunnel_key
;
1310 memset(&cookie
, 0, sizeof cookie
);
1311 memcpy(&cookie
, nl_attr_get(userdata
), sizeof cookie
.ipfix
);
1313 if (upcall
->out_tun_key
) {
1314 odp_tun_key_from_attr(upcall
->out_tun_key
, &output_tunnel_key
);
1316 dpif_ipfix_bridge_sample(upcall
->ipfix
, packet
, flow
,
1317 flow
->in_port
.odp_port
,
1318 cookie
.ipfix
.output_odp_port
,
1319 upcall
->out_tun_key
?
1320 &output_tunnel_key
: NULL
);
1324 case FLOW_SAMPLE_UPCALL
:
1325 if (upcall
->ipfix
) {
1326 union user_action_cookie cookie
;
1327 struct flow_tnl output_tunnel_key
;
1329 memset(&cookie
, 0, sizeof cookie
);
1330 memcpy(&cookie
, nl_attr_get(userdata
), sizeof cookie
.flow_sample
);
1332 if (upcall
->out_tun_key
) {
1333 odp_tun_key_from_attr(upcall
->out_tun_key
, &output_tunnel_key
);
1336 /* The flow reflects exactly the contents of the packet.
1337 * Sample the packet using it. */
1338 dpif_ipfix_flow_sample(upcall
->ipfix
, packet
, flow
,
1339 &cookie
, flow
->in_port
.odp_port
,
1340 upcall
->out_tun_key
?
1341 &output_tunnel_key
: NULL
);
1353 handle_upcalls(struct udpif
*udpif
, struct upcall
*upcalls
,
1356 struct dpif_op
*opsp
[UPCALL_MAX_BATCH
* 2];
1357 struct ukey_op ops
[UPCALL_MAX_BATCH
* 2];
1358 size_t n_ops
, n_opsp
, i
;
1360 /* Handle the packets individually in order of arrival.
1362 * - For SLOW_CFM, SLOW_LACP, SLOW_STP, SLOW_BFD, and SLOW_LLDP,
1363 * translation is what processes received packets for these
1366 * - For SLOW_CONTROLLER, translation sends the packet to the OpenFlow
1369 * - For SLOW_ACTION, translation executes the actions directly.
1371 * The loop fills 'ops' with an array of operations to execute in the
1374 for (i
= 0; i
< n_upcalls
; i
++) {
1375 struct upcall
*upcall
= &upcalls
[i
];
1376 const struct dp_packet
*packet
= upcall
->packet
;
1379 if (should_install_flow(udpif
, upcall
)) {
1380 struct udpif_key
*ukey
= upcall
->ukey
;
1382 if (ukey_install(udpif
, ukey
)) {
1383 upcall
->ukey_persists
= true;
1384 put_op_init(&ops
[n_ops
++], ukey
, DPIF_FP_CREATE
);
1388 if (upcall
->odp_actions
.size
) {
1391 op
->dop
.type
= DPIF_OP_EXECUTE
;
1392 op
->dop
.u
.execute
.packet
= CONST_CAST(struct dp_packet
*, packet
);
1393 op
->dop
.u
.execute
.flow
= upcall
->flow
;
1394 odp_key_to_pkt_metadata(upcall
->key
, upcall
->key_len
,
1395 &op
->dop
.u
.execute
.packet
->md
);
1396 op
->dop
.u
.execute
.actions
= upcall
->odp_actions
.data
;
1397 op
->dop
.u
.execute
.actions_len
= upcall
->odp_actions
.size
;
1398 op
->dop
.u
.execute
.needs_help
= (upcall
->xout
.slow
& SLOW_ACTION
) != 0;
1399 op
->dop
.u
.execute
.probe
= false;
1400 op
->dop
.u
.execute
.mtu
= upcall
->mru
;
1404 /* Execute batch. */
1406 for (i
= 0; i
< n_ops
; i
++) {
1407 opsp
[n_opsp
++] = &ops
[i
].dop
;
1409 dpif_operate(udpif
->dpif
, opsp
, n_opsp
);
1410 for (i
= 0; i
< n_ops
; i
++) {
1411 struct udpif_key
*ukey
= ops
[i
].ukey
;
1414 ovs_mutex_lock(&ukey
->mutex
);
1415 if (ops
[i
].dop
.error
) {
1416 transition_ukey(ukey
, UKEY_EVICTED
);
1417 } else if (ukey
->state
< UKEY_OPERATIONAL
) {
1418 transition_ukey(ukey
, UKEY_OPERATIONAL
);
1420 ovs_mutex_unlock(&ukey
->mutex
);
1426 get_ukey_hash(const ovs_u128
*ufid
, const unsigned pmd_id
)
1428 return hash_2words(ufid
->u32
[0], pmd_id
);
1431 static struct udpif_key
*
1432 ukey_lookup(struct udpif
*udpif
, const ovs_u128
*ufid
, const unsigned pmd_id
)
1434 struct udpif_key
*ukey
;
1435 int idx
= get_ukey_hash(ufid
, pmd_id
) % N_UMAPS
;
1436 struct cmap
*cmap
= &udpif
->ukeys
[idx
].cmap
;
1438 CMAP_FOR_EACH_WITH_HASH (ukey
, cmap_node
,
1439 get_ukey_hash(ufid
, pmd_id
), cmap
) {
1440 if (ovs_u128_equals(ukey
->ufid
, *ufid
)) {
1447 /* Provides safe lockless access of RCU protected 'ukey->actions'. Callers may
1448 * alternatively access the field directly if they take 'ukey->mutex'. */
1450 ukey_get_actions(struct udpif_key
*ukey
, const struct nlattr
**actions
, size_t *size
)
1452 const struct ofpbuf
*buf
= ovsrcu_get(struct ofpbuf
*, &ukey
->actions
);
1453 *actions
= buf
->data
;
1458 ukey_set_actions(struct udpif_key
*ukey
, const struct ofpbuf
*actions
)
1460 ovsrcu_postpone(ofpbuf_delete
,
1461 ovsrcu_get_protected(struct ofpbuf
*, &ukey
->actions
));
1462 ovsrcu_set(&ukey
->actions
, ofpbuf_clone(actions
));
1465 static struct udpif_key
*
1466 ukey_create__(const struct nlattr
*key
, size_t key_len
,
1467 const struct nlattr
*mask
, size_t mask_len
,
1468 bool ufid_present
, const ovs_u128
*ufid
,
1469 const unsigned pmd_id
, const struct ofpbuf
*actions
,
1470 uint64_t dump_seq
, uint64_t reval_seq
, long long int used
,
1471 uint32_t key_recirc_id
, struct xlate_out
*xout
)
1472 OVS_NO_THREAD_SAFETY_ANALYSIS
1474 struct udpif_key
*ukey
= xmalloc(sizeof *ukey
);
1476 memcpy(&ukey
->keybuf
, key
, key_len
);
1477 ukey
->key
= &ukey
->keybuf
.nla
;
1478 ukey
->key_len
= key_len
;
1479 memcpy(&ukey
->maskbuf
, mask
, mask_len
);
1480 ukey
->mask
= &ukey
->maskbuf
.nla
;
1481 ukey
->mask_len
= mask_len
;
1482 ukey
->ufid_present
= ufid_present
;
1484 ukey
->pmd_id
= pmd_id
;
1485 ukey
->hash
= get_ukey_hash(&ukey
->ufid
, pmd_id
);
1487 ovsrcu_init(&ukey
->actions
, NULL
);
1488 ukey_set_actions(ukey
, actions
);
1490 ovs_mutex_init(&ukey
->mutex
);
1491 ukey
->dump_seq
= dump_seq
;
1492 ukey
->reval_seq
= reval_seq
;
1493 ukey
->state
= UKEY_CREATED
;
1494 ukey
->state_thread
= ovsthread_id_self();
1495 ukey
->state_where
= OVS_SOURCE_LOCATOR
;
1496 ukey
->created
= time_msec();
1497 memset(&ukey
->stats
, 0, sizeof ukey
->stats
);
1498 ukey
->stats
.used
= used
;
1499 ukey
->xcache
= NULL
;
1501 ukey
->key_recirc_id
= key_recirc_id
;
1502 recirc_refs_init(&ukey
->recircs
);
1504 /* Take ownership of the action recirc id references. */
1505 recirc_refs_swap(&ukey
->recircs
, &xout
->recircs
);
1511 static struct udpif_key
*
1512 ukey_create_from_upcall(struct upcall
*upcall
, struct flow_wildcards
*wc
)
1514 struct odputil_keybuf keystub
, maskstub
;
1515 struct ofpbuf keybuf
, maskbuf
;
1517 struct odp_flow_key_parms odp_parms
= {
1518 .flow
= upcall
->flow
,
1519 .mask
= wc
? &wc
->masks
: NULL
,
1522 odp_parms
.support
= upcall
->ofproto
->backer
->support
.odp
;
1523 if (upcall
->key_len
) {
1524 ofpbuf_use_const(&keybuf
, upcall
->key
, upcall
->key_len
);
1526 /* dpif-netdev doesn't provide a netlink-formatted flow key in the
1527 * upcall, so convert the upcall's flow here. */
1528 ofpbuf_use_stack(&keybuf
, &keystub
, sizeof keystub
);
1529 odp_flow_key_from_flow(&odp_parms
, &keybuf
);
1532 atomic_read_relaxed(&enable_megaflows
, &megaflow
);
1533 ofpbuf_use_stack(&maskbuf
, &maskstub
, sizeof maskstub
);
1534 if (megaflow
&& wc
) {
1535 odp_parms
.key_buf
= &keybuf
;
1536 odp_flow_key_from_mask(&odp_parms
, &maskbuf
);
1539 return ukey_create__(keybuf
.data
, keybuf
.size
, maskbuf
.data
, maskbuf
.size
,
1540 true, upcall
->ufid
, upcall
->pmd_id
,
1541 &upcall
->put_actions
, upcall
->dump_seq
,
1542 upcall
->reval_seq
, 0,
1543 upcall
->have_recirc_ref
? upcall
->recirc
->id
: 0,
1548 ukey_create_from_dpif_flow(const struct udpif
*udpif
,
1549 const struct dpif_flow
*flow
,
1550 struct udpif_key
**ukey
)
1552 struct dpif_flow full_flow
;
1553 struct ofpbuf actions
;
1554 uint64_t dump_seq
, reval_seq
;
1555 uint64_t stub
[DPIF_FLOW_BUFSIZE
/ 8];
1556 const struct nlattr
*a
;
1559 if (!flow
->key_len
|| !flow
->actions_len
) {
1563 /* If the key or actions were not provided by the datapath, fetch the
1565 ofpbuf_use_stack(&buf
, &stub
, sizeof stub
);
1566 err
= dpif_flow_get(udpif
->dpif
, flow
->key
, flow
->key_len
,
1567 flow
->ufid_present
? &flow
->ufid
: NULL
,
1568 flow
->pmd_id
, &buf
, &full_flow
);
1575 /* Check the flow actions for recirculation action. As recirculation
1576 * relies on OVS userspace internal state, we need to delete all old
1577 * datapath flows with either a non-zero recirc_id in the key, or any
1578 * recirculation actions upon OVS restart. */
1579 NL_ATTR_FOR_EACH_UNSAFE (a
, left
, flow
->key
, flow
->key_len
) {
1580 if (nl_attr_type(a
) == OVS_KEY_ATTR_RECIRC_ID
1581 && nl_attr_get_u32(a
) != 0) {
1585 NL_ATTR_FOR_EACH_UNSAFE (a
, left
, flow
->actions
, flow
->actions_len
) {
1586 if (nl_attr_type(a
) == OVS_ACTION_ATTR_RECIRC
) {
1591 dump_seq
= seq_read(udpif
->dump_seq
);
1592 reval_seq
= seq_read(udpif
->reval_seq
);
1593 ofpbuf_use_const(&actions
, &flow
->actions
, flow
->actions_len
);
1594 *ukey
= ukey_create__(flow
->key
, flow
->key_len
,
1595 flow
->mask
, flow
->mask_len
, flow
->ufid_present
,
1596 &flow
->ufid
, flow
->pmd_id
, &actions
, dump_seq
,
1597 reval_seq
, flow
->stats
.used
, 0, NULL
);
1603 try_ukey_replace(struct umap
*umap
, struct udpif_key
*old_ukey
,
1604 struct udpif_key
*new_ukey
)
1605 OVS_REQUIRES(umap
->mutex
)
1606 OVS_TRY_LOCK(true, new_ukey
->mutex
)
1608 bool replaced
= false;
1610 if (!ovs_mutex_trylock(&old_ukey
->mutex
)) {
1611 if (old_ukey
->state
== UKEY_EVICTED
) {
1612 /* The flow was deleted during the current revalidator dump,
1613 * but its ukey won't be fully cleaned up until the sweep phase.
1614 * In the mean time, we are receiving upcalls for this traffic.
1615 * Expedite the (new) flow install by replacing the ukey. */
1616 ovs_mutex_lock(&new_ukey
->mutex
);
1617 cmap_replace(&umap
->cmap
, &old_ukey
->cmap_node
,
1618 &new_ukey
->cmap_node
, new_ukey
->hash
);
1619 ovsrcu_postpone(ukey_delete__
, old_ukey
);
1620 transition_ukey(old_ukey
, UKEY_DELETED
);
1621 transition_ukey(new_ukey
, UKEY_VISIBLE
);
1624 ovs_mutex_unlock(&old_ukey
->mutex
);
1628 COVERAGE_INC(upcall_ukey_replace
);
1630 COVERAGE_INC(handler_duplicate_upcall
);
1635 /* Attempts to insert a ukey into the shared ukey maps.
1637 * On success, returns true, installs the ukey and returns it in a locked
1638 * state. Otherwise, returns false. */
1640 ukey_install__(struct udpif
*udpif
, struct udpif_key
*new_ukey
)
1641 OVS_TRY_LOCK(true, new_ukey
->mutex
)
1644 struct udpif_key
*old_ukey
;
1646 bool locked
= false;
1648 idx
= new_ukey
->hash
% N_UMAPS
;
1649 umap
= &udpif
->ukeys
[idx
];
1650 ovs_mutex_lock(&umap
->mutex
);
1651 old_ukey
= ukey_lookup(udpif
, &new_ukey
->ufid
, new_ukey
->pmd_id
);
1653 /* Uncommon case: A ukey is already installed with the same UFID. */
1654 if (old_ukey
->key_len
== new_ukey
->key_len
1655 && !memcmp(old_ukey
->key
, new_ukey
->key
, new_ukey
->key_len
)) {
1656 locked
= try_ukey_replace(umap
, old_ukey
, new_ukey
);
1658 struct ds ds
= DS_EMPTY_INITIALIZER
;
1660 odp_format_ufid(&old_ukey
->ufid
, &ds
);
1661 ds_put_cstr(&ds
, " ");
1662 odp_flow_key_format(old_ukey
->key
, old_ukey
->key_len
, &ds
);
1663 ds_put_cstr(&ds
, "\n");
1664 odp_format_ufid(&new_ukey
->ufid
, &ds
);
1665 ds_put_cstr(&ds
, " ");
1666 odp_flow_key_format(new_ukey
->key
, new_ukey
->key_len
, &ds
);
1668 VLOG_WARN_RL(&rl
, "Conflicting ukey for flows:\n%s", ds_cstr(&ds
));
1672 ovs_mutex_lock(&new_ukey
->mutex
);
1673 cmap_insert(&umap
->cmap
, &new_ukey
->cmap_node
, new_ukey
->hash
);
1674 transition_ukey(new_ukey
, UKEY_VISIBLE
);
1677 ovs_mutex_unlock(&umap
->mutex
);
1683 transition_ukey_at(struct udpif_key
*ukey
, enum ukey_state dst
,
1685 OVS_REQUIRES(ukey
->mutex
)
1687 if (dst
< ukey
->state
) {
1688 VLOG_ABORT("Invalid ukey transition %d->%d (last transitioned from "
1689 "thread %u at %s)", ukey
->state
, dst
, ukey
->state_thread
,
1692 if (ukey
->state
== dst
&& dst
== UKEY_OPERATIONAL
) {
1696 /* Valid state transitions:
1697 * UKEY_CREATED -> UKEY_VISIBLE
1698 * Ukey is now visible in the umap.
1699 * UKEY_VISIBLE -> UKEY_OPERATIONAL
1700 * A handler has installed the flow, and the flow is in the datapath.
1701 * UKEY_VISIBLE -> UKEY_EVICTING
1702 * A handler installs the flow, then revalidator sweeps the ukey before
1703 * the flow is dumped. Most likely the flow was installed; start trying
1705 * UKEY_VISIBLE -> UKEY_EVICTED
1706 * A handler attempts to install the flow, but the datapath rejects it.
1707 * Consider that the datapath has already destroyed it.
1708 * UKEY_OPERATIONAL -> UKEY_EVICTING
1709 * A revalidator decides to evict the datapath flow.
1710 * UKEY_EVICTING -> UKEY_EVICTED
1711 * A revalidator has evicted the datapath flow.
1712 * UKEY_EVICTED -> UKEY_DELETED
1713 * A revalidator has removed the ukey from the umap and is deleting it.
1715 if (ukey
->state
== dst
- 1 || (ukey
->state
== UKEY_VISIBLE
&&
1716 dst
< UKEY_DELETED
)) {
1719 struct ds ds
= DS_EMPTY_INITIALIZER
;
1721 odp_format_ufid(&ukey
->ufid
, &ds
);
1722 VLOG_WARN_RL(&rl
, "Invalid state transition for ukey %s: %d -> %d",
1723 ds_cstr(&ds
), ukey
->state
, dst
);
1726 ukey
->state_thread
= ovsthread_id_self();
1727 ukey
->state_where
= where
;
1731 ukey_install(struct udpif
*udpif
, struct udpif_key
*ukey
)
1735 installed
= ukey_install__(udpif
, ukey
);
1737 ovs_mutex_unlock(&ukey
->mutex
);
1743 /* Searches for a ukey in 'udpif->ukeys' that matches 'flow' and attempts to
1744 * lock the ukey. If the ukey does not exist, create it.
1746 * Returns 0 on success, setting *result to the matching ukey and returning it
1747 * in a locked state. Otherwise, returns an errno and clears *result. EBUSY
1748 * indicates that another thread is handling this flow. Other errors indicate
1749 * an unexpected condition creating a new ukey.
1751 * *error is an output parameter provided to appease the threadsafety analyser,
1752 * and its value matches the return value. */
1754 ukey_acquire(struct udpif
*udpif
, const struct dpif_flow
*flow
,
1755 struct udpif_key
**result
, int *error
)
1756 OVS_TRY_LOCK(0, (*result
)->mutex
)
1758 struct udpif_key
*ukey
;
1761 ukey
= ukey_lookup(udpif
, &flow
->ufid
, flow
->pmd_id
);
1763 retval
= ovs_mutex_trylock(&ukey
->mutex
);
1765 /* Usually we try to avoid installing flows from revalidator threads,
1766 * because locking on a umap may cause handler threads to block.
1767 * However there are certain cases, like when ovs-vswitchd is
1768 * restarted, where it is desirable to handle flows that exist in the
1769 * datapath gracefully (ie, don't just clear the datapath). */
1772 retval
= ukey_create_from_dpif_flow(udpif
, flow
, &ukey
);
1776 install
= ukey_install__(udpif
, ukey
);
1780 ukey_delete__(ukey
);
1796 ukey_delete__(struct udpif_key
*ukey
)
1797 OVS_NO_THREAD_SAFETY_ANALYSIS
1800 if (ukey
->key_recirc_id
) {
1801 recirc_free_id(ukey
->key_recirc_id
);
1803 recirc_refs_unref(&ukey
->recircs
);
1804 xlate_cache_delete(ukey
->xcache
);
1805 ofpbuf_delete(ovsrcu_get(struct ofpbuf
*, &ukey
->actions
));
1806 ovs_mutex_destroy(&ukey
->mutex
);
1812 ukey_delete(struct umap
*umap
, struct udpif_key
*ukey
)
1813 OVS_REQUIRES(umap
->mutex
)
1815 ovs_mutex_lock(&ukey
->mutex
);
1816 if (ukey
->state
< UKEY_DELETED
) {
1817 cmap_remove(&umap
->cmap
, &ukey
->cmap_node
, ukey
->hash
);
1818 ovsrcu_postpone(ukey_delete__
, ukey
);
1819 transition_ukey(ukey
, UKEY_DELETED
);
1821 ovs_mutex_unlock(&ukey
->mutex
);
1825 should_revalidate(const struct udpif
*udpif
, uint64_t packets
,
1828 long long int metric
, now
, duration
;
1831 /* Always revalidate the first time a flow is dumped. */
1835 if (udpif
->dump_duration
< 200) {
1836 /* We are likely to handle full revalidation for the flows. */
1840 /* Calculate the mean time between seeing these packets. If this
1841 * exceeds the threshold, then delete the flow rather than performing
1842 * costly revalidation for flows that aren't being hit frequently.
1844 * This is targeted at situations where the dump_duration is high (~1s),
1845 * and revalidation is triggered by a call to udpif_revalidate(). In
1846 * these situations, revalidation of all flows causes fluctuations in the
1847 * flow_limit due to the interaction with the dump_duration and max_idle.
1848 * This tends to result in deletion of low-throughput flows anyway, so
1849 * skip the revalidation and just delete those flows. */
1850 packets
= MAX(packets
, 1);
1851 now
= MAX(used
, time_msec());
1852 duration
= now
- used
;
1853 metric
= duration
/ packets
;
1856 /* The flow is receiving more than ~5pps, so keep it. */
1862 struct reval_context
{
1863 /* Optional output parameters */
1864 struct flow_wildcards
*wc
;
1865 struct ofpbuf
*odp_actions
;
1866 struct netflow
**netflow
;
1867 struct xlate_cache
*xcache
;
1869 /* Required output parameters */
1870 struct xlate_out xout
;
1874 /* Translates 'key' into a flow, populating 'ctx' as it goes along.
1876 * Returns 0 on success, otherwise a positive errno value.
1878 * The caller is responsible for uninitializing ctx->xout on success.
1881 xlate_key(struct udpif
*udpif
, const struct nlattr
*key
, unsigned int len
,
1882 const struct dpif_flow_stats
*push
, struct reval_context
*ctx
)
1884 struct ofproto_dpif
*ofproto
;
1885 ofp_port_t ofp_in_port
;
1886 struct xlate_in xin
;
1889 if (odp_flow_key_to_flow(key
, len
, &ctx
->flow
) == ODP_FIT_ERROR
) {
1893 error
= xlate_lookup(udpif
->backer
, &ctx
->flow
, &ofproto
, NULL
, NULL
,
1894 ctx
->netflow
, &ofp_in_port
);
1899 xlate_in_init(&xin
, ofproto
, ofproto_dpif_get_tables_version(ofproto
),
1900 &ctx
->flow
, ofp_in_port
, NULL
, push
->tcp_flags
,
1901 NULL
, ctx
->wc
, ctx
->odp_actions
);
1902 if (push
->n_packets
) {
1903 xin
.resubmit_stats
= push
;
1904 xin
.allow_side_effects
= true;
1906 xin
.xcache
= ctx
->xcache
;
1907 xlate_actions(&xin
, &ctx
->xout
);
1913 xlate_ukey(struct udpif
*udpif
, const struct udpif_key
*ukey
,
1914 uint16_t tcp_flags
, struct reval_context
*ctx
)
1916 struct dpif_flow_stats push
= {
1917 .tcp_flags
= tcp_flags
,
1919 return xlate_key(udpif
, ukey
->key
, ukey
->key_len
, &push
, ctx
);
1923 populate_xcache(struct udpif
*udpif
, struct udpif_key
*ukey
,
1925 OVS_REQUIRES(ukey
->mutex
)
1927 struct reval_context ctx
= {
1928 .odp_actions
= NULL
,
1934 ovs_assert(!ukey
->xcache
);
1935 ukey
->xcache
= ctx
.xcache
= xlate_cache_new();
1936 error
= xlate_ukey(udpif
, ukey
, tcp_flags
, &ctx
);
1940 xlate_out_uninit(&ctx
.xout
);
1945 static enum reval_result
1946 revalidate_ukey__(struct udpif
*udpif
, const struct udpif_key
*ukey
,
1947 uint16_t tcp_flags
, struct ofpbuf
*odp_actions
,
1948 struct recirc_refs
*recircs
, struct xlate_cache
*xcache
)
1950 struct xlate_out
*xoutp
;
1951 struct netflow
*netflow
;
1952 struct flow_wildcards dp_mask
, wc
;
1953 enum reval_result result
;
1954 struct reval_context ctx
= {
1955 .odp_actions
= odp_actions
,
1956 .netflow
= &netflow
,
1961 result
= UKEY_DELETE
;
1965 if (xlate_ukey(udpif
, ukey
, tcp_flags
, &ctx
)) {
1970 if (xoutp
->avoid_caching
) {
1975 ofpbuf_clear(odp_actions
);
1976 compose_slow_path(udpif
, xoutp
, &ctx
.flow
, ctx
.flow
.in_port
.odp_port
,
1980 if (odp_flow_key_to_mask(ukey
->mask
, ukey
->mask_len
, &dp_mask
, &ctx
.flow
)
1985 /* Do not modify if any bit is wildcarded by the installed datapath flow,
1986 * but not the newly revalidated wildcard mask (wc), i.e., if revalidation
1987 * tells that the datapath flow is now too generic and must be narrowed
1988 * down. Note that we do not know if the datapath has ignored any of the
1989 * wildcarded bits, so we may be overtly conservative here. */
1990 if (flow_wildcards_has_extra(&dp_mask
, ctx
.wc
)) {
1994 if (!ofpbuf_equal(odp_actions
,
1995 ovsrcu_get(struct ofpbuf
*, &ukey
->actions
))) {
1996 /* The datapath mask was OK, but the actions seem to have changed.
1997 * Let's modify it in place. */
1998 result
= UKEY_MODIFY
;
1999 /* Transfer recirc action ID references to the caller. */
2000 recirc_refs_swap(recircs
, &xoutp
->recircs
);
2007 if (netflow
&& result
== UKEY_DELETE
) {
2008 netflow_flow_clear(netflow
, &ctx
.flow
);
2010 xlate_out_uninit(xoutp
);
2014 /* Verifies that the datapath actions of 'ukey' are still correct, and pushes
2017 * Returns a recommended action for 'ukey', options include:
2018 * UKEY_DELETE The ukey should be deleted.
2019 * UKEY_KEEP The ukey is fine as is.
2020 * UKEY_MODIFY The ukey's actions should be changed but is otherwise
2021 * fine. Callers should change the actions to those found
2022 * in the caller supplied 'odp_actions' buffer. The
2023 * recirculation references can be found in 'recircs' and
2024 * must be handled by the caller.
2026 * If the result is UKEY_MODIFY, then references to all recirc_ids used by the
2027 * new flow will be held within 'recircs' (which may be none).
2029 * The caller is responsible for both initializing 'recircs' prior this call,
2030 * and ensuring any references are eventually freed.
2032 static enum reval_result
2033 revalidate_ukey(struct udpif
*udpif
, struct udpif_key
*ukey
,
2034 const struct dpif_flow_stats
*stats
,
2035 struct ofpbuf
*odp_actions
, uint64_t reval_seq
,
2036 struct recirc_refs
*recircs
)
2037 OVS_REQUIRES(ukey
->mutex
)
2039 bool need_revalidate
= ukey
->reval_seq
!= reval_seq
;
2040 enum reval_result result
= UKEY_DELETE
;
2041 struct dpif_flow_stats push
;
2043 ofpbuf_clear(odp_actions
);
2045 push
.used
= stats
->used
;
2046 push
.tcp_flags
= stats
->tcp_flags
;
2047 push
.n_packets
= (stats
->n_packets
> ukey
->stats
.n_packets
2048 ? stats
->n_packets
- ukey
->stats
.n_packets
2050 push
.n_bytes
= (stats
->n_bytes
> ukey
->stats
.n_bytes
2051 ? stats
->n_bytes
- ukey
->stats
.n_bytes
2054 if (need_revalidate
) {
2055 if (should_revalidate(udpif
, push
.n_packets
, ukey
->stats
.used
)) {
2056 if (!ukey
->xcache
) {
2057 ukey
->xcache
= xlate_cache_new();
2059 xlate_cache_clear(ukey
->xcache
);
2061 result
= revalidate_ukey__(udpif
, ukey
, push
.tcp_flags
,
2062 odp_actions
, recircs
, ukey
->xcache
);
2063 } /* else delete; too expensive to revalidate */
2064 } else if (!push
.n_packets
|| ukey
->xcache
2065 || !populate_xcache(udpif
, ukey
, push
.tcp_flags
)) {
2069 /* Stats for deleted flows will be attributed upon flow deletion. Skip. */
2070 if (result
!= UKEY_DELETE
) {
2071 xlate_push_stats(ukey
->xcache
, &push
);
2072 ukey
->stats
= *stats
;
2073 ukey
->reval_seq
= reval_seq
;
2080 delete_op_init__(struct udpif
*udpif
, struct ukey_op
*op
,
2081 const struct dpif_flow
*flow
)
2084 op
->dop
.type
= DPIF_OP_FLOW_DEL
;
2085 op
->dop
.u
.flow_del
.key
= flow
->key
;
2086 op
->dop
.u
.flow_del
.key_len
= flow
->key_len
;
2087 op
->dop
.u
.flow_del
.ufid
= flow
->ufid_present
? &flow
->ufid
: NULL
;
2088 op
->dop
.u
.flow_del
.pmd_id
= flow
->pmd_id
;
2089 op
->dop
.u
.flow_del
.stats
= &op
->stats
;
2090 op
->dop
.u
.flow_del
.terse
= udpif_use_ufid(udpif
);
2094 delete_op_init(struct udpif
*udpif
, struct ukey_op
*op
, struct udpif_key
*ukey
)
2097 op
->dop
.type
= DPIF_OP_FLOW_DEL
;
2098 op
->dop
.u
.flow_del
.key
= ukey
->key
;
2099 op
->dop
.u
.flow_del
.key_len
= ukey
->key_len
;
2100 op
->dop
.u
.flow_del
.ufid
= ukey
->ufid_present
? &ukey
->ufid
: NULL
;
2101 op
->dop
.u
.flow_del
.pmd_id
= ukey
->pmd_id
;
2102 op
->dop
.u
.flow_del
.stats
= &op
->stats
;
2103 op
->dop
.u
.flow_del
.terse
= udpif_use_ufid(udpif
);
2107 put_op_init(struct ukey_op
*op
, struct udpif_key
*ukey
,
2108 enum dpif_flow_put_flags flags
)
2111 op
->dop
.type
= DPIF_OP_FLOW_PUT
;
2112 op
->dop
.u
.flow_put
.flags
= flags
;
2113 op
->dop
.u
.flow_put
.key
= ukey
->key
;
2114 op
->dop
.u
.flow_put
.key_len
= ukey
->key_len
;
2115 op
->dop
.u
.flow_put
.mask
= ukey
->mask
;
2116 op
->dop
.u
.flow_put
.mask_len
= ukey
->mask_len
;
2117 op
->dop
.u
.flow_put
.ufid
= ukey
->ufid_present
? &ukey
->ufid
: NULL
;
2118 op
->dop
.u
.flow_put
.pmd_id
= ukey
->pmd_id
;
2119 op
->dop
.u
.flow_put
.stats
= NULL
;
2120 ukey_get_actions(ukey
, &op
->dop
.u
.flow_put
.actions
,
2121 &op
->dop
.u
.flow_put
.actions_len
);
2124 /* Executes datapath operations 'ops' and attributes stats retrieved from the
2125 * datapath as part of those operations. */
2127 push_dp_ops(struct udpif
*udpif
, struct ukey_op
*ops
, size_t n_ops
)
2129 struct dpif_op
*opsp
[REVALIDATE_MAX_BATCH
];
2132 ovs_assert(n_ops
<= REVALIDATE_MAX_BATCH
);
2133 for (i
= 0; i
< n_ops
; i
++) {
2134 opsp
[i
] = &ops
[i
].dop
;
2136 dpif_operate(udpif
->dpif
, opsp
, n_ops
);
2138 for (i
= 0; i
< n_ops
; i
++) {
2139 struct ukey_op
*op
= &ops
[i
];
2140 struct dpif_flow_stats
*push
, *stats
, push_buf
;
2142 stats
= op
->dop
.u
.flow_del
.stats
;
2145 if (op
->dop
.type
!= DPIF_OP_FLOW_DEL
) {
2146 /* Only deleted flows need their stats pushed. */
2150 if (op
->dop
.error
) {
2151 /* flow_del error, 'stats' is unusable. */
2156 ovs_mutex_lock(&op
->ukey
->mutex
);
2157 transition_ukey(op
->ukey
, UKEY_EVICTED
);
2158 push
->used
= MAX(stats
->used
, op
->ukey
->stats
.used
);
2159 push
->tcp_flags
= stats
->tcp_flags
| op
->ukey
->stats
.tcp_flags
;
2160 push
->n_packets
= stats
->n_packets
- op
->ukey
->stats
.n_packets
;
2161 push
->n_bytes
= stats
->n_bytes
- op
->ukey
->stats
.n_bytes
;
2162 ovs_mutex_unlock(&op
->ukey
->mutex
);
2167 if (push
->n_packets
|| netflow_exists()) {
2168 const struct nlattr
*key
= op
->dop
.u
.flow_del
.key
;
2169 size_t key_len
= op
->dop
.u
.flow_del
.key_len
;
2170 struct netflow
*netflow
;
2171 struct reval_context ctx
= {
2172 .netflow
= &netflow
,
2177 ovs_mutex_lock(&op
->ukey
->mutex
);
2178 if (op
->ukey
->xcache
) {
2179 xlate_push_stats(op
->ukey
->xcache
, push
);
2180 ovs_mutex_unlock(&op
->ukey
->mutex
);
2183 ovs_mutex_unlock(&op
->ukey
->mutex
);
2184 key
= op
->ukey
->key
;
2185 key_len
= op
->ukey
->key_len
;
2188 error
= xlate_key(udpif
, key
, key_len
, push
, &ctx
);
2190 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
2192 VLOG_WARN_RL(&rl
, "xlate_actions failed (%s)!",
2193 xlate_strerror(error
));
2195 xlate_out_uninit(&ctx
.xout
);
2197 netflow_flow_clear(netflow
, &ctx
.flow
);
2204 /* Executes datapath operations 'ops', attributes stats retrieved from the
2205 * datapath, and deletes ukeys corresponding to deleted flows. */
2207 push_ukey_ops(struct udpif
*udpif
, struct umap
*umap
,
2208 struct ukey_op
*ops
, size_t n_ops
)
2212 push_dp_ops(udpif
, ops
, n_ops
);
2213 ovs_mutex_lock(&umap
->mutex
);
2214 for (i
= 0; i
< n_ops
; i
++) {
2215 if (ops
[i
].dop
.type
== DPIF_OP_FLOW_DEL
) {
2216 ukey_delete(umap
, ops
[i
].ukey
);
2219 ovs_mutex_unlock(&umap
->mutex
);
2223 log_unexpected_flow(const struct dpif_flow
*flow
, int error
)
2225 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 60);
2226 struct ds ds
= DS_EMPTY_INITIALIZER
;
2228 ds_put_format(&ds
, "Failed to acquire udpif_key corresponding to "
2229 "unexpected flow (%s): ", ovs_strerror(error
));
2230 odp_format_ufid(&flow
->ufid
, &ds
);
2231 VLOG_WARN_RL(&rl
, "%s", ds_cstr(&ds
));
2236 reval_op_init(struct ukey_op
*op
, enum reval_result result
,
2237 struct udpif
*udpif
, struct udpif_key
*ukey
,
2238 struct recirc_refs
*recircs
, struct ofpbuf
*odp_actions
)
2239 OVS_REQUIRES(ukey
->mutex
)
2241 if (result
== UKEY_DELETE
) {
2242 delete_op_init(udpif
, op
, ukey
);
2243 transition_ukey(ukey
, UKEY_EVICTING
);
2244 } else if (result
== UKEY_MODIFY
) {
2245 /* Store the new recircs. */
2246 recirc_refs_swap(&ukey
->recircs
, recircs
);
2247 /* Release old recircs. */
2248 recirc_refs_unref(recircs
);
2249 /* ukey->key_recirc_id remains, as the key is the same as before. */
2251 ukey_set_actions(ukey
, odp_actions
);
2252 put_op_init(op
, ukey
, DPIF_FP_MODIFY
);
2257 revalidate(struct revalidator
*revalidator
)
2259 uint64_t odp_actions_stub
[1024 / 8];
2260 struct ofpbuf odp_actions
= OFPBUF_STUB_INITIALIZER(odp_actions_stub
);
2262 struct udpif
*udpif
= revalidator
->udpif
;
2263 struct dpif_flow_dump_thread
*dump_thread
;
2264 uint64_t dump_seq
, reval_seq
;
2265 unsigned int flow_limit
;
2267 dump_seq
= seq_read(udpif
->dump_seq
);
2268 reval_seq
= seq_read(udpif
->reval_seq
);
2269 atomic_read_relaxed(&udpif
->flow_limit
, &flow_limit
);
2270 dump_thread
= dpif_flow_dump_thread_create(udpif
->dump
);
2272 struct ukey_op ops
[REVALIDATE_MAX_BATCH
];
2275 struct dpif_flow flows
[REVALIDATE_MAX_BATCH
];
2276 const struct dpif_flow
*f
;
2279 long long int max_idle
;
2284 n_dumped
= dpif_flow_dump_next(dump_thread
, flows
, ARRAY_SIZE(flows
));
2291 /* In normal operation we want to keep flows around until they have
2292 * been idle for 'ofproto_max_idle' milliseconds. However:
2294 * - If the number of datapath flows climbs above 'flow_limit',
2295 * drop that down to 100 ms to try to bring the flows down to
2298 * - If the number of datapath flows climbs above twice
2299 * 'flow_limit', delete all the datapath flows as an emergency
2300 * measure. (We reassess this condition for the next batch of
2301 * datapath flows, so we will recover before all the flows are
2303 n_dp_flows
= udpif_get_n_flows(udpif
);
2304 kill_them_all
= n_dp_flows
> flow_limit
* 2;
2305 max_idle
= n_dp_flows
> flow_limit
? 100 : ofproto_max_idle
;
2307 for (f
= flows
; f
< &flows
[n_dumped
]; f
++) {
2308 long long int used
= f
->stats
.used
;
2309 struct recirc_refs recircs
= RECIRC_REFS_EMPTY_INITIALIZER
;
2310 enum reval_result result
;
2311 struct udpif_key
*ukey
;
2312 bool already_dumped
;
2315 if (ukey_acquire(udpif
, f
, &ukey
, &error
)) {
2316 if (error
== EBUSY
) {
2317 /* Another thread is processing this flow, so don't bother
2319 COVERAGE_INC(upcall_ukey_contention
);
2321 log_unexpected_flow(f
, error
);
2322 if (error
!= ENOENT
) {
2323 delete_op_init__(udpif
, &ops
[n_ops
++], f
);
2329 already_dumped
= ukey
->dump_seq
== dump_seq
;
2330 if (already_dumped
) {
2331 /* The flow has already been handled during this flow dump
2332 * operation. Skip it. */
2334 COVERAGE_INC(dumped_duplicate_flow
);
2336 COVERAGE_INC(dumped_new_flow
);
2338 ovs_mutex_unlock(&ukey
->mutex
);
2342 if (ukey
->state
<= UKEY_OPERATIONAL
) {
2343 /* The flow is now confirmed to be in the datapath. */
2344 transition_ukey(ukey
, UKEY_OPERATIONAL
);
2346 VLOG_INFO("Unexpected ukey transition from state %d "
2347 "(last transitioned from thread %u at %s)",
2348 ukey
->state
, ukey
->state_thread
, ukey
->state_where
);
2349 ovs_mutex_unlock(&ukey
->mutex
);
2354 used
= ukey
->created
;
2356 if (kill_them_all
|| (used
&& used
< now
- max_idle
)) {
2357 result
= UKEY_DELETE
;
2359 result
= revalidate_ukey(udpif
, ukey
, &f
->stats
, &odp_actions
,
2360 reval_seq
, &recircs
);
2362 ukey
->dump_seq
= dump_seq
;
2364 if (result
!= UKEY_KEEP
) {
2365 /* Takes ownership of 'recircs'. */
2366 reval_op_init(&ops
[n_ops
++], result
, udpif
, ukey
, &recircs
,
2369 ovs_mutex_unlock(&ukey
->mutex
);
2373 /* Push datapath ops but defer ukey deletion to 'sweep' phase. */
2374 push_dp_ops(udpif
, ops
, n_ops
);
2378 dpif_flow_dump_thread_destroy(dump_thread
);
2379 ofpbuf_uninit(&odp_actions
);
2382 /* Pauses the 'revalidator', can only proceed after main thread
2383 * calls udpif_resume_revalidators(). */
2385 revalidator_pause(struct revalidator
*revalidator
)
2387 /* The first block is for sync'ing the pause with main thread. */
2388 ovs_barrier_block(&revalidator
->udpif
->pause_barrier
);
2389 /* The second block is for pausing until main thread resumes. */
2390 ovs_barrier_block(&revalidator
->udpif
->pause_barrier
);
2394 revalidator_sweep__(struct revalidator
*revalidator
, bool purge
)
2396 struct udpif
*udpif
;
2397 uint64_t dump_seq
, reval_seq
;
2400 udpif
= revalidator
->udpif
;
2401 dump_seq
= seq_read(udpif
->dump_seq
);
2402 reval_seq
= seq_read(udpif
->reval_seq
);
2403 slice
= revalidator
- udpif
->revalidators
;
2404 ovs_assert(slice
< udpif
->n_revalidators
);
2406 for (int i
= slice
; i
< N_UMAPS
; i
+= udpif
->n_revalidators
) {
2407 uint64_t odp_actions_stub
[1024 / 8];
2408 struct ofpbuf odp_actions
= OFPBUF_STUB_INITIALIZER(odp_actions_stub
);
2410 struct ukey_op ops
[REVALIDATE_MAX_BATCH
];
2411 struct udpif_key
*ukey
;
2412 struct umap
*umap
= &udpif
->ukeys
[i
];
2415 CMAP_FOR_EACH(ukey
, cmap_node
, &umap
->cmap
) {
2416 enum ukey_state ukey_state
;
2418 /* Handler threads could be holding a ukey lock while it installs a
2419 * new flow, so don't hang around waiting for access to it. */
2420 if (ovs_mutex_trylock(&ukey
->mutex
)) {
2423 ukey_state
= ukey
->state
;
2424 if (ukey_state
== UKEY_OPERATIONAL
2425 || (ukey_state
== UKEY_VISIBLE
&& purge
)) {
2426 struct recirc_refs recircs
= RECIRC_REFS_EMPTY_INITIALIZER
;
2427 bool seq_mismatch
= (ukey
->dump_seq
!= dump_seq
2428 && ukey
->reval_seq
!= reval_seq
);
2429 enum reval_result result
;
2432 result
= UKEY_DELETE
;
2433 } else if (!seq_mismatch
) {
2436 struct dpif_flow_stats stats
;
2437 COVERAGE_INC(revalidate_missed_dp_flow
);
2438 memset(&stats
, 0, sizeof stats
);
2439 result
= revalidate_ukey(udpif
, ukey
, &stats
, &odp_actions
,
2440 reval_seq
, &recircs
);
2442 if (result
!= UKEY_KEEP
) {
2443 /* Clears 'recircs' if filled by revalidate_ukey(). */
2444 reval_op_init(&ops
[n_ops
++], result
, udpif
, ukey
, &recircs
,
2448 ovs_mutex_unlock(&ukey
->mutex
);
2450 if (ukey_state
== UKEY_EVICTED
) {
2451 /* The common flow deletion case involves deletion of the flow
2452 * during the dump phase and ukey deletion here. */
2453 ovs_mutex_lock(&umap
->mutex
);
2454 ukey_delete(umap
, ukey
);
2455 ovs_mutex_unlock(&umap
->mutex
);
2458 if (n_ops
== REVALIDATE_MAX_BATCH
) {
2459 /* Update/delete missed flows and clean up corresponding ukeys
2461 push_ukey_ops(udpif
, umap
, ops
, n_ops
);
2467 push_ukey_ops(udpif
, umap
, ops
, n_ops
);
2470 ofpbuf_uninit(&odp_actions
);
2476 revalidator_sweep(struct revalidator
*revalidator
)
2478 revalidator_sweep__(revalidator
, false);
2482 revalidator_purge(struct revalidator
*revalidator
)
2484 revalidator_sweep__(revalidator
, true);
2487 /* In reaction to dpif purge, purges all 'ukey's with same 'pmd_id'. */
2489 dp_purge_cb(void *aux
, unsigned pmd_id
)
2490 OVS_NO_THREAD_SAFETY_ANALYSIS
2492 struct udpif
*udpif
= aux
;
2495 udpif_pause_revalidators(udpif
);
2496 for (i
= 0; i
< N_UMAPS
; i
++) {
2497 struct ukey_op ops
[REVALIDATE_MAX_BATCH
];
2498 struct udpif_key
*ukey
;
2499 struct umap
*umap
= &udpif
->ukeys
[i
];
2502 CMAP_FOR_EACH(ukey
, cmap_node
, &umap
->cmap
) {
2503 if (ukey
->pmd_id
== pmd_id
) {
2504 delete_op_init(udpif
, &ops
[n_ops
++], ukey
);
2505 transition_ukey(ukey
, UKEY_EVICTING
);
2507 if (n_ops
== REVALIDATE_MAX_BATCH
) {
2508 push_ukey_ops(udpif
, umap
, ops
, n_ops
);
2515 push_ukey_ops(udpif
, umap
, ops
, n_ops
);
2520 udpif_resume_revalidators(udpif
);
2524 upcall_unixctl_show(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
2525 const char *argv
[] OVS_UNUSED
, void *aux OVS_UNUSED
)
2527 struct ds ds
= DS_EMPTY_INITIALIZER
;
2528 struct udpif
*udpif
;
2530 LIST_FOR_EACH (udpif
, list_node
, &all_udpifs
) {
2531 unsigned int flow_limit
;
2535 atomic_read_relaxed(&udpif
->flow_limit
, &flow_limit
);
2536 ufid_enabled
= udpif_use_ufid(udpif
);
2538 ds_put_format(&ds
, "%s:\n", dpif_name(udpif
->dpif
));
2539 ds_put_format(&ds
, "\tflows : (current %lu)"
2540 " (avg %u) (max %u) (limit %u)\n", udpif_get_n_flows(udpif
),
2541 udpif
->avg_n_flows
, udpif
->max_n_flows
, flow_limit
);
2542 ds_put_format(&ds
, "\tdump duration : %lldms\n", udpif
->dump_duration
);
2543 ds_put_format(&ds
, "\tufid enabled : ");
2545 ds_put_format(&ds
, "true\n");
2547 ds_put_format(&ds
, "false\n");
2549 ds_put_char(&ds
, '\n');
2551 for (i
= 0; i
< n_revalidators
; i
++) {
2552 struct revalidator
*revalidator
= &udpif
->revalidators
[i
];
2553 int j
, elements
= 0;
2555 for (j
= i
; j
< N_UMAPS
; j
+= n_revalidators
) {
2556 elements
+= cmap_count(&udpif
->ukeys
[j
].cmap
);
2558 ds_put_format(&ds
, "\t%u: (keys %d)\n", revalidator
->id
, elements
);
2562 unixctl_command_reply(conn
, ds_cstr(&ds
));
2566 /* Disable using the megaflows.
2568 * This command is only needed for advanced debugging, so it's not
2569 * documented in the man page. */
2571 upcall_unixctl_disable_megaflows(struct unixctl_conn
*conn
,
2572 int argc OVS_UNUSED
,
2573 const char *argv
[] OVS_UNUSED
,
2574 void *aux OVS_UNUSED
)
2576 atomic_store_relaxed(&enable_megaflows
, false);
2577 udpif_flush_all_datapaths();
2578 unixctl_command_reply(conn
, "megaflows disabled");
2581 /* Re-enable using megaflows.
2583 * This command is only needed for advanced debugging, so it's not
2584 * documented in the man page. */
2586 upcall_unixctl_enable_megaflows(struct unixctl_conn
*conn
,
2587 int argc OVS_UNUSED
,
2588 const char *argv
[] OVS_UNUSED
,
2589 void *aux OVS_UNUSED
)
2591 atomic_store_relaxed(&enable_megaflows
, true);
2592 udpif_flush_all_datapaths();
2593 unixctl_command_reply(conn
, "megaflows enabled");
2596 /* Disable skipping flow attributes during flow dump.
2598 * This command is only needed for advanced debugging, so it's not
2599 * documented in the man page. */
2601 upcall_unixctl_disable_ufid(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
2602 const char *argv
[] OVS_UNUSED
, void *aux OVS_UNUSED
)
2604 atomic_store_relaxed(&enable_ufid
, false);
2605 unixctl_command_reply(conn
, "Datapath dumping tersely using UFID disabled");
2608 /* Re-enable skipping flow attributes during flow dump.
2610 * This command is only needed for advanced debugging, so it's not documented
2611 * in the man page. */
2613 upcall_unixctl_enable_ufid(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
2614 const char *argv
[] OVS_UNUSED
, void *aux OVS_UNUSED
)
2616 atomic_store_relaxed(&enable_ufid
, true);
2617 unixctl_command_reply(conn
, "Datapath dumping tersely using UFID enabled "
2618 "for supported datapaths");
2621 /* Set the flow limit.
2623 * This command is only needed for advanced debugging, so it's not
2624 * documented in the man page. */
2626 upcall_unixctl_set_flow_limit(struct unixctl_conn
*conn
,
2627 int argc OVS_UNUSED
,
2629 void *aux OVS_UNUSED
)
2631 struct ds ds
= DS_EMPTY_INITIALIZER
;
2632 struct udpif
*udpif
;
2633 unsigned int flow_limit
= atoi(argv
[1]);
2635 LIST_FOR_EACH (udpif
, list_node
, &all_udpifs
) {
2636 atomic_store_relaxed(&udpif
->flow_limit
, flow_limit
);
2638 ds_put_format(&ds
, "set flow_limit to %u\n", flow_limit
);
2639 unixctl_command_reply(conn
, ds_cstr(&ds
));
2644 upcall_unixctl_dump_wait(struct unixctl_conn
*conn
,
2645 int argc OVS_UNUSED
,
2646 const char *argv
[] OVS_UNUSED
,
2647 void *aux OVS_UNUSED
)
2649 if (ovs_list_is_singleton(&all_udpifs
)) {
2650 struct udpif
*udpif
= NULL
;
2653 udpif
= OBJECT_CONTAINING(ovs_list_front(&all_udpifs
), udpif
, list_node
);
2654 len
= (udpif
->n_conns
+ 1) * sizeof *udpif
->conns
;
2655 udpif
->conn_seq
= seq_read(udpif
->dump_seq
);
2656 udpif
->conns
= xrealloc(udpif
->conns
, len
);
2657 udpif
->conns
[udpif
->n_conns
++] = conn
;
2659 unixctl_command_reply_error(conn
, "can't wait on multiple udpifs.");
2664 upcall_unixctl_purge(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
2665 const char *argv
[] OVS_UNUSED
, void *aux OVS_UNUSED
)
2667 struct udpif
*udpif
;
2669 LIST_FOR_EACH (udpif
, list_node
, &all_udpifs
) {
2672 for (n
= 0; n
< udpif
->n_revalidators
; n
++) {
2673 revalidator_purge(&udpif
->revalidators
[n
]);
2676 unixctl_command_reply(conn
, "");