Hi All
I am having this issue I don't know how to solve (digged
the source, it didn't clarify)
I have this kind of half complex data structure that
needs to be per-cpu and I need to initialize them.
The problem is it contains an array of list_heads
and I cannot initialize that with an static initializer,
AFAIK:
#define NUMBER_OF_QUEUES 256
struct rtf_h {
spinlock_t lock;
struct list_head queues[NUMBER_OF_QUEUES];
}
static DEFINE_PER_CPU (struct rtf_h, rtf_lh);
So I want to initialize those - I cannot use the variable
initializing because (a) it is very dirty to add a huge
number of INIT_LIST_HEAD and (b) it would break the
DEFINE_PER_CPU() semantics, as I assume they are copied
and thus the values would be broken.
So I can have it initialized except the list_heads (only
the locks) and then manually initialize the list_heads
with some rth_h_init() function;
Now the question is: how do I walk each structure that is
associated to each CPU - I mean, something like:
struct rtf_h *h;
for_each_cpu (h, rtf_lh) {
rtf_h_init (h);
}
TIA
I?aky P?rez-Gonz?lez -- Not speaking for Intel -- all opinions are my own
(and my fault)
> From: Perez-Gonzalez, Inaky [mailto:[email protected]]
> ...
> Now the question is: how do I walk each structure that is
> associated to each CPU - I mean, something like:
>
> struct rtf_h *h;
> for_each_cpu (h, rtf_lh) {
> rtf_h_init (h);
> }
Uh, I think it can be done perfectly as:
on_each_cpu (rtf_h_init, NULL, 1, 1);
with:
rtf_h_init (void *dummy) {
const int cpu = get_cpu();
struct rtf_h *h = per_cpu (rtf_lh, cpu);
/* ... blah ... init the queues */
put_cpu();
}
If I am wrong, pls let me know ...
TIA again
I?aky P?rez-Gonz?lez -- Not speaking for Intel -- all opinions are my own
(and my fault)
On Thu, Jun 05, 2003 at 09:35:37PM +0000, Perez-Gonzalez, Inaky wrote:
> Now the question is: how do I walk each structure that is
> associated to each CPU - I mean, something like:
>
> struct rtf_h *h;
> for_each_cpu (h, rtf_lh) {
> rtf_h_init (h);
> }
One way to do this would be to do -
for (i = 0; i < NR_CPUS; i++) {
if (cpu_possible(i))
rtf_h_init(&per_cpu(rtf_lh, i));
}
However you might want to actually use the CPU notifiers to do this. See
rcu_init() in kernel/rcupdate.c.
Thanks
Dipankar
> From: Dipankar Sarma [mailto:[email protected]]
>
> On Thu, Jun 05, 2003 at 09:35:37PM +0000, Perez-Gonzalez, Inaky wrote:
> > Now the question is: how do I walk each structure that is
> > associated to each CPU - I mean, something like:
> >
> > struct rtf_h *h;
> > for_each_cpu (h, rtf_lh) {
> > rtf_h_init (h);
> > }
>
> One way to do this would be to do -
>
> for (i = 0; i < NR_CPUS; i++) {
> if (cpu_possible(i))
> rtf_h_init(&per_cpu(rtf_lh, i));
> }
Yeap, that is a way ...
> However you might want to actually use the CPU notifiers to do this. See
> rcu_init() in kernel/rcupdate.c.
Aha ... that is the bit I was missing - cool, thanks; the only thing,
although I don't think I will have a problem with it, is that the
notifiers are going to be called before my __initcall, probably (or
even worse, there is no defined order) ... well, I don't think that
will be a problem.
Thanks so much,
I?aky P?rez-Gonz?lez -- Not speaking for Intel -- all opinions are my own
(and my fault)