numam-dpdk/drivers/event/dsw/dsw_sort.h
Mattias Rönnblom 4ba0dcaa42 event/dsw: sort events on dequeue
With this patch, the DSW event device will (optionally) sort the event
burst before giving it to the application. The sorting will primarily
be on queue id, and secondary on flow id.

The sorting is an attempt to optimize data and instruction cache usage
for the application, at the cost of additional event device overhead.

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
2018-10-01 16:46:03 +02:00

49 lines
1.2 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Ericsson AB
*/
#ifndef _DSW_SORT_
#define _DSW_SORT_
#include <string.h>
#include <rte_common.h>
#define DSW_ARY_ELEM_PTR(_ary, _idx, _elem_size) \
RTE_PTR_ADD(_ary, (_idx) * (_elem_size))
#define DSW_ARY_ELEM_SWAP(_ary, _a_idx, _b_idx, _elem_size) \
do { \
char tmp[_elem_size]; \
void *_a_ptr = DSW_ARY_ELEM_PTR(_ary, _a_idx, _elem_size); \
void *_b_ptr = DSW_ARY_ELEM_PTR(_ary, _b_idx, _elem_size); \
memcpy(tmp, _a_ptr, _elem_size); \
memcpy(_a_ptr, _b_ptr, _elem_size); \
memcpy(_b_ptr, tmp, _elem_size); \
} while (0)
static inline void
dsw_insertion_sort(void *ary, uint16_t len, uint16_t elem_size,
int (*cmp_fn)(const void *, const void *))
{
uint16_t i;
for (i = 1; i < len; i++) {
uint16_t j;
for (j = i; j > 0 &&
cmp_fn(DSW_ARY_ELEM_PTR(ary, j-1, elem_size),
DSW_ARY_ELEM_PTR(ary, j, elem_size)) > 0;
j--)
DSW_ARY_ELEM_SWAP(ary, j, j-1, elem_size);
}
}
static inline void
dsw_stable_sort(void *ary, uint16_t len, uint16_t elem_size,
int (*cmp_fn)(const void *, const void *))
{
dsw_insertion_sort(ary, len, elem_size, cmp_fn);
}
#endif