Skip to content

Commit d071004

Browse files
zhang-ruilenb
authored andcommitted
tools/power turbostat: Consolidate graphics sysfs access
Currently, there is an inconsistency in how graphics sysfs knobs are accessed: graphics residency sysfs knobs are opened and closed for each read, while graphics frequency sysfs knobs are opened once and remain open until turbostat exits. This inconsistency is confusing and adds unnecessary code complexity. Consolidate the access method by opening the sysfs files once and reusing the file pointers for subsequent accesses. This approach simplifies the code and ensures a consistent method for accessing graphics sysfs knobs. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent ba99a4f commit d071004

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5764,27 +5764,24 @@ int snapshot_proc_interrupts(void)
57645764
*/
57655765
int snapshot_graphics(int idx)
57665766
{
5767-
FILE *fp;
57685767
int retval;
57695768

5769+
if (gfx_info[idx].fp == NULL)
5770+
gfx_info[idx].fp = fopen_or_die(gfx_info[idx].path, "r");
5771+
else
5772+
rewind(gfx_info[idx].fp);
5773+
57705774
switch (idx) {
57715775
case GFX_rc6:
57725776
case SAM_mc6:
5773-
fp = fopen_or_die(gfx_info[idx].path, "r");
5774-
retval = fscanf(fp, "%lld", &gfx_info[idx].val_ull);
5777+
retval = fscanf(gfx_info[idx].fp, "%lld", &gfx_info[idx].val_ull);
57755778
if (retval != 1)
57765779
err(1, "rc6");
5777-
fclose(fp);
57785780
return 0;
57795781
case GFX_MHz:
57805782
case GFX_ACTMHz:
57815783
case SAM_MHz:
57825784
case SAM_ACTMHz:
5783-
if (gfx_info[idx].fp == NULL)
5784-
gfx_info[idx].fp = fopen_or_die(gfx_info[idx].path, "r");
5785-
else
5786-
rewind(gfx_info[idx].fp);
5787-
57885785
retval = fscanf(gfx_info[idx].fp, "%d", &gfx_info[idx].val);
57895786
if (retval != 1)
57905787
err(1, "MHz");

0 commit comments

Comments
 (0)