Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2018 12:01:46 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r341818 - in head/sys: kern sys
Message-ID:  <201812111201.wBBC1kl2031373@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Tue Dec 11 12:01:46 2018
New Revision: 341818
URL: https://svnweb.freebsd.org/changeset/base/341818

Log:
  Make lim_cur inline if possible.
  
  It is a function call only to accomodate *some* ABIs which install a hook.
  They only care for 3 types of limits: DATA, STACK, VMEM
  
  Instead of always calling the func, see at compilation time if the requested
  limit is something else and just do the read if so.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_resource.c
  head/sys/sys/resourcevar.h

Modified: head/sys/kern/kern_resource.c
==============================================================================
--- head/sys/kern/kern_resource.c	Tue Dec 11 11:58:44 2018	(r341817)
+++ head/sys/kern/kern_resource.c	Tue Dec 11 12:01:46 2018	(r341818)
@@ -1168,7 +1168,7 @@ lim_max_proc(struct proc *p, int which)
  * The which parameter which specifies the index into the rlimit array
  */
 rlim_t
-lim_cur(struct thread *td, int which)
+(lim_cur)(struct thread *td, int which)
 {
 	struct rlimit rl;
 

Modified: head/sys/sys/resourcevar.h
==============================================================================
--- head/sys/sys/resourcevar.h	Tue Dec 11 11:58:44 2018	(r341817)
+++ head/sys/sys/resourcevar.h	Tue Dec 11 12:01:46 2018	(r341818)
@@ -132,6 +132,19 @@ struct plimit
 	*lim_alloc(void);
 void	 lim_copy(struct plimit *dst, struct plimit *src);
 rlim_t	 lim_cur(struct thread *td, int which);
+#define lim_cur(td, which)	({					\
+	rlim_t _rlim;							\
+	struct thread *_td = (td);					\
+	int _which = (which);						\
+	if (__builtin_constant_p(which) && which != RLIMIT_DATA &&	\
+	    which != RLIMIT_STACK && which != RLIMIT_VMEM) {		\
+		_rlim = td->td_limit->pl_rlimit[which].rlim_cur;	\
+	} else {							\
+		_rlim = lim_cur(_td, _which);				\
+	}								\
+	_rlim;								\
+})
+
 rlim_t	 lim_cur_proc(struct proc *p, int which);
 void	 lim_fork(struct proc *p1, struct proc *p2);
 void	 lim_free(struct plimit *limp);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812111201.wBBC1kl2031373>