iris: Don't enable smooth points when point sprites are enabled
[mesa.git] / src / gallium / auxiliary / hud / hud_cpufreq.c
index bfc748b47f9e8256b1120416e0c613a03bea818b..d3cf2019c38e632bf2b407eee180c7b37c302ed0 100644 (file)
@@ -26,7 +26,7 @@
  *
  **************************************************************************/
 
-#if HAVE_GALLIUM_EXTRA_HUD
+#ifdef HAVE_GALLIUM_EXTRA_HUD
 
 /* Purpose:
  * Reading /sys/devices/system/cpu/cpu?/cpufreq/scaling_???_freq
@@ -35,7 +35,8 @@
 
 #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>
@@ -61,6 +62,7 @@ struct cpufreq_info
 
 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)
@@ -89,7 +91,7 @@ get_file_value(const char *fn, uint64_t *KHz)
 }
 
 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;
 
@@ -147,6 +149,7 @@ hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index,
       break;
    case CPUFREQ_MAXIMUM:
       snprintf(gr->name, sizeof(gr->name), "%s-Max", cfi->name);
+      break;
    default:
       return;
    }
@@ -186,21 +189,30 @@ hud_get_num_cpufreq(bool displayhelp)
    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) {
 
-      /* Avoid 'lo' and '..' and '.' */
-      if (strlen(dp->d_name) <= 2)
+      size_t d_name_len = strlen(dp->d_name);
+
+      /* Avoid 'lo' and '..' and '.', and avoid overlong names that
+       * would  result in a buffer overflow in add_object.
+       */
+      if (d_name_len <= 2 || d_name_len > 15)
          continue;
 
       if (sscanf(dp->d_name, "cpu%d\n", &cpu_index) != 1)
@@ -225,6 +237,7 @@ hud_get_num_cpufreq(bool displayhelp)
       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) {
@@ -238,6 +251,7 @@ hud_get_num_cpufreq(bool displayhelp)
       }
    }
 
+   mtx_unlock(&gcpufreq_mutex);
    return gcpufreq_count;
 }