Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
gkrellm2 plugin::displaying CPU frequency
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Sun Jun 06, 2004 8:37 am    Post subject: gkrellm2 plugin::displaying CPU frequency Reply with quote

this is a basic gkrellm plugin(i've tested it in 2.1.28,and 2.2.0 and work well)and if u could help me with some athlon and intel cpuinfos so i can add the modelname too

here's the code(and if u know another routine that extracts mhz and it's not as bloated as mine post it here :P )
Code:
#include <stdio.h>
#include <string.h>
#include <gkrellm2/gkrellm.h>
#define CONFIG_NAME "CPU-freqency"
#define STYLE_NAME "cpumhz"

static GkrellmMonitor *monitor;
static GkrellmPanel* panel;
static GkrellmTicks* pGK;
static gint style_id;
static int lung = BUFSIZ;
char frequ[BUFSIZ];

static void read_freq() {
   FILE *file;
   char *filename = "/proc/cpuinfo";
   char freq[lung],buf[lung];
   int i;

   if ((file=fopen(filename, "r"))){
   while ( fgets(buf, sizeof buf, file)){
      if ( strncmp(buf, "cpu M", 5)==0 )
         sprintf (freq, "%s", strchr(buf, ':')+2);
   }

   for(i=0; i<strlen(freq) ; i++)
      if (freq[i] == 46 )
         i = strlen(freq);
      else
         frequ[i]=freq[i];
   }
   fclose( file );
}

static gint panel_expose_event(GtkWidget* widget, GdkEventExpose* ev) {
  gdk_draw_pixmap(widget->window,
                  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;
 
  if (first_create)
     panel = gkrellm_panel_new0();

  style = gkrellm_meter_style(style_id);

  read_freq();
 
  char _text_[lung];
  sprintf(_text_,"%s MHz",frequ);
  gkrellm_panel_configure(panel, _text_ , 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);
  }
}

#define PLUGIN_CONFIG_KEYWORD  STYLE_NAME

static void config_plugin(GtkWidget *vbox) {
  gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("Gkrellm plugin for CPU frequency display(v0.3)\n\n"
                    "by <colegu@gmx.net>\n"), TRUE, TRUE, 0);
}


static GkrellmMonitor  plugin_mon = {
  CONFIG_NAME,       
  0,                 
  create_plugin,     
  NULL,         
  config_plugin,     
  NULL,             

  NULL,                
  NULL,               
  PLUGIN_CONFIG_KEYWORD,

  NULL,               
  NULL,               
  NULL,               

  MON_CPU,           

  NULL,               
  NULL               
};



GkrellmMonitor* gkrellm_init_plugin(void)

{
 
  pGK = gkrellm_ticks();
  style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME);
  monitor = &plugin_mon;
  return &plugin_mon;
}


to compile it here's the script build.sh(taken from gkrellm demos)
Code:
#!/bin/sh

case $# in
  0)
    echo "Usage:  build  plugin"
    echo "  Compile a GKrellM demo plugin.c to a .so file,"
   echo "  where plugin is any of the .c demo files in this directory."
    echo "  After creating the .so file, check it out by running:"
    echo "      gkrellm -p plugin.so"
   echo ""
        exit 1 ;;
esac


gcc -Wall -fPIC -Wall `pkg-config --cflags gtk+-2.0` -c $1.c
gcc -shared -Wl -o $1.so $1.o
rm $1.o

use it like this
$./build.sh mycode (where the plugin code is named mycode.c)
after this move the resulting .so to /home/*/.gkrellm2/plugins/
restart gkrellm and select my plugin

hope this is usefull for the eyecandy maniacs :))

alles gute!
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
drewmanto
n00b
n00b


Joined: 29 May 2004
Posts: 26
Location: Arizona

PostPosted: Sun Jun 06, 2004 8:40 am    Post subject: Reply with quote

im suprised that there is no current plugin for this exact feature. I currently run gentoo on a laptop with a pentrium 4M so this is really a cool peice of code you have. Ill take a look at it and see if i can add my 2 sense. :)
_________________
fvwm Iron men
Ikaro - http://fluxmod.dk/ikaro.dk/public_html/
taviso - http://dev.gentoo.org/~taviso/
Syzygy - http://desintegr.free.fr/fvwm/
Sparks - http://www.bzsparks.com/fvwm/
Back to top
View user's profile Send private message
cryos
Retired Dev
Retired Dev


Joined: 08 Mar 2003
Posts: 242
Location: US

PostPosted: Sun Jun 06, 2004 3:55 pm    Post subject: Reply with quote

This works great on my AMD Athlon 64 3200+ - correctly shows when it is at 1000MHz or 2000MHz. Thanks for sharing the plugin - you should try to get this made into an ebuild!
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Sun Jun 06, 2004 4:31 pm    Post subject: Reply with quote

i forgot something
to display the frequency left,center or right(in gkrellm)
put this line in ~/.gkrellm2/themes/your_theme/gkrellmrc
Code:

StyleMeter  cpumhz.label_position = 50

50 - displays the freq in the center,0 left,100 right
to customize it even more make a dir called cpumhz in ~/.gkrellm2/themes/your_theme/
and create your own bg_meter.png

as,for the ebuild,it's abit difficult cause i dont have any server to host it
and i'm not always onlain..
future updates will get posted here (i'm planning to add the model name of the cpu too,but i need cpuinfos and right now i'm too lazy to search on google :P )
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
cryos
Retired Dev
Retired Dev


Joined: 08 Mar 2003
Posts: 242
Location: US

PostPosted: Mon Jun 07, 2004 6:44 pm    Post subject: Reply with quote

I think I spoke too soon actually. For some reason it always thinks my CPU is at 2000 MHz, even though it has been at 1000 MHz for the last 20 minutes. I tried opening and closing gkrellm2, and it still doesn't work. My /proc/cpuinfo is below for when it is clocked to 1000 MHz,
Code:
marcus@athlon64 marcus $ cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 15
model           : 4
model name      : AMD Athlon(tm) 64 Processor 3200+
stepping        : 10
cpu MHz         : 1000.074
cache size      : 1024 KB
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow
bogomips        : 2031.61
TLB size        : 1088 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp

Don't know why it isn't detecting the proc speed now... Do you have any ideas? This is Gentoo Linux 64 bit compiled with GCC 3.4. I've had a quick look myself and I can't see immediately anything wrong.
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Mon Jun 07, 2004 7:37 pm    Post subject: Reply with quote

cryos wrote:
For some reason it always thinks my CPU is at 2000 MHz, n though it has been at 1000 MHz for the last 20 minutes.

your CPU is changing it's speed while the kernel is running?

the plugin doesnt have an update function,once the plugin is created(or a theme si changed) the plugin should display the freq corectly
i took your cpuinfo and for me it works (though,when i change the speed from 1000.xxx to 2000.xxx it doesnt display it corectly until i restart gkrellm
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
cryos
Retired Dev
Retired Dev


Joined: 08 Mar 2003
Posts: 242
Location: US

PostPosted: Mon Jun 07, 2004 8:57 pm    Post subject: Reply with quote

It's a power saving feature of AMD Athlon 64 processors. They can all change their core frequency (via multiplier change) and their core voltage. GKrellm2 picks up the core voltage change, but this plugin doesn't pick up the change to 1000 MHz. I suspect it clocks back up to 2000 MHz momentarily whilst gkrellm2 loads.

Using cpudynd to change frequency, and gentoo-dev-sources-2.6.5-r1. It works really well but I thought this plugin would be great to show the change in CPU frequency. Is there an easy way to modify it to poll every 5 seconds or something? I think some laptops can do the same too.
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Tue Jun 08, 2004 4:48 am    Post subject: Reply with quote

i'll add an update function soon
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Wed Jun 09, 2004 6:38 am    Post subject: Reply with quote

mortix wrote:
i'll add an update function soon

lol,this update was not so soon,yesterday i had some problems...
the update_plugin feature came up to be,an almost total rewrite of the plugin :)
i've based my update_plugin function upon uptime.c(from gkrellm 2.1.28)
for me it works but it points out a stupid warning(ignore it)
here's the updated code,it updates the mhz once five seconds,so at the startup notice a little delay ...
this plugin should be used only if your cpu frequency changes speed while running,in any other case use the first version

Code:

#include <stdio.h>
#include <string.h>
#include <gkrellm2/gkrellm.h>
#define CONFIG_NAME "CPU-freqency"
#define STYLE_NAME "cpumhz"

static GkrellmMonitor *monitor;
static GkrellmPanel* panel;
static GkrellmTicks* pGK;
static GkrellmDecal* text_decal;
static gint style_id;
static int lung = BUFSIZ;
static char frequ[BUFSIZ];

static void read_freq() {
   FILE *file;
   char *filename = "/proc/cpuinfo";
   char freq[lung],buf[lung];
   int i;
   
   
   if ((file=fopen(filename, "r"))){
   while ( fgets(buf, sizeof buf, file)){
      if ( strncmp(buf, "cpu M", 5)==0 )
         sprintf (freq, "%s", strchr(buf, ':')+2);
   }

   for(i=0; i<strlen(freq) ; i++)
      if (freq[i] == 46 )
         i = strlen(freq);
      else
         frequ[i]=freq[i];
   }
   fclose( file );
}

static gint panel_expose_event(GtkWidget* widget, GdkEventExpose* ev) {
  gdk_draw_pixmap(widget->window,
                  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 update_plugin(){
   GkrellmTextstyle *ts;
   gint w;

   ts = gkrellm_meter_textstyle(style_id);
   
   if(pGK->five_second_tick){
      read_freq();
      char _text_[lung];
      sprintf(_text_,"%s MHz",frequ);
      w = gkrellm_gdk_string_width(ts->font,_text_);
      text_decal->x_off = (text_decal->w - w) /2;
      if (text_decal->x_off <0)
         text_decal->x_off = 0;
      text_decal->text_style.font = ts->font;
      gkrellm_draw_decal_text(panel,text_decal,_text_,-1);
      gkrellm_draw_panel_layers(panel);
   }
   
}
static void create_plugin(GtkWidget* vbox, gint first_create) {
 GkrellmStyle* style;
 GkrellmTextstyle* ts;
 
 if (first_create)
     panel = gkrellm_panel_new0();

  style = gkrellm_meter_style(style_id);
  ts = gkrellm_meter_textstyle(style_id);

  text_decal = gkrellm_create_decal_text(panel,"MHz",ts,style,-1,-1,-1);
  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);
  }
}

#define PLUGIN_CONFIG_KEYWORD  STYLE_NAME

static void config_plugin(GtkWidget *vbox) {
  gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("Gkrellm plugin for CPU frequency display(v0.4)\n\n"
                    "by <colegu@gmx.net>\n"), TRUE, TRUE, 0);
}


static GkrellmMonitor  plugin_mon = {
  CONFIG_NAME,       
  0,                 
  create_plugin,     
  update_plugin,         
  config_plugin,     
  NULL,               

  NULL,                
  NULL,               
  PLUGIN_CONFIG_KEYWORD,

  NULL,               
  NULL,               
  NULL,               

  MON_CPU,           

  NULL,               
  NULL               
};
GkrellmMonitor* gkrellm_init_plugin(void)
{
  pGK = gkrellm_ticks();
  style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME);
  monitor = &plugin_mon;
  read_freq();
  return &plugin_mon;
}

cyros,please tell me if this works for you,if you find that five seconds isn't resonable enough tell me and i'll change it(you could change it aswell )
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
cryos
Retired Dev
Retired Dev


Joined: 08 Mar 2003
Posts: 242
Location: US

PostPosted: Wed Jun 09, 2004 4:49 pm    Post subject: Reply with quote

It works perfectly. I am not sure what rate the gkrellm2 sensors update at - I might update the poll frequency. Other than that it works great though - you can see it correctly sensing the 1GHz clock along with the lower VCore. Thanks for coding this up - I think it will be really useful for others using cpudynd with laptops too where the frequency is dynamically altered according to needs. It is reassuring to see the speed there.

I can't get the image tag to work, but a screenshot is here.

Thanks :P
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Wed Jun 09, 2004 5:05 pm    Post subject: Reply with quote

cryos wrote:

I can't get the image tag to work, but a screenshot is here.

i'm not sure i understand what image tag is it about(english not my mother language :) )
i'm glad u found my plugin usefull
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
cryos
Retired Dev
Retired Dev


Joined: 08 Mar 2003
Posts: 242
Location: US

PostPosted: Wed Jun 09, 2004 8:41 pm    Post subject: Reply with quote

Thanks for going to the trouble of authoring the plugin! It works great now that it can update itself too - I have to say I wouldn't find it useful if my CPU didn't change speed whilst running to reduce power consumption and heat generation.

It seems to work really well despite the warnings it generated. Great work!
Back to top
View user's profile Send private message
beastmaster
Apprentice
Apprentice


Joined: 24 May 2004
Posts: 230

PostPosted: Wed Jun 09, 2004 11:45 pm    Post subject: Reply with quote

i use it too, it's awesome ;)

Thanks mortix. :P
Back to top
View user's profile Send private message
Master_Of_Disaster
l33t
l33t


Joined: 28 Feb 2003
Posts: 610
Location: 15.05072° East, 48.13747° North (aka Mauer), Austria

PostPosted: Thu Jun 10, 2004 10:24 am    Post subject: Reply with quote

Good work mortix!

I quickly hacked together a Makefile and put some things into a header file.

I put it on an Angelfire account, I hope this is ok.
Find it here:
http://www.angelfire.com/linux/ifs/gkrellm2-cpuinfo.tar.bz2
_________________
post tenebras lux, post fenestras tux
Registered Linux User Nr. 312509
Adopt an unanswered post today!
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Thu Jun 10, 2004 12:16 pm    Post subject: Reply with quote

Master_Of_Disaster wrote:
Good work mortix!

I quickly hacked together a Makefile and put some things into a header file.

I put it on an Angelfire account, I hope this is ok.
Find it here:
http://www.angelfire.com/linux/ifs/gkrellm2-cpuinfo.tar.bz2

good work!
now,an ebuild will be on my todo list

gkrellm rocks!
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
paolo
l33t
l33t


Joined: 23 Jul 2002
Posts: 768
Location: SBT (AP)

PostPosted: Thu Jun 10, 2004 7:58 pm    Post subject: Reply with quote

Hi guys,
I use this: http://iacs.epfl.ch/~winkelma/gkrellm2-cpufreq/
Let's take a look.

Bye,
P.
_________________
Nihil sine magno labore
Back to top
View user's profile Send private message
gigel
Guru
Guru


Joined: 14 Jan 2003
Posts: 350
Location: .se/.ro

PostPosted: Fri Jun 11, 2004 4:38 am    Post subject: Reply with quote

paolo wrote:
Hi guys,
I use this: http://iacs.epfl.ch/~winkelma/gkrellm2-cpufreq/
Let's take a look.

Bye,
P.

when one needs a program the best thing to do is search google :P...
too bad that this was not in portage
i't has far more features than my plugin!
thanx for the link
_________________
$emerge sux
:D
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum