Lines Matching +full:open +full:- +full:pic

30  * thread-specific data to export CPU performance counters
33 * There are three access methods exported - the 'shared' device
49 * models to co-exist in a reasonable way.
55 #include <sys/open.h>
101 if (curproc->p_agenttp == curthread) { in cpc()
107 * have to grab p_lock because no-one else can change in cpc()
112 ASSERT(t->t_tid == lwpid && ttolwp(t) != NULL); in cpc()
116 if (t->t_cpc_set == NULL && (cmd == CPC_SAMPLE || cmd == CPC_RELE)) in cpc()
142 if (t->t_cpc_set != NULL) in cpc()
143 (void) kcpc_unbind(t->t_cpc_set); in cpc()
144 ASSERT(t->t_cpc_set == NULL); in cpc()
146 if ((error = kcpc_copyin_set(&t->t_cpc_set, udata1, in cpc()
152 if ((error = kcpc_verify_set(t->t_cpc_set)) != 0) { in cpc()
154 kcpc_free_set(t->t_cpc_set); in cpc()
155 t->t_cpc_set = NULL; in cpc()
156 if (copyout(&error, udata3, sizeof (error)) == -1) in cpc()
161 if ((error = kcpc_bind_thread(t->t_cpc_set, t, &code)) != 0) { in cpc()
163 kcpc_free_set(t->t_cpc_set); in cpc()
164 t->t_cpc_set = NULL; in cpc()
170 copyout(&code, udata3, sizeof (code)) == -1) in cpc()
184 * We only allow thread-bound sets to be sampled via the in cpc()
185 * syscall, so if this set has a CPU-bound context, return an in cpc()
188 if (t->t_cpc_set->ks_ctx->kc_cpuid != -1) in cpc()
190 if ((error = kcpc_sample(t->t_cpc_set, udata1, udata2, in cpc()
200 if (t->t_cpc_set == NULL) in cpc()
205 * parts. This lets us handle 64-bit values from 32-bit in cpc()
206 * and 64-bit applications in the same manner. in cpc()
209 * udata2 = new 64-bit preset (most sig. 32 bits) in cpc()
210 * udata3 = new 64-bit preset (least sig. 32 bits) in cpc()
212 if ((error = kcpc_preset(t->t_cpc_set, (intptr_t)udata1, in cpc()
218 * udata[1-3] = unused in cpc()
220 if ((error = kcpc_restart(t->t_cpc_set)) != 0) in cpc()
230 if (t != curthread || t->t_cpc_set == NULL) in cpc()
253 return (pcbe_ops->pcbe_caps); in cpc()
265 pcbe_ops->pcbe_list_events((uintptr_t)udata2)) + 1; in cpc()
268 if (suword32(udata1, size) == -1) in cpc()
272 pcbe_ops->pcbe_list_events((uintptr_t)udata2), in cpc()
273 udata1, size) == -1) in cpc()
284 * attrlist size is length of PCBE-supported attributes, plus in cpc()
287 str = pcbe_ops->pcbe_list_attrs(); in cpc()
296 if (suword32(udata1, size) == -1) in cpc()
303 if (copyout(str, udata1, strlen(str)) == -1) in cpc()
309 == -1) in cpc()
314 strlen(ATTRLIST) + 1) == -1) in cpc()
326 str = pcbe_ops->pcbe_impl_name(); in cpc()
329 str = pcbe_ops->pcbe_cpuref(); in cpc()
340 if ((error = kcpc_unbind(t->t_cpc_set)) != 0) in cpc()
352 * above is that the context handlers are -not- installed, thus
355 * Because they manipulate per-cpu state, these ioctls can
357 * who can open the relevant entry in /devices (the act of holding it open
360 * Note that for correct results, the caller -must- ensure that
361 * all existing per-lwp contexts are either inactive or marked invalid;
362 * that's what the open routine does.
380 if (curthread->t_bind_cpu != getminor(dev)) in kcpc_ioctl()
387 STRUCT_SIZE(args)) == -1) in kcpc_ioctl()
402 if (t->t_cpc_set != NULL) { in kcpc_ioctl()
403 (void) kcpc_unbind(t->t_cpc_set); in kcpc_ioctl()
404 ASSERT(t->t_cpc_set == NULL); in kcpc_ioctl()
407 if ((error = kcpc_copyin_set(&t->t_cpc_set, udata1, in kcpc_ioctl()
412 if ((error = kcpc_verify_set(t->t_cpc_set)) != 0) { in kcpc_ioctl()
413 kcpc_free_set(t->t_cpc_set); in kcpc_ioctl()
414 t->t_cpc_set = NULL; in kcpc_ioctl()
415 if (copyout(&error, udata3, sizeof (error)) == -1) in kcpc_ioctl()
420 if ((error = kcpc_bind_cpu(t->t_cpc_set, cpuid, &code)) != 0) { in kcpc_ioctl()
421 kcpc_free_set(t->t_cpc_set); in kcpc_ioctl()
422 t->t_cpc_set = NULL; in kcpc_ioctl()
427 copyout(&code, udata3, sizeof (code)) == -1) in kcpc_ioctl()
440 * Only CPU-bound sets may be sampled via the ioctl(). If this in kcpc_ioctl()
441 * set has no CPU-bound context, return an error. in kcpc_ioctl()
443 if (t->t_cpc_set == NULL) in kcpc_ioctl()
445 if ((error = kcpc_sample(t->t_cpc_set, udata1, udata2, in kcpc_ioctl()
450 if (t->t_cpc_set == NULL) in kcpc_ioctl()
452 return (kcpc_unbind(t->t_cpc_set)); in kcpc_ioctl()
459 * The device supports multiple opens, but only one open
480 if ((cpuid = curthread->t_bind_cpu) == PBIND_NONE) in kcpc_open()
493 kcpc_cpuctx--; in kcpc_open()
500 * When this device is open for processor-based contexts, in kcpc_open()
501 * no further lwp-based contexts can be created. in kcpc_open()
503 * Since this is the first open, ensure that all existing in kcpc_open()
508 kcpc_cpuctx--; in kcpc_open()
512 kcpc_cpuctx--; in kcpc_open()
530 if (--kcpc_cpuctx == 0) { in kcpc_close()
580 uint32_t setflags = (uint32_t)-1; in kcpc_copyin_set()
589 if (copyin(ubuf, packbuf, len) == -1) { in kcpc_copyin_set()
631 * There should be two members in the top-level nvlist: in kcpc_copyin_set()
651 set->ks_req = (kcpc_request_t *)kmem_zalloc(sizeof (kcpc_request_t) * in kcpc_copyin_set()
653 set->ks_nreqs = nreqs; in kcpc_copyin_set()
658 set->ks_flags = setflags; in kcpc_copyin_set()
662 set->ks_state &= ~KCPC_SET_BOUND; in kcpc_copyin_set()
665 * Build the set up one request at a time, always keeping it self- in kcpc_copyin_set()
671 set->ks_req[i].kr_picnum = -1; in kcpc_copyin_set()
679 set->ks_req[i].kr_flags = uint32; in kcpc_copyin_set()
681 set->ks_req[i].kr_index = uint32; in kcpc_copyin_set()
687 set->ks_req[i].kr_preset = uint64; in kcpc_copyin_set()
693 (void) strncpy(set->ks_req[i].kr_event, in kcpc_copyin_set()
713 set->ks_req[i].kr_picnum = uint64; in kcpc_copyin_set()
716 if ((set->ks_req[i].kr_nattrs = in kcpc_copyin_set()
720 if (set->ks_req[i].kr_nattrs > CPC_MAX_ATTRS) in kcpc_copyin_set()
723 set->ks_req[i].kr_attr = in kcpc_copyin_set()
724 kmem_alloc(set->ks_req[i].kr_nattrs * in kcpc_copyin_set()
730 attrp = &set->ks_req[i].kr_attr[j]; in kcpc_copyin_set()
736 (void) strncpy(attrp->ka_name, in kcpc_copyin_set()
741 &(attrp->ka_val)) == EINVAL) in kcpc_copyin_set()
745 ASSERT(j == set->ks_req[i].kr_nattrs); in kcpc_copyin_set()
780 * Returns a detailed error subcode, or -1 if there is no applicable subcode.
790 if (set->ks_nreqs > cpc_ncounters) in kcpc_verify_set()
791 return (-1); in kcpc_verify_set()
793 if (CPC_SET_VALID_FLAGS(set->ks_flags) == 0) in kcpc_verify_set()
794 return (-1); in kcpc_verify_set()
796 for (i = 0; i < set->ks_nreqs; i++) { in kcpc_verify_set()
797 rp = &set->ks_req[i]; in kcpc_verify_set()
801 * because kr_picnum will be -1 if the request didn't explicitly in kcpc_verify_set()
802 * choose a PIC. in kcpc_verify_set()
804 if (rp->kr_picnum >= (int)cpc_ncounters) in kcpc_verify_set()
809 * sure each PIC appears only once in set. in kcpc_verify_set()
811 if ((n = set->ks_req[i].kr_picnum) != -1) { in kcpc_verify_set()
813 return (-1); in kcpc_verify_set()
821 if (rp->kr_index < 0 || rp->kr_index >= set->ks_nreqs) in kcpc_verify_set()
822 return (-1); in kcpc_verify_set()
827 if (KCPC_REQ_VALID_FLAGS(rp->kr_flags) == 0) in kcpc_verify_set()
931 "32-bit cpc sampling system call",