[ovs-dev] [PATCH 11/15] datapath-windows: Add RefCount.h

Nithin Raju nithin at vmware.com
Sat Aug 16 04:50:11 UTC 2014

On Aug 6, 2014, at 9:14 AM, Samuel Ghinet <sghinet at cloudbasesolutions.com> wrote:

> How it works:
> Say we have a list of OVS_FLOWs, where OVS_FLOW uses OVS_REF_COUNT.
> * The OVS_REF_COUNT must be initialized to 0 at object creation.
> * Assign a destruction function to the func ptr "Destroy" of OVS_REF_COUNT.
> * When you need to retrieve a ptr to an OVS_FLOW, from the list, you must do the following:
> *** lock the OVS_FLOW list for read (obviously)
> *** do the lookup: a ptr to an existing OVS_FLOW, pFlow, is found.
> *** call "OVS_REFCOUNT_REFERENCE(pFlow);" - by doing so, you deny destruction of pFlow, while the object
> is referenced, ensuring that you keep a valid pointer to a flow.
> *** unlock the list
> *** return pFlow.
> * When you need to modify fields in the pFlow, use the rw lock / spinlock field of pFlow.
> * When you no longer need the ptr, use "OVS_REFCOUNT_DEREFERENCE(pFlow);"
> * When you need to do deferred deletion, call "OVS_REFCOUNT_DESTROY(pFlow);": this will
> mark the pFlow for deletion. If the object is not referenced, it will be destroyed immediately. Otherwise,
> it will be destroyed when the refCount = 0.

This is what I have in mind on how the workflow should look like. Nothing fancy, just a standard way of doing ref counting:

Context #1: packet processing context
1. Lock Flowtable (read)
2. pFlow = FlowLookup()
   * This one checks if the flag on the flow is ACTIVE
   * Increment the refcount on the flow
3. Unlock Flowtable
4. Process the packet using the flow
5. Lock Flowtable (write)
6. Decrement the refcount on the flow. 
   * if the new refcount == 0, cleanup the flow by deleting it from the flowable.
7. Unblock Flowtable.

Context #2: flow put context
1. Lock Flowtable (write)
2. Decrement the refcount on the flow:
   * if new refcount is 0, cleanup the flow by deleting it from the flowable.
   * if new refcount is 1, mark the flag on the flow as INACTIVE
3. Unblock Flowtable.

This is a very simple usage of refcounting. Once we agree on this, we can work out the API specifics etc.

Pls. let me know if you have other ideas.


More information about the dev mailing list