@@ -116,9 +116,13 @@ impl Cpu {
116116
117117 const PATH : & str = "/sys/devices/system/cpu" ;
118118
119+ log:: info!( "detecting CPUs..." ) ;
120+
119121 let mut cpus = vec ! [ ] ;
120122 let cache = CpuScanCache :: default ( ) ;
121123
124+ log:: debug!( "scanning CPU entries in {PATH}" ) ;
125+
122126 for entry in fs:: read_dir ( PATH )
123127 . context ( "failed to read CPU entries" ) ?
124128 . with_context ( || format ! ( "'{PATH}' doesn't exist, are you on linux?" ) ) ?
@@ -146,16 +150,21 @@ impl Cpu {
146150
147151 // Fall back if sysfs iteration above fails to find any cpufreq CPUs.
148152 if cpus. is_empty ( ) {
153+ log:: warn!( "no CPUs found in sysfs, using logical CPU count fallback" ) ;
149154 for number in 0 ..num_cpus:: get ( ) as u32 {
150155 cpus. push ( from_number ( number, & cache) ?) ;
151156 }
152157 }
153158
159+ log:: info!( "detected {} CPUs" , cpus. len( ) ) ;
160+
154161 Ok ( cpus)
155162 }
156163
157164 /// Scan CPU, tuning local copy of settings.
158165 fn scan ( & mut self , cache : & CpuScanCache ) -> anyhow:: Result < ( ) > {
166+ log:: debug!( "scanning CPU {}" , self . number) ;
167+
159168 let Self { number, .. } = self ;
160169
161170 if !fs:: exists ( format ! ( "/sys/devices/system/cpu/cpu{number}" ) ) {
@@ -165,6 +174,8 @@ impl Cpu {
165174 self . has_cpufreq =
166175 fs:: exists ( format ! ( "/sys/devices/system/cpu/cpu{number}/cpufreq" ) ) ;
167176
177+ log:: trace!( "CPU {} has cpufreq: {}" , self . number, self . has_cpufreq) ;
178+
168179 if self . has_cpufreq {
169180 self . scan_governor ( ) ?;
170181 self . scan_frequency ( ) ?;
@@ -179,6 +190,8 @@ impl Cpu {
179190 }
180191
181192 fn scan_governor ( & mut self ) -> anyhow:: Result < ( ) > {
193+ log:: trace!( "scanning governor for CPU {}" , self . number) ;
194+
182195 let Self { number, .. } = * self ;
183196
184197 self . governor = fs:: read ( format ! (
@@ -210,6 +223,8 @@ impl Cpu {
210223 }
211224
212225 fn scan_frequency ( & mut self ) -> anyhow:: Result < ( ) > {
226+ log:: trace!( "scanning frequency for CPU {}" , self . number) ;
227+
213228 let Self { number, .. } = * self ;
214229
215230 let frequency_khz = fs:: read_n :: < u64 > ( format ! (
@@ -233,6 +248,8 @@ impl Cpu {
233248 }
234249
235250 fn scan_epp ( & mut self ) -> anyhow:: Result < ( ) > {
251+ log:: trace!( "scanning EPP for CPU {}" , self . number) ;
252+
236253 let Self { number, .. } = * self ;
237254
238255 self . epp = fs:: read ( format ! (
@@ -263,6 +280,8 @@ impl Cpu {
263280 }
264281
265282 fn scan_epb ( & mut self ) -> anyhow:: Result < ( ) > {
283+ log:: trace!( "scanning EPB for CPU {}" , self . number) ;
284+
266285 let Self { number, .. } = self ;
267286
268287 self . epb = fs:: read ( format ! (
@@ -300,6 +319,8 @@ impl Cpu {
300319 }
301320
302321 fn scan_stat ( & mut self , cache : & CpuScanCache ) -> anyhow:: Result < ( ) > {
322+ log:: trace!( "scanning stat for CPU {}" , self . number) ;
323+
303324 // OnceCell::get_or_try_init is unstable. Cope:
304325 let stat = match cache. stat . get ( ) {
305326 Some ( stat) => stat,
@@ -349,6 +370,8 @@ impl Cpu {
349370 }
350371
351372 fn scan_info ( & mut self , cache : & CpuScanCache ) -> anyhow:: Result < ( ) > {
373+ log:: trace!( "scanning info for CPU {}" , self . number) ;
374+
352375 // OnceCell::get_or_try_init is unstable. Cope:
353376 let info = match cache. info . get ( ) {
354377 Some ( stat) => stat,
@@ -436,6 +459,8 @@ impl Cpu {
436459
437460 self . governor = Some ( governor. to_owned ( ) ) ;
438461
462+ log:: info!( "CPU {} governor set to {}" , self . number, governor) ;
463+
439464 Ok ( ( ) )
440465 }
441466
@@ -470,6 +495,8 @@ impl Cpu {
470495
471496 self . epp = Some ( epp. to_owned ( ) ) ;
472497
498+ log:: info!( "CPU {} EPP set to {}" , self . number, epp) ;
499+
473500 Ok ( ( ) )
474501 }
475502
@@ -503,6 +530,8 @@ impl Cpu {
503530
504531 self . epb = Some ( epb. to_owned ( ) ) ;
505532
533+ log:: info!( "CPU {} EPB set to {}" , self . number, epb) ;
534+
506535 Ok ( ( ) )
507536 }
508537
@@ -529,6 +558,12 @@ impl Cpu {
529558 )
530559 } ) ?;
531560
561+ log:: info!(
562+ "CPU {} min frequency set to {} MHz" ,
563+ self . number,
564+ frequency_mhz
565+ ) ;
566+
532567 Ok ( ( ) )
533568 }
534569
@@ -581,6 +616,12 @@ impl Cpu {
581616 )
582617 } ) ?;
583618
619+ log:: info!(
620+ "CPU {} max frequency set to {} MHz" ,
621+ self . number,
622+ frequency_mhz
623+ ) ;
624+
584625 Ok ( ( ) )
585626 }
586627
@@ -616,6 +657,8 @@ impl Cpu {
616657 on : bool ,
617658 mut cpus : impl Iterator < Item = & ' a Self > ,
618659 ) -> anyhow:: Result < ( ) > {
660+ log:: info!( "setting CPU turbo boost to {on}" ) ;
661+
619662 let value_boost = match on {
620663 true => "1" , // boost = 1 means turbo is enabled.
621664 false => "0" , // boost = 0 means turbo is disabled.
@@ -667,6 +710,8 @@ impl Cpu {
667710 }
668711
669712 pub fn hardware_frequency_mhz_maximum ( ) -> anyhow:: Result < Option < u64 > > {
713+ log:: trace!( "reading hardware frequency limits" ) ;
714+
670715 fs:: read_n :: < u64 > ( "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" )
671716 . context ( "failed to read CPU hardware maximum frequency" )
672717 . map ( |x| x. map ( |freq| freq / 1000 ) )
@@ -679,6 +724,8 @@ impl Cpu {
679724 }
680725
681726 pub fn turbo ( ) -> anyhow:: Result < Option < bool > > {
727+ log:: trace!( "reading turbo boost status" ) ;
728+
682729 if let Some ( content) =
683730 fs:: read_n :: < u64 > ( "/sys/devices/system/cpu/intel_pstate/no_turbo" )
684731 . context ( "failed to read CPU turbo boost status" ) ?
0 commit comments