示例#1
0
TpSensorDriver::TpSensorDriver(std::string path)
: SensorDriver(path)
{
	std::ifstream f(path_);
	try {
		f.exceptions(f.failbit | f.badbit);
		int tmp;
		unsigned int count = 0;

		string skip;
		skip.resize(skip_prefix_.size());

		f.exceptions(f.badbit);
		f.getline(&*skip.begin(), skip_prefix_.size()+1);
		f.clear(f.rdstate() & ~f.failbit);

		if (skip == skip_prefix_)
			skip_bytes_ = f.tellg();
		else
			throw SystemError(path_ + ": Unknown file format.");

		while (!(f.eof() || f.fail())) {
			f >> tmp;
			if (!f.fail())
				++count;
		}
		set_num_temps(count);
	} catch (std::ios_base::failure &e) {
		string msg = std::strerror(errno);
		throw SystemError(MSG_SENSOR_INIT(path_) + msg);
	}
}
示例#2
0
AtasmartSensorDriver::AtasmartSensorDriver(string device_path)
: SensorDriver(device_path)
{
	if (sk_disk_open(device_path.c_str(), &disk_) < 0) {
		string msg = std::strerror(errno);
		throw SystemError("sk_disk_open(" + device_path + "): " + msg);
	}
	set_num_temps(1);
}
示例#3
0
NvmlSensorDriver::NvmlSensorDriver(string bus_id)
    : dl_nvmlInit_v2(nullptr),
      dl_nvmlDeviceGetHandleByPciBusId_v2(nullptr),
      dl_nvmlDeviceGetName(nullptr),
      dl_nvmlDeviceGetTemperature(nullptr),
      dl_nvmlShutdown(nullptr)
{
    if (!(nvml_so_handle_ = dlopen("libnvidia-ml.so", RTLD_LAZY))) {
        string msg = strerror(errno);
        fail(TF_ERR) << SystemError("Failed to load NVML driver: " + msg) << flush;
    }

    /* Apparently GCC doesn't want to cast to function pointers, so we have to do
     * this kind of weird stuff.
     * See http://stackoverflow.com/questions/1096341/function-pointers-casting-in-c
     */
    *reinterpret_cast<void **>(&dl_nvmlInit_v2) = dlsym(nvml_so_handle_, "nvmlInit_v2");
    *reinterpret_cast<void **>(&dl_nvmlDeviceGetHandleByPciBusId_v2) = dlsym(
                nvml_so_handle_, "nvmlDeviceGetHandleByPciBusId_v2");
    *reinterpret_cast<void **>(&dl_nvmlDeviceGetName) = dlsym(nvml_so_handle_, "nvmlDeviceGetName");
    *reinterpret_cast<void **>(&dl_nvmlDeviceGetTemperature) = dlsym(nvml_so_handle_, "nvmlDeviceGetTemperature");
    *reinterpret_cast<void **>(&dl_nvmlShutdown) = dlsym(nvml_so_handle_, "nvmlShutdown");

    if (!(dl_nvmlDeviceGetHandleByPciBusId_v2 && dl_nvmlDeviceGetName &&
            dl_nvmlDeviceGetTemperature && dl_nvmlInit_v2 && dl_nvmlShutdown))
        fail(TF_ERR) << SystemError("Incompatible NVML driver.") << flush;

    nvmlReturn_t ret;
    string name, brand;
    name.resize(256);
    brand.resize(256);

    if ((ret = dl_nvmlInit_v2()))
        fail(TF_ERR)
                << SystemError("Failed to initialize NVML driver. Error code (cf. nvml.h): " + std::to_string(ret))
                << flush;
    if ((ret = dl_nvmlDeviceGetHandleByPciBusId_v2(bus_id.c_str(), &device_)))
        fail(TF_ERR)
                << SystemError("Failed to open PCI device " + bus_id + ". Error code (cf. nvml.h): " + std::to_string(ret))
                << flush;
    dl_nvmlDeviceGetName(device_, &*name.begin(), 255);
    log(TF_DBG, TF_DBG) << "Initialized NVML sensor on " << name << " at PCI " << bus_id << "." << flush;
    set_num_temps(1);
}
示例#4
0
TpSensorDriver::TpSensorDriver(std::string path)
    : SensorDriver(path)
{
    try {
        std::ifstream f(path_);
        f.exceptions(f.failbit | f.badbit);
        int tmp;
        unsigned int count = 0;

        while (!f.eof()) {
            f >> tmp;
            ++count;
        }
        set_num_temps(count);
    } catch (std::exception &e) {
        string msg = std::strerror(errno);
        fail(TF_ERR) << path_ + ": " << SystemError(string(e.what()) + ": " + msg) << flush;
    }
}
示例#5
0
HwmonSensorDriver::HwmonSensorDriver(std::string path)
: SensorDriver(path)
{ set_num_temps(1); }