Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Nov 2018 14:58:41 +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: r340676 - in head/sys: kern sys
Message-ID:  <201811201458.wAKEwftP033152@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Tue Nov 20 14:58:41 2018
New Revision: 340676
URL: https://svnweb.freebsd.org/changeset/base/340676

Log:
  Implement unr64
  
  Important users of unr like tmpfs or pipes can get away with just
  ever-increasing counters, making the overhead of managing the state
  for 32 bit counters a pessimization.
  
  Change it to an atomic variable. This can be further sped up by making
  the counts variable "allocate" ranges and store them per-cpu.
  
  Reviewed by:	kib
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D18054

Modified:
  head/sys/kern/subr_unit.c
  head/sys/sys/systm.h

Modified: head/sys/kern/subr_unit.c
==============================================================================
--- head/sys/kern/subr_unit.c	Tue Nov 20 14:52:43 2018	(r340675)
+++ head/sys/kern/subr_unit.c	Tue Nov 20 14:58:41 2018	(r340676)
@@ -98,6 +98,19 @@ static struct mtx unitmtx;
 
 MTX_SYSINIT(unit, &unitmtx, "unit# allocation", MTX_DEF);
 
+#ifdef UNR64_LOCKED
+uint64_t
+alloc_unr64(struct unrhdr64 *unr64)
+{
+	uint64_t item;
+
+	mtx_lock(&unitmtx);
+	item = unr64->counter++;
+	mtx_unlock(&unitmtx);
+	return (item);
+}
+#endif
+
 #else /* ...USERLAND */
 
 #include <bitstring.h>

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h	Tue Nov 20 14:52:43 2018	(r340675)
+++ head/sys/sys/systm.h	Tue Nov 20 14:58:41 2018	(r340676)
@@ -523,6 +523,32 @@ int alloc_unr_specific(struct unrhdr *uh, u_int item);
 int alloc_unrl(struct unrhdr *uh);
 void free_unr(struct unrhdr *uh, u_int item);
 
+#if defined(__mips__) || defined(__powerpc__)
+#define UNR64_LOCKED
+#endif
+
+struct unrhdr64 {
+        uint64_t	counter;
+};
+
+static __inline void
+new_unrhdr64(struct unrhdr64 *unr64, uint64_t low)
+{
+
+	unr64->counter = low;
+}
+
+#ifdef UNR64_LOCKED
+uint64_t alloc_unr64(struct unrhdr64 *);
+#else
+static __inline uint64_t
+alloc_unr64(struct unrhdr64 *unr64)
+{
+
+	return (atomic_fetchadd_64(&unr64->counter, 1));
+}
+#endif
+
 void	intr_prof_stack_use(struct thread *td, struct trapframe *frame);
 
 void counted_warning(unsigned *counter, const char *msg);



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