Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2012 11:50:52 GMT
From:      Andrey Zonov <zont@FreeBSD.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/174366: [new port] sysutils/i7z: A better i7 (and now i3, i5) reporting tool for Linux
Message-ID:  <201212111150.qBBBoq6A028896@red.freebsd.org>
Resent-Message-ID: <201212111200.qBBC00Ya063453@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         174366
>Category:       ports
>Synopsis:       [new port] sysutils/i7z: A better i7 (and now i3, i5) reporting tool for Linux
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 11 12:00:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Andrey Zonov
>Release:        
>Organization:
>Environment:
>Description:

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	sysutils/i7z
#	sysutils/i7z/Makefile
#	sysutils/i7z/pkg-descr
#	sysutils/i7z/files
#	sysutils/i7z/files/0002-Properly-legend-printing.patch
#	sysutils/i7z/files/0001-Add-FreeBSD-support.patch
#	sysutils/i7z/distinfo
#
echo c - sysutils/i7z
mkdir -p sysutils/i7z > /dev/null 2>&1
echo x - sysutils/i7z/Makefile
sed 's/^X//' >sysutils/i7z/Makefile << '49e43cd3b3bd49f078f76875bc763ad6'
X# $FreeBSD$
X
XPORTNAME=	i7z
XPORTVERSION=	0.27.2
XCATEGORIES=	sysutils
XMASTER_SITES=	http://${PORTNAME}.googlecode.com/files/
X
XMAINTAINER=	zont@FreeBSD.org
XCOMMENT=	A better i7 (and now i3, i5) reporting tool for Linux
X
XUSE_GMAKE=	yes
X
XPATCH_STRIP=	-p1
XEXTRA_PATCHES+=	${FILESDIR}/0001-Add-FreeBSD-support.patch
XEXTRA_PATCHES+=	${FILESDIR}/0002-Properly-legend-printing.patch
X
XPLIST_FILES=	sbin/${PORTNAME}
XMAN1=		${PORTNAME}.1
X
Xdo-install:
X	${INSTALL_PROGRAM} ${WRKSRC}/${PORTNAME} ${PREFIX}/sbin/
X	${INSTALL_MAN} ${WRKSRC}/doc/i7z.man ${MANPREFIX}/man/man1/${MAN1}
X
X.include <bsd.port.mk>
49e43cd3b3bd49f078f76875bc763ad6
echo x - sysutils/i7z/pkg-descr
sed 's/^X//' >sysutils/i7z/pkg-descr << '61939b48aef59d3cfb970d192ff475ae'
Xi7z prints out the C-states and temperature for i3, i5 and i7 based
XCore processors from Intel (including Nehalems, Sandy Bridge and
XIvy Bridge).
X
XWWW: http://code.google.com/p/i7z/
61939b48aef59d3cfb970d192ff475ae
echo c - sysutils/i7z/files
mkdir -p sysutils/i7z/files > /dev/null 2>&1
echo x - sysutils/i7z/files/0002-Properly-legend-printing.patch
sed 's/^X//' >sysutils/i7z/files/0002-Properly-legend-printing.patch << '7eb54190a4ae9b8619c4956752badfa3'
XFrom 58f1fb0f46952ba2dfe377de27e15a94e5228940 Mon Sep 17 00:00:00 2001
XFrom: Andrey Zonov <zont@FreeBSD.org>
XDate: Tue, 30 Oct 2012 16:12:18 +0400
XSubject: [PATCH 2/2] Properly legend printing
X
X---
X i7z_Dual_Socket.c | 18 +++++++++---------
X 1 file changed, 9 insertions(+), 9 deletions(-)
X
Xdiff --git a/i7z_Dual_Socket.c b/i7z_Dual_Socket.c
Xindex 04e40ea..1f8db8e 100644
X--- a/i7z_Dual_Socket.c
X+++ b/i7z_Dual_Socket.c
X@@ -242,14 +242,14 @@ void print_i7z_socket(struct cpu_socket_info socket_0, int printw_offset, int PL
X 
X         if (socket_0.socket_num == 0)
X         {
X-            mvprintw (31, 0, "C0 = Processor running without halting");
X-            mvprintw (32, 0, "C1 = Processor running with halts (States >C0 are power saver)");
X-            mvprintw (33, 0, "C3 = Cores running with PLL turned off and core cache turned off");
X-            mvprintw (34, 0, "C6 = Everything in C3 + core state saved to last level cache");
X-            mvprintw (35, 0, "  Above values in table are in percentage over the last 1 sec");
X-            mvprintw (36, 0, "[core-id] refers to core-id number in /proc/cpuinfo");
X-            mvprintw (37, 0, "'Garbage Values' message printed when garbage values are read");
X-            mvprintw (38, 0, "  Ctrl+C to exit");
X+            mvprintw (3 + (socket_0.max_cpu+8)*2, 0, "C0 = Processor running without halting");
X+            mvprintw (4 + (socket_0.max_cpu+8)*2, 0, "C1 = Processor running with halts (States >C0 are power saver)");
X+            mvprintw (5 + (socket_0.max_cpu+8)*2, 0, "C3 = Cores running with PLL turned off and core cache turned off");
X+            mvprintw (6 + (socket_0.max_cpu+8)*2, 0, "C6 = Everything in C3 + core state saved to last level cache");
X+            mvprintw (7 + (socket_0.max_cpu+8)*2, 0, "  Above values in table are in percentage over the last 1 sec");
X+            mvprintw (8 + (socket_0.max_cpu+8)*2, 0, "[core-id] refers to core-id number in /proc/cpuinfo");
X+            mvprintw (9 + (socket_0.max_cpu+8)*2, 0, "'Garbage Values' message printed when garbage values are read");
X+            mvprintw (10 + (socket_0.max_cpu+8)*2, 0, "  Ctrl+C to exit");
X         }
X 
X         numCPUs = core_list_size_phy;
X@@ -763,7 +763,7 @@ void print_i7z ()
X           		C3_time[socket_num], C6_time[socket_num], tvstart[socket_num], tvstop[socket_num], &max_observed_cpu_socket2);
X         }else{*/
X         socket_num=1;
X-        printw_offset=14;
X+        printw_offset=socket_0.max_cpu+8;
X         print_i7z_socket(socket_1, printw_offset, PLATFORM_INFO_MSR,  PLATFORM_INFO_MSR_high, PLATFORM_INFO_MSR_low,
X                          online_cpus, cpu_freq_cpuinfo, one_second_sleep, TURBO_MODE, HT_ON_str, &kk_2,
X                          old_val_CORE[socket_num], old_val_REF[socket_num], old_val_C3[socket_num], old_val_C6[socket_num], old_val_C7[socket_num],
X-- 
X1.7.11.5
X
7eb54190a4ae9b8619c4956752badfa3
echo x - sysutils/i7z/files/0001-Add-FreeBSD-support.patch
sed 's/^X//' >sysutils/i7z/files/0001-Add-FreeBSD-support.patch << '0ba15b6b48880dc18ca12f7b949e6097'
XFrom 546bfa37f0c9aa1ef59fc8950e29c2a3ab1398c6 Mon Sep 17 00:00:00 2001
XFrom: Andrey Zonov <zont@FreeBSD.org>
XDate: Tue, 30 Oct 2012 01:24:37 +0400
XSubject: [PATCH 1/2] Add FreeBSD support
X
X---
X Makefile           |   2 +-
X cpuinfo.c          |  44 ++++++++++++++++++++++
X helper_functions.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++---
X i7z.c              |   4 ++
X 4 files changed, 152 insertions(+), 6 deletions(-)
X
Xdiff --git a/Makefile b/Makefile
Xindex 763dbb1..a9809e8 100644
X--- a/Makefile
X+++ b/Makefile
X@@ -6,7 +6,7 @@
X 
X #explicitly disable two scheduling flags as they cause segfaults, two more seem to crash the GUI version so putting them
X #here 
X-CFLAGS_FOR_AVOIDING_SEG_FAULT = -fno-schedule-insns2  -fno-schedule-insns -fno-inline-small-functions -fno-caller-saves
X+CFLAGS_FOR_AVOIDING_SEG_FAULT = -fno-schedule-insns2  -fno-schedule-insns -fno-caller-saves
X CFLAGS ?= -O3
X CFLAGS += $(CFLAGS_FOR_AVOIDING_SEG_FAULT) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN -Wimplicit-function-declaration
X 
Xdiff --git a/cpuinfo.c b/cpuinfo.c
Xindex 5b5cea0..ea0abf9 100644
X--- a/cpuinfo.c
X+++ b/cpuinfo.c
X@@ -147,6 +147,7 @@ void print_socket_information(struct cpu_socket_info* socket)
X     printf("Socket-%d [num of cpus %d physical %d logical %d] %s\n",socket->socket_num,socket->max_cpu,socket->num_physical_cores,socket->num_logical_cores,socket_list);
X }
X 
X+#ifdef __linux__
X void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
X {
X     int i;
X@@ -193,7 +194,50 @@ void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
X     chi->max_online_cpu = it_processor_num+1;
X 
X }
X+#elif __FreeBSD__
X+void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
X+{
X+    int i;
X+    FILE *fp = fopen("/var/run/dmesg.boot", "r");
X+    char strinfo[200];
X+    char *tmp;
X 
X+    int processor_num, physicalid_num = 0, coreid_num = 0;
X+    int ncpu = 0, packages, cores, threads;
X+
X+    if (fp!=NULL) {
X+        while ( fgets(strinfo,200,fp) != NULL) {
X+            if (strstr(strinfo, "FreeBSD/SMP: ") != NULL) {
X+                if ((tmp = strstr(strinfo, "Multiprocessor System Detected: ")) != NULL) {
X+                    tmp = strchr(tmp, ':');
X+                    tmp++; /* skip space */
X+                    ncpu = atoi(tmp);
X+                } else {
X+                    tmp = strchr(strinfo, ' ');
X+                    tmp++; /* skip space */
X+                    packages = atoi(tmp);
X+                    tmp = strchr(tmp, 'x');
X+                    tmp++; /* skip space */
X+                    cores = atoi(tmp);
X+                    threads = ncpu / (packages * cores);
X+                }
X+            }
X+        }
X+        for (i = 0; i < ncpu; i++) {
X+            processor_num = i;
X+            if ((coreid_num + 1) == cores)
X+                physicalid_num++;
X+            physicalid_num %= packages;
X+            coreid_num = processor_num % cores;
X+
X+            chi->processor_num[i] = processor_num;
X+            chi->package_num[i] = physicalid_num;
X+            chi->coreid_num[i] = coreid_num;
X+        }
X+    }
X+    chi->max_online_cpu = ncpu;
X+}
X+#endif
X void print_CPU_Heirarchy(struct cpu_heirarchy_info chi)
X {
X     int i;
Xdiff --git a/helper_functions.c b/helper_functions.c
Xindex 2f8da87..2f7e61c 100644
X--- a/helper_functions.c
X+++ b/helper_functions.c
X@@ -30,6 +30,11 @@
X #include <inttypes.h>
X #include <sys/types.h>
X #include <sys/time.h>
X+#ifdef __FreeBSD__
X+#include <sys/cpuctl.h>
X+#include <sys/ioctl.h>
X+#include <sys/sysctl.h>
X+#endif
X #include <time.h>
X #include <assert.h>
X #include <math.h>
X@@ -45,6 +50,14 @@ bool E7_mp_present=false;
X #define IA32_TEMPERATURE_TARGET 0x1a2
X #define IA32_PACKAGE_THERM_STATUS 0x1b1
X 
X+#ifdef __linux__
X+#define	_DEV_CPU_MSR	"/dev/cpu/%d/msr"
X+#define	_DEV_CPU0_MSR	"/dev/cpu/0/msr"
X+#elif __FreeBSD__
X+#define	_DEV_CPU_MSR	"/dev/cpuctl%d"
X+#define	_DEV_CPU0_MSR	"/dev/cpuctl0"
X+#endif
X+
X int Get_Bits_Value(unsigned long val,int highbit, int lowbit){ 
X 	unsigned long data = val;
X 	int bits = highbit - lowbit + 1;
X@@ -234,7 +247,7 @@ uint64_t get_msr_value (int cpu, uint32_t reg, unsigned int highbit,
X     int bits;
X     *error_indx =0;
X 
X-    sprintf (msr_file_name, "/dev/cpu/%d/msr", cpu);
X+    sprintf (msr_file_name, _DEV_CPU_MSR, cpu);
X     fd = open (msr_file_name, O_RDONLY);
X     if (fd < 0)
X     {
X@@ -255,11 +268,21 @@ uint64_t get_msr_value (int cpu, uint32_t reg, unsigned int highbit,
X         }
X     }
X 
X+#ifdef __linux__
X     if (pread (fd, &data, sizeof data, reg) != sizeof data)
X     {
X         perror ("rdmsr:pread");
X         exit (127);
X     }
X+#elif __FreeBSD__
X+    cpuctl_msr_args_t args;
X+    args.msr = reg;
X+    if (ioctl (fd, CPUCTL_RDMSR, &args) < 0) {
X+        perror ("rdmsr:ioctl");
X+        exit (127);
X+    }
X+    data = args.data;
X+#endif
X 
X     close (fd);
X 
X@@ -287,7 +310,7 @@ uint64_t set_msr_value (int cpu, uint32_t reg, uint64_t data)
X     int fd;
X     char msr_file_name[64];
X 
X-    sprintf (msr_file_name, "/dev/cpu/%d/msr", cpu);
X+    sprintf (msr_file_name, _DEV_CPU_MSR, cpu);
X     fd = open (msr_file_name, O_WRONLY);
X     if (fd < 0)
X     {
X@@ -304,11 +327,21 @@ uint64_t set_msr_value (int cpu, uint32_t reg, uint64_t data)
X         }
X     }
X 
X+#if __linux__
X     if (pwrite (fd, &data, sizeof data, reg) != sizeof data)
X     {
X         perror ("wrmsr:pwrite");
X         exit (127);
X     }
X+#elif __FreeBSD__
X+    cpuctl_msr_args_t args;
X+    args.msr = reg;
X+    args.data = data;
X+    if (ioctl (fd, CPUCTL_WRMSR, &args) < 0) {
X+        perror ("wrmsr:ioctl");
X+        exit (127);
X+    }
X+#endif
X     close(fd);
X     return(1);
X }
X@@ -487,10 +520,10 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge)
X void Test_Or_Make_MSR_DEVICE_FILES() 
X {
X     //test if the msr file exists
X-    if (access ("/dev/cpu/0/msr", F_OK) == 0)
X+    if (access (_DEV_CPU0_MSR, F_OK) == 0)
X     {
X-        printf ("i7z DEBUG: msr device files exist /dev/cpu/*/msr\n");
X-        if (access ("/dev/cpu/0/msr", W_OK) == 0)
X+        printf ("i7z DEBUG: msr device files exist %s\n", _DEV_CPU0_MSR);
X+        if (access (_DEV_CPU0_MSR, W_OK) == 0)
X         {
X             //a system mght have been set with msr allowable to be written
X             //by a normal user so...
X@@ -505,6 +538,7 @@ void Test_Or_Make_MSR_DEVICE_FILES()
X         printf ("i7z DEBUG: msr device files DONOT exist, trying out a makedev script\n");
X         if (geteuid () == 0)
X         {
X+#ifdef __linux__
X             //Try the Makedev script
X             //sourced from MAKEDEV-cpuid-msr script in msr-tools
X             system ("msr_major=202; \
X@@ -519,6 +553,9 @@ void Test_Or_Make_MSR_DEVICE_FILES()
X 							");
X             printf ("i7z DEBUG: modprobbing for msr\n");
X             system ("modprobe msr");
X+#elif __FreeBSD__
X+            system ("kldload cpuctl");
X+#endif
X         } else {
X             printf ("i7z DEBUG: You DONOT have root privileges, mknod to create device entries won't work out\n");
X             printf ("i7z DEBUG: A solution is to run this program as root\n");
X@@ -526,6 +563,7 @@ void Test_Or_Make_MSR_DEVICE_FILES()
X         }
X     }
X }
X+#ifdef __linux__
X double cpufreq_info()
X {
X     //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present
X@@ -543,6 +581,21 @@ double cpufreq_info()
X     fclose (tmp_file);
X     return atof(tmp_str);
X }
X+#elif __FreeBSD__
X+double cpufreq_info()
X+{
X+    struct clockinfo clock;
X+    size_t len;
X+
X+    len = sizeof(clock);
X+    if (sysctlbyname ("hw.clockrate", &clock, &len, NULL, 0) == -1)
X+    {
X+        perror ("cpufreq_info:sysctl");
X+        exit (127);
X+    }
X+    return (clock.hz);
X+}
X+#endif
X 
X int check_and_return_processor(char*strinfo)
X {
X@@ -669,6 +722,7 @@ void print_socket_information(struct cpu_socket_info* socket)
X     printf("Socket-%d [num of cpus %d physical %d logical %d] %s\n",socket->socket_num,socket->max_cpu,socket->num_physical_cores,socket->num_logical_cores,socket_list);
X }
X 
X+#ifdef __linux__
X void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
X {
X     FILE *fp = fopen("/proc/cpuinfo","r");
X@@ -715,7 +769,51 @@ void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
X     chi->max_online_cpu = it_processor_num+1;
X     fclose(fp);
X }
X+#elif __FreeBSD__
X+void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
X+{
X+    int i;
X+    FILE *fp = fopen("/var/run/dmesg.boot", "r");
X+    char strinfo[200];
X+    char *tmp;
X 
X+    int processor_num, physicalid_num = 0, coreid_num = 0;
X+    int ncpu = 0, packages, cores, threads;
X+
X+    if (fp!=NULL) {
X+        while ( fgets(strinfo,200,fp) != NULL) {
X+            if (strstr(strinfo, "FreeBSD/SMP: ") != NULL) {
X+                if ((tmp = strstr(strinfo, "Multiprocessor System Detected: ")) != NULL) {
X+                    tmp = strchr(tmp, ':');
X+                    tmp++; /* skip space */
X+                    ncpu = atoi(tmp);
X+                } else {
X+                    tmp = strchr(strinfo, ' ');
X+                    tmp++; /* skip space */
X+                    packages = atoi(tmp);
X+                    tmp = strchr(tmp, 'x');
X+                    tmp++; /* skip space */
X+                    cores = atoi(tmp);
X+                    threads = ncpu / (packages * cores);
X+                }
X+            }
X+        }
X+        for (i = 0; i < ncpu; i++) {
X+            processor_num = i;
X+            if ((coreid_num + 1) == cores)
X+                physicalid_num++;
X+            physicalid_num %= packages;
X+            coreid_num = processor_num % cores;
X+
X+            chi->processor_num[i] = processor_num;
X+            chi->package_num[i] = physicalid_num;
X+            chi->coreid_num[i] = coreid_num;
X+        }
X+    }
X+    chi->max_online_cpu = ncpu;
X+    fclose(fp);
X+}
X+#endif
X void print_CPU_Heirarchy(struct cpu_heirarchy_info chi)
X {
X     int i;
Xdiff --git a/i7z.c b/i7z.c
Xindex d692ba3..03c750a 100644
X--- a/i7z.c
X+++ b/i7z.c
X@@ -386,7 +386,11 @@ void atexit_runsttysane()
X 
X void modprobing_msr()
X {
X+#ifdef __linux__
X     system("modprobe msr");
X+#elif __FreeBSD__
X+    system("kldload cpuctl");
X+#endif
X }
X 
X //Info: I start from index 1 when i talk about cores on CPU
X-- 
X1.7.11.5
X
0ba15b6b48880dc18ca12f7b949e6097
echo x - sysutils/i7z/distinfo
sed 's/^X//' >sysutils/i7z/distinfo << 'fe1a4d6263b156deec5ec676241eef08'
XSHA256 (i7z-0.27.2.tar.gz) = a7f72d65732c17eef0df4f284927fe744fc650075f2364c51c9497534d8f47f1
XSIZE (i7z-0.27.2.tar.gz) = 51226
fe1a4d6263b156deec5ec676241eef08
exit



>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212111150.qBBBoq6A028896>