|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright 2021-2023 Software Radio Systems Limited |
| 4 | + * |
| 5 | + * By using this file, you agree to the terms and conditions set |
| 6 | + * forth in the LICENSE file which can be found at the top level of |
| 7 | + * the distribution. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +#include "srsran/srslog/srslog.h" |
| 12 | +#include <fstream> |
| 13 | +#include <string> |
| 14 | +#include <thread> |
| 15 | + |
| 16 | +#pragma once |
| 17 | + |
| 18 | +/// \brief Check whether the CPU scaling governor is set to performance. |
| 19 | +/// |
| 20 | +/// \param[in] logger to print warnings. |
| 21 | +/// \return True if we were able to read the sysfs scaling governor information. |
| 22 | +inline bool check_cpu_governor(srslog::basic_logger& logger) |
| 23 | +{ |
| 24 | + unsigned int n_cpus = std::thread::hardware_concurrency(); |
| 25 | + std::string filename_base = "/sys/devices/system/cpu/cpu"; |
| 26 | + for (unsigned int i = 0; i < n_cpus; ++i) { |
| 27 | + std::string filename = filename_base + std::to_string(i) + "/cpufreq/scaling_governor"; |
| 28 | + std::ifstream input(filename); |
| 29 | + if (input.fail()) { |
| 30 | + logger.warning("Could not check scaling governor. filename={} error=\"{}\"", filename, strerror(errno)); |
| 31 | + return false; |
| 32 | + } |
| 33 | + std::string gov; |
| 34 | + std::getline(input, gov); |
| 35 | + if (input.fail()) { |
| 36 | + logger.warning("Could not check scaling governor. filename={} error=\"{}\"", filename, strerror(errno)); |
| 37 | + return false; |
| 38 | + } |
| 39 | + if (gov == "performance") { |
| 40 | + logger.debug("CPU{} scaling governor is set to performance", i); |
| 41 | + } else { |
| 42 | + logger.warning( |
| 43 | + "CPU{} scaling governor is not set to performance, which may hinder performance. You can set it to " |
| 44 | + "performance using the " |
| 45 | + "\"srsran_performance\" script", |
| 46 | + i); |
| 47 | + } |
| 48 | + } |
| 49 | + return true; |
| 50 | +} |
| 51 | + |
| 52 | +/// \brief Check whether the DRM KMS polling is set. |
| 53 | +/// |
| 54 | +/// \param[in] logger to print warnings. |
| 55 | +/// \return True if we were able to read the sysfs for the DRM KMS polling information. |
| 56 | +inline bool check_drm_kms_polling(srslog::basic_logger& logger) |
| 57 | +{ |
| 58 | + std::string filename = "/sys/module/drm_kms_helper/parameters/poll"; |
| 59 | + std::ifstream input(filename); |
| 60 | + if (input.fail()) { |
| 61 | + logger.warning("Could not check DRM KMS polling. filename={} error=\"{}\"", filename, strerror(errno)); |
| 62 | + return false; |
| 63 | + } |
| 64 | + std::string polling; |
| 65 | + std::getline(input, polling); |
| 66 | + if (input.fail()) { |
| 67 | + logger.warning("Could not check DRM KMS polling. filename={} error=\"{}\"", filename, strerror(errno)); |
| 68 | + return false; |
| 69 | + } |
| 70 | + if (polling == "N") { |
| 71 | + logger.debug("DRM KMS polling is disabled"); |
| 72 | + } else { |
| 73 | + logger.warning("DRM KMS polling is enabled, which may hinder performance. You can disable it using the " |
| 74 | + "\"srsran_performance\" script"); |
| 75 | + } |
| 76 | + return true; |
| 77 | +} |
0 commit comments