• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-13-stable/contrib/processor-trace/libipt/src/

Lines Matching refs:iscache

57 int pt_iscache_init(struct pt_image_section_cache *iscache, const char *name)
59 if (!iscache)
62 memset(iscache, 0, sizeof(*iscache));
63 iscache->limit = UINT64_MAX;
65 iscache->name = dupstr(name);
66 if (!iscache->name)
74 errcode = mtx_init(&iscache->lock, mtx_plain);
83 void pt_iscache_fini(struct pt_image_section_cache *iscache)
85 if (!iscache)
88 (void) pt_iscache_clear(iscache);
89 free(iscache->name);
93 mtx_destroy(&iscache->lock);
98 static inline int pt_iscache_lock(struct pt_image_section_cache *iscache)
100 if (!iscache)
107 errcode = mtx_lock(&iscache->lock);
116 static inline int pt_iscache_unlock(struct pt_image_section_cache *iscache)
118 if (!iscache)
125 errcode = mtx_unlock(&iscache->lock);
139 static int pt_iscache_expand(struct pt_image_section_cache *iscache)
144 if (!iscache)
147 capacity = iscache->capacity;
154 entries = realloc(iscache->entries, target * sizeof(*entries));
158 iscache->capacity = target;
159 iscache->entries = entries;
163 static int pt_iscache_find_locked(struct pt_image_section_cache *iscache,
169 if (!iscache || !filename)
172 end = iscache->size;
179 entry = &iscache->entries[idx];
230 static int pt_iscache_lru_prune(struct pt_image_section_cache *iscache,
236 if (!iscache || !tail)
239 limit = iscache->limit;
242 pnext = &iscache->lru;
250 iscache->used = used - lru->size;
261 /* Add @section to the front of @iscache->lru.
267 static int pt_isache_lru_new(struct pt_image_section_cache *iscache,
274 if (!iscache)
284 limit = iscache->limit;
301 lru->next = iscache->lru;
302 iscache->lru = lru;
304 used = iscache->used;
309 iscache->used = total;
314 /* Add or move @section to the front of @iscache->lru.
320 static int pt_iscache_lru_add(struct pt_image_section_cache *iscache,
325 if (!iscache)
328 pnext = &iscache->lru;
336 lru->next = iscache->lru;
337 iscache->lru = lru;
343 return pt_isache_lru_new(iscache, section);
347 /* Remove @section from @iscache->lru.
351 static int pt_iscache_lru_remove(struct pt_image_section_cache *iscache,
356 if (!iscache)
359 pnext = &iscache->lru;
375 /* Add or move @section to the front of @iscache->lru and update its size.
381 static int pt_iscache_lru_resize(struct pt_image_section_cache *iscache,
388 if (!iscache)
391 status = pt_iscache_lru_add(iscache, section);
395 lru = iscache->lru;
407 if (iscache->limit < memsize)
420 used = iscache->used;
424 iscache->used = used;
426 return (iscache->limit < used) ? 1 : 0;
429 /* Clear @iscache->lru.
431 * Unlike other iscache_lru functions, the caller does not lock @iscache.
435 static int pt_iscache_lru_clear(struct pt_image_section_cache *iscache)
440 errcode = pt_iscache_lock(iscache);
444 lru = iscache->lru;
445 iscache->lru = NULL;
446 iscache->used = 0ull;
448 errcode = pt_iscache_unlock(iscache);
455 /* Search @iscache for a partial or exact match of @section loaded at @laddr and
456 * return the corresponding index or @iscache->size if no match is found.
458 * The caller must lock @iscache.
463 pt_iscache_find_section_locked(const struct pt_image_section_cache *iscache,
471 if (!iscache || !filename)
475 match = end = iscache->size;
480 entry = &iscache->entries[idx];
524 int pt_iscache_add(struct pt_image_section_cache *iscache,
532 if (!iscache || !section)
551 * and require taking the iscache lock.
553 * Hence we can't attach to a section while holding the iscache lock.
556 * We therefore attach to @section first and then lock @iscache.
559 * from @iscache and replaced by a new matching section. We would want
562 * After locking @iscache, we therefore check for existing matching
566 * And for this, we will have to temporarily unlock @iscache again.
572 errcode = pt_section_attach(section, iscache);
576 errcode = pt_iscache_lock(iscache);
601 match = pt_iscache_find_section_locked(iscache, filename,
609 if (iscache->size <= match)
612 entry = &iscache->entries[match];
622 errcode = pt_iscache_unlock(iscache);
626 errcode = pt_section_detach(section, iscache);
643 * requires temporarily unlocking @iscache.
645 * We further need to remove @section from @iscache->lru.
651 errcode = pt_iscache_unlock(iscache);
657 errcode = pt_section_detach(section, iscache);
663 errcode = pt_section_attach(sec, iscache);
669 errcode = pt_iscache_lock(iscache);
678 * may have added @section to @iscache->lru.
683 errcode = pt_iscache_lru_remove(iscache, section);
707 if (iscache->capacity <= iscache->size) {
709 if (iscache->capacity < iscache->size) {
714 errcode = pt_iscache_expand(iscache);
719 if (iscache->capacity <= iscache->size) {
727 * This hands both attach and reference over to @iscache. We will
730 idx = iscache->size++;
732 iscache->entries[idx].section = section;
733 iscache->entries[idx].laddr = laddr;
735 errcode = pt_iscache_unlock(iscache);
742 (void) pt_iscache_unlock(iscache);
745 (void) pt_section_detach(section, iscache);
748 (void) pt_iscache_lru_clear(iscache);
756 int pt_iscache_find(struct pt_image_section_cache *iscache,
762 errcode = pt_iscache_lock(iscache);
766 isid = pt_iscache_find_locked(iscache, filename, offset, size, laddr);
768 errcode = pt_iscache_unlock(iscache);
775 int pt_iscache_lookup(struct pt_image_section_cache *iscache,
781 if (!iscache || !section || !laddr)
793 errcode = pt_iscache_lock(iscache);
797 if (iscache->size <= index)
802 entry = &iscache->entries[index];
809 errcode = pt_iscache_unlock(iscache);
816 int pt_iscache_clear(struct pt_image_section_cache *iscache)
823 if (!iscache)
826 errcode = pt_iscache_lock(iscache);
830 entries = iscache->entries;
831 end = iscache->size;
832 lru = iscache->lru;
834 iscache->entries = NULL;
835 iscache->capacity = 0;
836 iscache->size = 0;
837 iscache->lru = NULL;
838 iscache->used = 0ull;
840 errcode = pt_iscache_unlock(iscache);
856 errcode = pt_section_detach(section, iscache);
871 struct pt_image_section_cache *iscache;
873 iscache = malloc(sizeof(*iscache));
874 if (iscache)
875 pt_iscache_init(iscache, name);
877 return iscache;
880 void pt_iscache_free(struct pt_image_section_cache *iscache)
882 if (!iscache)
885 pt_iscache_fini(iscache);
886 free(iscache);
889 int pt_iscache_set_limit(struct pt_image_section_cache *iscache, uint64_t limit)
894 if (!iscache)
900 errcode = pt_iscache_lock(iscache);
904 iscache->limit = limit;
905 if (limit < iscache->used)
906 status = pt_iscache_lru_prune(iscache, &tail);
908 errcode = pt_iscache_unlock(iscache);
916 const char *pt_iscache_name(const struct pt_image_section_cache *iscache)
918 if (!iscache)
921 return iscache->name;
924 int pt_iscache_add_file(struct pt_image_section_cache *iscache,
931 if (!iscache || !filename)
934 errcode = pt_iscache_lock(iscache);
938 match = pt_iscache_find_section_locked(iscache, filename, offset,
941 (void) pt_iscache_unlock(iscache);
952 if (match < iscache->size) {
955 entry = &iscache->entries[match];
957 errcode = pt_iscache_unlock(iscache);
968 (void) pt_iscache_unlock(iscache);
972 errcode = pt_iscache_unlock(iscache);
978 errcode = pt_iscache_unlock(iscache);
988 /* We unlocked @iscache and hold a reference to @section. */
989 isid = pt_iscache_add(iscache, section, vaddr);
1002 int pt_iscache_read(struct pt_image_section_cache *iscache, uint8_t *buffer,
1009 if (!iscache || !buffer || !size)
1012 errcode = pt_iscache_lookup(iscache, &section, &laddr, isid);
1050 int pt_iscache_notify_map(struct pt_image_section_cache *iscache,
1058 errcode = pt_iscache_lock(iscache);
1062 status = pt_iscache_lru_add(iscache, section);
1064 status = pt_iscache_lru_prune(iscache, &tail);
1066 errcode = pt_iscache_unlock(iscache);
1074 int pt_iscache_notify_resize(struct pt_image_section_cache *iscache,
1082 errcode = pt_iscache_lock(iscache);
1086 status = pt_iscache_lru_resize(iscache, section, memsize);
1088 status = pt_iscache_lru_prune(iscache, &tail);
1090 errcode = pt_iscache_unlock(iscache);