From: Balasubramanian Manoharan <bala.manoha...@linaro.org>

Signed-off-by: Balasubramanian Manoharan <bala.manoha...@linaro.org>
---
/** Email created from pull request 160 (bala-manoharan:api_sched_order_lock)
 ** https://github.com/Linaro/odp/pull/160
 ** Patch: https://github.com/Linaro/odp/pull/160.patch
 ** Base sha: 7fa8e2c97ed18f8dd6e95cbc78b7e668ccb98869
 ** Merge commit sha: eeca3e8f8849d22500b6f87e1304c48f2d417d29
 **/
 platform/linux-generic/include/odp_schedule_if.h       |  1 +
 platform/linux-generic/include/odp_schedule_scalable.h |  1 +
 platform/linux-generic/odp_schedule.c                  | 11 ++++++++++-
 platform/linux-generic/odp_schedule_if.c               |  5 +++++
 platform/linux-generic/odp_schedule_iquery.c           | 11 ++++++++++-
 platform/linux-generic/odp_schedule_scalable.c         |  8 ++++++++
 platform/linux-generic/odp_schedule_sp.c               |  8 +++++++-
 7 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/platform/linux-generic/include/odp_schedule_if.h 
b/platform/linux-generic/include/odp_schedule_if.h
index 657993b13..b0db67ab8 100644
--- a/platform/linux-generic/include/odp_schedule_if.h
+++ b/platform/linux-generic/include/odp_schedule_if.h
@@ -95,6 +95,7 @@ typedef struct {
                                   odp_schedule_group_info_t *);
        void (*schedule_order_lock)(unsigned);
        void (*schedule_order_unlock)(unsigned);
+       void (*schedule_order_unlock_lock)(unsigned);
 
 } schedule_api_t;
 
diff --git a/platform/linux-generic/include/odp_schedule_scalable.h 
b/platform/linux-generic/include/odp_schedule_scalable.h
index 8a2d70da0..41c614975 100644
--- a/platform/linux-generic/include/odp_schedule_scalable.h
+++ b/platform/linux-generic/include/odp_schedule_scalable.h
@@ -113,6 +113,7 @@ typedef struct {
        uint8_t tidx;
        uint8_t pad;
        uint32_t dequeued; /* Number of events dequeued from atomic queue */
+       uint32_t lock_index; /* Index of the acquired ordered lock */
        uint16_t pktin_next; /* Next pktin tag to poll */
        uint16_t pktin_poll_cnts;
        uint16_t ticket; /* Ticket for atomic queue or TICKET_INVALID */
diff --git a/platform/linux-generic/odp_schedule.c 
b/platform/linux-generic/odp_schedule.c
index 5b9407624..27498ddb3 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -163,6 +163,7 @@ typedef struct {
                int stash_num; /**< Number of stashed enqueue operations */
                uint8_t in_order; /**< Order status */
                lock_called_t lock_called; /**< States of ordered locks */
+               uint32_t lock_index; /**< Index of the acquired ordered lock */
                /** Storage for stashed enqueue operations */
                ordered_stash_t stash[MAX_ORDERED_STASH];
        } ordered;
@@ -1121,6 +1122,7 @@ static void schedule_order_lock(unsigned lock_index)
 
                if (lock_seq == sched_local.ordered.ctx) {
                        sched_local.ordered.lock_called.u8[lock_index] = 1;
+                       sched_local.ordered.lock_index = lock_index;
                        return;
                }
                odp_cpu_pause();
@@ -1144,6 +1146,12 @@ static void schedule_order_unlock(unsigned lock_index)
        odp_atomic_store_rel_u64(ord_lock, sched_local.ordered.ctx + 1);
 }
 
+static void schedule_order_unlock_lock(unsigned lock_index)
+{
+       schedule_order_unlock(sched_local.ordered.lock_index);
+       schedule_order_lock(lock_index);
+}
+
 static void schedule_pause(void)
 {
        sched_local.pause = 1;
@@ -1429,5 +1437,6 @@ const schedule_api_t schedule_default_api = {
        .schedule_group_thrmask   = schedule_group_thrmask,
        .schedule_group_info      = schedule_group_info,
        .schedule_order_lock      = schedule_order_lock,
-       .schedule_order_unlock    = schedule_order_unlock
+       .schedule_order_unlock    = schedule_order_unlock,
+       .schedule_order_unlock_lock    = schedule_order_unlock_lock
 };
diff --git a/platform/linux-generic/odp_schedule_if.c 
b/platform/linux-generic/odp_schedule_if.c
index e56e3722b..858c19490 100644
--- a/platform/linux-generic/odp_schedule_if.c
+++ b/platform/linux-generic/odp_schedule_if.c
@@ -129,3 +129,8 @@ void odp_schedule_order_unlock(unsigned lock_index)
 {
        return sched_api->schedule_order_unlock(lock_index);
 }
+
+void odp_schedule_order_unlock_lock(uint32_t lock_index)
+{
+       sched_api->schedule_order_unlock_lock(lock_index);
+}
diff --git a/platform/linux-generic/odp_schedule_iquery.c 
b/platform/linux-generic/odp_schedule_iquery.c
index b81e5dab1..ca30cfd63 100644
--- a/platform/linux-generic/odp_schedule_iquery.c
+++ b/platform/linux-generic/odp_schedule_iquery.c
@@ -223,6 +223,7 @@ struct sched_thread_local {
                int stash_num; /**< Number of stashed enqueue operations */
                uint8_t in_order; /**< Order status */
                lock_called_t lock_called; /**< States of ordered locks */
+               uint32_t lock_index; /**< Index of the acquired ordered lock */
                /** Storage for stashed enqueue operations */
                ordered_stash_t stash[MAX_ORDERED_STASH];
        } ordered;
@@ -1273,6 +1274,7 @@ static void schedule_order_lock(unsigned lock_index)
 
                if (lock_seq == thread_local.ordered.ctx) {
                        thread_local.ordered.lock_called.u8[lock_index] = 1;
+                       thread_local.ordered.lock_index = lock_index;
                        return;
                }
                odp_cpu_pause();
@@ -1296,6 +1298,12 @@ static void schedule_order_unlock(unsigned lock_index)
        odp_atomic_store_rel_u64(ord_lock, thread_local.ordered.ctx + 1);
 }
 
+static void schedule_order_unlock_lock(unsigned lock_index)
+{
+       schedule_order_unlock(thread_local.ordered.lock_index);
+       schedule_order_lock(lock_index);
+}
+
 static unsigned schedule_max_ordered_locks(void)
 {
        return CONFIG_QUEUE_MAX_ORD_LOCKS;
@@ -1368,7 +1376,8 @@ const schedule_api_t schedule_iquery_api = {
        .schedule_group_thrmask   = schedule_group_thrmask,
        .schedule_group_info      = schedule_group_info,
        .schedule_order_lock      = schedule_order_lock,
-       .schedule_order_unlock    = schedule_order_unlock
+       .schedule_order_unlock    = schedule_order_unlock,
+       .schedule_order_unlock_lock    = schedule_order_unlock_lock
 };
 
 static void thread_set_interest(sched_thread_local_t *thread,
diff --git a/platform/linux-generic/odp_schedule_scalable.c 
b/platform/linux-generic/odp_schedule_scalable.c
index 765326e8e..b714792f1 100644
--- a/platform/linux-generic/odp_schedule_scalable.c
+++ b/platform/linux-generic/odp_schedule_scalable.c
@@ -1008,6 +1008,7 @@ static void schedule_order_lock(unsigned lock_index)
                                 __ATOMIC_ACQUIRE) != rctx->sn)
                        doze();
        }
+       sched_ts->lock_index = lock_index;
 }
 
 static void schedule_order_unlock(unsigned lock_index)
@@ -1028,6 +1029,12 @@ static void schedule_order_unlock(unsigned lock_index)
        rctx->olock_flags |= 1U << lock_index;
 }
 
+static void schedule_order_unlock_lock(unsigned lock_index)
+{
+       schedule_order_unlock(sched_ts->lock_index);
+       schedule_order_lock(lock_index);
+}
+
 static void schedule_release_atomic(void)
 {
        sched_scalable_thread_state_t *ts;
@@ -1978,4 +1985,5 @@ const schedule_api_t schedule_scalable_api = {
        .schedule_group_info            = schedule_group_info,
        .schedule_order_lock            = schedule_order_lock,
        .schedule_order_unlock          = schedule_order_unlock,
+       .schedule_order_unlock_lock     = schedule_order_unlock_lock,
 };
diff --git a/platform/linux-generic/odp_schedule_sp.c 
b/platform/linux-generic/odp_schedule_sp.c
index 05241275d..d4dfbcaf0 100644
--- a/platform/linux-generic/odp_schedule_sp.c
+++ b/platform/linux-generic/odp_schedule_sp.c
@@ -819,6 +819,11 @@ static void schedule_order_unlock(unsigned lock_index)
        (void)lock_index;
 }
 
+static void schedule_order_unlock_lock(unsigned lock_index)
+{
+       (void)lock_index;
+}
+
 static void order_lock(void)
 {
 }
@@ -868,5 +873,6 @@ const schedule_api_t schedule_sp_api = {
        .schedule_group_thrmask   = schedule_group_thrmask,
        .schedule_group_info      = schedule_group_info,
        .schedule_order_lock      = schedule_order_lock,
-       .schedule_order_unlock    = schedule_order_unlock
+       .schedule_order_unlock    = schedule_order_unlock,
+       .schedule_order_unlock_lock     = schedule_order_unlock_lock
 };

Reply via email to