Lines Matching refs:ctx

83 static void kcpc_ctx_clone(kcpc_ctx_t *ctx, kcpc_ctx_t *cctx);
96 #define KCPC_CTX_FLAG_SET(ctx, flag) atomic_or_uint(&(ctx)->kc_flags, (flag)) argument
97 #define KCPC_CTX_FLAG_CLR(ctx, flag) atomic_and_uint(&(ctx)->kc_flags, ~(flag)) argument
184 kcpc_ctx_t *ctx; in kcpc_bind_cpu() local
188 ctx = kcpc_ctx_alloc(KM_SLEEP); in kcpc_bind_cpu()
190 if (kcpc_assign_reqs(set, ctx) != 0) { in kcpc_bind_cpu()
191 kcpc_ctx_free(ctx); in kcpc_bind_cpu()
196 ctx->kc_cpuid = cpuid; in kcpc_bind_cpu()
197 ctx->kc_thread = curthread; in kcpc_bind_cpu()
201 if ((error = kcpc_configure_reqs(ctx, set, subcode)) != 0) { in kcpc_bind_cpu()
203 kcpc_ctx_free(ctx); in kcpc_bind_cpu()
207 set->ks_ctx = ctx; in kcpc_bind_cpu()
208 ctx->kc_set = set; in kcpc_bind_cpu()
250 kcpc_program(ctx, B_FALSE, B_TRUE); in kcpc_bind_cpu()
269 kcpc_ctx_free(ctx); in kcpc_bind_cpu()
276 kcpc_ctx_t *ctx; in kcpc_bind_thread() local
287 ctx = kcpc_ctx_alloc(KM_SLEEP); in kcpc_bind_thread()
294 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_FREEZE); in kcpc_bind_thread()
295 ctx->kc_hrtime = gethrtime(); in kcpc_bind_thread()
297 if (kcpc_assign_reqs(set, ctx) != 0) { in kcpc_bind_thread()
298 kcpc_ctx_free(ctx); in kcpc_bind_thread()
303 ctx->kc_cpuid = -1; in kcpc_bind_thread()
305 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_LWPINHERIT); in kcpc_bind_thread()
306 ctx->kc_thread = t; in kcpc_bind_thread()
307 t->t_cpc_ctx = ctx; in kcpc_bind_thread()
311 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_NONPRIV); in kcpc_bind_thread()
318 if ((error = kcpc_configure_reqs(ctx, set, subcode)) != 0) { in kcpc_bind_thread()
320 kcpc_ctx_free(ctx); in kcpc_bind_thread()
325 set->ks_ctx = ctx; in kcpc_bind_thread()
326 ctx->kc_set = set; in kcpc_bind_thread()
331 ctxop_install(t, &kcpc_ctxop_tpl, ctx); in kcpc_bind_thread()
341 kcpc_program(ctx, B_TRUE, B_TRUE); in kcpc_bind_thread()
353 KCPC_CTX_FLAG_CLR(ctx, KCPC_CTX_FREEZE); in kcpc_bind_thread()
369 kcpc_configure_reqs(kcpc_ctx_t *ctx, kcpc_set_t *set, int *subcode) in kcpc_configure_reqs() argument
383 ASSERT(ctx->kc_pics[n].kp_req == NULL); in kcpc_configure_reqs()
396 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_SIGOVF); in kcpc_configure_reqs()
402 &(rp->kr_config), (void *)ctx)) != 0) { in kcpc_configure_reqs()
414 ctx->kc_pics[n].kp_req = rp; in kcpc_configure_reqs()
415 rp->kr_picp = &ctx->kc_pics[n]; in kcpc_configure_reqs()
440 kcpc_ctx_t *ctx = set->ks_ctx; in kcpc_sample() local
458 if (ctx->kc_flags & KCPC_CTX_INVALID) { in kcpc_sample()
464 if ((ctx->kc_flags & KCPC_CTX_FREEZE) == 0) { in kcpc_sample()
465 if (ctx->kc_cpuid != -1) { in kcpc_sample()
466 if (curthread->t_bind_cpu != ctx->kc_cpuid) { in kcpc_sample()
473 if (ctx->kc_thread == curthread) { in kcpc_sample()
476 ctx->kc_hrtime = gethrtime_waitfree(); in kcpc_sample()
477 pcbe_ops->pcbe_sample(ctx); in kcpc_sample()
478 ctx->kc_vtick += curtick - ctx->kc_rawtick; in kcpc_sample()
479 ctx->kc_rawtick = curtick; in kcpc_sample()
486 if (ctx->kc_flags & KCPC_CTX_INVALID) { in kcpc_sample()
500 if (copyout(&ctx->kc_hrtime, hrtime, sizeof (uint64_t)) == -1) in kcpc_sample()
502 if (copyout(&ctx->kc_vtick, tick, sizeof (uint64_t)) == -1) in kcpc_sample()
512 kcpc_stop_hw(kcpc_ctx_t *ctx) in kcpc_stop_hw() argument
518 if (ctx->kc_cpuid == CPU->cpu_id) { in kcpc_stop_hw()
521 cp = cpu_get(ctx->kc_cpuid); in kcpc_stop_hw()
524 ASSERT(cp != NULL && cp->cpu_cpc_ctx == ctx); in kcpc_stop_hw()
533 kcpc_ctx_t *ctx; in kcpc_unbind() local
546 ctx = set->ks_ctx; in kcpc_unbind()
551 mutex_enter(&ctx->kc_lock); in kcpc_unbind()
552 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID); in kcpc_unbind()
553 mutex_exit(&ctx->kc_lock); in kcpc_unbind()
555 if (ctx->kc_cpuid == -1) { in kcpc_unbind()
556 t = ctx->kc_thread; in kcpc_unbind()
567 if (!(ctx->kc_flags & KCPC_CTX_INVALID_STOPPED)) in kcpc_unbind()
568 kcpc_unprogram(ctx, B_TRUE); in kcpc_unbind()
572 VERIFY3U(ctxop_remove(t, &kcpc_ctxop_tpl, ctx), !=, 0); in kcpc_unbind()
589 cp = cpu_get(ctx->kc_cpuid); in kcpc_unbind()
595 if ((ctx->kc_flags & KCPC_CTX_INVALID_STOPPED) == 0) in kcpc_unbind()
596 kcpc_stop_hw(ctx); in kcpc_unbind()
597 ASSERT(ctx->kc_flags & KCPC_CTX_INVALID_STOPPED); in kcpc_unbind()
601 if (ctx->kc_thread == curthread) { in kcpc_unbind()
602 kcpc_free(ctx, 0); in kcpc_unbind()
635 kcpc_ctx_t *ctx = set->ks_ctx; in kcpc_restart() local
640 ASSERT(ctx->kc_thread == curthread); in kcpc_restart()
641 ASSERT(ctx->kc_cpuid == -1); in kcpc_restart()
656 if ((ctx->kc_flags & KCPC_CTX_FREEZE) == 0) in kcpc_restart()
662 ctx->kc_rawtick = KCPC_GET_TICK(); in kcpc_restart()
663 KCPC_CTX_FLAG_CLR(ctx, KCPC_CTX_FREEZE); in kcpc_restart()
664 pcbe_ops->pcbe_program(ctx); in kcpc_restart()
677 kcpc_ctx_t *ctx = t->t_cpc_ctx; in kcpc_enable() local
686 if (ctx == NULL) { in kcpc_enable()
694 } else if (ctx->kc_flags & KCPC_CTX_INVALID) in kcpc_enable()
698 if ((ctx->kc_flags & KCPC_CTX_FREEZE) == 0) in kcpc_enable()
701 KCPC_CTX_FLAG_CLR(ctx, KCPC_CTX_FREEZE); in kcpc_enable()
702 kcpc_restore(ctx); in kcpc_enable()
705 if (ctx->kc_flags & KCPC_CTX_FREEZE) in kcpc_enable()
708 kcpc_save(ctx); in kcpc_enable()
709 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_FREEZE); in kcpc_enable()
721 KCPC_CTX_FLAG_SET(ctx, in kcpc_enable()
762 kcpc_ctx_t *ctx = (kcpc_ctx_t *)token; in kcpc_next_config() local
771 if (ctx->kc_pics[i].kp_req != NULL) in kcpc_next_config()
783 pic = &ctx->kc_pics[i]; in kcpc_next_config()
795 pic = &ctx->kc_pics[i]; in kcpc_next_config()
805 *data = ctx->kc_pics[i].kp_req->kr_data; in kcpc_next_config()
808 return (ctx->kc_pics[i].kp_req->kr_config); in kcpc_next_config()
815 kcpc_ctx_t *ctx; in kcpc_ctx_alloc() local
818 ctx = (kcpc_ctx_t *)kmem_zalloc(sizeof (kcpc_ctx_t), kmem_flags); in kcpc_ctx_alloc()
819 if (ctx == NULL) in kcpc_ctx_alloc()
822 hash = CPC_HASH_CTX(ctx); in kcpc_ctx_alloc()
824 ctx->kc_next = kcpc_ctx_list[hash]; in kcpc_ctx_alloc()
825 kcpc_ctx_list[hash] = ctx; in kcpc_ctx_alloc()
828 ctx->kc_pics = (kcpc_pic_t *)kmem_zalloc(sizeof (kcpc_pic_t) * in kcpc_ctx_alloc()
831 ctx->kc_cpuid = -1; in kcpc_ctx_alloc()
833 return (ctx); in kcpc_ctx_alloc()
841 kcpc_ctx_clone(kcpc_ctx_t *ctx, kcpc_ctx_t *cctx) in kcpc_ctx_clone() argument
843 kcpc_set_t *ks = ctx->kc_set, *cks; in kcpc_ctx_clone()
895 kcpc_ctx_free(kcpc_ctx_t *ctx) in kcpc_ctx_free() argument
898 long hash = CPC_HASH_CTX(ctx); in kcpc_ctx_free()
903 while (*loc != ctx) in kcpc_ctx_free()
905 *loc = ctx->kc_next; in kcpc_ctx_free()
908 kmem_free(ctx->kc_pics, cpc_ncounters * sizeof (kcpc_pic_t)); in kcpc_ctx_free()
909 cv_destroy(&ctx->kc_condv); in kcpc_ctx_free()
910 mutex_destroy(&ctx->kc_lock); in kcpc_ctx_free()
911 kmem_free(ctx, sizeof (*ctx)); in kcpc_ctx_free()
924 kcpc_ctx_t *ctx; in kcpc_overflow_intr() local
950 ctx = NULL; in kcpc_overflow_intr()
953 ctx = t->t_cpc_ctx; in kcpc_overflow_intr()
956 ctx = t->t_cpc_ctx; in kcpc_overflow_intr()
958 if (ctx == NULL) { in kcpc_overflow_intr()
968 ctx = curthread->t_cpu->cpu_cpc_ctx; in kcpc_overflow_intr()
969 if (ctx != NULL) { in kcpc_overflow_intr()
975 return (ctx); in kcpc_overflow_intr()
1014 } else if ((ctx->kc_flags & KCPC_CTX_INVALID) == 0) { in kcpc_overflow_intr()
1027 if (ctx->kc_pics[i].kp_req != NULL && in kcpc_overflow_intr()
1029 ctx->kc_pics[i].kp_req->kr_flags & in kcpc_overflow_intr()
1036 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_FREEZE); in kcpc_overflow_intr()
1037 atomic_or_uint(&ctx->kc_pics[i].kp_flags, in kcpc_overflow_intr()
1042 } else if (ctx->kc_flags & KCPC_CTX_INVALID_STOPPED) { in kcpc_overflow_intr()
1061 kcpc_ctx_t *ctx; in kcpc_hw_overflow_intr() local
1093 ctx = curthread->t_cpu->cpu_cpc_ctx; in kcpc_hw_overflow_intr()
1094 if (ctx == NULL) { in kcpc_hw_overflow_intr()
1103 for (i = 0; i < ctx->kc_set->ks_nreqs; i++) { in kcpc_hw_overflow_intr()
1104 req = ctx->kc_set->ks_req[i]; in kcpc_hw_overflow_intr()
1111 (void *)ctx); in kcpc_hw_overflow_intr()
1114 pcbe_ops->pcbe_program(ctx); in kcpc_hw_overflow_intr()
1147 if ((ctx = kcpc_overflow_intr(arg1, bitmap)) != NULL) { in kcpc_hw_overflow_intr()
1150 ctx->kc_hrtime = gethrtime_waitfree(); in kcpc_hw_overflow_intr()
1151 ctx->kc_vtick += curtick - ctx->kc_rawtick; in kcpc_hw_overflow_intr()
1152 ctx->kc_rawtick = curtick; in kcpc_hw_overflow_intr()
1153 pcbe_ops->pcbe_sample(ctx); in kcpc_hw_overflow_intr()
1154 pcbe_ops->pcbe_program(ctx); in kcpc_hw_overflow_intr()
1168 kcpc_ctx_t *ctx = curthread->t_cpc_ctx; in kcpc_overflow_ast() local
1173 ASSERT(ctx != NULL); /* Beware of interrupt skid. */ in kcpc_overflow_ast()
1181 ctx->kc_hrtime = gethrtime_waitfree(); in kcpc_overflow_ast()
1182 pcbe_ops->pcbe_sample(ctx); in kcpc_overflow_ast()
1185 ctx->kc_vtick += curtick - ctx->kc_rawtick; in kcpc_overflow_ast()
1196 if (ctx->kc_pics[i].kp_flags & KCPC_PIC_OVERFLOWED) { in kcpc_overflow_ast()
1197 atomic_and_uint(&ctx->kc_pics[i].kp_flags, in kcpc_overflow_ast()
1209 KCPC_CTX_FLAG_CLR(ctx, KCPC_CTX_FREEZE); in kcpc_overflow_ast()
1210 pcbe_ops->pcbe_program(ctx); in kcpc_overflow_ast()
1221 kcpc_ctx_t *ctx = arg; in kcpc_save() local
1228 if (ctx->kc_flags & KCPC_CTX_INVALID) { in kcpc_save()
1229 if (ctx->kc_flags & KCPC_CTX_INVALID_STOPPED) { in kcpc_save()
1238 kcpc_unprogram(ctx, B_TRUE); in kcpc_save()
1245 if (ctx->kc_flags & KCPC_CTX_FREEZE) { in kcpc_save()
1254 ctx->kc_hrtime = gethrtime_waitfree(); in kcpc_save()
1255 ctx->kc_vtick += KCPC_GET_TICK() - ctx->kc_rawtick; in kcpc_save()
1256 pcbe_ops->pcbe_sample(ctx); in kcpc_save()
1262 ASSERT(ctx->kc_cpuid == -1); in kcpc_save()
1271 kcpc_ctx_t *ctx = arg; in kcpc_restore() local
1274 mutex_enter(&ctx->kc_lock); in kcpc_restore()
1276 if ((ctx->kc_flags & (KCPC_CTX_INVALID | KCPC_CTX_INVALID_STOPPED)) == in kcpc_restore()
1283 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID_STOPPED); in kcpc_restore()
1286 if (ctx->kc_flags & (KCPC_CTX_INVALID | KCPC_CTX_FREEZE)) { in kcpc_restore()
1287 mutex_exit(&ctx->kc_lock); in kcpc_restore()
1300 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_RESTORE); in kcpc_restore()
1301 mutex_exit(&ctx->kc_lock); in kcpc_restore()
1310 kcpc_program(ctx, B_TRUE, B_TRUE); in kcpc_restore()
1317 mutex_enter(&ctx->kc_lock); in kcpc_restore()
1318 KCPC_CTX_FLAG_CLR(ctx, KCPC_CTX_RESTORE); in kcpc_restore()
1319 cv_signal(&ctx->kc_condv); in kcpc_restore()
1320 mutex_exit(&ctx->kc_lock); in kcpc_restore()
1399 kcpc_ctx_t *ctx = t->t_cpc_ctx, *cctx; in kcpc_lwp_create() local
1402 if (ctx == NULL || (ctx->kc_flags & KCPC_CTX_LWPINHERIT) == 0) in kcpc_lwp_create()
1406 if (ctx->kc_flags & KCPC_CTX_INVALID) { in kcpc_lwp_create()
1411 kcpc_ctx_clone(ctx, cctx); in kcpc_lwp_create()
1418 KCPC_CTX_FLAG_SET(cctx, ctx->kc_flags); in kcpc_lwp_create()
1433 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_FREEZE); in kcpc_lwp_create()
1486 kcpc_ctx_t *ctx = arg; in kcpc_free() local
1488 kcpc_set_t *set = ctx->kc_set; in kcpc_free()
1495 mutex_enter(&ctx->kc_lock); in kcpc_free()
1496 while (ctx->kc_flags & KCPC_CTX_RESTORE) in kcpc_free()
1497 cv_wait(&ctx->kc_condv, &ctx->kc_lock); in kcpc_free()
1498 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID); in kcpc_free()
1499 mutex_exit(&ctx->kc_lock); in kcpc_free()
1508 if (ctx->kc_cpuid != -1) { in kcpc_free()
1516 cp = cpu_get(ctx->kc_cpuid); in kcpc_free()
1524 kcpc_stop_hw(ctx); in kcpc_free()
1537 kcpc_unprogram(ctx, B_TRUE); in kcpc_free()
1549 ASSERT(ctx->kc_thread == curthread); in kcpc_free()
1563 kcpc_ctx_free(ctx); in kcpc_free()
1568 kcpc_free_cpu(kcpc_ctx_t *ctx) in kcpc_free_cpu() argument
1570 kcpc_free(ctx, 0); in kcpc_free_cpu()
1605 kcpc_ctx_t *ctx; in kcpc_invalidate_all() local
1610 for (ctx = kcpc_ctx_list[hash]; ctx; ctx = ctx->kc_next) in kcpc_invalidate_all()
1611 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID); in kcpc_invalidate_all()
1623 kcpc_ctx_t *ctx = token; in kcpc_invalidate_config() local
1625 ASSERT(ctx != NULL); in kcpc_invalidate_config()
1627 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID); in kcpc_invalidate_config()
1636 kcpc_ctx_t *ctx = curthread->t_cpc_ctx; in kcpc_passivate() local
1643 if (ctx == NULL) { in kcpc_passivate()
1671 if ((ctx->kc_flags & KCPC_CTX_INVALID_STOPPED) == 0) { in kcpc_passivate()
1672 kcpc_unprogram(ctx, B_TRUE); in kcpc_passivate()
1673 KCPC_CTX_FLAG_SET(ctx, in kcpc_passivate()
1694 kcpc_assign_reqs(kcpc_set_t *set, kcpc_ctx_t *ctx) in kcpc_assign_reqs() argument
1842 kcpc_ctx_t *ctx = t->t_cpc_ctx; in kcpc_invalidate() local
1844 if (ctx != NULL) in kcpc_invalidate()
1845 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID); in kcpc_invalidate()
1924 kcpc_ctx_t *ctx; in kcpc_cpu_ctx_create() local
1931 ctx = kcpc_ctx_alloc(kmem_flags); in kcpc_cpu_ctx_create()
1934 kcpc_ctx_free(ctx); in kcpc_cpu_ctx_create()
1942 if (kcpc_assign_reqs(set, ctx) != 0) { in kcpc_cpu_ctx_create()
1954 kcpc_ctx_free(ctx); in kcpc_cpu_ctx_create()
1957 if (kcpc_assign_reqs(set, ctx) != 0) { in kcpc_cpu_ctx_create()
1964 kcpc_ctx_free(ctx); in kcpc_cpu_ctx_create()
1978 kcpc_ctx_free(ctx); in kcpc_cpu_ctx_create()
1985 if (kcpc_configure_reqs(ctx, set, &subcode) != 0) { in kcpc_cpu_ctx_create()
1996 kcpc_ctx_free(ctx); in kcpc_cpu_ctx_create()
2004 set->ks_ctx = ctx; in kcpc_cpu_ctx_create()
2005 ctx->kc_set = set; in kcpc_cpu_ctx_create()
2006 ctx->kc_cpuid = cp->cpu_id; in kcpc_cpu_ctx_create()
2007 ctx->kc_thread = curthread; in kcpc_cpu_ctx_create()
2009 ctx_ptrs[nctx] = ctx; in kcpc_cpu_ctx_create()
2095 kcpc_program(kcpc_ctx_t *ctx, boolean_t for_thread, boolean_t cu_interpose) in kcpc_program() argument
2106 ASSERT(ctx != NULL && (ctx->kc_cpuid == CPU->cpu_id || in kcpc_program()
2107 ctx->kc_cpuid == -1) && curthread->t_preempt > 0); in kcpc_program()
2108 if (ctx == NULL || (ctx->kc_cpuid != CPU->cpu_id && in kcpc_program()
2109 ctx->kc_cpuid != -1) || curthread->t_preempt < 1) in kcpc_program()
2119 kcpc_set_t *set = ctx->kc_set; in kcpc_program()
2148 ctx->kc_rawtick = KCPC_GET_TICK(); in kcpc_program()
2149 pcbe_ops->pcbe_program(ctx); in kcpc_program()
2156 KCPC_CTX_FLAG_CLR(ctx, KCPC_CTX_FREEZE); in kcpc_program()
2158 CPU->cpu_cpc_ctx = ctx; in kcpc_program()
2172 kcpc_unprogram(kcpc_ctx_t *ctx, boolean_t cu_interpose) in kcpc_unprogram() argument
2183 ASSERT(ctx != NULL && (ctx->kc_cpuid == CPU->cpu_id || in kcpc_unprogram()
2184 ctx->kc_cpuid == -1) && curthread->t_preempt > 0); in kcpc_unprogram()
2186 if (ctx == NULL || (ctx->kc_cpuid != CPU->cpu_id && in kcpc_unprogram()
2187 ctx->kc_cpuid != -1) || curthread->t_preempt < 1 || in kcpc_unprogram()
2188 (ctx->kc_flags & KCPC_CTX_INVALID_STOPPED) != 0) { in kcpc_unprogram()
2196 ASSERT(CPU->cpu_cpc_ctx == ctx || curthread->t_cpc_ctx == ctx); in kcpc_unprogram()
2202 KCPC_CTX_FLAG_SET(ctx, KCPC_CTX_INVALID_STOPPED); in kcpc_unprogram()
2220 kcpc_ctx_t *ctx; in kcpc_read() local
2233 ctx = CPU->cpu_cpc_ctx; in kcpc_read()
2234 if (ctx == NULL) { in kcpc_read()
2242 pcbe_ops->pcbe_sample(ctx); in kcpc_read()
2244 set = ctx->kc_set; in kcpc_read()
2494 kcpc_ctx_t *ctx = (kcpc_ctx_t *)arg1; in kcpc_remoteprogram_func() local
2497 ASSERT(ctx != NULL); in kcpc_remoteprogram_func()
2500 kcpc_program(ctx, for_thread, B_TRUE); in kcpc_remoteprogram_func()
2508 kcpc_cpu_program(cpu_t *cp, kcpc_ctx_t *ctx) in kcpc_cpu_program() argument
2510 cpu_call(cp, kcpc_remoteprogram_func, (uintptr_t)ctx, in kcpc_cpu_program()