From owner-svn-src-head@FreeBSD.ORG Mon Oct 25 09:16:04 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C24C01065674; Mon, 25 Oct 2010 09:16:04 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A56538FC0C; Mon, 25 Oct 2010 09:16:04 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o9P9G41f058180; Mon, 25 Oct 2010 09:16:04 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9P9G4YO058177; Mon, 25 Oct 2010 09:16:04 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201010250916.o9P9G4YO058177@svn.freebsd.org> From: David Xu Date: Mon, 25 Oct 2010 09:16:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214334 - head/lib/libthr/thread X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Mon, 25 Oct 2010 09:16:05 -0000 Author: davidxu Date: Mon Oct 25 09:16:04 2010 New Revision: 214334 URL: http://svn.freebsd.org/changeset/base/214334 Log: Get cpuset in pthread_attr_get_np() and free it in pthread_attr_destroy(). MFC after: 7 days Modified: head/lib/libthr/thread/thr_attr.c head/lib/libthr/thread/thr_private.h Modified: head/lib/libthr/thread/thr_attr.c ============================================================================== --- head/lib/libthr/thread/thr_attr.c Mon Oct 25 08:30:19 2010 (r214333) +++ head/lib/libthr/thread/thr_attr.c Mon Oct 25 09:16:04 2010 (r214334) @@ -104,6 +104,8 @@ #include "thr_private.h" +static size_t _get_kern_cpuset_size(void); + __weak_reference(_pthread_attr_destroy, pthread_attr_destroy); int @@ -116,6 +118,8 @@ _pthread_attr_destroy(pthread_attr_t *at /* Invalid argument: */ ret = EINVAL; else { + if ((*attr)->cpuset != NULL) + free((*attr)->cpuset); /* Free the memory allocated to the attribute object: */ free(*attr); @@ -132,28 +136,43 @@ _pthread_attr_destroy(pthread_attr_t *at __weak_reference(_pthread_attr_get_np, pthread_attr_get_np); int -_pthread_attr_get_np(pthread_t pthread, pthread_attr_t *dst) +_pthread_attr_get_np(pthread_t pthread, pthread_attr_t *dstattr) { struct pthread *curthread; - struct pthread_attr attr; + struct pthread_attr attr, *dst; int ret; + size_t cpusetsize; - if (pthread == NULL || dst == NULL || *dst == NULL) + if (pthread == NULL || dst_attr == NULL || (dst = *dstattr) == NULL) return (EINVAL); - + cpusetsize = _get_kern_cpuset_size(); + if (dst->cpusetsize < cpusetsize) { + char *newset = realloc(dst->cpuset, cpusetsize); + if (newset == NULL) + return (errno); + memset(newset + dst->cpusetsize, 0, cpusetsize - + dst->cpusetsize); + dst->cpuset = (cpuset_t *)newset; + dst->cpusetsize = cpusetsize; + } curthread = _get_curthread(); if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0)) != 0) return (ret); attr = pthread->attr; if (pthread->flags & THR_FLAGS_DETACHED) attr.flags |= PTHREAD_DETACHED; + ret = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, TID(pthread), + dst->cpusetsize, dst->cpuset); + if (ret == -1) + ret = errno; THR_THREAD_UNLOCK(curthread, pthread); - - memcpy(*dst, &attr, sizeof(struct pthread_attr)); - /* XXX */ - (*dst)->cpuset = NULL; - (*dst)->cpusetsize = 0; - return (0); + if (ret == 0) { + memcpy(&dst->pthread_attr_start_copy, + &attr.pthread_attr_start_copy, + offsetof(struct pthread_attr, pthread_attr_end_copy) - + offsetof(struct pthread_attr, pthread_attr_start_copy)); + } + return (ret); } __weak_reference(_pthread_attr_getdetachstate, pthread_attr_getdetachstate); Modified: head/lib/libthr/thread/thr_private.h ============================================================================== --- head/lib/libthr/thread/thr_private.h Mon Oct 25 08:30:19 2010 (r214333) +++ head/lib/libthr/thread/thr_private.h Mon Oct 25 09:16:04 2010 (r214334) @@ -230,6 +230,7 @@ struct pthread_atfork { }; struct pthread_attr { +#define pthread_attr_start_copy sched_policy int sched_policy; int sched_inherit; int prio; @@ -239,6 +240,7 @@ struct pthread_attr { void *stackaddr_attr; size_t stacksize_attr; size_t guardsize_attr; +#define pthread_attr_end_copy cpuset cpuset_t *cpuset; size_t cpusetsize; };