Date: Mon, 16 Jul 2012 15:14:33 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239471 - in soc2012/gmiller/locking-head: . lib/libwitness Message-ID: <20120716151433.D1474106567D@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Mon Jul 16 15:14:33 2012 New Revision: 239471 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239471 Log: r239507@FreeBSD-dev: root | 2012-07-14 06:35:51 -0500 Merge graph_node into lock_info to simplify code and improve performance. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/lib/libwitness/graph.c soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c soc2012/gmiller/locking-head/lib/libwitness/witness.h Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 16 15:14:21 2012 (r239470) +++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 16 15:14:33 2012 (r239471) @@ -27,29 +27,23 @@ #include "witness.h" -struct graph_node { - struct lock_info *lock; - struct graph_node *child; - struct graph_node *sibling; -}; +struct lock_info *root = NULL; -struct graph_node *root = NULL; - -static struct graph_node * -scan_graph(struct graph_node *graph, struct lock_info *lock) +static int +scan_graph(struct lock_info *graph, struct lock_info *lock) { - struct graph_node *ret; + int ret; if (graph == NULL) { - return (NULL); + return (0); } - if (graph->lock == lock) { - return (graph); + if (graph == lock) { + return (1); } ret = scan_graph(graph->child, lock); - if (ret == NULL) { + if (!ret) { ret = scan_graph(graph->sibling, lock); } @@ -57,24 +51,24 @@ } static void -optimize_links(struct graph_node *to) +optimize_links(struct lock_info *to) { - to = to; - /* - find first node with multiple children, then start scanning for - multiple paths to "to" from any node with multiple children and - a link to "to" - */ + to = to; + /* + XXX find first node with multiple children, then start scanning for + multiple paths to "to" from any node with multiple children and + a link to "to" + */ } -static int -insert_edge(struct graph_node *from, struct graph_node *to) +int +insert_lock(struct lock_info *from, struct lock_info *to) { if (from == to) { return (0); } - if (scan_graph(to, from->lock) != NULL) { + if (scan_graph(to, from)) { return (-1); } @@ -85,29 +79,3 @@ return (0); } - -static struct graph_node * -lookup_node(void *lock) -{ - struct graph_node *node = NULL; - - if (root != NULL) { - node = scan_graph(root, lock); - } - - if (node == NULL) { - node = malloc(sizeof(struct graph_node)); - node->lock = lock; - node->child = NULL; - node->sibling = root; - root = node; - } - - return (node); -} - -int -insert_lock(struct lock_info *new_lock, struct lock_info *previous) -{ - return (insert_edge(lookup_node(previous), lookup_node(new_lock))); -} Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 16 15:14:21 2012 (r239470) +++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 16 15:14:33 2012 (r239471) @@ -45,6 +45,8 @@ info = malloc(sizeof(struct lock_info)); info->active = 1; info->lock = lock; + info->child = NULL; + info->sibling = NULL; SLIST_INSERT_HEAD(&lock_info_head, info, lock_info_next); } Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/witness.h Mon Jul 16 15:14:21 2012 (r239470) +++ soc2012/gmiller/locking-head/lib/libwitness/witness.h Mon Jul 16 15:14:33 2012 (r239471) @@ -35,6 +35,8 @@ SLIST_ENTRY(lock_info) lock_info_next; void *lock; int active; + struct lock_info *child; + struct lock_info *sibling; }; extern pthread_mutex_t witness_mtx;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120716151433.D1474106567D>