Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2012 13:45:36 +0000 (UTC)
From:      Emanuel Haupt <ehaupt@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r308691 - in head/sysutils: . i7z i7z/files
Message-ID:  <201212111345.qBBDjaBY005752@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ehaupt
Date: Tue Dec 11 13:45:36 2012
New Revision: 308691
URL: http://svnweb.freebsd.org/changeset/ports/308691

Log:
  Add i7z, a thermal and C-state reporting utility for Intel-Core-i CPUs.
  
  PR:		174366
  Submitted by:	zont

Added:
  head/sysutils/i7z/
  head/sysutils/i7z/Makefile   (contents, props changed)
  head/sysutils/i7z/distinfo   (contents, props changed)
  head/sysutils/i7z/files/
  head/sysutils/i7z/files/patch-Makefile   (contents, props changed)
  head/sysutils/i7z/files/patch-cpuinfo.c   (contents, props changed)
  head/sysutils/i7z/files/patch-doc__i7z.man   (contents, props changed)
  head/sysutils/i7z/files/patch-helper_functions.c   (contents, props changed)
  head/sysutils/i7z/files/patch-i7z.c   (contents, props changed)
  head/sysutils/i7z/files/patch-i7z_Dual_Socket.c   (contents, props changed)
  head/sysutils/i7z/pkg-descr   (contents, props changed)
Modified:
  head/sysutils/Makefile

Modified: head/sysutils/Makefile
==============================================================================
--- head/sysutils/Makefile	Tue Dec 11 13:40:31 2012	(r308690)
+++ head/sysutils/Makefile	Tue Dec 11 13:45:36 2012	(r308691)
@@ -382,6 +382,7 @@
     SUBDIR += hwstat
     SUBDIR += hyperic-sigar
     SUBDIR += i2c-tools
+    SUBDIR += i7z
     SUBDIR += iat
     SUBDIR += iextract
     SUBDIR += installwatch

Added: head/sysutils/i7z/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/Makefile	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,30 @@
+# $FreeBSD$
+
+PORTNAME=	i7z
+PORTVERSION=	0.27.2
+CATEGORIES=	sysutils
+MASTER_SITES=	GOOGLE_CODE
+
+MAINTAINER=	zont@FreeBSD.org
+COMMENT=	Thermal and C-state reporting utility for Intel-Core-i CPUs
+
+LICENSE=	GPLv2
+
+USE_GMAKE=	yes
+MAKE_JOBS_SAFE=	yes
+
+MAN1=		i7z.1
+PLIST_FILES=	bin/i7z
+
+ONLY_FOR_ARCHS=	i386 amd64
+
+# Disable scheduling flags as they cause segfaults since they are enabled at
+# default FreeBSD optimization levels (-O2, -O3, -Os)
+CFLAGS+=	-fno-schedule-insns2 -fno-schedule-insns -fno-caller-saves
+
+do-install:
+	${INSTALL_PROGRAM} ${WRKSRC}/${PORTNAME} ${PREFIX}/bin
+	${INSTALL_MAN} ${WRKSRC}/doc/${PORTNAME}.man \
+		${MANPREFIX}/man/man1/${MAN1}
+
+.include <bsd.port.mk>

Added: head/sysutils/i7z/distinfo
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/distinfo	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,2 @@
+SHA256 (i7z-0.27.2.tar.gz) = a7f72d65732c17eef0df4f284927fe744fc650075f2364c51c9497534d8f47f1
+SIZE (i7z-0.27.2.tar.gz) = 51226

Added: head/sysutils/i7z/files/patch-Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/files/patch-Makefile	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,24 @@
+--- ./Makefile.orig	2012-09-11 08:15:54.000000000 +0200
++++ ./Makefile	2012-12-11 14:41:28.000000000 +0100
+@@ -4,11 +4,7 @@
+ 
+ #makefile updated from patch by anestling
+ 
+-#explicitly disable two scheduling flags as they cause segfaults, two more seem to crash the GUI version so putting them
+-#here 
+-CFLAGS_FOR_AVOIDING_SEG_FAULT = -fno-schedule-insns2  -fno-schedule-insns -fno-inline-small-functions -fno-caller-saves
+-CFLAGS ?= -O3
+-CFLAGS += $(CFLAGS_FOR_AVOIDING_SEG_FAULT) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN -Wimplicit-function-declaration
++CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN
+ 
+ LBITS := $(shell getconf LONG_BIT)
+ ifeq ($(LBITS),64)
+@@ -48,7 +44,7 @@
+ # 	$(CC) $(CFLAGS) $(LDFLAGS) -o $(PERFMON-BIN) perfmon-i7z.c helper_functions.c $(LIBS)
+ 
+ test_exist: bin
+-	@test -f i7z && echo 'Succeeded, now run sudo ./i7z' || echo 'Compilation failed'
++	@true
+ 
+ clean:
+ 	rm -f *.o $(BIN)

Added: head/sysutils/i7z/files/patch-cpuinfo.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/files/patch-cpuinfo.c	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,61 @@
+--- ./cpuinfo.c.orig	2012-09-11 08:15:54.000000000 +0200
++++ ./cpuinfo.c	2012-12-11 14:41:28.000000000 +0100
+@@ -147,6 +147,7 @@
+     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);
+ }
+ 
++#ifdef __linux__
+ void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
+ {
+     int i;
+@@ -193,7 +194,50 @@
+     chi->max_online_cpu = it_processor_num+1;
+ 
+ }
++#elif __FreeBSD__
++void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
++{
++    int i;
++    FILE *fp = fopen("/var/run/dmesg.boot", "r");
++    char strinfo[200];
++    char *tmp;
++
++    int processor_num, physicalid_num = 0, coreid_num = 0;
++    int ncpu = 0, packages, cores, threads;
++
++    if (fp!=NULL) {
++        while ( fgets(strinfo,200,fp) != NULL) {
++            if (strstr(strinfo, "FreeBSD/SMP: ") != NULL) {
++                if ((tmp = strstr(strinfo, "Multiprocessor System Detected: ")) != NULL) {
++                    tmp = strchr(tmp, ':');
++                    tmp++; /* skip space */
++                    ncpu = atoi(tmp);
++                } else {
++                    tmp = strchr(strinfo, ' ');
++                    tmp++; /* skip space */
++                    packages = atoi(tmp);
++                    tmp = strchr(tmp, 'x');
++                    tmp++; /* skip space */
++                    cores = atoi(tmp);
++                    threads = ncpu / (packages * cores);
++                }
++            }
++        }
++        for (i = 0; i < ncpu; i++) {
++            processor_num = i;
++            if ((coreid_num + 1) == cores)
++                physicalid_num++;
++            physicalid_num %= packages;
++            coreid_num = processor_num % cores;
+ 
++            chi->processor_num[i] = processor_num;
++            chi->package_num[i] = physicalid_num;
++            chi->coreid_num[i] = coreid_num;
++        }
++    }
++    chi->max_online_cpu = ncpu;
++}
++#endif
+ void print_CPU_Heirarchy(struct cpu_heirarchy_info chi)
+ {
+     int i;

Added: head/sysutils/i7z/files/patch-doc__i7z.man
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/files/patch-doc__i7z.man	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,10 @@
+--- ./doc/i7z.man.orig	2012-12-11 14:41:38.000000000 +0100
++++ ./doc/i7z.man	2012-12-11 14:41:55.000000000 +0100
+@@ -1,6 +1,6 @@
+ .TH i7z 1 "20 July 2012"
+ .SH NAME
+-i7z \- A better i7 (and now i3, i5) reporting tool for Linux.
++i7z \- A better i7 (and now i3, i5) reporting tool.
+ .SH SYNOPSIS
+ \fBi7z [OPTION]\fP, [OPTION] is optional. i7z needs to be run in super user (root) mode.
+ .SH DESCRIPTION

Added: head/sysutils/i7z/files/patch-helper_functions.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/files/patch-helper_functions.c	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,213 @@
+--- ./helper_functions.c.orig	2012-09-11 08:15:54.000000000 +0200
++++ ./helper_functions.c	2012-12-11 14:41:28.000000000 +0100
+@@ -30,6 +30,11 @@
+ #include <inttypes.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
++#ifdef __FreeBSD__
++#include <sys/cpuctl.h>
++#include <sys/ioctl.h>
++#include <sys/sysctl.h>
++#endif
+ #include <time.h>
+ #include <assert.h>
+ #include <math.h>
+@@ -45,6 +50,14 @@
+ #define IA32_TEMPERATURE_TARGET 0x1a2
+ #define IA32_PACKAGE_THERM_STATUS 0x1b1
+ 
++#ifdef __linux__
++#define	_DEV_CPU_MSR	"/dev/cpu/%d/msr"
++#define	_DEV_CPU0_MSR	"/dev/cpu/0/msr"
++#elif __FreeBSD__
++#define	_DEV_CPU_MSR	"/dev/cpuctl%d"
++#define	_DEV_CPU0_MSR	"/dev/cpuctl0"
++#endif
++
+ int Get_Bits_Value(unsigned long val,int highbit, int lowbit){ 
+ 	unsigned long data = val;
+ 	int bits = highbit - lowbit + 1;
+@@ -234,7 +247,7 @@
+     int bits;
+     *error_indx =0;
+ 
+-    sprintf (msr_file_name, "/dev/cpu/%d/msr", cpu);
++    sprintf (msr_file_name, _DEV_CPU_MSR, cpu);
+     fd = open (msr_file_name, O_RDONLY);
+     if (fd < 0)
+     {
+@@ -255,11 +268,21 @@
+         }
+     }
+ 
++#ifdef __linux__
+     if (pread (fd, &data, sizeof data, reg) != sizeof data)
+     {
+         perror ("rdmsr:pread");
+         exit (127);
+     }
++#elif __FreeBSD__
++    cpuctl_msr_args_t args;
++    args.msr = reg;
++    if (ioctl (fd, CPUCTL_RDMSR, &args) < 0) {
++        perror ("rdmsr:ioctl");
++        exit (127);
++    }
++    data = args.data;
++#endif
+ 
+     close (fd);
+ 
+@@ -287,7 +310,7 @@
+     int fd;
+     char msr_file_name[64];
+ 
+-    sprintf (msr_file_name, "/dev/cpu/%d/msr", cpu);
++    sprintf (msr_file_name, _DEV_CPU_MSR, cpu);
+     fd = open (msr_file_name, O_WRONLY);
+     if (fd < 0)
+     {
+@@ -304,11 +327,21 @@
+         }
+     }
+ 
++#if __linux__
+     if (pwrite (fd, &data, sizeof data, reg) != sizeof data)
+     {
+         perror ("wrmsr:pwrite");
+         exit (127);
+     }
++#elif __FreeBSD__
++    cpuctl_msr_args_t args;
++    args.msr = reg;
++    args.data = data;
++    if (ioctl (fd, CPUCTL_WRMSR, &args) < 0) {
++        perror ("wrmsr:ioctl");
++        exit (127);
++    }
++#endif
+     close(fd);
+     return(1);
+ }
+@@ -487,10 +520,10 @@
+ void Test_Or_Make_MSR_DEVICE_FILES() 
+ {
+     //test if the msr file exists
+-    if (access ("/dev/cpu/0/msr", F_OK) == 0)
++    if (access (_DEV_CPU0_MSR, F_OK) == 0)
+     {
+-        printf ("i7z DEBUG: msr device files exist /dev/cpu/*/msr\n");
+-        if (access ("/dev/cpu/0/msr", W_OK) == 0)
++        printf ("i7z DEBUG: msr device files exist %s\n", _DEV_CPU0_MSR);
++        if (access (_DEV_CPU0_MSR, W_OK) == 0)
+         {
+             //a system mght have been set with msr allowable to be written
+             //by a normal user so...
+@@ -505,6 +538,7 @@
+         printf ("i7z DEBUG: msr device files DONOT exist, trying out a makedev script\n");
+         if (geteuid () == 0)
+         {
++#ifdef __linux__
+             //Try the Makedev script
+             //sourced from MAKEDEV-cpuid-msr script in msr-tools
+             system ("msr_major=202; \
+@@ -519,6 +553,9 @@
+ 							");
+             printf ("i7z DEBUG: modprobbing for msr\n");
+             system ("modprobe msr");
++#elif __FreeBSD__
++            system ("kldload cpuctl");
++#endif
+         } else {
+             printf ("i7z DEBUG: You DONOT have root privileges, mknod to create device entries won't work out\n");
+             printf ("i7z DEBUG: A solution is to run this program as root\n");
+@@ -526,6 +563,7 @@
+         }
+     }
+ }
++#ifdef __linux__
+ double cpufreq_info()
+ {
+     //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present
+@@ -543,6 +581,21 @@
+     fclose (tmp_file);
+     return atof(tmp_str);
+ }
++#elif __FreeBSD__
++double cpufreq_info()
++{
++    struct clockinfo clock;
++    size_t len;
++
++    len = sizeof(clock);
++    if (sysctlbyname ("hw.clockrate", &clock, &len, NULL, 0) == -1)
++    {
++        perror ("cpufreq_info:sysctl");
++        exit (127);
++    }
++    return (clock.hz);
++}
++#endif
+ 
+ int check_and_return_processor(char*strinfo)
+ {
+@@ -669,6 +722,7 @@
+     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);
+ }
+ 
++#ifdef __linux__
+ void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
+ {
+     FILE *fp = fopen("/proc/cpuinfo","r");
+@@ -715,7 +769,51 @@
+     chi->max_online_cpu = it_processor_num+1;
+     fclose(fp);
+ }
++#elif __FreeBSD__
++void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi)
++{
++    int i;
++    FILE *fp = fopen("/var/run/dmesg.boot", "r");
++    char strinfo[200];
++    char *tmp;
++
++    int processor_num, physicalid_num = 0, coreid_num = 0;
++    int ncpu = 0, packages, cores, threads;
++
++    if (fp!=NULL) {
++        while ( fgets(strinfo,200,fp) != NULL) {
++            if (strstr(strinfo, "FreeBSD/SMP: ") != NULL) {
++                if ((tmp = strstr(strinfo, "Multiprocessor System Detected: ")) != NULL) {
++                    tmp = strchr(tmp, ':');
++                    tmp++; /* skip space */
++                    ncpu = atoi(tmp);
++                } else {
++                    tmp = strchr(strinfo, ' ');
++                    tmp++; /* skip space */
++                    packages = atoi(tmp);
++                    tmp = strchr(tmp, 'x');
++                    tmp++; /* skip space */
++                    cores = atoi(tmp);
++                    threads = ncpu / (packages * cores);
++                }
++            }
++        }
++        for (i = 0; i < ncpu; i++) {
++            processor_num = i;
++            if ((coreid_num + 1) == cores)
++                physicalid_num++;
++            physicalid_num %= packages;
++            coreid_num = processor_num % cores;
+ 
++            chi->processor_num[i] = processor_num;
++            chi->package_num[i] = physicalid_num;
++            chi->coreid_num[i] = coreid_num;
++        }
++    }
++    chi->max_online_cpu = ncpu;
++    fclose(fp);
++}
++#endif
+ void print_CPU_Heirarchy(struct cpu_heirarchy_info chi)
+ {
+     int i;

Added: head/sysutils/i7z/files/patch-i7z.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/files/patch-i7z.c	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,14 @@
+--- ./i7z.c.orig	2012-09-11 08:15:54.000000000 +0200
++++ ./i7z.c	2012-12-11 14:41:28.000000000 +0100
+@@ -386,7 +386,11 @@
+ 
+ void modprobing_msr()
+ {
++#ifdef __linux__
+     system("modprobe msr");
++#elif __FreeBSD__
++    system("kldload cpuctl");
++#endif
+ }
+ 
+ //Info: I start from index 1 when i talk about cores on CPU

Added: head/sysutils/i7z/files/patch-i7z_Dual_Socket.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/files/patch-i7z_Dual_Socket.c	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,34 @@
+--- ./i7z_Dual_Socket.c.orig	2012-09-11 08:15:54.000000000 +0200
++++ ./i7z_Dual_Socket.c	2012-12-11 14:41:28.000000000 +0100
+@@ -242,14 +242,14 @@
+ 
+         if (socket_0.socket_num == 0)
+         {
+-            mvprintw (31, 0, "C0 = Processor running without halting");
+-            mvprintw (32, 0, "C1 = Processor running with halts (States >C0 are power saver)");
+-            mvprintw (33, 0, "C3 = Cores running with PLL turned off and core cache turned off");
+-            mvprintw (34, 0, "C6 = Everything in C3 + core state saved to last level cache");
+-            mvprintw (35, 0, "  Above values in table are in percentage over the last 1 sec");
+-            mvprintw (36, 0, "[core-id] refers to core-id number in /proc/cpuinfo");
+-            mvprintw (37, 0, "'Garbage Values' message printed when garbage values are read");
+-            mvprintw (38, 0, "  Ctrl+C to exit");
++            mvprintw (3 + (socket_0.max_cpu+8)*2, 0, "C0 = Processor running without halting");
++            mvprintw (4 + (socket_0.max_cpu+8)*2, 0, "C1 = Processor running with halts (States >C0 are power saver)");
++            mvprintw (5 + (socket_0.max_cpu+8)*2, 0, "C3 = Cores running with PLL turned off and core cache turned off");
++            mvprintw (6 + (socket_0.max_cpu+8)*2, 0, "C6 = Everything in C3 + core state saved to last level cache");
++            mvprintw (7 + (socket_0.max_cpu+8)*2, 0, "  Above values in table are in percentage over the last 1 sec");
++            mvprintw (8 + (socket_0.max_cpu+8)*2, 0, "[core-id] refers to core-id number in /proc/cpuinfo");
++            mvprintw (9 + (socket_0.max_cpu+8)*2, 0, "'Garbage Values' message printed when garbage values are read");
++            mvprintw (10 + (socket_0.max_cpu+8)*2, 0, "  Ctrl+C to exit");
+         }
+ 
+         numCPUs = core_list_size_phy;
+@@ -763,7 +763,7 @@
+           		C3_time[socket_num], C6_time[socket_num], tvstart[socket_num], tvstop[socket_num], &max_observed_cpu_socket2);
+         }else{*/
+         socket_num=1;
+-        printw_offset=14;
++        printw_offset=socket_0.max_cpu+8;
+         print_i7z_socket(socket_1, printw_offset, PLATFORM_INFO_MSR,  PLATFORM_INFO_MSR_high, PLATFORM_INFO_MSR_low,
+                          online_cpus, cpu_freq_cpuinfo, one_second_sleep, TURBO_MODE, HT_ON_str, &kk_2,
+                          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],

Added: head/sysutils/i7z/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/i7z/pkg-descr	Tue Dec 11 13:45:36 2012	(r308691)
@@ -0,0 +1,4 @@
+i7z prints out the C-states and temperature for i3, i5 and i7 based Core
+processors from Intel (including Nehalems, Sandy Bridge and Ivy Bridge).
+
+WWW: http://code.google.com/p/i7z/



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