Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 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 | |
| 42 | unsigned int num_queued; |
| 43 | unsigned int adj_limit; |
| 44 | unsigned int last_obj_cnt; |
| 45 | |
| 46 | |
| 47 | |
| 48 | unsigned int limit ____cacheline_aligned_in_smp; |
| 49 | unsigned int num_completed; |
| 50 | |
| 51 | unsigned int prev_ovlimit; |
| 52 | unsigned int prev_num_queued; |
| 53 | unsigned int prev_last_obj_cnt; |
| 54 | |
| 55 | unsigned int lowest_slack; |
| 56 | unsigned long slack_start_time; |
| 57 | |
| 58 | |
| 59 | unsigned int max_limit; |
| 60 | unsigned int min_limit; |
| 61 | unsigned int slack_hold_time; |
| 62 | }; |
| 63 | |
| 64 | #define DQL_MAX_OBJECT (UINT_MAX / 16) |
| 65 | #define DQL_MAX_LIMIT ((UINT_MAX / 2) - DQL_MAX_OBJECT) |
| 66 | |
| 67 | static inline void dql_queued(struct dql *dql, unsigned int count) |
| 68 | { |
| 69 | BUG_ON(count > DQL_MAX_OBJECT); |
| 70 | |
| 71 | dql->num_queued += count; |
| 72 | dql->last_obj_cnt = count; |
| 73 | } |
| 74 | |
| 75 | static inline int dql_avail(const struct dql *dql) |
| 76 | { |
| 77 | return dql->adj_limit - dql->num_queued; |
| 78 | } |
| 79 | |
| 80 | void dql_completed(struct dql *dql, unsigned int count); |
| 81 | |
| 82 | void dql_reset(struct dql *dql); |
| 83 | |
| 84 | int dql_init(struct dql *dql, unsigned hold_time); |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | #endif |