All of lore.kernel.org
 help / color / mirror / Atom feed
* about RCU programming
       [not found] <BANLkTimW6oLjQoEbHGOAnXwbWMYUvK00fw@mail.gmail.com>
@ 2011-06-22  9:15 ` Manuel Sáez
  2011-06-22 10:01   ` Johannes Berg
  0 siblings, 1 reply; 7+ messages in thread
From: Manuel Sáez @ 2011-06-22  9:15 UTC (permalink / raw)
  To: linux-wireless

Hi all,

I am trying to include a list o devices to poll to. I am not very
experienced but looking the current kernel code for wireless, I
thought it would be a good idea to use a linked list list_head
protected with RCU and one mutex for the add/delete parts.

I would like to receive the next device to be poll from the list every
time that someone calls the function instead of iterating the whole
list every time to find out the next device to poll. Is it possible to
use a pointer to the head and update the pointer to the next element
of the list? I mean could i do something like this?

The write side could be something like this:
mutex_lock(&sdata->u.ap.polllist_mtx);
list_add_rcu(poll_req->list, sdata->u.ap.polling_list);
mutex_unlock(&sdata->u.ap.polllist_mtx);

and the read side:
rcu_read_lock();
rcu_derreference(sdata->u.ap.polling_list->sta);
copy_sta(sdata->u.ap.polling_list->sta);
rcu_read_unlock();

sdata->u.ap.polling_list = sdata.u.ap.polling_list->next;

Do I need to use the same mutex or is this operation fast enought?

Thank you in advance!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: about RCU programming
  2011-06-22  9:15 ` about RCU programming Manuel Sáez
@ 2011-06-22 10:01   ` Johannes Berg
  2011-06-22 11:54     ` Manuel Sáez
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Berg @ 2011-06-22 10:01 UTC (permalink / raw)
  To: Manuel Sáez; +Cc: linux-wireless

On Wed, 2011-06-22 at 11:15 +0200, Manuel Sáez wrote:

> and the read side:
> rcu_read_lock();
> rcu_derreference(sdata->u.ap.polling_list->sta);
> copy_sta(sdata->u.ap.polling_list->sta);
> rcu_read_unlock();
> 
> sdata->u.ap.polling_list = sdata.u.ap.polling_list->next;

This code snippet makes no sense at all. I suggest you read up on how
RCU works first.

johannes


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: about RCU programming
  2011-06-22 10:01   ` Johannes Berg
@ 2011-06-22 11:54     ` Manuel Sáez
  2011-06-22 12:03       ` Johannes Berg
  0 siblings, 1 reply; 7+ messages in thread
From: Manuel Sáez @ 2011-06-22 11:54 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-wireless

Thank you for your answer. I have actually read some articles like this ones:

http://lwn.net/Articles/262464/
http://lwn.net/Articles/263130/

I think I understood how I should normally use it, but not how it
really works. I found lots of code snippets in internet and it seems
to be very easy to use, but when I try to get more information it gets
more complicated. Although the code is wrong, do you think it could be
possible what I want to do? I mean, could it be possible in theory to
"shift" the header in order to make a ring buffer.

Anyway I will try to get more information about the linked list and
RCU. I have a lot of things to learn!! :)

Best regards and thank you again



2011/6/22 Johannes Berg <johannes@sipsolutions.net>:
> On Wed, 2011-06-22 at 11:15 +0200, Manuel Sáez wrote:
>
>> and the read side:
>> rcu_read_lock();
>> rcu_derreference(sdata->u.ap.polling_list->sta);
>> copy_sta(sdata->u.ap.polling_list->sta);
>> rcu_read_unlock();
>>
>> sdata->u.ap.polling_list = sdata.u.ap.polling_list->next;
>
> This code snippet makes no sense at all. I suggest you read up on how
> RCU works first.
>
> johannes
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: about RCU programming
  2011-06-22 11:54     ` Manuel Sáez
@ 2011-06-22 12:03       ` Johannes Berg
  2011-06-22 12:51         ` Manuel Sáez
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Berg @ 2011-06-22 12:03 UTC (permalink / raw)
  To: Manuel Sáez; +Cc: linux-wireless

On Wed, 2011-06-22 at 13:54 +0200, Manuel Sáez wrote:
> Thank you for your answer. I have actually read some articles like this ones:
> 
> http://lwn.net/Articles/262464/
> http://lwn.net/Articles/263130/
> 
> I think I understood how I should normally use it, but not how it
> really works. I found lots of code snippets in internet and it seems
> to be very easy to use, but when I try to get more information it gets
> more complicated. Although the code is wrong, do you think it could be
> possible what I want to do? I mean, could it be possible in theory to
> "shift" the header in order to make a ring buffer.

I haven't understood what you want to do, but "shifting" anything would
seem to me to be a write operation.

johannes


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: about RCU programming
  2011-06-22 12:03       ` Johannes Berg
@ 2011-06-22 12:51         ` Manuel Sáez
  2011-06-22 13:05           ` Johannes Berg
  0 siblings, 1 reply; 7+ messages in thread
From: Manuel Sáez @ 2011-06-22 12:51 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-wireless

Yes, I probably need some kind of mutex, but I was wondering if it
would be enough with some memory barrier, since read and write
operations in modern computers are usually atomics.

What I pretend to do is that everytime I read one element from the
list, the function changes the "head pointer" with the next element ,
so the next time the function is called, it will return the next
element. When the list reach the last element, it starts again from
the beggining. The function should somehow remember the last extracted
element each time and consecutively return the next one. I could
probably use a counter and iterate the list looking for the next
element, but it would be hard to maintain when some elements are added
or deleted.

Best regards


2011/6/22 Johannes Berg <johannes@sipsolutions.net>:
> On Wed, 2011-06-22 at 13:54 +0200, Manuel Sáez wrote:
>> Thank you for your answer. I have actually read some articles like this ones:
>>
>> http://lwn.net/Articles/262464/
>> http://lwn.net/Articles/263130/
>>
>> I think I understood how I should normally use it, but not how it
>> really works. I found lots of code snippets in internet and it seems
>> to be very easy to use, but when I try to get more information it gets
>> more complicated. Although the code is wrong, do you think it could be
>> possible what I want to do? I mean, could it be possible in theory to
>> "shift" the header in order to make a ring buffer.
>
> I haven't understood what you want to do, but "shifting" anything would
> seem to me to be a write operation.
>
> johannes
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: about RCU programming
  2011-06-22 12:51         ` Manuel Sáez
@ 2011-06-22 13:05           ` Johannes Berg
  2011-06-22 13:29             ` Manuel Sáez
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Berg @ 2011-06-22 13:05 UTC (permalink / raw)
  To: Manuel Sáez; +Cc: linux-wireless

Please don't top-post.

On Wed, 2011-06-22 at 14:51 +0200, Manuel Sáez wrote:
> Yes, I probably need some kind of mutex, but I was wondering if it
> would be enough with some memory barrier, since read and write
> operations in modern computers are usually atomics.
> 
> What I pretend to do is that everytime I read one element from the
> list, the function changes the "head pointer" with the next element ,
> so the next time the function is called, it will return the next
> element. When the list reach the last element, it starts again from
> the beggining. The function should somehow remember the last extracted
> element each time and consecutively return the next one. I could
> probably use a counter and iterate the list looking for the next
> element, but it would be hard to maintain when some elements are added
> or deleted.

Well ... you'd need to synchronize that offset or whatever, and also
reset whenever you modify the list, or whatever. It doesn't seem
feasible. I suggest you try implementing what you want first, and then
maybe somebody can help you optimise it.

johannes


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: about RCU programming
  2011-06-22 13:05           ` Johannes Berg
@ 2011-06-22 13:29             ` Manuel Sáez
  0 siblings, 0 replies; 7+ messages in thread
From: Manuel Sáez @ 2011-06-22 13:29 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-wireless

2011/6/22 Johannes Berg <johannes@sipsolutions.net>:
> Please don't top-post.
>
> On Wed, 2011-06-22 at 14:51 +0200, Manuel Sáez wrote:
>> Yes, I probably need some kind of mutex, but I was wondering if it
>> would be enough with some memory barrier, since read and write
>> operations in modern computers are usually atomics.
>>
>> What I pretend to do is that everytime I read one element from the
>> list, the function changes the "head pointer" with the next element ,
>> so the next time the function is called, it will return the next
>> element. When the list reach the last element, it starts again from
>> the beggining. The function should somehow remember the last extracted
>> element each time and consecutively return the next one. I could
>> probably use a counter and iterate the list looking for the next
>> element, but it would be hard to maintain when some elements are added
>> or deleted.
>
> Well ... you'd need to synchronize that offset or whatever, and also
> reset whenever you modify the list, or whatever. It doesn't seem
> feasible. I suggest you try implementing what you want first, and then
> maybe somebody can help you optimise it.
>
> johannes
>
>

Thank you, I will give a try and post the results.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-06-22 13:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <BANLkTimW6oLjQoEbHGOAnXwbWMYUvK00fw@mail.gmail.com>
2011-06-22  9:15 ` about RCU programming Manuel Sáez
2011-06-22 10:01   ` Johannes Berg
2011-06-22 11:54     ` Manuel Sáez
2011-06-22 12:03       ` Johannes Berg
2011-06-22 12:51         ` Manuel Sáez
2011-06-22 13:05           ` Johannes Berg
2011-06-22 13:29             ` Manuel Sáez

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.