1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
9 #include "power_common.h"
11 #define POWER_SYSFILE_SCALING_DRIVER \
12 "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver"
15 cpufreq_check_scaling_driver(const char *driver_name)
17 unsigned int lcore_id = 0; /* always check core 0 */
18 char fullpath[PATH_MAX];
19 char readbuf[PATH_MAX];
25 * Check if scaling driver matches what we expect.
27 snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SCALING_DRIVER,
29 f = fopen(fullpath, "r");
31 /* if there's no driver at all, bail out */
35 s = fgets(readbuf, sizeof(readbuf), f);
36 /* don't need it any more */
39 /* if we can't read it, consider unsupported */
43 /* when read from sysfs, driver name has an extra newline at the end */
44 end_idx = strnlen(readbuf, sizeof(readbuf));
45 if (end_idx > 0 && readbuf[end_idx - 1] == '\n') {
47 readbuf[end_idx] = '\0';
50 /* does the driver name match? */
51 if (strncmp(readbuf, driver_name, sizeof(readbuf)) != 0)
55 * We might have a situation where the driver is supported, but we don't
56 * have permissions to do frequency scaling. This error should not be
57 * handled here, so consider the system to support scaling for now.