From mboxrd@z Thu Jan 1 00:00:00 1970 From: Frederic Weisbecker Subject: [PATCH 1/8] cgroups: add res_counter_write_u64() API Date: Fri, 13 Jan 2012 19:13:46 +0100 Message-ID: <1326478441-3048-3-git-send-email-fweisbec@gmail.com> References: <1326478441-3048-1-git-send-email-fweisbec@gmail.com> Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=3ioVye9l6bpPStYWkl5doq/2soKH6p8EJ9IeqAUvDmQ=; b=c+pjhbkV90PpVbBlayGUxsWQiwJs/Y4ozhKV/lnLe5B+P6fG4JFvY/XkkSuSWx0k26 GZugf5mlBWn4PNiNDSkIgh6tdONTwy3BuysNLhfi4+L8SOwWTAHR1mBf6ge063qiu1/j ifs47e9VeDozNnFHMONdJO9wFtKciYTak7POA= In-Reply-To: <1326478441-3048-1-git-send-email-fweisbec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: LKML Cc: Frederic Weisbecker , Glauber Costa , Cgroups , "Kirill A. Shutemov" , Daniel J Walsh , "Daniel P. Berrange" , KAMEZAWA Hiroyuki , Max Kellermann , Mandeep Singh Baines , Li Zefan , Johannes Weiner , Aditya Kali , Oleg Nesterov , Kay Sievers , Tim Hockin , Tejun Heo , Andrew Morton Extend the resource counter API with a mirror of res_counter_read_u64() to make it handy to update a resource counter value from a cgroup subsystem u64 value file. Signed-off-by: Frederic Weisbecker Acked-by: Paul Menage Cc: Li Zefan Cc: Johannes Weiner Cc: Aditya Kali Cc: Oleg Nesterov Cc: Kay Sievers Cc: Tim Hockin Cc: Tejun Heo Cc: Kirill A. Shutemov Signed-off-by: Andrew Morton --- include/linux/res_counter.h | 2 ++ kernel/res_counter.c | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index c9d625c..1b3fe05 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h @@ -82,6 +82,8 @@ int res_counter_memparse_write_strategy(const char *buf, int res_counter_write(struct res_counter *counter, int member, const char *buffer, write_strategy_fn write_strategy); +void res_counter_write_u64(struct res_counter *counter, int member, u64 val); + /* * the field descriptors. one for each member of res_counter */ diff --git a/kernel/res_counter.c b/kernel/res_counter.c index 6d269cc..58ae85e 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c @@ -167,12 +167,26 @@ int res_counter_memparse_write_strategy(const char *buf, return 0; } +void res_counter_write_u64(struct res_counter *counter, int member, u64 val) +{ + unsigned long long *target; + unsigned long flags; + + /* + * We need the lock to protect against concurrent add/dec on 32 bits. + * No need to ifdef it's seldom used. + */ + spin_lock_irqsave(&counter->lock, flags); + target = res_counter_member(counter, member); + *target = val; + spin_unlock_irqrestore(&counter->lock, flags); +} + int res_counter_write(struct res_counter *counter, int member, const char *buf, write_strategy_fn write_strategy) { char *end; - unsigned long flags; - unsigned long long tmp, *val; + unsigned long long tmp; if (write_strategy) { if (write_strategy(buf, &tmp)) @@ -182,9 +196,8 @@ int res_counter_write(struct res_counter *counter, int member, if (*end != '\0') return -EINVAL; } - spin_lock_irqsave(&counter->lock, flags); - val = res_counter_member(counter, member); - *val = tmp; - spin_unlock_irqrestore(&counter->lock, flags); + + res_counter_write_u64(counter, member, tmp); + return 0; } -- 1.7.5.4