]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - kernel/jump_label.c
ftrace: Create ftrace_hash_empty() helper routine
[karo-tx-linux.git] / kernel / jump_label.c
index a8ce45097f3d21354c7ed8c18e5fcbc4e11792d1..30c3c770813275ed7c9f9a47ca47275a00fc5fbf 100644 (file)
@@ -66,20 +66,52 @@ void jump_label_inc(struct jump_label_key *key)
                return;
 
        jump_label_lock();
-       if (atomic_add_return(1, &key->enabled) == 1)
+       if (atomic_read(&key->enabled) == 0)
                jump_label_update(key, JUMP_LABEL_ENABLE);
+       atomic_inc(&key->enabled);
        jump_label_unlock();
 }
 
-void jump_label_dec(struct jump_label_key *key)
+static void __jump_label_dec(struct jump_label_key *key,
+               unsigned long rate_limit, struct delayed_work *work)
 {
        if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex))
                return;
 
-       jump_label_update(key, JUMP_LABEL_DISABLE);
+       if (rate_limit) {
+               atomic_inc(&key->enabled);
+               schedule_delayed_work(work, rate_limit);
+       } else
+               jump_label_update(key, JUMP_LABEL_DISABLE);
+
        jump_label_unlock();
 }
 
+static void jump_label_update_timeout(struct work_struct *work)
+{
+       struct jump_label_key_deferred *key =
+               container_of(work, struct jump_label_key_deferred, work.work);
+       __jump_label_dec(&key->key, 0, NULL);
+}
+
+void jump_label_dec(struct jump_label_key *key)
+{
+       __jump_label_dec(key, 0, NULL);
+}
+
+void jump_label_dec_deferred(struct jump_label_key_deferred *key)
+{
+       __jump_label_dec(&key->key, key->timeout, &key->work);
+}
+
+
+void jump_label_rate_limit(struct jump_label_key_deferred *key,
+               unsigned long rl)
+{
+       key->timeout = rl;
+       INIT_DELAYED_WORK(&key->work, jump_label_update_timeout);
+}
+
 static int addr_conflict(struct jump_entry *entry, void *start, void *end)
 {
        if (entry->code <= (unsigned long)end &&
@@ -104,6 +136,18 @@ static int __jump_label_text_reserved(struct jump_entry *iter_start,
        return 0;
 }
 
+/* 
+ * Update code which is definitely not currently executing.
+ * Architectures which need heavyweight synchronization to modify
+ * running code can override this to make the non-live update case
+ * cheaper.
+ */
+void __weak __init_or_module arch_jump_label_transform_static(struct jump_entry *entry,
+                                           enum jump_label_type type)
+{
+       arch_jump_label_transform(entry, type); 
+}
+
 static void __jump_label_update(struct jump_label_key *key,
                                struct jump_entry *entry,
                                struct jump_entry *stop, int enable)
@@ -121,14 +165,7 @@ static void __jump_label_update(struct jump_label_key *key,
        }
 }
 
-/*
- * Not all archs need this.
- */
-void __weak arch_jump_label_text_poke_early(jump_label_t addr)
-{
-}
-
-static __init int jump_label_init(void)
+void __init jump_label_init(void)
 {
        struct jump_entry *iter_start = __start___jump_table;
        struct jump_entry *iter_stop = __stop___jump_table;
@@ -139,22 +176,22 @@ static __init int jump_label_init(void)
        jump_label_sort_entries(iter_start, iter_stop);
 
        for (iter = iter_start; iter < iter_stop; iter++) {
-               arch_jump_label_text_poke_early(iter->code);
-               if (iter->key == (jump_label_t)(unsigned long)key)
+               struct jump_label_key *iterk;
+
+               iterk = (struct jump_label_key *)(unsigned long)iter->key;
+               arch_jump_label_transform_static(iter, jump_label_enabled(iterk) ?
+                                                JUMP_LABEL_ENABLE : JUMP_LABEL_DISABLE);
+               if (iterk == key)
                        continue;
 
-               key = (struct jump_label_key *)(unsigned long)iter->key;
-               atomic_set(&key->enabled, 0);
+               key = iterk;
                key->entries = iter;
 #ifdef CONFIG_MODULES
                key->next = NULL;
 #endif
        }
        jump_label_unlock();
-
-       return 0;
 }
-early_initcall(jump_label_init);
 
 #ifdef CONFIG_MODULES
 
@@ -211,8 +248,13 @@ void jump_label_apply_nops(struct module *mod)
        if (iter_start == iter_stop)
                return;
 
-       for (iter = iter_start; iter < iter_stop; iter++)
-               arch_jump_label_text_poke_early(iter->code);
+       for (iter = iter_start; iter < iter_stop; iter++) {
+               struct jump_label_key *iterk;
+
+               iterk = (struct jump_label_key *)(unsigned long)iter->key;
+               arch_jump_label_transform_static(iter, jump_label_enabled(iterk) ?
+                               JUMP_LABEL_ENABLE : JUMP_LABEL_DISABLE);
+       }
 }
 
 static int jump_label_add_module(struct module *mod)
@@ -252,8 +294,7 @@ static int jump_label_add_module(struct module *mod)
                key->next = jlm;
 
                if (jump_label_enabled(key))
-                       __jump_label_update(key, iter, iter_stop,
-                                           JUMP_LABEL_ENABLE);
+                       __jump_label_update(key, iter, iter_stop, JUMP_LABEL_ENABLE);
        }
 
        return 0;