Skip to content

Commit 6db3376

Browse files
committed
Add 'lima-memtester-genchart' script
It can be used to process a list of top DRAM clock frequencies from multiple boards of the same type and evaluate overall reliability for this particular board model. Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
1 parent e767733 commit 6db3376

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

lima-memtester-genchart

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Copyright © 2015 Siarhei Siamashka <siarhei.siamashka@gmail.com>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a
6+
# copy of this software and associated documentation files (the "Software"),
7+
# to deal in the Software without restriction, including without limitation
8+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
# and/or sell copies of the Software, and to permit persons to whom the
10+
# Software is furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice (including the next
13+
# paragraph) shall be included in all copies or substantial portions of the
14+
# Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
# DEALINGS IN THE SOFTWARE.
23+
24+
###############################################################################
25+
# Assuming Gaussian distribution of the DRAM clock speeds where the #
26+
# lima-memtester test starts to detect reliability problems due to variances #
27+
# between different board samples (but the same board model!), predict how #
28+
# many boards of the same type are expected to pass/fail the test at each #
29+
# DRAM clock speed. #
30+
# #
31+
# If a "good" DRAM clock frequency (passes the test) is 672 MHz and a "bad" #
32+
# clock frequency is 696 MHz, then we are assuming that the cross over point #
33+
# is somewhere in the middle. So we want to pass the "(672 + 696) / 2" value #
34+
# into this script. In order to make this easier, there is the <freq_delta> #
35+
# command line argument, which can be used to add a 12 MHz shift to the #
36+
# "good" value or subtract 12 MHz from the "bad" value. It is a convenience #
37+
# feature to avoid maual adjustment of the DRAM clock frequency lists #
38+
# used as input for this script. #
39+
###############################################################################
40+
41+
require 'tempfile'
42+
43+
if ARGV.size < 1
44+
printf("Usage: #{$PROGRAM_NAME} <freq_delta> <png_file>\n")
45+
printf("Where:\n")
46+
printf(" freq_delta - adjustment for the frequency.\n")
47+
printf(" png_file - resulting PNG file with the plot.\n")
48+
printf("\n")
49+
printf("This script reads the list of space separated DRAM clock\n")
50+
printf("frequency values from STDIN, adds <freq_delta> to them and\n")
51+
printf("generates a gnuplot chart\n")
52+
exit(1)
53+
end
54+
55+
###############################################################################
56+
# Analyze data, calculate probabilities #
57+
###############################################################################
58+
59+
freq_delta = ARGV[0].to_f
60+
61+
printf("Frequency shift : %d MHz\n", freq_delta.to_i)
62+
samples = STDIN.read.split.map {|x| x.to_f + freq_delta }
63+
printf("Processing data : %s\n", samples.map {|x| x.to_i })
64+
abort "As least two DRAM clock speed samples are needed" if samples.size < 2
65+
66+
sample_mean = samples.reduce(:+) / samples.size.to_f
67+
sample_stddev = Math.sqrt(samples.reduce(0) {|sum, x| sum + (x - sample_mean) ** 2} /
68+
(samples.size - 1))
69+
70+
printf("Sample mean : %f\n", sample_mean)
71+
printf("Sample stddev : %f\n", sample_stddev)
72+
73+
# https://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function
74+
def cumulative_distribution_function(x, sample_mean, sample_stddev)
75+
return 0.5 * (1 + Math.erf((x - sample_mean) / (sample_stddev * Math.sqrt(2))))
76+
end
77+
78+
printf("{| class=\"wikitable\"\n")
79+
printf("! DRAM clock speed ")
80+
printf("|| Share of boards expected to fail the lima-memtester test\n")
81+
82+
freq = 816
83+
while true
84+
p = cumulative_distribution_function(freq, sample_mean, sample_stddev)
85+
break if p < 0.0001 || freq == 360
86+
freq -= 24
87+
end
88+
89+
while freq <= 816
90+
p = cumulative_distribution_function(freq, sample_mean, sample_stddev)
91+
printf("|-\n| %.0f MHz|| %.2f %%\n", freq, p * 100)
92+
break if p >= 0.99
93+
freq += 24
94+
end
95+
printf("|}\n")
96+
97+
###############################################################################
98+
# Gnuplot #
99+
###############################################################################
100+
101+
if ARGV.size >= 2
102+
# Test the availability of the required tools
103+
def tool_exists(tool_name)
104+
`which #{tool_name} > /dev/null 2>&1`
105+
if $?.to_i != 0 then
106+
printf("Error: the required '%s' executable is not found in PATH\n", tool_name)
107+
return false
108+
else
109+
return true
110+
end
111+
end
112+
exit(1) unless tool_exists("gnuplot")
113+
pngfile = ARGV[1]
114+
115+
tmp = Tempfile.new("lima-memetster-genchart")
116+
(360..816).step(4) do |freq|
117+
p = cumulative_distribution_function(freq, sample_mean, sample_stddev)
118+
tmp.printf("%f %f\n", freq, p * 100)
119+
end
120+
tmp.flush
121+
122+
IO.popen("gnuplot", "w") do |fh|
123+
fh.write "
124+
set terminal png size 800, 600
125+
set output '#{pngfile}'
126+
set format y '%.0f'
127+
set xtics 24
128+
set ytics (1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100)
129+
set grid xtics ytics
130+
set xrange [360:816]
131+
set yrange [0:103]
132+
set xlabel 'DRAM clock frequency, MHz'
133+
set ylabel 'Share of boards expected to fail the lima-memtester test, %'
134+
set style line 1 lc rgb '#0060ff' lt 1 lw 2 pt 7 pi 6 ps 0
135+
plot '#{tmp.path}' using 1:2 with linespoints ls 1 notitle
136+
"
137+
end
138+
end

0 commit comments

Comments
 (0)