From patchwork Fri Dec 2 16:30:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Pisati X-Patchwork-Id: 128919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id ABCEE100C62 for ; Sat, 3 Dec 2011 03:31:13 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RWW0v-0007oq-8N; Fri, 02 Dec 2011 16:31:05 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RWW0o-0007ib-T4 for kernel-team@lists.ubuntu.com; Fri, 02 Dec 2011 16:30:58 +0000 Received: from 2-230-238-136.ip204.fastwebnet.it ([2.230.238.136] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1RWW0o-0001s8-OU for kernel-team@lists.ubuntu.com; Fri, 02 Dec 2011 16:30:58 +0000 From: Paolo Pisati To: kernel-team@lists.ubuntu.com Subject: [lucid/fsl-imx51] [PATCH 3/3] resource: add helpers for fetching rlimits Date: Fri, 2 Dec 2011 17:30:39 +0100 Message-Id: <1322843439-3552-8-git-send-email-paolo.pisati@canonical.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1322843439-3552-1-git-send-email-paolo.pisati@canonical.com> References: <1322843439-3552-1-git-send-email-paolo.pisati@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com From: Jiri Slaby We want to be sure that compiler fetches the limit variable only once, so add helpers for fetching current and maximal resource limits which do that. Add them to sched.h (instead of resource.h) due to circular dependency sched.h->resource.h->task_struct Alternative would be to create a separate res_access.h or similar. Signed-off-by: Jiri Slaby Cc: James Morris Cc: Heiko Carstens Cc: Andrew Morton Cc: Ingo Molnar Signed-off-by: Paolo Pisati --- include/linux/sched.h | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index d1e5b06..51c7417 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2486,6 +2486,28 @@ static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) } #endif /* CONFIG_MM_OWNER */ +static inline unsigned long task_rlimit(const struct task_struct *tsk, + unsigned int limit) +{ + return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur); +} + +static inline unsigned long task_rlimit_max(const struct task_struct *tsk, + unsigned int limit) +{ + return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max); +} + +static inline unsigned long rlimit(unsigned int limit) +{ + return task_rlimit(current, limit); +} + +static inline unsigned long rlimit_max(unsigned int limit) +{ + return task_rlimit_max(current, limit); +} + #define TASK_STATE_TO_CHAR_STR "RSDTtZX" #endif /* __KERNEL__ */