It is currently Sat, 09 Dec 2023 05:13:12 GMT



 
Author Message
 How to initialize complex per-cpu variables?

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 Prez-Gonzlez -- Not speaking for Intel -- all opinions are my own
(and my fault)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at   http://www.**-**.com/
Please read the FAQ at   http://www.**-**.com/



 Mon, 21 Nov 2005 22:40:12 GMT   
 How to initialize complex per-cpu variables?

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 Prez-Gonzlez -- Not speaking for Intel -- all opinions are my own
(and my fault)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



 Mon, 21 Nov 2005 23:10:15 GMT   
 How to initialize complex per-cpu variables?

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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



 Tue, 22 Nov 2005 14:00:20 GMT   
 How to initialize complex per-cpu variables?

Yeap, that is a way ...

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 Prez-Gonzlez -- Not speaking for Intel -- all opinions are my own
(and my fault)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



 Tue, 22 Nov 2005 23:40:12 GMT   
 
   [ 4 post ] 

Similar Threads

1. Make ksoftirqd a normal per-cpu variable.

2. Make ksoftirqd a normal per-cpu variable

3. Per-cpu variable in mm/slab.c

4. Make runqueues a per-cpu variable

5. Make ksoftirqd a per-cpu variable

6. On Local Per-Cpu Variables

7. How to limit cpu time per process per user account

8. How to limit cpu time per process per user account

9. How to monitor CPU Utilisation per CPU

10. Only allocate per-cpu copies for possible CPUs


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software