avoid races

This commit is contained in:
Stefan Lankes 2011-10-05 13:23:59 -07:00
parent 907eb10e28
commit 264ab41457

View file

@ -85,7 +85,12 @@
* regarding the driver & its configuration
*/
#define MMNIF_RX_BUFFERLEN 32*1024
#if MMNIF_USE_MPB
#define MMNIF_RX_BUFFERLEN 7*1024
#else
#define MMNIF_RX_BUFFERLEN 8*1024
#endif
#define MMNIF_MAX_DESCRIPTORS 64
#define MMNIF_CORES 2
@ -429,6 +434,7 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
// if ((rb->head - rb->tail < len)&&(rb->tail != rb->head))
// return NULL;
RCCE_acquire_lock(dest-1);
spinlock_lock(&rb->dlock);
if (rb->dcount)
{
@ -444,6 +450,7 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = (rb->tail + len);
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return ret;
} else if (rb->head > len) {
rb->desc_table[rb->dwrite].stat = MMNIF_STATUS_PENDING;
@ -454,9 +461,11 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = len;
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return ret;
} else {
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return 0;
}
} else {
@ -470,6 +479,7 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = (rb->tail + len);
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return ret;
} else if (rb->tail == rb->head) {
if (MMNIF_RX_BUFFERLEN - rb->tail < len)
@ -486,14 +496,17 @@ static uint32_t mmnif_rxbuff_alloc(uint8_t dest, uint16_t len)
rb->dwrite = (rb->dwrite + 1) % MMNIF_MAX_DESCRIPTORS;
rb->tail = (rb->tail + len);
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return ret;
} else {
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return 0;
}
}
} else {
spinlock_unlock(&rb->dlock);
RCCE_release_lock(dest-1);
return 0;
}
}
@ -554,6 +567,7 @@ static void mmnif_rxbuff_free(void)
uint32_t i, j;
uint32_t rpos;
RCCE_acquire_lock(RCCE_ue());
spinlock_lock(&b->dlock);
rpos = b->dread;
@ -580,7 +594,9 @@ static void mmnif_rxbuff_free(void)
} else
break;
}
spinlock_unlock(&b->dlock);
RCCE_release_lock(RCCE_ue());
}
/*
@ -593,7 +609,7 @@ static err_t mmnif_tx(struct netif *netif, struct pbuf *p)
uint32_t i;
struct pbuf *q; /* interator */
uint32_t dest_ip = mmnif_get_destination(netif, p);
int8_t chances = 20;
int8_t chances = 40;
/* check for over/underflow */
if (BUILTIN_EXPECT((p->tot_len < 20 /* IP header size */) || (p->tot_len > 1536), 0)) {
@ -608,23 +624,18 @@ realloc:
{
//DEBUGPRINTF("mmnif_tx(): concurrency");
if (chances <= 0)
goto drop_packet;
//if (chances <= 0)
// goto drop_packet;
chances--;
//chances--;
//mmnif_trigger_irq(dest_ip);
NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;
//NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;NOP8;
goto realloc;
}
if (!write_address)
goto drop_packet;
/* write buffer to buffer & increment the queued packet count
* this can be safely done without locking because this place is
* reserved for us because it has the status "pending"
*/
#if MMNIF_USE_MPB
asm volatile (".byte 0x0f; .byte 0x0a;\n");
#endif
@ -634,7 +645,7 @@ realloc:
#if MMNIF_USE_MPB
memcpy_put((char*) write_address + i, q->payload, q->len);
#else
memcpy((char*)write_address+ i, q->payload, q->len);
memcpy((char*) write_address+ i, q->payload, q->len);
#endif
i += q->len;
}