summaryrefslogtreecommitdiff
path: root/lib/pvector.h
Commit message (Collapse)AuthorAgeFilesLines
* pvector: Document that multiple elements with a given priority are allowed.Ben Pfaff2020-05-271-4/+6
| | | | | Acked-by: Greg Rose <gvrose8192@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* pvector: Use acquire-release semantics for size.Yanqin Wei2020-03-151-4/+9
| | | | | | | | | | | | | | | | | | | | Read/write concurrency of pvector library is implemented by a temp vector and RCU protection. Considering performance reason, insertion does not follow this scheme. In insertion function, a thread fence ensures size increment is done after new entry is stored. But there is no barrier in the iteration fuction(pvector_cursor_init). Entry point access may be reordered before loading vector size, so the invalid entry point may be loaded when vector iteration. This patch fixes it by acquire-release pair. It can guarantee new size is observed by reader after new entry stored by writer. And this is implemented by one-way barrier instead of two-way memory fence. Fixes: fe7cfa5c3f19 ("lib/pvector: Non-intrusive RCU priority vector.") Reviewed-by: Gavin Hu <Gavin.Hu@arm.com> Reviewed-by: Lijian Zhang <Lijian.Zhang@arm.com> Signed-off-by: Yanqin Wei <Yanqin.Wei@arm.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* pvector: Document the entry destruction policy.Ilya Maximets2019-04-151-0/+7
| | | | | | | This describes how to safely destroy pvector entries after removal. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Revert "pvector: Expose non-concurrent priority vector."Jarno Rajahalme2016-08-101-127/+60
| | | | | | | | | | | | | | | This reverts commit 8bdfe1313894047d44349fa4cf4402970865950f. I failed to see that lib/dpif-netdev.c actually needs the concurrency provided by pvector prior to this change. More specifically, when a subtable is removed, concurrent lookups may skip over another subtable swapped in to the place of the removed subtable in the vector. Since this was the only use of the non-concurrent pvector, it is cleaner to revert the whole patch. Reported-by: Jan Scheurich <jan.scheurich@ericsson.com> Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Daniele Di Proietto <diproiettod@vmware.com>
* pvector: Expose non-concurrent priority vector.Jarno Rajahalme2016-07-291-60/+127
| | | | | | | | | | | | PMD threads use pvectors but do not need the overhead of the concurrent version. Expose the non-concurrent version for that use. Note that struct pvector is renamed as struct cpvector (for concurrent priority vector), and the former struct pvector_impl is now struct pvector. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* pvector: Get rid of special purpose of INT_MIN.Jarno Rajahalme2016-07-291-8/+6
| | | | | | | | | Allow clients to use the whole priority range. Note that this changes the semantics of PVECTOR_FOR_EACH_PRIORITY so that the iteration still continues for entries at the given priority. Suggested-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* pvector: Move PVECTOR_EXTRA_ALLOC to pvector.c.Jarno Rajahalme2016-07-291-5/+1
| | | | | | | There is no need to expose PVECTOR_EXTRA_ALLOC in the API. Suggested-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* classifier: Defer pvector publication.Jarno Rajahalme2014-11-141-5/+27
| | | | | | | | | | | | | | | | | | | | | | | | This patch adds a new functions classifier_defer() and classifier_publish(), which control when the classifier modifications are made available to lookups. By default, all modifications are made available to lookups immediately. Modifications made after a classifier_defer() call MAY be 'deferred' for later 'publication'. A call to classifier_publish() will both publish any deferred modifications, and cause subsequent changes to to be published immediately. Currently any deferring is limited to the visibility of the subtable vector changes. pvector now processes modifications mostly in a working copy, which needs to be explicitly published with pvector_publish(). pvector_publish() sorts the working copy and removes gaps before publishing it. This change helps avoiding O(n**2) memory behavior in corner cases, where large number of rules with different masks are inserted or deleted. VMware-BZ: #1322017 Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* classifier: Lockless and robust classifier iteration.Jarno Rajahalme2014-11-141-0/+7
| | | | | | | | | | | | | | | | | | | | | | | Previously, accurate iteration required writers to be excluded during iteration. This patch adds an rculist to struct cls_subtable, and a corresponding list node to struct cls_rule, which makes iteration more straightforward, and allows the iterators to remain ignorant of the internals of the cls_match. This new list allows iteration of rules in the classifier by traversing the RCU-friendly subtables vector, and the rculist of rules in each subtable. Classifier modifications may be performed concurrently, but whether or not the concurrent iterator sees those changes depends on the timing of change. More specifically, an concurrent iterator: - May or may not see a rule that is being inserted or removed. - Will see either the new or the old version of a rule that is replaced. - Will see all the other rules (that are not being modified). Finally, The subtable's rculist also allows to make classifier_rule_overlaps() lockless, which this patch also does. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* classifier: Change type used for priorities from 'unsigned int' to 'int'.Ben Pfaff2014-10-301-6/+8
| | | | | | | | | | | | | | | | OpenFlow has priorities in the 16-bit unsigned range, from 0 to 65535. In the classifier, it is sometimes useful to be able to have values below and above this range. With the 'unsigned int' type used for priorities until now, there were no values below the range, so some code worked around it by converting priorities to 64-bit signed integers. This didn't seem so great to me given that a plain 'int' also had the needed range. This commit therefore changes the type used for priorities to int. The interesting parts of this change are in pvector.h and classifier.c, where one can see the elimination of the use of int64_t. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* lib/pvector: Non-intrusive RCU priority vector.Jarno Rajahalme2014-06-261-0/+210
Factor out the priority vector code from the classifier. Making the classifier use RCU instead of locking requires parallel access to the priority vector, pointing to subtables in descending priority order. When a new subtable is added, a new copy of the priority vector is allocated, while the current readers can keep on using the old copy they started with. Adding and removing subtables is usually less frequent than adding and removing rules, so this should not have a visible performance implication. As an optimization for the userspace datapath use, where all the subtables have the same priority, new subtables can be added to the end of the vector without reallocation and without disturbing readers. cls_subtables_reset() is now removed, as it served its purpose in bug hunting. Checks on the new pvector are now incorporated into tests/test-classifier.c. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>