Skip to content

Commit

Permalink
Merge branch 'master' into api-next
Browse files Browse the repository at this point in the history
  • Loading branch information
muvarov committed Aug 10, 2017
2 parents e420668 + 65d0fbb commit 762372f
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 87 deletions.
165 changes: 100 additions & 65 deletions example/generator/odp_generator.c
Expand Up @@ -137,6 +137,7 @@ static void millisleep(uint32_t ms,
uint64_t ticks = odp_timer_ns_to_tick(tp, 1000000ULL * ms);
odp_event_t ev = odp_timeout_to_event(tmo);
int rc = odp_timer_set_rel(tim, ticks, &ev);

if (rc != ODP_TIMER_SUCCESS)
EXAMPLE_ABORT("odp_timer_set_rel() failed\n");
/* Spin waiting for timeout event */
Expand Down Expand Up @@ -186,13 +187,77 @@ static int scan_ip(char *buf, unsigned int *paddr)
return 0;
}

/**
* Setup array of reference packets
*
* @param pool Packet pool
* @param pkt_ref_array Packet array
* @param pkt_ref_array_size Packet array size
* @param setup_ref Packet setup function
* @return 0 success, -1 failed
*/
static int setup_pkt_ref_array(odp_pool_t pool,
odp_packet_t *pkt_ref_array,
int pkt_ref_array_size,
odp_packet_t (*setup_ref)(odp_pool_t))
{
int i;

for (i = 0; i < pkt_ref_array_size; i++) {
pkt_ref_array[i] = (*setup_ref)(pool);
if (pkt_ref_array[i] == ODP_PACKET_INVALID)
break;
}

if (i < pkt_ref_array_size) {
odp_packet_free_multi(pkt_ref_array, i);
return -1;
}
return 0;
}

/**
* Setup array of packets
*
* @param pkt_ref_array Reference packet array
* @param pkt_array Packet array
* @param pkt_array_size Packet array size
* @param setup_pkt Packet setup function
* @return 0 success, -1 failed
*/
static int setup_pkt_array(odp_packet_t *pkt_ref_array,
odp_packet_t *pkt_array,
int pkt_array_size,
int (*setup_pkt)(odp_packet_t))
{
int i;

for (i = 0; i < pkt_array_size; i++) {
if ((*setup_pkt)(pkt_ref_array[i]))
break;

pkt_array[i] = odp_packet_ref_static(pkt_ref_array[i]);
if (pkt_array[i] == ODP_PACKET_INVALID)
break;
}
if (i < pkt_array_size) {
if (i)
odp_packet_free_multi(pkt_array, i - 1);

return -1;
}
return 0;
}

/**
* set up an udp packet reference
*
* @param pool Buffer pool to create packet in
*
* @return Handle of created packet
*
* @retval Handle of created packet
* @retval ODP_PACKET_INVALID Packet could not be created
*
*/
static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool)
{
Expand Down Expand Up @@ -247,37 +312,27 @@ static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool)
/**
* set up an udp packet
*
* @param pool Buffer pool to create packet in
* @param pkt_ref Reference UDP packet
* @param pkt Reference UDP packet
*
* @return Handle of created packet
* @retval ODP_PACKET_INVALID Packet could not be created
* @return Success/Failed
* @retval 0 on success, -1 on fail
*/
static odp_packet_t pack_udp_pkt(odp_pool_t pool, odp_packet_t pkt_ref)
static int setup_udp_pkt(odp_packet_t pkt)
{
odp_packet_t pkt;
char *buf;
odph_ipv4hdr_t *ip;
unsigned short seq;

pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_UDPHDR_LEN +
ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);

if (pkt == ODP_PACKET_INVALID)
return pkt;

buf = (char *)odp_packet_data(pkt);
odp_memcpy(buf, odp_packet_data(pkt_ref),
args->appl.payload + ODPH_UDPHDR_LEN +
ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);

/*Update IP ID and checksum*/
ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xFFFF;
ip->id = odp_cpu_to_be_16(seq);
ip->chksum = 0;
ip->chksum = odph_chksum(ip, ODPH_IPV4HDR_LEN);

return pkt;
return 0;
}

/**
Expand Down Expand Up @@ -338,37 +393,27 @@ static odp_packet_t setup_icmp_pkt_ref(odp_pool_t pool)
/**
* Set up an icmp packet
*
* @param pool Buffer pool to create packet in
* @param pkt_ref Reference ICMP packet
* @param pkt Reference ICMP packet
*
* @return Handle of created packet
* @retval ODP_PACKET_INVALID Packet could not be created
* @return Success/Failed
* @retval 0 on success, -1 on fail
*/
static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref)
static int setup_icmp_pkt(odp_packet_t pkt)
{
odp_packet_t pkt;
char *buf;
odph_ipv4hdr_t *ip;
odph_icmphdr_t *icmp;
uint64_t tval;
uint8_t *tval_d;
unsigned short seq;

pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_ICMPHDR_LEN +
ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);

if (pkt == ODP_PACKET_INVALID)
return pkt;

buf = (char *)odp_packet_data(pkt);
odp_memcpy(buf, odp_packet_data(pkt_ref),
args->appl.payload + ODPH_ICMPHDR_LEN +
ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);

/* ip */
ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
seq = odp_atomic_fetch_add_u64(&counters.seq, 1) % 0xffff;
ip->id = odp_cpu_to_be_16(seq);
ip->chksum = 0;
ip->chksum = odph_chksum(ip, ODPH_IPV4HDR_LEN);

/* icmp */
Expand All @@ -383,7 +428,7 @@ static odp_packet_t pack_icmp_pkt(odp_pool_t pool, odp_packet_t pkt_ref)
icmp->chksum = 0;
icmp->chksum = odph_chksum(icmp, args->appl.payload + ODPH_ICMPHDR_LEN);

return pkt;
return 0;
}

/**
Expand Down Expand Up @@ -480,33 +525,40 @@ static int create_pktio(const char *dev, odp_pool_t pool,
static int gen_send_thread(void *arg)
{
int thr;
int ret, i;
int ret = 0;
thread_args_t *thr_args;
odp_pktout_queue_t pktout;
odp_packet_t pkt_ref_array[MAX_UDP_TX_BURST];
odp_packet_t pkt_array[MAX_UDP_TX_BURST];
int pkt_array_size;
int burst_start, burst_size;
odp_packet_t pkt_ref = ODP_PACKET_INVALID;
odp_packet_t (*setup_pkt_ref)(odp_pool_t) = NULL;
int (*setup_pkt)(odp_packet_t) = NULL;

thr = odp_thread_id();
thr_args = arg;

pktout = thr_args->pktout;

/* Create reference packets*/
if (args->appl.mode == APPL_MODE_UDP) {
pkt_ref = setup_udp_pkt_ref(thr_args->pool);
pkt_array_size = args->appl.udp_tx_burst;
setup_pkt_ref = setup_udp_pkt_ref;
setup_pkt = setup_udp_pkt;
} else if (args->appl.mode == APPL_MODE_PING) {
pkt_ref = setup_icmp_pkt_ref(thr_args->pool);
pkt_array_size = 1;
setup_pkt_ref = setup_icmp_pkt_ref;
setup_pkt = setup_icmp_pkt;
} else {
EXAMPLE_ERR(" [%02i] Error: invalid processing mode %d\n",
thr, args->appl.mode);
return -1;
}
if (pkt_ref == ODP_PACKET_INVALID) {
EXAMPLE_ERR(" [%2i] Error: reference packet creation failed\n",
thr);

if (setup_pkt_ref_array(thr_args->pool, pkt_ref_array,
pkt_array_size, setup_pkt_ref)) {
EXAMPLE_ERR("[%02i] Error: failed to create"
" reference packets\n", thr);
return -1;
}

Expand All @@ -520,30 +572,15 @@ static int gen_send_thread(void *arg)
(unsigned int)args->appl.number)
break;

if (args->appl.mode == APPL_MODE_UDP) {
for (i = 0; i < pkt_array_size; i++) {
pkt_array[i] = pack_udp_pkt(thr_args->pool,
pkt_ref);
if (!odp_packet_is_valid(pkt_array[i]))
break;
}
if (i != pkt_array_size) {
EXAMPLE_ERR(" [%2i] alloc_multi failed\n",
thr);
odp_packet_free_multi(pkt_array, i);
break;
}
} else if (args->appl.mode == APPL_MODE_PING) {
pkt_array[0] = pack_icmp_pkt(thr_args->pool, pkt_ref);
if (!odp_packet_is_valid(pkt_array[0])) {
EXAMPLE_ERR(" [%2i] alloc_single failed\n",
thr);
break;
}
} else {
/* Setup TX burst*/
if (setup_pkt_array(pkt_ref_array, pkt_array,
pkt_array_size, setup_pkt)) {
EXAMPLE_ERR("[%02i] Error: failed to setup packets\n",
thr);
break;
}

/* Send TX burst*/
for (burst_start = 0, burst_size = pkt_array_size;;) {
ret = odp_pktout_send(pktout, &pkt_array[burst_start],
burst_size);
Expand Down Expand Up @@ -573,7 +610,6 @@ static int gen_send_thread(void *arg)
thr_args->tim,
thr_args->tq,
thr_args->tmo_ev);

}
}

Expand All @@ -591,7 +627,8 @@ static int gen_send_thread(void *arg)
args->appl.timeout--;
}
}
odp_packet_free(pkt_ref);

odp_packet_free_multi(pkt_ref_array, pkt_array_size);

return 0;
}
Expand Down Expand Up @@ -1091,7 +1128,6 @@ int main(int argc, char *argv[])
odph_odpthreads_create(&thread_tbl[i],
&thd_mask, &thr_params);
cpu = odp_cpumask_next(&cpumask, cpu);

}
}

Expand Down Expand Up @@ -1139,7 +1175,6 @@ int main(int argc, char *argv[])
return 0;
}


/**
* Parse and store the command line arguments
*
Expand Down
1 change: 1 addition & 0 deletions platform/linux-generic/include/odp_pool_internal.h
Expand Up @@ -71,6 +71,7 @@ typedef struct pool_t {
uint8_t *uarea_base_addr;

/* Used by DPDK zero-copy pktio */
uint8_t mem_from_huge_pages;
pool_destroy_cb_fn ext_destroy;
void *ext_desc;

Expand Down
19 changes: 19 additions & 0 deletions platform/linux-generic/odp_pool.c
Expand Up @@ -8,6 +8,7 @@
#include <odp/api/shared_memory.h>
#include <odp/api/align.h>
#include <odp/api/ticketlock.h>
#include <odp/api/system_info.h>

#include <odp_pool_internal.h>
#include <odp_internal.h>
Expand Down Expand Up @@ -282,6 +283,22 @@ static void init_buffers(pool_t *pool)
}
}

static bool shm_is_from_huge_pages(odp_shm_t shm)
{
odp_shm_info_t info;
uint64_t huge_page_size = odp_sys_huge_page_size();

if (huge_page_size == 0)
return 0;

if (odp_shm_info(shm, &info)) {
ODP_ERR("Failed to fetch shm info\n");
return 0;
}

return (info.page_size >= huge_page_size);
}

static odp_pool_t pool_create(const char *name, odp_pool_param_t *params,
uint32_t shmflags)
{
Expand Down Expand Up @@ -407,6 +424,8 @@ static odp_pool_t pool_create(const char *name, odp_pool_param_t *params,
goto error;
}

pool->mem_from_huge_pages = shm_is_from_huge_pages(pool->shm);

pool->base_addr = odp_shm_addr(pool->shm);

pool->uarea_shm = ODP_SHM_INVALID;
Expand Down

0 comments on commit 762372f

Please sign in to comment.