~ubuntu-branches/ubuntu/precise/xserver-xorg-video-intel-lts-quantal/precise-proposed

« back to all changes in this revision

Viewing changes to src/scripts/clock-graph.5c

  • Committer: Package Import Robot
  • Author(s): Maarten Lankhorst
  • Date: 2013-06-19 12:00:59 UTC
  • Revision ID: package-import@ubuntu.com-20130619120059-jlt0e9ghrs6pkcfs
Tags: 2:2.20.9-0ubuntu2.2~precise1
Added patches to add/fix Haswell pci-id's (LP: #1175533)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
autoload Cairo;
2
 
import Cairo;
3
 
library "examples/sort.5c";
4
 
import Sort;
5
 
 
6
 
int width = 1000, height = 200;
7
 
int min_vco = 1400000000;
8
 
int max_vco = 2800000000;
9
 
int min = 0xffffffff;
10
 
int max = 0;
11
 
 
12
 
int max_clocks = 2000;
13
 
int[4][max_clocks] clocks;
14
 
int[4][max_clocks] vcos;
15
 
int[4] clock_count = {0...};
16
 
 
17
 
int[4] p2vals = {5,10,7,14};
18
 
 
19
 
cairo_t cr = Cairo::new(width, height);
20
 
 
21
 
void calc_p2(int p2i)
22
 
{
23
 
        int p2 = p2vals[p2i];
24
 
        int min_p, max_p;
25
 
 
26
 
        clocks[p2i] = (int [max_clocks]){0...};
27
 
 
28
 
                if (p2 == 7 || p2 == 14) {
29
 
                /* LVDS */
30
 
                min_p = 7;
31
 
                max_p = 98;
32
 
        } else {
33
 
                /* SDVO/DAC */
34
 
                min_p = 5;
35
 
                max_p = 80;
36
 
        }
37
 
 
38
 
        for (int m1 = 10; m1 <= 22; m1++) {
39
 
                for (int m2 = 5; m2 <= 9; m2++) {
40
 
                        for (int n = 1; n <= 5; n++) {
41
 
                                for (int p1 = 1; p1 <= 8; p1++) {
42
 
                                        int ref = 96000000;
43
 
                                        int m = 5 * (m1 + 2) + (m2 + 2);
44
 
                                        int p = p1 * p2;
45
 
                                        int vco = floor(ref * m / (n + 2));
46
 
                                        int clock = floor(vco / p);
47
 
 
48
 
                                        if (p < min_p || p > max_p)
49
 
                                                continue;
50
 
                                        if (m < 70 || m > 120)
51
 
                                                continue;
52
 
                                        if (m2 > m1)
53
 
                                                continue; /* won't happen */
54
 
                                        if (vco < min_vco || vco > max_vco)
55
 
                                                continue;
56
 
 
57
 
/*
58
 
                                        printf("clock: %d (%d,%d), %d, "
59
 
                                                "(%d,%d)\n",
60
 
                                                floor(clock / 1000),
61
 
                                                m1, m2, n, p1, p2);
62
 
*/
63
 
 
64
 
                                        clocks[p2i][clock_count[p2i]] = clock;
65
 
                                        vcos[p2i][clock_count[p2i]] = vco;
66
 
                                        clock_count[p2i]++;
67
 
                                }
68
 
                        }
69
 
                }
70
 
        }
71
 
}
72
 
 
73
 
bool sort_p2(poly a, poly b)
74
 
{
75
 
        return a > b;
76
 
}
77
 
 
78
 
int min_rate = 25000 * 1000;
79
 
int max_rate = 200000 * 1000;
80
 
 
81
 
real scale_x(real clock)
82
 
{
83
 
        int min_x = 75, max_x = width - 50;
84
 
 
85
 
        real frac = (clock - min_rate) / (max_rate - min_rate);
86
 
 
87
 
        return min_x + frac * (max_x - min_x);
88
 
}
89
 
 
90
 
for (p2i = 0; p2i < dim(p2vals); p2i++) {
91
 
        int p2 = p2vals[p2i]; 
92
 
        calc_p2(p2i);
93
 
        real row_y1 = (p2i + 1) / (dim(p2vals) + 1) * height;
94
 
        real row_y2 = p2i / (dim(p2vals) + 1) * height;
95
 
 
96
 
        /*qsort(&p2vals[p2i], sort_p2);*/
97
 
 
98
 
        switch (p2) {
99
 
        case 5:
100
 
                set_source_rgb(cr, 1,0,0);
101
 
                break;
102
 
        case 10:
103
 
                set_source_rgb(cr, 0,1,0);
104
 
                break;
105
 
        case 7:
106
 
                set_source_rgb(cr, 0,0,1);
107
 
                break;
108
 
        case 14:
109
 
                set_source_rgb(cr, 0,0,0);
110
 
                break;
111
 
        }
112
 
 
113
 
        /* draw the line for the clock */
114
 
        for (int i = 0; i < clock_count[p2i]; i++) {
115
 
                int clock = clocks[p2i][i];
116
 
                real xpos;
117
 
 
118
 
                if (clock < min_rate || clock > max_rate)
119
 
                        continue;
120
 
 
121
 
                xpos = scale_x(clock);
122
 
                move_to(cr, xpos, row_y1);
123
 
                line_to(cr, xpos, row_y2);
124
 
                stroke(cr);
125
 
        }
126
 
 
127
 
        set_source_rgb(cr, 1, 1, 1);
128
 
        /* add a mark for the vco value of the clocks at each location */
129
 
        for (int i = 0; i < clock_count[p2i]; i++) {
130
 
                int clock = clocks[p2i][i];
131
 
                int vco = vcos[p2i][i];
132
 
                real mark_center;
133
 
 
134
 
                if (clock < min_rate || clock > max_rate)
135
 
                        continue;
136
 
 
137
 
                real xpos = scale_x(clock);
138
 
                real vcofrac = (vco - min_vco) / (max_vco - min_vco);
139
 
                real mark_height = (row_y1 + vcofrac * (row_y2 - row_y1));
140
 
 
141
 
                move_to(cr, xpos, mark_height - 1);
142
 
                line_to(cr, xpos, mark_height + 1);
143
 
                stroke(cr);
144
 
        }
145
 
 
146
 
        set_source_rgb(cr, 0, 0, 0);
147
 
        string p2label = sprintf("p2 = %d", p2);
148
 
        move_to(cr, 5, (p2i + .5) / (dim(p2vals) + 1) * height + 4);
149
 
        show_text(cr, p2label);
150
 
}
151
 
 
152
 
void label_clock(real clock) {
153
 
        real center_x = scale_x(clock);
154
 
        string label = sprintf("%d", floor((clock + 500) / 1000000));
155
 
                text_extents_t e = text_extents(cr, label);
156
 
        real left_x = center_x - e.x_advance / 2;
157
 
        save(cr);
158
 
        move_to(cr, left_x, height - 20);
159
 
        show_text(cr, label);
160
 
        restore(cr);
161
 
}
162
 
 
163
 
label_clock(min_rate);
164
 
label_clock(max_rate);
165
 
label_clock(140 * 1000 * 1000);
166
 
label_clock(115 * 1000 * 1000);
167
 
label_clock(100 * 1000 * 1000);
168
 
label_clock(82 * 1000 * 1000);
169
 
 
170
 
string xlabel = "Clock in Mhz";
171
 
text_extents_t e = text_extents(cr, xlabel);
172
 
move_to(cr, width / 2 - e.x_advance / 2, height - 5);
173
 
show_text(cr, xlabel);
174
 
sleep(10);