The number of supported ordered locks may vary between the scheduler
implementations. Add an internal scheduler API call for fetching the
maximum value from currently active scheduler.

Add an internal definition CONFIG_QUEUE_MAX_ORD_LOCKS for the scheduler
independent maximum value.

Signed-off-by: Matias Elo <matias....@nokia.com>
---
 platform/linux-generic/include/odp_config_internal.h |  5 +++++
 platform/linux-generic/include/odp_schedule_if.h     |  8 ++------
 platform/linux-generic/odp_queue.c                   |  5 ++---
 platform/linux-generic/odp_schedule.c                | 14 +++++++++++++-
 platform/linux-generic/odp_schedule_sp.c             | 12 +++++++++++-
 5 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/platform/linux-generic/include/odp_config_internal.h 
b/platform/linux-generic/include/odp_config_internal.h
index 8818cda..c494660 100644
--- a/platform/linux-generic/include/odp_config_internal.h
+++ b/platform/linux-generic/include/odp_config_internal.h
@@ -22,6 +22,11 @@ extern "C" {
 #define ODP_CONFIG_QUEUES 1024
 
 /*
+ * Maximum number of ordered locks per queue
+ */
+#define CONFIG_QUEUE_MAX_ORD_LOCKS 4
+
+/*
  * Maximum number of packet IO resources
  */
 #define ODP_CONFIG_PKTIO_ENTRIES 64
diff --git a/platform/linux-generic/include/odp_schedule_if.h 
b/platform/linux-generic/include/odp_schedule_if.h
index 72af01e..6c2b050 100644
--- a/platform/linux-generic/include/odp_schedule_if.h
+++ b/platform/linux-generic/include/odp_schedule_if.h
@@ -14,12 +14,6 @@ extern "C" {
 #include <odp/api/queue.h>
 #include <odp/api/schedule.h>
 
-/* Constants defined by the scheduler. These should be converted into interface
- * functions. */
-
-/* Number of ordered locks per queue */
-#define SCHEDULE_ORDERED_LOCKS_PER_QUEUE 2
-
 typedef void (*schedule_pktio_start_fn_t)(int pktio_index, int num_in_queue,
                                          int in_queue_idx[]);
 typedef int (*schedule_thr_add_fn_t)(odp_schedule_group_t group, int thr);
@@ -38,6 +32,7 @@ typedef int (*schedule_init_local_fn_t)(void);
 typedef int (*schedule_term_local_fn_t)(void);
 typedef void (*schedule_order_lock_fn_t)(void);
 typedef void (*schedule_order_unlock_fn_t)(void);
+typedef unsigned (*schedule_max_ordered_locks_fn_t)(void);
 
 typedef struct schedule_fn_t {
        schedule_pktio_start_fn_t   pktio_start;
@@ -54,6 +49,7 @@ typedef struct schedule_fn_t {
        schedule_term_local_fn_t    term_local;
        schedule_order_lock_fn_t    order_lock;
        schedule_order_unlock_fn_t  order_unlock;
+       schedule_max_ordered_locks_fn_t max_ordered_locks;
 } schedule_fn_t;
 
 /* Interface towards the scheduler */
diff --git a/platform/linux-generic/odp_queue.c 
b/platform/linux-generic/odp_queue.c
index 74f384d..99c91e7 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -70,8 +70,7 @@ static int queue_init(queue_entry_t *queue, const char *name,
                queue->s.name[ODP_QUEUE_NAME_LEN - 1] = 0;
        }
        memcpy(&queue->s.param, param, sizeof(odp_queue_param_t));
-       if (queue->s.param.sched.lock_count >
-           SCHEDULE_ORDERED_LOCKS_PER_QUEUE)
+       if (queue->s.param.sched.lock_count > sched_fn->max_ordered_locks())
                return -1;
 
        if (param->type == ODP_QUEUE_TYPE_SCHED)
@@ -162,7 +161,7 @@ int odp_queue_capability(odp_queue_capability_t *capa)
 
        /* Reserve some queues for internal use */
        capa->max_queues        = ODP_CONFIG_QUEUES - NUM_INTERNAL_QUEUES;
-       capa->max_ordered_locks = SCHEDULE_ORDERED_LOCKS_PER_QUEUE;
+       capa->max_ordered_locks = sched_fn->max_ordered_locks();
        capa->max_sched_groups  = sched_fn->num_grps();
        capa->sched_prios       = odp_schedule_num_prio();
 
diff --git a/platform/linux-generic/odp_schedule.c 
b/platform/linux-generic/odp_schedule.c
index 50639ff..5bc274f 100644
--- a/platform/linux-generic/odp_schedule.c
+++ b/platform/linux-generic/odp_schedule.c
@@ -110,6 +110,12 @@ ODP_STATIC_ASSERT((8 * sizeof(pri_mask_t)) >= 
QUEUES_PER_PRIO,
 /* Maximum number of dequeues */
 #define MAX_DEQ CONFIG_BURST_SIZE
 
+/* Maximum number of ordered locks per queue */
+#define MAX_ORDERED_LOCKS_PER_QUEUE 1
+
+ODP_STATIC_ASSERT(MAX_ORDERED_LOCKS_PER_QUEUE <= CONFIG_QUEUE_MAX_ORD_LOCKS,
+                 "Too_many_ordered_locks");
+
 /* Scheduler local data */
 typedef struct {
        int thr;
@@ -323,6 +329,11 @@ static int schedule_term_local(void)
        return 0;
 }
 
+static unsigned schedule_max_ordered_locks(void)
+{
+       return MAX_ORDERED_LOCKS_PER_QUEUE;
+}
+
 static inline int queue_per_prio(uint32_t queue_index)
 {
        return ((QUEUES_PER_PRIO - 1) & queue_index);
@@ -1026,7 +1037,8 @@ const schedule_fn_t schedule_default_fn = {
        .init_local  = schedule_init_local,
        .term_local  = schedule_term_local,
        .order_lock = order_lock,
-       .order_unlock = order_unlock
+       .order_unlock = order_unlock,
+       .max_ordered_locks = schedule_max_ordered_locks
 };
 
 /* Fill in scheduler API calls */
diff --git a/platform/linux-generic/odp_schedule_sp.c 
b/platform/linux-generic/odp_schedule_sp.c
index 069b8bf..76d1357 100644
--- a/platform/linux-generic/odp_schedule_sp.c
+++ b/platform/linux-generic/odp_schedule_sp.c
@@ -28,6 +28,10 @@
 #define GROUP_ALL         ODP_SCHED_GROUP_ALL
 #define GROUP_WORKER      ODP_SCHED_GROUP_WORKER
 #define GROUP_CONTROL     ODP_SCHED_GROUP_CONTROL
+#define MAX_ORDERED_LOCKS_PER_QUEUE 1
+
+ODP_STATIC_ASSERT(MAX_ORDERED_LOCKS_PER_QUEUE <= CONFIG_QUEUE_MAX_ORD_LOCKS,
+                 "Too_many_ordered_locks");
 
 struct sched_cmd_t;
 
@@ -162,6 +166,11 @@ static int term_local(void)
        return 0;
 }
 
+static unsigned max_ordered_locks(void)
+{
+       return MAX_ORDERED_LOCKS_PER_QUEUE;
+}
+
 static int thr_add(odp_schedule_group_t group, int thr)
 {
        sched_group_t *sched_group = &sched_global.sched_group;
@@ -682,7 +691,8 @@ const schedule_fn_t schedule_sp_fn = {
        .init_local    = init_local,
        .term_local    = term_local,
        .order_lock =    order_lock,
-       .order_unlock =  order_unlock
+       .order_unlock =  order_unlock,
+       .max_ordered_locks = max_ordered_locks
 };
 
 /* Fill in scheduler API calls */
-- 
2.7.4

Reply via email to