Lines Matching defs:reservation

166  * number of reservations * 2). The "*2" is because each reservation has a
223 * every task and thread) to determine if/when a new reservation would
656 static void pmc_internal_reservation_store(pmc_reservation_t reservation);
657 static void pmc_internal_reservation_load(pmc_reservation_t reservation);
667 * reservation, decrementing the reference count for the pmc used to create the
668 * reservation, and deallocating the reservation's memory.
683 /* Free reservation */
688 * reservation_init initializes a newly created reservation.
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
743 * Used to place reservation into one of the system, task, and thread queues
760 /* Returns TRUE if the reservation applies to the current execution context */
800 * This method will inspect the task/thread of the reservation to see if it
817 * Found a reservation in system queue with same pmc - always a
873 * pmc_internal_reservation_validate_for_pmc returns TRUE if the given reservation can be
875 * determined by the reservation's scope flags). Further, this method returns
876 * FALSE if any level contains a reservation for a PMC that can be accessed from
877 * more than just 1 core, and the given reservation also wants the same PMC.
900 * If the parent task just dropped its reservation, iterate the thread
948 * pmc_internal_reservation_add adds a reservation to the global tracking queues after
949 * ensuring there are no reservation conflicts. To do this, it takes all the
951 * reservation for the same pmc to a queue that has already been checked).
961 /* Check if the reservation can be added without conflicts */
964 /* add reservation to appropriate scope */
1014 static void pmc_internal_reservation_broadcast(pmc_reservation_t reservation, void (*action_func)(void *)) {
1019 if (KERN_SUCCESS == pmc_get_accessible_core_list(reservation->pmc, &cores, &core_cnt)) {
1024 action_func(reservation);
1040 mp_cpus_call(mask, ASYNC, action_func, reservation);
1054 * pmc_internal_reservation_remove removes the given reservation from the appropriate
1055 * reservation queue according to its scope.
1064 * the reservation without knowing which queue it's in. We figure this out
1065 * using the reservation's scope flags.
1433 static uint32_t pmc_internal_reservation_move_for_event(pmc_reservation_t reservation, pmc_state_event_t event, pmc_state_t *old_state_out) {
1437 assert(reservation);
1443 oldState = reservation->state;
1445 } while (newState != PMC_STATE_INVALID && !OSCompareAndSwap(oldState, newState, &(reservation->state)));
1448 COUNTER_DEBUG("Moved reservation %p from state "PMC_STATE_FORMAT" to state "PMC_STATE_FORMAT" for event %s\n", reservation, PMC_STATE_ARGS(oldState), PMC_STATE_ARGS(newState), pmc_state_event_name(event));
1450 COUNTER_DEBUG("No valid moves for reservation %p in state "PMC_STATE_FORMAT" for event %s\n", reservation, PMC_STATE_ARGS(oldState), pmc_state_event_name(event));
1460 static void pmc_internal_reservation_context_out(pmc_reservation_t reservation) {
1461 assert(reservation);
1465 /* Clear that the this reservation was active when this cpu did its last context in */
1466 OSBitAndAtomic(~(1U << cpu_number()), &(reservation->active_last_context_in));
1469 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_CONTEXT_OUT, &oldState))) {
1475 /* Just moved into STORE, so store the reservation. */
1476 pmc_internal_reservation_store(reservation);
1478 /* Wakeup any thread blocking for this reservation to hit <DEALLOC, 0, > */
1479 thread_wakeup((event_t)reservation);
1484 static void pmc_internal_reservation_context_in(pmc_reservation_t reservation) {
1485 assert(reservation);
1490 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_CONTEXT_IN, &oldState))) {
1494 /* Mark that the reservation was active when this cpu did its last context in */
1495 OSBitOrAtomic(1U << cpu_number(), &(reservation->active_last_context_in));
1499 /* Just moved into LOAD, so load the reservation. */
1500 pmc_internal_reservation_load(reservation);
1505 static void pmc_internal_reservation_store(pmc_reservation_t reservation) {
1506 assert(reservation);
1507 assert(PMC_STATE_STATE(reservation->state) == PMC_STATE_STATE_STORE);
1509 assert(reservation->pmc);
1510 assert(reservation->config);
1515 pmc_t store_pmc = reservation->pmc;
1535 /* store the counter value into the reservation's stored count */
1536 ret = store_pmc->methods.get_count(store_pmc_obj, &reservation->value);
1543 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_STORE_FINISHED, NULL))) {
1549 /* Just moved into LOAD, so load the reservation. */
1550 pmc_internal_reservation_load(reservation);
1552 /* Wakeup any thread blocking for this reservation to hit <DEALLOC, 0, > */
1553 thread_wakeup((event_t)reservation);
1558 static void pmc_internal_reservation_load(pmc_reservation_t reservation) {
1559 assert(reservation);
1560 assert(PMC_STATE_STATE(reservation->state) == PMC_STATE_STATE_LOAD);
1565 assert(reservation->pmc);
1566 assert(reservation->config);
1568 pmc_t load_pmc = reservation->pmc;
1573 ret = load_pmc->methods.set_config(load_pmc_obj, reservation->config->object);
1580 ret = load_pmc->methods.set_count(load_pmc_obj, reservation->value);
1605 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_LOAD_FINISHED, NULL))) {
1611 /* Just moved into STORE, so store the reservation. */
1612 pmc_internal_reservation_store(reservation);
1634 pmc_reservation_t reservation = (pmc_reservation_t)arg;
1636 assert(reservation);
1639 if (pmc_internal_reservation_matches_context(reservation)) {
1640 /* We are in context, but the reservation may have already had the context_in method run. Attempt
1643 uint32_t oldMask = OSBitOrAtomic(1U << cpu_number(), &(reservation->active_last_context_in));
1646 COUNTER_DEBUG("Starting already in-context reservation %p for cpu %d\n", reservation, cpu_number());
1648 pmc_internal_reservation_context_in(reservation);
1654 pmc_reservation_t reservation = (pmc_reservation_t)arg;
1656 assert(reservation);
1659 if (pmc_internal_reservation_matches_context(reservation)) {
1660 COUNTER_DEBUG("Stopping in-context reservation %p for cpu %d\n", reservation, cpu_number());
1662 pmc_internal_reservation_context_out(reservation);
1667 * pmc_reservation_interrupt is called when a PMC reservation which was setup
1670 * method is called. This method marks the reservation as stopped, and passes
1672 * reservation (so that the user can, for example, write a 0 to the counter, and
1673 * restart the reservation).
1674 * This method assumes the reservation has a valid pmc_config_t within.
1680 pmc_reservation_t reservation = (pmc_reservation_t)target;
1685 assert(reservation);
1688 if (PMC_STATE_INVALID == pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_INTERRUPT, NULL)) {
1696 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_stop_cpu);
1702 while (PMC_STATE_STATE(reservation->state) != PMC_STATE_STATE_INTERRUPT) {
1714 assert(reservation->config);
1715 assert(reservation->config->method);
1722 (void)reservation->config->method(reservation, refCon);
1728 reservation->config->method, (end - start));
1733 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_END_OF_INTERRUPT, NULL))) {
1739 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_start_cpu);
1741 /* Wakeup any thread blocking for this reservation to hit <DEALLOC, 0, > */
1742 thread_wakeup((event_t)reservation);
2111 * the config to never change once a reservation has been taken out with
2112 * it. However, in order to have the PMI method have the reservation as
2118 * reservation (in pmc_reserve() and friends, below).
2361 pmc_reservation_t *reservation) {
2363 if(!pmc || !config || !reservation) {
2382 /* enqueue reservation in proper place */
2393 *reservation = resv;
2413 task_t task, pmc_reservation_t *reservation) {
2415 if(!pmc || !config || !reservation || !task) {
2441 /* enqueue reservation in proper place */
2452 *reservation = resv;
2472 thread_t thread, pmc_reservation_t *reservation) {
2473 if(!pmc || !config || !reservation || !thread) {
2499 /* enqueue reservation in proper place */
2510 *reservation = resv;
2516 * pmc_reservation_start instructs the given reservation to start counting as
2521 kern_return_t pmc_reservation_start(pmc_reservation_t reservation) {
2524 if(!reservation) {
2529 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_START, NULL))) {
2541 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_start_cpu);
2548 * pmc_reservation_stop instructs the given reservation to stop counting as
2552 * to the reservation state, the pmc hardware _will_ stop shortly.
2555 kern_return_t pmc_reservation_stop(pmc_reservation_t reservation) {
2558 if(!reservation) {
2563 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_STOP, NULL))) {
2576 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_stop_cpu);
2583 * pmc_reservation_read will read the event count associated with a reservation.
2585 * reservation's context, and b) can access the reservation's pmc directly, the
2586 * value will be read from hardware. Otherwise, this returns the reservation's
2592 kern_return_t pmc_reservation_read(pmc_reservation_t reservation, uint64_t *value) {
2597 if(!reservation || !value) {
2605 uint32_t state = reservation->state;
2610 assert(reservation->pmc);
2612 ret = reservation->pmc->methods.get_count(reservation->pmc->object, value);
2635 *value = reservation->value;
2642 * pmc_reservation_write will write the event count associated with a reservation.
2644 * reservation's context, and b) can access the reservation's pmc directly, the
2645 * value will be written to hardware. Otherwise, this writes the reservation's
2651 kern_return_t pmc_reservation_write(pmc_reservation_t reservation, uint64_t value) {
2656 if(!reservation) {
2664 uint32_t state = reservation->state;
2668 assert(reservation->pmc);
2670 ret = reservation->pmc->methods.set_count(reservation->pmc->object, value);
2691 reservation->value = value;
2698 * pmc_reservation_free releases a reservation and all associated resources.
2702 kern_return_t pmc_reservation_free(pmc_reservation_t reservation) {
2705 if(!reservation) {
2709 perf_monitor_reservation_remove(reservation->pmc->monitor);
2712 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_FREE, NULL))) {
2722 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_stop_cpu);
2725 /* Block until the reservation hits the <DEALLOC, 0, > state */
2726 while (!(PMC_STATE_STATE(reservation->state) == PMC_STATE_STATE_DEALLOC && PMC_STATE_CONTEXT_COUNT(reservation->state) == 0 && PMC_STATE_FLAGS(reservation->state) == 0)) {
2727 assert_wait((event_t)reservation, THREAD_UNINT);
2732 pmc_internal_reservation_remove(reservation);
2734 /* free reservation */
2735 reservation_free(reservation);
2916 pmc_config_t config __unused, pmc_reservation_t *reservation __unused) {
2922 pmc_reservation_t *reservation __unused) {
2928 pmc_reservation_t *reservation __unused) {
2932 kern_return_t pmc_reservation_start(pmc_reservation_t reservation __unused) {
2936 kern_return_t pmc_reservation_stop(pmc_reservation_t reservation __unused) {
2940 kern_return_t pmc_reservation_read(pmc_reservation_t reservation __unused,
2945 kern_return_t pmc_reservation_write(pmc_reservation_t reservation __unused,
2950 kern_return_t pmc_reservation_free(pmc_reservation_t reservation __unused) {