Skip to content
This repository
Browse code

Merge pull request #3162 from amet/smc

[osx] cosmetic fixes in System info page
  • Loading branch information...
commit 2b2e2d175b135c39a2618579ad84a9742a36917b 2 parents a1c6b23 + 3fbb085
Martijn Kaijser authored August 31, 2013
10  XBMC.xcodeproj/project.pbxproj
@@ -28,6 +28,9 @@
28 28
 		0E3036EC1760F68A00D93596 /* FavouritesDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E3036EA1760F68A00D93596 /* FavouritesDirectory.cpp */; };
29 29
 		0E3036ED1760F68A00D93596 /* FavouritesDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E3036EA1760F68A00D93596 /* FavouritesDirectory.cpp */; };
30 30
 		0E3036EE1760F68A00D93596 /* FavouritesDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E3036EA1760F68A00D93596 /* FavouritesDirectory.cpp */; };
  31
+		180F6C8117CE9A5700127892 /* smc.c in Sources */ = {isa = PBXBuildFile; fileRef = 180F6C8017CE9A5700127892 /* smc.c */; };
  32
+		180F6C8217CE9A5700127892 /* smc.c in Sources */ = {isa = PBXBuildFile; fileRef = 180F6C8017CE9A5700127892 /* smc.c */; };
  33
+		180F6C8317CE9A5700127892 /* smc.c in Sources */ = {isa = PBXBuildFile; fileRef = 180F6C8017CE9A5700127892 /* smc.c */; };
31 34
 		183FDF8A11AF0B0500B81E9C /* PluginSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 183FDF8811AF0B0500B81E9C /* PluginSource.cpp */; };
32 35
 		18404DA61396C31B00863BBA /* SlingboxLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 18404DA51396C31B00863BBA /* SlingboxLib.a */; };
33 36
 		1840B74D13993D8A007C848B /* JSONVariantParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1840B74B13993D8A007C848B /* JSONVariantParser.cpp */; };
@@ -3174,6 +3177,8 @@
3174 3177
 		0E30286C1759FCC200D93596 /* SettingsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsManager.h; sourceTree = "<group>"; };
3175 3178
 		0E3036EA1760F68A00D93596 /* FavouritesDirectory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FavouritesDirectory.cpp; sourceTree = "<group>"; };
3176 3179
 		0E3036EB1760F68A00D93596 /* FavouritesDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FavouritesDirectory.h; sourceTree = "<group>"; };
  3180
+		180F6C7F17CE9A5700127892 /* smc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = smc.h; sourceTree = "<group>"; };
  3181
+		180F6C8017CE9A5700127892 /* smc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smc.c; sourceTree = "<group>"; };
3177 3182
 		18308CB41303370800AA309E /* stat_utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stat_utf8.h; sourceTree = "<group>"; };
3178 3183
 		18308CB51303370800AA309E /* stdio_utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stdio_utf8.h; sourceTree = "<group>"; };
3179 3184
 		183FDF8811AF0B0500B81E9C /* PluginSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginSource.cpp; sourceTree = "<group>"; };
@@ -7126,6 +7131,8 @@
7126 7131
 				6E2FACD20E26E92800DF79EA /* Info.plist */,
7127 7132
 				F51CEEEE0F5C5D20004F4602 /* OSXGNUReplacements.c */,
7128 7133
 				F51CEEF00F5C5D28004F4602 /* OSXGNUReplacements.h */,
  7134
+				180F6C7F17CE9A5700127892 /* smc.h */,
  7135
+				180F6C8017CE9A5700127892 /* smc.c */,
7129 7136
 				E306D12C0DDF7B590052C2AD /* XBMCHelper.cpp */,
7130 7137
 				E306D12D0DDF7B590052C2AD /* XBMCHelper.h */,
7131 7138
 				820023D9171A28A300667D1C /* OSXTextInputResponder.h */,
@@ -10594,6 +10601,7 @@
10594 10601
 				F59EED7E17AD5174005BB7C6 /* ApplicationPlayer.cpp in Sources */,
10595 10602
 				DF29668017B2B04300DF10F9 /* SettingRequirement.cpp in Sources */,
10596 10603
 				DF28DF4D17B8379E0077F41A /* ProfilesOperations.cpp in Sources */,
  10604
+				180F6C8117CE9A5700127892 /* smc.c in Sources */,
10597 10605
 			);
10598 10606
 			runOnlyForDeploymentPostprocessing = 0;
10599 10607
 		};
@@ -11621,6 +11629,7 @@
11621 11629
 				F59EED8017AD5174005BB7C6 /* ApplicationPlayer.cpp in Sources */,
11622 11630
 				DF29668217B2B04300DF10F9 /* SettingRequirement.cpp in Sources */,
11623 11631
 				DF28DF4F17B8379E0077F41A /* ProfilesOperations.cpp in Sources */,
  11632
+				180F6C8317CE9A5700127892 /* smc.c in Sources */,
11624 11633
 			);
11625 11634
 			runOnlyForDeploymentPostprocessing = 0;
11626 11635
 		};
@@ -12650,6 +12659,7 @@
12650 12659
 				F59EED7F17AD5174005BB7C6 /* ApplicationPlayer.cpp in Sources */,
12651 12660
 				DF29668117B2B04300DF10F9 /* SettingRequirement.cpp in Sources */,
12652 12661
 				DF28DF4E17B8379E0077F41A /* ProfilesOperations.cpp in Sources */,
  12662
+				180F6C8217CE9A5700127892 /* smc.c in Sources */,
12653 12663
 			);
12654 12664
 			runOnlyForDeploymentPostprocessing = 0;
12655 12665
 		};
22  xbmc/GUIInfoManager.cpp
@@ -85,6 +85,12 @@
85 85
 #include "cores/AudioEngine/Utils/AEUtil.h"
86 86
 #include "cores/VideoRenderers/BaseRenderer.h"
87 87
 
  88
+#if defined(TARGET_DARWIN)
  89
+#include "osx/smc.h"
  90
+#include "linux/LinuxResourceCounter.h"
  91
+static CLinuxResourceCounter m_resourceCounter;
  92
+#endif
  93
+
88 94
 #define SYSHEATUPDATEINTERVAL 60000
89 95
 
90 96
 using namespace std;
@@ -4009,7 +4015,9 @@ string CGUIInfoManager::GetSystemHeatInfo(int info)
4009 4015
       text.Format("%i%%", m_fanSpeed * 2);
4010 4016
       break;
4011 4017
     case SYSTEM_CPU_USAGE:
4012  
-#if defined(TARGET_DARWIN) || defined(TARGET_WINDOWS)
  4018
+#if defined(TARGET_DARWIN)
  4019
+      text.Format("%4.2f%%", m_resourceCounter.GetCPUUsage());
  4020
+#elif defined(TARGET_WINDOWS)
4013 4021
       text.Format("%d%%", g_cpuInfo.getUsedPercentage());
4014 4022
 #else
4015 4023
       text.Format("%s", g_cpuInfo.GetCoresUsageString());
@@ -4021,10 +4029,15 @@ string CGUIInfoManager::GetSystemHeatInfo(int info)
4021 4029
 
4022 4030
 CTemperature CGUIInfoManager::GetGPUTemperature()
4023 4031
 {
  4032
+  int  value = 0;
  4033
+  char scale = 0;
  4034
+
  4035
+#if defined(TARGET_DARWIN)
  4036
+  value = SMCGetTemperature(SMC_KEY_GPU_TEMP);
  4037
+  return CTemperature::CreateFromCelsius(value);
  4038
+#else
4024 4039
   CStdString  cmd   = g_advancedSettings.m_gpuTempCmd;
4025  
-  int         value = 0,
4026  
-              ret   = 0;
4027  
-  char        scale = 0;
  4040
+  int         ret   = 0;
4028 4041
   FILE        *p    = NULL;
4029 4042
 
4030 4043
   if (cmd.IsEmpty() || !(p = popen(cmd.c_str(), "r")))
@@ -4035,6 +4048,7 @@ CTemperature CGUIInfoManager::GetGPUTemperature()
4035 4048
 
4036 4049
   if (ret != 2)
4037 4050
     return CTemperature();
  4051
+#endif
4038 4052
 
4039 4053
   if (scale == 'C' || scale == 'c')
4040 4054
     return CTemperature::CreateFromCelsius(value);
2  xbmc/osx/DarwinUtils.mm
@@ -362,7 +362,7 @@ int DarwinBatteryLevel(void)
362 362
     powerSourceVal = CFDictionaryGetValue(powerSource, CFSTR(kIOPSMaxCapacityKey));
363 363
     CFNumberGetValue((CFNumberRef)powerSourceVal, kCFNumberSInt32Type, &maxLevel);
364 364
 
365  
-    batteryLevel = (int)((double)curLevel/(double)maxLevel);
  365
+    batteryLevel = (double)curLevel/(double)maxLevel;
366 366
   }
367 367
 #endif
368 368
   return batteryLevel * 100;  
170  xbmc/osx/smc.c
... ...
@@ -0,0 +1,170 @@
  1
+/*
  2
+ * Apple System Management Control (SMC) Tool
  3
+ * Copyright (C) 2006 devnull
  4
+ *
  5
+ * This program is free software; you can redistribute it and/or
  6
+ * modify it under the terms of the GNU General Public License
  7
+ * as published by the Free Software Foundation; either version 2
  8
+ * of the License, or (at your option) any later version.
  9
+ 
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ 
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program; if not, write to the Free Software
  17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18
+ */
  19
+
  20
+#include <stdio.h>
  21
+#include <string.h>
  22
+#include <IOKit/IOKitLib.h>
  23
+
  24
+#include "smc.h"
  25
+
  26
+static io_connect_t conn;
  27
+
  28
+UInt32 _strtoul(char *str, int size, int base)
  29
+{
  30
+  UInt32 total = 0;
  31
+  int i;
  32
+  
  33
+  for (i = 0; i < size; i++)
  34
+  {
  35
+    if (base == 16)
  36
+      total += str[i] << (size - 1 - i) * 8;
  37
+    else
  38
+      total += (unsigned char) (str[i] << (size - 1 - i) * 8);
  39
+  }
  40
+  return total;
  41
+}
  42
+
  43
+void _ultostr(char *str, UInt32 val)
  44
+{
  45
+  str[0] = '\0';
  46
+  sprintf(str, "%c%c%c%c",
  47
+          (unsigned int) val >> 24,
  48
+          (unsigned int) val >> 16,
  49
+          (unsigned int) val >> 8,
  50
+          (unsigned int) val);
  51
+}
  52
+
  53
+kern_return_t SMCOpen(void)
  54
+{
  55
+  kern_return_t result;
  56
+  mach_port_t   masterPort;
  57
+  io_iterator_t iterator;
  58
+  io_object_t   device;
  59
+  
  60
+  result = IOMasterPort(MACH_PORT_NULL, &masterPort);
  61
+  
  62
+  CFMutableDictionaryRef matchingDictionary = IOServiceMatching("AppleSMC");
  63
+  result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
  64
+  if (result != kIOReturnSuccess)
  65
+  {
  66
+    printf("Error: IOServiceGetMatchingServices() = %08x\n", result);
  67
+    return 1;
  68
+  }
  69
+  
  70
+  device = IOIteratorNext(iterator);
  71
+  IOObjectRelease(iterator);
  72
+  if (device == 0)
  73
+  {
  74
+    printf("Error: no SMC found\n");
  75
+    return 1;
  76
+  }
  77
+  
  78
+  result = IOServiceOpen(device, mach_task_self(), 0, &conn);
  79
+  IOObjectRelease(device);
  80
+  if (result != kIOReturnSuccess)
  81
+  {
  82
+    printf("Error: IOServiceOpen() = %08x\n", result);
  83
+    return 1;
  84
+  }
  85
+  
  86
+  return kIOReturnSuccess;
  87
+}
  88
+
  89
+kern_return_t SMCClose()
  90
+{
  91
+  return IOServiceClose(conn);
  92
+}
  93
+
  94
+
  95
+kern_return_t SMCCall(int index, SMCKeyData_t *inputStructure, SMCKeyData_t *outputStructure)
  96
+{
  97
+  size_t   structureInputSize;
  98
+  size_t   structureOutputSize;
  99
+  
  100
+  structureInputSize = sizeof(SMCKeyData_t);
  101
+  structureOutputSize = sizeof(SMCKeyData_t);
  102
+  
  103
+#if MAC_OS_X_VERSION_10_5
  104
+  return IOConnectCallStructMethod( conn, index,
  105
+                                   // inputStructure
  106
+                                   inputStructure, structureInputSize,
  107
+                                   // ouputStructure
  108
+                                   outputStructure, &structureOutputSize );
  109
+#else
  110
+  return IOConnectMethodStructureIStructureO( conn, index,
  111
+                                             structureInputSize, /* structureInputSize */
  112
+                                             &structureOutputSize,   /* structureOutputSize */
  113
+                                             inputStructure,        /* inputStructure */
  114
+                                             outputStructure);       /* ouputStructure */
  115
+#endif
  116
+  
  117
+}
  118
+
  119
+kern_return_t SMCReadKey(UInt32Char_t key, SMCVal_t *val)
  120
+{
  121
+  kern_return_t result;
  122
+  SMCKeyData_t  inputStructure;
  123
+  SMCKeyData_t  outputStructure;
  124
+  
  125
+  memset(&inputStructure, 0, sizeof(SMCKeyData_t));
  126
+  memset(&outputStructure, 0, sizeof(SMCKeyData_t));
  127
+  memset(val, 0, sizeof(SMCVal_t));
  128
+  
  129
+  inputStructure.key = _strtoul(key, 4, 16);
  130
+  inputStructure.data8 = SMC_CMD_READ_KEYINFO;
  131
+  
  132
+  result = SMCCall(KERNEL_INDEX_SMC, &inputStructure, &outputStructure);
  133
+  if (result != kIOReturnSuccess)
  134
+    return result;
  135
+  
  136
+  val->dataSize = outputStructure.keyInfo.dataSize;
  137
+  _ultostr(val->dataType, outputStructure.keyInfo.dataType);
  138
+  inputStructure.keyInfo.dataSize = val->dataSize;
  139
+  inputStructure.data8 = SMC_CMD_READ_BYTES;
  140
+  
  141
+  result = SMCCall(KERNEL_INDEX_SMC, &inputStructure, &outputStructure);
  142
+  if (result != kIOReturnSuccess)
  143
+    return result;
  144
+  
  145
+  memcpy(val->bytes, outputStructure.bytes, sizeof(outputStructure.bytes));
  146
+  
  147
+  return kIOReturnSuccess;
  148
+}
  149
+
  150
+double SMCGetTemperature(char *key)
  151
+{
  152
+  SMCVal_t val;
  153
+  kern_return_t result;
  154
+  SMCOpen();
  155
+  result = SMCReadKey(key, &val);
  156
+  SMCClose();
  157
+  if (result == kIOReturnSuccess) {
  158
+    // read succeeded - check returned value
  159
+    if (val.dataSize > 0) {
  160
+      if (strcmp(val.dataType, DATATYPE_SP78) == 0) {
  161
+        // convert fp78 value to temperature
  162
+        int intValue = (val.bytes[0] * 256 + val.bytes[1]) >> 2;
  163
+        return intValue / 64.0;
  164
+      }
  165
+    }
  166
+  }
  167
+  // read failed
  168
+  return 0.0;
  169
+}
  170
+
111  xbmc/osx/smc.h
... ...
@@ -0,0 +1,111 @@
  1
+/*
  2
+ * Apple System Management Control (SMC) Tool
  3
+ * Copyright (C) 2006 devnull
  4
+ *
  5
+ * This program is free software; you can redistribute it and/or
  6
+ * modify it under the terms of the GNU General Public License
  7
+ * as published by the Free Software Foundation; either version 2
  8
+ * of the License, or (at your option) any later version.
  9
+ 
  10
+ * This program is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13
+ * GNU General Public License for more details.
  14
+ 
  15
+ * You should have received a copy of the GNU General Public License
  16
+ * along with this program; if not, write to the Free Software
  17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  18
+ */
  19
+
  20
+#ifndef __SMC_H__
  21
+#define __SMC_H__
  22
+#endif
  23
+
  24
+#define SMC_VERSION               "0.01"
  25
+
  26
+#define OP_NONE               0
  27
+#define OP_LIST               1
  28
+#define OP_READ               2
  29
+#define OP_READ_FAN           3
  30
+#define OP_WRITE              4
  31
+
  32
+#define KERNEL_INDEX_SMC      2
  33
+
  34
+#define SMC_CMD_READ_BYTES    5
  35
+#define SMC_CMD_WRITE_BYTES   6
  36
+#define SMC_CMD_READ_INDEX    8
  37
+#define SMC_CMD_READ_KEYINFO  9
  38
+#define SMC_CMD_READ_PLIMIT   11
  39
+#define SMC_CMD_READ_VERS     12
  40
+
  41
+#define DATATYPE_FPE2         "fpe2"
  42
+#define DATATYPE_UINT8        "ui8 "
  43
+#define DATATYPE_UINT16       "ui16"
  44
+#define DATATYPE_UINT32       "ui32"
  45
+#define DATATYPE_SP78         "sp78"
  46
+
  47
+// key values
  48
+#define SMC_KEY_CPU_TEMP      "TC0D"
  49
+#define SMC_KEY_GPU_TEMP      "TG0D"
  50
+#define SMC_KEY_FAN0_RPM_MIN  "F0Mn"
  51
+#define SMC_KEY_FAN1_RPM_MIN  "F1Mn"
  52
+#define SMC_KEY_FAN0_RPM_CUR  "F0Ac"
  53
+#define SMC_KEY_FAN1_RPM_CUR  "F1Ac"
  54
+
  55
+
  56
+typedef struct {
  57
+  char                  major;
  58
+  char                  minor;
  59
+  char                  build;
  60
+  char                  reserved[1];
  61
+  UInt16                release;
  62
+} SMCKeyData_vers_t;
  63
+
  64
+typedef struct {
  65
+  UInt16                version;
  66
+  UInt16                length;
  67
+  UInt32                cpuPLimit;
  68
+  UInt32                gpuPLimit;
  69
+  UInt32                memPLimit;
  70
+} SMCKeyData_pLimitData_t;
  71
+
  72
+typedef struct {
  73
+  UInt32                dataSize;
  74
+  UInt32                dataType;
  75
+  char                  dataAttributes;
  76
+} SMCKeyData_keyInfo_t;
  77
+
  78
+typedef char              SMCBytes_t[32];
  79
+
  80
+typedef struct {
  81
+  UInt32                  key;
  82
+  SMCKeyData_vers_t       vers;
  83
+  SMCKeyData_pLimitData_t pLimitData;
  84
+  SMCKeyData_keyInfo_t    keyInfo;
  85
+  char                    result;
  86
+  char                    status;
  87
+  char                    data8;
  88
+  UInt32                  data32;
  89
+  SMCBytes_t              bytes;
  90
+} SMCKeyData_t;
  91
+
  92
+typedef char              UInt32Char_t[5];
  93
+
  94
+typedef struct {
  95
+  UInt32Char_t            key;
  96
+  UInt32                  dataSize;
  97
+  UInt32Char_t            dataType;
  98
+  SMCBytes_t              bytes;
  99
+} SMCVal_t;
  100
+
  101
+#ifdef __cplusplus
  102
+extern "C"
  103
+{
  104
+#endif
  105
+
  106
+// prototypes
  107
+double SMCGetTemperature(char *key);
  108
+
  109
+#ifdef __cplusplus
  110
+}
  111
+#endif
11  xbmc/utils/CPUInfo.cpp
@@ -26,6 +26,7 @@
26 26
 #if defined(TARGET_DARWIN)
27 27
 #include <sys/types.h>
28 28
 #include <sys/sysctl.h>
  29
+#include "osx/smc.h"
29 30
 #ifdef __ppc__
30 31
 #include <mach-o/arch.h>
31 32
 #endif
@@ -504,9 +505,14 @@ float CCPUInfo::getCPUFrequency()
504 505
 
505 506
 bool CCPUInfo::getTemperature(CTemperature& temperature)
506 507
 {
507  
-  int         value = 0,
508  
-              ret   = 0;
  508
+  int         value = 0;
509 509
   char        scale = 0;
  510
+  
  511
+#if defined(TARGET_DARWIN)
  512
+  value = SMCGetTemperature(SMC_KEY_CPU_TEMP);
  513
+  scale = 'c';
  514
+#else
  515
+  int         ret   = 0;
510 516
   FILE        *p    = NULL;
511 517
   CStdString  cmd   = g_advancedSettings.m_cpuTempCmd;
512 518
 
@@ -546,6 +552,7 @@ bool CCPUInfo::getTemperature(CTemperature& temperature)
546 552
 
547 553
   if (ret != 2)
548 554
     return false; 
  555
+#endif
549 556
 
550 557
   if (scale == 'C' || scale == 'c')
551 558
     temperature = CTemperature::CreateFromCelsius(value);
4  xbmc/utils/SystemInfo.cpp
@@ -450,7 +450,9 @@ bool CSysInfo::IsOS64bit()
450 450
 
451 451
 CStdString CSysInfo::GetKernelVersion()
452 452
 {
453  
-#if defined (TARGET_POSIX)
  453
+#if defined(TARGET_DARWIN)
  454
+  return g_sysinfo.GetUnameVersion();
  455
+#elif defined (TARGET_POSIX)
454 456
   struct utsname un;
455 457
   if (uname(&un)==0)
456 458
   {

0 notes on commit 2b2e2d1

Please sign in to comment.
Something went wrong with that request. Please try again.