Skip to content

Commit 5663785

Browse files
kaushlenlenb
authored andcommitted
tools/power turbostat: Add Android support for MSR device handling
It uses /dev/msrN device paths on Android instead of /dev/cpu/N/msr, updates error messages and permission checks to reflect the Android device path, and wraps platform-specific code with #if defined(ANDROID) to ensure correct behavior on both Android and non-Android systems. These changes improve compatibility and usability of turbostat on Android devices. Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent c967900 commit 5663785

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,13 +2140,20 @@ int get_msr_fd(int cpu)
21402140

21412141
if (fd)
21422142
return fd;
2143-
2143+
#if defined(ANDROID)
2144+
sprintf(pathname, "/dev/msr%d", cpu);
2145+
#else
21442146
sprintf(pathname, "/dev/cpu/%d/msr", cpu);
2147+
#endif
21452148
fd = open(pathname, O_RDONLY);
21462149
if (fd < 0)
2150+
#if defined(ANDROID)
2151+
err(-1, "%s open failed, try chown or chmod +r /dev/msr*, "
2152+
"or run with --no-msr, or run as root", pathname);
2153+
#else
21472154
err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, "
21482155
"or run with --no-msr, or run as root", pathname);
2149-
2156+
#endif
21502157
fd_percpu[cpu] = fd;
21512158

21522159
return fd;
@@ -6476,8 +6483,11 @@ void check_dev_msr()
64766483

64776484
if (no_msr)
64786485
return;
6479-
6486+
#if defined(ANDROID)
6487+
sprintf(pathname, "/dev/msr%d", base_cpu);
6488+
#else
64806489
sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
6490+
#endif
64816491
if (stat(pathname, &sb))
64826492
if (system("/sbin/modprobe msr > /dev/null 2>&1"))
64836493
no_msr = 1;
@@ -6527,7 +6537,11 @@ void check_msr_permission(void)
65276537
failed += check_for_cap_sys_rawio();
65286538

65296539
/* test file permissions */
6540+
#if defined(ANDROID)
6541+
sprintf(pathname, "/dev/msr%d", base_cpu);
6542+
#else
65306543
sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
6544+
#endif
65316545
if (euidaccess(pathname, R_OK)) {
65326546
failed++;
65336547
}

0 commit comments

Comments
 (0)