summaryrefslogtreecommitdiffstats
path: root/src/hardware/LMI_ProcessorCapabilitiesProvider.c
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-03-26 15:35:34 +0100
committerPeter Schiffer <pschiffe@redhat.com>2013-03-26 15:35:34 +0100
commitc47c5c19c5857439db30e40d4a691f5b700adf5f (patch)
tree2cf25719bd0a4e87d56a51cf19cf7d509507a222 /src/hardware/LMI_ProcessorCapabilitiesProvider.c
parent338db1b89aa1276f5c57ba4f970df3c28bfb03ec (diff)
downloadopenlmi-providers-c47c5c19c5857439db30e40d4a691f5b700adf5f.tar.gz
openlmi-providers-c47c5c19c5857439db30e40d4a691f5b700adf5f.tar.xz
openlmi-providers-c47c5c19c5857439db30e40d4a691f5b700adf5f.zip
Hardware: added new providers
Providers added: * LMI_ProcessorCapabilitiesProvider * LMI_ProcessorElementCapabilitiesProvider
Diffstat (limited to 'src/hardware/LMI_ProcessorCapabilitiesProvider.c')
-rw-r--r--src/hardware/LMI_ProcessorCapabilitiesProvider.c275
1 files changed, 275 insertions, 0 deletions
diff --git a/src/hardware/LMI_ProcessorCapabilitiesProvider.c b/src/hardware/LMI_ProcessorCapabilitiesProvider.c
new file mode 100644
index 0000000..c9f7e14
--- /dev/null
+++ b/src/hardware/LMI_ProcessorCapabilitiesProvider.c
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
+#include <konkret/konkret.h>
+#include "LMI_ProcessorCapabilities.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+#include "lscpu.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void LMI_ProcessorCapabilitiesInitialize()
+{
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_ProcessorCapabilities lmi_cpu_cap;
+ CMPIUint16 cores = 1, threads = 1;
+ const char *ns = KNameSpace(cop),
+ *element_name_string = "Capabilities of processor ";
+ char *error_msg = NULL, *instance_id = NULL, *element_name = NULL;
+ unsigned i, cpus_nb = 0;
+ DmiProcessor *dmi_cpus;
+ unsigned dmi_cpus_nb;
+ LscpuProcessor lscpu;
+
+ if (dmi_get_processors(&dmi_cpus, &dmi_cpus_nb) != 0 || dmi_cpus_nb < 1) {
+ dmi_free_processors(&dmi_cpus, &dmi_cpus_nb);
+ }
+
+ if (lscpu_get_processor(&lscpu) != 0) {
+ error_msg = "Unable to get processor information.";
+ goto done;
+ }
+
+ if (dmi_cpus_nb > 0) {
+ cpus_nb = dmi_cpus_nb;
+ } else if (lscpu.processors > 0) {
+ cpus_nb = lscpu.processors;
+ } else {
+ error_msg = "Unable to get processor information.";
+ goto done;
+ }
+
+ for (i = 0; i < cpus_nb; i++) {
+ LMI_ProcessorCapabilities_Init(&lmi_cpu_cap, _cb, ns);
+
+ /* do we have output from dmidecode program? */
+ if (dmi_cpus_nb > 0) {
+ if (asprintf(&instance_id, "%s:%s:%s", ORGID,
+ CPU_CAP_CLASS_NAME, dmi_cpus[i].id) < 0) {
+ instance_id = NULL;
+ error_msg = "Not enough available memory.";
+ goto done;
+ }
+
+ cores = dmi_cpus[i].cores;
+ threads = dmi_cpus[i].threads;
+
+ if (asprintf(&element_name, "%s%s",
+ element_name_string, dmi_cpus[i].id) < 0) {
+ element_name = NULL;
+ error_msg = "Not enough available memory.";
+ goto done;
+ }
+ } else {
+ if (asprintf(&instance_id, "%s:%s:%u", ORGID,
+ CPU_CAP_CLASS_NAME, i) < 0) {
+ instance_id = NULL;
+ error_msg = "Not enough available memory.";
+ goto done;
+ }
+
+ cores = lscpu.cores;
+ threads = lscpu.threads_per_core * lscpu.cores;
+
+ if (asprintf(&element_name, "%s%u",
+ element_name_string, i) < 0) {
+ element_name = NULL;
+ error_msg = "Not enough available memory.";
+ goto done;
+ }
+ }
+
+ LMI_ProcessorCapabilities_Set_InstanceID(&lmi_cpu_cap, instance_id);
+ LMI_ProcessorCapabilities_Set_NumberOfProcessorCores(&lmi_cpu_cap,
+ cores);
+ LMI_ProcessorCapabilities_Set_NumberOfHardwareThreads(&lmi_cpu_cap,
+ threads);
+ LMI_ProcessorCapabilities_Set_ElementNameEditSupported(&lmi_cpu_cap, 0);
+ LMI_ProcessorCapabilities_Set_Caption(&lmi_cpu_cap,
+ "Processor Capabilities");
+ LMI_ProcessorCapabilities_Set_Description(&lmi_cpu_cap,
+ "This object represents (mainly multi-core and multi-thread) capabilities of processor in system.");
+ LMI_ProcessorCapabilities_Set_ElementName(&lmi_cpu_cap, element_name);
+
+ KReturnInstance(cr, lmi_cpu_cap);
+
+ if (instance_id) {
+ free(instance_id);
+ }
+ instance_id = NULL;
+ if (element_name) {
+ free(element_name);
+ }
+ element_name = NULL;
+ }
+
+done:
+ if (instance_id) {
+ free(instance_id);
+ }
+ instance_id = NULL;
+ if (element_name) {
+ free(element_name);
+ }
+ element_name = NULL;
+
+ dmi_free_processors(&dmi_cpus, &dmi_cpus_nb);
+ lscpu_free_processor(&lscpu);
+
+ if (error_msg) {
+ KReturn2(_cb, ERR_FAILED, error_msg);
+ }
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesGetInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ return KDefaultGetInstance(
+ _cb, mi, cc, cr, cop, properties);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesModifyInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci,
+ const char** properties)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesExecQuery(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* lang,
+ const char* query)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+CMInstanceMIStub(
+ LMI_ProcessorCapabilities,
+ LMI_ProcessorCapabilities,
+ _cb,
+ LMI_ProcessorCapabilitiesInitialize())
+
+static CMPIStatus LMI_ProcessorCapabilitiesMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_ProcessorCapabilitiesInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_ProcessorCapabilities_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_ProcessorCapabilities,
+ LMI_ProcessorCapabilities,
+ _cb,
+ LMI_ProcessorCapabilitiesInitialize())
+
+KUint16 LMI_ProcessorCapabilities_CreateGoalSettings(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_ProcessorCapabilitiesRef* self,
+ const KStringA* TemplateGoalSettings,
+ KStringA* SupportedGoalSettings,
+ CMPIStatus* status)
+{
+ KUint16 result = KUINT16_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_ProcessorCapabilities",
+ "LMI_ProcessorCapabilities",
+ "instance method")