util.c (9dfbdec7b7fea1ff1b7b5d5d12980dbc7dca46c7) | util.c (47344e330eabc1515cbe6061eb337100a3ab6d37) |
---|---|
1/* 2 * random utiility code, for bcache but in theory not specific to bcache 3 * 4 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com> 5 * Copyright 2012 Google, Inc. 6 */ 7 8#include <linux/bio.h> --- 68 unchanged lines hidden (view full) --- 77} \ 78 79STRTO_H(strtoint, int) 80STRTO_H(strtouint, unsigned int) 81STRTO_H(strtoll, long long) 82STRTO_H(strtoull, unsigned long long) 83 84/** | 1/* 2 * random utiility code, for bcache but in theory not specific to bcache 3 * 4 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com> 5 * Copyright 2012 Google, Inc. 6 */ 7 8#include <linux/bio.h> --- 68 unchanged lines hidden (view full) --- 77} \ 78 79STRTO_H(strtoint, int) 80STRTO_H(strtouint, unsigned int) 81STRTO_H(strtoll, long long) 82STRTO_H(strtoull, unsigned long long) 83 84/** |
85 * bch_hprint() - formats @v to human readable string for sysfs. | 85 * bch_hprint - formats @v to human readable string for sysfs. 86 * @buf: the (at least 8 byte) buffer to format the result into. 87 * @v: signed 64 bit integer |
86 * | 88 * |
87 * @v - signed 64 bit integer 88 * @buf - the (at least 8 byte) buffer to format the result into. 89 * | |
90 * Returns the number of bytes used by format. 91 */ 92ssize_t bch_hprint(char *buf, int64_t v) 93{ 94 static const char units[] = "?kMGTPEZY"; 95 int u = 0, t; 96 97 uint64_t q; --- 122 unchanged lines hidden (view full) --- 220 } 221 222 stats->last = now ?: 1; 223 224 spin_unlock(&stats->lock); 225} 226 227/** | 89 * Returns the number of bytes used by format. 90 */ 91ssize_t bch_hprint(char *buf, int64_t v) 92{ 93 static const char units[] = "?kMGTPEZY"; 94 int u = 0, t; 95 96 uint64_t q; --- 122 unchanged lines hidden (view full) --- 219 } 220 221 stats->last = now ?: 1; 222 223 spin_unlock(&stats->lock); 224} 225 226/** |
228 * bch_next_delay() - increment @d by the amount of work done, and return how 229 * long to delay until the next time to do some work. | 227 * bch_next_delay() - update ratelimiting statistics and calculate next delay 228 * @d: the struct bch_ratelimit to update 229 * @done: the amount of work done, in arbitrary units |
230 * | 230 * |
231 * @d - the struct bch_ratelimit to update 232 * @done - the amount of work done, in arbitrary units 233 * 234 * Returns the amount of time to delay by, in jiffies | 231 * Increment @d by the amount of work done, and return how long to delay in 232 * jiffies until the next time to do some work. |
235 */ 236uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done) 237{ 238 uint64_t now = local_clock(); 239 240 d->next += div_u64(done * NSEC_PER_SEC, d->rate); 241 242 /* Bound the time. Don't let us fall further than 2 seconds behind --- 207 unchanged lines hidden --- | 233 */ 234uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done) 235{ 236 uint64_t now = local_clock(); 237 238 d->next += div_u64(done * NSEC_PER_SEC, d->rate); 239 240 /* Bound the time. Don't let us fall further than 2 seconds behind --- 207 unchanged lines hidden --- |