module changes
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
In message <[email protected]> you write:
Quoted 2 lines
I had a quick question: is the inability to declare per-CPU variables in modules going to be permanent?
<sigh>
I'd really like to fix it, but that's *hard*.
<think think think, ask Paulus>
There might be a neater way, and there's definitely a more space-efficient way, but this is a start (the wastage is small as long as there are only a few per-cpu vars, as there are at the moment).
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: per-cpu support inside modules
Author: Rusty Russell
Status: Tested on 2.5.62
D: This adds percpu support for modules. A module cannot have more
D: percpu data than the base kernel does (on my kernel 5636 bytes).
D: This version is quite wasteful: we could allocate them separately
D: in base-kernel-size chunks, and/or only allocate up to the max
D: cpu_possible() cpu, if we cared enough.
include/asm-generic/percpu.h +0 -5
@@ -8,10 +8,8 @@extern unsigned long __per_cpu_offset[NR_CPUS ];/* Separate out the type, so (int[3], foo) works. */ -#ifndef MODULE #define DEFINE_PER_CPU (type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) name##__per_cpu -#endif /* var is in discarded region: offset to particular copy we want */ #define per_cpu (var, cpu) (*RELOC_HIDE(&var##__per_cpu, __per_cpu_offset[cpu]))
@@ -19,11 +17,8 @@ extern unsigned long __per_cpu_offset[NR#else /* ! SMP */ -/* Can't define per-cpu variables in modules. Sorry --RR */ -#ifndef MODULE #define DEFINE_PER_CPU (type, name) \ __typeof__(type) name##__per_cpu -#endif #define per_cpu (var, cpu) ((void)cpu, var##__per_cpu)#define __get_cpu_var (var) var##__per_cpu
include/linux/module.h +5 -0
@@ -264,6 +264,11 @@ struct modulechar *strtab;#endif +#ifdef CONFIG_SMP +/* How far into module_core is the per-cpu stuff (it's at the end) */ +unsigned long percpu_offset; +#endif +/* The command line arguments (may be mangled). People like keeping pointers to this stuff */ char *args;
kernel/module.c +75 -2
113 lines not on this page · raw message
Quoted 18 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 2 lines
I had a quick question: is the inability to declare per-CPU variables in modules going to be permanent?
<sigh>
I'd really like to fix it, but that's *hard*.
<think think think, ask Paulus>
There might be a neater way, and there's definitely a more space-efficient way, but this is a start (the wastage is small as long as there are only a few per-cpu vars, as there are at the moment).
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 6 lines
Name: per-cpu support inside modules
Author: Rusty Russell
Status: Tested on 2.5.62D: This adds percpu support for modules. A module cannot have more
D: percpu data than the base kernel does (on my kernel 5636 bytes).
This limitation is quite horrible.
Does the implementation have to be perfect? The per_cpu API can easily be simulated using good old NR_CPUS arrays:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,8) && !defined(MODULE)
#include <linux/percpu.h> /* why doesn't this work for modules? */
#else
/* Simulate per_cpu() for older kernels or modular builds. */ #define DEFINE_PER_CPU(type, name) \
__typeof__(type) name[NR_CPUS] __cacheline_aligned
#define per_cpu(var, cpu) ((var)[(cpu)])
#endif
Yes it wastes space. Big deal. Rather that than arbitrary limitations.
/Mikael
Quoted 2 lines · Mikael Pettersson
Does the implementation have to be perfect? The
per_cpuAPI can easily be simulated using good oldNR_CPUSarrays:
I agree, the main advantage of having per-cpu API available to modules is that code can just use it and not worry about module vs. monolithic. Some obscure limitation doesn't sound like a good idea in that respect :)
regards
john
In message <[email protected]> you write:
Quoted 8 lines
Quoted 2 lines · Rusty Russell
D: This adds percpu support for modules. A module cannot have more
D: percpu data than the base kernel does (on my kernel 5636 bytes).This limitation is quite horrible.
Does the implementation have to be perfect? The
per_cpuAPI can easily be simulated using good oldNR_CPUSarrays:
The problem is that then you have to have to know whether this is a per-cpu thing created in a module, or not, when you use it 8(
There are two things we can use to alleviate the problem. The first would be to put a minimal cap on the per-cpu data size (eg. 8k). The other possibility is to allocate on an object granularity, in which case the rule becomes "no single per-cpu object can be larger than XXX", but the cost is to write a mini allocator.
I agree with you (and John) about disliking the limitation, but is it worse than the current no per-cpu stuff in modules at all?
Thanks!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 11 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 8 lines
Quoted 2 lines · Rusty Russell
D: This adds percpu support for modules. A module cannot have more
D: percpu data than the base kernel does (on my kernel 5636 bytes).This limitation is quite horrible.
Does the implementation have to be perfect? The
per_cpuAPI can easily be simulated using good oldNR_CPUSarrays:
Quoted 9 lines
The problem is that then you have to have to know whether this is a per-cpu thing created in a module, or not, when you use it 8(
There are two things we can use to alleviate the problem. The first would be to put a minimal cap on the per-cpu data size (eg. 8k). The other possibility is to allocate on an object granularity, in which case the rule becomes "no single per-cpu object can be larger than XXX", but the cost is to write a mini allocator.
Is kmalloc_percpu() not suitable?
In message <[email protected]> you write:
Quoted 4 lines
Quoted 3 lines · Rusty Russell
The problem is that then you have to have to know whether this is a per-cpu thing created in a module, or not, when you use it 8(
Quoted 8 lines
Quoted 6 lines
There are two things we can use to alleviate the problem. The first would be to put a minimal cap on the per-cpu data size (eg. 8k). The other possibility is to allocate on an object granularity, in which case the rule becomes "no single per-cpu object can be larger than XXX", but the cost is to write a mini allocator.
Is
kmalloc_percpu()not suitable?
Unfortunately, no. You have to use the same offsets as the in-kernel DEFINE_PER_CPU declarations, meaning that each cpu's stuff needs to be "sizeof kernel per-cpu-section" apart.
Which means an allocator which keeps a linked list of NR_CPUS * sizeof kernel-per-cpu-section things, and allocs and frees from that.
Hence this patch just tacks it on the end of the module, rather than deal with an allocator. A minor improvement would be only to allocate for the maximum possible CPU, which means about 6k * numcpus per module which declares per-cpu data, which is probably fine.
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Quoted 5 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 4 lines
Quoted 2 lines · Rusty Russell
D: This adds percpu support for modules. A module cannot have more
D: percpu data than the base kernel does (on my kernel 5636 bytes).
Quoted 7 lines
Quoted 4 lines
This limitation is quite horrible.
Does the implementation have to be perfect? The
per_cpuAPI can easily be simulated using good oldNR_CPUSarrays:The problem is that then you have to have to know whether this is a per-cpu thing created in a module, or not, when you use it 8(
Ah yes. I totally missed that. (Shakes head in disbelief.)
Quoted 2 lines
I agree with you (and John) about disliking the limitation, but is it worse than the current no per-cpu stuff in modules at all?
In my case (perfctr driver) it means not being able to use per-cpu stuff at all since I need to be able to build it modular. Or I have to hide per_cpu() behind private macros that fall back to an [NR_CPUS] implementation in the modular case. I can live with that.
/Mikael
In message <[email protected]> you write:
Quoted 5 lines
Quoted 2 lines · Rusty Russell
The problem is that then you have to have to know whether this is a per-cpu thing created in a module, or not, when you use it 8(
Ah yes. I totally missed that. (Shakes head in disbelief.)
<shrug> It's an easy thing to miss.
Quoted 7 lines
Quoted 2 lines
I agree with you (and John) about disliking the limitation, but is it worse than the current no per-cpu stuff in modules at all?
In my case (perfctr driver) it means not being able to use per-cpu stuff at all since I need to be able to build it modular. Or I have to hide
per_cpu()behind private macros that fall back to an [NR_CPUS] implementation in the modular case. I can live with that.
Well, there's kmalloc_percpu() there already. But perfctr certainly won't hit the "more per-cpu data than the core kernel" case, from my brief reading of the code. If something does, then the core kernel minimum can be increased (which is a little hacky, but hey).
Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.