linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How to initialize complex per-cpu variables?
@ 2003-06-05 21:32 Perez-Gonzalez, Inaky
  2003-06-06 12:58 ` Dipankar Sarma
  0 siblings, 1 reply; 4+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-05 21:32 UTC (permalink / raw)
  To: 'lkml (linux-kernel@vger.kernel.org)'


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)

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

* Re: How to initialize complex per-cpu variables?
  2003-06-05 21:32 How to initialize complex per-cpu variables? Perez-Gonzalez, Inaky
@ 2003-06-06 12:58 ` Dipankar Sarma
  0 siblings, 0 replies; 4+ messages in thread
From: Dipankar Sarma @ 2003-06-06 12:58 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky; +Cc: 'lkml (linux-kernel@vger.kernel.org)'

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

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

* RE: How to initialize complex per-cpu variables?
@ 2003-06-06 20:44 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 4+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-06 20:44 UTC (permalink / raw)
  To: 'dipankar@in.ibm.com'
  Cc: 'lkml (linux-kernel@vger.kernel.org)'

> From: Dipankar Sarma [mailto:dipankar@in.ibm.com]
> 
> 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)

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

* RE: How to initialize complex per-cpu variables?
@ 2003-06-05 22:01 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 4+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-05 22:01 UTC (permalink / raw)
  To: 'lkml (linux-kernel@vger.kernel.org)'


> From: Perez-Gonzalez, Inaky [mailto:inaky.perez-gonzalez@intel.com]
> ...
> 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)


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

end of thread, other threads:[~2003-06-06 22:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-05 21:32 How to initialize complex per-cpu variables? Perez-Gonzalez, Inaky
2003-06-06 12:58 ` Dipankar Sarma
2003-06-05 22:01 Perez-Gonzalez, Inaky
2003-06-06 20:44 Perez-Gonzalez, Inaky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).