@@ -251,11 +251,8 @@ char *output_buffer, *outp;
251251unsigned int do_dts ;
252252unsigned int do_ptm ;
253253unsigned int do_ipc ;
254- unsigned long long gfx_cur_rc6_ms ;
255254unsigned long long cpuidle_cur_cpu_lpi_us ;
256255unsigned long long cpuidle_cur_sys_lpi_us ;
257- unsigned int gfx_cur_mhz ;
258- unsigned int gfx_act_mhz ;
259256unsigned int tj_max ;
260257unsigned int tj_max_override ;
261258double rapl_power_units , rapl_time_units ;
@@ -285,6 +282,9 @@ enum gfx_sysfs_idx {
285282
286283struct gfx_sysfs_info {
287284 const char * path ;
285+ FILE * fp ;
286+ unsigned int val ;
287+ unsigned long long val_ull ;
288288};
289289
290290static struct gfx_sysfs_info gfx_info [GFX_MAX ];
@@ -3573,17 +3573,17 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
35733573 }
35743574
35753575 if (DO_BIC (BIC_GFX_rc6 ))
3576- p -> gfx_rc6_ms = gfx_cur_rc6_ms ;
3576+ p -> gfx_rc6_ms = gfx_info [ GFX_rc6 ]. val_ull ;
35773577
35783578 /* n.b. assume die0 uncore frequency applies to whole package */
35793579 if (DO_BIC (BIC_UNCORE_MHZ ))
35803580 p -> uncore_mhz = get_uncore_mhz (p -> package_id , 0 );
35813581
35823582 if (DO_BIC (BIC_GFXMHz ))
3583- p -> gfx_mhz = gfx_cur_mhz ;
3583+ p -> gfx_mhz = gfx_info [ GFX_MHz ]. val ;
35843584
35853585 if (DO_BIC (BIC_GFXACTMHz ))
3586- p -> gfx_act_mhz = gfx_act_mhz ;
3586+ p -> gfx_act_mhz = gfx_info [ GFX_ACTMHz ]. val ;
35873587
35883588 for (i = 0 , mp = sys .pp ; mp ; i ++ , mp = mp -> next ) {
35893589 if (get_mp (cpu , mp , & p -> counter [i ]))
@@ -4621,81 +4621,40 @@ int snapshot_proc_interrupts(void)
46214621}
46224622
46234623/*
4624- * snapshot_gfx_rc6_ms ()
4624+ * snapshot_graphics ()
46254625 *
4626- * record snapshot of
4627- * /sys/class/drm/card0/power/rc6_residency_ms
4626+ * record snapshot of specified graphics sysfs knob
46284627 *
46294628 * return 1 if config change requires a restart, else return 0
46304629 */
4631- int snapshot_gfx_rc6_ms ( void )
4630+ int snapshot_graphics ( int idx )
46324631{
46334632 FILE * fp ;
46344633 int retval ;
46354634
4636- fp = fopen_or_die (gfx_info [GFX_rc6 ].path , "r" );
4637-
4638- retval = fscanf (fp , "%lld" , & gfx_cur_rc6_ms );
4639- if (retval != 1 )
4640- err (1 , "GFX rc6" );
4641-
4642- fclose (fp );
4643-
4644- return 0 ;
4645- }
4646-
4647- /*
4648- * snapshot_gfx_mhz()
4649- *
4650- * fall back to /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz
4651- * when /sys/class/drm/card0/gt_cur_freq_mhz is not available.
4652- *
4653- * return 1 if config change requires a restart, else return 0
4654- */
4655- int snapshot_gfx_mhz (void )
4656- {
4657- static FILE * fp ;
4658- int retval ;
4659-
4660- if (fp == NULL ) {
4661- fp = fopen_or_die (gfx_info [GFX_MHz ].path , "r" );
4662- } else {
4663- rewind (fp );
4664- fflush (fp );
4665- }
4666-
4667- retval = fscanf (fp , "%d" , & gfx_cur_mhz );
4668- if (retval != 1 )
4669- err (1 , "GFX MHz" );
4670-
4671- return 0 ;
4672- }
4673-
4674- /*
4675- * snapshot_gfx_cur_mhz()
4676- *
4677- * fall back to /sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz
4678- * when /sys/class/drm/card0/gt_act_freq_mhz is not available.
4679- *
4680- * return 1 if config change requires a restart, else return 0
4681- */
4682- int snapshot_gfx_act_mhz (void )
4683- {
4684- static FILE * fp ;
4685- int retval ;
4686-
4687- if (fp == NULL ) {
4688- fp = fopen_or_die (gfx_info [GFX_ACTMHz ].path , "r" );
4689- } else {
4690- rewind (fp );
4691- fflush (fp );
4635+ switch (idx ) {
4636+ case GFX_rc6 :
4637+ fp = fopen_or_die (gfx_info [idx ].path , "r" );
4638+ retval = fscanf (fp , "%lld" , & gfx_info [idx ].val_ull );
4639+ if (retval != 1 )
4640+ err (1 , "rc6" );
4641+ fclose (fp );
4642+ return 0 ;
4643+ case GFX_MHz :
4644+ case GFX_ACTMHz :
4645+ if (gfx_info [idx ].fp == NULL ) {
4646+ gfx_info [idx ].fp = fopen_or_die (gfx_info [idx ].path , "r" );
4647+ } else {
4648+ rewind (gfx_info [idx ].fp );
4649+ fflush (gfx_info [idx ].fp );
4650+ }
4651+ retval = fscanf (gfx_info [idx ].fp , "%d" , & gfx_info [idx ].val );
4652+ if (retval != 1 )
4653+ err (1 , "MHz" );
4654+ return 0 ;
4655+ default :
4656+ return - EINVAL ;
46924657 }
4693-
4694- retval = fscanf (fp , "%d" , & gfx_act_mhz );
4695- if (retval != 1 )
4696- err (1 , "GFX ACT MHz" );
4697-
4698- return 0 ;
46994658}
47004659
47014660/*
@@ -4760,13 +4719,13 @@ int snapshot_proc_sysfs_files(void)
47604719 return 1 ;
47614720
47624721 if (DO_BIC (BIC_GFX_rc6 ))
4763- snapshot_gfx_rc6_ms ( );
4722+ snapshot_graphics ( GFX_rc6 );
47644723
47654724 if (DO_BIC (BIC_GFXMHz ))
4766- snapshot_gfx_mhz ( );
4725+ snapshot_graphics ( GFX_MHz );
47674726
47684727 if (DO_BIC (BIC_GFXACTMHz ))
4769- snapshot_gfx_act_mhz ( );
4728+ snapshot_graphics ( GFX_ACTMHz );
47704729
47714730 if (DO_BIC (BIC_CPU_LPI ))
47724731 snapshot_cpu_lpi_us ();
0 commit comments