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);
1052 * pmc_internal_reservation_remove removes the given reservation from the appropriate
1053 * reservation queue according to its scope.
1062 * the reservation without knowing which queue it's in. We figure this out
1063 * using the reservation's scope flags.
1431 static uint32_t pmc_internal_reservation_move_for_event(pmc_reservation_t reservation, pmc_state_event_t event, pmc_state_t *old_state_out) {
1435 assert(reservation);
1441 oldState = reservation->state;
1443 } while (newState != PMC_STATE_INVALID && !OSCompareAndSwap(oldState, newState, &(reservation->state)));
1446 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));
1448 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));
1458 static void pmc_internal_reservation_context_out(pmc_reservation_t reservation) {
1459 assert(reservation);
1463 /* Clear that the this reservation was active when this cpu did its last context in */
1464 OSBitAndAtomic(~(1U << cpu_number()), &(reservation->active_last_context_in));
1467 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_CONTEXT_OUT, &oldState))) {
1473 /* Just moved into STORE, so store the reservation. */
1474 pmc_internal_reservation_store(reservation);
1476 /* Wakeup any thread blocking for this reservation to hit <DEALLOC, 0, > */
1477 thread_wakeup((event_t)reservation);
1482 static void pmc_internal_reservation_context_in(pmc_reservation_t reservation) {
1483 assert(reservation);
1488 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_CONTEXT_IN, &oldState))) {
1492 /* Mark that the reservation was active when this cpu did its last context in */
1493 OSBitOrAtomic(1U << cpu_number(), &(reservation->active_last_context_in));
1497 /* Just moved into LOAD, so load the reservation. */
1498 pmc_internal_reservation_load(reservation);
1503 static void pmc_internal_reservation_store(pmc_reservation_t reservation) {
1504 assert(reservation);
1505 assert(PMC_STATE_STATE(reservation->state) == PMC_STATE_STATE_STORE);
1507 assert(reservation->pmc);
1508 assert(reservation->config);
1513 pmc_t store_pmc = reservation->pmc;
1533 /* store the counter value into the reservation's stored count */
1534 ret = store_pmc->methods.get_count(store_pmc_obj, &reservation->value);
1541 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_STORE_FINISHED, NULL))) {
1547 /* Just moved into LOAD, so load the reservation. */
1548 pmc_internal_reservation_load(reservation);
1550 /* Wakeup any thread blocking for this reservation to hit <DEALLOC, 0, > */
1551 thread_wakeup((event_t)reservation);
1556 static void pmc_internal_reservation_load(pmc_reservation_t reservation) {
1557 assert(reservation);
1558 assert(PMC_STATE_STATE(reservation->state) == PMC_STATE_STATE_LOAD);
1563 assert(reservation->pmc);
1564 assert(reservation->config);
1566 pmc_t load_pmc = reservation->pmc;
1571 ret = load_pmc->methods.set_config(load_pmc_obj, reservation->config->object);
1578 ret = load_pmc->methods.set_count(load_pmc_obj, reservation->value);
1603 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_LOAD_FINISHED, NULL))) {
1609 /* Just moved into STORE, so store the reservation. */
1610 pmc_internal_reservation_store(reservation);
1632 pmc_reservation_t reservation = (pmc_reservation_t)arg;
1634 assert(reservation);
1637 if (pmc_internal_reservation_matches_context(reservation)) {
1638 /* We are in context, but the reservation may have already had the context_in method run. Attempt
1641 uint32_t oldMask = OSBitOrAtomic(1U << cpu_number(), &(reservation->active_last_context_in));
1644 COUNTER_DEBUG("Starting already in-context reservation %p for cpu %d\n", reservation, cpu_number());
1646 pmc_internal_reservation_context_in(reservation);
1652 pmc_reservation_t reservation = (pmc_reservation_t)arg;
1654 assert(reservation);
1657 if (pmc_internal_reservation_matches_context(reservation)) {
1658 COUNTER_DEBUG("Stopping in-context reservation %p for cpu %d\n", reservation, cpu_number());
1660 pmc_internal_reservation_context_out(reservation);
1665 * pmc_reservation_interrupt is called when a PMC reservation which was setup
1668 * method is called. This method marks the reservation as stopped, and passes
1670 * reservation (so that the user can, for example, write a 0 to the counter, and
1671 * restart the reservation).
1672 * This method assumes the reservation has a valid pmc_config_t within.
1678 pmc_reservation_t reservation = (pmc_reservation_t)target;
1683 assert(reservation);
1686 if (PMC_STATE_INVALID == pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_INTERRUPT, NULL)) {
1694 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_stop_cpu);
1700 while (PMC_STATE_STATE(reservation->state) != PMC_STATE_STATE_INTERRUPT) {
1712 assert(reservation->config);
1713 assert(reservation->config->method);
1720 (void)reservation->config->method(reservation, refCon);
1726 reservation->config->method, (end - start));
1731 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_END_OF_INTERRUPT, NULL))) {
1737 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_start_cpu);
1739 /* Wakeup any thread blocking for this reservation to hit <DEALLOC, 0, > */
1740 thread_wakeup((event_t)reservation);
2109 * the config to never change once a reservation has been taken out with
2110 * it. However, in order to have the PMI method have the reservation as
2116 * reservation (in pmc_reserve() and friends, below).
2359 pmc_reservation_t *reservation) {
2361 if(!pmc || !config || !reservation) {
2380 /* enqueue reservation in proper place */
2391 *reservation = resv;
2411 task_t task, pmc_reservation_t *reservation) {
2413 if(!pmc || !config || !reservation || !task) {
2439 /* enqueue reservation in proper place */
2450 *reservation = resv;
2470 thread_t thread, pmc_reservation_t *reservation) {
2471 if(!pmc || !config || !reservation || !thread) {
2497 /* enqueue reservation in proper place */
2508 *reservation = resv;
2514 * pmc_reservation_start instructs the given reservation to start counting as
2519 kern_return_t pmc_reservation_start(pmc_reservation_t reservation) {
2522 if(!reservation) {
2527 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_START, NULL))) {
2539 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_start_cpu);
2546 * pmc_reservation_stop instructs the given reservation to stop counting as
2550 * to the reservation state, the pmc hardware _will_ stop shortly.
2553 kern_return_t pmc_reservation_stop(pmc_reservation_t reservation) {
2556 if(!reservation) {
2561 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_STOP, NULL))) {
2574 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_stop_cpu);
2581 * pmc_reservation_read will read the event count associated with a reservation.
2583 * reservation's context, and b) can access the reservation's pmc directly, the
2584 * value will be read from hardware. Otherwise, this returns the reservation's
2590 kern_return_t pmc_reservation_read(pmc_reservation_t reservation, uint64_t *value) {
2595 if(!reservation || !value) {
2603 uint32_t state = reservation->state;
2608 assert(reservation->pmc);
2610 ret = reservation->pmc->methods.get_count(reservation->pmc->object, value);
2633 *value = reservation->value;
2640 * pmc_reservation_write will write the event count associated with a reservation.
2642 * reservation's context, and b) can access the reservation's pmc directly, the
2643 * value will be written to hardware. Otherwise, this writes the reservation's
2649 kern_return_t pmc_reservation_write(pmc_reservation_t reservation, uint64_t value) {
2654 if(!reservation) {
2662 uint32_t state = reservation->state;
2666 assert(reservation->pmc);
2668 ret = reservation->pmc->methods.set_count(reservation->pmc->object, value);
2689 reservation->value = value;
2696 * pmc_reservation_free releases a reservation and all associated resources.
2700 kern_return_t pmc_reservation_free(pmc_reservation_t reservation) {
2703 if(!reservation) {
2707 perf_monitor_reservation_remove(reservation->pmc->monitor);
2710 if (PMC_STATE_INVALID == (newState = pmc_internal_reservation_move_for_event(reservation, PMC_STATE_EVENT_FREE, NULL))) {
2720 pmc_internal_reservation_broadcast(reservation, pmc_internal_reservation_stop_cpu);
2723 /* Block until the reservation hits the <DEALLOC, 0, > state */
2724 while (!(PMC_STATE_STATE(reservation->state) == PMC_STATE_STATE_DEALLOC && PMC_STATE_CONTEXT_COUNT(reservation->state) == 0 && PMC_STATE_FLAGS(reservation->state) == 0)) {
2725 assert_wait((event_t)reservation, THREAD_UNINT);
2730 pmc_internal_reservation_remove(reservation);
2732 /* free reservation */
2733 reservation_free(reservation);
2914 pmc_config_t config __unused, pmc_reservation_t *reservation __unused) {
2920 pmc_reservation_t *reservation __unused) {
2926 pmc_reservation_t *reservation __unused) {
2930 kern_return_t pmc_reservation_start(pmc_reservation_t reservation __unused) {
2934 kern_return_t pmc_reservation_stop(pmc_reservation_t reservation __unused) {
2938 kern_return_t pmc_reservation_read(pmc_reservation_t reservation __unused,
2943 kern_return_t pmc_reservation_write(pmc_reservation_t reservation __unused,
2948 kern_return_t pmc_reservation_free(pmc_reservation_t reservation __unused) {