~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/dynamic_queue_limits.h

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Dynamic queue limits (dql) - Definitions
  3  *
  4  * Copyright (c) 2011, Tom Herbert <therbert@google.com>
  5  *
  6  * This header file contains the definitions for dynamic queue limits (dql).
  7  * dql would be used in conjunction with a producer/consumer type queue
  8  * (possibly a HW queue).  Such a queue would have these general properties:
  9  *
 10  *   1) Objects are queued up to some limit specified as number of objects.
 11  *   2) Periodically a completion process executes which retires consumed
 12  *      objects.
 13  *   3) Starvation occurs when limit has been reached, all queued data has
 14  *      actually been consumed, but completion processing has not yet run
 15  *      so queuing new data is blocked.
 16  *   4) Minimizing the amount of queued data is desirable.
 17  *
 18  * The goal of dql is to calculate the limit as the minimum number of objects
 19  * needed to prevent starvation.
 20  *
 21  * The primary functions of dql are:
 22  *    dql_queued - called when objects are enqueued to record number of objects
 23  *    dql_avail - returns how many objects are available to be queued based
 24  *      on the object limit and how many objects are already enqueued
 25  *    dql_completed - called at completion time to indicate how many objects
 26  *      were retired from the queue
 27  *
 28  * The dql implementation does not implement any locking for the dql data
 29  * structures, the higher layer should provide this.  dql_queued should
 30  * be serialized to prevent concurrent execution of the function; this
 31  * is also true for  dql_completed.  However, dql_queued and dlq_completed  can
 32  * be executed concurrently (i.e. they can be protected by different locks).
 33  */
 34 
 35 #ifndef _LINUX_DQL_H
 36 #define _LINUX_DQL_H
 37 
 38 #ifdef __KERNEL__
 39 
 40 struct dql {
 41         /* Fields accessed in enqueue path (dql_queued) */
 42         unsigned int    num_queued;             /* Total ever queued */
 43         unsigned int    adj_limit;              /* limit + num_completed */
 44         unsigned int    last_obj_cnt;           /* Count at last queuing */
 45 
 46         /* Fields accessed only by completion path (dql_completed) */
 47 
 48         unsigned int    limit ____cacheline_aligned_in_smp; /* Current limit */
 49         unsigned int    num_completed;          /* Total ever completed */
 50 
 51         unsigned int    prev_ovlimit;           /* Previous over limit */
 52         unsigned int    prev_num_queued;        /* Previous queue total */
 53         unsigned int    prev_last_obj_cnt;      /* Previous queuing cnt */
 54 
 55         unsigned int    lowest_slack;           /* Lowest slack found */
 56         unsigned long   slack_start_time;       /* Time slacks seen */
 57 
 58         /* Configuration */
 59         unsigned int    max_limit;              /* Max limit */
 60         unsigned int    min_limit;              /* Minimum limit */
 61         unsigned int    slack_hold_time;        /* Time to measure slack */
 62 };
 63 
 64 /* Set some static maximums */
 65 #define DQL_MAX_OBJECT (UINT_MAX / 16)
 66 #define DQL_MAX_LIMIT ((UINT_MAX / 2) - DQL_MAX_OBJECT)
 67 
 68 /*
 69  * Record number of objects queued. Assumes that caller has already checked
 70  * availability in the queue with dql_avail.
 71  */
 72 static inline void dql_queued(struct dql *dql, unsigned int count)
 73 {
 74         BUG_ON(count > DQL_MAX_OBJECT);
 75 
 76         dql->last_obj_cnt = count;
 77 
 78         /* We want to force a write first, so that cpu do not attempt
 79          * to get cache line containing last_obj_cnt, num_queued, adj_limit
 80          * in Shared state, but directly does a Request For Ownership
 81          * It is only a hint, we use barrier() only.
 82          */
 83         barrier();
 84 
 85         dql->num_queued += count;
 86 }
 87 
 88 /* Returns how many objects can be queued, < 0 indicates over limit. */
 89 static inline int dql_avail(const struct dql *dql)
 90 {
 91         return ACCESS_ONCE(dql->adj_limit) - ACCESS_ONCE(dql->num_queued);
 92 }
 93 
 94 /* Record number of completed objects and recalculate the limit. */
 95 void dql_completed(struct dql *dql, unsigned int count);
 96 
 97 /* Reset dql state */
 98 void dql_reset(struct dql *dql);
 99 
100 /* Initialize dql state */
101 int dql_init(struct dql *dql, unsigned hold_time);
102 
103 #endif /* _KERNEL_ */
104 
105 #endif /* _LINUX_DQL_H */
106 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp