New CPU functionality and Host wordsize
by Darryl L. Pierce
The following patch set includes code to report the wordsize of the
system's processor, as reported by CPU flags. It also determines the
host's binary wordsize by checking the size of a memory address and
multiplying it by the size of a single byte.
13 years, 9 months
[PATCH] Retrieves the CPU and core count for Windows.
by Darryl L. Pierce
This code loops through the result for a call to
GetLogicalProcessorInformation and counts the number of processors and
cores.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 95 insertions(+), 1 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index d6955a5..c9135d5 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -36,6 +36,56 @@ extern "C" {
using namespace std;
+#ifdef WIN32
+
+/* The following definitions make up for what is lacking currently
+ * in the MinGW packages, and should be moved out to them at some
+ * point in future.
+ */
+
+typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
+ RelationProcessorCore,
+ RelationNumaNode,
+ RelationCache,
+ RelationProcessorPackage,
+ RelationGroup,
+ RelationAll = 0xffff
+} LOGICAL_PROCESSOR_RELATIONSHIP;
+
+typedef enum _PROCESSOR_CACHE_TYPE {
+ CacheUnified,
+ CacheInstruction,
+ CacheData,
+ CacheTrace
+} PROCESSOR_CACHE_TYPE;
+
+typedef struct _CACHE_DESCRIPTOR {
+ BYTE Level;
+ BYTE Associativity;
+ WORD LineSize;
+ DWORD Size;
+ PROCESSOR_CACHE_TYPE Type;
+} CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
+
+typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
+ ULONG_PTR ProcessorMask;
+ LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
+ union {
+ struct {
+ BYTE Flags;
+ } ProcessorCore;
+ struct {
+ DWORD NodeNumber;
+ } NumaNode;
+ CACHE_DESCRIPTOR Cache;
+ ULONGLONG Reserved[2];
+ } ;
+} SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
+
+typedef BOOL (WINAPI* LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
+
+#endif
+
typedef struct cpuinfo_
{
static bool initialized;
@@ -260,8 +310,52 @@ host_get_cpu_details()
input.close();
cpuinfo.cpus /= cpuinfo.cores;
}
-#endif
+#elif defined WIN32
+ LPFN_GLPI proc;
+ DWORD ret_length;
+ PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer, ptr;
+
+ proc = (LPFN_GLPI) GetProcAddress(GetModuleHandle(TEXT("kernel32")),
+ "GetLogicalProcessorInformation");
+ if(proc)
+ {
+ BOOL done = FALSE;
+
+ while (!done)
+ {
+ DWORD rc = proc(buffer, &ret_length);
+
+ if(rc == FALSE)
+ {
+ if(GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+ {
+ if(buffer) free(buffer);
+
+ buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(ret_length);
+ }
+ }
+ else
+ {
+ done = TRUE;
+ }
+ }
+
+ ptr = buffer;
+
+ DWORD offset = 0;
+ while(offset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= ret_length)
+ {
+ switch(ptr->Relationship)
+ {
+ case RelationProcessorCore: cpuinfo.cores++; break;
+ case RelationProcessorPackage: cpuinfo.cpus++; break;
+ }
+ }
+
+ if(buffer) free(buffer);
+ }
+#endif
}
string
--
1.7.2
13 years, 9 months
Specifying the platform and architecture
by Darryl L. Pierce
The goal with these two properties is to specific what the operating system's
wordsize and the processor's wordsize are, respectively. But in thinking
about this, is this necessary or can it be done better?
I'm going to suggest that the architecture API on the Host agent go away
and instead be replaced with a similar property on the Processor agent. It
makes more sense to have it there in the first place.
Platform itself would remain as is and would be more clearly understood
with the above change.
Thoughts?
--
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/
13 years, 9 months
[PATCH] Provides the Win32 code for fetching total system memory.
by Darryl L. Pierce
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index d6955a5..29dcc29 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -162,7 +162,6 @@ host_get_architecture()
if(architecture.empty())
{
-
#ifdef __linux__
struct utsname details;
@@ -170,8 +169,9 @@ host_get_architecture()
{
architecture = string(details.machine);
}
-#endif
+#elif defined WIN32
+#endif
}
return architecture;
@@ -184,15 +184,18 @@ host_get_memory()
if(!memory)
{
-
#ifdef __linux__
struct sysinfo sysinf;
if(!sysinfo(&sysinf))
{
memory = sysinf.totalram / 1024L;
}
-#endif
+#elif defined WIN32
+ MEMORYSTATUS status;
+ GlobalMemoryStatus(&status);
+ memory = status.dwTotalPhys / 1024L;
+#endif
}
return memory;
--
1.7.2
13 years, 9 months
[PATCH] Windows support for the hostname APIs.
by Darryl L. Pierce
Added conditional code for get the hostname via Windows APIs when
compiling on Windows.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index d6955a5..2f86dea 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -27,8 +27,17 @@
#include <stdexcept>
#include <string>
#include <sys/sysinfo.h>
+
+#ifdef __linux__
+
#include <sys/utsname.h>
+#elif defined WIN32
+
+#include <winsock.h>
+
+#endif
+
// TODO remove this wrapper once rhbz#583747 is fixed
extern "C" {
#include <libudev.h>
@@ -117,16 +126,32 @@ host_get_hostname()
if(hostname.empty())
{
-
#ifdef __linux__
+
struct utsname details;
if(!uname(&details))
{
hostname = string(details.nodename);
}
- #endif
+#elif defined WIN32
+
+ char buffer[512];
+ WORD verreq;
+ WSADATA wsadata;
+
+ verreq = MAKEWORD(2, 2);
+ if(!WSAStartup(verreq, &wsadata))
+ {
+ if(!gethostname(buffer, 512))
+ {
+ hostname = string(buffer);
+ }
+ WSACleanup();
+ }
+
+ #endif
}
return hostname;
--
1.7.1.1
13 years, 9 months
[PATCH] Changed the build process to allow for multiple schema files.
by Darryl L. Pierce
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/Makefile.am | 9 ++++++---
src/schema-host.xml | 38 ++++++++++++++++++++++++++++++++++++++
src/schema.xml | 38 --------------------------------------
3 files changed, 44 insertions(+), 41 deletions(-)
create mode 100644 src/schema-host.xml
delete mode 100644 src/schema.xml
diff --git a/src/Makefile.am b/src/Makefile.am
index daddf9d..304214c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,8 +27,11 @@ matahari_SOURCES = \
qmf/hostagent.cpp \
qmf/hostagent.h
-$(generated_file_list): schema.xml
- qmf-gen -o ./qmf ./schema.xml
+SCHEMAS = \
+ schema-host.xml
+
+$(generated_file_list): $(SCHEMAS)
+ qmf-gen -o ./qmf $(SCHEMAS)
BUILT_SOURCES = $(generated_file_list)
CLEANFILES = $(generated_file_list)
@@ -37,4 +40,4 @@ matahari_CPPFLAGS = -fno-strict-aliasing
matahari_LDADD = -lpcre -lqmf -lqpidclient -lqpidcommon -ludev -lvirt
matahari_LDADD += ../lib/libmatahari.a
-dist_pkgdata_DATA = schema.xml
+dist_pkgdata_DATA = schema-host.xml
diff --git a/src/schema-host.xml b/src/schema-host.xml
new file mode 100644
index 0000000..7a223f9
--- /dev/null
+++ b/src/schema-host.xml
@@ -0,0 +1,38 @@
+<schema package="com.redhat.matahari.host">
+
+ <class name="Host">
+ <!-- properties -->
+ <property name="uuid" type="sstr" access="RO" desc="Host UUID" index="y" />
+ <property name="hostname" type="sstr" access="RO" desc="Hostname" />
+ <property name="is_virtual" type="bool" access="RO" desc="Is this machine virtual?" />
+ <property name="operating_system" type="sstr" access="RO" desc="The installed operating system." />
+ <property name="memory" type="int64" access="RO" desc="Amount of primary memory for host (kb)" unit="kb" />
+ <property name="arch" type="sstr" access="RO" desc="Architecture of host" />
+ <property name="hypervisor" type="sstr" access="RO" desc="Hypervisor used by host" />
+ <property name="platform" type="sstr" access="RO" desc="The wordsize for the host." />
+ <property name="cpu_model" type="lstr" access="RO" desc="The process model description." />
+ <property name="cpu_count" type="uint8" access="RO" desc="The number of physical CPUs." />
+ <property name="cpu_cores" type="uint8" access="RO" desc="The total number of processor cores." />
+
+ <!-- statistics -->
+ <statistic name="last_updated" type="absTime" desc="The last time a heartbeat occurred." />
+ <statistic name="load_average_1" type="double" desc="The one minute load average." />
+ <statistic name="load_average_5" type="double" desc="The five minute load average." />
+ <statistic name="load_average_15" type="double" desc="The fiften minute load average" />
+
+ <!-- APIs -->
+ <method name="list_network_interfaces" desc="Returns the list of all network interfaces." />
+ <method name="identify" desc="Tells the host to beep its pc speaker." />
+ <method name="shutdown" desc="Shutdown node" />
+ <method name="reboot" desc="Reboot node" />
+
+ </class>
+
+ <eventArguments>
+ <arg name="timestamp" type="absTime" />
+ <arg name="sequence" type="uint32" />
+ </eventArguments>
+
+ <event name="heartbeat" args="timestamp,sequence" />
+
+</schema>
diff --git a/src/schema.xml b/src/schema.xml
deleted file mode 100644
index 7a223f9..0000000
--- a/src/schema.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<schema package="com.redhat.matahari.host">
-
- <class name="Host">
- <!-- properties -->
- <property name="uuid" type="sstr" access="RO" desc="Host UUID" index="y" />
- <property name="hostname" type="sstr" access="RO" desc="Hostname" />
- <property name="is_virtual" type="bool" access="RO" desc="Is this machine virtual?" />
- <property name="operating_system" type="sstr" access="RO" desc="The installed operating system." />
- <property name="memory" type="int64" access="RO" desc="Amount of primary memory for host (kb)" unit="kb" />
- <property name="arch" type="sstr" access="RO" desc="Architecture of host" />
- <property name="hypervisor" type="sstr" access="RO" desc="Hypervisor used by host" />
- <property name="platform" type="sstr" access="RO" desc="The wordsize for the host." />
- <property name="cpu_model" type="lstr" access="RO" desc="The process model description." />
- <property name="cpu_count" type="uint8" access="RO" desc="The number of physical CPUs." />
- <property name="cpu_cores" type="uint8" access="RO" desc="The total number of processor cores." />
-
- <!-- statistics -->
- <statistic name="last_updated" type="absTime" desc="The last time a heartbeat occurred." />
- <statistic name="load_average_1" type="double" desc="The one minute load average." />
- <statistic name="load_average_5" type="double" desc="The five minute load average." />
- <statistic name="load_average_15" type="double" desc="The fiften minute load average" />
-
- <!-- APIs -->
- <method name="list_network_interfaces" desc="Returns the list of all network interfaces." />
- <method name="identify" desc="Tells the host to beep its pc speaker." />
- <method name="shutdown" desc="Shutdown node" />
- <method name="reboot" desc="Reboot node" />
-
- </class>
-
- <eventArguments>
- <arg name="timestamp" type="absTime" />
- <arg name="sequence" type="uint32" />
- </eventArguments>
-
- <event name="heartbeat" args="timestamp,sequence" />
-
-</schema>
--
1.7.1.1
13 years, 9 months
First pass of updated features
by Darryl L. Pierce
This pair of patches refactors the CPU identification code, and
also ensures the last updated timestamp is properly set each time
a heartbeat event is fired.
13 years, 9 months
Refactored Host APIs
by Darryl L. Pierce
Refactored the patch based on feedback from beekhof. Changes the load
average API to return all three averages and added a CPU count API.
13 years, 9 months
Host and Network Device APIs...
by Darryl L. Pierce
I've been going over the previous set of APIs and looking at what we can
do next to make the Host and Network Device APIs more usable. What I'm
thinking is the following:
Host:
Generally, the Host APIs will let us do the current set of host-related
tasks (identify, reboot, shutdown, get CPU information, hostname, etc.)
An additional API would be to get the list of Network Devices on the
host. An optional flag would be to specify whether they be physical
devices only, or all devices which would include bridges, bonded
interfaces, etc.
Another API would be to configure a new network interface. It will take
in as input a NetCF descriptor for the new interface and would return
the success of the operation.
Network Device:
I've scaled back the APIs on this to have the interface's name and mac
address (if one is present). The APIs it would present include methods
to configure and destroy the device, start and stop the device, and
return the NetCF descriptor.
The overall philosophy of the APIs is that to create a new device
(network, storage partition or otherwise) should go through the Host
agent. Then, once it's created, it can be retrieved by fetching the
{NetworkDevice,Storage}Agent for that newly created device by the unique
index (interface name, partition or volume name, or by some UUID).
Thoughts?
--
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/
13 years, 9 months