1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 12:27:52 +00:00

- On FreeBSD, first try dev.cpu.0.freq sysctl (see cpufreq(4) for details)

to detect CPU frequency and only then do i386 magic
- Minor cleanup


git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@159 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Roman Bogorodskiy 2005-08-24 05:33:10 +00:00
parent 79e6886e1c
commit 9c56581089

View File

@ -1,4 +1,9 @@
#include "conky.h" /** freebsd.c
* Contains FreeBSD specific stuff
*
* $Id$
*/
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
@ -20,6 +25,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include "conky.h"
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
#define KELVTOC(x) ((x - 2732) / 10.0) #define KELVTOC(x) ((x - 2732) / 10.0)
@ -59,8 +66,7 @@ static unsigned int get_cpu_speed(void)
return ((tscstop - tscstart) / ((stop - start) / 1000.0)); return ((tscstop - tscstart) / ((stop - start) / 1000.0));
} }
#endif #endif /* i386 */
static int getsysctl(char *name, void *ptr, size_t len) static int getsysctl(char *name, void *ptr, size_t len)
{ {
@ -80,7 +86,6 @@ static kvm_t *kd = NULL;
struct ifmibdata *data = NULL; struct ifmibdata *data = NULL;
size_t len = 0; size_t len = 0;
static int swapmode(int *retavail, int *retfree) static int swapmode(int *retavail, int *retfree)
{ {
int n; int n;
@ -119,12 +124,10 @@ static int swapmode(int *retavail, int *retfree)
return n; return n;
} }
void prepare_update() void prepare_update()
{ {
} }
/*double get_uptime() */
void update_uptime() void update_uptime()
{ {
int mib[2] = { CTL_KERN, KERN_BOOTTIME }; int mib[2] = { CTL_KERN, KERN_BOOTTIME };
@ -142,7 +145,6 @@ void update_uptime()
} }
} }
void update_meminfo() void update_meminfo()
{ {
int total_pages, inactive_pages, free_pages; int total_pages, inactive_pages, free_pages;
@ -237,8 +239,6 @@ void update_net_stats()
void update_total_processes() void update_total_processes()
{ {
/* It's easier to use kvm here than sysctl */
int n_processes; int n_processes;
static int kd_init = 1; static int kd_init = 1;
@ -423,31 +423,38 @@ char *get_adt746x_fan()
char *get_freq() char *get_freq()
{ {
#if defined(i386) || defined(__i386__) /* First, try to obtain CPU frequency via dev.cpu.0.freq sysctl
int i; * (cpufreq(4)). If failed, do i386 magic. */
int freq;
char *cpuspeed; char *cpuspeed;
if ((cpuspeed = (char *) malloc(16)) == NULL) { if ((cpuspeed = malloc(8)) == NULL)
CRIT_ERR("get_freq()"); CRIT_ERR("get_freq()");
if (GETSYSCTL("dev.cpu.0.freq", freq) == 0) {
snprintf(cpuspeed, 8, "%d", freq);
return cpuspeed;
} }
#if defined(i386) || defined(__i386__)
else {
int i;
i = 0; i = 0;
if ((i = get_cpu_speed()) > 0) { if ((i = get_cpu_speed()) > 0) {
if (i < 1000000) { if (i < 1000000) {
i += 50; /* for rounding */ i += 50; /* for rounding */
snprintf(cpuspeed, 15, "%d.%d MHz", i / 1000, snprintf(cpuspeed, 8, "%d.%d", i / 1000,
(i / 100) % 10); (i / 100) % 10);
} else { } else
snprintf(cpuspeed, 15, "%d MHz", i / 1000); snprintf(cpuspeed, 8, "%d", i / 1000);
} } else
} else {
cpuspeed = ""; cpuspeed = "";
}
return cpuspeed; return cpuspeed;
}
#else #else
return ""; return "";
#endif #endif /* i386 */
} }
void update_top() void update_top()