Lines Matching defs:cpc
55 static void cpc_err(cpc_t *cpc, const char *fn, int subcode, ...);
56 static int cpc_set_valid(cpc_t *cpc, cpc_set_t *set);
57 static int cpc_lock(cpc_t *cpc);
58 static void cpc_unlock(cpc_t *cpc, int blocked);
59 static int cpc_valid_event(cpc_t *cpc, uint_t pic, const char *ev);
60 static int cpc_valid_attr(cpc_t *cpc, char *attr);
61 static void cpc_invalidate_pctx(cpc_t *cpc, pctx_t *pctx);
66 cpc_t *cpc;
99 if ((cpc = malloc(sizeof (cpc_t))) == NULL) {
104 cpc->cpc_npic = syscall(SYS_cpc, CPC_NPIC, -1, 0, 0, 0);
105 cpc->cpc_caps = syscall(SYS_cpc, CPC_CAPS, -1, 0, 0, 0);
107 if (syscall(SYS_cpc, CPC_IMPL_NAME, -1, &cpc->cpc_cciname, 0, 0) != 0)
109 if (syscall(SYS_cpc, CPC_CPUREF, -1, &cpc->cpc_cpuref, 0, 0) != 0)
113 if ((cpc->cpc_attrlist = cpc_get_list(CPC_LIST_ATTRS, 0)) == NULL) {
114 free(cpc);
118 if ((cpc->cpc_evlist = malloc(cpc->cpc_npic * sizeof (char *))) ==
120 free(cpc->cpc_attrlist);
121 free(cpc);
125 for (i = 0; i < cpc->cpc_npic; i++) {
126 if ((cpc->cpc_evlist[i] = cpc_get_list(CPC_LIST_EVENTS, i)) ==
130 if (i != cpc->cpc_npic) {
132 free(cpc->cpc_evlist[j]);
133 free(cpc->cpc_evlist);
134 free(cpc->cpc_attrlist);
135 free(cpc);
139 cpc->cpc_sets = NULL;
140 cpc->cpc_bufs = NULL;
141 cpc->cpc_errfn = NULL;
142 (void) mutex_init(&cpc->cpc_lock, USYNC_THREAD, NULL);
145 return (cpc);
156 cpc_close(cpc_t *cpc)
158 while (cpc->cpc_sets != NULL) {
159 if (cpc->cpc_sets->cs_state != CS_UNBOUND)
160 (void) cpc_unbind(cpc, cpc->cpc_sets);
161 (void) cpc_set_destroy(cpc, cpc->cpc_sets);
164 while (cpc->cpc_bufs != NULL)
165 (void) cpc_buf_destroy(cpc, cpc->cpc_bufs);
167 free(cpc);
175 cpc_terminate(cpc_t *cpc)
180 sigblocked = cpc_lock(cpc);
181 for (csp = cpc->cpc_sets; csp != NULL; csp = csp->cs_next) {
185 cpc_unlock(cpc, sigblocked);
189 cpc_set_create(cpc_t *cpc)
207 sigblocked = cpc_lock(cpc);
208 set->cs_next = cpc->cpc_sets;
209 cpc->cpc_sets = set;
210 cpc_unlock(cpc, sigblocked);
216 cpc_set_destroy(cpc_t *cpc, cpc_set_t *set)
223 * Remove this set from the cpc handle's list of sets.
225 sigblocked = cpc_lock(cpc);
226 for (csp = prev = cpc->cpc_sets; csp != NULL; csp = csp->cs_next) {
232 cpc_unlock(cpc, sigblocked);
236 if (csp == cpc->cpc_sets)
237 cpc->cpc_sets = csp->cs_next;
239 cpc_unlock(cpc, sigblocked);
242 (void) cpc_unbind(cpc, csp);
269 cpc_set_add_request(cpc_t *cpc, cpc_set_t *set, const char *event,
275 int npics = cpc_npic(cpc);
277 if (cpc_set_valid(cpc, set) != 0 || set->cs_state != CS_UNBOUND) {
283 if (cpc_valid_event(cpc, i, event))
286 cpc_err(cpc, fn, CPC_INVALID_EVENT);
309 cpc_valid_attr(cpc, attrs[i].ca_name) == 0) {
310 cpc_err(cpc, fn, CPC_INVALID_ATTRIBUTE);
320 cpc_err(cpc, fn, CPC_INVALID_PICNUM);
324 if (cpc_valid_event(cpc, attrs[i].ca_val,
326 cpc_err(cpc, fn, CPC_PIC_NOT_CAPABLE);
359 cpc_buf_create(cpc_t *cpc, cpc_set_t *set)
364 if (cpc_set_valid(cpc, set) != 0) {
383 sigblocked = cpc_lock(cpc);
384 buf->cb_next = cpc->cpc_bufs;
385 cpc->cpc_bufs = buf;
386 cpc_unlock(cpc, sigblocked);
392 cpc_buf_destroy(cpc_t *cpc, cpc_buf_t *buf)
398 * Remove this buf from the cpc handle's list of bufs.
400 sigblocked = cpc_lock(cpc);
401 for (cbp = prev = cpc->cpc_bufs; cbp != NULL; cbp = cbp->cb_next) {
407 cpc_unlock(cpc, sigblocked);
411 if (cbp == cpc->cpc_bufs)
412 cpc->cpc_bufs = cbp->cb_next;
415 cpc_unlock(cpc, sigblocked);
424 cpc_bind_curlwp(cpc_t *cpc, cpc_set_t *set, uint_t flags)
451 cpc_err(cpc, "cpc_bind_curlwp", subcode);
462 cpc_bind_pctx(cpc_t *cpc, pctx_t *pctx, id_t id, cpc_set_t *set, uint_t flags)
472 if (flags != 0 || cpc_set_valid(cpc, set) != 0 || set->cs_nreqs <= 0) {
482 ret = __pctx_cpc(pctx, cpc, CPC_BIND, id, packed_set, (void *)packsize,
492 cpc_err(cpc, "cpc_bind_pctx", subcode);
499 cpc_bind_cpu(cpc_t *cpc, processorid_t id, cpc_set_t *set, uint_t flags)
512 if (flags != 0 || cpc_set_valid(cpc, set) != 0 || set->cs_nreqs <= 0) {
518 cpc_err(cpc, fn, CPC_PBIND_FAILED);
555 cpc_err(cpc, fn, subcode);
570 cpc_request_preset(cpc_t *cpc, int index, uint64_t preset)
578 cpc_set_restart(cpc_t *cpc, cpc_set_t *set)
585 cpc_unbind(cpc_t *cpc, cpc_set_t *set)
590 if (cpc_set_valid(cpc, set) != 0) {
612 ret = __pctx_cpc(set->cs_pctx, cpc, CPC_RELE,
629 cpc_set_sample(cpc_t *cpc, cpc_set_t *set, cpc_buf_t *buf)
654 return (__pctx_cpc(set->cs_pctx, cpc, CPC_SAMPLE, set->cs_id,
665 cpc_buf_sub(cpc_t *cpc, cpc_buf_t *ds, cpc_buf_t *a, cpc_buf_t *b)
682 cpc_buf_add(cpc_t *cpc, cpc_buf_t *ds, cpc_buf_t *a, cpc_buf_t *b)
699 cpc_buf_copy(cpc_t *cpc, cpc_buf_t *ds, cpc_buf_t *src)
711 cpc_buf_zero(cpc_t *cpc, cpc_buf_t *buf)
723 cpc_buf_get(cpc_t *cpc, cpc_buf_t *buf, int index, uint64_t *val)
732 cpc_buf_set(cpc_t *cpc, cpc_buf_t *buf, int index, uint64_t val)
741 cpc_buf_hrtime(cpc_t *cpc, cpc_buf_t *buf)
748 cpc_buf_tick(cpc_t *cpc, cpc_buf_t *buf)
781 cpc_walk_requests(cpc_t *cpc, cpc_set_t *set, void *arg,
812 cpc_walk_events_impl(cpc_t *cpc, void *arg,
819 int ncounters = cpc_npic(cpc);
831 if ((list[i] = strdup(cpc->cpc_evlist[i])) == NULL)
872 cpc_walk_events_all(cpc_t *cpc, void *arg,
875 cpc_walk_events_impl(cpc, arg, action, 0);
881 cpc_walk_generic_events_all(cpc_t *cpc, void *arg,
884 cpc_walk_events_impl(cpc, arg, action, 1);
889 cpc_walk_events_pic_impl(cpc_t *cpc, uint_t picno, void *arg,
897 if (picno >= cpc->cpc_npic) {
902 if ((list = strdup(cpc->cpc_evlist[picno])) == NULL)
936 cpc_walk_events_pic(cpc_t *cpc, uint_t picno, void *arg,
939 cpc_walk_events_pic_impl(cpc, picno, arg, action, 0);
944 cpc_walk_generic_events_pic(cpc_t *cpc, uint_t picno, void *arg,
947 cpc_walk_events_pic_impl(cpc, picno, arg, action, 1);
952 cpc_walk_attrs(cpc_t *cpc, void *arg,
959 if ((list = strdup(cpc->cpc_attrlist)) == NULL)
985 cpc_enable(cpc_t *cpc)
992 cpc_disable(cpc_t *cpc)
999 cpc_npic(cpc_t *cpc)
1001 return (cpc->cpc_npic);
1006 cpc_caps(cpc_t *cpc)
1008 return (cpc->cpc_caps);
1012 cpc_cciname(cpc_t *cpc)
1014 return (cpc->cpc_cciname);
1018 cpc_cpuref(cpc_t *cpc)
1020 return (cpc->cpc_cpuref);
1024 cpc_seterrhndlr(cpc_t *cpc, cpc_errhndlr_t *fn)
1026 cpc->cpc_errfn = fn;
1050 cpc_err(cpc_t *cpc, const char *fn, int subcode, ...)
1071 if (cpc->cpc_errfn != NULL)
1072 cpc->cpc_errfn(fn, subcode, str, ap);
1092 cpc_invalidate_pctx(cpc_t *cpc, pctx_t *pctx)
1097 sigblocked = cpc_lock(cpc);
1098 for (set = cpc->cpc_sets; set != NULL; set = set->cs_next)
1101 cpc_unlock(cpc, sigblocked);
1105 * Check that the set is valid; if so it will be in the cpc handle's
1110 cpc_set_valid(cpc_t *cpc, cpc_set_t *set)
1115 sigblocked = cpc_lock(cpc);
1116 for (csp = cpc->cpc_sets; csp != NULL; csp = csp->cs_next)
1119 cpc_unlock(cpc, sigblocked);
1126 cpc_lock(cpc_t *cpc)
1129 (void) mutex_lock(&cpc->cpc_lock);
1134 cpc_unlock(cpc_t *cpc, int sigblocked)
1136 (void) mutex_unlock(&cpc->cpc_lock);
1162 cpc_valid_event(cpc_t *cpc, uint_t pic, const char *ev)
1169 cpc_walk_events_pic(cpc, pic, &pr, ev_walker);
1173 cpc_walk_generic_events_pic(cpc, pic, &pr, ev_walker);
1199 cpc_valid_attr(cpc_t *cpc, char *attr)
1204 cpc_walk_attrs(cpc, &pr, at_walker);