projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8ba5c8a
)
Turbostat: better error handling for get/read_msr
author
Vincent Brillault
<git@lerya.net>
Sat, 23 Aug 2014 07:46:31 +0000
(09:46 +0200)
committer
Vincent Brillault
<git@lerya.net>
Sat, 28 Feb 2015 06:35:40 +0000
(07:35 +0100)
src/turbostat.c
patch
|
blob
|
history
diff --git
a/src/turbostat.c
b/src/turbostat.c
index
d602ffe
..
ff19cc4
100644
(file)
--- a/
src/turbostat.c
+++ b/
src/turbostat.c
@@
-270,6
+270,7
@@
static int __attribute__((warn_unused_result))
open_msr(int cpu)
{
char pathname[32];
open_msr(int cpu)
{
char pathname[32];
+ int fd;
/* FIXME: Do we really need this, why? */
if (cpu_migrate(cpu)) {
/* FIXME: Do we really need this, why? */
if (cpu_migrate(cpu)) {
@@
-277,8
+278,11
@@
open_msr(int cpu)
return -ERR_CPU_MIGRATE;
}
return -ERR_CPU_MIGRATE;
}
- ssnprintf(pathname, 32, "/dev/cpu/%d/msr", cpu);
- return open(pathname, O_RDONLY);
+ ssnprintf(pathname, STATIC_ARRAY_SIZE(pathname), "/dev/cpu/%d/msr", cpu);
+ fd = open(pathname, O_RDONLY);
+ if (fd < 0)
+ return -ERR_CANT_OPEN_MSR;
+ return fd;
}
static int __attribute__((warn_unused_result))
}
static int __attribute__((warn_unused_result))
@@
-303,7
+307,7
@@
get_msr(int cpu, off_t offset, unsigned long long *msr)
fd = open_msr(cpu);
if (fd < 0)
fd = open_msr(cpu);
if (fd < 0)
- return
-1
;
+ return
fd
;
retval = read_msr(fd, offset, msr);
close(fd);
return retval;
retval = read_msr(fd, offset, msr);
close(fd);
return retval;
@@
-446,7
+450,7
@@
get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
msr_fd = open_msr(cpu);
if (msr_fd < 0)
msr_fd = open_msr(cpu);
if (msr_fd < 0)
- return
-ERR_CANT_OPEN_MSR
;
+ return
msr_fd
;
#define READ_MSR(msr, dst) \
do { \
#define READ_MSR(msr, dst) \
do { \