Exemplo n.º 1
0
void glxosdPluginConstructor(glxosd::GLXOSD *glxosd) {
	glxosd->getConfigurationManager().addDefaultConfigurationValue(
			"nvidia_gpu_format", glxosd::glxosdFormat("%1% (%2%): %3%\n"));

	nvidiaGPUFormat = glxosd->getConfigurationManager().getProperty < boost::format
			> ("nvidia_gpu_format");

	int event, error;

	display = XOpenDisplay(NULL);

	if (!display || !XNVCTRLQueryExtension(display, &event, &error)
			|| !XNVCTRLQueryTargetCount(display, NV_CTRL_TARGET_TYPE_GPU,
					&numberOfGpus)) {
		errorResult = "Couldn't read the number of NVIDIA GPUs.";
	} else {
		for (int i = 0; i < numberOfGpus; i++) {
			char *name;
			if (XNVCTRLQueryTargetStringAttribute(display,
			NV_CTRL_TARGET_TYPE_GPU, i, 0,
			NV_CTRL_STRING_PRODUCT_NAME, &name) != True) {
				displayNames.push_back(std::string("unknown"));
			} else {
				displayNames.push_back(std::string(name));
			}
		}
	}
}
Exemplo n.º 2
0
bool UINVControl::NVControlAvailable(Display *XDisplay)
{
    QMutexLocker locker(gNVCtrlLock);

    static bool available = false;
    static bool checked   = false;

    if (checked || !XDisplay)
        return available;

    checked = true;

    int event = 0;
    int error = 0;
    Bool ok = XNVCTRLQueryExtension(XDisplay, &event, &error);

    if (ok != True)
    {
        LOG(VB_GENERAL, LOG_INFO, QString("NV-CONTROL X extension not available on display '%1'").arg(XDisplayName(NULL)));
        return available;
    }

    int major = 0;
    int minor = 0;
    ok = XNVCTRLQueryVersion(XDisplay, &major, &minor);

    if (ok != True)
    {
        LOG(VB_GENERAL, LOG_INFO, QString("NV-CONTROL X extension not available on display '%1'").arg(XDisplayName(NULL)));
        return available;
    }

    available = true;

    LOG(VB_GENERAL, LOG_INFO, QString("NV-CONTROL X extension version %1.%2 available on display '%3'")
        .arg(major).arg(minor).arg(XDisplayName(NULL)));

    return available;
}
Exemplo n.º 3
0
egl::Error DisplayGLX::getNVIDIADriverVersion(std::string *version) const
{
    *version = "";

    int eventBase = 0;
    int errorBase = 0;
    if (XNVCTRLQueryExtension(mXDisplay, &eventBase, &errorBase))
    {
        int screenCount = ScreenCount(mXDisplay);
        for (int screen = 0; screen < screenCount; ++screen)
        {
            char *buffer = nullptr;
            if (XNVCTRLIsNvScreen(mXDisplay, screen) &&
                XNVCTRLQueryStringAttribute(mXDisplay, screen, 0,
                                            NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, &buffer))
            {
                *version = buffer;
                XFree(buffer);
            }
        }
    }

    return egl::Error(EGL_SUCCESS);
}
Exemplo n.º 4
0
// this function does some checks
int nvidia_gpu_init(Display * dpy, int screen) {

	int event_base, error_base;

    int ret = XNVCTRLQueryExtension(dpy, &event_base, &error_base);
    if (ret != True) {
        fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n",
                XDisplayName(NULL));
        return 0;
    }

	if(!XNVCTRLIsNvScreen(dpy, screen)) {
		fprintf(stderr, "Screen %d does not support the NV-Control extension\n", screen);
		return 0;
	}

	int max;
	ret = XNVCTRLQueryAttribute(dpy, screen, 0, NV_CTRL_GPU_CORE_THRESHOLD, &max);
	if(ret) {
		nvidia_gpu_max_temperature = max;
	}
	
	return 1;
}
/**
 * load initial data
 *
 * TODO:350:M: Implement nvCtrlTable data load
 * This function will also be called by the cache helper to load
 * the container again (after the container free function has been
 * called to free the previous contents).
 *
 * @param container container to which items should be inserted
 *
 * @retval MFD_SUCCESS              : success.
 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
 * @retval MFD_ERROR                : other error.
 *
 *  This function is called to load the index(es) (and data, optionally)
 *  for the every row in the data set.
 *
 * @remark
 *  While loading the data, the only important thing is the indexes.
 *  If access to your data is cheap/fast (e.g. you have a pointer to a
 *  structure in memory), it would make sense to update the data here.
 *  If, however, the accessing the data invovles more work (e.g. parsing
 *  some other existing data, or peforming calculations to derive the data),
 *  then you can limit yourself to setting the indexes and saving any
 *  information you will need later. Then use the saved information in
 *  nvCtrlTable_row_prep() for populating data.
 *
 * @note
 *  If you need consistency between rows (like you want statistics
 *  for each row to be from the same time frame), you should set all
 *  data here.
 *
 */
int
nvCtrlTable_container_load(netsnmp_container *container)
{
    nvCtrlTable_rowreq_ctx *rowreq_ctx;
    size_t                 count = 0;
    Display *dpy;
    Bool ret;
    int event_base, error_base, major, minor, gpus;
    int gpu, retval, len;
    char *str;

    DEBUGMSGTL(("verbose:nvCtrlTable:nvCtrlTable_container_load", "called\n"));

    /*
     * open a connection to the X server indicated by the DISPLAY
     * environment variable
     */

    dpy = XOpenDisplay(NULL);
    if (!dpy) {
	DEBUGMSGTL(("nvCtrlTable:nvCtrlTable_container_load",
		    "Cannot open display '%s'.\n", XDisplayName(NULL)));
        return MFD_RESOURCE_UNAVAILABLE;
    }

    /*
     * check if the NV-CONTROL X extension is present on this X server
     */

    ret = XNVCTRLQueryExtension(dpy, &event_base, &error_base);
    if (ret != True) {
	DEBUGMSGTL(("nvCtrlTable:nvCtrlTable_container_load",
		    "The NV-CONTROL X extension does not exist on '%s'.\n",
		    XDisplayName(NULL)));
        return MFD_RESOURCE_UNAVAILABLE;
    }

    /*
     * query the major and minor extension version
     */

    ret = XNVCTRLQueryVersion(dpy, &major, &minor);
    if (ret != True) {
	DEBUGMSGTL(("nvCtrlTable:nvCtrlTable_container_load",
		    "The NV-CONTROL X extension does not exist on '%s'.\n",
		    XDisplayName(NULL)));
        return MFD_RESOURCE_UNAVAILABLE;
    }

    /*
     * query number of GPUs via the NV-CONTROL X extension; then, allocate
     * a rowreq context, set the index(es) and data, and insert into the
     * container.
     */

    if (!XNVCTRLQueryTargetCount(dpy, NV_CTRL_TARGET_TYPE_GPU, &gpus)) {
	snmp_log(LOG_ERR, "failed to query number of GPUs\n");
	return MFD_ERROR;
    }

    for (gpu = 0; gpu < gpus; gpu++) {
        rowreq_ctx = nvCtrlTable_allocate_rowreq_ctx();
        if (NULL == rowreq_ctx) {
            snmp_log(LOG_ERR, "memory allocation failed\n");
            return MFD_RESOURCE_UNAVAILABLE;
        }
	if (MFD_SUCCESS != nvCtrlTable_indexes_set(rowreq_ctx, gpu)) {
            snmp_log(LOG_ERR, "error setting index while loading"
		     "nvCtrlTable data.\n");
            nvCtrlTable_release_rowreq_ctx(rowreq_ctx);
            continue;
        }

	/*
	 * setup/save data for nvCtrlProductName
	 * nvCtrlProductName(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H
	 */
	ret = XNVCTRLQueryTargetStringAttribute(dpy,
						NV_CTRL_TARGET_TYPE_GPU,
						gpu,
						0,
						NV_CTRL_STRING_PRODUCT_NAME,
						&str);
	if (ret) {
	    len = strlen(str);
	    if (sizeof(rowreq_ctx->data.nvCtrlProductName) < len) {
		snmp_log(LOG_ERR,"not enough space for value\n");
		return MFD_ERROR;
	    }
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_PRODUCT_NAME_FLAG;
	    rowreq_ctx->data.nvCtrlProductName_len = len;
	    memcpy(rowreq_ctx->data.nvCtrlProductName, str, len);
	    XFree(str);
	}

	/*
	 * setup/save data for nvCtrlVBiosVersion
	 * nvCtrlVBiosVersion(3)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H
	 */
	ret = XNVCTRLQueryTargetStringAttribute(dpy,
						NV_CTRL_TARGET_TYPE_GPU,
						gpu,
						0,
						NV_CTRL_STRING_VBIOS_VERSION,
						&str);
	if (ret) {
	    len = strlen(str);
	    if (sizeof(rowreq_ctx->data.nvCtrlVBiosVersion) < len) {
		snmp_log(LOG_ERR,"not enough space for value\n");
		return MFD_ERROR;
	    }
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_VBIOS_VERSION_FLAG;
	    rowreq_ctx->data.nvCtrlVBiosVersion_len = len;
	    memcpy(rowreq_ctx->data.nvCtrlVBiosVersion, str, len);
	    XFree(str);
	}

	/*
	 * setup/save data for nvCtrlNvidiaDriverVersion
	 * nvCtrlNvidiaDriverVersion(4)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H
	 */
	ret = XNVCTRLQueryTargetStringAttribute(dpy,
						NV_CTRL_TARGET_TYPE_GPU,
						gpu,
						0,
						NV_CTRL_STRING_NVIDIA_DRIVER_VERSION,
						&str);
	if (ret) {
	    len = strlen(str);
	    if (sizeof(rowreq_ctx->data.nvCtrlNvidiaDriverVersion) < len) {
		snmp_log(LOG_ERR,"not enough space for value\n");
		return MFD_ERROR;
	    }
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_NVIDIA_DRIVER_VERSION_FLAG;
	    rowreq_ctx->data.nvCtrlNvidiaDriverVersion_len = len;
	    memcpy(rowreq_ctx->data.nvCtrlNvidiaDriverVersion, str, len);
	    XFree(str);
	}

	/*
	 * setup/save data for nvCtrlVersion
	 * nvCtrlVersion(5)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H
	 */
	rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_VERSION_FLAG;
	snprintf(rowreq_ctx->data.nvCtrlVersion, sizeof(rowreq_ctx->data.nvCtrlVersion), "%d.%d", major, minor);
	rowreq_ctx->data.nvCtrlVersion_len = strlen(rowreq_ctx->data.nvCtrlVersion);

	/*
	 * setup/save data for nvCtrlBusType
	 * nvCtrlBusType(6)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_BUS_TYPE,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_BUS_TYPE_FLAG;
	    rowreq_ctx->data.nvCtrlBusType = retval;
	}

	/*
	 * setup/save data for nvCtrlBusRate
	 * nvCtrlBusRate(7)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_BUS_RATE,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_BUS_RATE_FLAG;
	    rowreq_ctx->data.nvCtrlBusRate = retval;
	}

	/*
	 * setup/save data for nvCtrlVideoRam
	 * nvCtrlVideoRam(8)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_VIDEO_RAM,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_VIDEO_RAM_FLAG;
	    rowreq_ctx->data.nvCtrlVideoRam = retval;
	}

	/*
	 * setup/save data for nvCtrlIrq
	 * nvCtrlIrq(9)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_IRQ,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_IRQ_FLAG;
	    rowreq_ctx->data.nvCtrlIrq = retval;
	}

	/*
	 * setup/save data for nvCtrlGPUCoreTemp
	 * nvCtrlGPUCoreTemp(10)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_CORE_TEMPERATURE,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_CORE_TEMP_FLAG;
	    rowreq_ctx->data.nvCtrlGPUCoreTemp = retval;
	}

	/*
	 * setup/save data for nvCtrlGPUCoreThreshold
	 * nvCtrlGPUCoreThreshold(11)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_CORE_THRESHOLD,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_CORE_THRESHOLD_FLAG;
	    rowreq_ctx->data.nvCtrlGPUCoreThreshold = retval;
	}

	/*
	 * setup/save data for nvCtrlGPUDefaultCoreThreshold
	 * nvCtrlGPUDefaultCoreThreshold(12)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD_FLAG;
	    rowreq_ctx->data.nvCtrlGPUDefaultCoreThreshold = retval;
	}

	/*
	 * setup/save data for nvCtrlGPUMaxCoreThreshold
	 * nvCtrlGPUMaxCoreThreshold(13)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_MAX_CORE_THRESHOLD,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_MAX_CORE_THRESHOLD_FLAG;
	    rowreq_ctx->data.nvCtrlGPUMaxCoreThreshold = retval;
	}

	/*
	 * setup/save data for nvCtrlGPUAmbientTemp
	 * nvCtrlGPUAmbientTemp(14)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_AMBIENT_TEMPERATURE,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_AMBIENT_TEMP_FLAG;
	    rowreq_ctx->data.nvCtrlGPUAmbientTemp = retval;
	}

	/*
	 * setup/save data for nvCtrlGPUOverclockingState
	 * nvCtrlGPUOverclockingState(15)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_OVERCLOCKING_STATE,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_OVERCLOCKING_STATE_FLAG;
	    rowreq_ctx->data.nvCtrlGPUOverclockingState = retval;
	}

	/*
	 * setup/save data for nvCtrlGPU2DGPUClockFreq
	 * nvCtrlGPU2DGPUClockFreq(16)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_2D_CLOCK_FREQS,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_2D_GPU_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPU2DGPUClockFreq = (retval >> 16) & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPU2DMemClockFreq
	 * nvCtrlGPU2DMemClockFreq(17)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_2D_MEM_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPU2DMemClockFreq = retval & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPU3DGPUClockFreq
	 * nvCtrlGPU3DGPUClockFreq(18)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_3D_CLOCK_FREQS,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_3D_GPU_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPU3DGPUClockFreq = (retval >> 16) & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPU3DMemClockFreq
	 * nvCtrlGPU3DMemClockFreq(19)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_3D_MEM_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPU3DMemClockFreq = retval & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPUDefault2DGPUClockFreq
	 * nvCtrlGPUDefault2DGPUClockFreq(20)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_DEFAULT_2D_GPU_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPUDefault2DGPUClockFreq = (retval >> 16) & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPUDefault2DMemClockFreq
	 * nvCtrlGPUDefault2DMemClockFreq(21)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_DEFAULT_2D_MEM_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPUDefault2DMemClockFreq = retval & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPUDefault3DGPUClockFreq
	 * nvCtrlGPUDefault3DGPUClockFreq(22)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_DEFAULT_3D_CLOCK_FREQS,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_DEFAULT_3D_GPU_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPUDefault3DGPUClockFreq = (retval >> 16) & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPUDefault3DMemClockFreq
	 * nvCtrlGPUDefault3DMemClockFreq(23)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_DEFAULT_3D_MEM_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPUDefault3DMemClockFreq = retval & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPUCurrentGPUClockFreq
	 * nvCtrlGPUCurrentGPUClockFreq(24)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	ret = XNVCTRLQueryTargetAttribute(dpy,
					  NV_CTRL_TARGET_TYPE_GPU,
					  gpu,
					  0,
					  NV_CTRL_GPU_CURRENT_CLOCK_FREQS,
					  &retval);
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_CURRENT_GPU_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPUCurrentGPUClockFreq = (retval >> 16) & 0xFFFF;
	}

	/*
	 * setup/save data for nvCtrlGPUCurrentMemClockFreq
	 * nvCtrlGPUCurrentMemClockFreq(25)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h
	 */
	if (ret) {
	    rowreq_ctx->column_exists_flags |= COLUMN_NV_CTRL_GPU_CURRENT_MEM_CLOCK_FREQ_FLAG;
	    rowreq_ctx->data.nvCtrlGPUCurrentMemClockFreq = retval & 0xFFFF;
	}

	/*
	 * insert into table container
	 */
	CONTAINER_INSERT(container, rowreq_ctx);
	++count;
    }

    /*
     * close the display connection
     */

    XCloseDisplay(dpy);


    DEBUGMSGT(("verbose:nvCtrlTable:nvCtrlTable_container_load",
               "inserted %d records\n", count));

    return MFD_SUCCESS;
} /* nvCtrlTable_container_load */
static void
is_nvidia_plugin_activate(PeasActivatable *activatable)
{
	IsNvidiaPlugin *self = IS_NVIDIA_PLUGIN(activatable);
	IsNvidiaPluginPrivate *priv = self->priv;
	Bool ret;
	int event_base, error_base;
	gint n;
	int i;

	/* search for sensors and add them to manager */
	if (!priv->inited) {
		is_warning("nvidia", "not inited, unable to find sensors");
		goto out;
	}

	is_debug("nvidia", "searching for sensors");

	/* check if the NV-CONTROL extension is available on this X
         * server */
	ret = XNVCTRLQueryExtension(priv->display, &event_base, &error_base);
	if (!ret) {
		goto out;
	}

	/* get number of GPUs, then for each GPU get any thermal_sensors and
	   coolers used by it */
	ret = XNVCTRLQueryTargetCount(priv->display,
				      NV_CTRL_TARGET_TYPE_GPU,
				      &n);
	if (!ret) {
		goto out;
	}

	for (i = 0; i < n; i++) {
		guint j;
		char *label = NULL;
		ret = XNVCTRLQueryTargetStringAttribute(priv->display,
							NV_CTRL_TARGET_TYPE_GPU,
							i,
							0,
							NV_CTRL_STRING_PRODUCT_NAME,
							&label);
		for (j = 0; j < G_N_ELEMENTS(map); j++) {
			int32_t *data;
			int len;
			int k;

			ret = XNVCTRLQueryTargetBinaryData(priv->display,
							   NV_CTRL_TARGET_TYPE_GPU,
							   i,
							   0,
							   map[j].gpu_attribute,
							   (unsigned char **)&data,
							   &len);
			if (!ret) {
				continue;
			}
			/* data[0] contains number of sensors, and each sensor
			   indice follows */
			for (k = 1; k <= data[0]; k++) {
				int idx = data[k];
				gint value;
				IsSensor *sensor;
				gchar *path;

				ret = XNVCTRLQueryTargetAttribute(priv->display,
								  map[j].target,
								  idx,
								  0,
								  map[j].attribute,
								  &value);
				if (!ret) {
					continue;
				}

				path = g_strdup_printf("nvidia/%s%d", map[j].description, idx);
				if (map[j].target == NV_CTRL_TARGET_TYPE_COOLER) {
					/* fan sensors are given as a percentage
					   from 0 to 100 */
					sensor = is_sensor_new(path);
					is_sensor_set_icon(sensor, IS_STOCK_FAN);
					is_sensor_set_units(sensor, "%");
					is_sensor_set_low_value(sensor, 0.0);
					is_sensor_set_high_value(sensor, 100.0);
				} else {
					sensor = is_temperature_sensor_new(path);
					is_sensor_set_icon(sensor, IS_STOCK_GPU);
				}
				/* no decimal places to display */
				is_sensor_set_digits(sensor, 0);
				is_sensor_set_label(sensor, label);
				/* connect to update-value signal */
				g_signal_connect(sensor, "update-value",
						 G_CALLBACK(update_sensor_value),
						 self);
				is_manager_add_sensor(is_application_get_manager(priv->application),
                                                      sensor);
				g_free(path);
			}
			free(data);
		}
		free(label);
	}

out:
	return;
}
Exemplo n.º 7
0
int main(void)
{
    Display *dpy;
    Bool ret;
    int event_base, error_base, major, minor, screens, i;
    char *str;
        
    /*
     * open a connection to the X server indicated by the DISPLAY
     * environment variable
     */
    
    dpy = XOpenDisplay(NULL);
    if (!dpy) {
        fprintf(stderr, "Cannot open display '%s'.\n", XDisplayName(NULL));
        return 1;
    }
    
    /*
     * check if the NV-CONTROL X extension is present on this X server
     */

    ret = XNVCTRLQueryExtension(dpy, &event_base, &error_base);
    if (ret != True) {
        fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n",
                XDisplayName(NULL));
        return 1;
    }

    /*
     * query the major and minor extension version
     */

    ret = XNVCTRLQueryVersion(dpy, &major, &minor);
    if (ret != True) {
        fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n",
                XDisplayName(NULL));
        return 1;
    }

    /*
     * print statistics thus far
     */

    printf("NV-CONTROL X extension present\n");
    printf("  version        : %d.%d\n", major, minor);
    printf("  event base     : %d\n", event_base);
    printf("  error base     : %d\n", error_base);
    
    /*
     * loop over each screen, and determine if each screen is
     * controlled by the NVIDIA X driver (and thus supports the
     * NV-CONTROL X extension); then, query the string attributes on
     * the screen.
     */

    screens = ScreenCount(dpy);
    for (i = 0; i < screens; i++) {
        if (XNVCTRLIsNvScreen(dpy, i)) {
            printf("Screen %d supports the NV-CONTROL X extension\n", i);

            ret = XNVCTRLQueryStringAttribute(dpy, i,
                                              0, /* XXX not curently used */
                                              NV_CTRL_STRING_PRODUCT_NAME,
                                              &str);
            if (ret) {
                printf("  GPU            : %s\n", str);
                XFree(str);
            }
            
            ret = XNVCTRLQueryStringAttribute(dpy, i,
                                              0, /* XXX not curently used */
                                              NV_CTRL_STRING_VBIOS_VERSION,
                                              &str);
            
            if (ret) {
                printf("  VideoBIOS      : %s\n", str);
                XFree(str);
            }

            ret = XNVCTRLQueryStringAttribute(dpy, i,
                                              0, /* XXX not curently used */
                                              NV_CTRL_STRING_NVIDIA_DRIVER_VERSION,
                                              &str);

            if (ret) {
                printf("  Driver version : %s\n", str);
                XFree(str);
            }
        }
    }

    /*
     * print attribute permission and type information.
     */

    printf("Attributes (Integers):\n");
    for (i = 0; i < NV_CTRL_LAST_ATTRIBUTE; i++) {
        const char *name = attr2str(i, attr_int_table);
        if (name) {
            NVCTRLAttributePermissionsRec perms;

            printf("  (%3d) [Perms: ", i);

            memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec));

            XNVCTRLQueryAttributePermissions(dpy, i, &perms);
            print_perms(&perms);
            printf("] [ ");
            printf("%-32s", GetAttrTypeName(perms.type));
            printf("] - %s\n", name);
        }
    }

    printf("Attributes (Strings):\n");
    for (i = 0; i < NV_CTRL_STRING_LAST_ATTRIBUTE; i++) {
        const char *name = attr2str(i, attr_str_table);
        if (name) {
            NVCTRLAttributePermissionsRec perms;

            printf("  (%3d) [Perms: ", i);

            memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec));

            XNVCTRLQueryStringAttributePermissions(dpy, i, &perms);
            print_perms(&perms);
            printf("] [ ");
            printf("%-32s", GetAttrTypeName(perms.type));
            printf("] - %s\n", name);
        }
    }

    printf("Attributes (Binary Data):\n");
    for (i = 0; i < NV_CTRL_BINARY_DATA_LAST_ATTRIBUTE; i++) {
        const char *name = attr2str(i, attr_bin_table);
        if (name) {
            NVCTRLAttributePermissionsRec perms;

            printf("  (%3d) [Perms: ", i);

            memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec));

            XNVCTRLQueryBinaryDataAttributePermissions(dpy, i, &perms);
            print_perms(&perms);
            printf("] [ ");
            printf("%-32s", GetAttrTypeName(perms.type));
            printf("] - %s\n", name);
        }
    }

    printf("Attributes (String Operations):\n");
    for (i = 0; i < NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE; i++) {
        const char *name = attr2str(i, attr_strop_table);
        if (name) {
            NVCTRLAttributePermissionsRec perms;

            printf("  (%3d) [Perms: ", i);

            memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec));

            XNVCTRLQueryStringOperationAttributePermissions(dpy, i, &perms);
            print_perms(&perms);
            printf("] [ ");
            printf("%-32s", GetAttrTypeName(perms.type));
            printf("] - %s\n", name);
        }
    }

    /*
     * close the display connection
     */

    XCloseDisplay(dpy);

    return 0;
}
/* creates the connection to the X server and checks whether the
 * NV-CONTROL extension is loaded */
static GList *nvidia_plugin_init(void) {
    int dummy;
    int event_base, error_base;
    GList *sensors = NULL;

    /* create the connection to the X server */
    if (!(nvidia_sensors_dpy = XOpenDisplay(NULL))) {
        /* no connection to the X server avaible */
        return sensors;
    }

    /* check if the NV-CONTROL extension is available on this X
         * server - if so add the two sensors if they exist */
    if (XNVCTRLQueryExtension(nvidia_sensors_dpy, &event_base, &error_base)) {
        int i, cnt;

        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy,
                        NV_CTRL_TARGET_TYPE_THERMAL_SENSOR,
                        &cnt)) {

            for (i = 0; i < cnt; i++) {
                gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_SENSOR_TEMP);

                sensors_applet_plugin_add_sensor(&sensors,
                                                 THERMAL_SENSOR_TEMP,
                                                 id,
                                                 _("GPU"),
                                                 TEMP_SENSOR,
                                                 TRUE,
                                                 GPU_ICON,
                                                 DEFAULT_GRAPH_COLOR);

                g_free(id);
            }
        }

        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy,
                        NV_CTRL_TARGET_TYPE_COOLER,
                        &cnt)) {

            for (i = 0; i < cnt; i++) {
                gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_COOLER_LEVEL);

                sensors_applet_plugin_add_sensor(&sensors,
                                                 THERMAL_COOLER_LEVEL,
                                                 id,
                                                 _("GPU"),
                                                 FAN_SENSOR,
                                                 TRUE,
                                                 FAN_ICON,
                                                 DEFAULT_GRAPH_COLOR);

                g_free(id);
            }
        }

        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy,
                        NV_CTRL_TARGET_TYPE_GPU,
                        &cnt)) {

            for (i = 0; i < cnt; i++) {
                if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy,
                                NV_CTRL_TARGET_TYPE_GPU,
                                i,
                                       0, NV_CTRL_GPU_CORE_TEMPERATURE, &dummy)) {

                    gchar *id = g_strdup_printf("GPU%d%s", i, GPU_CORE_TEMP);

                    sensors_applet_plugin_add_sensor(&sensors,
                                                     GPU_CORE_TEMP,
                                                     id,
                                                     _("GPU"),
                                                     TEMP_SENSOR,
                                                     TRUE,
                                                     GPU_ICON,
                                                     DEFAULT_GRAPH_COLOR);
                    g_free(id);
                }

                if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy,
                                NV_CTRL_TARGET_TYPE_GPU,
                                i,
                                       0, NV_CTRL_AMBIENT_TEMPERATURE, &dummy)) {
                    gchar *id = g_strdup_printf("GPU%d%s", i, AMBIENT_TEMP);

                    sensors_applet_plugin_add_sensor(&sensors,
                                                     AMBIENT_TEMP,
                                                     id,
                                                     _("Ambient"),
                                                     TEMP_SENSOR,
                                                     FALSE,
                                                     GENERIC_ICON,
                                                     DEFAULT_GRAPH_COLOR);
                    g_free(id);
                }
            }
        }

    }
    return sensors;
}