vhost: fix missing virtqueue status check in async path
[dpdk.git] / lib / librte_power / power_common.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4
5 #include <limits.h>
6 #include <stdio.h>
7 #include <string.h>
8
9 #include "power_common.h"
10
11 #define POWER_SYSFILE_SCALING_DRIVER   \
12                 "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver"
13
14 int
15 cpufreq_check_scaling_driver(const char *driver_name)
16 {
17         unsigned int lcore_id = 0; /* always check core 0 */
18         char fullpath[PATH_MAX];
19         char readbuf[PATH_MAX];
20         char *s;
21         FILE *f;
22
23         /*
24          * Check if scaling driver matches what we expect.
25          */
26         snprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SCALING_DRIVER,
27                         lcore_id);
28         f = fopen(fullpath, "r");
29
30         /* if there's no driver at all, bail out */
31         if (f == NULL)
32                 return 0;
33
34         s = fgets(readbuf, sizeof(readbuf), f);
35         /* don't need it any more */
36         fclose(f);
37
38         /* if we can't read it, consider unsupported */
39         if (s == NULL)
40                 return 0;
41
42         /* does the driver name match? */
43         if (strncmp(readbuf, driver_name, sizeof(readbuf)) != 0)
44                 return 0;
45
46         /*
47          * We might have a situation where the driver is supported, but we don't
48          * have permissions to do frequency scaling. This error should not be
49          * handled here, so consider the system to support scaling for now.
50          */
51         return 1;
52 }