• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/xnu-2782.1.97/osfmk/pmc/

Lines Matching defs:pmc

33 #include <pmc/pmc.h>
183 #define PERF_BIG_UNIT_SZ (sizeof(struct pmc))
240 * attributes required for the pmc sub-system.
249 pmc_lock_grp = lck_grp_alloc_init("pmc", pmc_lock_grp_attr);
261 * init_pmc_zones initializes the allocation zones used by the pmc subsystem
266 "pmc.small zone");
272 "pmc.big zone");
311 * pmc sub-system.
489 static void perf_monitor_add_pmc(perf_monitor_t pm, pmc_t pmc __unused) {
491 assert(pmc);
493 /* Today, we merely add a reference count now that a new pmc is attached */
501 static void perf_monitor_remove_pmc(perf_monitor_t pm, pmc_t pmc __unused) {
503 assert(pmc);
505 /* Today, we merely remove a reference count now that the pmc is detached */
517 static void pmc_free(void *pmc) {
518 zfree(perf_big_zone, pmc);
524 static void pmc_init(pmc_t pmc) {
525 assert(pmc);
527 pmc->object = NULL;
528 pmc->monitor = NULL;
530 bzero(&pmc->methods, sizeof(pmc_methods_t));
533 pmc->useCount = 1;
539 static void pmc_reference(pmc_t pmc) {
540 assert(pmc);
542 OSIncrementAtomic(&(pmc->useCount));
550 static void pmc_deallocate(pmc_t pmc) {
551 assert(pmc);
554 if(1 == OSDecrementAtomic(&(pmc->useCount))) {
555 /* Free the pmc */
556 pmc_free(pmc);
561 * pmc_dequeue removes the given, newly *un*registered pmc from the
564 static void pmc_dequeue(pmc_t pmc) {
567 queue_remove(perf_counters_queue, pmc, pmc_t, link);
575 * pmc_enqueue adds the given, newly registered pmc to the perf_counters_queue
577 static void pmc_enqueue(pmc_t pmc) {
580 queue_enter(perf_counters_queue, pmc, pmc_t, link);
618 static pmc_config_t pmc_config_alloc(pmc_t pmc __unused) {
623 static void pmc_config_free(pmc_t pmc, pmc_config_t config) {
624 assert(pmc);
628 pmc->methods.free_config(pmc->object, config->object);
635 static kern_return_t pmc_open(pmc_t pmc) {
636 assert(pmc);
637 assert(pmc->object);
638 assert(pmc->open_object);
640 return pmc->methods.open(pmc->object, pmc->open_object);
643 static kern_return_t pmc_close(pmc_t pmc) {
644 assert(pmc);
645 assert(pmc->object);
646 assert(pmc->open_object);
648 return pmc->methods.close(pmc->object, pmc->open_object);
655 static kern_return_t pmc_internal_reservation_set_pmc(pmc_reservation_t resv, pmc_t pmc);
660 /* pmc reservations come from the perf small zone */
667 * reservation, decrementing the reference count for the pmc used to create the
673 assert(resv->pmc);
675 pmc_free_config(resv->pmc, resv->config);
693 resv->pmc = NULL;
709 * pmc_internal_reservation_set_pmc sets the pmc associated with the reservation object. If
715 * dropping the reference on any previously set pmc, and setting the reservation
716 * to having no pmc set.
718 static kern_return_t pmc_internal_reservation_set_pmc(pmc_reservation_t resv, pmc_t pmc) {
721 if(resv->pmc) {
722 (void)pmc_close(resv->pmc);
723 pmc_deallocate(resv->pmc);
724 resv->pmc = NULL;
727 resv->pmc = pmc;
729 if(resv->pmc) {
730 pmc_reference(resv->pmc);
731 if(KERN_SUCCESS != pmc_open(resv->pmc)) {
732 pmc_deallocate(resv->pmc);
733 resv->pmc = NULL;
782 * a given @pmc. 0 means every core in the system.
784 static uint32_t pmc_accessible_core_count(pmc_t pmc) {
785 assert(pmc);
790 if(KERN_SUCCESS != pmc->methods.accessible_cores(pmc->object,
812 if(tmp->pmc == resv->pmc) {
817 * Found a reservation in system queue with same pmc - always a
833 * so far, no conflict - check that the pmc that is
838 if(1 != pmc_accessible_core_count(tmp->pmc)) {
852 * so far, no conflict - check that the pmc that is
857 if(1 != pmc_accessible_core_count(tmp->pmc)) {
901 * reservations to see if we need to keep the pmc flag set for the given
951 * reservation for the same pmc to a queue that has already been checked).
1019 if (KERN_SUCCESS == pmc_get_accessible_core_list(reservation->pmc, &cores, &core_cnt)) {
1507 assert(reservation->pmc);
1513 pmc_t store_pmc = reservation->pmc;
1563 assert(reservation->pmc);
1566 pmc_t load_pmc = reservation->pmc;
1592 * Instruct the Perf Monitor containing the pmc to enable the
1616 * pmc_accessible_from_core will return TRUE if the given @pmc is directly
1621 static inline boolean_t pmc_accessible_from_core(pmc_t pmc, uint32_t logicalCore) {
1624 assert(pmc);
1626 ret = pmc->methods.accessible_from_core(pmc->object, logicalCore);
1863 * pmc_register registers a new PMC for use with the pmc subsystem. Each PMC is
1920 /* make a new pmc */
1921 pmc_t pmc = pmc_alloc();
1922 if(!pmc) {
1929 pmc_init(pmc);
1931 pmc->object = pmc_object;
1932 pmc->open_object = object;
1935 memcpy(&(pmc->methods), methods, sizeof(pmc_methods_t));
1937 pmc->monitor = pm;
1939 perf_monitor_add_pmc(pmc->monitor, pmc);
1942 pmc_enqueue(pmc);
1962 pmc_t pmc = pmc_find(pmc_object);
1963 if(!pmc) {
1964 COUNTER_DEBUG("Could not find a matching pmc.\n");
1969 pmc_dequeue(pmc);
1971 perf_monitor_remove_pmc(pmc->monitor, pmc);
1974 pmc_deallocate(pmc);
1976 /* dealloc the pmc */
1977 pmc_deallocate(pmc);
2002 * pmc_create_config creates a new configuration area from a given @pmc.
2006 kern_return_t pmc_create_config(pmc_t pmc, pmc_config_t *config) {
2009 if(!pmc || !config) {
2013 pmc_reference(pmc);
2015 tmp = pmc_config_alloc(pmc);
2017 tmp->object = pmc->methods.create_config(pmc->object);
2020 pmc_config_free(pmc, tmp);
2029 pmc_deallocate(pmc);
2041 * pmc_free_config frees a configuration area created from a given @pmc
2045 void pmc_free_config(pmc_t pmc, pmc_config_t config) {
2046 assert(pmc);
2049 pmc_reference(pmc);
2051 pmc_config_free(pmc, config);
2053 pmc_deallocate(pmc);
2062 kern_return_t pmc_config_set_value(pmc_t pmc, pmc_config_t config,
2067 if(!pmc || !config) {
2071 pmc_reference(pmc);
2073 ret = pmc->methods.config_set_value(config->object, id, value);
2075 pmc_deallocate(pmc);
2082 * the pmc that it should generate a call to the given pmc_interrupt_method_t
2093 kern_return_t pmc_config_set_interrupt_threshold(pmc_t pmc, pmc_config_t config,
2097 if(!config || !pmc) {
2102 assert(pmc);
2104 pmc_reference(pmc);
2128 pmc_deallocate(pmc);
2142 pmc_t pmc = NULL;
2177 queue_iterate(perf_counters_queue, pmc, pmc_t, link) {
2179 array[count++] = pmc;
2224 * If the pmc name is shorter than the requested match, it's no
2280 * given pmc.
2285 const char *pmc_get_name(pmc_t pmc) {
2286 assert(pmc);
2288 const char *name = pmc->methods.get_name(pmc->object);
2296 * (hardware threads) from which the given @pmc can be accessed directly.
2300 kern_return_t pmc_get_accessible_core_list(pmc_t pmc, uint32_t **logicalCores,
2305 if(!pmc || !logicalCores || !logicalCoreCt) {
2309 ret = pmc->methods.accessible_cores(pmc->object, logicalCores, logicalCoreCt);
2316 assert(resv->pmc);
2324 kern_return_t ret = resv->pmc->methods.config_set_threshold(config->object,
2332 COUNTER_DEBUG("Failed to set threshold for pmc %p\n", resv->pmc);
2336 if(KERN_SUCCESS != resv->pmc->methods.config_set_handler(config->object,
2339 COUNTER_DEBUG("Failed to set handler for pmc %p\n", resv->pmc);
2348 * pmc_reserve will attempt to reserve the given @pmc, with a given
2350 * KERN_FAILURE if the given pmc is already reserved at any scope.
2358 kern_return_t pmc_reserve(pmc_t pmc, pmc_config_t config,
2361 if(!pmc || !config || !reservation) {
2375 if(KERN_SUCCESS != pmc_internal_reservation_set_pmc(resv, pmc)) {
2389 perf_monitor_reservation_add(pmc->monitor);
2397 * pmc_reserve_task will attempt to reserve the given @pmc with a given
2399 * logical core that can directly access the given @pmc. This method will fail
2400 * with KERN_FAILURE if the given pmc is already reserved at either system or
2407 * NOTE: You can reserve the same pmc for N different tasks concurrently.
2410 kern_return_t pmc_reserve_task(pmc_t pmc, pmc_config_t config,
2413 if(!pmc || !config || !reservation || !task) {
2417 if (!(pmc->monitor->methods.flags & PERFMON_FLAG_SUPPORTS_CONTEXT_SWITCHING)) {
2418 COUNTER_DEBUG("pmc %p cannot be context switched!\n", pmc);
2434 if(KERN_SUCCESS != pmc_internal_reservation_set_pmc(resv, pmc)) {
2448 perf_monitor_reservation_add(pmc->monitor);
2456 * pmc_reserve_thread will attempt to reserve the given @pmc with a given
2458 * logical core that can directly access the given @pmc. This method will fail
2459 * with KERN_FAILURE if the given pmc is already reserved at either system or
2466 * NOTE: You can reserve the same pmc for N different threads concurrently.
2469 kern_return_t pmc_reserve_thread(pmc_t pmc, pmc_config_t config,
2471 if(!pmc || !config || !reservation || !thread) {
2475 if (!(pmc->monitor->methods.flags & PERFMON_FLAG_SUPPORTS_CONTEXT_SWITCHING)) {
2476 COUNTER_DEBUG("pmc %p cannot be context switched!\n", pmc);
2492 if(KERN_SUCCESS != pmc_internal_reservation_set_pmc(resv, pmc)) {
2506 perf_monitor_reservation_add(pmc->monitor);
2547 * soon as possible. When this method returns, the pmc will be marked as stopping
2549 * that the pmc hardware has _actually_ stopped running. Assuming no other changes
2550 * to the reservation state, the pmc hardware _will_ stop shortly.
2583 * reservation's context, and b) can access the reservation's pmc directly, the
2608 assert(reservation->pmc);
2610 ret = reservation->pmc->methods.get_count(reservation->pmc->object, value);
2642 * reservation's context, and b) can access the reservation's pmc directly, the
2666 assert(reservation->pmc);
2668 ret = reservation->pmc->methods.set_count(reservation->pmc->object, value);
2707 perf_monitor_reservation_remove(reservation->pmc->monitor);
2789 * pmc_context_switch performs all context switching necessary to save all pmc
2791 * as well as to restore all pmc state associated with @newThread (and the task
2802 /* Save pmc states */
2805 if ((oldThread == resv->thread) && pmc_accessible_from_core(resv->pmc, cpuNum)) {
2813 if ((resv->task == oldThread->task) && pmc_accessible_from_core(resv->pmc, cpuNum)) {
2822 if ((resv->thread == newThread) && pmc_accessible_from_core(resv->pmc, cpuNum)) {
2830 if ((resv->task == newThread->task) && pmc_accessible_from_core(resv->pmc, cpuNum)) {
2863 pmc_object_t pmc __unused, pmc_methods_t *methods __unused, void *object __unused) {
2868 pmc_object_t pmc __unused) {
2872 kern_return_t pmc_create_config(pmc_t pmc __unused,
2877 void pmc_free_config(pmc_t pmc __unused, pmc_config_t config __unused) {
2880 kern_return_t pmc_config_set_value(pmc_t pmc __unused,
2886 kern_return_t pmc_config_set_interrupt_threshold(pmc_t pmc __unused,
2904 const char *pmc_get_name(pmc_t pmc __unused) {
2908 kern_return_t pmc_get_accessible_core_list(pmc_t pmc __unused,
2913 kern_return_t pmc_reserve(pmc_t pmc __unused,
2918 kern_return_t pmc_reserve_task(pmc_t pmc __unused,
2924 kern_return_t pmc_reserve_thread(pmc_t pmc __unused,