]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
cgroups: add res_counter_write_u64() API
authorFrederic Weisbecker <fweisbec@gmail.com>
Wed, 5 Oct 2011 00:43:45 +0000 (11:43 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 5 Oct 2011 07:56:05 +0000 (18:56 +1100)
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 <fweisbec@gmail.com>
Acked-by: Paul Menage <paul@paulmenage.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Aditya Kali <adityakali@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Tim Hockin <thockin@hockin.org>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Andrew Morton <akpm@google.com>
include/linux/res_counter.h
kernel/res_counter.c

index c9d625ca659ec387c6b9456c4d03d0bb4af80fb9..1b3fe058fcb15b8cf21629ca2d5de3b31a3a469c 100644 (file)
@@ -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
  */
index 34683efa2cceee37f0a76db7531b8f5fc265a325..0faafccbb80ec60d0d46785965ffcc2d98b0edd2 100644 (file)
@@ -168,12 +168,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))
@@ -183,9 +197,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;
 }