All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Jan Kiszka <jan.kiszka@domain.hid>
Cc: Xenomai core <Xenomai-core@domain.hid>
Subject: Re: [Xenomai-core] RFC: use a pool of pre-allocated buffers in rt_printf
Date: Thu, 23 Jun 2011 11:05:08 +0200	[thread overview]
Message-ID: <4E0301C4.8080605@domain.hid> (raw)
In-Reply-To: <4E02ED7E.7040204@domain.hid>

On 06/23/2011 09:38 AM, Jan Kiszka wrote:
>> +#ifdef CONFIG_XENO_FASTSYNCH
>> +	if (xeno_get_current() != XN_NO_HANDLE &&
>> +	    !(xeno_get_current_mode() & XNRELAX) && buf_pool_get()) {
>> +		struct print_buffer *old;
>> +
>> +		old = buf_pool_get();
>> +		while (old != buffer) {
>> +			buffer = old;
>> +			old = buf_pool_cmpxchg(buffer, buffer->pool_next);
> 
> Though unlikely, it's still possible: The buffer obtained in the last
> round may have been dequeued meanwhile and then freed (in case a third
> buffer was released to the pool, filling it up to pool_capacity).

I do not get it: it seems to me that if the current head (that is
buf_pool_get()) is freed, then the cmpxchg will fail, so we will loop
and try again.

>> @@ -346,12 +396,36 @@ static void cleanup_buffer(struct print_buffer *buffer)
>>  {
>>  	struct print_buffer *prev, *next;
>>  
>> +	assert_nrt();
>> +
>>  	pthread_setspecific(buffer_key, NULL);
>>  
>>  	pthread_mutex_lock(&buffer_lock);
>>  
>>  	print_buffers();
> 
> You also need to unhook the buffer from the active list before returning
> it to the pool.

We can not do that: we want that when rt_print_init takes a buffer from
the pool, it does not need to do any operation which would need to
switch to secondary mode. This includes getting the active list mutex.
So, the buffer in the pool are also in the active list, but they remain
empty, so, nothing will be printed.

> This looks strange:
> 
> 	buffer->pool_next = buffer;
> 	...
> 	buf_pool_cmpxchg(buffer->pool_next, buffer);
> 
> Don't you want
> 
> 	buffer->pool_next = old;
> 	buf_pool_cmpxchg(old, buffer);

Yes, search and replace error.

-- 
					    Gilles.


  reply	other threads:[~2011-06-23  9:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-22 21:55 [Xenomai-core] RFC: use a pool of pre-allocated buffers in rt_printf Gilles Chanteperdrix
2011-06-23  7:38 ` Jan Kiszka
2011-06-23  9:05   ` Gilles Chanteperdrix [this message]
2011-06-23  9:09     ` Jan Kiszka
2011-06-23 11:29       ` Gilles Chanteperdrix
2011-06-23 11:36         ` Jan Kiszka
2011-06-23 11:40           ` Gilles Chanteperdrix
2011-06-24 19:58           ` Gilles Chanteperdrix
2011-06-27  6:32             ` Jan Kiszka
2011-06-27 10:57               ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E0301C4.8080605@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=Xenomai-core@domain.hid \
    --cc=jan.kiszka@domain.hid \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.