Author: marius
Date: Mon May  8 21:08:39 2017
New Revision: 317982
URL: https://svnweb.freebsd.org/changeset/base/317982

Log:
  - Also outside of the KOBJOPLOOKUP macro - which in turn is used by
    the code auto-generated for *.m - kobj_lookup_method(9) is useful;
    for example in back-ends or base class device drivers in order to
    determine whether a default method has been overridden. Thus, allow
    for the kobj_method_t pointer argument - used by KOBJOPLOOKUP in
    order to update the cache entry - of kobj_lookup_method(9), to be
    NULL. Actually, that pointer is redundant as it's just set to the
    same kobj_method_t that the kobj_lookup_method(9) function returns
    in the first place, but probably it serves to reduce the number of
    instructions generated for KOBJOPLOOKUP.
  - For the same reason, move updating kobj_lookup_{hits,misses} (if
    KOBJ_STATS is defined) from kobj_lookup_method(9) to KOBJOPLOOKUP.
    As a side-effect, this gets rid of the convoluted approach of always
    incrementing kobj_lookup_hits in KOBJOPLOOKUP and then in case of
    a cache miss, decrementing it in kobj_lookup_method(9) again.

Modified:
  head/sys/kern/subr_kobj.c
  head/sys/sys/kobj.h

Modified: head/sys/kern/subr_kobj.c
==============================================================================
--- head/sys/kern/subr_kobj.c   Mon May  8 20:58:32 2017        (r317981)
+++ head/sys/kern/subr_kobj.c   Mon May  8 21:08:39 2017        (r317982)
@@ -213,19 +213,11 @@ kobj_lookup_method(kobj_class_t cls,
 {
        kobj_method_t *ce;
 
-#ifdef KOBJ_STATS
-       /*
-        * Correct for the 'hit' assumption in KOBJOPLOOKUP and record
-        * a 'miss'.
-        */
-       kobj_lookup_hits--;
-       kobj_lookup_misses++;
-#endif
-
        ce = kobj_lookup_method_mi(cls, desc);
        if (!ce)
                ce = &desc->deflt;
-       *cep = ce;
+       if (cep)
+               *cep = ce;
        return ce;
 }
 

Modified: head/sys/sys/kobj.h
==============================================================================
--- head/sys/sys/kobj.h Mon May  8 20:58:32 2017        (r317981)
+++ head/sys/sys/kobj.h Mon May  8 21:08:39 2017        (r317982)
@@ -226,10 +226,12 @@ extern u_int kobj_lookup_misses;
        kobj_method_t **_cep =                                  \
            &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)];       \
        kobj_method_t *_ce = *_cep;                             \
-       kobj_lookup_hits++; /* assume hit */                    \
-       if (_ce->desc != _desc)                                 \
+       if (_ce->desc != _desc) {                               \
                _ce = kobj_lookup_method(OPS->cls,              \
                                         _cep, _desc);          \
+               kobj_lookup_misses++;                           \
+       } else                                                  \
+               kobj_lookup_hits++;                             \
        _m = _ce->func;                                         \
 } while(0)
 #else
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to