tests: Fix race condition waiting for monitor thread.

Occasionally, test #770 "ofproto-dpif - ofproto-dpif-monitor 1" would
fail, because the testsuite looked in the logs for evidence of a thread
being created, but it checked before vswitchd was able to spawn the
thread.

This patch fixes the race by modifying the commands that check for
creation/termination of threads to wait until they see the messages
instead.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
ofproto-dpif: Use sequence number to wake up main thread for
packet-in I/O.

This commit adds per 'struct ofproto_dpif' sequence number for
packet-in I/O.  Whenever ofproto_dpif_send_packet_in() is called,
the calling thread will change the sequence number to wake up the
main thread.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
bridge: Refactor the 'Instant' stats logic.

This commit refactors the 'Instant' stats related logic in bridge.c
by moving it into bridge_run().

This change brings the following effects:

1. bridge.c will wait on the global connectivity sequence number when
   there is no pending instant stats transaction.  and the main thread
   will no longer be waken up every 100 ms for 'Instant' stats check.
   the related overhead is eliminated.

2. the netdev's sequence number is used to avoid updating unchanged netdev
   status.  so, the update is more efficient.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
Python Logging Formatting Improvements

The Open vSwitch daemons written in C support user-configured logging
patterns as described in ovs-appctl(8). This commit adds this capability
to the daemons written in Python.

- Add a '__log_patterns' attribute to the Vlog class
- Populate this using the default patterns in ovs-appctl(8)
- Add a '__start_time' attribute to the Vlog class to support '%r'
- Update the '_log' method to build the log message according to the
  pattern
- Add a 'set_pattern' method to allow the default patterns to be changed
- Update 'set_levels_from_string' to support setting the pattern from a
  string

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath: Check for backported skb_orphan_frags().

This was causing build failures on debian wheezy. Check for the feature
rather than the version.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
timeval: Preserve quiescence across time_poll().

Otherwise ovsrcu_synchronize() busy-waits in its loop because its
poll_block() un-quiesces, causing the global_seqno to increase, which is
what it waits for.

Reported-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
ovs-thread: Quiesce in xpthread_barrier_wait().

Otherwise the udpif revalidator threads can postpone RCU callbacks
essentially forever, especially if there are many revalidator threads and
little network traffic.

Reported-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
ovs-thread: Make caller provide thread name when creating a thread.

Thread names are occasionally very useful for debugging, but from time to
time we've forgotten to set one.  This commit adds the new thread's name
as a parameter to the function to start a thread, to make that mistake
impossible.  This also simplifies code, since two function calls become
only one.

This makes a few other changes to the thread creation function:

    * Since it is no longer a direct wrapper around a pthread function,
      rename it to avoid giving that impression.

    * Remove 'pthread_attr_t *' param that every caller supplied as NULL.

    * Change 'pthread *' parameter into a return value, for convenience.

The system-stats code hadn't set a thread name, so this fixes that issue.

This patch is a prerequisite for making RCU report the name of a thread
that is blocking RCU synchronization, because the easiest way to do that is
for ovsrcu_quiesce_end() to record the current thread's name.
ovsrcu_quiesce_end() is called before the thread function is called, so it
won't get a name set within the thread function itself.  Setting the thread
name earlier, as in this patch, avoids the problem.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
ovs-rcu: Log a helpful warning when ovsrcu_synchronize() stalls.

This made it easier for me to find a thread that was causing stalls.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
Prepare for 2.2.0.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
Prepare for post-2.2.0 (2.2.90).

Signed-off-by: Justin Pettit <jpettit@nicira.com>
lacp: Don't lock potentially uninitialized mutex in lacp_status().

If the 'lacp' parameter is nonnull, then we know that the file scope mutex
has been initialized, since that's done as a side effect of creating a
lacp object, but otherwise there's no guarantee.

Signed-off-by: Ben Pfaff <blp@nicira.com>
ovs-thread: Add checking for mutex and rwlock initialization.

With glibc, a mutex or rwlock filled with all-zero-bytes is properly
initialized for use, but this is not true for any other libc that OVS
supports.  However, OVS gets a lot more testing with glibc than any other
libc.  This means that developers keep introducing bugs that do not
manifest on the main development platform.

This commit should help avoid the problem, by reusing the existing 'where'
members to indicate whether a mutex or rwlock has been initialized.

Signed-off-by: Ben Pfaff <blp@nicira.com>
tests: Fix up "ofproto-dpif - ofproto-dpif-monitor 1".

Commit 1335a8d578b03e (tests: Fix race condition waiting for monitor
thread.) fixed a race condition in a test.  Commit 8ba0a5227f6 (ovs-thread:
Make caller provide thread name when creating a thread.) slightly changed
the output that the test checked, breaking the test.  However, I was used
to the test occasionally failing due to the race (not realizing that the
race had been fixed) so I applied the commit anyway.

This commit fixes the broken test.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
lib/ofp-actions: Update comment.

We recently renamed ofpbuf's 'l2' member as 'frame'.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
openvswitch.h: Note that 64 bit ints are 4-aligned.

In general, all Netlink 64-bit data may be 4-byte aligned, due to
netlink header and attributes being 4-aligned.

To avoid unaligned access the data should be copied out of the netlink
attribute before access.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
lib/odp-util: Remove extra parenthesis from sctp key output.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
openvswitch.h: Clarify use of key attributes.

Key attributes relating to actual packet headers are ignored for
OVS_PACKET_CMD_EXECUTE as the header key attributes are retrieved
from the packet itself.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
ofproto-bond: do not allow recirculation when we failed to allocate recirc_id

When recirc pool is exhausted, a new bond won't be allocate a new
recirc_id. The bond->recirc_id will remain zero. This condition
should prevent the bond from use recirculation. This check was missing
before this patch.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto-dpif: restore bond rebalance for non-recirc bond

Bond rebalancing was disabled for bonds not using recirculation. The
patch fixes this bug.

While fixing the bug, the bond_rebalance() was also restructured
slightly to move bond related logic back into ofproto/bond.c

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>