2 /*************************************************************************/
3 /* piece of code and pixmaps from */
5 /* wmspeedfreq ( Tom Kistner ) */
6 /* wmppp ( Martijn Pieterse, Antoine Nulle ) */
7 /* wmapkill (S.Rozange */
9 /* This program is free software; you can redistribute it and/or modify */
10 /* it under the terms of the GNU General Public License as published by */
11 /* the Free Software Foundation; either version 2, or (at your option) */
12 /* any later version. */
14 /* This program is distributed in the hope that it will be useful, */
15 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17 /* GNU General Public License for more details. */
19 /* You should have received a copy of the GNU General Public License */
20 /* along with this program (see the file COPYING); if not, write to the */
21 /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
22 /* Boston, MA 02111-1307, USA */
24 /* you need libcpufreq for the libarary */
25 /* and libcpufreq-dev for cpufreq.h */
28 /*************************************************************************/
38 #include <libdockapp/wmgeneral.h>
39 #include "wmcpufreq_master_1.xpm"
40 #include "wmcpufreq_master_2.xpm"
41 #include "wmcpufreq_master_3.xpm"
42 #include "wmcpufreq_mask_1.xbm"
43 #include "wmcpufreq_mask_2.xbm"
44 #include "wmcpufreq_mask_3.xbm"
46 #define DELAY 200000000 /*nano second */
47 #define WMCPUFREQ_VERSION "VERSION 3.0 2009/05/14 \n"
50 pid_t
execCommand(char *);
51 void show_mhz(unsigned long*,int);
52 void show_governor(char* );
53 void show_driver(char *);
56 static unsigned char *wm_bits
;
57 struct cpufreq_policy
*policy
;
59 unsigned long min
,max
,f_min
,f_max
;
60 int main(int argc
, char *argv
[])
62 struct timespec ts
,ts1
;
65 unsigned long freq
[8];
68 char drv
[20],*ptr
,*endptr
;
75 for(i
=0;i
<MAX_CPU
;i
++)
79 for (i
=1; i
<=argc
; i
++)
81 if (!strcmp(argv
[i
], "-v"))
83 printf(WMCPUFREQ_VERSION
);
86 if (!strcmp(argv
[i
], "-exe"))
88 if(strlen(argv
[i
+1]) < LN_PATH
)
89 strcpy(prg
,argv
[i
+1]);
92 if (!strcmp(argv
[i
], "-cpuid"))
94 if(strlen(argv
[i
+1]) < LN_PATH
)
95 idcpu
=strtol(argv
[i
+1],&endptr
,0);
96 printf("cpuid= %d \n",idcpu
);
99 printf("only -v, -exe, -cpuid supported \n");
107 printf("cpuid < 0 \n");
111 /* get driver name (guess all cpu have the same driver) */
112 ptr
=cpufreq_get_driver(cpu
);
115 printf("no driver found \n");
119 cpufreq_put_driver(ptr
);
122 /* get number of cpu (0=cpu0, 1=cpu1 ...) */
126 for(i
=0;i
<MAX_CPU
;i
++)
128 if( cpufreq_cpu_exists(idcpu
+i
) ==0)
130 printf("cpuid %d found\n",idcpu
+i
);
137 printf("no cpuid found \n");
140 wm_xpm
=wmcpufreq_master_xpm_1
;
141 wm_bits
=wmcpufreq_mask_bits_1
;
144 wm_xpm
=wmcpufreq_master_xpm_2
;
145 wm_bits
=wmcpufreq_mask_bits_2
;
148 wm_xpm
=wmcpufreq_master_3
;
149 wm_bits
=wmcpufreq_mask_3_bits
;
152 wm_xpm
=wmcpufreq_master_3
;
153 wm_bits
=wmcpufreq_mask_3_bits
;
156 printf("no yet implemented: cpuid %d \n",ncpu
);
161 /* guess every cpu has the same limits */
162 if(cpufreq_get_hardware_limits(cpu
, &f_min
, &f_max
))
164 printf("can't determine hardware limits \n");
167 openXwindow(argc
,argv
,
170 wmcpufreq_mask_width
,
171 wmcpufreq_mask_height
);
174 /* Process any pending X events */
175 while(XPending(display
))
177 XNextEvent(display
, &event
);
194 freq
[i
]=cpufreq_get_freq_kernel(i
+idcpu
);
195 policy
=cpufreq_get_policy(cpu
);
196 strcpy(gov
,policy
->governor
);
199 cpufreq_put_policy(policy
);
209 void show_driver( char *pt
)
216 copyXPMArea(6+(6*c
),64,6,9, 7+(6*i
), 34);
221 void show_governor(char *ptr
)
228 copyXPMArea(6+(6*c
),78,6,9, 7+(6*i
), 49);
233 void show_mhz(unsigned long *kHz
,int nu
)
235 int i
,j
,delta
=0,ddelta
=0,odelta
=0;
240 snprintf(buffer
, 5, "%4ld", (kHz
[0] / 1000));
243 if (buffer
[i
] == ' ')
246 copyXPMArea(75, 93, 6, 9, 7+(7*i
), 7);
250 /* a standard digit */
251 copyXPMArea(((buffer
[i
]-48)*7)+5,93, 6, 9, 7+(7*i
), 7);
253 /* update speed bar */
254 copyXPMArea(65, 18, 49, 9, 7, 18);
258 copyXPMArea(65, 40, ((kHz
[0] - f_min
) / ((f_max
- f_min
) / 49)), 9, 7, 18);
265 snprintf(buffer
, 5, "%4ld", (kHz
[j
] / 1000));
269 if (buffer
[i
] == ' ')
272 copyXPMArea(75, 93, 6, 9, 7+(7*i
), 7+delta
);
276 /* a standard digit */
277 copyXPMArea(((buffer
[i
]-48)*7)+5, 93, 6, 9, 7+(7*i
), 7+delta
);
280 /* update speed bar */
281 copyXPMArea(65, 18, 49, 4, 7, 18+delta
);
282 copyXPMArea(65, 40, ((kHz
[j
] - f_min
) / ((f_max
- f_min
) / 49)), 4, 7, 18+delta
);
295 snprintf(buffer
, 5, "%4ld", (kHz
[j
] / 1000));
299 if (buffer
[i
] == ' ')
302 copyXPMArea(126,6+odelta
*j
,6,7, 6+(6*i
),5+ddelta
*j
);
306 /* a standard digit */
307 copyXPMArea(((buffer
[i
]-48)*6)+66,6+odelta
*j
, 6,7, 6+(6*i
), 5+ddelta
*j
);
311 copyXPMArea(31,67,24,7,34,5+ddelta
*j
);
312 /* update spped bar */
313 if( !(nu
==2 && j
==3) ) /* 3 cpu 4 bar nul */
314 copyXPMArea(6,67 , ((kHz
[j
] - f_min
) / ((f_max
- f_min
) / 24)),7, 34,5+ddelta
*j
);