Skip to contentSkip to conversation

move __read_mostly to xen/cache.h

PATCH In review Jan Beulich 3 participants 10 messages Aug 8, 2023 – Mar 8, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 move __read_mostly to xen/cache.h

There's no need for every arch to define its own identical copy. If down the road an arch needs to customize it, we can add #ifndef around the common #define.

To be on the safe side build-breakage-wise, change a couple of #include <asm/cache.h> to the xen/ equivalent.

xen/arch/arm/include/asm/cache.h +0 -2
@@ -6,8 +6,6 @@
 #define L1_CACHE_SHIFT  (CONFIG_ARM_L1_CACHE_SHIFT)
 #define L1_CACHE_BYTES  (1 << L1_CACHE_SHIFT)
 
-#define __read_mostly __section(".data.read_mostly")
-
 #endif
 /*
  * Local variables:
xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -34,13 +34,13 @@
 #include <xen/lib.h>
 #include <xen/types.h>
 #include <xen/acpi.h>
+#include <xen/cache.h>
 #include <xen/smp.h>
 #include <xen/guest_access.h>
 #include <xen/keyhandler.h>
 #include <xen/param.h>
 #include <xen/trace.h>
 #include <xen/irq.h>
-#include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/iocap.h>
 #include <asm/hpet.h>
xen/arch/x86/flushtlb.c +1 -1
@@ -7,11 +7,11 @@
  * Copyright (c) 2003-2006, K A Fraser
  */
 
+#include <xen/cache.h>
 #include <xen/paging.h>
 #include <xen/sched.h>
 #include <xen/smp.h>
 #include <xen/softirq.h>
-#include <asm/cache.h>
 #include <asm/flushtlb.h>
 #include <asm/invpcid.h>
 #include <asm/nops.h>
xen/arch/x86/genapic/probe.c +1 -1
@@ -6,10 +6,10 @@
 #include <xen/cpumask.h>
 #include <xen/string.h>
 #include <xen/kernel.h>
+#include <xen/cache.h>
 #include <xen/ctype.h>
 #include <xen/init.h>
 #include <xen/param.h>
-#include <asm/cache.h>
 #include <asm/fixmap.h>
 #include <asm/mpspec.h>
 #include <asm/apicdef.h>
xen/arch/x86/guest/hypervisor.c +1 -1
@@ -6,11 +6,11 @@
  *
  * Copyright (c) 2019 Microsoft.
  */
+#include <xen/cache.h>
 #include <xen/cpumask.h>
 #include <xen/init.h>
 #include <xen/types.h>
 
-#include <asm/cache.h>
 #include <asm/guest.h>
 
 static struct hypervisor_ops __read_mostly ops;
xen/arch/x86/include/asm/cache.h +0 -2
@@ -9,8 +9,6 @@
 #define L1_CACHE_SHIFT	(CONFIG_X86_L1_CACHE_SHIFT)
 #define L1_CACHE_BYTES	(1 << L1_CACHE_SHIFT)
 
-#define __read_mostly __section(".data.read_mostly")
-
 #ifndef __ASSEMBLY__
 
 void cache_flush(const void *addr, unsigned int size);
xen/common/version.c +1 -2
@@ -1,3 +1,4 @@
+#include <xen/cache.h>
 #include <xen/compile.h>
 #include <xen/init.h>
 #include <xen/errno.h>
@@ -8,8 +9,6 @@
 #include <xen/elf.h>
 #include <xen/version.h>
 
-#include <asm/cache.h>
-
 const char *xen_compile_date(void)
 {
     return XEN_COMPILE_DATE;
xen/include/xen/cache.h +1 -0
@@ -15,6 +15,7 @@
 #define __cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
 #endif
 
+#define __read_mostly   __section(".data.read_mostly")
 #define __ro_after_init __section(".data.ro_after_init")
 
 #endif /* __LINUX_CACHE_H */
#1 lore raw
Quoted 8 lines · Jan Beulich

There's no need for every arch to define its own identical copy. If down the road an arch needs to customize it, we can add #ifndef around the common #define.

To be on the safe side build-breakage-wise, change a couple of #include <asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is only microarchitectural, and is not the same kind of information as the rest of cache.h

__ro_after_init is only here because __read_mostly is here, but has absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

~Andre

#2 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich

There's no need for every arch to define its own identical copy. If down the road an arch needs to customize it, we can add #ifndef around the common #define.

To be on the safe side build-breakage-wise, change a couple of #include <asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

Quoted 8 lines

__read_mostly is just a section.  It's relationship to the cache is only microarchitectural, and is not the same kind of information as the rest of cache.h

__ro_after_init is only here because __read_mostly is here, but has absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

I would be considering init.h (for having most other __section() uses, and for also needing __read_mostly), but that's not a great place to put these either. In fact I see less connection there than for cache.h. So the primary need is a good suggestion (I'm hesitant to suggest to introduce section.h just for this). In the absence of this, can we perhaps deal with this in a 2nd step, thus not blocking this patch and therefore not needing to then also clean up PPC-specific code?

Jan

#3 lore raw
Quoted 22 lines · Jan Beulich
Quoted 12 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich

There's no need for every arch to define its own identical copy. If down the road an arch needs to customize it, we can add #ifndef around the common #define.

To be on the safe side build-breakage-wise, change a couple of #include <asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

Quoted 8 lines

__read_mostly is just a section.  It's relationship to the cache is only microarchitectural, and is not the same kind of information as the rest of cache.h

__ro_after_init is only here because __read_mostly is here, but has absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

Quoted 7 lines

I would be considering init.h (for having most other __section() uses, and for also needing __read_mostly), but that's not a great place to put these either. In fact I see less connection there than for cache.h. So the primary need is a good suggestion (I'm hesitant to suggest to introduce section.h just for this). In the absence of this, can we perhaps deal with this in a 2nd step, thus not blocking this patch and therefore not needing to then also clean up PPC-specific code?

Oh, also: I we move them elsewhere, it wouldn't be logical for xen/cache.h to include that other header as well. Yet without that the risk of build breakages (perhaps in only exotic configs) is of course quite a bit higher.

Jan

#4 lore raw
In reply to Jan Beulich
Quoted 27 lines · Jan Beulich
Quoted 21 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich

There's no need for every arch to define its own identical copy. If down
the road an arch needs to customize it, we can add #ifndef around the
common #define.

To be on the safe side build-breakage-wise, change a couple of #include
<asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is only
microarchitectural, and is not the same kind of information as the rest
of cache.h

Quoted 4 lines

__ro_after_init is only here because __read_mostly is here, but has absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

Quoted 7 lines

I would be considering init.h (for having most other __section() uses,
and for also needing __read_mostly), but that's not a great place to put these either. In fact I see less connection there than for cache.h.
So the primary need is a good suggestion (I'm hesitant to suggest to introduce section.h just for this).

Andrew sent some suggestions here:
https://lore.kernel.org/xen-devel/[email protected]/

Will that work for you?

Quoted 4 lines

In the absence of this, can we
perhaps deal with this in a 2nd step, thus not blocking this patch and
therefore not needing to then also clean up PPC-specific code?

~ Oleksii

#5 lore raw
Quoted 35 lines · Oleksii
Quoted 27 lines · Jan Beulich
Quoted 21 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich

There's no need for every arch to define its own identical copy. If down
the road an arch needs to customize it, we can add #ifndef around the
common #define.

To be on the safe side build-breakage-wise, change a couple of #include
<asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is only
microarchitectural, and is not the same kind of information as the rest
of cache.h

Quoted 4 lines

__ro_after_init is only here because __read_mostly is here, but has absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

Quoted 7 lines

I would be considering init.h (for having most other __section() uses,
and for also needing __read_mostly), but that's not a great place to put these either. In fact I see less connection there than for cache.h.
So the primary need is a good suggestion (I'm hesitant to suggest to introduce section.h just for this).

Quoted 4 lines

Andrew sent some suggestions here:
https://lore.kernel.org/xen-devel/[email protected]/

Will that work for you?

I still need to properly look at the suggested options.

Jan

#6 lore raw
Quoted 44 lines · Jan Beulich
Quoted 43 lines · Oleksii
Quoted 42 lines · Jan Beulich
Quoted 26 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich

There's no need for every arch to define its own identical copy.
If down
the road an arch needs to customize it, we can add #ifndef around
the
common #define.

Quoted 6 lines

To be on the safe side build-breakage-wise, change a couple of
#include
<asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is
only
microarchitectural, and is not the same kind of information as the
rest
of cache.h

Quoted 5 lines

__ro_after_init is only here because __read_mostly is here, but has
absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

I would be considering init.h (for having most other __section() uses,
and for also needing __read_mostly), but that's not a great place to
put these either. In fact I see less connection there than for cache.h.
So the primary need is a good suggestion (I'm hesitant to suggest to
introduce section.h just for this).

Quoted 6 lines
Quoted 4 lines

Andrew sent some suggestions here:
https://lore.kernel.org/xen-devel/[email protected]/

Will that work for you?

I still need to properly look at the suggested options.

Have you had a chance to review the suggested options?

~ Oleksii

#7 lore raw
Quoted 45 lines · Oleksii
Quoted 44 lines · Jan Beulich
Quoted 43 lines · Oleksii
Quoted 42 lines · Jan Beulich
Quoted 26 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich

There's no need for every arch to define its own identical copy.
If down
the road an arch needs to customize it, we can add #ifndef around
the
common #define.

Quoted 6 lines

To be on the safe side build-breakage-wise, change a couple of
#include
<asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is
only
microarchitectural, and is not the same kind of information as the
rest
of cache.h

Quoted 5 lines

__ro_after_init is only here because __read_mostly is here, but has
absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

I would be considering init.h (for having most other __section() uses,
and for also needing __read_mostly), but that's not a great place to
put these either. In fact I see less connection there than for cache.h.
So the primary need is a good suggestion (I'm hesitant to suggest to
introduce section.h just for this).

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

Andrew sent some suggestions here:
https://lore.kernel.org/xen-devel/[email protected]/

Will that work for you?

I still need to properly look at the suggested options.

Have you had a chance to review the suggested options?

I'm sure you've seen

https://lists.xen.org/archives/html/xen-devel/2024-01/msg00145.html

To add to that - xen/linkage.h is for assembly code only right now. While I'd be happy to add C stuff there, there's an (imo) obvious issue with code churn then: All C files using __read_mostly would then need to be changed to include xen/linkage.h. And no, I don't view including the file once in a "central" other header file as a viable solution: That's where some of our really bad header dependency issues come from. Plus a goal ought to be (imo) that touching a header like this one would better not result in a full re-build of everything, when doing incremental builds.

Same obviously goes for the case of introducing xen/sections.h, i.e. the other proposed alternative.

Bottom line: Given the state of our tree, I still view my proposed placement as the least bad one for the time being. To change my view, I'd still expect a _viable_ alternative proposal to be made.

Jan

#8 lore raw
Quoted 84 lines · Jan Beulich
Quoted 54 lines · Oleksii
Quoted 53 lines · Jan Beulich
Quoted 52 lines · Oleksii
Quoted 51 lines · Jan Beulich
Quoted 30 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich

There's no need for every arch to define its own identical
copy.
If down
the road an arch needs to customize it, we can add #ifndef
around
the
common #define.

Quoted 7 lines

To be on the safe side build-breakage-wise, change a couple
of
#include
<asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is
only
microarchitectural, and is not the same kind of information as
the
rest
of cache.h

Quoted 6 lines

__ro_after_init is only here because __read_mostly is here, but
has
absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

I would be considering init.h (for having most other __section()
uses,
and for also needing __read_mostly), but that's not a great place
to
put these either. In fact I see less connection there than for
cache.h.
So the primary need is a good suggestion (I'm hesitant to suggest
to
introduce section.h just for this).

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

Andrew sent some suggestions here:
https://lore.kernel.org/xen-devel/[email protected]/

Will that work for you?

I still need to properly look at the suggested options.

Have you had a chance to review the suggested options?

I'm sure you've seen

https://lists.xen.org/archives/html/xen-devel/2024-01/msg00145.html

To add to that - xen/linkage.h is for assembly code only right now. While
I'd be happy to add C stuff there, there's an (imo) obvious issue with
code churn then: All C files using __read_mostly would then need to be
changed to include xen/linkage.h. And no, I don't view including the file
once in a "central" other header file as a viable solution: That's where
some of our really bad header dependency issues come from. Plus a goal
ought to be (imo) that touching a header like this one would better not
result in a full re-build of everything, when doing incremental builds.

Quoted 7 lines

Same obviously goes for the case of introducing xen/sections.h, i.e. the
other proposed alternative.

Bottom line: Given the state of our tree, I still view my proposed placement as the least bad one for the time being. To change my view, I'd still expect a _viable_ alternative proposal to be made.

Based on your replies, I can conclude that there is no good place for __read_mostly and __ro_after_init.

If my conclusion is correct, then an introduction of a new header is required. I totally agree that the inclusion of the introduced header to 'central' header only for the reason not to update all C files using __read_mostly macros is not a good solution, but I don't see an issue with an update of all C files which use __read_mostly/__ro_after_init if it is required. I realize that it can be a huge amount of files, but if the situation requires that, it looks not so bad solution. If to look at places where <xen/cache.h> is included now, then there wouldn't be too many places that needed to be updated.

Despite this fact, I don't think that an introduction of xen/section.h is a bad solution, xen/cache.h can also be a good place for it as my understanding of __read_mostly is that it is not only meant for just read-only data, there are performance reasons for using it:
/*
* __read_mostly is used to keep rarely changing variables out of frequently
* updated cachelines. Its use should be reserved for data that is used
* frequently in hot paths. Performance traces can help decide when to use
* this. You want __read_mostly data to be tightly packed, so that in the
* best case multiple frequently read variables for a hot path will be next
* to each other in order to reduce the number of cachelines needed to
* execute a critical path.
*/

Not related to my words above, here is a little remark about the patch changes. Does it make sense to wrap the definition of __read_mostly() by "#ifndef __read_mostly" in case architecture decides to redefine it?

~ Oleksii

#9 lore raw
Quoted 89 lines · Oleksii
Quoted 88 lines · Jan Beulich
Quoted 54 lines · Oleksii
Quoted 53 lines · Jan Beulich
Quoted 52 lines · Oleksii
Quoted 51 lines · Jan Beulich
Quoted 30 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich

There's no need for every arch to define its own identical
copy.
If down
the road an arch needs to customize it, we can add #ifndef
around
the
common #define.

Quoted 7 lines

To be on the safe side build-breakage-wise, change a couple
of
#include
<asm/cache.h> to the xen/ equivalent.

Could we find a better place to put this?

__read_mostly is just a section.  It's relationship to the cache is
only
microarchitectural, and is not the same kind of information as
the
rest
of cache.h

Quoted 6 lines

__ro_after_init is only here because __read_mostly is here, but
has
absolutely nothing to do with caches whatsoever.

If we're cleaning them up, they ought to live elsewhere.

I would be considering init.h (for having most other __section()
uses,
and for also needing __read_mostly), but that's not a great place
to
put these either. In fact I see less connection there than for
cache.h.
So the primary need is a good suggestion (I'm hesitant to suggest
to
introduce section.h just for this).

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

Andrew sent some suggestions here:
https://lore.kernel.org/xen-devel/[email protected]/

Will that work for you?

I still need to properly look at the suggested options.

Have you had a chance to review the suggested options?

I'm sure you've seen

https://lists.xen.org/archives/html/xen-devel/2024-01/msg00145.html

To add to that - xen/linkage.h is for assembly code only right now. While
I'd be happy to add C stuff there, there's an (imo) obvious issue with
code churn then: All C files using __read_mostly would then need to be
changed to include xen/linkage.h. And no, I don't view including the file
once in a "central" other header file as a viable solution: That's where
some of our really bad header dependency issues come from. Plus a goal
ought to be (imo) that touching a header like this one would better not
result in a full re-build of everything, when doing incremental builds.

Same obviously goes for the case of introducing xen/sections.h, i.e. the
other proposed alternative.

Quoted 5 lines
Quoted 3 lines

Bottom line: Given the state of our tree, I still view my proposed placement as the least bad one for the time being. To change my view, I'd still expect a _viable_ alternative proposal to be made.

Based on your replies, I can conclude that there is no good place for __read_mostly and __ro_after_init.

No, no, I'd be happy with xen/linkage.h, if there wasn't the need to then add perhaps many dozens of #include-s throughout the tree.

Quoted 3 lines

Not related to my words above, here is a little remark about the patch changes. Does it make sense to wrap the definition of __read_mostly() by "#ifndef __read_mostly" in case architecture decides to redefine it?

I'd say not ahead of there actually arising such a need.

Jan