Skip to contentSkip to conversation

Add and use get_cpu_cacheinfo_level()

PATCH Superseded Tony Luck 3 participants 11 messages Jun 6, 2024 – Jun 8, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Tony Luck

author maintainer
#0 lore raw

v3 cover Add and use get_cpu_cacheinfo_level()

This helper function came up in discussion of the resctrl patches for Sub-NUMA Cluster (SNC) support. Reinette pointed out[1] that there are already two places where it would clean things up by avoiding open coding. The SNC patches will add two additional call sites.

So rather than have this jammed up as part of the SNC series, I'm posting it as a simple standalone cleanup.

[1] https://lore.kernel.org/all/[email protected]/

---
Changes since v2:

Add lockdep_assert_cpus_held() to enforce what was simply a comment.

Combine patches 2 & 3. Both functions using get_cpu_cacheinfo_level() are called inside rdtgroup_kn_lock_live()/rdtgroup_kn_unlock() code blocks. So cpuhp lock is held.

Tony Luck (2):
cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel) x86/resctrl: Replace open code cacheinfo searches

 include/linux/cacheinfo.h                 | 25 ++++++++++++++++++-----
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 17 ++++++---------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 14 +++++--------
 3 files changed, 31 insertions(+), 25 deletions(-)

base-commit: c3f38fa61af77b49866b006939479069cd451173

Signature · 1 line
2.45.0
author maintainer
#1 lore raw

PATCH v3 1/2 cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

Resctrl code open codes a search for information about a given cache level in a couple of places (and more are on the way).

Provide a new inline function get_cpu_cacheinfo_level() in <linux/cacheinfo.h> to do the search and return a pointer to the cacheinfo structure.

Add lockdep_assert_cpus_held() to enforce the comment that cpuhp lock must be held.

Simplify the existing get_cpu_cacheinfo_id() by using this new function to do the search.

---
 include/linux/cacheinfo.h | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
include/linux/cacheinfo.h +20 -5
index 2cb15fe4fe12..530a16980aea 100644
@@ -3,6 +3,7 @@
 #define _LINUX_CACHEINFO_H
 
 #include <linux/bitops.h>
+#include <linux/cpu.h>
 #include <linux/cpumask.h>
 #include <linux/smp.h>
 
@@ -113,23 +114,37 @@ int acpi_get_cache_info(unsigned int cpu,
 const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_leaf);
 
 /*
- * Get the id of the cache associated with @cpu at level @level.
+ * Get the cacheinfo structure for the cache associated with @cpu at
+ * level @level.
  * cpuhp lock must be held.
  */
-static inline int get_cpu_cacheinfo_id(int cpu, int level)
+static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, int level)
 {
 	struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
 	int i;
 
+	lockdep_assert_cpus_held();
+
 	for (i = 0; i < ci->num_leaves; i++) {
 		if (ci->info_list[i].level == level) {
 			if (ci->info_list[i].attributes & CACHE_ID)
-				return ci->info_list[i].id;
-			return -1;
+				return &ci->info_list[i];
+			return NULL;
 		}
 	}
 
-	return -1;
+	return NULL;
+}
+
+/*
+ * Get the id of the cache associated with @cpu at level @level.
+ * cpuhp lock must be held.
+ */
+static inline int get_cpu_cacheinfo_id(int cpu, int level)
+{
+	struct cacheinfo *ci = get_cpu_cacheinfo_level(cpu, level);
+
+	return ci ? ci->id : -1;
 }
 
 #ifdef CONFIG_ARM64
Signature · 1 line
2.45.0
#2 lore raw

Re: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

kernel test robot noticed the following build errors:

Hi Tony,

kernel test robot noticed the following build errors:

[auto build test ERROR on c3f38fa61af77b49866b006939479069cd451173]

url:    https://github.com/intel-lab-lkp/linux/commits/Tony-Luck/cacheinfo-Add-function-to-get-cacheinfo-for-a-given-cpu-cachelevel/20240607-004316
base:   c3f38fa61af77b49866b006939479069cd451173
patch link:    https://lore.kernel.org/r/20240606164047.318378-2-tony.luck%40intel.com
patch subject: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)
config: riscv-allnoconfig (https://download.01.org/0day-ci/archive/20240607/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240607/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

In file included from arch/riscv/include/asm/cacheinfo.h:9,
from arch/riscv/include/asm/elf.h:16, from include/linux/elf.h:6,
from include/linux/module.h:19,
from include/linux/device/driver.h:21, from include/linux/device.h:32,
from include/linux/node.h:18,
from include/linux/cpu.h:17,
from include/linux/static_call.h:135, from include/linux/tracepoint.h:22, from include/trace/syscall.h:5,
from include/linux/syscalls.h:93, from init/noinitramfs.c:11:
include/linux/cacheinfo.h: In function 'get_cpu_cacheinfo_level':

>> include/linux/cacheinfo.h:126:9: error: implicit declaration of function 'lockdep_assert_cpus_held'; did you mean 'lockdep_assert_not_held'? [-Werror=implicit-function-declaration]
     126 |         lockdep_assert_cpus_held();
         |         ^~~~~~~~~~~~~~~~~~~~~~~~
         |         lockdep_assert_not_held
   include/linux/cpu.h: At top level:
>> include/linux/cpu.h:158:20: warning: conflicting types for 'lockdep_assert_cpus_held'; have 'void(void)'
     158 | static inline void lockdep_assert_cpus_held(void) { }
         |                    ^~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/cpu.h:158:20: error: static declaration of 'lockdep_assert_cpus_held' follows non-static declaration
   include/linux/cacheinfo.h:126:9: note: previous implicit declaration of 'lockdep_assert_cpus_held' with type 'void(void)'
     126 |         lockdep_assert_cpus_held();
         |         ^~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors
--
   In file included from include/linux/cpu.h:17,
                    from include/linux/cacheinfo.h:6,
                    from arch/riscv/include/asm/cacheinfo.h:9,
                    from arch/riscv/include/asm/elf.h:16,
                    from include/linux/elf.h:6,
                    from include/linux/module.h:19,
                    from include/linux/device/driver.h:21,
                    from include/linux/device.h:32,
                    from include/linux/blk_types.h:11,
                    from include/linux/writeback.h:13,
                    from include/linux/memcontrol.h:23,
                    from include/linux/swap.h:9,
                    from mm/filemap.c:23:
>> include/linux/node.h:96:25: error: field 'dev' has incomplete type
      96 |         struct device   dev;
         |                         ^~~
>> include/linux/cpu.h:30:23: error: field 'dev' has incomplete type
      30 |         struct device dev;
         |                       ^~~
>> include/linux/cpu.h:45:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      45 | extern int cpu_add_dev_attr(struct device_attribute *attr);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:46:40: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      46 | extern void cpu_remove_dev_attr(struct device_attribute *attr);
         |                                        ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:52:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      52 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:54:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      54 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:56:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      56 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:58:50: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      58 |                                           struct device_attribute *attr, char *buf);
         |                                                  ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:60:37: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      60 |                              struct device_attribute *attr, char *buf);
         |                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:62:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      62 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:64:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      64 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:67:46: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      67 |                                       struct device_attribute *attr, char *buf);
         |                                              ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:68:58: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      68 | extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
         |                                                          ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:70:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      70 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:73:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      73 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:75:53: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      75 |                                              struct device_attribute *attr, char *buf);
         |                                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:77:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      77 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:79:55: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      79 |                                                struct device_attribute *attr, char *buf);
         |                                                       ^~~~~~~~~~~~~~~~

--
In file included from include/linux/cpu.h:17,
from include/linux/cacheinfo.h:6, from arch/riscv/include/asm/cacheinfo.h:9, from arch/riscv/include/asm/elf.h:16, from include/linux/elf.h:6,
from include/linux/module.h:19, from include/linux/device/driver.h:21, from include/linux/device.h:32, from include/linux/blk_types.h:11, from include/linux/writeback.h:13, from include/linux/memcontrol.h:23, from include/linux/swap.h:9, from mm/page-writeback.c:21:

>> include/linux/node.h:96:25: error: field 'dev' has incomplete type
      96 |         struct device   dev;
         |                         ^~~
>> include/linux/cpu.h:30:23: error: field 'dev' has incomplete type
      30 |         struct device dev;
         |                       ^~~
>> include/linux/cpu.h:45:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      45 | extern int cpu_add_dev_attr(struct device_attribute *attr);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:46:40: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      46 | extern void cpu_remove_dev_attr(struct device_attribute *attr);
         |                                        ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:52:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      52 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:54:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      54 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:56:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      56 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:58:50: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      58 |                                           struct device_attribute *attr, char *buf);
         |                                                  ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:60:37: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      60 |                              struct device_attribute *attr, char *buf);
         |                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:62:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      62 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:64:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      64 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:67:46: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      67 |                                       struct device_attribute *attr, char *buf);
         |                                              ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:68:58: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      68 | extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
         |                                                          ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:70:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      70 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:73:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      73 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:75:53: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      75 |                                              struct device_attribute *attr, char *buf);
         |                                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:77:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      77 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:79:55: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      79 |                                                struct device_attribute *attr, char *buf);
         |                                                       ^~~~~~~~~~~~~~~~
   mm/page-writeback.c: In function 'cgwb_calc_thresh':
   mm/page-writeback.c:900:39: warning: variable 'gdtc' set but not used [-Wunused-but-set-variable]
     900 |         struct dirty_throttle_control gdtc = { GDTC_INIT_NO_WB };
         |                                       ^~~~
--
   In file included from include/linux/cacheinfo.h:6,
                    from arch/riscv/include/asm/cacheinfo.h:9,
                    from arch/riscv/include/asm/elf.h:16,
                    from include/linux/elf.h:6,
                    from include/linux/module.h:19,
                    from include/linux/device/driver.h:21,
                    from include/linux/device.h:32,
                    from include/linux/node.h:18,
                    from include/linux/memory.h:19,
                    from mm/mm_init.c:13:
>> include/linux/cpu.h:30:23: error: field 'dev' has incomplete type
      30 |         struct device dev;
         |                       ^~~
>> include/linux/cpu.h:45:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      45 | extern int cpu_add_dev_attr(struct device_attribute *attr);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:46:40: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      46 | extern void cpu_remove_dev_attr(struct device_attribute *attr);
         |                                        ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:52:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      52 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:54:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      54 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:56:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      56 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:58:50: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      58 |                                           struct device_attribute *attr, char *buf);
         |                                                  ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:60:37: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      60 |                              struct device_attribute *attr, char *buf);
         |                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:62:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      62 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:64:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      64 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:67:46: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      67 |                                       struct device_attribute *attr, char *buf);
         |                                              ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:68:58: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      68 | extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
         |                                                          ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:70:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      70 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:73:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      73 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:75:53: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      75 |                                              struct device_attribute *attr, char *buf);
         |                                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:77:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      77 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:79:55: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      79 |                                                struct device_attribute *attr, char *buf);
         |                                                       ^~~~~~~~~~~~~~~~
--
   In file included from include/linux/cpu.h:17,
                    from include/linux/cacheinfo.h:6,
                    from arch/riscv/include/asm/cacheinfo.h:9,
                    from arch/riscv/include/asm/elf.h:16,
                    from include/linux/elf.h:6,
                    from include/linux/module.h:19,
                    from include/linux/device/driver.h:21,
                    from include/linux/device.h:32,
                    from include/linux/blk_types.h:11,
                    from include/linux/writeback.h:13,
                    from include/linux/memcontrol.h:23,
                    from include/linux/swap.h:9,
                    from mm/slub.c:14:
>> include/linux/node.h:96:25: error: field 'dev' has incomplete type
      96 |         struct device   dev;
         |                         ^~~
>> include/linux/cpu.h:30:23: error: field 'dev' has incomplete type
      30 |         struct device dev;
         |                       ^~~
>> include/linux/cpu.h:45:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      45 | extern int cpu_add_dev_attr(struct device_attribute *attr);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:46:40: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      46 | extern void cpu_remove_dev_attr(struct device_attribute *attr);
         |                                        ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:52:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      52 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:54:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      54 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:56:43: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      56 |                                    struct device_attribute *attr, char *buf);
         |                                           ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:58:50: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      58 |                                           struct device_attribute *attr, char *buf);
         |                                                  ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:60:37: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      60 |                              struct device_attribute *attr, char *buf);
         |                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:62:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      62 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:64:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      64 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:67:46: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      67 |                                       struct device_attribute *attr, char *buf);
         |                                              ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:68:58: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      68 | extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
         |                                                          ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:70:48: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      70 |                                         struct device_attribute *attr,
         |                                                ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:73:41: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      73 |                                  struct device_attribute *attr, char *buf);
         |                                         ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:75:53: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      75 |                                              struct device_attribute *attr, char *buf);
         |                                                     ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:77:36: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      77 |                             struct device_attribute *attr, char *buf);
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/cpu.h:79:55: warning: 'struct device_attribute' declared inside parameter list will not be visible outside of this definition or declaration
      79 |                                                struct device_attribute *attr, char *buf);
         |                                                       ^~~~~~~~~~~~~~~~
   mm/slub.c: In function 'slab_post_alloc_hook':
   mm/slub.c:3904:29: warning: variable 'obj_exts' set but not used [-Wunused-but-set-variable]
    3904 |         struct slabobj_ext *obj_exts;
         |                             ^~~~~~~~

..

vim +126 include/linux/cacheinfo.h

115
116 /*
117 * Get the cacheinfo structure for the cache associated with @cpu at
118 * level @level.
119 * cpuhp lock must be held.
120 */
121 static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, int level)
122 {
123 struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
124 int i;
125

 > 126		lockdep_assert_cpus_held();

127
128 for (i = 0; i < ci->num_leaves; i++) {
129 if (ci->info_list[i].level == level) {
130 if (ci->info_list[i].attributes & CACHE_ID)
131 return &ci->info_list[i];
132 return NULL;
133 }
134 }
135
136 return NULL;
137 }
138

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

In reply to Tony Luck
kernel test robot noticed the following build errors:

Hi Tony,

kernel test robot noticed the following build errors:

[auto build test ERROR on c3f38fa61af77b49866b006939479069cd451173]

url:    https://github.com/intel-lab-lkp/linux/commits/Tony-Luck/cacheinfo-Add-function-to-get-cacheinfo-for-a-given-cpu-cachelevel/20240607-004316
base:   c3f38fa61af77b49866b006939479069cd451173
patch link:    https://lore.kernel.org/r/20240606164047.318378-2-tony.luck%40intel.com
patch subject: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)
config: riscv-defconfig (https://download.01.org/0day-ci/archive/20240607/[email protected]/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project d7d2d4f53fc79b4b58e8d8d08151b577c3699d4a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240607/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

In file included from io_uring/io_uring.c:45:
In file included from include/linux/syscalls.h:93:
In file included from include/trace/syscall.h:5:
In file included from include/linux/tracepoint.h:22:
In file included from include/linux/static_call.h:135:
In file included from include/linux/cpu.h:17:
In file included from include/linux/node.h:18:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/riscv/include/asm/elf.h:16:
In file included from arch/riscv/include/asm/cacheinfo.h:9:

>> include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/io_uring.c:45:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:5:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
>> include/linux/cpu.h:143:13: error: conflicting types for 'lockdep_assert_cpus_held'
     143 | extern void lockdep_assert_cpus_held(void);
         |             ^
   include/linux/cacheinfo.h:126:2: note: previous implicit declaration is here
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/io_uring.c:45:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:6:
   In file included from include/linux/ring_buffer.h:5:
   In file included from include/linux/mm.h:2253:
   include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from io_uring/io_uring.c:56:
   include/linux/mman.h:158:9: warning: division by zero is undefined [-Wdivision-by-zero]
     158 |                _calc_vm_trans(flags, MAP_SYNC,       VM_SYNC      ) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~
   include/linux/mman.h:159:9: warning: division by zero is undefined [-Wdivision-by-zero]
     159 |                _calc_vm_trans(flags, MAP_STACK,      VM_NOHUGEPAGE) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~

3 warnings and 2 errors generated.
--
In file included from io_uring/opdef.c:11:
In file included from io_uring/io_uring.h:6:
In file included from include/linux/resume_user_mode.h:8:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:9:
In file included from include/linux/interrupt.h:21:
In file included from arch/riscv/include/asm/sections.h:9:
In file included from include/linux/mm.h:2253:
include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]

     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from io_uring/opdef.c:11:
   In file included from io_uring/io_uring.h:6:
   In file included from include/linux/resume_user_mode.h:8:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
   In file included from include/linux/cacheinfo.h:6:
   In file included from include/linux/cpu.h:17:
>> include/linux/node.h:96:16: error: field has incomplete type 'struct device'
      96 |         struct device   dev;
         |                         ^
   include/linux/bitmap.h:17:8: note: forward declaration of 'struct device'
      17 | struct device;
         |        ^
   In file included from io_uring/opdef.c:11:
   In file included from io_uring/io_uring.h:6:
   In file included from include/linux/resume_user_mode.h:8:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
   In file included from include/linux/cacheinfo.h:6:
>> include/linux/cpu.h:30:16: error: field has incomplete type 'struct device'
      30 |         struct device dev;
         |                       ^
   include/linux/bitmap.h:17:8: note: forward declaration of 'struct device'
      17 | struct device;
         |        ^
   In file included from io_uring/opdef.c:11:
   In file included from io_uring/io_uring.h:6:
   In file included from include/linux/resume_user_mode.h:8:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
   In file included from include/linux/cacheinfo.h:6:
>> include/linux/cpu.h:45:36: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      45 | extern int cpu_add_dev_attr(struct device_attribute *attr);
         |                                    ^
   include/linux/cpu.h:46:40: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      46 | extern void cpu_remove_dev_attr(struct device_attribute *attr);
         |                                        ^
   include/linux/cpu.h:52:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      52 |                                  struct device_attribute *attr, char *buf);
         |                                         ^
   include/linux/cpu.h:54:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      54 |                                    struct device_attribute *attr, char *buf);
         |                                           ^
   include/linux/cpu.h:56:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      56 |                                    struct device_attribute *attr, char *buf);
         |                                           ^
   include/linux/cpu.h:58:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      58 |                                           struct device_attribute *attr, char *buf);
         |                                                  ^
   include/linux/cpu.h:60:16: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      60 |                              struct device_attribute *attr, char *buf);
         |                                     ^
   include/linux/cpu.h:62:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      62 |                             struct device_attribute *attr, char *buf);
         |                                    ^
   include/linux/cpu.h:64:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      64 |                                         struct device_attribute *attr,
         |                                                ^
   include/linux/cpu.h:67:18: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      67 |                                       struct device_attribute *attr, char *buf);
         |                                              ^
   include/linux/cpu.h:68:58: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      68 | extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
         |                                                          ^
   include/linux/cpu.h:70:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      70 |                                         struct device_attribute *attr,
         |                                                ^
   include/linux/cpu.h:73:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      73 |                                  struct device_attribute *attr, char *buf);
         |                                         ^
   include/linux/cpu.h:75:18: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      75 |                                              struct device_attribute *attr, char *buf);
         |                                                     ^
   include/linux/cpu.h:77:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      77 |                             struct device_attribute *attr, char *buf);
         |                                    ^
   include/linux/cpu.h:79:20: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      79 |                                                struct device_attribute *attr, char *buf);
         |                                                       ^

17 warnings and 2 errors generated.
--
In file included from io_uring/poll.c:6:
In file included from include/linux/mm.h:2253:
include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]

     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from io_uring/poll.c:12:
   In file included from include/trace/events/io_uring.h:8:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
   In file included from include/linux/cpu.h:17:
   In file included from include/linux/node.h:18:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
>> include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/poll.c:12:
   In file included from include/trace/events/io_uring.h:8:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
>> include/linux/cpu.h:143:13: error: conflicting types for 'lockdep_assert_cpus_held'
     143 | extern void lockdep_assert_cpus_held(void);
         |             ^
   include/linux/cacheinfo.h:126:2: note: previous implicit declaration is here
     126 |         lockdep_assert_cpus_held();
         |         ^

1 warning and 2 errors generated.
--
In file included from io_uring/timeout.c:7:
In file included from include/trace/events/io_uring.h:8:
In file included from include/linux/tracepoint.h:22:
In file included from include/linux/static_call.h:135:
In file included from include/linux/cpu.h:17:
In file included from include/linux/node.h:18:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/riscv/include/asm/elf.h:16:
In file included from arch/riscv/include/asm/cacheinfo.h:9:

>> include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/timeout.c:7:
   In file included from include/trace/events/io_uring.h:8:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
>> include/linux/cpu.h:143:13: error: conflicting types for 'lockdep_assert_cpus_held'
     143 | extern void lockdep_assert_cpus_held(void);
         |             ^
   include/linux/cacheinfo.h:126:2: note: previous implicit declaration is here
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/timeout.c:7:
   In file included from include/trace/events/io_uring.h:10:
   In file included from include/linux/io_uring_types.h:4:
   In file included from include/linux/blkdev.h:9:
   In file included from include/linux/blk_types.h:10:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:8:
   In file included from include/linux/cacheflush.h:5:
   In file included from arch/riscv/include/asm/cacheflush.h:9:
   In file included from include/linux/mm.h:2253:
   include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~

1 warning and 2 errors generated.
--
In file included from io_uring/register.c:9:
In file included from include/linux/syscalls.h:93:
In file included from include/trace/syscall.h:5:
In file included from include/linux/tracepoint.h:22:
In file included from include/linux/static_call.h:135:
In file included from include/linux/cpu.h:17:
In file included from include/linux/node.h:18:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/riscv/include/asm/elf.h:16:
In file included from arch/riscv/include/asm/cacheinfo.h:9:

>> include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/register.c:9:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:5:
   In file included from include/linux/tracepoint.h:22:
   In file included from include/linux/static_call.h:135:
>> include/linux/cpu.h:143:13: error: conflicting types for 'lockdep_assert_cpus_held'
     143 | extern void lockdep_assert_cpus_held(void);
         |             ^
   include/linux/cacheinfo.h:126:2: note: previous implicit declaration is here
     126 |         lockdep_assert_cpus_held();
         |         ^
   In file included from io_uring/register.c:9:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:6:
   In file included from include/linux/ring_buffer.h:5:
   In file included from include/linux/mm.h:2253:
   include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   io_uring/register.c:175:24: warning: arithmetic between different enumeration types ('enum io_uring_register_restriction_op' and 'enum io_uring_register_op') [-Wenum-enum-conversion]
     175 |         if (!arg || nr_args > IORING_MAX_RESTRICTIONS)
         |                               ^~~~~~~~~~~~~~~~~~~~~~~
   io_uring/register.c:31:58: note: expanded from macro 'IORING_MAX_RESTRICTIONS'
      31 | #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
         |                                  ~~~~~~~~~~~~~~~~~~~~~~~ ^
      32 |                                  IORING_REGISTER_LAST + IORING_OP_LAST)
         |                                  ~~~~~~~~~~~~~~~~~~~~

2 warnings and 2 errors generated.
--
In file included from mm/filemap.c:15:
In file included from include/linux/dax.h:6:
In file included from include/linux/mm.h:2253:
include/linux/vmstat.h:514:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]

     514 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   In file included from mm/filemap.c:23:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
   In file included from include/linux/cacheinfo.h:6:
   In file included from include/linux/cpu.h:17:
>> include/linux/node.h:96:16: error: field has incomplete type 'struct device'
      96 |         struct device   dev;
         |                         ^
   include/linux/bitmap.h:17:8: note: forward declaration of 'struct device'
      17 | struct device;
         |        ^
   In file included from mm/filemap.c:23:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
   In file included from include/linux/cacheinfo.h:6:
>> include/linux/cpu.h:30:16: error: field has incomplete type 'struct device'
      30 |         struct device dev;
         |                       ^
   include/linux/bitmap.h:17:8: note: forward declaration of 'struct device'
      17 | struct device;
         |        ^
   In file included from mm/filemap.c:23:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/riscv/include/asm/elf.h:16:
   In file included from arch/riscv/include/asm/cacheinfo.h:9:
   In file included from include/linux/cacheinfo.h:6:
>> include/linux/cpu.h:45:36: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      45 | extern int cpu_add_dev_attr(struct device_attribute *attr);
         |                                    ^
   include/linux/cpu.h:46:40: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      46 | extern void cpu_remove_dev_attr(struct device_attribute *attr);
         |                                        ^
   include/linux/cpu.h:52:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      52 |                                  struct device_attribute *attr, char *buf);
         |                                         ^
   include/linux/cpu.h:54:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      54 |                                    struct device_attribute *attr, char *buf);
         |                                           ^
   include/linux/cpu.h:56:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      56 |                                    struct device_attribute *attr, char *buf);
         |                                           ^
   include/linux/cpu.h:58:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      58 |                                           struct device_attribute *attr, char *buf);
         |                                                  ^
   include/linux/cpu.h:60:16: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      60 |                              struct device_attribute *attr, char *buf);
         |                                     ^
   include/linux/cpu.h:62:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      62 |                             struct device_attribute *attr, char *buf);
         |                                    ^
   include/linux/cpu.h:64:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      64 |                                         struct device_attribute *attr,
         |                                                ^
   include/linux/cpu.h:67:18: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      67 |                                       struct device_attribute *attr, char *buf);
         |                                              ^
   include/linux/cpu.h:68:58: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      68 | extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
         |                                                          ^
   include/linux/cpu.h:70:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      70 |                                         struct device_attribute *attr,
         |                                                ^
   include/linux/cpu.h:73:13: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      73 |                                  struct device_attribute *attr, char *buf);
         |                                         ^
   include/linux/cpu.h:75:18: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      75 |                                              struct device_attribute *attr, char *buf);
         |                                                     ^
   include/linux/cpu.h:77:15: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      77 |                             struct device_attribute *attr, char *buf);
         |                                    ^
   include/linux/cpu.h:79:20: warning: declaration of 'struct device_attribute' will not be visible outside of this function [-Wvisibility]
      79 |                                                struct device_attribute *attr, char *buf);
         |                                                       ^
   In file included from mm/filemap.c:26:
   include/linux/mman.h:158:9: warning: division by zero is undefined [-Wdivision-by-zero]
     158 |                _calc_vm_trans(flags, MAP_SYNC,       VM_SYNC      ) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~
   include/linux/mman.h:159:9: warning: division by zero is undefined [-Wdivision-by-zero]
     159 |                _calc_vm_trans(flags, MAP_STACK,      VM_NOHUGEPAGE) |
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/mman.h:136:21: note: expanded from macro '_calc_vm_trans'
     136 |    : ((x) & (bit1)) / ((bit1) / (bit2))))
         |                     ^ ~~~~~~~~~~~~~~~~~

19 warnings and 2 errors generated.
..

vim +/lockdep_assert_cpus_held +126 include/linux/cacheinfo.h

115
116 /*
117 * Get the cacheinfo structure for the cache associated with @cpu at
118 * level @level.
119 * cpuhp lock must be held.
120 */
121 static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, int level)
122 {
123 struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
124 int i;
125

 > 126		lockdep_assert_cpus_held();

127
128 for (i = 0; i < ci->num_leaves; i++) {
129 if (ci->info_list[i].level == level) {
130 if (ci->info_list[i].attributes & CACHE_ID)
131 return &ci->info_list[i];
132 return NULL;
133 }
134 }
135
136 return NULL;
137 }
138

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#4 lore raw

RE: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

In reply to Tony Luck

+ lockdep_assert_cpus_held();
+

lkp says this breaks riscv-allnoconfig and riscv-defconfig

In file included from arch/riscv/include/asm/cacheinfo.h:9:

Quoted 1 line
Quoted 1 line

include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

     126 |         lockdep_assert_cpus_held();

but I'm not really sure why. I added "#include <linux/cpu.h>" to <linux/cpuinfo,h> to deal with similar warning when building for x86.

-Tony

author maintainer
#5 lore raw

RE: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

Quoted 10 lines
(quoted diff) +2 -0
+     lockdep_assert_cpus_held();
+

lkp says this breaks riscv-allnoconfig and riscv-defconfig

In file included from arch/riscv/include/asm/cacheinfo.h:9:

Quoted 1 line
Quoted 1 line

include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

     126 |         lockdep_assert_cpus_held();

but I'm not really sure why. I added "#include <linux/cpu.h>" to <linux/cpuinfo,h> to deal with similar warning when building for x86.

Ah. The full trace from lkp explains:

In file included from io_uring/io_uring.c:45:
In file included from include/linux/syscalls.h:93:
In file included from include/trace/syscall.h:5:
In file included from include/linux/tracepoint.h:22:
In file included from include/linux/static_call.h:135:
In file included from include/linux/cpu.h:17: <<<< only part way through cpu.h, lockdep_assert_cpus_held not defined yet
In file included from include/linux/node.h:18:
In file included from include/linux/device.h:32:
In file included from include/linux/device/driver.h:21:
In file included from include/linux/module.h:19:
In file included from include/linux/elf.h:6:
In file included from arch/riscv/include/asm/elf.h:16:
In file included from arch/riscv/include/asm/cacheinfo.h:9: <<< doesn't matter that this includes cpu.h because of #ifndef _LINUX_CPU_H_

Quoted 1 line
Quoted 1 line

include/linux/cacheinfo.h:126:2: error: call to undeclared function 'lockdep_assert_cpus_held'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

     126 |         lockdep_assert_cpus_held();

So this is #include hell that many others have complained about.

How much do you *REALLY* want that lockdep_assert_cpus_held() to be in <linux/cacheinfo.h>

The lack of an assert did not come up when James added get_cpu_cacheinfo_id()

https://lkml.kernel.org/r/[email protected]

-Tony

maintainer
#6 lore raw

Re: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

Quoted 1 line · Tony

So this is #include hell that many others have complained about.

Starts much earlier:

In file included from ./include/linux/cpu.h:17,

                 from ./include/linux/cacheinfo.h:6,
                 from ./arch/riscv/include/asm/cacheinfo.h:9,
                 from ./arch/riscv/include/asm/elf.h:16,
                 from ./include/linux/elf.h:6,
                 from ./include/linux/module.h:19,
                 from ./include/linux/device/driver.h:21,
                 from ./include/linux/device.h:32,
                 from ./include/linux/acpi.h:14,
                 from drivers/irqchip/irqchip.c:11:
./include/linux/node.h:96:25: error: field 'dev' has incomplete type
   96 |         struct device   dev;
      |

And yeah, this is an abomination.

Quoted 1 line

How much do you *REALLY* want that lockdep_assert_cpus_held() to be in <linux/cacheinfo.h>

If we had an easy fix sure but this really is a nightmare after trying it a bit here too.

Oh well, some other time.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#7 lore raw

RE: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

Quoted 6 lines

And yeah, this is an abomination.

Quoted 1 line

How much do you *REALLY* want that lockdep_assert_cpus_held() to be in <linux/cacheinfo.h>

If we had an easy fix sure but this really is a nightmare after trying it a bit here too.

I tried something too. I moved the cpu hotplug lock bits out of <linux/cpu.h> into their own file <linux/cpuhplock.h>. Made cpu.h include this new file to keep things the same for anything that includes cpu.h.

In the change to cacheinfo.h I just include the new cpuhplock.h as all it needs is the lockdep_assert_cpus_held() declaration.

I haven't heard back from lkp yet ... but it may be promising. Code is the top three commits in:

git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git get_cpu_cacheinfo_level

Does this look like an OK direction?

Any better name for the new header?

While I'm moving those declarations, should I zap the "extern " from the function ones to match current fashion for this (checkpatch barfs all over them)?

-Tony

maintainer
#8 lore raw

Re: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

Quoted 1 line · Tony

Does this look like an OK direction?

Yap, actually pretty nice and straight-forward at a quick glance.

Quoted 1 line

Any better name for the new header?

Considering how we call that machinery "cpuhp" everywhere, I think it actually fits perfectly.

Quoted 3 lines

While I'm moving those declarations, should I zap the "extern " from the function ones to match current fashion for this (checkpatch barfs all over them)?

Yeah, you can ignore checkpatch or simply do another patch ontop which does just that. Code movement should be only mechanical movement, with no other changes for ease of review.

In any case, thanks for doing that, that looks real good to me.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#9 lore raw

Re: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)

In reply to Tony Luck
kernel test robot noticed the following build warnings:

Hi Tony,

kernel test robot noticed the following build warnings:

[auto build test WARNING on c3f38fa61af77b49866b006939479069cd451173]

url:    https://github.com/intel-lab-lkp/linux/commits/Tony-Luck/cacheinfo-Add-function-to-get-cacheinfo-for-a-given-cpu-cachelevel/20240607-004316
base:   c3f38fa61af77b49866b006939479069cd451173
patch link:    https://lore.kernel.org/r/20240606164047.318378-2-tony.luck%40intel.com
patch subject: [PATCH v3 1/2] cacheinfo: Add function to get cacheinfo for a given (cpu, cachelevel)
config: riscv-randconfig-001-20240608 (https://download.01.org/0day-ci/archive/20240608/[email protected]/config)
compiler: riscv64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240608/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/module.h:19,
from include/linux/device/driver.h:21,
from include/linux/device.h:32,
from include/linux/node.h:18,
from include/linux/cpu.h:17,
from include/linux/cacheinfo.h:6,
from arch/riscv/include/asm/cacheinfo.h:9,
from arch/riscv/include/asm/elf.h:16,
from arch/riscv/kernel/vector.c:19:
include/linux/elf.h:38:5: warning: "ELF_CLASS" is not defined, evaluates to 0 [-Wundef]

      38 | #if ELF_CLASS == ELFCLASS32
         |     ^~~~~~~~~
>> arch/riscv/include/asm/elf.h:137: warning: "SET_PERSONALITY" redefined
     137 | #define SET_PERSONALITY(ex)                                     \
         | 
   include/linux/elf.h:16: note: this is the location of the previous definition
      16 | #define SET_PERSONALITY(ex) \
         | 

--
In file included from arch/riscv/include/asm/elf.h:16,
from include/linux/elf.h:6, from include/linux/module.h:19, from include/linux/device/driver.h:21, from include/linux/device.h:32, from include/linux/node.h:18, from include/linux/cpu.h:17, from include/linux/cacheinfo.h:6, from drivers/cache/ax45mp_cache.c:9:

>> arch/riscv/include/asm/cacheinfo.h:12:65: warning: 'struct cacheinfo' declared inside parameter list will not be visible outside of this definition or declaration
      12 |         const struct attribute_group * (*get_priv_group)(struct cacheinfo
         |                                                                 ^~~~~~~~~
>> arch/riscv/include/asm/cacheinfo.h:17:42: warning: 'enum cache_type' declared inside parameter list will not be visible outside of this definition or declaration
      17 | uintptr_t get_cache_size(u32 level, enum cache_type type);
         |                                          ^~~~~~~~~~
   arch/riscv/include/asm/cacheinfo.h:18:46: warning: 'enum cache_type' declared inside parameter list will not be visible outside of this definition or declaration
      18 | uintptr_t get_cache_geometry(u32 level, enum cache_type type);
         |                                              ^~~~~~~~~~

vim +12 arch/riscv/include/asm/cacheinfo.h

087958a17658dc Yash Shah 2020-02-20 10

087958a17658dc Yash Shah 2020-02-20  11  struct riscv_cacheinfo_ops {
087958a17658dc Yash Shah 2020-02-20 @12  	const struct attribute_group * (*get_priv_group)(struct cacheinfo
087958a17658dc Yash Shah 2020-02-20  13  							*this_leaf);
087958a17658dc Yash Shah 2020-02-20  14  };
087958a17658dc Yash Shah 2020-02-20  15  
087958a17658dc Yash Shah 2020-02-20  16  void riscv_set_cacheinfo_ops(struct riscv_cacheinfo_ops *ops);
38f5bd23deae24 Zong Li   2020-08-31 @17  uintptr_t get_cache_size(u32 level, enum cache_type type);
38f5bd23deae24 Zong Li   2020-08-31  18  uintptr_t get_cache_geometry(u32 level, enum cache_type type);

087958a17658dc Yash Shah 2020-02-20 19

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#10 lore raw

PATCH v3 2/2 x86/resctrl: Replace open code cacheinfo searches

In reply to Tony Luck

pseudo_lock_region_init() and rdtgroup_cbm_to_size() open code a search for details of a particular cache level.

Replace with get_cpu_cacheinfo_level()

---
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 17 ++++++-----------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 14 +++++---------
 2 files changed, 11 insertions(+), 20 deletions(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +6 -11
index aacf236dfe3b..1bbfd3c1e300 100644
@@ -292,9 +292,8 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)
  */
 static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
 {
-	struct cpu_cacheinfo *ci;
+	struct cacheinfo *ci;
 	int ret;
-	int i;
 
 	/* Pick the first cpu we find that is associated with the cache. */
 	plr->cpu = cpumask_first(&plr->d->cpu_mask);
@@ -306,15 +305,11 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)
 		goto out_region;
 	}
 
-	ci = get_cpu_cacheinfo(plr->cpu);
-
-	plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm);
-
-	for (i = 0; i < ci->num_leaves; i++) {
-		if (ci->info_list[i].level == plr->s->res->cache_level) {
-			plr->line_size = ci->info_list[i].coherency_line_size;
-			return 0;
-		}
+	ci = get_cpu_cacheinfo_level(plr->cpu, plr->s->res->cache_level);
+	if (ci) {
+		plr->line_size = ci->coherency_line_size;
+		plr->size = rdtgroup_cbm_to_size(plr->s->res, plr->d, plr->cbm);
+		return 0;
 	}
 
 	ret = -1;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -9
index 02f213f1c51c..cb68a121dabb 100644
@@ -1450,18 +1450,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
 				  struct rdt_domain *d, unsigned long cbm)
 {
-	struct cpu_cacheinfo *ci;
 	unsigned int size = 0;
-	int num_b, i;
+	struct cacheinfo *ci;
+	int num_b;
 
 	num_b = bitmap_weight(&cbm, r->cache.cbm_len);
-	ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask));
-	for (i = 0; i < ci->num_leaves; i++) {
-		if (ci->info_list[i].level == r->cache_level) {
-			size = ci->info_list[i].size / r->cache.cbm_len * num_b;
-			break;
-		}
-	}
+	ci = get_cpu_cacheinfo_level(cpumask_any(&d->cpu_mask), r->cache_level);
+	if (ci)
+		size = ci->size / r->cache.cbm_len * num_b;
 
 	return size;
 }
Signature · 1 line
2.45.0