From owner-svn-src-head@freebsd.org Tue Aug 4 06:02:04 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A11AF9B2986; Tue, 4 Aug 2015 06:02:04 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8F1CC9C9; Tue, 4 Aug 2015 06:02:04 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t74624jT031414; Tue, 4 Aug 2015 06:02:04 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t74624YJ031413; Tue, 4 Aug 2015 06:02:04 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201508040602.t74624YJ031413@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Tue, 4 Aug 2015 06:02:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286278 - head/sys/compat/cloudabi X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Aug 2015 06:02:04 -0000 Author: ed Date: Tue Aug 4 06:02:03 2015 New Revision: 286278 URL: https://svnweb.freebsd.org/changeset/base/286278 Log: Let the CloudABI futex code use umtx_keys. The CloudABI kernel still passes all of the cloudlibc unit tests. Reviewed by: vangyzen Differential Revision: https://reviews.freebsd.org/D3286 Modified: head/sys/compat/cloudabi/cloudabi_futex.c Modified: head/sys/compat/cloudabi/cloudabi_futex.c ============================================================================== --- head/sys/compat/cloudabi/cloudabi_futex.c Tue Aug 4 06:01:13 2015 (r286277) +++ head/sys/compat/cloudabi/cloudabi_futex.c Tue Aug 4 06:02:03 2015 (r286278) @@ -35,13 +35,7 @@ __FBSDID("$FreeBSD$"); #include #include #include - -#include -#include -#include -#include -#include -#include +#include #include #include @@ -105,13 +99,7 @@ struct futex_waiter; /* Identifier of a location in memory. */ struct futex_address { - /* For process-private objects: address space of the process. */ - struct vmspace * fa_vmspace; - /* For process-shared objects: VM object containing the object. */ - struct vm_object * fa_vmobject; - - /* Memory address within address space or offset within VM object. */ - uintptr_t fa_offset; + struct umtx_key fa_key; }; /* A set of waiting threads. */ @@ -225,61 +213,16 @@ static int futex_address_create(struct futex_address *fa, struct thread *td, const void *object, cloudabi_mflags_t scope) { - struct vmspace *vs; - struct vm_object *vo; - vm_map_t map; - vm_map_entry_t entry; - vm_pindex_t pindex; - vm_prot_t prot; - boolean_t wired; - /* - * Most of the time objects are stored in privately mapped - * anonymous memory. For these objects we wouldn't need to look - * up the corresponding VM object. The scope hint provided by - * userspace allows us to skip the VM map lookup for the common - * case. - * - * POSIX does permit enabling PTHREAD_PROCESS_SHARED on a lock - * stored in a private mapping, at the cost of additional - * performance overhead. Fall back to identifying the object by - * virtual memory address if the mapping isn't shared. - */ - vs = td->td_proc->p_vmspace; + KASSERT(td == curthread, + ("Can only create umtx keys for the current thread")); switch (scope) { - case CLOUDABI_MAP_SHARED: - map = &vs->vm_map; - if (vm_map_lookup(&map, (vm_offset_t)object, - VM_PROT_COPY | VM_PROT_WRITE, &entry, &vo, &pindex, &prot, - &wired) != KERN_SUCCESS) - return (EFAULT); - - if (entry->inheritance == VM_INHERIT_SHARE) { - /* - * Address corresponds to a shared mapping. - * Identify the address by its VM object. - */ - fa->fa_vmspace = NULL; - fa->fa_vmobject = vo; - vm_object_reference(vo); - fa->fa_offset = entry->offset - entry->start + - (vm_offset_t)object; - vm_map_lookup_done(map, entry); - return (0); - } - vm_map_lookup_done(map, entry); - /* FALLTHROUGH */ case CLOUDABI_MAP_PRIVATE: - /* - * Address corresponds to a private mapping. Never - * identify the address by its VM object, as shadow - * objects may get inserted if another thread forks. - * Simply use the VM space instead. - */ - fa->fa_vmspace = vs; - fa->fa_vmobject = NULL; - fa->fa_offset = (uintptr_t)object; - return (0); + return (umtx_key_get(object, TYPE_FUTEX, THREAD_SHARE, + &fa->fa_key)); + case CLOUDABI_MAP_SHARED: + return (umtx_key_get(object, TYPE_FUTEX, AUTO_SHARE, + &fa->fa_key)); default: return (EINVAL); } @@ -289,8 +232,7 @@ static void futex_address_free(struct futex_address *fa) { - if (fa->fa_vmobject != NULL) - vm_object_deallocate(fa->fa_vmobject); + umtx_key_release(&fa->fa_key); } static bool @@ -298,10 +240,7 @@ futex_address_match(const struct futex_a const struct futex_address *fa2) { - /* Either fa_vmspace or fa_vmobject is NULL. */ - return (fa1->fa_vmspace == fa2->fa_vmspace && - fa1->fa_vmobject == fa2->fa_vmobject && - fa1->fa_offset == fa2->fa_offset); + return (umtx_key_match(&fa1->fa_key, &fa2->fa_key)); } /*