~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/kernel/topology.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/arm/kernel/topology.c (Version linux-6.11.5) and /arch/sparc/kernel/topology.c (Version linux-2.6.32.71)


  1 /*                                                  1 
  2  * arch/arm/kernel/topology.c                     
  3  *                                                
  4  * Copyright (C) 2011 Linaro Limited.             
  5  * Written by: Vincent Guittot                    
  6  *                                                
  7  * based on arch/sh/kernel/topology.c             
  8  *                                                
  9  * This file is subject to the terms and condi    
 10  * License.  See the file "COPYING" in the mai    
 11  * for more details.                              
 12  */                                               
 13                                                   
 14 #include <linux/arch_topology.h>                  
 15 #include <linux/cpu.h>                            
 16 #include <linux/cpufreq.h>                        
 17 #include <linux/cpumask.h>                        
 18 #include <linux/export.h>                         
 19 #include <linux/init.h>                           
 20 #include <linux/percpu.h>                         
 21 #include <linux/node.h>                           
 22 #include <linux/nodemask.h>                       
 23 #include <linux/of.h>                             
 24 #include <linux/sched.h>                          
 25 #include <linux/sched/topology.h>                 
 26 #include <linux/slab.h>                           
 27 #include <linux/string.h>                         
 28                                                   
 29 #include <asm/cpu.h>                              
 30 #include <asm/cputype.h>                          
 31 #include <asm/topology.h>                         
 32                                                   
 33 /*                                                
 34  * cpu capacity scale management                  
 35  */                                               
 36                                                   
 37 /*                                                
 38  * cpu capacity table                             
 39  * This per cpu data structure describes the r    
 40  * On a heteregenous system, cores don't have     
 41  * and we reflect that difference in the cpu_c    
 42  * can take this difference into account durin    
 43  * structure is preferred because each CPU upd    
 44  * during the load balance except for idle cor    
 45  * to run the sched_balance_domains for all id    
 46  * updated during this sequence.                  
 47  */                                               
 48                                                   
 49 #ifdef CONFIG_OF                                  
 50 struct cpu_efficiency {                           
 51         const char *compatible;                   
 52         unsigned long efficiency;                 
 53 };                                                
 54                                                   
 55 /*                                                
 56  * Table of relative efficiency of each proces    
 57  * The efficiency value must fit in 20bit and     
 58  * cpu_scale value must be in the range           
 59  *   0 < cpu_scale < 3*SCHED_CAPACITY_SCALE/2     
 60  * in order to return at most 1 when DIV_ROUND    
 61  * is used to compute the capacity of a CPU.      
 62  * Processors that are not defined in the tabl    
 63  * use the default SCHED_CAPACITY_SCALE value     
 64  */                                               
 65 static const struct cpu_efficiency table_effic    
 66         {"arm,cortex-a15", 3891},                 
 67         {"arm,cortex-a7",  2048},                 
 68         {NULL, },                                 
 69 };                                                
 70                                                   
 71 static unsigned long *__cpu_capacity;             
 72 #define cpu_capacity(cpu)       __cpu_capacity    
 73                                                   
 74 static unsigned long middle_capacity = 1;         
 75 static bool cap_from_dt = true;                   
 76                                                   
 77 /*                                                
 78  * Iterate all CPUs' descriptor in DT and comp    
 79  * (as per table_efficiency). Also calculate a    
 80  * as close as possible to  (max{eff_i} - min{    
 81  * This is later used to scale the cpu_capacit    
 82  * 'average' CPU is of middle capacity. Also s    
 83  * table_efficiency[] and update_cpu_capacity(    
 84  */                                               
 85 static void __init parse_dt_topology(void)        
 86 {                                                 
 87         const struct cpu_efficiency *cpu_eff;     
 88         struct device_node *cn = NULL;            
 89         unsigned long min_capacity = ULONG_MAX    
 90         unsigned long max_capacity = 0;           
 91         unsigned long capacity = 0;               
 92         int cpu = 0;                              
 93                                                   
 94         __cpu_capacity = kcalloc(nr_cpu_ids, s    
 95                                  GFP_NOWAIT);     
 96                                                   
 97         for_each_possible_cpu(cpu) {              
 98                 const __be32 *rate;               
 99                 int len;                          
100                                                   
101                 /* too early to use cpu->of_no    
102                 cn = of_get_cpu_node(cpu, NULL    
103                 if (!cn) {                        
104                         pr_err("missing device    
105                         continue;                 
106                 }                                 
107                                                   
108                 if (topology_parse_cpu_capacit    
109                         of_node_put(cn);          
110                         continue;                 
111                 }                                 
112                                                   
113                 cap_from_dt = false;              
114                                                   
115                 for (cpu_eff = table_efficienc    
116                         if (of_device_is_compa    
117                                 break;            
118                                                   
119                 if (cpu_eff->compatible == NUL    
120                         continue;                 
121                                                   
122                 rate = of_get_property(cn, "cl    
123                 if (!rate || len != 4) {          
124                         pr_err("%pOF missing c    
125                         continue;                 
126                 }                                 
127                                                   
128                 capacity = ((be32_to_cpup(rate    
129                                                   
130                 /* Save min capacity of the sy    
131                 if (capacity < min_capacity)      
132                         min_capacity = capacit    
133                                                   
134                 /* Save max capacity of the sy    
135                 if (capacity > max_capacity)      
136                         max_capacity = capacit    
137                                                   
138                 cpu_capacity(cpu) = capacity;     
139         }                                         
140                                                   
141         /* If min and max capacities are equal    
142          * cpu_scale because all CPUs have the    
143          * compute a middle_capacity factor th    
144          * of an 'average' CPU of the system w    
145          * SCHED_CAPACITY_SCALE, which is the     
146          * constraint explained near table_eff    
147          */                                       
148         if (4*max_capacity < (3*(max_capacity     
149                 middle_capacity = (min_capacit    
150                                 >> (SCHED_CAPA    
151         else                                      
152                 middle_capacity = ((max_capaci    
153                                 >> (SCHED_CAPA    
154                                                   
155         if (cap_from_dt)                          
156                 topology_normalize_cpu_scale()    
157 }                                                 
158                                                   
159 /*                                                
160  * Look for a customed capacity of a CPU in th    
161  * boot. The update of all CPUs is in O(n^2) f    
162  * function returns directly for SMP system.      
163  */                                               
164 static void update_cpu_capacity(unsigned int c    
165 {                                                 
166         if (!cpu_capacity(cpu) || cap_from_dt)    
167                 return;                           
168                                                   
169         topology_set_cpu_scale(cpu, cpu_capaci    
170                                                   
171         pr_info("CPU%u: update cpu_capacity %l    
172                 cpu, topology_get_cpu_scale(cp    
173 }                                                 
174                                                   
175 #else                                             
176 static inline void parse_dt_topology(void) {}     
177 static inline void update_cpu_capacity(unsigne    
178 #endif                                            
179                                                   
180 /*                                                
181  * store_cpu_topology is called at boot when o    
182  * and with the mutex cpu_hotplug.lock locked,    
183  * which prevents simultaneous write access to    
184  */                                               
185 void store_cpu_topology(unsigned int cpuid)       
186 {                                                 
187         struct cpu_topology *cpuid_topo = &cpu    
188         unsigned int mpidr;                       
189                                                   
190         if (cpuid_topo->package_id != -1)         
191                 goto topology_populated;          
192                                                   
193         mpidr = read_cpuid_mpidr();               
194                                                   
195         /* create cpu topology mapping */         
196         if ((mpidr & MPIDR_SMP_BITMASK) == MPI    
197                 /*                                
198                  * This is a multiprocessor sy    
199                  * multiprocessor format & mul    
200                  */                               
201                                                   
202                 if (mpidr & MPIDR_MT_BITMASK)     
203                         /* core performance in    
204                         cpuid_topo->thread_id     
205                         cpuid_topo->core_id =     
206                         cpuid_topo->package_id    
207                 } else {                          
208                         /* largely independent    
209                         cpuid_topo->thread_id     
210                         cpuid_topo->core_id =     
211                         cpuid_topo->package_id    
212                 }                                 
213         } else {                                  
214                 /*                                
215                  * This is an uniprocessor sys    
216                  * we are in multiprocessor fo    
217                  * or in the old uniprocessor     
218                  */                               
219                 cpuid_topo->thread_id = -1;       
220                 cpuid_topo->core_id = 0;          
221                 cpuid_topo->package_id = -1;      
222         }                                         
223                                                   
224         update_cpu_capacity(cpuid);               
225                                                   
226         pr_info("CPU%u: thread %d, cpu %d, soc    
227                 cpuid, cpu_topology[cpuid].thr    
228                 cpu_topology[cpuid].core_id,      
229                 cpu_topology[cpuid].package_id    
230                                                   
231 topology_populated:                               
232         update_siblings_masks(cpuid);             
233 }                                                 
234                                                   
235 /*                                                
236  * init_cpu_topology is called at boot when on    
237  * which prevent simultaneous write access to     
238  */                                               
239 void __init init_cpu_topology(void)               
240 {                                                 
241         reset_cpu_topology();                     
242         smp_wmb();                                
243                                                   
244         parse_dt_topology();                      
245 }                                                 
246                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php