diff mbox

[v3,4/4] performance: odp_scheduling: use multi alloc/free buffer functions

Message ID 1469181897-19168-4-git-send-email-matias.elo@nokia.com
State New
Headers show

Commit Message

Elo, Matias (Nokia - FI/Espoo) July 22, 2016, 10:04 a.m. UTC
Use odp_buffer_alloc_multi() and odp_buffer_free_multi() functions where
appropriate for improved performance.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 test/common_plat/performance/odp_scheduling.c | 50 ++++++++++++++++++---------
 1 file changed, 33 insertions(+), 17 deletions(-)

-- 
2.7.4

Comments

Bill Fischofer July 26, 2016, 12:14 a.m. UTC | #1
On Fri, Jul 22, 2016 at 5:04 AM, Matias Elo <matias.elo@nokia.com> wrote:

> Use odp_buffer_alloc_multi() and odp_buffer_free_multi() functions where

> appropriate for improved performance.

>

> Signed-off-by: Matias Elo <matias.elo@nokia.com>

> ---

>  test/common_plat/performance/odp_scheduling.c | 50

> ++++++++++++++++++---------

>  1 file changed, 33 insertions(+), 17 deletions(-)

>

> diff --git a/test/common_plat/performance/odp_scheduling.c

> b/test/common_plat/performance/odp_scheduling.c

> index 5a2997f..1d1bf01 100644

> --- a/test/common_plat/performance/odp_scheduling.c

> +++ b/test/common_plat/performance/odp_scheduling.c

> @@ -29,7 +29,7 @@

>  #include <getopt.h>

>

>  #define MSG_POOL_SIZE         (4 * 1024 * 1024) /**< Message pool size */

> -#define MAX_ALLOCS            35            /**< Alloc burst size */

> +#define MAX_ALLOCS            32            /**< Alloc burst size */

>


Not a biggie, but it's not clear why this change has been made. As far as I
can tell, changing this has negligible effect on the performance numbers
reported.


>  #define QUEUES_PER_PRIO       64            /**< Queue per priority */

>  #define NUM_PRIOS             2             /**< Number of tested

> priorities */

>  #define QUEUE_ROUNDS          (512 * 1024)    /**< Queue test rounds */

> @@ -131,9 +131,10 @@ static void clear_sched_queues(void)

>  static int enqueue_events(int thr, int prio, int num_queues, int

> num_events,

>                           test_globals_t *globals)

>  {

> -       odp_buffer_t buf;

> +       odp_buffer_t buf[num_events];

> +       odp_event_t ev[num_events];

>         odp_queue_t queue;

> -       int i, j, k;

> +       int i, j, k, ret;

>

>         if (prio == ODP_SCHED_PRIO_HIGHEST)

>                 i = 0;

> @@ -144,19 +145,28 @@ static int enqueue_events(int thr, int prio, int

> num_queues, int num_events,

>         for (j = 0; j < num_queues; j++) {

>                 queue = globals->queue[i][j];

>

> +               ret = odp_buffer_alloc_multi(globals->pool, buf,

> num_events);

> +               if (ret != num_events) {

> +                       LOG_ERR("  [%i] buffer alloc failed\n", thr);

> +                       ret = ret < 0 ? 0 : ret;

> +                       odp_buffer_free_multi(buf, ret);

> +                       return -1;

> +               }

>                 for (k = 0; k < num_events; k++) {

> -                       buf = odp_buffer_alloc(globals->pool);

> -

> -                       if (!odp_buffer_is_valid(buf)) {

> +                       if (!odp_buffer_is_valid(buf[k])) {

>                                 LOG_ERR("  [%i] buffer alloc failed\n",

> thr);

> +                               odp_buffer_free_multi(buf, num_events);

>                                 return -1;

>                         }

> +                       ev[k] = odp_buffer_to_event(buf[k]);

> +               }

>

> -                       if (odp_queue_enq(queue,

> odp_buffer_to_event(buf))) {

> -                               LOG_ERR("  [%i] Queue enqueue failed.\n",

> thr);

> -                               odp_buffer_free(buf);

> -                               return -1;

> -                       }

> +               ret = odp_queue_enq_multi(queue, ev, num_events);

> +               if (ret != num_events) {

> +                       LOG_ERR("  [%i] Queue enqueue failed.\n", thr);

> +                       ret = ret < 0 ? 0 : ret;

> +                       odp_buffer_free_multi(&buf[ret], num_events - ret);

> +                       return -1;

>                 }

>         }

>

> @@ -210,24 +220,30 @@ static int test_alloc_single(int thr, test_globals_t

> *globals)

>   */

>  static int test_alloc_multi(int thr, test_globals_t *globals)

>  {

> -       int i, j;

> +       int i, j, ret;

>         odp_buffer_t temp_buf[MAX_ALLOCS];

>         uint64_t c1, c2, cycles;

>

>         c1 = odp_cpu_cycles();

>

>         for (i = 0; i < ALLOC_ROUNDS; i++) {

> +               ret = odp_buffer_alloc_multi(globals->pool, temp_buf,

> +                                            MAX_ALLOCS);

> +               if (ret != MAX_ALLOCS) {

> +                       LOG_ERR("  [%i] buffer alloc failed\n", thr);

> +                       ret = ret < 0 ? 0 : ret;

> +                       odp_buffer_free_multi(temp_buf, ret);

> +                       return -1;

> +               }

> +

>                 for (j = 0; j < MAX_ALLOCS; j++) {

> -                       temp_buf[j] = odp_buffer_alloc(globals->pool);

> -

>                         if (!odp_buffer_is_valid(temp_buf[j])) {

>                                 LOG_ERR("  [%i] alloc_multi failed\n",

> thr);

> +                               odp_buffer_free_multi(temp_buf,

> MAX_ALLOCS);

>                                 return -1;

>                         }

>                 }

> -

> -               for (; j > 0; j--)

> -                       odp_buffer_free(temp_buf[j - 1]);

> +               odp_buffer_free_multi(temp_buf, MAX_ALLOCS);

>         }

>

>         c2     = odp_cpu_cycles();

> --

> 2.7.4

>

>
Maxim Uvarov July 26, 2016, 7:35 a.m. UTC | #2
On 07/26/16 03:14, Bill Fischofer wrote:
>> >  #define MSG_POOL_SIZE         (4 * 1024 * 1024) /**< Message pool size */

>> >-#define MAX_ALLOCS            35            /**< Alloc burst size */

>> >+#define MAX_ALLOCS            32            /**< Alloc burst size */

>> >

> Not a biggie, but it's not clear why this change has been made. As far as I

> can tell, changing this has negligible effect on the performance numbers

> reported.

>

>

I guess that is because of round division (4 * 1024 * 1024) / 4194304 = 32

Maxim.
diff mbox

Patch

diff --git a/test/common_plat/performance/odp_scheduling.c b/test/common_plat/performance/odp_scheduling.c
index 5a2997f..1d1bf01 100644
--- a/test/common_plat/performance/odp_scheduling.c
+++ b/test/common_plat/performance/odp_scheduling.c
@@ -29,7 +29,7 @@ 
 #include <getopt.h>
 
 #define MSG_POOL_SIZE         (4 * 1024 * 1024) /**< Message pool size */
-#define MAX_ALLOCS            35            /**< Alloc burst size */
+#define MAX_ALLOCS            32            /**< Alloc burst size */
 #define QUEUES_PER_PRIO       64            /**< Queue per priority */
 #define NUM_PRIOS             2             /**< Number of tested priorities */
 #define QUEUE_ROUNDS          (512 * 1024)    /**< Queue test rounds */
@@ -131,9 +131,10 @@  static void clear_sched_queues(void)
 static int enqueue_events(int thr, int prio, int num_queues, int num_events,
 			  test_globals_t *globals)
 {
-	odp_buffer_t buf;
+	odp_buffer_t buf[num_events];
+	odp_event_t ev[num_events];
 	odp_queue_t queue;
-	int i, j, k;
+	int i, j, k, ret;
 
 	if (prio == ODP_SCHED_PRIO_HIGHEST)
 		i = 0;
@@ -144,19 +145,28 @@  static int enqueue_events(int thr, int prio, int num_queues, int num_events,
 	for (j = 0; j < num_queues; j++) {
 		queue = globals->queue[i][j];
 
+		ret = odp_buffer_alloc_multi(globals->pool, buf, num_events);
+		if (ret != num_events) {
+			LOG_ERR("  [%i] buffer alloc failed\n", thr);
+			ret = ret < 0 ? 0 : ret;
+			odp_buffer_free_multi(buf, ret);
+			return -1;
+		}
 		for (k = 0; k < num_events; k++) {
-			buf = odp_buffer_alloc(globals->pool);
-
-			if (!odp_buffer_is_valid(buf)) {
+			if (!odp_buffer_is_valid(buf[k])) {
 				LOG_ERR("  [%i] buffer alloc failed\n", thr);
+				odp_buffer_free_multi(buf, num_events);
 				return -1;
 			}
+			ev[k] = odp_buffer_to_event(buf[k]);
+		}
 
-			if (odp_queue_enq(queue, odp_buffer_to_event(buf))) {
-				LOG_ERR("  [%i] Queue enqueue failed.\n", thr);
-				odp_buffer_free(buf);
-				return -1;
-			}
+		ret = odp_queue_enq_multi(queue, ev, num_events);
+		if (ret != num_events) {
+			LOG_ERR("  [%i] Queue enqueue failed.\n", thr);
+			ret = ret < 0 ? 0 : ret;
+			odp_buffer_free_multi(&buf[ret], num_events - ret);
+			return -1;
 		}
 	}
 
@@ -210,24 +220,30 @@  static int test_alloc_single(int thr, test_globals_t *globals)
  */
 static int test_alloc_multi(int thr, test_globals_t *globals)
 {
-	int i, j;
+	int i, j, ret;
 	odp_buffer_t temp_buf[MAX_ALLOCS];
 	uint64_t c1, c2, cycles;
 
 	c1 = odp_cpu_cycles();
 
 	for (i = 0; i < ALLOC_ROUNDS; i++) {
+		ret = odp_buffer_alloc_multi(globals->pool, temp_buf,
+					     MAX_ALLOCS);
+		if (ret != MAX_ALLOCS) {
+			LOG_ERR("  [%i] buffer alloc failed\n", thr);
+			ret = ret < 0 ? 0 : ret;
+			odp_buffer_free_multi(temp_buf, ret);
+			return -1;
+		}
+
 		for (j = 0; j < MAX_ALLOCS; j++) {
-			temp_buf[j] = odp_buffer_alloc(globals->pool);
-
 			if (!odp_buffer_is_valid(temp_buf[j])) {
 				LOG_ERR("  [%i] alloc_multi failed\n", thr);
+				odp_buffer_free_multi(temp_buf, MAX_ALLOCS);
 				return -1;
 			}
 		}
-
-		for (; j > 0; j--)
-			odp_buffer_free(temp_buf[j - 1]);
+		odp_buffer_free_multi(temp_buf, MAX_ALLOCS);
 	}
 
 	c2     = odp_cpu_cycles();