x86/resctrl: Add cpumask_any_housekeeping() for limbo/overflow
[linux-2.6-microblaze.git] / arch / x86 / kernel / cpu / resctrl / internal.h
index b7b9d92..81f5de9 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/kernfs.h>
 #include <linux/fs_context.h>
 #include <linux/jump_label.h>
+#include <linux/tick.h>
 
 #include <asm/resctrl.h>
 
 /* Max event bits supported */
 #define MAX_EVT_CONFIG_BITS            GENMASK(6, 0)
 
+/**
+ * cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that
+ *                             aren't marked nohz_full
+ * @mask:      The mask to pick a CPU from.
+ *
+ * Returns a CPU in @mask. If there are housekeeping CPUs that don't use
+ * nohz_full, these are preferred.
+ */
+static inline unsigned int cpumask_any_housekeeping(const struct cpumask *mask)
+{
+       unsigned int cpu, hk_cpu;
+
+       cpu = cpumask_any(mask);
+       if (!tick_nohz_full_cpu(cpu))
+               return cpu;
+
+       hk_cpu = cpumask_nth_andnot(0, mask, tick_nohz_full_mask);
+       if (hk_cpu < nr_cpu_ids)
+               cpu = hk_cpu;
+
+       return cpu;
+}
+
 struct rdt_fs_context {
        struct kernfs_fs_context        kfc;
        bool                            enable_cdpl2;