gkrellm2-cpufreq-0.6.4/0000755000175000017500000000000011715135422013030 5ustar chwchwgkrellm2-cpufreq-0.6.4/Makefile0000644000175000017500000000155511715135422014476 0ustar chwchw# Makefile for gkrellm cpufreq plugin GTK_INCLUDE = `pkg-config gtk+-2.0 --cflags` GTK_LIB = `pkg-config gtk+-2.0 --libs` FLAGS = -O2 -Wall -fPIC $(GTK_INCLUDE) LIBS = $(GTK_LIB) LFLAGS = -shared -lcpufreq CC = gcc $(CFLAGS) $(FLAGS) OBJS = cpufreq.o cpufreq.so: $(OBJS) $(CC) $(OBJS) -o cpufreq.so $(LFLAGS) $(LIBS) install: cpufreq.so install -D -m 755 -s cpufreq.so $(DESTDIR)/usr/lib/gkrellm2/plugins/cpufreq.so install -g root -o root -D -m 755 cpufreqnextgovernor $(DESTDIR)/usr/sbin/cpufreqnextgovernor install-sudo: echo "$(USER) ALL = (root) NOPASSWD: /usr/bin/cpufreq-set -c [0-9]* -g userspace" >> /etc/sudoers echo "$(USER) ALL = (root) NOPASSWD: /usr/bin/cpufreq-set -c [0-9]* -f [0-9]*" >> /etc/sudoers echo "$(USER) ALL = (root) NOPASSWD: /usr/sbin/cpufreqnextgovernor" >> /etc/sudoers clean: rm -f *.o core *.so* *.bak *~ cpufreq.o: cpufreq.c gkrellm2-cpufreq-0.6.4/LICENSE0000644000175000017500000003535411715135422014047 0ustar chwchw GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. gkrellm2-cpufreq-0.6.4/ChangeLog0000644000175000017500000000460011715135422014602 0ustar chwchw* 0.6.4 10.02.2012 Christoph Winkelmann - fix segmentation fault - update url in info tab * 0.6.3 09.02.2012 Christoph Winkelmann - more fine grain control of what to display when controls are coupled * 0.6.2 30.01.2012 Christoph Winkelmann - display only first governor and last slider when controls are coupled * 0.6.1 15.07.2007 Christoph Winkelmann - bugfix: segmentation fault on wakeup on SMP systems (patch from David Serrano) * 0.6 02.10.2006 Christoph Winkelmann - base on cpufrequtils - drop temperature support - SMP support * 0.5.5 24.11.2005 Christoph Winkelmann - bugfix: configuration was not loaded correctly (patch from Paul Cannon) * 0.5.4 09.11.2005 Christoph Winkelmann - remove degree sign for encoding incompatibilities - display slider optionally * 0.5.3 01.11.2005 Christoph Winkelmann - fixed typo in target 'install-sudo' in Makefile - change governor via new script for more flexibility (ondemand governor) - check for ondemand governor when reading frequency * 0.5.2 18.10.2004 Christoph Winkelmann - cpufreqset does not assume order in scaling_available_frequencies * 0.5.1 16.03.2004 Christoph Winkelmann - scaling factor for temperature added * 0.5 15.03.2004 Christoph Winkelmann - update plugin once a second only - display cpu temperature optionally - display cpufreq governor optionally - toggle governor when clicking on governor name - optionally set userspace governor when moving slider - reserve more height for text and slider - added 'install-sudo' target to Makefile - check for >1 cpu in cpufreqset * 0.4 31.01.2004 Christoph Winkelmann - make economic and efficient use of available interfaces * 0.3.3 28.01.2004 Christoph Winkelmann - supports new /sys (2.6.x kernel) interface (to be improved) * 0.3.2 12.01.2004 Christoph Winkelmann - improved documentation - improved Makefile * 0.3.1 12.01.2004 Christoph Winkelmann - always get cpu frequency from /proc/cpuinfo - get khz_max with khz - save khz_max in configuration - hand over absolute frequency to cpufreqset * 0.3 31.12.2003 Christoph Winkelmann - get cpu frequency from /proc/cpuinfo if /proc/sys/cpu/ unavailable - added numerical display of cpu frequency - display slider only * 0.2 12.12.2003 Christoph Winkelmann - added slider to set cpu freqency * 0.1 07.11.2003 Christoph Winkelmann - initial version gkrellm2-cpufreq-0.6.4/README0000644000175000017500000000305611715135422013714 0ustar chwchwREADME for gkrellm2-cpufreq =========================== Christoph Winkelmann Description: ------------ gkrellm2-cpufreq consists of two components: 1) A plugin for gkrellm 2.0 (http://www.gkrellm.net) called cpufreq.so displaying the current CPU frequency numerically and by the position of a slider, optionally the current cpufreq governor and the CPU temperature from /proc/acpi 2) A bash script called cpufreqnextgovernor allowing to set the cpufreq governor via the plugin. The plugin reads the CPU frequency and the cpufreq governor using cpufrequtils and displays it. Clicking on the governor name will toggle the governor. Moving the slider will reset the CPU frequency if the userspace governor is active. The slider position also represents the current frequency, on the left for 0, on the right for the maximal frequency, which is determined as the maximum found - in the configuration file - using cpufrequtils - in current operation Note: The maximal frequency found is NOT saved in the configuration file unless the configuration page is viewed by pressing the right mouse button on the plugin. Options: -------- Right-click on the plugin to set the options: - The display of the governor name may be switched off - The display of the slider may be switched off - The plugin can set the userspace governor when moving the slider - The control for multiple processors can be coupled Installation: ------------- See file INSTALL License: -------- See file LICENSE Anything else: -------------- Suggestions are welcome! gkrellm2-cpufreq-0.6.4/INSTALL0000644000175000017500000000342111715135422014061 0ustar chwchwInstallation of gkrellm2-cpufreq ================================ Christoph Winkelmann Requirements ------------ * gkrellm 2.0.0 or higher * linux kernel >= 2.6.0 including the respective cpufreq-driver for your CPU * cpufrequtils (see http://www.kernel.org/pub/linux/utils/kernel/cpufreq/cpufrequtils.html) If you want to change the CPU frequency and/or cpufreq governor using the plugin, you need moreover: * sudo (http://www.sudo.ws/sudo/) Installation ------------ 1) To compile the plugin, type 'make' 2) To install the plugin to foo/usr/lib/gkrellm2/plugins/ and the bash script cpufreqnextgovernor to foo/usr/sbin/, type 'make DESTDIR=foo install' Alternatively, you may install the plugin manually to ~/.gkrellm2/plugins/ (if you don't have root permissions) Post-Install ------------ 1) To allow the plugin to set frequencies and governors, add the following lines to your /etc/sudoers file, using visudo (as root, replacing /usr/bin with the path to cpufreq-set on your system): = (root) NOPASSWD: /usr/bin/cpufreq-set -c [0-9]* -g userspace = (root) NOPASSWD: /usr/bin/cpufreq-set -c [0-9]* -f [0-9]* = (root) NOPASSWD: /usr/sbin/cpufreqnextgovernor where is the user that runs gkrellm and is the name of the host to set the CPU frequency/governor. Alternatively you may type 'make install-sudo', which tries to do this automatically. This does not involve the syntax checking of visudo. Use 'make install-sudo' at your own risk! 2) To allow the bash script (or any userspace program) to change the CPU frequency, the userspace governor must be available. Any problems? ------------- Feel free to contact me if you encounter any problems. gkrellm2-cpufreq-0.6.4/cpufreqnextgovernor0000755000175000017500000000064711715135422017113 0ustar chwchw#!/bin/bash cpu="$1" # determine actual governor actual_gov=`cpufreq-info -c $cpu -p | sed 's/.*\ //'` # determine available governors avail_gov=`cpufreq-info -c $cpu -g` avail_gov1=`echo $avail_gov | sed "s/.*$actual_gov//"` avail_gov2=`echo $avail_gov | sed "s/$actual_gov.*//"` avail_gov=`echo "$avail_gov1 $avail_gov2" | sed "s/^\ //"` next_gov=`echo $avail_gov | sed "s/\ .*//"` cpufreq-set -c $cpu -g $next_gov gkrellm2-cpufreq-0.6.4/cpufreq.c0000644000175000017500000005244511715135422014653 0ustar chwchw/* cpufreq.c - requires GKrellmM 2.0.0 or higher * requires cpufrequtils * * author: Christoph Winkelmann, * * date version comment * 07/11/2003 0.1 initial release * 12/12/2003 0.2 added slider to set cpu frequency * 29/12/2003 0.2.1 get cpu frequency from /proc/cpuinfo if * /proc/sys/cpu/ unavailable * 31/12/2003 0.3 added numerical display of cpu frequency * display slider only * 11/01/2004 0.3.1 always get cpu frequency from /proc/cpuinfo * get khz_max with khz * save khz_max in configuration * hand over absolute frequency to cpufreqset * 28/01/2004 0.3.3 support for /sys interface * 31/01/2004 0.4 make economic and efficient use of available * interfaces * 15/03/2004 0.5 update plugin once a second only * display cpu temperature optionally * display cpufreq governor optionally * toggle governor when clicking on governor name * optionally set userspace governor when moving slider * reserve more height for text and slider * 16/03/2004 0.5.1 scaling factor for temperature added * 18/10/2004 0.5.2 added version number and www-link to about screen * 01/11/2005 0.5.3 use new script cpufreqnextgovernor to toggle gov. * check for ondemand governor when reading frequency * 09/11/2005 0.5.4 remove degree sign for encoding incompatibilities * display slider optionally * 24/11/2005 0.5.5 bugfix: configuration was not loaded correctly * 02/10/2006 0.6 base on cpufrequtils * drop temperature support * SMP support * 15/07/2007 0.6.1 bugfix: segmentation fault on wakeup on SMP systems * 30/01/2012 0.6.2 display only first governor and last slider * when controls are coupled * 09/02/2012 0.6.3 more fine grain control of what to display when * controls are coupled * 10/02/2012 0.6.4 fix segmentation fault * * gcc -Wall -fPIC -Wall `pkg-config --cflags gtk+-2.0` -c cpufreq.c * gcc -shared -lcpufreq -Wl -o cpufreq.so cpufreq.o * gkrellm -p cpufreq.so * * Adapted from the official plugin-demos */ #include #include /* version number */ #define VERSION "0.6.4" /* name in the configuration tree */ #define CONFIG_NAME "CPUfreq" /* theme subdirectory for custom images for this plugin and gkrellmrc style name for custom settings */ #define STYLE_NAME "cpufreq" #define NCPU_MAX 8 static unsigned int ncpu; static unsigned long khz_max; static unsigned long khz[NCPU_MAX]; static const int length = BUFSIZ; static char governor[NCPU_MAX][256]; static char empty[1]; static char* governor_text[NCPU_MAX]; static GkrellmMonitor* monitor; static GkrellmPanel* panel; static GkrellmTicks* pGK; static GkrellmDecal* text_decal_freq[NCPU_MAX]; static GkrellmDecal* text_decal_gov[NCPU_MAX]; static GkrellmKrell* slider_krell[NCPU_MAX]; static GkrellmKrell* slider_in_motion[NCPU_MAX]; static double slider_value[NCPU_MAX]; static gint gov_enable = 1; static gint gov_enable_current; static gint slider_enable = 1; static gint slider_enable_current; static gint slider_userspace_enable = 1; static gint controls_coupled = 0; static gint controls_coupled_current; static gint one_slider_coupled = 1; static gint one_slider_coupled_current; static gint one_freq_coupled = 0; static gint one_freq_coupled_current; static gint style_id; static void read_governors() { unsigned int cpu; for ( cpu=0; cpugovernor); cpufreq_put_policy(policy); } else { strcpy(governor[cpu], "unknown"); } } } static void read_khz() { if (!gov_enable_current) { /* otherwise it has already been read in this update step */ read_governors(); } /* current freqs */ unsigned int cpu; for ( cpu=0; cpu khz_max ? khz[cpu] : khz_max; } } static void next_governor(unsigned int cpu) { char cmd[length]; sprintf(cmd, "sudo /usr/sbin/cpufreqnextgovernor %u", cpu); system(cmd); } static void governor_userspace(unsigned int cpu) { char cmd[length]; sprintf(cmd, "sudo cpufreq-set -c %u -g userspace", cpu); system(cmd); } static void set_frequency(unsigned int cpu, unsigned long freq) { char cmd[length]; sprintf(cmd, "sudo cpufreq-set -c %u -f %lu", cpu, freq ); system(cmd); } static void update_plugin() { if(!pGK->second_tick) { return; } if (gov_enable_current) { read_governors(); } read_khz(); unsigned int cpu; if (slider_enable_current) { if (controls_coupled_current && one_slider_coupled_current) { if(!slider_in_motion[ncpu-1]) { int krellpos = 0; for( cpu=0; cpuw_scale; } krellpos /= khz_max*ncpu; gkrellm_update_krell(panel, slider_krell[ncpu-1], krellpos); } } else { for( cpu=0; cpuw_scale*khz[cpu]/khz_max; gkrellm_update_krell(panel, slider_krell[cpu], krellpos); } } } } char theText[length]; if (controls_coupled_current && one_freq_coupled_current) { int khz_sum = 0; for ( cpu=0; cpux_off = 0; gkrellm_draw_decal_text(panel, text_decal_gov[cpu], governor_text[cpu], -1); } sprintf(theText, "%d MHz", (int)((khz_sum/ncpu+500)/1000)); text_decal_freq[0]->x_off = 0; gkrellm_draw_decal_text(panel, text_decal_freq[0], theText, -1); } else { for ( cpu=0; cpux_off = 0; gkrellm_draw_decal_text(panel, text_decal_freq[cpu], theText, -1); text_decal_gov[cpu]->x_off = 0; gkrellm_draw_decal_text(panel, text_decal_gov[cpu], governor_text[cpu], -1); } } gkrellm_draw_panel_layers(panel); } static void update_slider_position(GkrellmKrell *k, gint x_ev, unsigned int cpu) { if (k) { gint x; /* Consider only x_ev values that are inside the dynamic range of the krell. */ x = x_ev - k->x0; if (x < 0) x = 0; if (x > k->w_scale) x = k->w_scale; gkrellm_update_krell(panel, k, x); gkrellm_draw_panel_layers(panel); slider_value[cpu] = (double) x / (double) k->w_scale; /* ranges 0.0-1.0 */ } } static gint cb_panel_motion(GtkWidget* widget, GdkEventMotion* ev, gpointer data) { GdkModifierType state; unsigned int cpu; for ( cpu=0; cpustate; if (!(state & GDK_BUTTON1_MASK)) { slider_in_motion[cpu] = NULL; } else { update_slider_position(slider_in_motion[cpu], (gint) ev->x, cpu); } } } return TRUE; } static gint cb_panel_release(GtkWidget* widget, GdkEventButton* ev, gpointer data) { unsigned int cpu; for ( cpu=0; cpubutton == 3) { gkrellm_open_config_window(monitor); return TRUE; } unsigned int cpu; for ( cpu=0; cpux > k->x0 && ev->x <= k->x0 + k->w_scale && ev->y >= k->y0 && ev->y <= k->y0 + k->h_frame ) { slider_in_motion[cpu] = k; } if (slider_in_motion[cpu]) { update_slider_position(slider_in_motion[cpu], (gint) ev->x, cpu); } /* Check if button was pressed within the space taken up by the governor text */ if (gov_enable_current && ev->x > text_decal_gov[cpu]->x && ev->x <= text_decal_gov[cpu]->x + text_decal_gov[cpu]->w && ev->y >= text_decal_gov[cpu]->y && ev->y <= text_decal_gov[cpu]->y + text_decal_gov[cpu]->h) { /* toggle governor */ if(controls_coupled) { unsigned int icpu; for ( icpu=0; icpuwindow, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], panel->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); return FALSE; } static void create_plugin(GtkWidget* vbox, gint first_create) { GkrellmStyle* style; GkrellmPiximage* krell_image; GkrellmTextstyle* ts; gint y = -1; unsigned int cpu; /* called when GKrellM is re-built at every theme or horizontal size change */ if (first_create) panel = gkrellm_panel_new0(); read_khz(); for ( cpu=0; cpuy + text_decal_gov[cpu]->h + 1; } else { governor_text[cpu] = empty; } /* the frequency text */ text_decal_freq[cpu] = gkrellm_create_decal_text(panel, "0123456789 MHz", ts, style, -1, /* x = -1 places at left margin */ y, /* y = -1 places at top margin */ -1); /* w = -1 makes decal the panel width minus margins */ if (!(controls_coupled && one_freq_coupled) || cpu==0) { y = text_decal_freq[cpu]->y + text_decal_freq[cpu]->h + 1; } /* the slider */ if (slider_enable && (!(controls_coupled && one_slider_coupled) || cpu==ncpu-1) ) { krell_image = gkrellm_krell_slider_piximage(); gkrellm_set_style_slider_values_default(style, y, /* y offset */ 0, 0); /* Left and right krell margins */ slider_krell[cpu] = gkrellm_create_krell(panel, krell_image, style); y = slider_krell[cpu]->y0 + slider_krell[cpu]->h_frame + 2; gkrellm_monotonic_krell_values(slider_krell[cpu], FALSE); gkrellm_set_krell_full_scale(slider_krell[cpu], slider_krell[cpu]->w_scale, 1); gkrellm_update_krell(panel, slider_krell[cpu], 0); update_slider_position(slider_krell[cpu], slider_krell[cpu]->w_scale*khz[cpu]/khz_max, cpu); } } slider_enable_current = slider_enable; gov_enable_current = gov_enable; controls_coupled_current = controls_coupled; one_slider_coupled_current = one_slider_coupled; one_freq_coupled_current = one_freq_coupled; /* configure and create the panel */ gkrellm_panel_configure(panel, "", style); gkrellm_panel_create(vbox, monitor, panel); if (first_create) { g_signal_connect(G_OBJECT (panel->drawing_area), "expose_event", G_CALLBACK(panel_expose_event), NULL); g_signal_connect(G_OBJECT(panel->drawing_area), "button_press_event", G_CALLBACK(cb_panel_press), NULL ); g_signal_connect(G_OBJECT(panel->drawing_area), "button_release_event", G_CALLBACK(cb_panel_release), NULL ); g_signal_connect(G_OBJECT(panel->drawing_area), "motion_notify_event", G_CALLBACK(cb_panel_motion), NULL); } } /* Configuration */ #define PLUGIN_CONFIG_KEYWORD STYLE_NAME static GtkWidget* gov_enable_button; static GtkWidget* slider_enable_button; static GtkWidget* slider_userspace_enable_button; static GtkWidget* controls_coupled_button; static GtkWidget* one_slider_coupled_button; static GtkWidget* one_freq_coupled_button; static void save_plugin_config(FILE *f) { fprintf(f, "%s khz_max %d\n", PLUGIN_CONFIG_KEYWORD, (int)khz_max); fprintf(f, "%s gov_enable %d\n", PLUGIN_CONFIG_KEYWORD, gov_enable); fprintf(f, "%s slider_userspace_enable %d\n", PLUGIN_CONFIG_KEYWORD, slider_userspace_enable); fprintf(f, "%s slider_enable %d\n", PLUGIN_CONFIG_KEYWORD, slider_enable); fprintf(f, "%s controls_coupled %d\n", PLUGIN_CONFIG_KEYWORD, controls_coupled); fprintf(f, "%s one_slider_coupled %d\n", PLUGIN_CONFIG_KEYWORD, one_slider_coupled); fprintf(f, "%s one_freq_coupled %d\n", PLUGIN_CONFIG_KEYWORD, one_freq_coupled); } static void load_plugin_config(gchar *arg) { gchar config[64], item[256]; gint n; int khz_max_config; n = sscanf(arg, "%s %[^\n]", config, item); if (n == 2) { if (strcmp(config, "khz_max") == 0) { sscanf(item, "%d\n", &khz_max_config); if (khz_max_config > khz_max) { khz_max = khz_max_config; } } else if (strcmp(config, "slider_enable") == 0) { sscanf(item, "%d", &slider_enable); slider_enable_current = slider_enable; } else if (strcmp(config, "slider_userspace_enable") == 0) { sscanf(item, "%d", &slider_userspace_enable); } else if (strcmp(config, "gov_enable") == 0) { sscanf(item, "%d", &gov_enable); gov_enable_current = gov_enable; unsigned int cpu; for ( cpu=0; cpuactive; slider_enable = GTK_TOGGLE_BUTTON(slider_enable_button)->active; slider_userspace_enable = GTK_TOGGLE_BUTTON(slider_userspace_enable_button)->active; controls_coupled = GTK_TOGGLE_BUTTON(controls_coupled_button)->active; one_slider_coupled = GTK_TOGGLE_BUTTON(one_slider_coupled_button)->active; one_freq_coupled = GTK_TOGGLE_BUTTON(one_freq_coupled_button)->active; } static gchar *plugin_info_text[] = { "CPU frequency plugin\n", "gkrellm2-cpufreq ",VERSION,", ", "
    http://chw.tks6.net/rub/7\n", "by Christoph Winkelmann, ", "
      chw@tks6.net\n\n", "Enabling and disabling display of governor, frequency or slider only\n", "takes effect after change of theme, change of width, or restart.\n\n", "The maximal frequency found during this run is saved for the next run\n", "when this page is viewed.\n\n", "Any suggestions are welcome!", /* "\n\tPut any documentation here to explain your plugin.\n", "\tText can be ", "bold", " or ", "italic", " or ", "
        underlined.\n", */ }; static void create_plugin_tab(GtkWidget *tab_vbox) { GtkWidget* tabs; GtkWidget* vbox; GtkWidget* vbox1; GtkWidget* text; gint i; tabs = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(tab_vbox), tabs, TRUE, TRUE, 0); /* -- Options tab -- */ vbox = gkrellm_gtk_framed_notebook_page(tabs, "Options"); /* -- Governor options -- */ vbox1 = gkrellm_gtk_framed_vbox(vbox, "CPUfreq governor", 4, FALSE, 0, 2); gkrellm_gtk_check_button(vbox1, &gov_enable_button, gov_enable, FALSE, 0, "Show governor (see Info tab)"); gkrellm_gtk_check_button(vbox1, &slider_userspace_enable_button, slider_userspace_enable, FALSE, 0, "Set userspace governor when moving slider"); /* -- Slider options -- */ vbox1 = gkrellm_gtk_framed_vbox(vbox, "Slider", 4, FALSE, 0, 2); gkrellm_gtk_check_button(vbox1, &slider_enable_button, slider_enable, FALSE, 0, "Show slider (see Info tab)"); /* -- SMP options -- */ vbox1 = gkrellm_gtk_framed_vbox(vbox, "SMP", 4, FALSE, 0, 2); gkrellm_gtk_check_button(vbox1, &controls_coupled_button, controls_coupled, FALSE, 0, "Couple controls of multiple CPUs"); gkrellm_gtk_check_button(vbox1, &one_slider_coupled_button, one_slider_coupled, FALSE, 0, "Display only one slider when controls are coupled (see Info tab)"); gkrellm_gtk_check_button(vbox1, &one_freq_coupled_button, one_freq_coupled, FALSE, 0, "Display only average frequency when controls are coupled (see Info tab)"); /* -- Info tab -- */ vbox = gkrellm_gtk_framed_notebook_page(tabs, "Info"); text = gkrellm_gtk_scrolled_text_view(vbox, NULL, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); for (i = 0; i < sizeof(plugin_info_text)/sizeof(gchar *); ++i) gkrellm_gtk_text_view_append(text, plugin_info_text[i]); } /* The monitor structure tells GKrellM how to call the plugin routines. */ static GkrellmMonitor plugin_mon = { CONFIG_NAME, /* Title for config clist */ 0, /* Id, 0 if a plugin */ create_plugin, /* The create function */ update_plugin, /* The update function */ create_plugin_tab, /* The config tab create function */ apply_plugin_config, /* Apply the config function */ save_plugin_config, /* Save user config */ load_plugin_config, /* Load user config */ PLUGIN_CONFIG_KEYWORD, /* config keyword */ NULL, /* Undefined 2 */ NULL, /* Undefined 1 */ NULL, /* private */ MON_CPU, /* Insert plugin before this monitor */ NULL, /* Handle if a plugin, filled in by GKrellM */ NULL /* path if a plugin, filled in by GKrellM */ }; /* All GKrellM plugins must have one global routine named init_plugin() which returns a pointer to a filled in monitor structure. */ GkrellmMonitor* gkrellm_init_plugin(void) { /* If this next call is made, the background and krell images for this plugin can be custom themed by putting bg_meter.png or krell.png in the subdirectory STYLE_NAME of the theme directory. Text colors (and other things) can also be specified for the plugin with gkrellmrc lines like: StyleMeter STYLE_NAME.textcolor orange black shadow If no custom theming has been done, then all above calls using style_id will be equivalent to style_id = DEFAULT_STYLE_ID. */ pGK = gkrellm_ticks(); style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME); monitor = &plugin_mon; /* determine number of cpus */ for( ncpu = 0; cpufreq_cpu_exists(ncpu)==0; ++ncpu ) ; ncpu = ncpu > NCPU_MAX ? NCPU_MAX : ncpu; /* determine maximal frequency */ unsigned int cpu; for ( cpu = 0; cpu