Date: Tue, 23 Jul 2013 00:28:49 GMT From: Jonathan Anderson <jonathan@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 231357 for review Message-ID: <201307230028.r6N0Snbh007308@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@231357?ac=10 Change 231357 by jonathan@jonathan-on-zenith on 2013/07/23 00:28:45 Pull in latest libtesla parts. Affected files ... .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/include/tesla-macros.h#9 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/include/tesla.h#7 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_class.c#7 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_debug.c#5 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_internal.h#10 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_notification.c#15 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_store.c#6 edit .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_update.c#11 edit Differences ... ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/include/tesla-macros.h#9 (text+ko) ==== @@ -90,17 +90,17 @@ #define tesla_done return (__tesla_automaton_done()) #define optional(...) __tesla_optional(TIGNORE, __VA_ARGS__) -#define ANY_REP INT_MAX +#define ANY_REP __TESLA_INFINITE_REPETITIONS #define REPEAT(m, n, ...) __tesla_repeat(m, n, __VA_ARGS__) #define UPTO(n, ...) __tesla_repeat(1, n, __VA_ARGS__) #define ATLEAST(n, ...) __tesla_repeat(n, ANY_REP, __VA_ARGS__) #define ANY(int_type) __tesla_any(int_type) /** A more programmer-friendly way to write assertions about the past. */ -#define previously(...) TSEQUENCE(__VA_ARGS__, TESLA_ASSERTION_SITE) +#define previously(...) TSEQUENCE(__VA_ARGS__, TESLA_ASSERTION_SITE) /** A more programmer-friendly way to write assertions about the future. */ -#define eventually(...) TSEQUENCE(TESLA_ASSERTION_SITE, __VA_ARGS__) +#define eventually(...) TSEQUENCE(TESLA_ASSERTION_SITE, __VA_ARGS__) /** @} */ ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/include/tesla.h#7 (text+ko) ==== @@ -66,17 +66,14 @@ __tesla_inline_assertion(const char *filename, int line, int count, __tesla_locality *loc, ...); +#define __TESLA_INFINITE_REPETITIONS INT_MAX + /* Only define the following things if doing TESLA analysis, not compiling. */ #ifdef __TESLA_ANALYSER__ #include <sys/types.h> - -#ifdef _KERNEL -#include <sys/limits.h> -#else #include <limits.h> -#endif /** * TESLA events can be serialised either with respect to the current thread @@ -89,7 +86,7 @@ struct __tesla_event* __tesla_sequence(__tesla_event*, ...); /** A sequence of events that repeats. */ -struct __tesla_event* __tesla_repeat(int min, int max, __tesla_event*, ...); +struct __tesla_event* __tesla_repeat(int min, int max, ...); /* TESLA events: */ /** Entering a function (with optionally-specified arguments). */ @@ -225,6 +222,7 @@ #define __tesla_strict(...) 0 #define __tesla_conditional(...) 0 +#define __tesla_repeat(...) 0 #endif /* __TESLA_ANALYSER__ */ ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_class.c#7 (text+ko) ==== @@ -33,6 +33,7 @@ */ #include "tesla_internal.h" +#include "tesla_key.h" #ifdef _KERNEL MALLOC_DEFINE(M_TESLA, "tesla", "TESLA internal state"); @@ -119,14 +120,6 @@ } -int -tesla_instance_active(const struct tesla_instance *i) -{ - assert(i != NULL); - - return ((i->ti_state != 0) || (i->ti_key.tk_mask != 0)); -} - int32_t tesla_instance_new(struct tesla_class *tclass, const struct tesla_key *name, ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_debug.c#5 (text+ko) ==== @@ -156,12 +156,23 @@ /* * Debugging paths could be more vulnerable to format string problems * than other code; don't allow when running setuid or setgid. - */ - if (issetugid()) + */ + static int isnotme = -1; + + if (isnotme == -1) + isnotme = issetugid(); + + if (isnotme) return 0; #endif - const char *env = getenv("TESLA_DEBUG"); + static const char *env = (char*)-1; + if (env == (char*)-1) + { + env = getenv("TESLA_DEBUG"); + if (env != 0 && *env == '\0') + env = 0; + } /* If TESLA_DEBUG is not set, we're definitely not debugging. */ if (env == NULL) @@ -246,5 +257,11 @@ print("%s", buffer); } +#else + +#undef tesla_debugging +int32_t +tesla_debugging(const char *name) { return 0; } + #endif /* !NDEBUG */ ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_internal.h#10 (text+ko) ==== @@ -113,7 +113,14 @@ * * @returns 1 if active, 0 if inactive */ -int32_t tesla_instance_active(const struct tesla_instance *i); +static inline int32_t +tesla_instance_active(const struct tesla_instance *i) +{ + assert(i != NULL); + + return ((i->ti_state != 0) || (i->ti_key.tk_mask != 0)); +} + /** Clone an existing instance into a new instance. */ @@ -139,13 +146,6 @@ int32_t tesla_match(struct tesla_class *tclass, const struct tesla_key *key, struct tesla_instance **array, uint32_t *size); -/** - * Check to see if a key matches a pattern. - * - * @returns 1 if @a k matches @a pattern, 0 otherwise - */ -int32_t tesla_key_matches( - const struct tesla_key *pattern, const struct tesla_key *k); /** Actions that can be taken by @ref tesla_update_state. */ @@ -176,9 +176,6 @@ const struct tesla_key*, const struct tesla_transitions*, const struct tesla_transition** trigger); -/** Copy new entries from @a source into @a dest. */ -int32_t tesla_key_union(struct tesla_key *dest, const struct tesla_key *source); - #ifndef __unused #if __has_attribute(unused) @@ -346,16 +343,17 @@ #define error(...) fprintf(stderr, __VA_ARGS__) #endif -#ifndef NDEBUG - -#define __debug - #ifdef _KERNEL #include <sys/systm.h> #else #include <stdio.h> #endif +#ifndef NDEBUG + +#define __debug + + /** Are we in (verbose) debug mode? */ int32_t tesla_debugging(const char*); @@ -369,7 +367,9 @@ #define __debug __unused #define DEBUG(...) -int32_t tesla_debugging(const char*) { return 0; } +#define tesla_debugging(...) 0 +#define print_key(...) +#define print_class(...) #endif @@ -407,6 +407,10 @@ char* sprint_transitions(char *buffer, const char *end, const struct tesla_transitions *); +/** Flag indicating whether ev_transition should be called. */ +extern int have_transitions; + /** @} */ + #endif /* TESLA_INTERNAL_H */ ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_notification.c#15 (text+ko) ==== @@ -34,6 +34,12 @@ #define ERROR_BUFFER_LENGTH 1024 +#ifndef NDEBUG +int have_transitions = 1; +#else +int have_transitions = 0; +#endif + /** * The currently-active event handlers. */ @@ -68,6 +74,7 @@ .tem_mask = 1, .tem_handlers = singleton, }; + have_transitions = (tehp->teh_transition != 0); singleton[0] = tehp; event_handlers = &singleton_handler; @@ -79,6 +86,7 @@ tesla_set_event_handlers(struct tesla_event_metahandler *temp) { int error = TESLA_SUCCESS; + int will_have_transitions = 0; if (!temp) return (TESLA_ERROR_EINVAL); @@ -91,8 +99,11 @@ error = check_event_handler(temp->tem_handlers[i]); if (error != TESLA_SUCCESS) return (error); + if (temp->tem_handlers[i]->teh_transition) + will_have_transitions = 1; } + have_transitions = will_have_transitions; event_handlers = temp; return (TESLA_SUCCESS); } @@ -101,21 +112,18 @@ /* * generic event handlers: */ -#define FOREACH_ERROR_HANDLER() \ +#define FOREACH_ERROR_HANDLER(x, ...) \ for (uint32_t i = 0; i < event_handlers->tem_length; i++) \ if (event_handlers->tem_mask & (1 << i)) \ - event_handlers->tem_handlers[i] + if (event_handlers->tem_handlers[i]->x) \ + event_handlers->tem_handlers[i]->x(__VA_ARGS__) -static void -ev_noop() -{ -} void ev_new_instance(struct tesla_class *tcp, struct tesla_instance *tip) { - FOREACH_ERROR_HANDLER()->teh_init(tcp, tip); + FOREACH_ERROR_HANDLER(teh_init, tcp, tip); } void @@ -123,7 +131,7 @@ const struct tesla_transition *ttp) { - FOREACH_ERROR_HANDLER()->teh_transition(tcp, tip, ttp); + FOREACH_ERROR_HANDLER(teh_transition, tcp, tip, ttp); } void @@ -131,7 +139,7 @@ struct tesla_instance *copy, const struct tesla_transition *ttp) { - FOREACH_ERROR_HANDLER()->teh_clone(tcp, orig, copy, ttp); + FOREACH_ERROR_HANDLER(teh_clone, tcp, orig, copy, ttp); } void @@ -139,7 +147,7 @@ const struct tesla_transitions *ttp) { - FOREACH_ERROR_HANDLER()->teh_fail_no_instance(tcp, tkp, ttp); + FOREACH_ERROR_HANDLER(teh_fail_no_instance, tcp, tkp, ttp); } void @@ -147,21 +155,21 @@ const struct tesla_transitions *ttp) { - FOREACH_ERROR_HANDLER()->teh_bad_transition(tcp, tip, ttp); + FOREACH_ERROR_HANDLER(teh_bad_transition, tcp, tip, ttp); } void ev_err(struct tesla_class *tcp, int errno, const char *message) { - FOREACH_ERROR_HANDLER()->teh_err(tcp, errno, message); + FOREACH_ERROR_HANDLER(teh_err, tcp, errno, message); } void ev_accept(struct tesla_class *tcp, struct tesla_instance *tip) { - FOREACH_ERROR_HANDLER()->teh_accept(tcp, tip); + FOREACH_ERROR_HANDLER(teh_accept, tcp, tip); } void @@ -169,7 +177,7 @@ const struct tesla_transitions *ttp) { - FOREACH_ERROR_HANDLER()->teh_ignored(tcp, tkp, ttp); + FOREACH_ERROR_HANDLER(teh_ignored, tcp, tkp, ttp); } @@ -309,14 +317,14 @@ }; static const struct tesla_event_handlers printf_on_failure = { - .teh_init = ev_noop, - .teh_transition = ev_noop, - .teh_clone = ev_noop, + .teh_init = 0, + .teh_transition = 0, + .teh_clone = 0, .teh_fail_no_instance = print_no_instance, .teh_bad_transition = print_bad_transition, .teh_err = print_error, - .teh_accept = ev_noop, - .teh_ignored = ev_noop, + .teh_accept = 0, + .teh_ignored = 0, }; /* @@ -349,14 +357,14 @@ } static const struct tesla_event_handlers failstop_handlers = { - .teh_init = ev_noop, - .teh_transition = ev_noop, - .teh_clone = ev_noop, + .teh_init = 0, + .teh_transition = 0, + .teh_clone = 0, .teh_fail_no_instance = panic_no_instance, .teh_bad_transition = panic_bad_transition, .teh_err = panic_errno, - .teh_accept = ev_noop, - .teh_ignored = ev_noop, + .teh_accept = 0, + .teh_ignored = 0, }; @@ -365,7 +373,9 @@ * either use DTrace or fail-stop if DTrace is not available. */ const static struct tesla_event_handlers* const default_handlers[] = { +#ifndef NDEBUG &printf_handlers, +#endif &printf_on_failure, #if defined(_KERNEL) && defined(KDTRACE_HOOKS) &dtrace_handlers, ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_store.c#6 (text+ko) ==== @@ -61,6 +61,10 @@ tesla_global_store_sysinit, NULL); #endif +#ifndef _KERNEL +__thread tesla_store *cache = NULL; +#endif + int32_t tesla_store_get(enum tesla_context context, uint32_t classes, uint32_t instances, tesla_store* *storep) @@ -78,8 +82,12 @@ #ifdef _KERNEL store = curthread->td_tesla; #else - pthread_key_t key = pthread_key(); - store = pthread_getspecific(key); + pthread_key_t key; + if (!cache) { + key = pthread_key(); + cache = pthread_getspecific(key); + } + store = cache; #endif // Create a new store if we don't already have one. ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_update.c#11 (text+ko) ==== @@ -31,6 +31,7 @@ */ #include "tesla_internal.h" +#include "tesla_key.h" #ifndef _KERNEL #include <stdbool.h> @@ -72,14 +73,15 @@ PRINT("\n----\n"); struct tesla_store *store; - assert(tesla_store_get(tesla_context, TESLA_MAX_CLASSES, - TESLA_MAX_INSTANCES, &store) == TESLA_SUCCESS); + int ret = tesla_store_get(tesla_context, TESLA_MAX_CLASSES, + TESLA_MAX_INSTANCES, &store); + assert(ret == TESLA_SUCCESS); PRINT("store: 0x%tx\n", (intptr_t) store); struct tesla_class *class; - assert(tesla_class_get(store, class_id, &class, name, description) - == TESLA_SUCCESS); + ret = tesla_class_get(store, class_id, &class, name, description); + assert(ret == TESLA_SUCCESS); print_class(class); @@ -99,13 +101,15 @@ // Iterate over existing instances, figure out what to do with each. int err = TESLA_SUCCESS; - for (uint32_t i = 0; i < class->tc_limit; i++) { + int expected = class->tc_limit - class->tc_free; + for (uint32_t i = 0; expected > 0 && (i < class->tc_limit); i++) { assert(class->tc_instances != NULL); tesla_instance *inst = class->tc_instances + i; const tesla_transition *trigger = NULL; enum tesla_action_t action = tesla_action(inst, pattern, trans, &trigger); + expected -= action == IGNORE ? 0 : 1; switch (action) { case FAIL: @@ -116,7 +120,8 @@ break; case UPDATE: - ev_transition(class, inst, trigger); + if (have_transitions) + ev_transition(class, inst, trigger); inst->ti_state = trigger->to; matched_something = true;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307230028.r6N0Snbh007308>