-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathovs.patch
More file actions
1933 lines (1814 loc) · 73.1 KB
/
ovs.patch
File metadata and controls
1933 lines (1814 loc) · 73.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/configure.ac b/configure.ac
index 55e8b509b..6573c684e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,7 @@ OVS_CHECK_CXX
AX_FUNC_POSIX_MEMALIGN
OVS_CHECK_UNBOUND
OVS_CHECK_UNWIND
+OVS_CHECK_NUEVOMATCHUP
OVS_CHECK_INCLUDE_NEXT([stdio.h string.h])
AC_CONFIG_FILES([
diff --git a/include/openvswitch/flow.h b/include/openvswitch/flow.h
index 57b6c925c..546a4d41d 100644
--- a/include/openvswitch/flow.h
+++ b/include/openvswitch/flow.h
@@ -198,6 +198,25 @@ struct flow_wildcards {
struct flow masks;
};
+/* Classifier iteration states for cmpflow synchronization */
+enum {
+ CMPFLOW_ITERATE_NONE = 0,
+ CMPFLOW_ITERATE_START,
+ CMPFLOW_ITERATE_TABLE,
+ CMPFLOW_ITERATE_FINISH
+};
+
+/* Information for installing computational flows */
+struct cmpflow_iterator {
+ struct flow flow;
+ struct flow_wildcards mask;
+ struct cls_cursor *cursor;
+ size_t unique_id;
+ int priority;
+ int table_id;
+ int iteration_state;
+};
+
#define WC_MASK_FIELD(WC, FIELD) \
memset(&(WC)->masks.FIELD, 0xff, sizeof (WC)->masks.FIELD)
#define WC_MASK_FIELD_MASK(WC, FIELD, MASK) \
diff --git a/lib/automake.mk b/lib/automake.mk
index 95925b57c..a713827cd 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -155,6 +155,8 @@ lib_libopenvswitch_la_SOURCES = \
lib/netlink.c \
lib/netlink.h \
lib/netnsid.h \
+ lib/dpif-netdev-nmu.h \
+ lib/dpif-netdev-nmu.c \
lib/nx-match.c \
lib/nx-match.h \
lib/object-collection.c \
diff --git a/lib/classifier-private.h b/lib/classifier-private.h
index 1d5ee007a..a5e77ab4a 100644
--- a/lib/classifier-private.h
+++ b/lib/classifier-private.h
@@ -72,6 +72,9 @@ struct cls_match {
/* Accessed by all readers. */
struct cmap_node cmap_node; /* Within struct cls_subtable 'rules'. */
+ /* Used for identifying cmpflows */
+ uint64_t unique_id;
+
/* Rule versioning. */
struct versions versions;
diff --git a/lib/classifier.c b/lib/classifier.c
index f2c3497c2..b679afe38 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -22,6 +22,7 @@
#include <netinet/in.h>
#include "byte-order.h"
#include "openvswitch/dynamic-string.h"
+#include "ovs-atomic.h"
#include "odp-util.h"
#include "packets.h"
#include "util.h"
@@ -102,6 +103,10 @@ cls_match_alloc(const struct cls_rule *rule, ovs_version_t version,
ovsrcu_set_hidden(&cls_match->conj_set,
cls_conjunction_set_alloc(cls_match, conj, n));
+ /* Install a unique ID per match */
+ static uint64_t unique_id = 0;
+ atomic_add_relaxed(&unique_id, 1ul, &cls_match->unique_id);
+
return cls_match;
}
@@ -937,7 +942,8 @@ free_conjunctive_matches(struct hmap *matches,
static const struct cls_rule *
classifier_lookup__(const struct classifier *cls, ovs_version_t version,
struct flow *flow, struct flow_wildcards *wc,
- bool allow_conjunctive_matches)
+ bool allow_conjunctive_matches,
+ struct cmpflow_iterator *it)
{
struct trie_ctx trie_ctx[CLS_MAX_TRIES];
const struct cls_match *match;
@@ -1016,6 +1022,9 @@ classifier_lookup__(const struct classifier *cls, ovs_version_t version,
if (soft != soft_stub) {
free(soft);
}
+ if (hard && it) {
+ cls_rule_set_cmpflow_iterator(hard->cls_rule, it);
+ }
return hard ? hard->cls_rule : NULL;
}
@@ -1097,7 +1106,7 @@ classifier_lookup__(const struct classifier *cls, ovs_version_t version,
const struct cls_rule *rule;
flow->conj_id = id;
- rule = classifier_lookup__(cls, version, flow, wc, false);
+ rule = classifier_lookup__(cls, version, flow, wc, false, it);
flow->conj_id = saved_conj_id;
if (rule) {
@@ -1147,9 +1156,30 @@ classifier_lookup__(const struct classifier *cls, ovs_version_t version,
if (soft != soft_stub) {
free(soft);
}
+ if (hard && it) {
+ cls_rule_set_cmpflow_iterator(hard->cls_rule, it);
+ }
return hard ? hard->cls_rule : NULL;
}
+/* Updates the computational flow iterator "it" with the properties of "rule.
+ * Returns "true" on success */
+bool
+cls_rule_set_cmpflow_iterator(const struct cls_rule *rule,
+ struct cmpflow_iterator *it)
+{
+ struct cls_match *match;
+ match = ovsrcu_get(struct cls_match *, &rule->cls_match);
+ if (!match) {
+ return false;
+ }
+ it->priority = rule->priority;
+ it->unique_id = match->unique_id;
+ miniflow_expand(rule->match.flow, &it->flow);
+ minimask_expand(rule->match.mask, &it->mask);
+ return true;
+}
+
/* Finds and returns the highest-priority rule in 'cls' that matches 'flow' and
* that is visible in 'version'. Returns a null pointer if no rules in 'cls'
* match 'flow'. If multiple rules of equal priority match 'flow', returns one
@@ -1166,7 +1196,17 @@ const struct cls_rule *
classifier_lookup(const struct classifier *cls, ovs_version_t version,
struct flow *flow, struct flow_wildcards *wc)
{
- return classifier_lookup__(cls, version, flow, wc, true);
+ return classifier_lookup__(cls, version, flow, wc, true, NULL);
+}
+
+const struct cls_rule *
+classifier_lookup_cmpflow(const struct classifier *cls,
+ ovs_version_t version,
+ struct flow *flow,
+ struct flow_wildcards *wc,
+ struct cmpflow_iterator *it)
+{
+ return classifier_lookup__(cls, version, flow, wc, true, it);
}
/* Finds and returns a rule in 'cls' with exactly the same priority and
diff --git a/lib/classifier.h b/lib/classifier.h
index f646a8f74..04423eb31 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -399,6 +399,11 @@ static inline void classifier_publish(struct classifier *);
const struct cls_rule *classifier_lookup(const struct classifier *,
ovs_version_t, struct flow *,
struct flow_wildcards *);
+const struct cls_rule *classifier_lookup_cmpflow(const struct classifier *cls,
+ ovs_version_t version,
+ struct flow *flow,
+ struct flow_wildcards *wc,
+ struct cmpflow_iterator *it);
bool classifier_rule_overlaps(const struct classifier *,
const struct cls_rule *, ovs_version_t);
const struct cls_rule *classifier_find_rule_exactly(const struct classifier *,
@@ -424,6 +429,8 @@ bool cls_rule_is_catchall(const struct cls_rule *);
bool cls_rule_is_loose_match(const struct cls_rule *rule,
const struct minimatch *criteria);
bool cls_rule_visible_in_version(const struct cls_rule *, ovs_version_t);
+bool cls_rule_set_cmpflow_iterator(const struct cls_rule *rule,
+ struct cmpflow_iterator *it);
/* Iteration.
*
diff --git a/lib/dpif-netdev-perf.c b/lib/dpif-netdev-perf.c
index 9560e7c3c..2cca4546c 100644
--- a/lib/dpif-netdev-perf.c
+++ b/lib/dpif-netdev-perf.c
@@ -206,6 +206,14 @@ pmd_perf_stats_init(struct pmd_perf_stats *s)
s->log_reason = NULL;
}
+void
+pmd_perf_stats_clear_extended(struct pmd_perf_stats *s)
+{
+ for (int i = PMD_TIME_DFC; i < PMD_N_STATS; i++) {
+ atomic_read_relaxed(&s->counters.n[i], &s->counters.zero[i]);
+ }
+}
+
void
pmd_perf_format_overall_stats(struct ds *str, struct pmd_perf_stats *s,
double duration)
diff --git a/lib/dpif-netdev-perf.h b/lib/dpif-netdev-perf.h
index 72645b6b3..fe383c251 100644
--- a/lib/dpif-netdev-perf.h
+++ b/lib/dpif-netdev-perf.h
@@ -35,6 +35,23 @@
#include "unixctl.h"
#include "util.h"
+/* Start measuring time (nano-secs) to an existing variable "name" */
+#define PERF_FILL(name) \
+ struct timespec name##_start, name##_end; \
+ clock_gettime(CLOCK_MONOTONIC, &name##_start);
+
+/* Start measuring time (nano-secs) to new variable "name" */
+#define PERF_START(name) \
+ struct timespec name##_start, name##_end; \
+ size_t name; \
+ clock_gettime(CLOCK_MONOTONIC, &name##_start);
+
+/* Stop measuring time, store results to variable double "name" */
+#define PERF_END(name) \
+ clock_gettime(CLOCK_MONOTONIC, &name##_end); \
+ name=-(name##_start.tv_sec * 1e9 + name##_start.tv_nsec) \
+ +(name##_end.tv_sec * 1e9 + name##_end.tv_nsec);
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -77,7 +94,18 @@ enum pmd_stat_type {
PMD_CYCLES_ITER_IDLE, /* Cycles spent in idle iterations. */
PMD_CYCLES_ITER_BUSY, /* Cycles spent in busy iterations. */
PMD_CYCLES_UPCALL, /* Cycles spent processing upcalls. */
- PMD_N_STATS
+ /* Used for measuring PMD extended statistics */
+ PMD_TIME_DFC,
+ PMD_TIME_FAST_PATH,
+ PMD_TIME_DPCLS,
+ PMD_TIME_FLOW_LOOKUP,
+ PMD_TIME_UPCALL,
+ PMD_TIME_EXECUTE,
+ PMD_DELTA_INSERTIONS,
+ PMD_DELTA_DELETIONS,
+ PMD_DELTA_UPCALLS,
+ PMD_DELTA_PACKETS,
+ PMD_N_STATS,
};
/* Array of PMD counters indexed by enum pmd_stat_type.
@@ -427,7 +455,7 @@ void pmd_perf_format_ms_history(struct ds *str, struct pmd_perf_stats *s,
void pmd_perf_log_set_cmd(struct unixctl_conn *conn,
int argc, const char *argv[],
void *aux OVS_UNUSED);
-
+void pmd_perf_stats_clear_extended(struct pmd_perf_stats *s);
#ifdef __cplusplus
}
#endif
diff --git a/lib/dpif-netdev-private.h b/lib/dpif-netdev-private.h
index 68c33a0f9..ce7ce8606 100644
--- a/lib/dpif-netdev-private.h
+++ b/lib/dpif-netdev-private.h
@@ -23,14 +23,27 @@
#include "dpif.h"
#include "cmap.h"
+#include "openvswitch/thread.h"
+#include "openvswitch/types.h"
+#include "pvector.h"
#ifdef __cplusplus
extern "C" {
#endif
+struct dpcls {
+ struct cmap_node node; /* Within dp_netdev_pmd_thread.classifiers */
+ odp_port_t in_port;
+ struct cmap subtables_map;
+ struct pvector subtables;
+};
+
/* Forward declaration for lookup_func typedef. */
struct dpcls_subtable;
struct dpcls_rule;
+struct dp_netdev_pmd_thread;
+
+extern struct odp_support dp_netdev_support;
/* Must be public as it is instantiated in subtable struct below. */
struct netdev_flow_key {
@@ -42,12 +55,37 @@ struct netdev_flow_key {
/* A rule to be inserted to the classifier. */
struct dpcls_rule {
+ struct cmpflow *cmpflow; /* Pointer to the relevant cmpflow */
+ uint64_t nmu_version; /* Which NMU version holds this */
+ bool in_nmu; /* Is this held by NMU library? */
+ bool is_cmpflow; /* False iff this is a megaflow */
struct cmap_node cmap_node; /* Within struct dpcls_subtable 'rules'. */
struct netdev_flow_key *mask; /* Subtable's mask. */
struct netdev_flow_key flow; /* Matching key. */
/* 'flow' must be the last field, additional space is allocated here. */
};
+/* A data-path computational flow. Computational flows can also represet
+ * "regular" non-overlapping megaflows without priorities. */
+struct cmpflow {
+ struct netdev_flow_key *flow; /* Used by NMU iSet match */
+ struct netdev_flow_key *mask; /* Used by NMU iSet match */
+ const uint64_t *mf_values; /* Packed values for flow */
+ uint64_t *mf_masks; /* Packed values for mask */
+ uint64_t unique_id; /* Unique ID of this */
+ int priority; /* Only has meaning if this is not megaflow */
+ uint8_t mf_bits_set_unit0; /* Used by NMU validation */
+ uint8_t mf_bits_set_unit1; /* Used by NMU validation */
+};
+
+/* dp_netdev_flow and methods are defined in dpif-netdev.c */
+struct dp_netdev_flow;
+
+void dp_netdev_flow_unref(struct dp_netdev_flow *);
+bool dp_netdev_flow_ref(struct dp_netdev_flow *);
+struct dp_netdev_flow * dp_netdev_flow_cast(const struct dpcls_rule *cr);
+
+
/* Lookup function for a subtable in the dpcls. This function is called
* by each subtable with an array of packets, and a bitmask of packets to
* perform the lookup on. Using a function pointer gives flexibility to
@@ -80,6 +118,9 @@ struct dpcls_subtable {
/* The fields are only used by writers. */
struct cmap_node cmap_node OVS_GUARDED; /* Within dpcls 'subtables_map'. */
+ /* Lock on "cmap_rules" */
+ struct ovs_spin cmap_rules_lock;
+
/* These fields are accessed by readers. */
struct cmap rules; /* Contains "struct dpcls_rule"s. */
uint32_t hit_cnt; /* Number of match hits in subtable in current
@@ -92,6 +133,9 @@ struct dpcls_subtable {
uint8_t mf_bits_set_unit0;
uint8_t mf_bits_set_unit1;
+ /* How many rules are linked to this subtable */
+ struct ovs_refcount ref_cnt;
+
/* The lookup function to use for this subtable. If there is a known
* property of the subtable (eg: only 3 bits of miniflow metadata is
* used for the lookup) then this can point at an optimized version of
@@ -105,6 +149,57 @@ struct dpcls_subtable {
/* 'mask' must be the last field, additional space is allocated here. */
};
+/* These support rule migration from dpcls to NMU */
+void dpcls_subtable_destroy_cb(struct dpcls_subtable *);
+bool dpcls_subtable_ref(struct dpcls_subtable *);
+void dpcls_subtable_unref(struct dpcls *cls, struct dpcls_subtable *);
+void dpcls_subtable_publish(struct dpcls *cls,
+ struct dpcls_subtable *);
+void dpcls_subtable_unpublish(struct dpcls *cls,
+ struct dpcls_subtable *subtable);
+
+/* Used both in dpif-netdev.c and dpif-netdev-nmu.c */
+void dpcls_insert(struct dpcls *, struct dpcls_rule *,
+ const struct netdev_flow_key *mask);
+void dpcls_remove(struct dpcls *, struct dpcls_rule *);
+
+void netdev_flow_mask_init_explicit(struct netdev_flow_key *mask,
+ const struct flow *flow,
+ const struct flow_wildcards *wc);
+void netdev_flow_key_init_masked(struct netdev_flow_key *dst,
+ const struct flow *flow,
+ const struct netdev_flow_key *mask);
+struct dpcls_rule * dp_netdev_flow_get_rule(struct dp_netdev_flow *);
+bool dp_netdev_flow_is_dead(struct dp_netdev_flow *);
+void dp_netdev_pmd_remove_flow(struct dp_netdev_pmd_thread *pmd,
+ struct dp_netdev_flow *flow);
+void dp_netdev_pmd_lock(struct dp_netdev_pmd_thread *pmd);
+void dp_netdev_pmd_unlock(struct dp_netdev_pmd_thread *pmd);
+void dp_netdev_pmd_unlock(struct dp_netdev_pmd_thread *pmd);
+long long dp_netdev_pmd_now(struct dp_netdev_pmd_thread *pmd);
+int dp_netdev_pmd_get_port_by_name(struct dp_netdev_pmd_thread *pmd,
+ const char *name,
+ odp_port_t *port_no_p);
+
+struct dp_netdev_flow * dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd,
+ struct match *match,
+ const ovs_u128 *ufid,
+ const struct nlattr *actions,
+ size_t actions_len,
+ struct cmpflow_iterator *);
+void dp_netdev_flow_used(struct dp_netdev_flow *netdev_flow,
+ int cnt,
+ int size,
+ uint16_t tcp_flags, long long now);
+const struct flow* dp_netdev_flow_get_flow(struct dp_netdev_flow *dp_flow);
+struct dpcls * dp_netdev_pmd_find_flow_dpcls(struct dp_netdev_pmd_thread *pmd,
+ struct dp_netdev_flow *flow);
+int dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
+ struct flow *flow, struct flow_wildcards *wc, ovs_u128 *ufid,
+ enum dpif_upcall_type type, const struct nlattr *userdata,
+ struct ofpbuf *actions, struct ofpbuf *put_actions,
+ struct cmpflow_iterator *it);
+
/* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */
#define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \
MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP)
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 42e1c44ae..c172d3431 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -42,6 +42,7 @@
#include "dp-packet.h"
#include "dpif.h"
#include "dpif-netdev-perf.h"
+#include "dpif-netdev-nmu.h"
#include "dpif-provider.h"
#include "dummy.h"
#include "fat-rwlock.h"
@@ -97,8 +98,8 @@ DEFINE_STATIC_PER_THREAD_DATA(uint32_t, recirc_depth, 0)
#define DEFAULT_TX_FLUSH_INTERVAL 0
/* Configuration parameters. */
-enum { MAX_FLOWS = 65536 }; /* Maximum number of flows in flow table. */
-enum { MAX_METERS = 65536 }; /* Maximum number of meters. */
+enum { MAX_FLOWS = 262144 }; /* Maximum number of flows in flow table. */
+enum { MAX_METERS = 262144 }; /* Maximum number of meters. */
enum { MAX_BANDS = 8 }; /* Maximum number of bands / meter. */
enum { N_METER_LOCKS = 64 }; /* Maximum number of meters. */
@@ -127,7 +128,7 @@ static struct vlog_rate_limit upcall_rl = VLOG_RATE_LIMIT_INIT(600, 600);
| CS_SRC_NAT | CS_DST_NAT)
#define DP_NETDEV_CS_UNSUPPORTED_MASK (~(uint32_t)DP_NETDEV_CS_SUPPORTED_MASK)
-static struct odp_support dp_netdev_support = {
+struct odp_support dp_netdev_support = {
.max_vlan_headers = SIZE_MAX,
.max_mpls_depth = SIZE_MAX,
.recirc = true,
@@ -239,13 +240,6 @@ struct dfc_cache {
* and used during rxq to pmd assignment. */
#define PMD_RXQ_INTERVAL_MAX 6
-struct dpcls {
- struct cmap_node node; /* Within dp_netdev_pmd_thread.classifiers */
- odp_port_t in_port;
- struct cmap subtables_map;
- struct pvector subtables;
-};
-
/* Data structure to keep packet order till fastpath processing. */
struct dp_packet_flow_map {
struct dp_packet *packet;
@@ -256,13 +250,12 @@ struct dp_packet_flow_map {
static void dpcls_init(struct dpcls *);
static void dpcls_destroy(struct dpcls *);
static void dpcls_sort_subtable_vector(struct dpcls *);
-static void dpcls_insert(struct dpcls *, struct dpcls_rule *,
- const struct netdev_flow_key *mask);
-static void dpcls_remove(struct dpcls *, struct dpcls_rule *);
-static bool dpcls_lookup(struct dpcls *cls,
+static bool dpcls_lookup(struct dp_netdev_pmd_thread *pmd,
+ odp_port_t in_port,
const struct netdev_flow_key *keys[],
struct dpcls_rule **rules, size_t cnt,
- int *num_lookups_p);
+ int *num_lookups_p,
+ struct nmucls *nmucls, size_t *dpcls_time_p);
/* Set of supported meter flags */
#define DP_SUPPORTED_METER_FLAGS_MASK \
@@ -339,6 +332,12 @@ struct dp_netdev {
/* Enable the SMC cache from ovsdb config */
atomic_bool smc_enable_db;
+ /* NuevoMatchUp configuration from ovsdb config */
+ struct nmu_config *nmu_config;
+
+ /* Interval in ms between each print */
+ double log_interval_ms;
+
/* Protects access to ofproto-dpif-upcall interface during revalidator
* thread synchronization. */
struct fat_rwlock upcall_rwlock;
@@ -567,8 +566,6 @@ struct dp_netdev_flow {
/* 'cr' must be the last member. */
};
-static void dp_netdev_flow_unref(struct dp_netdev_flow *);
-static bool dp_netdev_flow_ref(struct dp_netdev_flow *);
static int dpif_netdev_flow_from_nlattrs(const struct nlattr *, uint32_t,
struct flow *, bool);
@@ -688,6 +685,11 @@ struct dp_netdev_pmd_thread {
struct seq *reload_seq;
uint64_t last_reload_seq;
+ struct nmucls *nmucls;
+
+ /* Used for PMD extended statistics */
+ long long int log_timestamp;
+
/* These are atomic variables used as a synchronization and configuration
* points for thread reload/exit.
*
@@ -1017,6 +1019,58 @@ format_pmd_thread(struct ds *reply, struct dp_netdev_pmd_thread *pmd)
ds_put_cstr(reply, ":\n");
}
+/* Print the PMD's extended statistics for the preconfigured interval in ms */
+static void
+pmd_info_extended_stats(struct dp_netdev_pmd_thread *pmd)
+{
+ uint64_t stats[PMD_N_STATS];
+ long long int elapsed;
+ double lookups_per_hit;
+ struct ds ds;
+
+ elapsed = time_msec() - pmd->log_timestamp;
+ if (elapsed < pmd->dp->log_interval_ms) {
+ return;
+ }
+ pmd->log_timestamp = time_msec();
+
+ pmd_perf_read_counters(&pmd->perf_stats, stats);
+
+ lookups_per_hit = 0;
+ if (stats[PMD_STAT_MASKED_HIT] > 0) {
+ lookups_per_hit = stats[PMD_STAT_MASKED_LOOKUP]
+ / (double) stats[PMD_STAT_MASKED_HIT];
+ }
+
+ ds_init(&ds);
+ nmucls_print_stats(&ds, pmd->nmucls, " ");
+
+ VLOG_INFO("Extended stats: insertions: %lu deletions: %lu "
+ "total-flows: %lu packets: %lu "
+ "subtables: %lf "
+ "upcalls: %lu upcall-avg-us: %.2lf "
+ "dfc-us: %.2lf fastpath-us: %.2lf execute-us: %.2lf "
+ "dpcls-us: %.2lf lookup-us: %.2lf "
+ "%s",
+ stats[PMD_DELTA_INSERTIONS],
+ stats[PMD_DELTA_DELETIONS],
+ cmap_count(&pmd->flow_table),
+ stats[PMD_DELTA_PACKETS],
+ lookups_per_hit,
+ stats[PMD_DELTA_UPCALLS],
+ stats[PMD_TIME_UPCALL] / (double) stats[PMD_DELTA_UPCALLS]
+ / 1000.0,
+ stats[PMD_TIME_DFC] / 1000.0,
+ stats[PMD_TIME_FAST_PATH] / 1000.0,
+ stats[PMD_TIME_EXECUTE] / 1000.0,
+ stats[PMD_TIME_DPCLS] / 1000.0,
+ stats[PMD_TIME_FLOW_LOOKUP] / 1000.0,
+ ds_cstr(&ds));
+
+ nmucls_clear_stats(pmd->nmucls);
+ pmd_perf_stats_clear_extended(&pmd->perf_stats);
+}
+
static void
pmd_info_show_stats(struct ds *reply,
struct dp_netdev_pmd_thread *pmd)
@@ -1065,6 +1119,8 @@ pmd_info_show_stats(struct ds *reply,
stats[PMD_STAT_MISS], stats[PMD_STAT_LOST],
packets_per_batch);
+ nmucls_print_stats(reply, pmd->nmucls, "\n ");
+
if (total_cycles == 0) {
return;
}
@@ -1605,6 +1661,8 @@ create_dp_netdev(const char *name, const struct dpif_class *class,
return error;
}
+ dp->nmu_config = nmu_config_init();
+
dp->last_tnl_conf_seq = seq_read(tnl_conf_seq);
*dpp = dp;
return 0;
@@ -1716,6 +1774,8 @@ dp_netdev_free(struct dp_netdev *dp)
ovs_mutex_destroy(&dp->meter_locks[i]);
}
+ nmu_config_destroy(dp->nmu_config);
+
free(dp->pmd_cmask);
free(CONST_CAST(char *, dp->name));
free(dp);
@@ -2112,7 +2172,7 @@ dp_netdev_flow_free(struct dp_netdev_flow *flow)
free(flow);
}
-static void dp_netdev_flow_unref(struct dp_netdev_flow *flow)
+void dp_netdev_flow_unref(struct dp_netdev_flow *flow)
{
if (ovs_refcount_unref_relaxed(&flow->ref_cnt) == 1) {
ovsrcu_postpone(dp_netdev_flow_free, flow);
@@ -2159,6 +2219,14 @@ dp_netdev_pmd_find_dpcls(struct dp_netdev_pmd_thread *pmd,
return cls;
}
+struct dpcls *
+dp_netdev_pmd_find_flow_dpcls(struct dp_netdev_pmd_thread *pmd,
+ struct dp_netdev_flow *flow)
+{
+ return dp_netdev_pmd_find_dpcls(pmd, flow->flow.in_port.odp_port);
+
+}
+
#define MAX_FLOW_MARK (UINT32_MAX - 1)
#define INVALID_FLOW_MARK 0
/* Zero flow mark is used to indicate the HW to remove the mark. A packet
@@ -2591,24 +2659,36 @@ queue_netdev_flow_put(struct dp_netdev_pmd_thread *pmd,
dp_netdev_append_flow_offload(offload);
}
-static void
+void
dp_netdev_pmd_remove_flow(struct dp_netdev_pmd_thread *pmd,
struct dp_netdev_flow *flow)
OVS_REQUIRES(pmd->flow_mutex)
{
struct cmap_node *node = CONST_CAST(struct cmap_node *, &flow->node);
struct dpcls *cls;
+ bool flow_in_nmu;
+
odp_port_t in_port = flow->flow.in_port.odp_port;
cls = dp_netdev_pmd_lookup_dpcls(pmd, in_port);
- ovs_assert(cls != NULL);
- dpcls_remove(cls, &flow->cr);
+
+ nmucls_rule_lock(pmd->nmucls, &flow->cr);
+ pmd_perf_update_counter(&pmd->perf_stats, PMD_DELTA_DELETIONS, 1);
+ flow_in_nmu = nmucls_remove(pmd->nmucls, cls, flow);
+
+ if (!flow_in_nmu && !nmucls_rule_is_cmpflow(&flow->cr)) {
+ ovs_assert(cls != NULL);
+ dpcls_remove(cls, &flow->cr);
+ }
+
cmap_remove(&pmd->flow_table, node, dp_netdev_flow_hash(&flow->ufid));
if (flow->mark != INVALID_FLOW_MARK) {
queue_netdev_flow_del(pmd, flow);
}
flow->dead = true;
+ nmucls_rule_unlock(pmd->nmucls, &flow->cr);
+
dp_netdev_flow_unref(flow);
}
@@ -2715,13 +2795,13 @@ dpif_netdev_port_poll_wait(const struct dpif *dpif_)
seq_wait(dpif->dp->port_seq, dpif->last_port_seq);
}
-static struct dp_netdev_flow *
+struct dp_netdev_flow *
dp_netdev_flow_cast(const struct dpcls_rule *cr)
{
return cr ? CONTAINER_OF(cr, struct dp_netdev_flow, cr) : NULL;
}
-static bool dp_netdev_flow_ref(struct dp_netdev_flow *flow)
+bool dp_netdev_flow_ref(struct dp_netdev_flow *flow)
{
return ovs_refcount_try_ref_rcu(&flow->ref_cnt);
}
@@ -2772,10 +2852,10 @@ netdev_flow_key_clone(struct netdev_flow_key *dst,
offsetof(struct netdev_flow_key, mf) + src->len);
}
-/* Initialize a netdev_flow_key 'mask' from 'match'. */
-static inline void
-netdev_flow_mask_init(struct netdev_flow_key *mask,
- const struct match *match)
+void
+netdev_flow_mask_init_explicit(struct netdev_flow_key *mask,
+ const struct flow *flow,
+ const struct flow_wildcards *wc)
{
uint64_t *dst = miniflow_values(&mask->mf);
struct flowmap fmap;
@@ -2783,11 +2863,11 @@ netdev_flow_mask_init(struct netdev_flow_key *mask,
size_t idx;
/* Only check masks that make sense for the flow. */
- flow_wc_map(&match->flow, &fmap);
+ flow_wc_map(flow, &fmap);
flowmap_init(&mask->mf.map);
FLOWMAP_FOR_EACH_INDEX(idx, fmap) {
- uint64_t mask_u64 = flow_u64_value(&match->wc.masks, idx);
+ uint64_t mask_u64 = flow_u64_value(&wc->masks, idx);
if (mask_u64) {
flowmap_set(&mask->mf.map, idx, 1);
@@ -2808,8 +2888,16 @@ netdev_flow_mask_init(struct netdev_flow_key *mask,
mask->len = netdev_flow_key_size(n);
}
-/* Initializes 'dst' as a copy of 'flow' masked with 'mask'. */
+/* Initialize a netdev_flow_key 'mask' from 'match'. */
static inline void
+netdev_flow_mask_init(struct netdev_flow_key *mask,
+ const struct match *match)
+{
+ netdev_flow_mask_init_explicit(mask, &match->flow, &match->wc);
+}
+
+/* Initializes 'dst' as a copy of 'flow' masked with 'mask'. */
+void
netdev_flow_key_init_masked(struct netdev_flow_key *dst,
const struct flow *flow,
const struct netdev_flow_key *mask)
@@ -2830,6 +2918,55 @@ netdev_flow_key_init_masked(struct netdev_flow_key *dst,
(dst_u64 - miniflow_get_values(&dst->mf)) * 8);
}
+struct dpcls_rule *
+dp_netdev_flow_get_rule(struct dp_netdev_flow *flow)
+{
+ return &flow->cr;
+}
+
+bool
+dp_netdev_flow_is_dead(struct dp_netdev_flow *flow)
+{
+ return flow->dead;
+}
+
+int
+dp_netdev_pmd_get_port_by_name(struct dp_netdev_pmd_thread *pmd,
+ const char *name,
+ odp_port_t *port_no_p)
+{
+ struct dp_netdev_port *port;
+ if (get_port_by_name(pmd->dp, name, &port)) {
+ return ENODEV;
+ }
+ *port_no_p = port->port_no;
+ return 0;
+}
+
+void
+dp_netdev_pmd_lock(struct dp_netdev_pmd_thread *pmd)
+{
+ ovs_mutex_lock(&pmd->flow_mutex);
+}
+
+void
+dp_netdev_pmd_unlock(struct dp_netdev_pmd_thread *pmd)
+{
+ ovs_mutex_unlock(&pmd->flow_mutex);
+}
+
+const struct flow*
+dp_netdev_flow_get_flow(struct dp_netdev_flow *dp_flow)
+{
+ return &dp_flow->flow;
+}
+
+long long
+dp_netdev_pmd_now(struct dp_netdev_pmd_thread *pmd)
+{
+ return pmd->ctx.now;
+}
+
static inline bool
emc_entry_alive(struct emc_entry *ce)
{
@@ -3013,17 +3150,20 @@ dp_netdev_pmd_lookup_flow(struct dp_netdev_pmd_thread *pmd,
const struct netdev_flow_key *key,
int *lookup_num_p)
{
- struct dpcls *cls;
struct dpcls_rule *rule;
odp_port_t in_port = u32_to_odp(MINIFLOW_GET_U32(&key->mf,
in_port.odp_port));
struct dp_netdev_flow *netdev_flow = NULL;
+ size_t dpcls_time;
- cls = dp_netdev_pmd_lookup_dpcls(pmd, in_port);
- if (OVS_LIKELY(cls)) {
- dpcls_lookup(cls, &key, &rule, 1, lookup_num_p);
- netdev_flow = dp_netdev_flow_cast(rule);
- }
+ PERF_START(flow_lookup);
+ dpcls_lookup(pmd, in_port, &key, &rule, 1, lookup_num_p,
+ pmd->nmucls, &dpcls_time);
+ netdev_flow = dp_netdev_flow_cast(rule);
+ PERF_END(flow_lookup);
+ pmd_perf_update_counter(&pmd->perf_stats,
+ PMD_TIME_FLOW_LOOKUP,
+ flow_lookup - dpcls_time);
return netdev_flow;
}
@@ -3248,6 +3388,7 @@ dp_netdev_flow_to_dpif_flow(const struct dp_netdev *dp,
flow->ufid = netdev_flow->ufid;
flow->ufid_present = true;
flow->pmd_id = netdev_flow->pmd_id;
+ flow->is_cmpflow = nmucls_rule_is_cmpflow(&netdev_flow->cr);
get_dpif_flow_status(dp, netdev_flow, &flow->stats, &flow->attrs);
flow->attrs.dp_extra_info = netdev_flow->dp_extra_info;
@@ -3384,10 +3525,11 @@ dp_netdev_get_mega_ufid(const struct match *match, ovs_u128 *mega_ufid)
odp_flow_key_hash(&masked_flow, sizeof masked_flow, mega_ufid);
}
-static struct dp_netdev_flow *
+struct dp_netdev_flow *
dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd,
struct match *match, const ovs_u128 *ufid,
- const struct nlattr *actions, size_t actions_len)
+ const struct nlattr *actions, size_t actions_len,
+ struct cmpflow_iterator *cmpflow_it)
OVS_REQUIRES(pmd->flow_mutex)
{
struct ds extra_info = DS_EMPTY_INITIALIZER;
@@ -3435,8 +3577,15 @@ dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd,
netdev_flow_key_init_masked(&flow->cr.flow, &match->flow, &mask);
/* Select dpcls for in_port. Relies on in_port to be exact match. */
- cls = dp_netdev_pmd_find_dpcls(pmd, in_port);
- dpcls_insert(cls, &flow->cr, &mask);
+ if (!nmucls_cmpflow_enabled(pmd->nmucls)) {
+ cls = dp_netdev_pmd_find_dpcls(pmd, in_port);
+ dpcls_insert(cls, &flow->cr, &mask);
+ }
+
+ nmucls_insert(pmd->nmucls, &match->flow,
+ &match->wc, &flow->cr, cmpflow_it);
+
+ pmd_perf_update_counter(&pmd->perf_stats, PMD_DELTA_INSERTIONS, 1);
ds_put_cstr(&extra_info, "miniflow_bits(");
FLOWMAP_FOR_EACH_UNIT (unit) {
@@ -3447,6 +3596,7 @@ dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd,
count_1bits(flow->cr.mask->mf.map.bits[unit]));
}
ds_put_char(&extra_info, ')');
+ ds_put_cstr(&extra_info, flow->cr.is_cmpflow ? " cmpflow" : " megaflow");
flow->dp_extra_info = ds_steal_cstr(&extra_info);
ds_destroy(&extra_info);
@@ -3523,7 +3673,7 @@ flow_put_on_pmd(struct dp_netdev_pmd_thread *pmd,
if (put->flags & DPIF_FP_CREATE) {
if (cmap_count(&pmd->flow_table) < MAX_FLOWS) {
dp_netdev_flow_add(pmd, match, ufid, put->actions,
- put->actions_len);
+ put->actions_len, NULL);
error = 0;
} else {
error = EFBIG;
@@ -3822,15 +3972,20 @@ dpif_netdev_flow_dump_next(struct dpif_flow_dump_thread *thread_,
do {
for (n_flows = 0; n_flows < flow_limit; n_flows++) {
+ struct dp_netdev_flow *dp_flow;
struct cmap_node *node;
node = cmap_next_position(&pmd->flow_table, &dump->flow_pos);
if (!node) {
break;
}
- netdev_flows[n_flows] = CONTAINER_OF(node,
- struct dp_netdev_flow,
- node);
+ dp_flow = CONTAINER_OF(node, struct dp_netdev_flow, node);
+ /* Cmpflows are not managed by revalidator threads */
+ if (nmucls_rule_is_cmpflow(&dp_flow->cr)) {
+ n_flows--;
+ continue;
+ }
+ netdev_flows[n_flows] = dp_flow;
}
/* When finishing dumping the current pmd thread, moves to
* the next. */
@@ -4086,6 +4241,17 @@ dpif_netdev_set_config(struct dpif *dpif, const struct smap *other_config)
}
}
+ int nmu_state_changed = nmu_config_read(dp->nmu_config, other_config);
+ if (nmu_state_changed) {
+ dp_netdev_request_reconfigure(dp);
+ }
+
+ dp->log_interval_ms = smap_get_int(other_config,
+ "log-interval-ms",
+ 1e3);
+ VLOG_INFO("Log interval: %.0lf ms", dp->log_interval_ms);
+
+
bool pmd_rxq_assign_cyc = !strcmp(pmd_rxq_assign, "cycles");
if (!pmd_rxq_assign_cyc && strcmp(pmd_rxq_assign, "roundrobin")) {
VLOG_WARN("Unsupported Rxq to PMD assignment mode in pmd-rxq-assign. "
@@ -4950,8 +5116,8 @@ reconfigure_pmd_threads(struct dp_netdev *dp)
ds_put_format(&name, "pmd-c%02d/id:", core->core_id);
pmd->thread = ovs_thread_create(ds_cstr(&name),
pmd_thread_main, pmd);
- ds_destroy(&name);
+ ds_destroy(&name);
VLOG_INFO("PMD thread on numa_id: %d, core id: %2d created.",
pmd->numa_id, pmd->core_id);
changed = true;
@@ -6230,6 +6396,9 @@ dp_netdev_configure_pmd(struct dp_netdev_pmd_thread *pmd, struct dp_netdev *dp,
pmd_perf_stats_init(&pmd->perf_stats);
cmap_insert(&dp->poll_threads, CONST_CAST(struct cmap_node *, &pmd->node),
hash_int(core_id, 0));
+
+ pmd->nmucls = nmucls_init(dp->nmu_config, pmd);
+ pmd->log_timestamp = 0;
}
static void
@@ -6237,6 +6406,7 @@ dp_netdev_destroy_pmd(struct dp_netdev_pmd_thread *pmd)
{
struct dpcls *cls;
+ nmucls_destroy(pmd->nmucls);
dp_netdev_pmd_flow_flush(pmd);
hmap_destroy(&pmd->send_port_cache);
hmap_destroy(&pmd->tnl_port_cache);
@@ -6412,7 +6582,7 @@ dpif_netdev_get_datapath_version(void)
return xstrdup("<built-in>");
}
-static void
+void
dp_netdev_flow_used(struct dp_netdev_flow *netdev_flow, int cnt, int size,
uint16_t tcp_flags, long long now)
{
@@ -6426,13 +6596,15 @@ dp_netdev_flow_used(struct dp_netdev_flow *netdev_flow, int cnt, int size,
atomic_store_relaxed(&netdev_flow->stats.tcp_flags, flags);
}
-static int
+int
dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
struct flow *flow, struct flow_wildcards *wc, ovs_u128 *ufid,
enum dpif_upcall_type type, const struct nlattr *userdata,
- struct ofpbuf *actions, struct ofpbuf *put_actions)
+ struct ofpbuf *actions, struct ofpbuf *put_actions,
+ struct cmpflow_iterator *it)
{
struct dp_netdev *dp = pmd->dp;
+ int retval;
if (OVS_UNLIKELY(!dp->upcall_cb)) {
return ENODEV;
@@ -6463,8 +6635,12 @@ dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_,
ds_destroy(&ds);
}
- return dp->upcall_cb(packet_, flow, ufid, pmd->core_id, type, userdata,
- actions, wc, put_actions, dp->upcall_aux);
+ PERF_START(upcall_time);
+ retval = dp->upcall_cb(packet_, flow, ufid, pmd->core_id, type, userdata,
+ actions, wc, put_actions, dp->upcall_aux, it);
+ PERF_END(upcall_time);
+ pmd_perf_update_counter(&pmd->perf_stats, PMD_TIME_UPCALL, upcall_time);
+ return retval;
}
static inline uint32_t
@@ -6697,6 +6873,7 @@ dfc_processing(struct dp_netdev_pmd_thread *pmd,
pmd_perf_update_counter(&pmd->perf_stats,
md_is_valid ? PMD_STAT_RECIRC : PMD_STAT_RECV,
cnt);
+ pmd_perf_update_counter(&pmd->perf_stats, PMD_DELTA_PACKETS, cnt);
DP_PACKET_BATCH_REFILL_FOR_EACH (i, cnt, packet, packets_) {
struct dp_netdev_flow *flow;
@@ -6805,6 +6982,7 @@ handle_packet_upcall(struct dp_netdev_pmd_thread *pmd,
const struct netdev_flow_key *key,
struct ofpbuf *actions, struct ofpbuf *put_actions)
{
+ struct cmpflow_iterator cmpflow_it;
struct ofpbuf *add_actions;
struct dp_packet_batch b;
struct match match;
@@ -6815,6 +6993,7 @@ handle_packet_upcall(struct dp_netdev_pmd_thread *pmd,