From patchwork Fri Feb 22 05:56:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 2174631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 721D73FCFC for ; Fri, 22 Feb 2013 05:59:39 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U8ld8-00037D-Ey; Fri, 22 Feb 2013 05:57:10 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U8lcu-00034d-SW for linux-arm-kernel@lists.infradead.org; Fri, 22 Feb 2013 05:57:03 +0000 Received: by mail-pb0-f46.google.com with SMTP id uo15so209872pbc.5 for ; Thu, 21 Feb 2013 21:56:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=Z3hZ3aXxH7eUzwOtCYBjnZqEBXYHRj8MOE8pmVdsJms=; b=XZqPdVLchSys9dHHEejuLV4MZZe/p6oEOmAMoQs5bnxdUSPsw9LQn3MlutyCfhRo1N LgJqxRbh9MmAI32cWJttriU92XvLoIu7CeYBYlN0OzL+mJHasa8bCwwo/mLe8aeJ9n8Z jFjM3c09KEUyxdmrMCIMXmc/kGFG5ZUo1ytQN98/QJ+O2Mc9dbve6ObnRa8ATIWffxUw anN4AFkK1WI58igEq9x9VDMVVsDrM3AA68sG046TANjfKroMrKdTW36Jja3EbJA3Klcj tWZZwzYCc0F0kiAEMkWwsidYwWCQxTnKlE2hO1+GWjMNClLPwfrnLreWrXB+7VNHu7E+ Da1g== X-Received: by 10.68.236.130 with SMTP id uu2mr1186639pbc.152.1361512614433; Thu, 21 Feb 2013 21:56:54 -0800 (PST) Received: from localhost (c-24-19-7-36.hsd1.wa.comcast.net. [24.19.7.36]) by mx.google.com with ESMTPS id y9sm1758006paw.1.2013.02.21.21.56.52 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 21 Feb 2013 21:56:53 -0800 (PST) From: Kevin Hilman To: Frederic Weisbecker Subject: [PATCH 2/2] cpustat: convert to atomic operations Date: Thu, 21 Feb 2013 21:56:44 -0800 Message-Id: <1361512604-2720-3-git-send-email-khilman@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361512604-2720-1-git-send-email-khilman@linaro.org> References: <1361512604-2720-1-git-send-email-khilman@linaro.org> X-Gm-Message-State: ALoCoQneXCYLasuje3Hkg/ND0Y4q2bXpV8N4E0RuyOweueqAMOnTp/LRz0BJpLo4ttvmqi3BTAqr X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130222_005657_048011_A09A3C76 X-CRM114-Status: UNSURE ( 9.82 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.46 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linaro-kernel@lists.linaro.org, Peter Zijlstra , linux-kernel@vger.kernel.org, Steven Rostedt , Russell King , Thomas Gleixner , Ingo Molnar , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For non 64-bit platforms, convert cpustat fields to atomic64 type so reads and udpates of cpustats are atomic on those platforms as well. For 64-bit platforms, the cpustat field is left as u64 because on 64-bit, using atomic64_add will have the additional overhead of a lock. We could also have used atomic64_set(atomic64_read() + delta), but on 32-bit platforms using the generic 64-bit ops (lib/atomic64.c), that results in taking a lock twice. Signed-off-by: Kevin Hilman --- include/linux/kernel_stat.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index df8ad75..a433f87 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -32,7 +32,11 @@ enum cpu_usage_stat { }; struct kernel_cpustat { +#ifdef CONFIG_64BIT u64 _cpustat[NR_STATS]; +#else + atomic64_t _cpustat[NR_STATS]; +#endif }; struct kernel_stat { @@ -51,11 +55,23 @@ DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat); #define kcpustat_this_cpu (&__get_cpu_var(kernel_cpustat)) #define kstat_cpu(cpu) per_cpu(kstat, cpu) #define kcpustat_cpu(cpu) per_cpu(kernel_cpustat, cpu) +#ifdef CONFIG_64BIT #define kcpustat_cpu_get(cpu, i) (kcpustat_cpu(cpu)._cpustat[i]) #define kcpustat_cpu_set(cpu, i, val) (kcpustat_cpu(cpu)._cpustat[i] = (val)) #define kcpustat_cpu_add(cpu, i, val) (kcpustat_cpu(cpu)._cpustat[i] += (val)) #define kcpustat_this_cpu_set(i, val) (kcpustat_this_cpu->_cpustat[i] = (val)) #define kcpustat_this_cpu_add(i, val) (kcpustat_this_cpu->_cpustat[i] += (val)) +#else +#define kcpustat_cpu_get(cpu, i) atomic64_read(&kcpustat_cpu(cpu)._cpustat[i]) +#define kcpustat_cpu_set(cpu, i, val) \ + atomic64_set(val, &kcpustat_cpu(cpu)._cpustat[i]) +#define kcpustat_cpu_add(cpu, i, val) \ + atomic64_add(val, &kcpustat_cpu(cpu)._cpustat[i]) +#define kcpustat_this_cpu_set(i, val) \ + atomic64_set(val, &kcpustat_this_cpu->_cpustat[i]) +#define kcpustat_this_cpu_add(i, val) \ + atomic64_add(val, &kcpustat_this_cpu->_cpustat[i]) +#endif extern unsigned long long nr_context_switches(void);