*
**************************************************************************/
-#if HAVE_GALLIUM_EXTRA_HUD
+#ifdef HAVE_GALLIUM_EXTRA_HUD
/* Purpose:
* Reading /sys/devices/system/cpu/cpu?/cpufreq/scaling_???_freq
#include "hud/hud_private.h"
#include "util/list.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
+#include "os/os_thread.h"
#include "util/u_memory.h"
#include <stdio.h>
#include <unistd.h>
static int gcpufreq_count = 0;
static struct list_head gcpufreq_list;
+static mtx_t gcpufreq_mutex = _MTX_INITIALIZER_NP;
static struct cpufreq_info *
find_cfi_by_index(int cpu_index, int mode)
}
static void
-query_cfi_load(struct hud_graph *gr)
+query_cfi_load(struct hud_graph *gr, struct pipe_context *pipe)
{
struct cpufreq_info *cfi = gr->query_data;
break;
case CPUFREQ_MAXIMUM:
snprintf(gr->name, sizeof(gr->name), "%s-Max", cfi->name);
+ break;
default:
return;
}
int cpu_index;
/* Return the number of CPU metrics we support. */
- if (gcpufreq_count)
+ mtx_lock(&gcpufreq_mutex);
+ if (gcpufreq_count) {
+ mtx_unlock(&gcpufreq_mutex);
return gcpufreq_count;
+ }
/* Scan /sys/devices.../cpu, for every object type we support, create
* and persist an object to represent its different metrics.
*/
list_inithead(&gcpufreq_list);
DIR *dir = opendir("/sys/devices/system/cpu");
- if (!dir)
+ if (!dir) {
+ mtx_unlock(&gcpufreq_mutex);
return 0;
+ }
while ((dp = readdir(dir)) != NULL) {
snprintf(fn, sizeof(fn), "%s/cpufreq/scaling_max_freq", basename);
add_object(dp->d_name, fn, CPUFREQ_MAXIMUM, cpu_index);
}
+ closedir(dir);
if (displayhelp) {
list_for_each_entry(struct cpufreq_info, cfi, &gcpufreq_list, list) {
}
}
+ mtx_unlock(&gcpufreq_mutex);
return gcpufreq_count;
}