enhanced cfq free list management a bit

This commit is contained in:
2019-01-16 04:37:53 +00:00
parent d0583e95c8
commit af20b13e04
7 changed files with 617 additions and 27 deletions

View File

@ -395,7 +395,7 @@ static void send_icmp (mio_dev_sck_t* dev, mio_uint16_t seq)
memset (&buf[MIO_SIZEOF(*icmphdr)], 'A', MIO_SIZEOF(buf) - MIO_SIZEOF(*icmphdr));
icmphdr->checksum = mio_checksumip (icmphdr, MIO_SIZEOF(buf));
if (mio_dev_sck_write (dev, buf, MIO_SIZEOF(buf), MIO_NULL, &dstaddr) <= -1)
if (mio_dev_sck_write(dev, buf, MIO_SIZEOF(buf), MIO_NULL, &dstaddr) <= -1)
{
printf ("CANNOT WRITE ICMP...\n");
mio_dev_sck_halt (dev);

View File

@ -741,6 +741,9 @@
/* MB_LEN_MAX */
#undef MIO_MBLEN_MAX
/* offsetof(struct sockaddr, sa_family) */
#undef MIO_OFFSETOF_SA_FAMILY
/* Author */
#undef MIO_PACKAGE_AUTHOR
@ -762,6 +765,9 @@
/* Patch level */
#undef MIO_PACKAGE_VERSION_PATCH
/* Define if sa_family_t is signed */
#undef MIO_SA_FAMILY_T_IS_SIGNED
/* sizeof(char) */
#undef MIO_SIZEOF_CHAR
@ -900,6 +906,9 @@
/* The size of `off_t', as computed by sizeof. */
#undef SIZEOF_OFF_T
/* The size of `sa_family_t', as computed by sizeof. */
#undef SIZEOF_SA_FAMILY_T
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT

View File

@ -40,6 +40,9 @@
#define MIO_MEMCMP(dst,src,count) memcmp(dst,src,count)
#define MIO_ASSERT assert
#define MIO_CWQFL_SIZE 16
#define MIO_CWQFL_ALIGN 16
typedef struct mio_mux_t mio_mux_t;
struct mio_t
@ -79,7 +82,7 @@ struct mio_t
} tmr;
mio_cwq_t cwq;
mio_cwq_t* cwq_zdf; /* list of free cwq objects with 0-sized dstaddr */
mio_cwq_t* cwqfl[MIO_CWQFL_SIZE]; /* list of free cwq objects */
/* platform specific fields below */
#if defined(_WIN32)

View File

@ -215,6 +215,9 @@ typedef int mio_sckfam_t;
struct mio_sckaddr_t
{
#if defined(MIO_OFFSETOF_SA_FAMILY) && (MIO_OFFSETOF_SA_FAMILY > 0)
mio_uint8_t filler[MIO_OFFSETOF_SA_FAMILY];
#endif
mio_sckfam_t family;
mio_uint8_t data[128]; /* TODO: use the actual sockaddr size */
};

View File

@ -394,12 +394,17 @@ void mio_fini (mio_t* mio)
mio_dev_t* head;
mio_dev_t* tail;
} diehard;
mio_oow_t i;
while (mio->cwq_zdf)
/* clean up free cwq list */
for (i = 0; i < MIO_COUNTOF(mio->cwqfl); i++)
{
mio_cwq_t* cwq = mio->cwq_zdf;
mio->cwq_zdf = cwq->next;
MIO_MMGR_FREE (mio->mmgr, cwq);
mio_cwq_t* cwq;
while ((cwq = mio->cwqfl[i]))
{
mio->cwqfl[i] = cwq->next;
MIO_MMGR_FREE (mio->mmgr, cwq);
}
}
/* kill all registered devices */
@ -408,6 +413,7 @@ void mio_fini (mio_t* mio)
mio_killdev (mio, mio->actdev.head);
}
/* kill all halted devices */
while (mio->hltdev.head)
{
mio_killdev (mio, mio->hltdev.head);
@ -735,16 +741,19 @@ static MIO_INLINE int __exec (mio_t* mio)
while (!MIO_CWQ_ISEMPTY(&mio->cwq))
{
mio_cwq_t* cwq;
mio_oow_t cwqfl_index;
cwq = MIO_CWQ_HEAD(&mio->cwq);
if (cwq->dev->dev_evcb->on_write(cwq->dev, cwq->olen, cwq->ctx, &cwq->dstaddr) <= -1) return -1;
cwq->dev->cw_count--;
MIO_CWQ_UNLINK (cwq);
if (cwq->dstaddr.len == 0)
cwqfl_index = MIO_ALIGN_POW2(cwq->dstaddr.len, MIO_CWQFL_ALIGN) / MIO_CWQFL_SIZE;
if (cwqfl_index < MIO_COUNTOF(mio->cwqfl))
{
/* reuse the cwq object if dstaddr is 0 in size. chain it to the free list */
cwq->next = mio->cwq_zdf;
mio->cwq_zdf = cwq;
cwq->next = mio->cwqfl[cwqfl_index];
mio->cwqfl[cwqfl_index] = cwq;
}
else
{
@ -1291,6 +1300,7 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
mio_iolen_t urem, ulen;
mio_wq_t* q;
mio_cwq_t* cwq;
mio_oow_t cwq_extra_aligned, cwqfl_index;
int x;
if (dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED)
@ -1341,7 +1351,11 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED;
}
//if (dev->dev_evcb->on_write(dev, len, wrctx, dstaddr) <= -1) return -1;
/* if i trigger the write completion callback here, the performance
* may increase, but there can be annoying recursion issues if the
* callback requests another writing operation. it's imperative to
* delay the callback until this write function is finished.
* ---> if (dev->dev_evcb->on_write(dev, len, wrctx, dstaddr) <= -1) return -1; */
goto enqueue_completed_write;
}
else
@ -1352,8 +1366,11 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
if (x <= -1) return -1;
else if (x == 0) goto enqueue_data;
/* partial writing is still considered ok for a non-stream device */
//if (dev->dev_evcb->on_write(dev, ulen, wrctx, dstaddr) <= -1) return -1;
/* partial writing is still considered ok for a non-stream device. */
/* read the comment in the 'if' block above for why i enqueue the write completion event
* instead of calling the event callback here...
* --> if (dev->dev_evcb->on_write(dev, ulen, wrctx, dstaddr) <= -1) return -1; */
goto enqueue_completed_write;
}
@ -1434,14 +1451,19 @@ enqueue_data:
enqueue_completed_write:
/* queue the remaining data*/
if (!dstaddr && dev->mio->cwq_zdf)
cwq_extra_aligned = (dstaddr? dstaddr->len: 0);
cwq_extra_aligned = MIO_ALIGN_POW2(cwq_extra_aligned, MIO_CWQFL_ALIGN);
cwqfl_index = cwq_extra_aligned / MIO_CWQFL_SIZE;
if (cwqfl_index < MIO_COUNTOF(dev->mio->cwqfl) && dev->mio->cwqfl[cwqfl_index])
{
cwq = dev->mio->cwq_zdf;
dev->mio->cwq_zdf = cwq->next;
/* take an available cwq object from the free cwq list */
cwq = dev->mio->cwqfl[cwqfl_index];
dev->mio->cwqfl[cwqfl_index] = cwq->next;
}
else
{
cwq = (mio_cwq_t*)MIO_MMGR_ALLOC(dev->mio->mmgr, MIO_SIZEOF(*cwq) + (dstaddr? dstaddr->len: 0));
cwq = (mio_cwq_t*)MIO_MMGR_ALLOC(dev->mio->mmgr, MIO_SIZEOF(*cwq) + cwq_extra_aligned);
if (!cwq)
{
dev->mio->errnum = MIO_ENOMEM;