diff mbox

[API-NEXT,PATCHv7,13/13] linux-generic: schedule: implement odp_schedule_order_sync()

Message ID 1438728085-3240-14-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Aug. 4, 2015, 10:41 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 platform/linux-generic/include/odp_queue_internal.h |  2 +-
 platform/linux-generic/odp_queue.c                  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Bill Fischofer Aug. 4, 2015, 10:48 p.m. UTC | #1
On Tue, Aug 4, 2015 at 5:41 PM, Bill Fischofer <bill.fischofer@linaro.org>
wrote:

> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> ---
>  platform/linux-generic/include/odp_queue_internal.h |  2 +-
>  platform/linux-generic/odp_queue.c                  | 17 +++++++++++++++++
>  2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/platform/linux-generic/include/odp_queue_internal.h
> b/platform/linux-generic/include/odp_queue_internal.h
> index 9cca552..0f7e3ba 100644
> --- a/platform/linux-generic/include/odp_queue_internal.h
> +++ b/platform/linux-generic/include/odp_queue_internal.h
> @@ -78,7 +78,7 @@ struct queue_entry_s {
>         odp_pktio_t       pktout;
>         char              name[ODP_QUEUE_NAME_LEN];
>         uint64_t          order_in;
> -       uint64_t          order_out;
> +       volatile uint64_t order_out;    /* May be observed unlocked */
>

Checkpatch flags this, but this seems to be proper use of volatile here.
 odp_schedule_order_sync() observes this value without locking the qentry.
It doesn't require "atomic" access.  Rather it just needs to tell the
compiler to not cache this variable in registers since it may be updated
elsewhere--precisely what volatile is designed to communicate.


>         odp_buffer_hdr_t *reorder_head;
>         odp_buffer_hdr_t *reorder_tail;
>  };
> diff --git a/platform/linux-generic/odp_queue.c
> b/platform/linux-generic/odp_queue.c
> index e92ef57..cfae99b 100644
> --- a/platform/linux-generic/odp_queue.c
> +++ b/platform/linux-generic/odp_queue.c
> @@ -22,6 +22,7 @@
>  #include <odp_debug_internal.h>
>  #include <odp/hints.h>
>  #include <odp/sync.h>
> +#include <odp_spin_internal.h>
>
>  #ifdef USE_TICKETLOCK
>  #include <odp/ticketlock.h>
> @@ -922,3 +923,19 @@ int odp_schedule_order_copy(odp_event_t src_event,
> odp_event_t dst_event)
>         UNLOCK(&origin_qe->s.lock);
>         return 0;
>  }
> +
> +int odp_schedule_order_sync(odp_event_t ev)
> +{
> +       odp_buffer_hdr_t *buf_hdr =
> odp_buf_to_hdr(odp_buffer_from_event(ev));
> +       queue_entry_t *origin_qe = buf_hdr->origin_qe;
> +
> +       /* Can't lock if we didn't originate from an ordered queue */
> +       if (!origin_qe)
> +               return -1;
> +
> +       /* Wait until we are in order */
> +       while (buf_hdr->order > origin_qe->s.order_out)
> +               odp_spin();
> +
> +       return 0;
> +}
> --
> 2.1.4
>
>
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_queue_internal.h b/platform/linux-generic/include/odp_queue_internal.h
index 9cca552..0f7e3ba 100644
--- a/platform/linux-generic/include/odp_queue_internal.h
+++ b/platform/linux-generic/include/odp_queue_internal.h
@@ -78,7 +78,7 @@  struct queue_entry_s {
 	odp_pktio_t       pktout;
 	char              name[ODP_QUEUE_NAME_LEN];
 	uint64_t          order_in;
-	uint64_t          order_out;
+	volatile uint64_t order_out;    /* May be observed unlocked */
 	odp_buffer_hdr_t *reorder_head;
 	odp_buffer_hdr_t *reorder_tail;
 };
diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
index e92ef57..cfae99b 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -22,6 +22,7 @@ 
 #include <odp_debug_internal.h>
 #include <odp/hints.h>
 #include <odp/sync.h>
+#include <odp_spin_internal.h>
 
 #ifdef USE_TICKETLOCK
 #include <odp/ticketlock.h>
@@ -922,3 +923,19 @@  int odp_schedule_order_copy(odp_event_t src_event, odp_event_t dst_event)
 	UNLOCK(&origin_qe->s.lock);
 	return 0;
 }
+
+int odp_schedule_order_sync(odp_event_t ev)
+{
+	odp_buffer_hdr_t *buf_hdr = odp_buf_to_hdr(odp_buffer_from_event(ev));
+	queue_entry_t *origin_qe = buf_hdr->origin_qe;
+
+	/* Can't lock if we didn't originate from an ordered queue */
+	if (!origin_qe)
+		return -1;
+
+	/* Wait until we are in order */
+	while (buf_hdr->order > origin_qe->s.order_out)
+		odp_spin();
+
+	return 0;
+}