Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | /* * Copyright (c) 2012-2013 Apple Computer, Inc. All Rights Reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include <IOKit/IOKernelReportStructs.h> #include <IOKit/IOKernelReporters.h> #include "IOReporterDefs.h" #define super IOReporter OSDefineMetaClassAndStructors(IOStateReporter, IOReporter); /* static */ IOStateReporter* IOStateReporter::with(IOService *reportingService, IOReportCategories categories, int nstates, IOReportUnits unit/* = kIOReportUnitHWTicks*/) { IOStateReporter *reporter, *rval = NULL; // kprintf("%s\n", __func__); // can't IORLOG() from static reporter = new IOStateReporter; if (!reporter) goto finish; if (!reporter->initWith(reportingService, categories, nstates, unit)) { goto finish; } // success rval = reporter; finish: if (!rval) { if (reporter) delete reporter; } return rval; } bool IOStateReporter::initWith(IOService *reportingService, IOReportCategories categories, int16_t nstates, IOReportUnits unit) { bool success = false; IOReportChannelType channelType = { .categories = categories, .report_format = kIOReportFormatState, .nelements = static_cast<uint16_t>(nstates), .element_idx = 0 }; if(super::init(reportingService, channelType, unit) != true) { IORLOG("ERROR super::initWith failed"); success = false; goto finish; } _currentStates = NULL; _lastUpdateTimes = NULL; success = true; finish: return success; } void IOStateReporter::free(void) { if (_currentStates) { PREFL_MEMOP_PANIC(_nChannels, int); IOFree(_currentStates, (size_t)_nChannels * sizeof(int)); } if (_lastUpdateTimes) { PREFL_MEMOP_PANIC(_nChannels, uint64_t); IOFree(_lastUpdateTimes, (size_t)_nChannels * sizeof(uint64_t)); } super::free(); } IOReturn IOStateReporter::handleSwapPrepare(int newNChannels) { IOReturn res = kIOReturnError; size_t newCurStatesSize, newTSSize; //IORLOG("handleSwapPrepare (state) _nChannels before = %u", _nChannels); IOREPORTER_CHECK_CONFIG_LOCK(); if (_swapCurrentStates || _swapLastUpdateTimes) { panic("IOStateReporter::_swap* already in use"); } // new currentStates buffer PREFL_MEMOP_FAIL(newNChannels, int); newCurStatesSize = (size_t)newNChannels * sizeof(int); _swapCurrentStates = (int*)IOMalloc(newCurStatesSize); if (_swapCurrentStates == NULL) { res = kIOReturnNoMemory; goto finish; } memset(_swapCurrentStates, -1, newCurStatesSize); // init w/"no state" // new timestamps buffer PREFL_MEMOP_FAIL(newNChannels, uint64_t); newTSSize = (size_t)newNChannels * sizeof(uint64_t); _swapLastUpdateTimes = (uint64_t *)IOMalloc(newTSSize); if (_swapLastUpdateTimes == NULL) { res = kIOReturnNoMemory; goto finish; } memset(_swapLastUpdateTimes, 0, newTSSize); res = super::handleSwapPrepare(newNChannels); finish: if (res) { if (_swapCurrentStates) { IOFree(_swapCurrentStates, newCurStatesSize); _swapCurrentStates = NULL; } if (_swapLastUpdateTimes) { IOFree(_swapLastUpdateTimes, newTSSize); _swapLastUpdateTimes = NULL; } } return res; } IOReturn IOStateReporter::handleAddChannelSwap(uint64_t channelID, const OSSymbol *symChannelName) { IOReturn res = kIOReturnError; int cnt; int *tmpCurStates; uint64_t *tmpTimestamps; bool swapComplete = false; //IORLOG("IOStateReporter::handleSwap"); if (!_swapCurrentStates || !_swapLastUpdateTimes) { IORLOG("IOReporter::handleSwap ERROR swap variables uninitialized!"); goto finish; } IOREPORTER_CHECK_CONFIG_LOCK(); IOREPORTER_CHECK_LOCK(); // Copy any existing buffers if (_currentStates) { PREFL_MEMOP_FAIL(_nChannels, int); memcpy(_swapCurrentStates, _currentStates, (size_t)_nChannels * sizeof(int)); if (!_lastUpdateTimes) { panic("IOStateReporter::handleAddChannelSwap _lastUpdateTimes unset despite non-NULL _currentStates"); } PREFL_MEMOP_FAIL(_nChannels, uint64_t); memcpy(_swapLastUpdateTimes, _lastUpdateTimes, (size_t)_nChannels * sizeof(uint64_t)); } // Update principal instance variables, keep old values in _swap* for cleanup tmpCurStates = _currentStates; _currentStates = _swapCurrentStates; _swapCurrentStates = tmpCurStates; tmpTimestamps = _lastUpdateTimes; _lastUpdateTimes = _swapLastUpdateTimes; _swapLastUpdateTimes = tmpTimestamps; swapComplete = true; // subclass success // invoke superclass(es): base class updates _nChannels & _nElements res = super::handleAddChannelSwap(channelID, symChannelName); if (res) { IORLOG("handleSwap(state) ERROR super::handleSwap failed!"); goto finish; } // Channel added successfully, initialize the new channel's state_ids to 0..nStates-1 for (cnt = 0; cnt < _channelDimension; cnt++) { handleSetStateID(channelID, cnt, (uint64_t)cnt); } finish: if (res && swapComplete) { // unswap so the unused buffers get cleaned up tmpCurStates = _currentStates; _currentStates = _swapCurrentStates; _swapCurrentStates = tmpCurStates; tmpTimestamps = _lastUpdateTimes; _lastUpdateTimes = _swapLastUpdateTimes; _swapLastUpdateTimes = tmpTimestamps; } return res; } void IOStateReporter::handleSwapCleanup(int swapNChannels) { IOREPORTER_CHECK_CONFIG_LOCK(); super::handleSwapCleanup(swapNChannels); if (_swapCurrentStates) { PREFL_MEMOP_PANIC(swapNChannels, int); IOFree(_swapCurrentStates, (size_t)swapNChannels * sizeof(int)); _swapCurrentStates = NULL; } if (_swapLastUpdateTimes) { PREFL_MEMOP_PANIC(swapNChannels, uint64_t); IOFree(_swapLastUpdateTimes, (size_t)swapNChannels * sizeof(uint64_t)); _swapLastUpdateTimes = NULL; } } IOReturn IOStateReporter::_getStateIndices(uint64_t channel_id, uint64_t state_id, int *channel_index, int *state_index) { IOReturn res = kIOReturnError; int cnt; IOStateReportValues *values; int element_index = 0; IOREPORTER_CHECK_LOCK(); if (getChannelIndices(channel_id, channel_index, &element_index) != kIOReturnSuccess) { res = kIOReturnBadArgument; goto finish; } for (cnt = 0; cnt < _channelDimension; cnt++) { values = (IOStateReportValues *)getElementValues(element_index + cnt); if (values == NULL) { res = kIOReturnError; goto finish; } if (values->state_id == state_id) { *state_index = cnt; res = kIOReturnSuccess; goto finish; } } res = kIOReturnBadArgument; finish: return res; } IOReturn IOStateReporter::setChannelState(uint64_t channel_id, uint64_t new_state_id) { IOReturn res = kIOReturnError; int channel_index, new_state_index; uint64_t last_intransition = 0; uint64_t prev_state_residency = 0; lockReporter(); if (_getStateIndices(channel_id, new_state_id, &channel_index, &new_state_index) == kIOReturnSuccess) { res = handleSetStateByIndices(channel_index, new_state_index, last_intransition, prev_state_residency); goto finish; } res = kIOReturnBadArgument; finish: unlockReporter(); return res; } IOReturn IOStateReporter::setChannelState(uint64_t channel_id, uint64_t new_state_id, uint64_t last_intransition, uint64_t prev_state_residency) { return setChannelState(channel_id, new_state_id); } IOReturn IOStateReporter::overrideChannelState(uint64_t channel_id, uint64_t state_id, uint64_t time_in_state, uint64_t intransitions, uint64_t last_intransition /*=0*/) { IOReturn res = kIOReturnError; int channel_index, state_index; lockReporter(); if (_getStateIndices(channel_id, state_id, &channel_index, &state_index) == kIOReturnSuccess) { if (_lastUpdateTimes[channel_index]) { panic("overrideChannelState() cannot be used after setChannelState()!\n"); } res = handleOverrideChannelStateByIndices(channel_index, state_index, time_in_state, intransitions, last_intransition); goto finish; } res = kIOReturnBadArgument; finish: unlockReporter(); return res; } IOReturn IOStateReporter::handleOverrideChannelStateByIndices(int channel_index, int state_index, uint64_t time_in_state, uint64_t intransitions, uint64_t last_intransition /*=0*/) { IOReturn kerr, result = kIOReturnError; IOStateReportValues state_values; int element_index; if (channel_index < 0 || channel_index >= _nChannels) { result = kIOReturnBadArgument; goto finish; } if (channel_index < 0 || channel_index > (_nElements - state_index) / _channelDimension) { result = kIOReturnOverrun; goto finish; } element_index = channel_index * _channelDimension + state_index; kerr = copyElementValues(element_index,(IOReportElementValues*)&state_values); if (kerr) { result = kerr; goto finish; } // last_intransition = 0 -> no current state ("residency summary only") state_values.last_intransition = last_intransition; state_values.intransitions = intransitions; state_values.upticks = time_in_state; // determines current time for metadata kerr = setElementValues(element_index, (IOReportElementValues *)&state_values); if (kerr) { result = kerr; goto finish; } // success result = kIOReturnSuccess; finish: return result; } IOReturn IOStateReporter::incrementChannelState(uint64_t channel_id, uint64_t state_id, uint64_t time_in_state, uint64_t intransitions, uint64_t last_intransition /*=0*/) { IOReturn res = kIOReturnError; int channel_index, state_index; lockReporter(); if (_getStateIndices(channel_id, state_id, &channel_index, &state_index) == kIOReturnSuccess) { if (_lastUpdateTimes[channel_index]) { panic("incrementChannelState() cannot be used after setChannelState()!\n"); } res = handleIncrementChannelStateByIndices(channel_index, state_index, time_in_state, intransitions, last_intransition); goto finish; } res = kIOReturnBadArgument; finish: unlockReporter(); return res; } IOReturn IOStateReporter::handleIncrementChannelStateByIndices(int channel_index, int state_index, uint64_t time_in_state, uint64_t intransitions, uint64_t last_intransition /*=0*/) { IOReturn kerr, result = kIOReturnError; IOStateReportValues state_values; int element_index; if (channel_index < 0 || channel_index >= _nChannels) { result = kIOReturnBadArgument; goto finish; } if (channel_index < 0 || channel_index > (_nElements - state_index) / _channelDimension) { result = kIOReturnOverrun; goto finish; } element_index = channel_index * _channelDimension + state_index; kerr = copyElementValues(element_index,(IOReportElementValues*)&state_values); if (kerr) { result = kerr; goto finish; } state_values.last_intransition = last_intransition; state_values.intransitions += intransitions; state_values.upticks += time_in_state; // determines current time for metadata kerr = setElementValues(element_index, (IOReportElementValues *)&state_values); if (kerr) { result = kerr; goto finish; } // success result = kIOReturnSuccess; finish: return result; } IOReturn IOStateReporter::setState(uint64_t new_state_id) { uint64_t last_intransition = 0; uint64_t prev_state_residency = 0; IOReturn res = kIOReturnError; IOStateReportValues *values; int channel_index = 0, element_index = 0, new_state_index = 0; int cnt; lockReporter(); if (_nChannels == 1) { for (cnt = 0; cnt < _channelDimension; cnt++) { new_state_index = element_index + cnt; values = (IOStateReportValues *)getElementValues(new_state_index); if (values == NULL) { res = kIOReturnError; goto finish; } if (values->state_id == new_state_id) { res = handleSetStateByIndices(channel_index, new_state_index, last_intransition, prev_state_residency); goto finish; } } } res = kIOReturnBadArgument; finish: unlockReporter(); return res; } IOReturn IOStateReporter::setState(uint64_t new_state_id, uint64_t last_intransition, uint64_t prev_state_residency) { return setState(new_state_id); } IOReturn IOStateReporter::setStateID(uint64_t channel_id, int state_index, uint64_t state_id) { IOReturn res = kIOReturnError; lockReporter(); res = handleSetStateID(channel_id, state_index, state_id); unlockReporter(); return res; } IOReturn IOStateReporter::handleSetStateID(uint64_t channel_id, int state_index, uint64_t state_id) { IOReturn res = kIOReturnError; IOStateReportValues state_values; int element_index = 0; IOREPORTER_CHECK_LOCK(); if (getFirstElementIndex(channel_id, &element_index) == kIOReturnSuccess) { if (state_index >= _channelDimension) { res = kIOReturnBadArgument; goto finish; } if (_nElements - state_index <= element_index) { res = kIOReturnOverrun; goto finish; } element_index += state_index; if (copyElementValues(element_index, (IOReportElementValues *)&state_values) != kIOReturnSuccess) { res = kIOReturnBadArgument; goto finish; } state_values.state_id = state_id; res = setElementValues(element_index, (IOReportElementValues *)&state_values); } // FIXME: set a bit somewhere (reporter-wide?) that state_ids can no longer be // assumed to be contiguous finish: return res; } IOReturn IOStateReporter::setStateByIndices(int channel_index, int new_state_index) { IOReturn res = kIOReturnError; uint64_t last_intransition = 0; uint64_t prev_state_residency = 0; lockReporter(); res = handleSetStateByIndices(channel_index, new_state_index, last_intransition, prev_state_residency); unlockReporter(); return res; } IOReturn IOStateReporter::setStateByIndices(int channel_index, int new_state_index, uint64_t last_intransition, uint64_t prev_state_residency) { return setStateByIndices(channel_index, new_state_index); } IOReturn IOStateReporter::handleSetStateByIndices(int channel_index, int new_state_index, uint64_t last_intransition, uint64_t prev_state_residency) { IOReturn res = kIOReturnError; IOStateReportValues curr_state_values, new_state_values; int curr_state_index = 0; int curr_element_index, new_element_index; uint64_t last_ch_update_time = 0; uint64_t recordTime = mach_absolute_time(); IOREPORTER_CHECK_LOCK(); if (channel_index < 0 || channel_index >= _nChannels) { res = kIOReturnBadArgument; goto finish; } // if no timestamp provided, last_intransition = time of recording (now) if (last_intransition == 0) { last_intransition = recordTime; } // First update target state if different than the current state // _currentStates[] initialized to -1 to detect first state transition curr_state_index = _currentStates[channel_index]; if (new_state_index != curr_state_index) { // fetch element data if (channel_index < 0 || channel_index > (_nElements-new_state_index) / _channelDimension) { res = kIOReturnOverrun; goto finish; } new_element_index = channel_index*_channelDimension + new_state_index; if (copyElementValues(new_element_index, (IOReportElementValues *)&new_state_values)) { res = kIOReturnBadArgument; goto finish; } // Update new state's transition info new_state_values.intransitions += 1; new_state_values.last_intransition = last_intransition; // and store the values res = setElementValues(new_element_index, (IOReportElementValues *)&new_state_values, recordTime); if (res != kIOReturnSuccess) { goto finish; } _currentStates[channel_index] = new_state_index; } /* Now update time spent in any previous state If new_state_index = curr_state_index, this updates time in the current state. If this is the channel's first state transition, the last update time will be zero. Note: While setState() should never be called on a channel being updated with increment/overrideChannelState(), that's another way that the last update time might not exist. Regardless, if there is no basis for determining time spent in previous state, there's nothing to update! */ last_ch_update_time = _lastUpdateTimes[channel_index]; if (last_ch_update_time != 0) { if (channel_index < 0 || channel_index > (_nElements-curr_state_index) / _channelDimension) { res = kIOReturnOverrun; goto finish; } curr_element_index = channel_index*_channelDimension + curr_state_index; if (copyElementValues(curr_element_index, (IOReportElementValues *)&curr_state_values)) { res = kIOReturnBadArgument; goto finish; } // compute the time spent in previous state, unless provided if (prev_state_residency == 0) { prev_state_residency = last_intransition - last_ch_update_time; } curr_state_values.upticks += prev_state_residency; res = setElementValues(curr_element_index, (IOReportElementValues*)&curr_state_values, recordTime); if (res != kIOReturnSuccess) { goto finish; } } // record basis for next "time in prior state" calculation // (also arms a panic in override/incrementChannelState()) _lastUpdateTimes[channel_index] = last_intransition; finish: return res; } // blocks might make this slightly easier? uint64_t IOStateReporter::getStateInTransitions(uint64_t channel_id, uint64_t state_id) { return _getStateValue(channel_id, state_id, kInTransitions); } uint64_t IOStateReporter::getStateResidencyTime(uint64_t channel_id, uint64_t state_id) { return _getStateValue(channel_id, state_id, kResidencyTime); } uint64_t IOStateReporter::getStateLastTransitionTime(uint64_t channel_id, uint64_t state_id) { return _getStateValue(channel_id, state_id, kLastTransitionTime); } uint64_t IOStateReporter::_getStateValue(uint64_t channel_id, uint64_t state_id, enum valueSelector value) { int channel_index = 0, element_index = 0, cnt; IOStateReportValues *values = NULL; uint64_t result = kIOReportInvalidValue; lockReporter(); if (getChannelIndices(channel_id, &channel_index, &element_index) == kIOReturnSuccess) { if (updateChannelValues(channel_index) == kIOReturnSuccess) { for (cnt = 0; cnt < _channelDimension; cnt++) { values = (IOStateReportValues *)getElementValues(element_index); if (state_id == values->state_id) { switch (value) { case kInTransitions: result = values->intransitions; break; case kResidencyTime: result = values->upticks; break; case kLastTransitionTime: result = values->last_intransition; default: break; } break; } element_index++; } } } unlockReporter(); return result; } uint64_t IOStateReporter::getStateLastChannelUpdateTime(uint64_t channel_id) { int channel_index; uint64_t result = kIOReportInvalidValue; lockReporter(); if (getChannelIndex(channel_id, &channel_index) == kIOReturnSuccess) { result = _lastUpdateTimes[channel_index]; } unlockReporter(); return result; } /* updateChannelValues() is called to refresh state before being reported outside the reporter. In the case of IOStateReporter, this is primarily an update to the "time in state" data. */ IOReturn IOStateReporter::updateChannelValues(int channel_index) { IOReturn kerr, result = kIOReturnError; int state_index, element_idx; uint64_t currentTime; uint64_t last_ch_update_time; uint64_t time_in_state; IOStateReportValues state_values; IOREPORTER_CHECK_LOCK(); if (channel_index < 0 || channel_index >= _nChannels) { result = kIOReturnBadArgument; goto finish; } /* First check to see whether this channel has begun self- calculation of time in state. It's possible this channel has yet to be initialized or that the driver is updating the channel with override/incrementChannelState() which never enable automatic time-in-state updates. In that case, there is nothing to update and we return success. */ last_ch_update_time = _lastUpdateTimes[channel_index]; if (last_ch_update_time == 0) { result = kIOReturnSuccess; goto finish; } // figure out the current state (if any) state_index = _currentStates[channel_index]; // e.g. given 4 4-state channels, the boundary is ch[3].st[3] <- _elems[15] if (channel_index < 0 || channel_index > (_nElements - state_index) / _channelDimension) { result = kIOReturnOverrun; goto finish; } element_idx = channel_index * _channelDimension + state_index; // get the current values kerr = copyElementValues(element_idx,(IOReportElementValues*)&state_values); if (kerr) { result = kerr; goto finish; } // calculate time in state currentTime = mach_absolute_time(); time_in_state = currentTime - last_ch_update_time; state_values.upticks += time_in_state; // and store the values kerr = setElementValues(element_idx, (IOReportElementValues *)&state_values, currentTime); if (kerr) { result = kerr; goto finish; } // Record basis for next "prior time" calculation _lastUpdateTimes[channel_index] = currentTime; // success result = kIOReturnSuccess; finish: return result; } |