jump_label defaults (was Re: [patch 00/17] CFS Bandwidth Controlv7.1)

From: Peter Zijlstra
Date: Thu Jul 07 2011 - 16:36:45 EST


[resend because I somehow managed to wreck the lkml address]

On Thu, 2011-07-07 at 14:15 -0400, Jason Baron wrote:
> We don't have to wait until jump_label_init() to make it take effect.
>
> We could introduce something like: static_branch_default_false(&foo),
> and static_branch_default_true(&foo), which are set at compile time. I
> was waiting for a real world example before introducing it, but if this
> would solve your issue, we can look at it.

Hrm,. I can't seem to make that work, damn CPP for not being recursive.

The thing in question is the below patch, I'd need something like:

sed -ie 's/1)/true)' -e 's/0)/false)/' kernel/sched_features.h

#define SCHED_FEAT(name, enabled) \
#define static_branch_##name static_branch_default_##enabled
#include "sched_features.h"
#undef SCHED_FEAT

so that I can then do:

#define sched_feat(x) \
static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))

Otherwise there's no way to get the default thing related to x.

Also, it still needs an initializer for jump_label_key to get in the
correct state.

---
Subject: sched: Use jump_labels for sched_feat
From: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Date: Wed Jul 06 14:20:14 CEST 2011

static_branch() is disabled by default, but more sched_feat are enabled
by default, so invert the logic. Fixup the few stragglers on
late_initcall().

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-10afjk8n3eu30jytrhdpaluc@xxxxxxxxxxxxxx
---
kernel/sched.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -71,6 +71,7 @@
#include <linux/ctype.h>
#include <linux/ftrace.h>
#include <linux/slab.h>
+#include <linux/jump_label.h>

#include <asm/tlb.h>
#include <asm/irq_regs.h>
@@ -691,6 +692,7 @@ int runqueue_is_locked(int cpu)

enum {
#include "sched_features.h"
+ __SCHED_FEAT_NR
};

#undef SCHED_FEAT
@@ -710,16 +712,17 @@ const_debug unsigned int sysctl_sched_fe

static __read_mostly char *sched_feat_names[] = {
#include "sched_features.h"
- NULL
};

#undef SCHED_FEAT

+static struct jump_label_key sched_feat_keys[__SCHED_FEAT_NR];
+
static int sched_feat_show(struct seq_file *m, void *v)
{
int i;

- for (i = 0; sched_feat_names[i]; i++) {
+ for (i = 0; i < __SCHED_FEAT_NR; i++) {
if (!(sysctl_sched_features & (1UL << i)))
seq_puts(m, "NO_");
seq_printf(m, "%s ", sched_feat_names[i]);
@@ -752,17 +755,22 @@ sched_feat_write(struct file *filp, cons
cmp += 3;
}

- for (i = 0; sched_feat_names[i]; i++) {
+ for (i = 0; i < __SCHED_FEAT_NR; i++) {
if (strcmp(cmp, sched_feat_names[i]) == 0) {
- if (neg)
+ if (neg) {
sysctl_sched_features &= ~(1UL << i);
- else
+ if (!jump_label_enabled(&sched_feat_keys[i]))
+ jump_label_inc(&sched_feat_keys[i]);
+ } else {
sysctl_sched_features |= (1UL << i);
+ if (jump_label_enabled(&sched_feat_keys[i]))
+ jump_label_dec(&sched_feat_keys[i]);
+ }
break;
}
}

- if (!sched_feat_names[i])
+ if (i == __SCHED_FEAT_NR)
return -EINVAL;

*ppos += cnt;
@@ -785,6 +793,13 @@ static const struct file_operations sche

static __init int sched_init_debug(void)
{
+ int i;
+
+ for (i = 0; i < __SCHED_FEAT_NR; i++) {
+ if (!(sysctl_sched_features & (1UL << i)))
+ jump_label_inc(&sched_feat_keys[i]);
+ }
+
debugfs_create_file("sched_features", 0644, NULL, NULL,
&sched_feat_fops);

@@ -792,10 +807,14 @@ static __init int sched_init_debug(void)
}
late_initcall(sched_init_debug);

-#endif
+#define sched_feat(x) (!static_branch(&sched_feat_keys[__SCHED_FEAT_##x]))
+
+#else /* CONFIG_SCHED_DEBUG */

#define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))

+#endif /* CONFIG_SCHED_DEBUG */
+
/*
* Number of tasks to iterate in a single balance run.
* Limited because this is done with IRQs disabled.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/