• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/lib/

Lines Matching refs:lc

41 	BUG_ON(!lc);			\
42 BUG_ON(!lc->nr_elements); \
43 BUG_ON(test_and_set_bit(__LC_PARANOIA, &lc->flags)); \
47 clear_bit(__LC_PARANOIA, &lc->flags); \
50 /* BUG() if e is not one of the elements tracked by lc */
51 #define PARANOIA_LC_ELEMENT(lc, e) do { \
52 struct lru_cache *lc_ = (lc); \
73 struct lru_cache *lc;
94 lc = kzalloc(sizeof(*lc), GFP_KERNEL);
95 if (!lc)
98 INIT_LIST_HEAD(&lc->in_use);
99 INIT_LIST_HEAD(&lc->lru);
100 INIT_LIST_HEAD(&lc->free);
102 lc->name = name;
103 lc->element_size = e_size;
104 lc->element_off = e_off;
105 lc->nr_elements = e_count;
106 lc->new_number = LC_FREE;
107 lc->lc_cache = cache;
108 lc->lc_element = element;
109 lc->lc_slot = slot;
116 memset(p, 0, lc->element_size);
120 list_add(&e->list, &lc->free);
124 return lc;
131 kfree(lc);
138 void lc_free_by_index(struct lru_cache *lc, unsigned i)
140 void *p = lc->lc_element[i];
143 p -= lc->element_off;
144 kmem_cache_free(lc->lc_cache, p);
150 * @lc: the lru cache to destroy
152 void lc_destroy(struct lru_cache *lc)
155 if (!lc)
157 for (i = 0; i < lc->nr_elements; i++)
158 lc_free_by_index(lc, i);
159 kfree(lc->lc_element);
160 kfree(lc->lc_slot);
161 kfree(lc);
165 * lc_reset - does a full reset for @lc and the hash table slots.
166 * @lc: the lru cache to operate on
169 * basically a short cut to lc_destroy(lc); lc = lc_create(...);
171 void lc_reset(struct lru_cache *lc)
175 INIT_LIST_HEAD(&lc->in_use);
176 INIT_LIST_HEAD(&lc->lru);
177 INIT_LIST_HEAD(&lc->free);
178 lc->used = 0;
179 lc->hits = 0;
180 lc->misses = 0;
181 lc->starving = 0;
182 lc->dirty = 0;
183 lc->changed = 0;
184 lc->flags = 0;
185 lc->changing_element = NULL;
186 lc->new_number = LC_FREE;
187 memset(lc->lc_slot, 0, sizeof(struct hlist_head) * lc->nr_elements);
189 for (i = 0; i < lc->nr_elements; i++) {
190 struct lc_element *e = lc->lc_element[i];
192 p -= lc->element_off;
193 memset(p, 0, lc->element_size);
197 list_add(&e->list, &lc->free);
202 * lc_seq_printf_stats - print stats about @lc into @seq
204 * @lc: the lru cache to print statistics of
206 size_t lc_seq_printf_stats(struct seq_file *seq, struct lru_cache *lc)
217 lc->name, lc->used, lc->nr_elements,
218 lc->hits, lc->misses, lc->starving, lc->dirty, lc->changed);
221 static struct hlist_head *lc_hash_slot(struct lru_cache *lc, unsigned int enr)
223 return lc->lc_slot + (enr % lc->nr_elements);
229 * @lc: The lru_cache object
236 struct lc_element *lc_find(struct lru_cache *lc, unsigned int enr)
241 BUG_ON(!lc);
242 BUG_ON(!lc->nr_elements);
243 hlist_for_each_entry(e, n, lc_hash_slot(lc, enr), colision) {
251 static struct lc_element *lc_evict(struct lru_cache *lc)
256 if (list_empty(&lc->lru))
259 n = lc->lru.prev;
262 PARANOIA_LC_ELEMENT(lc, e);
271 * @lc: The lru_cache object
277 void lc_del(struct lru_cache *lc, struct lc_element *e)
280 PARANOIA_LC_ELEMENT(lc, e);
285 list_move(&e->list, &lc->free);
289 static struct lc_element *lc_get_unused_element(struct lru_cache *lc)
293 if (list_empty(&lc->free))
294 return lc_evict(lc);
296 n = lc->free.next;
301 static int lc_unused_element_available(struct lru_cache *lc)
303 if (!list_empty(&lc->free))
305 if (!list_empty(&lc->lru))
314 * @lc: the lru cache to operate on
329 * and a changing transaction is still pending (@lc was marked %LC_DIRTY).
330 * Or no unused or free element could be recycled (@lc will be marked as
343 * Then he must call lc_changed(lc,element_pointer), to finish
349 struct lc_element *lc_get(struct lru_cache *lc, unsigned int enr)
354 if (lc->flags & LC_STARVING) {
355 ++lc->starving;
359 e = lc_find(lc, enr);
361 ++lc->hits;
363 lc->used++;
364 list_move(&e->list, &lc->in_use); /* Not evictable... */
368 ++lc->misses;
373 if (!lc_unused_element_available(lc)) {
374 __set_bit(__LC_STARVING, &lc->flags);
382 if (test_and_set_bit(__LC_DIRTY, &lc->flags)) {
383 ++lc->dirty;
387 e = lc_get_unused_element(lc);
390 clear_bit(__LC_STARVING, &lc->flags);
392 lc->used++;
394 lc->changing_element = e;
395 lc->new_number = enr;
405 struct lc_element *lc_try_get(struct lru_cache *lc, unsigned int enr)
410 if (lc->flags & LC_STARVING) {
411 ++lc->starving;
415 e = lc_find(lc, enr);
417 ++lc->hits;
419 lc->used++;
420 list_move(&e->list, &lc->in_use); /* Not evictable... */
426 * lc_changed - tell @lc that the change has been recorded
427 * @lc: the lru cache to operate on
430 void lc_changed(struct lru_cache *lc, struct lc_element *e)
433 BUG_ON(e != lc->changing_element);
434 PARANOIA_LC_ELEMENT(lc, e);
435 ++lc->changed;
436 e->lc_number = lc->new_number;
437 list_add(&e->list, &lc->in_use);
438 hlist_add_head(&e->colision, lc_hash_slot(lc, lc->new_number));
439 lc->changing_element = NULL;
440 lc->new_number = LC_FREE;
441 clear_bit(__LC_DIRTY, &lc->flags);
449 * @lc: the lru cache to operate on
456 unsigned int lc_put(struct lru_cache *lc, struct lc_element *e)
459 PARANOIA_LC_ELEMENT(lc, e);
461 BUG_ON(e == lc->changing_element);
464 list_move(&e->list, &lc->lru);
465 lc->used--;
466 clear_bit(__LC_STARVING, &lc->flags);
474 * @lc: the lru cache to operate on
477 struct lc_element *lc_element_by_index(struct lru_cache *lc, unsigned i)
479 BUG_ON(i >= lc->nr_elements);
480 BUG_ON(lc->lc_element[i] == NULL);
481 BUG_ON(lc->lc_element[i]->lc_index != i);
482 return lc->lc_element[i];
487 * @lc: the lru cache to operate on
488 * @e: the element to query for its index position in lc->element
490 unsigned int lc_index_of(struct lru_cache *lc, struct lc_element *e)
492 PARANOIA_LC_ELEMENT(lc, e);
498 * @lc: the lru cache to operate on
504 void lc_set(struct lru_cache *lc, unsigned int enr, int index)
508 if (index < 0 || index >= lc->nr_elements)
511 e = lc_element_by_index(lc, index);
515 hlist_add_head(&e->colision, lc_hash_slot(lc, enr));
516 list_move(&e->list, e->refcnt ? &lc->in_use : &lc->lru);
521 * @lc: the lru cache to operate on
527 void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext,
530 unsigned int nr_elements = lc->nr_elements;
536 e = lc_element_by_index(lc, i);