dpif-linux: Fix a bug in creating port.

Based on the policy of 'OVS_VPORT_ATTR_UPCALL_PID', if upcall should
not be sent to userspace (i.e. the number of handler threads is zero),
the netlink message for creating vport should be an one-element array of
value 0.  However, dpif_linux_port_add__() fails to obey it and generates
zero-payload netlink message which causes the netlink transaction failing
with ERANGE error.

This is particularly bad when the 'flow-restore-wait' is set during upgrade,
since number of handler threads is not set in dpif-linux module and ovs is
not able to add port in datapath until the 'flow-restore-wait' is disabled.
Connection may lose due to this bug.

This bug was introduced by commit 1579cf677fc (dpif-linux: Implement the
API functions to allow multiple handler threads read upcall.).

This commit fixes the bug by fixing the dpif_linux_port_add__() to generate
the correct netlink message when the number of handler threads is not set.

Bug #1239914.
Bug #1240598.
Bug #1240626.

Reported-by: Gurucharan Shetty <gshetty@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
netdev: Fix an use of uninitialized mutex.

Commit 05bf6d3c62e1d (ovs-thread: Add checking for mutex and
rwlock initialization.) helps find an use of uninitialized
mutex (netdev_class_mutex) during upgrade.  The assertion
check aborts the ovs.

This commit fixes the issue by adding the proper initialization.

Bug #1239914.
Bug #1240598.
Bug #1240626.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
datapath: Move table destroy to dp-rcu callback.

Ths simplifies flow-table-destroy API.  This change is required
for following patches.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Thomas Graf <tgraf@redhat.com>
datapath: Add flow mask cache.

On every packet OVS needs to lookup flow-table with every mask
until it finds a match. The packet flow-key is first masked
with mask in the list and then the masked key is looked up in
flow-table.  Therefore number of masks can affect packet
processing performance.

Following patch adds mask index to mask cache from last
pakcet lookup in same flow.  Index of mask is stored in
this cache. This cache is searched by 5 tuple hash (skb rxhash).

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Thomas Graf <tgraf@redhat.com>
datapath: Convert mask list in mask array.

mask caches index of mask in mask_list.  On packet recv OVS
need to traverse mask-list to get cached mask.  Therefore array
is better for retrieving cached mask.  This also allows better
cache replacement algorithm by directly checking mask's existence.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Thomas Graf <tgraf@redhat.com>
ofp-version-opt: Fix spelling and capitalization.

"OpenFlow" is one word.
"Version" isn't a proper noun.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
tests: Whitelist messages about RCU blocking in the testsuite.

In production these may indicate a bug, but in the testsuite they probably
just indicate a time-warp.

Reported-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
ovs-rcu: Log the name of the main thread as "main" instead of "".

The main thread has the empty string as its name, but that's not a good
log string.

Without this patch we can get log message like
    blocked 1000 ms waiting for  to quiesce
from ovsrcu_synchronize().

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
ofproto: Inline actions in struct rule_actions.

Allocate struct rule_actions and the space for the actions at once.
This reduces one memory indirection and helps reduce cache misses
visible in perf annotations.

Fix some old comments referring to ref count, since we now use RCU for
this.

Enforce constness of the actions that are assigned from rule_actions
throughout the code.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto: Inline trivial functions.

rule_dpif_is_internal is among the top ten OVS internal functions in
recent perf reports.  Inline it and some other equally trivial
functions.

This change removes rule_is_internal(), since the fact that a table is
an internal one is defined within ofproto-dpif, not ofproto.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/flow: Simplify miniflow accessors, add ipv6 support.

Add new macro MINIFLOW_MAP(FIELD) that returns the map covering the
given struct flow field.

Change the miniflow accessors to macros so that they can take the
field name directly.

Use these to add ipv6 support to miniflow_hash_5tuple().

Add ipv6 support to flow_hash_5tuple() as well so that these two
functions continue to return the same hash value for the corresponding
flows.

Also, simplify miniflow_get_metadata().

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib: Inline functions used in classifier_lookup.

This helps about 1% in TCP_CRR performance test.  However, this also
helps by clearly showing the classifier_lookup() cost in perf reports
as one item.

This also cleans up the flow/match APIs from functionality only used
by the classifier, making is more straightforward to evolve them
later.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
ofproto: Use classifer cursor API to collect vlan usage.

This was the only place in OVS code that accessed classifier internal
data structures directly.  Use the classifier cursor API instead, so
that following patches can hide classifier internal data structures.

Note: There seems to be no test case to verify that this vlan usage
collection is implemented correctly.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/classifier: Hide more of the internal data structures.

It is better not to expose definitions not needed by users.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/flow: Optimize minimask_has_extra() and minimask_is_catchall()

We only need to iterate over the bits masked by the 'b' in
minimask_has_extra(), since for zeroes in 'b' there can be no 'extra'
wildcards in 'a', as 'b' has already wildcarded all the bits.

minimask_is_catchall() can be simplified by the invariant that mask's
map never has 1-bits for all-zero values.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib: Add prefetch support (for GCC)

Define OVS_PREFETCH() and OVS_PREFETCH_WRITE() using builtin prefetch
for GCC, and ovs_prefetch_range() for prefetching a range of addresses.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
classifier: Use array for subtables instead of a list.

Using a linear array allows more efficient memory access for lookups.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/classifier: Separate cls_rule internals from the API.

Keep an internal representation of a rule separate from the one
embedded into user's structs.  This allows for further memory
optimization in the classifier.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/flow: Maintain miniflow offline values explicitly.

This allows use of miniflows that have all of their values inline.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/classifier: Support variable sized miniflows.

Change the classifier to allocate variable sized miniflows and
minimasks in cls_match and cls_subtable, respectively.  Do not
duplicate the mask in cls_rule any more.

miniflow_clone and miniflow_move can now take variably sized miniflows
as source.  The destination is assumed to be regularly sized miniflow.

Inlining miniflow and mask values reduces memory indirection and helps
reduce cache misses.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>