The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/tim_filter.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #ifndef __tim_filter_h__
    2 #define __tim_filter_h__
    3 /*-
    4  * Copyright (c) 2016-9 Netflix, Inc.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  * $FreeBSD$
   29  */
   30 /*
   31  * Author: Randall Stewart <rrs@netflix.com>
   32  */
   33 
   34 #include <sys/types.h>
   35 #include <machine/param.h>
   36 /* 
   37  * Do not change the size unless you know what you are
   38  * doing, the current size of 5 is designed around
   39  * the cache-line size for an amd64 processor. Other processors
   40  * may need other sizes.
   41  */
   42 #define NUM_FILTER_ENTRIES 3
   43 
   44 struct filter_entry {
   45         uint64_t value;         /* Value */
   46         uint32_t time_up;       /* Time updated */
   47 } __packed ;
   48 
   49 struct filter_entry_small {
   50         uint32_t value;         /* Value */
   51         uint32_t time_up;       /* Time updated */
   52 };
   53 
   54 struct time_filter {
   55         uint32_t cur_time_limit;
   56         struct filter_entry entries[NUM_FILTER_ENTRIES];
   57 #ifdef _KERNEL
   58 } __aligned(CACHE_LINE_SIZE);
   59 #else   
   60 };
   61 #endif
   62 struct time_filter_small {
   63         uint32_t cur_time_limit;
   64         struct filter_entry_small entries[NUM_FILTER_ENTRIES];
   65 };
   66 
   67 /*
   68  * To conserve on space there is a code duplication here (this
   69  * is where polymophism would be nice in the kernel). Everything
   70  * is duplicated to have a filter with a value of uint32_t instead
   71  * of a uint64_t. This saves 20 bytes and the structure size
   72  * drops to 44 from 64. The bad part about this is you end
   73  * up with two sets of functions. The xxx_small() access
   74  * the uint32_t value's where the xxx() the uint64_t values.
   75  * This forces the user to keep straight which type of structure
   76  * they allocated and which call they need to make. crossing
   77  * over calls will create either invalid memory references or
   78  * very bad results :)
   79  */
   80 
   81 #define FILTER_TYPE_MIN 1
   82 #define FILTER_TYPE_MAX 2
   83 
   84 #ifdef _KERNEL
   85 int setup_time_filter(struct time_filter *tf, int fil_type, uint32_t time_len);
   86 void reset_time(struct time_filter *tf, uint32_t time_len);
   87 void forward_filter_clock(struct time_filter *tf, uint32_t ticks_forward);
   88 void tick_filter_clock(struct time_filter *tf, uint32_t now);
   89 uint32_t apply_filter_min(struct time_filter *tf, uint64_t value, uint32_t now);
   90 uint32_t apply_filter_max(struct time_filter *tf, uint64_t value, uint32_t now);
   91 void filter_reduce_by(struct time_filter *tf, uint64_t reduce_by, uint32_t now);
   92 void filter_increase_by(struct time_filter *tf, uint64_t incr_by, uint32_t now);
   93 static uint64_t inline
   94 get_filter_value(struct time_filter *tf)
   95 {
   96         return(tf->entries[0].value);
   97 }
   98 
   99 static uint32_t inline
  100 get_cur_timelim(struct time_filter *tf)
  101 {
  102         return(tf->cur_time_limit);
  103 }
  104 
  105 int setup_time_filter_small(struct time_filter_small *tf,
  106                             int fil_type, uint32_t time_len);
  107 void reset_time_small(struct time_filter_small *tf, uint32_t time_len);
  108 void forward_filter_clock_small(struct time_filter_small *tf,
  109                                 uint32_t ticks_forward);
  110 void tick_filter_clock_small(struct time_filter_small *tf, uint32_t now);
  111 uint32_t apply_filter_min_small(struct time_filter_small *tf,
  112                                 uint32_t value, uint32_t now);
  113 uint32_t apply_filter_max_small(struct time_filter_small *tf,
  114                                 uint32_t value, uint32_t now);
  115 void filter_reduce_by_small(struct time_filter_small *tf,
  116                             uint32_t reduce_by, uint32_t now);
  117 void filter_increase_by_small(struct time_filter_small *tf,
  118                               uint32_t incr_by, uint32_t now);
  119 static uint64_t inline
  120 get_filter_value_small(struct time_filter_small *tf)
  121 {
  122         return(tf->entries[0].value);
  123 }
  124 
  125 static uint32_t inline
  126 get_cur_timelim_small(struct time_filter_small *tf)
  127 {
  128         return(tf->cur_time_limit);
  129 }
  130 
  131 #endif
  132 #endif

Cache object: 441f43c964e6a19ab707dc2146240bed


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.