From: "Radim Krčmář" <rkrcmar@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
"Raghavendra K T" <raghavendra.kt@linux.vnet.ibm.com>,
"Andrew Jones" <drjones@redhat.com>,
"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>,
"H. Peter Anvin" <hpa@linux.intel.com>,
"Ingo Molnar" <mingo@kernel.org>
Subject: [PATCH 3/7] static_key: keep deferred enabled counter debt
Date: Thu, 17 Oct 2013 12:10:26 +0200 [thread overview]
Message-ID: <1382004631-25895-4-git-send-email-rkrcmar@redhat.com> (raw)
In-Reply-To: <1382004631-25895-1-git-send-email-rkrcmar@redhat.com>
When '.enabled.counter == 1', static_key_slow_dec_deferred() gets
silently dropped if the decrease is already pending.
We print a warning if this happens and because .enabled.counter cannot
go below 1 before the decrease has finished, the number of ignored
static_key_slow_dec_deferred() is kept and we skip an equal amount of
static_key_slow_inc_deferred().
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
atomic_dec_if_positive() is weird ...
include/linux/jump_label_ratelimit.h | 1 +
kernel/jump_label.c | 17 +++++++++++------
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/linux/jump_label_ratelimit.h b/include/linux/jump_label_ratelimit.h
index e2fa2e7..e3a7a83 100644
--- a/include/linux/jump_label_ratelimit.h
+++ b/include/linux/jump_label_ratelimit.h
@@ -9,6 +9,7 @@ struct static_key_deferred {
struct static_key key;
unsigned long timeout;
struct delayed_work work;
+ atomic_t enabled_debt;
};
#endif
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index ff67257..30aa3b0 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -75,13 +75,15 @@ EXPORT_SYMBOL_GPL(static_key_slow_inc);
void static_key_slow_inc_deferred(struct static_key_deferred *key)
{
+ if (atomic_dec_if_positive(&key->enabled_debt) >= 0)
+ return;
if (!cancel_delayed_work(&key->work))
static_key_slow_inc(&key->key);
}
EXPORT_SYMBOL_GPL(static_key_slow_inc_deferred);
static void __static_key_slow_dec(struct static_key *key,
- unsigned long rate_limit, struct delayed_work *work)
+ struct static_key_deferred *dkey)
{
if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
WARN(atomic_read(&key->enabled) < 0,
@@ -89,9 +91,12 @@ static void __static_key_slow_dec(struct static_key *key,
return;
}
- if (rate_limit) {
+ if (dkey && dkey->timeout) {
atomic_inc(&key->enabled);
- schedule_delayed_work(work, rate_limit);
+ if (!schedule_delayed_work(&dkey->work, dkey->timeout)) {
+ atomic_inc(&dkey->enabled_debt);
+ WARN(1, "jump label: negative deferred count!\n");
+ }
} else {
if (!jump_label_get_branch_default(key))
jump_label_update(key, JUMP_LABEL_DISABLE);
@@ -105,18 +110,18 @@ static void jump_label_update_timeout(struct work_struct *work)
{
struct static_key_deferred *key =
container_of(work, struct static_key_deferred, work.work);
- __static_key_slow_dec(&key->key, 0, NULL);
+ __static_key_slow_dec(&key->key, NULL);
}
void static_key_slow_dec(struct static_key *key)
{
- __static_key_slow_dec(key, 0, NULL);
+ __static_key_slow_dec(key, NULL);
}
EXPORT_SYMBOL_GPL(static_key_slow_dec);
void static_key_slow_dec_deferred(struct static_key_deferred *key)
{
- __static_key_slow_dec(&key->key, key->timeout, &key->work);
+ __static_key_slow_dec(&key->key, key);
}
EXPORT_SYMBOL_GPL(static_key_slow_dec_deferred);
--
1.8.3.1
next prev parent reply other threads:[~2013-10-17 10:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-17 10:10 [PATCH 0/7] static_key: fix timer bugs & change api (a bit) Radim Krčmář
2013-10-17 10:10 ` [PATCH 1/7] static_key: flush rate limit timer on rmmod Radim Krčmář
2013-10-17 10:35 ` Paolo Bonzini
2013-10-18 7:24 ` Radim Krčmář
2013-10-17 10:10 ` [PATCH 2/7] static_key: add static_key_slow_inc_deferred() Radim Krčmář
2013-10-17 10:10 ` Radim Krčmář [this message]
2013-10-17 10:10 ` [PATCH 4/7] static_key: use static_key_slow_inc_deferred() Radim Krčmář
2013-10-17 10:39 ` Paolo Bonzini
2013-10-18 7:29 ` Radim Krčmář
2013-10-17 10:10 ` [PATCH 5/7] jump_label: relax branch hinting restrictions Radim Krčmář
2013-10-17 17:35 ` Steven Rostedt
2013-10-18 7:30 ` Radim Krčmář
2013-10-17 10:10 ` [PATCH 7/7] init: execute jump_label_init() earlier Radim Krčmář
2013-10-17 10:43 ` [PATCH 0/7] static_key: fix timer bugs & change api (a bit) Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382004631-25895-4-git-send-email-rkrcmar@redhat.com \
--to=rkrcmar@redhat.com \
--cc=drjones@redhat.com \
--cc=hpa@linux.intel.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=raghavendra.kt@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®