Lines Matching defs:cpc

54 static void cpc_err(cpc_t *cpc, const char *fn, int subcode, ...);
55 static int cpc_set_valid(cpc_t *cpc, cpc_set_t *set);
56 static int cpc_rdlock(cpc_t *cpc);
57 static int cpc_wrlock(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) rwlock_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_wrlock(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)
210 sigblocked = cpc_wrlock(cpc);
211 set->cs_next = cpc->cpc_sets;
212 cpc->cpc_sets = set;
213 cpc_unlock(cpc, sigblocked);
219 cpc_set_destroy(cpc_t *cpc, cpc_set_t *set)
226 * Remove this set from the cpc handle's list of sets.
228 sigblocked = cpc_wrlock(cpc);
229 for (csp = prev = cpc->cpc_sets; csp != NULL; csp = csp->cs_next) {
235 cpc_unlock(cpc, sigblocked);
239 if (csp == cpc->cpc_sets)
240 cpc->cpc_sets = csp->cs_next;
242 cpc_unlock(cpc, sigblocked);
245 (void) cpc_unbind(cpc, csp);
274 cpc_set_add_request(cpc_t *cpc, cpc_set_t *set, const char *event,
280 int npics = cpc_npic(cpc);
282 if (cpc_set_valid(cpc, set) != 0 || set->cs_state != CS_UNBOUND) {
288 if (cpc_valid_event(cpc, i, event))
291 cpc_err(cpc, fn, CPC_INVALID_EVENT);
314 cpc_valid_attr(cpc, attrs[i].ca_name) == 0) {
315 cpc_err(cpc, fn, CPC_INVALID_ATTRIBUTE);
325 cpc_err(cpc, fn, CPC_INVALID_PICNUM);
329 if (cpc_valid_event(cpc, attrs[i].ca_val,
331 cpc_err(cpc, fn, CPC_PIC_NOT_CAPABLE);
383 cpc_buf_create(cpc_t *cpc, cpc_set_t *set)
388 if (cpc_set_valid(cpc, set) != 0) {
407 sigblocked = cpc_wrlock(cpc);
408 buf->cb_next = cpc->cpc_bufs;
409 cpc->cpc_bufs = buf;
410 cpc_unlock(cpc, sigblocked);
416 cpc_buf_destroy(cpc_t *cpc, cpc_buf_t *buf)
422 * Remove this buf from the cpc handle's list of bufs.
424 sigblocked = cpc_wrlock(cpc);
425 for (cbp = prev = cpc->cpc_bufs; cbp != NULL; cbp = cbp->cb_next) {
431 cpc_unlock(cpc, sigblocked);
435 if (cbp == cpc->cpc_bufs)
436 cpc->cpc_bufs = cbp->cb_next;
439 cpc_unlock(cpc, sigblocked);
448 cpc_bind_curlwp(cpc_t *cpc, cpc_set_t *set, uint_t flags)
490 cpc_err(cpc, "cpc_bind_curlwp", subcode);
501 cpc_bind_pctx(cpc_t *cpc, pctx_t *pctx, id_t id, cpc_set_t *set, uint_t flags)
509 if (flags != 0 || cpc_set_valid(cpc, set) != 0 || set->cs_nreqs <= 0) {
522 ret = __pctx_cpc(pctx, cpc, CPC_BIND, id, set->cs_packed,
530 cpc_err(cpc, "cpc_bind_pctx", subcode);
537 cpc_bind_cpu(cpc_t *cpc, processorid_t id, cpc_set_t *set, uint_t flags)
545 if ((cpc_set_valid(cpc, set) != 0) ||
568 cpc_err(cpc, fn, CPC_PBIND_FAILED);
598 cpc_err(cpc, fn, subcode);
614 cpc_request_preset(cpc_t *cpc, int index, uint64_t preset)
622 cpc_set_restart(cpc_t *cpc, cpc_set_t *set)
629 cpc_unbind(cpc_t *cpc, cpc_set_t *set)
634 if (cpc_set_valid(cpc, set) != 0) {
658 ret = __pctx_cpc(set->cs_pctx, cpc, CPC_RELE,
675 cpc_set_sample(cpc_t *cpc, cpc_set_t *set, cpc_buf_t *buf)
700 return (__pctx_cpc(set->cs_pctx, cpc, CPC_SAMPLE, set->cs_id,
711 cpc_buf_sub(cpc_t *cpc, cpc_buf_t *ds, cpc_buf_t *a, cpc_buf_t *b)
728 cpc_buf_add(cpc_t *cpc, cpc_buf_t *ds, cpc_buf_t *a, cpc_buf_t *b)
745 cpc_buf_copy(cpc_t *cpc, cpc_buf_t *ds, cpc_buf_t *src)
757 cpc_buf_zero(cpc_t *cpc, cpc_buf_t *buf)
769 cpc_buf_get(cpc_t *cpc, cpc_buf_t *buf, int index, uint64_t *val)
778 cpc_buf_set(cpc_t *cpc, cpc_buf_t *buf, int index, uint64_t val)
787 cpc_buf_hrtime(cpc_t *cpc, cpc_buf_t *buf)
794 cpc_set_hrtime(cpc_t *cpc, cpc_buf_t *buf, uint64_t hrtime)
801 cpc_buf_tick(cpc_t *cpc, cpc_buf_t *buf)
808 cpc_set_tick(cpc_t *cpc, cpc_buf_t *buf, uint64_t ticks)
841 cpc_walk_requests(cpc_t *cpc, cpc_set_t *set, void *arg,
872 cpc_walk_events_impl(cpc_t *cpc, void *arg,
879 int ncounters = cpc_npic(cpc);
891 if ((list[i] = strdup(cpc->cpc_evlist[i])) == NULL)
932 cpc_walk_events_all(cpc_t *cpc, void *arg,
935 cpc_walk_events_impl(cpc, arg, action, 0);
941 cpc_walk_generic_events_all(cpc_t *cpc, void *arg,
944 cpc_walk_events_impl(cpc, arg, action, 1);
949 cpc_walk_events_pic_impl(cpc_t *cpc, uint_t picno, void *arg,
957 if (picno >= cpc->cpc_npic) {
962 if ((list = strdup(cpc->cpc_evlist[picno])) == NULL)
996 cpc_walk_events_pic(cpc_t *cpc, uint_t picno, void *arg,
999 cpc_walk_events_pic_impl(cpc, picno, arg, action, 0);
1004 cpc_walk_generic_events_pic(cpc_t *cpc, uint_t picno, void *arg,
1007 cpc_walk_events_pic_impl(cpc, picno, arg, action, 1);
1012 cpc_walk_attrs(cpc_t *cpc, void *arg,
1019 if ((list = strdup(cpc->cpc_attrlist)) == NULL)
1045 cpc_enable(cpc_t *cpc)
1052 cpc_disable(cpc_t *cpc)
1059 cpc_npic(cpc_t *cpc)
1061 return (cpc->cpc_npic);
1066 cpc_caps(cpc_t *cpc)
1068 return (cpc->cpc_caps);
1072 cpc_cciname(cpc_t *cpc)
1074 return (cpc->cpc_cciname);
1078 cpc_cpuref(cpc_t *cpc)
1080 return (cpc->cpc_cpuref);
1084 cpc_seterrhndlr(cpc_t *cpc, cpc_errhndlr_t *fn)
1086 cpc->cpc_errfn = fn;
1110 cpc_err(cpc_t *cpc, const char *fn, int subcode, ...)
1131 if (cpc->cpc_errfn != NULL)
1132 cpc->cpc_errfn(fn, subcode, str, ap);
1152 cpc_invalidate_pctx(cpc_t *cpc, pctx_t *pctx)
1157 sigblocked = cpc_wrlock(cpc);
1158 for (set = cpc->cpc_sets; set != NULL; set = set->cs_next)
1161 cpc_unlock(cpc, sigblocked);
1165 * Check that the set is valid; if so it will be in the cpc handle's
1170 cpc_set_valid(cpc_t *cpc, cpc_set_t *set)
1175 sigblocked = cpc_rdlock(cpc);
1176 for (csp = cpc->cpc_sets; csp != NULL; csp = csp->cs_next)
1179 cpc_unlock(cpc, sigblocked);
1186 cpc_rdlock(cpc_t *cpc)
1189 (void) rw_rdlock(&cpc->cpc_lock);
1194 cpc_wrlock(cpc_t *cpc)
1197 (void) rw_wrlock(&cpc->cpc_lock);
1202 cpc_unlock(cpc_t *cpc, int sigblocked)
1204 (void) rw_unlock(&cpc->cpc_lock);
1230 cpc_valid_event(cpc_t *cpc, uint_t pic, const char *ev)
1237 cpc_walk_events_pic(cpc, pic, &pr, ev_walker);
1241 cpc_walk_generic_events_pic(cpc, pic, &pr, ev_walker);
1267 cpc_valid_attr(cpc_t *cpc, char *attr)
1272 cpc_walk_attrs(cpc, &pr, at_walker);