trace: convert init_trace_bufs() to constructor
PATCH 1/1 trace: convert init_trace_bufs() to constructor
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to init_constructors() it can easily be a constructor itself.
---
Same could then apparently be done for heap_init_late(). Thoughts?
xen/arch/arm/setup.c +0 -2
@@ -491,8 +491,6 @@ void asmlinkage __init start_xen(unsigneheap_init_late (); -init_trace_bufs (); -init_constructors ();console_endboot ();
xen/arch/x86/setup.c +0 -2
@@ -2143,8 +2143,6 @@ void asmlinkage __init noreturn __start_heap_init_late (); -init_trace_bufs (); -init_constructors ();console_endboot ();
xen/common/trace.c +1 -1
@@ -336,7 +336,7 @@ int trace_will_trace_event(u32 event)* trace buffers. The trace buffers are then available for debugging use, via * the %TRACE_xD macros exported in <xen/trace.h>. */ -void __init init_trace_bufs (void ) +static void __init __constructor init_trace_bufs(void) {cpumask_setall (&tb_cpu_mask);register_cpu_notifier (&cpu_nfb);
xen/include/xen/trace.h +0 -4
@@ -29,9 +29,6 @@extern bool tb_init_done; -/* Used to initialise trace buffer functionality */ -void init_trace_bufs (void ); -/* used to retrieve the physical address of the trace buffers */ int tb_control (struct xen_sysctl_tbuf_op *tbc);
@@ -49,7 +46,6 @@ void __trace_hypercall(uint32_t event, u#define tb_init_done false -static inline void init_trace_bufs (void ) {}static inline int tb_control (struct xen_sysctl_tbuf_op *tbc) {return -ENOSYS ;
Quoted 5 lines · Jan Beulich
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to
init_constructors()it can easily be a constructor itself.Signed-off-by Jan Beulich <[email protected]>
This has a side effect of wiring it up on RISC-V and PPC, as they process constructors. It looks safe enough, but have you double checked?
However, the position and logic during init is nonsense, I think.
It registers a cpu notifier which only does spin_lock_init() on a per-cpu variable, which I think only works today because 0 is the init value.
alloc_trace_bufs() on the other hand has a for_each_online_cpu() loop because it's too late and ought to be a presmp_initcall().
Also the allocations could be NUMA-local for all but the biggest of servers (given the 16T upper limit because there are raw uint32_t's involved in the protocol).
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.
~Andrew
Quoted 9 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to
init_constructors()it can easily be a constructor itself.Signed-off-by Jan Beulich <[email protected]>This has a side effect of wiring it up on RISC-V and PPC, as they process constructors. It looks safe enough, but have you double checked?
I've been looking at this differently: For both it can't be right for the function to _not_ be called. And no matter that ...
Quoted 6 lines
However, the position and logic during init is nonsense, I think.
It registers a cpu notifier which only does
spin_lock_init()on a per-cpu variable, which I think only works today because 0 is the init value.
Quoted 6 lines
alloc_trace_bufs()on the other hand has afor_each_online_cpu()loop because it's too late and ought to be apresmp_initcall().Also the allocations could be NUMA-local for all but the biggest of servers (given the 16T upper limit because there are raw uint32_t's involved in the protocol).
... there's certainly further room for improvement, init_trace_bufs() is all just "normal" code, which was already built before.
If there are missing pieces to make trace buffers fully working there, that's no different from before the patch.
As to alloc_trace_bufs() - that has a 2nd caller, so converting to presmp_initcall() may not buy us all that much.
Quoted 2 lines
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.
I understand you like adding such comments; I, however, at least sometimes (e.g.) don't. Especially without at least outlining what would need doing. Just saying "this is all mad" doesn't really help very much.
Jan
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to
init_constructors()it can easily be a constructor itself.Signed-off-by Jan Beulich <[email protected]>This has a side effect of wiring it up on RISC-V and PPC, as they process constructors. It looks safe enough, but have you double checked?
I've been looking at this differently: For both it can't be right for the function to _not_ be called.
Eventually, sure. But they're both in the early bringup stage, still getting the basics working.
So really, the question is "does this (not) cause CI to explode".
In c/s 8c3ab4ffa953 I noted it was easy to make CONFIG_TRACEBUFFER build for PPC, but I didn't try running init_trace_bufs().
Anyway, I've kicked off
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1715210166
to check.
Quoted 13 lines
Quoted 7 lines
However, the position and logic during init is nonsense, I think.
It registers a cpu notifier which only does
spin_lock_init()on a per-cpu variable, which I think only works today because 0 is the init value.Quoted 6 lines
alloc_trace_bufs()on the other hand has afor_each_online_cpu()loop because it's too late and ought to be apresmp_initcall().Also the allocations could be NUMA-local for all but the biggest of servers (given the 16T upper limit because there are raw uint32_t's involved in the protocol).
Quoted 8 lines
... there's certainly further room for improvement,
init_trace_bufs()is all just "normal" code, which was already built before.If there are missing pieces to make trace buffers fully working there, that's no different from before the patch.
As to
alloc_trace_bufs()- that has a 2nd caller, so converting topresmp_initcall()may not buy us all that much.
Another bug I've realised is that this fails if we hot-online new CPUs later, because tb_init will be set but nothing allocated on the new CPUs.
Quoted 7 lines
Quoted 3 lines
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.
I understand you like adding such comments; I, however, at least sometimes (e.g.) don't. Especially without at least outlining what would need doing. Just saying "this is all mad" doesn't really help very much.
I was being somewhat flippant. But a /* TODO, try and make this a presmp_initcall() to improve alloc_trace_bufs() */ would be fine.
~Andrew
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
On 13/03/2025 1:38 pm, Jan Beulich wrote:
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.
Quoted 7 lines
Quoted 4 lines
I understand you like adding such comments; I, however, at least sometimes (e.g.) don't. Especially without at least outlining what would need doing. Just saying "this is all mad" doesn't really help very much.
I was being somewhat flippant. But a /* TODO, try and make this a
presmp_initcall()to improvealloc_trace_bufs()*/ would be fine.
Okay, added (to the existing comment).
Jan
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
On 13/03/2025 1:38 pm, Jan Beulich wrote:
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
I understand you like adding such comments; I, however, at least sometimes (e.g.) don't. Especially without at least outlining what would need doing. Just saying "this is all mad" doesn't really help very much.
I was being somewhat flippant. But a /* TODO, try and make this a
presmp_initcall()to improvealloc_trace_bufs()*/ would be fine.Okay, added (to the existing comment).
RISC-V and PPC were both green in the pipeline, so they seem happy.
~Andrew
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
On 13/03/2025 1:38 pm, Jan Beulich wrote:
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.I understand you like adding such comments; I, however, at least sometimes (e.g.) don't. Especially without at least outlining what would need doing. Just saying "this is all mad" doesn't really help very much.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
I was being somewhat flippant. But a /* TODO, try and make this a
presmp_initcall()to improvealloc_trace_bufs()*/ would be fine.Okay, added (to the existing comment).
RISC-V and PPC were both green in the pipeline, so they seem happy.
As alluded to, not surprising at all, as the tests surely don't supply a "tbuf_size=" command line option. Without which init_trace_bufs() does close to nothing. Still - thanks for double checking. May I imply an ack from this (formally I'll need a separate Arm one then still anyway)?
Jan
Andrew Cooper
Reviewed-byQuoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
On 13/03/2025 1:38 pm, Jan Beulich wrote:
I'm tempted to ack this on the basis that it is an improvement, but a /* TODO this is all mad, please fix */ wouldn't go amiss either.I understand you like adding such comments; I, however, at least sometimes (e.g.) don't. Especially without at least outlining what would need doing. Just saying "this is all mad" doesn't really help very much.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
I was being somewhat flippant. But a /* TODO, try and make this a
presmp_initcall()to improvealloc_trace_bufs()*/ would be fine.Okay, added (to the existing comment).
RISC-V and PPC were both green in the pipeline, so they seem happy.
As alluded to, not surprising at all, as the tests surely don't supply a "tbuf_size=" command line option. Without which
init_trace_bufs()does close to nothing. Still - thanks for double checking. May I imply an ack from this (formally I'll need a separate Arm one then still anyway)?
Hi Jan,
Quoted 5 lines · Jan Beulich
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to
init_constructors()it can easily be a constructor itself.Signed-off-by Jan Beulich <[email protected]>
Quoted 2 lines
---
Same could then apparently be done forheap_init_late(). Thoughts?
Looking at the code, I couldn't figure out whether any of the constructors may rely on some changes done by heap_init_late().
The only issue I can think of is scrubbing. In the case it is synchronous, would the memory allocated before hand be scrubbed?
Cheers,
Signature · 1 line
Julien Grall
Quoted 8 lines · Julien Grall
Quoted 5 lines · Jan Beulich
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to
init_constructors()it can easily be a constructor itself.Signed-off-by Jan Beulich <[email protected]>Acked-by Julien Grall <[email protected]>
Thanks.
Quoted 8 lines
Quoted 2 lines
---
Same could then apparently be done forheap_init_late(). Thoughts?Looking at the code, I couldn't figure out whether any of the constructors may rely on some changes done by
heap_init_late().The only issue I can think of is scrubbing. In the case it is synchronous, would the memory allocated before hand be scrubbed?
Memory that is allocated can't possibly be scrubbed; only memory that's still un-allocated can be. With that I fear I don't properly understand the question you raise.
Jan
Hi Jan,
Quoted 18 lines · Jan Beulich
Quoted 8 lines · Julien Grall
Quoted 5 lines · Jan Beulich
There's no need for each arch to invoke it directly, and there's no need for having a stub either. With the present placement of the calls to
init_constructors()it can easily be a constructor itself.Signed-off-by Jan Beulich <[email protected]>Acked-by Julien Grall <[email protected]>Thanks.
Quoted 6 lines
Quoted 2 lines
---
Same could then apparently be done forheap_init_late(). Thoughts?Looking at the code, I couldn't figure out whether any of the constructors may rely on some changes done by
heap_init_late().
Quoted 6 lines
Quoted 2 lines
The only issue I can think of is scrubbing. In the case it is synchronous, would the memory allocated before hand be scrubbed?
Memory that is allocated can't possibly be scrubbed; only memory that's still un-allocated can be. With that I fear I don't properly understand the question you raise.
I meant that if memory is allocated by calls from init_constructors(). Before this patch, the memory would be scrubbed. After this patch, anything constructors called before heap_init_late() would end up to not be scrubbed if it is synchronous.
Cheers,
Signature · 1 line
Julien Grall
Quoted 12 lines · Julien Grall
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 2 lines · Jan Beulich
---
Same could then apparently be done forheap_init_late(). Thoughts?Looking at the code, I couldn't figure out whether any of the constructors may rely on some changes done by
heap_init_late().The only issue I can think of is scrubbing. In the case it is synchronous, would the memory allocated before hand be scrubbed?
Quoted 8 lines
Quoted 3 lines
Memory that is allocated can't possibly be scrubbed; only memory that's still un-allocated can be. With that I fear I don't properly understand the question you raise.
I meant that if memory is allocated by calls from
init_constructors(). Before this patch, the memory would be scrubbed. After this patch, anything constructors called beforeheap_init_late()would end up to not be scrubbed if it is synchronous.
Oh, I see. Since scrubbing may be asynchronous, any site relying on scrubbing having happened would be flawed anyway. Apart from that, unless callers pass MEMF_no_scrub to alloc_heap_pages(), un-scrubbed pages would be scrubbed anyway (see near the end of the function).
Jan
Hi Jan,
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Julien Grall
Quoted 14 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 2 lines · Jan Beulich
---
Same could then apparently be done forheap_init_late(). Thoughts?Looking at the code, I couldn't figure out whether any of the constructors may rely on some changes done by
heap_init_late().The only issue I can think of is scrubbing. In the case it is synchronous, would the memory allocated before hand be scrubbed?
Memory that is allocated can't possibly be scrubbed; only memory that's still un-allocated can be. With that I fear I don't properly understand the question you raise.
Quoted 7 lines
Quoted 4 lines
I meant that if memory is allocated by calls from
init_constructors(). Before this patch, the memory would be scrubbed. After this patch, anything constructors called beforeheap_init_late()would end up to not be scrubbed if it is synchronous.Oh, I see. Since scrubbing may be asynchronous, any site relying on scrubbing having happened would be flawed anyway.
I have to disagree. If the scrubbing is asynchronous then...
Quoted 2 lines
Apart from that, unless callers pass
MEMF_no_scrubtoalloc_heap_pages(), un-scrubbed pages would be scrubbed> anyway (see near the end of the function).
... the page will be scrubbed at the time it is allocated if it was not done before. But for synchronous scrubbing, at boot, this will not be the case (unless CONFIG_SCRUB_DEBUG is set and with the associated command line option). It will only happen during heap_init_late(). This is because init_heap_pages() will not request scrubbing unless asynchronous scrubbing is enabled (or CONFIG_SCRUB_DEBUG is set and with the associated command line).
So I still think there is a potential difference of behavior if we move heap_init_late() later. Someone will need to investigate whether there is effectively an issue.
Cheers,
Signature · 1 line
Julien Grall