-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance systemtools.py to also support POWER systems #1044
Changes from 2 commits
f3db58e
b2ab456
b97f84f
00bfdb5
6f900a4
82f3b4a
526c4fe
793af55
d6b33a0
708de3e
1a9f9a3
b6f57c3
c977b3e
9bde497
900b660
0f8b583
297dea1
11d199b
eab3153
cdc875d
403acba
06ec32a
7ff5511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,23 +190,26 @@ def get_cpu_model(): | |
returns cpu model | ||
f.ex Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz | ||
""" | ||
model = UNKNOWN | ||
os_type = get_os_type() | ||
if os_type == LINUX: | ||
regexp = re.compile(r"^model name\s+:\s*(?P<modelname>.+)\s*$", re.M) | ||
try: | ||
txt = read_file('/proc/cpuinfo', log_error=False) | ||
if txt is not None: | ||
return regexp.search(txt).groupdict()['modelname'].strip() | ||
res = regexp.search(txt) | ||
if res is not None: | ||
model = res.group('modelname').strip() | ||
except IOError, err: | ||
raise SystemToolsException("An error occured when determining CPU model: %s" % err) | ||
|
||
elif os_type == DARWIN: | ||
out, exitcode = run_cmd("sysctl -n machdep.cpu.brand_string") | ||
out = out.strip() | ||
if not exitcode: | ||
return out | ||
model = out | ||
|
||
return UNKNOWN | ||
return model | ||
|
||
|
||
def get_cpu_speed(): | ||
|
@@ -219,30 +222,40 @@ def get_cpu_speed(): | |
try: | ||
# Linux with cpu scaling | ||
max_freq_fp = '/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq' | ||
_log.debug("Trying to determine CPU frequency via %s" % max_freq_fp) | ||
try: | ||
f = open(max_freq_fp, 'r') | ||
cpu_freq = float(f.read())/1000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, if the |
||
f.close() | ||
return cpu_freq | ||
except IOError, err: | ||
_log.warning("Failed to read %s to determine max. CPU clock frequency with CPU scaling: %s" % (max_freq_fp, err)) | ||
_log.debug("Failed to read %s to determine max. CPU clock frequency with CPU scaling: %s" % (max_freq_fp, err)) | ||
|
||
# Linux without cpu scaling | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, this is linux with procfs mounted, nothing more then that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's Linux without a cpu governor. procfs and sysfs are always mounted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, if we are assuming this is the case, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree |
||
cpuinfo_fp = '/proc/cpuinfo' | ||
_log.debug("Trying to determine CPU frequency via %s" % cpuinfo_fp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? it it's not there, then we're not in Linux. |
||
try: | ||
cpu_freq = None | ||
f = open(cpuinfo_fp, 'r') | ||
for line in f: | ||
cpu_freq = re.match("^cpu MHz\s*:\s*([0-9.]+)", line) | ||
if cpu_freq is not None: | ||
cpuinfo_txt = open(cpuinfo_fp, 'r').read() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apperently we have a |
||
cpu_freq_patterns = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this a list? cpu_freq_reg = re.compile(r'^(?:cpu MHz|clock)\s*:\s*(?P<cpu_freq>[0-9.]+)', re.M) is all you need. if you want to add the output on x86 and power, then add a line of such output as a comment |
||
r"^cpu MHz\s*:\s*(?P<cpu_freq>[0-9.]+)", # Linux x86 & more | ||
r"^clock\s*:\s*(?P<cpu_freq>[0-9.]+)", # Linux on POWER | ||
] | ||
for cpu_freq_pattern in cpu_freq_patterns: | ||
cpu_freq_re = re.compile(cpu_freq_pattern, re.M) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point in compiling this? |
||
res = cpu_freq_re.search(cpuinfo_txt) | ||
if res: | ||
cpu_freq = res.group('cpu_freq') | ||
_log.debug("Found CPU frequency using regex '%s': %s" % (cpu_freq_pattern, cpu_freq)) | ||
break | ||
f.close() | ||
else: | ||
_log.debug("Failed to determine CPU frequency using regex '%s'" % cpu_freq_re.pattern) | ||
if cpu_freq is None: | ||
raise SystemToolsException("Failed to determine CPU frequency from %s" % cpuinfo_fp) | ||
else: | ||
return float(cpu_freq.group(1)) | ||
return float(cpu_freq) | ||
except IOError, err: | ||
_log.warning("Failed to read %s to determine CPU clock frequency: %s" % (cpuinfo_fp, err)) | ||
_log.debug("Failed to read %s to determine CPU clock frequency: %s" % (cpuinfo_fp, err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not error? something is serioulsy wrong, but i would limit the try/excpet to the part wher you read /proc/info, nothing more then that |
||
|
||
except (IOError, OSError), err: | ||
raise SystemToolsException("Determining CPU speed failed, exception occured: %s" % err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seeing this block made me think of http://www.isitfriday.org/ on a thursday....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this whole block wrapped in a
try/except
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please recheck, cleaned up significantly now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The affinity mask is a POSIX thing right? So why not try the BSD thing and then fall back to the affinity mask?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the BSD one takes into account cpuset and all that crap, the affinity one does, so that should be tried first (and it should always work on Linux)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agreed. But now, it's only tried on Linux. Why not try it always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it won't work on non-Linux systems :)