Gilles,
patch is in attachment, no problem.
I wanted to check first whether my reasoning is correct.
Best regards,
Ronny
On Tue, Oct 26, 2010 at 1:34 PM, Gilles Chanteperdrix <
[email protected]> wrote:
> ronny meeus wrote:
> > Hello
> >
> > I did some further debugging on the problem described below and I made
> > some progress.
> > At creation time of the message queue using:
> > q_create("TEST",0,Q_NOLIMIT|Q_PRIOR,&qid);
> > a chunk of message buffers (64) is allocated and added to the free
> > message list of the queue (queue->freeq).
> > Once the message queue is deleted, the messages are added into the
> > global psosmbufq.
> > During the q_create/q_delete loop, the memory pool get depleted since
> > the number of messages in the psosmbufq keeps on increasing all the time.
> >
> > In my opinion if the Q_PRIBUF is not set during queue creation, the
> > "psosmbufq" has to be used to allocate/release from/to.
> > This also implies that the local freeq in the queue object is not used
> > in this mode anymore.
> > Each time a message needs to be send, in function get_mbuf it is simply
> > taken from the psosmbufq. In case this would be empty, a feed_pool
> > operation is called on it.
> >
> > static psosmbuf_t *get_mbuf(psosqueue_t *queue, u_long msglen)
> > {
> > psosmbuf_t *mbuf = NULL;
> >
> > if (testbits(queue->synchbase.status, Q_NOCACHE)) {
> > mbuf =
> > (psosmbuf_t *) xnmalloc(sizeof(*mbuf) + msglen -
> > sizeof(mbuf->data));
> >
> > if (mbuf)
> > inith(&mbuf->link);
> > } else {
> > xnholder_t *holder = NULL;
> > if (testbits(queue->synchbase.status, Q_SHAREDINIT)) {
> > holder = getq(&psosmbufq);
> > if (!holder) {
> > feed_pool(&psoschunkq,
> > &psosmbufq,PSOS_QUEUE_MIN_ALLOC,queue->maxlen);
> > holder = getq(&psosmbufq);
> > }
> > } else {
> > holder = getq(&queue->freeq);
> > if (!holder && testbits(queue->synchbase.status, Q_INFINITE))
> {
> > feed_pool(&queue->chunkq,&queue->freeq,
> > PSOS_QUEUE_MIN_ALLOC,queue->maxlen);
> > holder = getq(&queue->freeq);
> > }
> > }
> > if (holder)
> > mbuf = link2psosmbuf(holder);
> > }
> > return mbuf;
> > }
> >
> > I have adapted the code accordingly and rerun my tests. Now it runs
> forever.
> > (Of course I also did changes in the code to create and delete a queue.)
> >
> > Now the question is: Is my understanding correct? If it is, the flag
> > Q_SHAREDINIT would be better renamed to Q_SHAREDMSGS.
> >
> > Please share your thoughts.
>
> A patch would be better than some fancy HTML colouring, if you intend
> your fix to be reviewed/integrated.
>
> --
> Gilles.
>
diff -r f8bbb3e78c40 xenomai-2.5.4/ksrc/skins/psos+/queue.c
--- a/xenomai-2.5.4/ksrc/skins/psos+/queue.c Mon Sep 27 20:26:32 2010 +0200
+++ b/xenomai-2.5.4/ksrc/skins/psos+/queue.c Tue Oct 26 15:12:06 2010 +0200
@@ -40,6 +40,7 @@
int len;
spl_t s;
+ p += sprintf(p, "psosmbufq #bufs=%d\n",countq(&psosmbufq));
p += sprintf(p, "maxnum=%lu:maxlen=%lu:mcount=%d\n",
queue->maxnum, queue->maxlen, countq(&queue->inq));
@@ -47,7 +48,7 @@
if (xnsynch_nsleepers(&queue->synchbase) > 0) {
xnpholder_t *holder;
-
+
/* Pended queue -- dump waiters. */
holder = getheadpq(xnsynch_wait_queue(&queue->synchbase));
@@ -164,15 +165,20 @@
if (mbuf)
inith(&mbuf->link);
} else {
- xnholder_t *holder = getq(&queue->freeq);
-
- if (!holder &&
- testbits(queue->synchbase.status, Q_INFINITE) &&
- feed_pool(&queue->chunkq,
- &queue->freeq, PSOS_QUEUE_MIN_ALLOC,
- queue->maxlen) != 0)
- holder = getq(&queue->freeq);
-
+ xnholder_t *holder = NULL;
+ if (testbits(queue->synchbase.status, Q_SHAREDINIT)) {
+ holder = getq(&psosmbufq);
+ if (!holder) {
+ feed_pool(&psoschunkq, &psosmbufq,PSOS_QUEUE_MIN_ALLOC,queue->maxlen);
+ holder = getq(&psosmbufq);
+ }
+ } else {
+ holder = getq(&queue->freeq);
+ if (!holder && testbits(queue->synchbase.status, Q_INFINITE)) {
+ feed_pool(&queue->chunkq,&queue->freeq, PSOS_QUEUE_MIN_ALLOC,queue->maxlen);
+ holder = getq(&queue->freeq);
+ }
+ }
if (holder)
mbuf = link2psosmbuf(holder);
}
@@ -187,7 +193,6 @@
static unsigned long msgq_ids;
psosqueue_t *queue;
int bflags, ret;
- u_long rc;
spl_t s;
bflags = (flags & Q_VARIABLE);
@@ -236,27 +241,13 @@
initq(&queue->chunkq);
if (bflags & Q_PRIVCACHE) {
- if (bflags & Q_SHAREDINIT) {
- xnlock_get_irqsave(&nklock, s);
- rc = feed_pool(&psoschunkq, &psosmbufq, maxnum, maxlen);
- xnlock_put_irqrestore(&nklock, s);
- } else
- rc = feed_pool(&queue->chunkq, &queue->freeq, maxnum,
- maxlen);
-
- if (!rc) {
- /* Can't preallocate msg buffers. */
- xnfree(queue);
- return ERR_NOMGB;
- }
-
- if (bflags & Q_SHAREDINIT) {
- xnlock_get_irqsave(&nklock, s);
-
- while (countq(&queue->freeq) < maxnum)
- appendq(&queue->freeq, getq(&psosmbufq));
-
- xnlock_put_irqrestore(&nklock, s);
+ if ((bflags & Q_SHAREDINIT) == 0) {
+ u_long rc = feed_pool(&queue->chunkq, &queue->freeq, maxnum, maxlen);
+ if (!rc) {
+ /* Can't preallocate msg buffers. */
+ xnfree(queue);
+ return ERR_NOMGB;
+ }
}
}
@@ -477,7 +468,10 @@
if (testbits(queue->synchbase.status, Q_NOCACHE))
xnfree(mbuf);
- else
+ else if (testbits(queue->synchbase.status, Q_SHAREDINIT)) {
+ /* Message buffer should go to the psosmbufq */
+ appendq(&psosmbufq, &mbuf->link);
+ } else
appendq(&queue->freeq, &mbuf->link);
unlock_and_exit:
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help