On 10/01/12 08:22, Vincent Torri wrote:
maybe this could help you :

http://stackoverflow.com/questions/4226353/show-memory-and-cpu-in-c

Vincent
?

There is no problem when getting the frequency.
The only difference with linux is that instead
of displaying available frequencies (in the menu),
we display 25-50-75-100% - as we can only set
percents.

We unfortunately cannot get available levels, so
we don't know what is the max/min frequency
available for the processor, and it sometimes
causes problem with the speedcounter, which
doesn't know where to place the freq in the
counter.

PS: I forgot to mention that the freebsd support
is broken.

Here are patches again. This time it's really ok,
I also quickly modified the freebsd code.

--- e_mod_main.c        Mon Oct  1 14:58:24 2012
+++ e_mod_main.c        Mon Oct  1 14:41:45 2012
@@ -1,9 +1,8 @@
 #include "e.h"
 #include "e_mod_main.h"
 
-#ifdef __FreeBSD__
-#include <sys/types.h>
-#include <sys/sysctl.h>
+#if defined (__FreeBSD__) || defined (__OpenBSD__)
+# include <sys/sysctl.h>
 #endif
 
 /* gadcon requirements */
@@ -291,17 +290,29 @@
 
                   frequency = (long)l->data;
                   mi = e_menu_item_new(mo);
+
+#ifdef __OpenBSD__
+                  snprintf(buf, sizeof(buf), "%i %%", frequency);
+#else
                   if (frequency < 1000000)
                     snprintf(buf, sizeof(buf), _("%i MHz"), frequency / 1000);
                   else
                     snprintf(buf, sizeof(buf), _("%'.1f GHz"),
                              frequency / 1000000.);
+#endif
+
                   buf[sizeof(buf) - 1] = 0;
                   e_menu_item_label_set(mi, buf);
                   e_menu_item_radio_set(mi, 1);
                   e_menu_item_radio_group_set(mi, 1);
+
+#ifdef __OpenBSD__
+                  if (cpufreq_config->status->cur_percent == frequency)
+                    e_menu_item_toggle_set(mi, 1);
+#else
                   if (cpufreq_config->status->cur_frequency == frequency)
                     e_menu_item_toggle_set(mi, 1);
+#endif
                   e_menu_item_callback_set(mi, _cpufreq_menu_frequency, 
l->data);
                }
           }
@@ -445,8 +456,10 @@
         return;
      }
 
-   // change it to "userspace"
+#ifndef __OpenBSD__
+   /* OpenBSD doesn't have governors */
    _cpufreq_set_governor("userspace");
+#endif
 
    snprintf(buf, sizeof(buf),
             "%s %s %i", cpufreq_config->set_exe_path, "frequency", frequency);
@@ -548,14 +561,45 @@
 {
    char buf[4096];
    Eina_List *l;
-   // FIXME: this sssumes all cores accept the same freqs/ might be wrong
-#ifdef __FreeBSD__
-   int freq, i;
-   size_t len = 0;
+   // FIXME: this assumes all cores accept the same freqs/ might be wrong
+
+#if defined (__OpenBSD__)
+   int freq, mib[] = {CTL_HW, HW_CPUSPEED};
+   size_t len = sizeof(freq);
+   int p;
+
+   if (sysctl(mib, 2, &freq, &len, NULL, 0) == 0)
+     {
+        if (s->frequencies)
+          {
+             eina_list_free(s->frequencies);
+             s->frequencies = NULL;
+          }
+
+        if (s->governors)
+          {
+             for (l = s->governors; l; l = l->next)
+               free(l->data);
+             eina_list_free(s->governors);
+             s->governors = NULL;
+          }
+
+        /* storing percents */
+        p = 100;
+        s->frequencies = eina_list_append(s->frequencies, (void *)p);
+        p = 75;
+        s->frequencies = eina_list_append(s->frequencies, (void *)p);
+        p = 50;
+        s->frequencies = eina_list_append(s->frequencies, (void *)p);
+        p = 25;
+        s->frequencies = eina_list_append(s->frequencies, (void *)p);
+     }
+#elif defined (__FreeBSD__)
+   int freq;
+   size_t len = sizeof(buf);
    char *freqs, *pos, *q;
 
    /* read freq_levels sysctl and store it in freq */
-   len = sizeof(buf);
    if (sysctlbyname("dev.cpu.0.freq_levels", buf, &len, NULL, 0) == 0)
      {
         /* sysctl returns 0 on success */
@@ -665,18 +709,37 @@
 static int
 _cpufreq_status_check_current(Status *s)
 {
-   char buf[4096];
-   int i;
-   FILE *f;
    int ret = 0;
    int frequency = 0;
-   int frequency_min = 0x7fffffff;
-   int frequency_max = 0;
-   int freqtot = 0;
-#ifdef __FreeBSD__
-   int len = 4;
 
+#if defined (__OpenBSD__)
+   size_t len = sizeof(frequency);
+   int percent, mib[] = {CTL_HW, HW_CPUSPEED};
    s->active = 0;
+
+   _cpufreq_status_check_available(s);
+
+   if (sysctl(mib, 2, &frequency, &len, NULL, 0) == 0)
+     {
+        frequency *= 1000;
+        if (frequency != s->cur_frequency) ret = 1;
+        s->cur_frequency = frequency;
+        s->active = 1;
+     }
+
+   mib[1] = HW_SETPERF;
+
+   if (sysctl(mib, 2, &percent, &len, NULL, 0) == 0)
+     {
+        s->cur_percent = percent;
+     }
+
+   s->can_set_frequency = 1;
+   s->cur_governor = NULL;
+#elif defined (__FreeBSD__)
+   size_t len = sizeof(frequency);
+   s->active = 0;
+
    /* frequency is stored in dev.cpu.0.freq */
    if (sysctlbyname("dev.cpu.0.freq", &frequency, &len, NULL, 0) == 0)
      {
@@ -690,6 +753,13 @@
    s->can_set_frequency = 1;
    s->cur_governor = NULL;
 #else
+   char buf[4096];
+   FILE *f;
+   int frequency_min = 0x7fffffff;
+   int frequency_max = 0;
+   int freqtot = 0;
+   int i;
+
    s->active = 0;
 
    _cpufreq_status_check_available(s);
@@ -724,7 +794,7 @@
 
 //  printf("%i | %i %i\n", frequency, frequency_min, frequency_max);
 
-   // FIXME: this sssumes all cores are on the same governor
+   // FIXME: this assumes all cores are on the same governor
    f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "r");
    if (f)
      {
--- e_mod_main.h        Mon Oct  1 15:01:29 2012
+++ e_mod_main.h        Mon Oct  1 14:33:10 2012
@@ -11,6 +11,9 @@
    Eina_List     *frequencies;
    Eina_List     *governors;
    int            cur_frequency;
+#ifdef __OpenBSD__
+   int            cur_percent;
+#endif
    int            cur_min_frequency;
    int            cur_max_frequency;
    int            can_set_frequency;
--- freqset.c   Mon Oct  1 07:59:21 2012
+++ freqset.c   Mon Oct  1 07:46:15 2012
@@ -5,10 +5,15 @@
 #include <string.h>
 
 #ifdef __FreeBSD__
-#include <sys/types.h>
-#include <sys/sysctl.h>
+# include <sys/sysctl.h>
 #endif
 
+#ifdef __OpenBSD__
+# include <sys/param.h>
+# include <sys/resource.h>
+# include <sys/sysctl.h>
+#endif
+
 static int sys_cpu_setall(const char *control, const char *value);
 static int sys_cpufreq_set(const char *control, const char *value);
 
@@ -25,9 +30,29 @@
    if (seteuid(0))
      {
         fprintf(stderr, "Unable to assume root privileges\n");
+        return 1;
      }
 
-#ifdef __FreeBSD__
+#if defined __OpenBSD__
+   if (!strcmp(argv[1], "frequency"))
+     {
+        int mib[] = {CTL_HW, HW_SETPERF};
+        int new_perf = atoi(argv[2]);
+        size_t len = sizeof(new_perf);
+
+        if (sysctl(mib, 2, NULL, 0, &new_perf, len) == -1)
+          {
+             return 1;
+          }
+
+        return 0;
+     }
+   else
+     {
+        fprintf(stderr, "Unknown command (%s %s).\n", argv[1], argv[2]);
+        return 1;
+     }
+#elif defined __FreeBSD__
    if (!strcmp(argv[1], "frequency"))
      {
         int new_frequency = atoi(argv[2]);
------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to