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

TOMOYO Linux Cross Reference
Linux/arch/x86/kernel/cpu/perfctr-watchdog.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/x86/kernel/cpu/perfctr-watchdog.c (Architecture ppc) and /arch/alpha/kernel/cpu/perfctr-watchdog.c (Architecture alpha)


  1 // SPDX-License-Identifier: GPL-2.0                 1 
  2 /*                                                
  3  * local apic based NMI watchdog for various C    
  4  *                                                
  5  * This file also handles reservation of perfo    
  6  * with other users.                              
  7  *                                                
  8  * Note that these events normally don't tick     
  9  * the frequency varies with CPU load.            
 10  *                                                
 11  * Original code for K7/P6 written by Keith Ow    
 12  *                                                
 13  */                                               
 14                                                   
 15 #include <linux/percpu.h>                         
 16 #include <linux/export.h>                         
 17 #include <linux/kernel.h>                         
 18 #include <linux/bitops.h>                         
 19 #include <linux/smp.h>                            
 20 #include <asm/nmi.h>                              
 21 #include <linux/kprobes.h>                        
 22                                                   
 23 #include <asm/apic.h>                             
 24 #include <asm/perf_event.h>                       
 25                                                   
 26 /*                                                
 27  * this number is calculated from Intel's MSR_    
 28  * offset from MSR_P4_BSU_ESCR0.                  
 29  *                                                
 30  * It will be the max for all platforms (for n    
 31  */                                               
 32 #define NMI_MAX_COUNTER_BITS 66                   
 33                                                   
 34 /*                                                
 35  * perfctr_nmi_owner tracks the ownership of t    
 36  * evtsel_nmi_owner tracks the ownership of th    
 37  * - different performance counters/ event sel    
 38  *   different subsystems this reservation sys    
 39  *   things a little                              
 40  */                                               
 41 static DECLARE_BITMAP(perfctr_nmi_owner, NMI_M    
 42 static DECLARE_BITMAP(evntsel_nmi_owner, NMI_M    
 43                                                   
 44 /* converts an msr to an appropriate reservati    
 45 static inline unsigned int nmi_perfctr_msr_to_    
 46 {                                                 
 47         /* returns the bit offset of the perfo    
 48         switch (boot_cpu_data.x86_vendor) {       
 49         case X86_VENDOR_HYGON:                    
 50         case X86_VENDOR_AMD:                      
 51                 if (msr >= MSR_F15H_PERF_CTR)     
 52                         return (msr - MSR_F15H    
 53                 return msr - MSR_K7_PERFCTR0;     
 54         case X86_VENDOR_INTEL:                    
 55                 if (cpu_has(&boot_cpu_data, X8    
 56                         return msr - MSR_ARCH_    
 57                                                   
 58                 switch (boot_cpu_data.x86) {      
 59                 case 6:                           
 60                         return msr - MSR_P6_PE    
 61                 case 11:                          
 62                         return msr - MSR_KNC_P    
 63                 case 15:                          
 64                         return msr - MSR_P4_BP    
 65                 }                                 
 66                 break;                            
 67         case X86_VENDOR_ZHAOXIN:                  
 68         case X86_VENDOR_CENTAUR:                  
 69                 return msr - MSR_ARCH_PERFMON_    
 70         }                                         
 71         return 0;                                 
 72 }                                                 
 73                                                   
 74 /*                                                
 75  * converts an msr to an appropriate reservati    
 76  * returns the bit offset of the event selecti    
 77  */                                               
 78 static inline unsigned int nmi_evntsel_msr_to_    
 79 {                                                 
 80         /* returns the bit offset of the event    
 81         switch (boot_cpu_data.x86_vendor) {       
 82         case X86_VENDOR_HYGON:                    
 83         case X86_VENDOR_AMD:                      
 84                 if (msr >= MSR_F15H_PERF_CTL)     
 85                         return (msr - MSR_F15H    
 86                 return msr - MSR_K7_EVNTSEL0;     
 87         case X86_VENDOR_INTEL:                    
 88                 if (cpu_has(&boot_cpu_data, X8    
 89                         return msr - MSR_ARCH_    
 90                                                   
 91                 switch (boot_cpu_data.x86) {      
 92                 case 6:                           
 93                         return msr - MSR_P6_EV    
 94                 case 11:                          
 95                         return msr - MSR_KNC_E    
 96                 case 15:                          
 97                         return msr - MSR_P4_BS    
 98                 }                                 
 99                 break;                            
100         case X86_VENDOR_ZHAOXIN:                  
101         case X86_VENDOR_CENTAUR:                  
102                 return msr - MSR_ARCH_PERFMON_    
103         }                                         
104         return 0;                                 
105                                                   
106 }                                                 
107                                                   
108 int reserve_perfctr_nmi(unsigned int msr)         
109 {                                                 
110         unsigned int counter;                     
111                                                   
112         counter = nmi_perfctr_msr_to_bit(msr);    
113         /* register not managed by the allocat    
114         if (counter > NMI_MAX_COUNTER_BITS)       
115                 return 1;                         
116                                                   
117         if (!test_and_set_bit(counter, perfctr    
118                 return 1;                         
119         return 0;                                 
120 }                                                 
121 EXPORT_SYMBOL(reserve_perfctr_nmi);               
122                                                   
123 void release_perfctr_nmi(unsigned int msr)        
124 {                                                 
125         unsigned int counter;                     
126                                                   
127         counter = nmi_perfctr_msr_to_bit(msr);    
128         /* register not managed by the allocat    
129         if (counter > NMI_MAX_COUNTER_BITS)       
130                 return;                           
131                                                   
132         clear_bit(counter, perfctr_nmi_owner);    
133 }                                                 
134 EXPORT_SYMBOL(release_perfctr_nmi);               
135                                                   
136 int reserve_evntsel_nmi(unsigned int msr)         
137 {                                                 
138         unsigned int counter;                     
139                                                   
140         counter = nmi_evntsel_msr_to_bit(msr);    
141         /* register not managed by the allocat    
142         if (counter > NMI_MAX_COUNTER_BITS)       
143                 return 1;                         
144                                                   
145         if (!test_and_set_bit(counter, evntsel    
146                 return 1;                         
147         return 0;                                 
148 }                                                 
149 EXPORT_SYMBOL(reserve_evntsel_nmi);               
150                                                   
151 void release_evntsel_nmi(unsigned int msr)        
152 {                                                 
153         unsigned int counter;                     
154                                                   
155         counter = nmi_evntsel_msr_to_bit(msr);    
156         /* register not managed by the allocat    
157         if (counter > NMI_MAX_COUNTER_BITS)       
158                 return;                           
159                                                   
160         clear_bit(counter, evntsel_nmi_owner);    
161 }                                                 
162 EXPORT_SYMBOL(release_evntsel_nmi);               
163                                                   

~ [ 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