Date: Mon, 23 Jul 2012 20:22:00 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239714 - in soc2012/gmiller/locking-head: . include lib/libwitness tools/regression/lib/libthr/lockprof tools/regression/lib/libwitness Message-ID: <20120723202200.107921065673@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Mon Jul 23 20:21:59 2012 New Revision: 239714 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239714 Log: r239754@FreeBSD-dev: root | 2012-07-23 14:28:03 -0500 Add lock names to pthread_lor_np, add a test for pthread_setname_np(), and fix the bugs that were found as a result. Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.t - copied unchanged from r239713, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.t Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/include/pthread_np.h soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c soc2012/gmiller/locking-head/lib/libwitness/logs.c soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/conflict.c soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c Modified: soc2012/gmiller/locking-head/include/pthread_np.h ============================================================================== --- soc2012/gmiller/locking-head/include/pthread_np.h Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/include/pthread_np.h Mon Jul 23 20:21:59 2012 (r239714) @@ -64,6 +64,8 @@ struct _pthread_lor_private *_pvt; void *lock_first; void *lock_second; + const char *name_first; + const char *name_second; }; struct _pthread_lockorder_private; Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 23 20:21:59 2012 (r239714) @@ -115,10 +115,8 @@ struct lock_info *info; info = lookup_lock(lock); - if (info->name != NULL) { - info->name = realloc(info->name, strlen(name) + 1); - strcpy(info->name, name); - } + info->name = realloc(info->name, strlen(name) + 1); + strcpy(info->name, name); } void Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/logs.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/lib/libwitness/logs.c Mon Jul 23 20:21:59 2012 (r239714) @@ -81,8 +81,10 @@ } if (lor->_pvt->last_record != NULL) { - lor->lock_first = lor->_pvt->last_record->lock_first; - lor->lock_second = lor->_pvt->last_record->lock_second; + lor->lock_first = lor->_pvt->last_record->lock_first->lock; + lor->lock_second = lor->_pvt->last_record->lock_second->lock; + lor->name_first = lor->_pvt->last_record->lock_first->name; + lor->name_second = lor->_pvt->last_record->lock_second->name; res = 1; } Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c Mon Jul 23 20:21:59 2012 (r239714) @@ -1,3 +1,29 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ #include <stdio.h> Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h Mon Jul 23 20:21:59 2012 (r239714) @@ -1,3 +1,29 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ void check(char cond); void show_test_results(void); Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/conflict.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/conflict.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/conflict.c Mon Jul 23 20:21:59 2012 (r239714) @@ -1,3 +1,29 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ #include <pthread.h> #include <pthread_np.h> Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Mon Jul 23 20:21:59 2012 (r239714) @@ -1,3 +1,29 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ #include <pthread.h> #include <pthread_np.h> Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c Mon Jul 23 20:21:59 2012 (r239714) @@ -1,3 +1,29 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ #include <pthread.h> #include <pthread_np.h> Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Mon Jul 23 20:21:59 2012 (r239714) @@ -1,6 +1,6 @@ # $FreeBSD$ -TESTS= lor-basic setorder bless +TESTS= lor-basic setorder bless setname CFLAGS+= -g -Wall -Wextra -Werror -lwitness .PHONY: tests @@ -19,3 +19,6 @@ bless: bless.c check.c ${CC} -o bless bless.c check.c ${CFLAGS} + +setname: setname.c check.c + ${CC} -o setname setname.c check.c ${CFLAGS} Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c Mon Jul 23 20:21:37 2012 (r239713) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c Mon Jul 23 20:21:59 2012 (r239714) @@ -27,7 +27,6 @@ #include <pthread.h> #include <pthread_np.h> -#include <stdio.h> #include "check.h" Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c Mon Jul 23 20:21:59 2012 (r239714) @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <pthread.h> +#include <pthread_np.h> +#include <string.h> + +#include "check.h" + +pthread_mutex_t mutex1; +pthread_mutex_t mutex2; + +void +setname_test(void) +{ + pthread_setname_np(&mutex1, "mutex 1"); + pthread_setname_np(&mutex2, "mutex 2"); + + pthread_mutex_lock(&mutex1); + pthread_mutex_lock(&mutex2); + + pthread_mutex_unlock(&mutex2); + pthread_mutex_unlock(&mutex1); + + pthread_mutex_lock(&mutex2); + pthread_mutex_lock(&mutex1); + + pthread_mutex_lock(&mutex1); + pthread_mutex_lock(&mutex2); +} + +void +check_setname(void) +{ + int record_count = 0; + struct pthread_lor_np lor; + + pthread_lor_begin_np(&lor); + while (pthread_lor_next_np(&lor)) { + record_count++; + } + pthread_lor_end_np(&lor); + + check(record_count == 1); + + check((strcmp(lor.name_first, "mutex 1") == 0 && + strcmp(lor.name_second, "mutex 2") == 0) || + (strcmp(lor.name_first, "mutex 2") == 0 && + strcmp(lor.name_second, "mutex 1") == 0)); +} + +int +main(void) +{ + setname_test(); + check_setname(); + + show_test_results(); + + return (0); +} Copied: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.t (from r239713, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.t) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.t Mon Jul 23 20:21:59 2012 (r239714, copy of r239713, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.t) @@ -0,0 +1,10 @@ +#!/bin/sh +# $FreeBSD$ + +cd `dirname $0` + +executable=`basename $0 .t` + +make $executable 2>&1 > /dev/null + +exec ./$executable
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120723202200.107921065673>