X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d9a64523371fa019c4575bb400cbbc3a50ac9903..c3c9b80d004dbbfdf763edeb97968c6997e3b45b:/iokit/Kernel/IOInterruptEventSource.cpp diff --git a/iokit/Kernel/IOInterruptEventSource.cpp b/iokit/Kernel/IOInterruptEventSource.cpp index 0d96bbb86..a720e9a30 100644 --- a/iokit/Kernel/IOInterruptEventSource.cpp +++ b/iokit/Kernel/IOInterruptEventSource.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2014 Apple 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 @@ -11,10 +11,10 @@ * 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, @@ -22,10 +22,13 @@ * 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@ */ +#define IOKIT_ENABLE_SHARED_PTR + +#include #include #include #include @@ -34,6 +37,7 @@ #include #include #include +#include #if IOKITSTATS @@ -72,258 +76,284 @@ OSMetaClassDefineReservedUnused(IOInterruptEventSource, 5); OSMetaClassDefineReservedUnused(IOInterruptEventSource, 6); OSMetaClassDefineReservedUnused(IOInterruptEventSource, 7); -bool IOInterruptEventSource::init(OSObject *inOwner, - Action inAction, - IOService *inProvider, - int inIntIndex) +bool +IOInterruptEventSource::init(OSObject *inOwner, + Action inAction, + IOService *inProvider, + int inIntIndex) { - bool res = true; + bool res = true; - if ( !super::init(inOwner, (IOEventSourceAction) inAction) ) - return false; + if (!super::init(inOwner, (IOEventSourceAction) inAction)) { + return false; + } - reserved = IONew(ExpansionData, 1); + reserved = IONew(ExpansionData, 1); - if (!reserved) { - return false; - } + if (!reserved) { + return false; + } - bzero(reserved, sizeof(ExpansionData)); + bzero(reserved, sizeof(ExpansionData)); + + provider = inProvider; + producerCount = consumerCount = 0; + autoDisable = explicitDisable = false; + intIndex = ~inIntIndex; + + // Assumes inOwner holds a reference(retain) on the provider + if (inProvider) { + if (IA_ANY_STATISTICS_ENABLED) { + /* + * We only treat this as an "interrupt" if it has a provider; if it does, + * set up the objects necessary to track interrupt statistics. Interrupt + * event sources without providers are most likely being used as simple + * event source in order to poke at workloops and kick off work. + * + * We also avoid try to avoid interrupt accounting overhead if none of + * the statistics are enabled. + */ + reserved->statistics = IONew(IOInterruptAccountingData, 1); + + if (!reserved->statistics) { + /* + * We rely on the free() routine to clean up after us if init fails + * midway. + */ + return false; + } - provider = inProvider; - producerCount = consumerCount = 0; - autoDisable = explicitDisable = false; - intIndex = ~inIntIndex; + bzero(reserved->statistics, sizeof(IOInterruptAccountingData)); - // Assumes inOwner holds a reference(retain) on the provider - if (inProvider) { - if (IA_ANY_STATISTICS_ENABLED) { - /* - * We only treat this as an "interrupt" if it has a provider; if it does, - * set up the objects necessary to track interrupt statistics. Interrupt - * event sources without providers are most likely being used as simple - * event source in order to poke at workloops and kick off work. - * - * We also avoid try to avoid interrupt accounting overhead if none of - * the statistics are enabled. - */ - reserved->statistics = IONew(IOInterruptAccountingData, 1); + reserved->statistics->owner = this; + } - if (!reserved->statistics) { - /* - * We rely on the free() routine to clean up after us if init fails - * midway. - */ - return false; - } + res = (kIOReturnSuccess == registerInterruptHandler(inProvider, inIntIndex)); - bzero(reserved->statistics, sizeof(IOInterruptAccountingData)); + if (res) { + intIndex = inIntIndex; + } + } - reserved->statistics->owner = this; - } + IOStatisticsInitializeCounter(); - res = (kIOReturnSuccess == registerInterruptHandler(inProvider, inIntIndex)); + return res; +} - if (res) { - intIndex = inIntIndex; - } - } +IOReturn +IOInterruptEventSource::registerInterruptHandler(IOService *inProvider, + int inIntIndex) +{ + IOReturn ret; + int intType; + IOInterruptAction intHandler; - IOStatisticsInitializeCounter(); + ret = inProvider->getInterruptType(inIntIndex, &intType); + if (kIOReturnSuccess != ret) { + return ret; + } - return res; -} + autoDisable = (intType == kIOInterruptTypeLevel); + if (autoDisable) { + intHandler = OSMemberFunctionCast(IOInterruptAction, + this, &IOInterruptEventSource::disableInterruptOccurred); + } else { + intHandler = OSMemberFunctionCast(IOInterruptAction, + this, &IOInterruptEventSource::normalInterruptOccurred); + } -IOReturn IOInterruptEventSource::registerInterruptHandler(IOService *inProvider, - int inIntIndex) -{ - IOReturn ret; - int intType; - IOInterruptAction intHandler; - - ret = inProvider->getInterruptType(inIntIndex, &intType); - if (kIOReturnSuccess != ret) - return (ret); - - autoDisable = (intType == kIOInterruptTypeLevel); - if (autoDisable) { - intHandler = OSMemberFunctionCast(IOInterruptAction, - this, &IOInterruptEventSource::disableInterruptOccurred); - } - else - intHandler = OSMemberFunctionCast(IOInterruptAction, - this, &IOInterruptEventSource::normalInterruptOccurred); - - ret = provider->registerInterrupt(inIntIndex, this, intHandler); - - /* - * Add statistics to the provider. The setWorkLoop convention should ensure - * that we always go down the unregister path before we register (outside of - * init()), so we don't have to worry that we will invoke addInterruptStatistics - * erroneously. - */ - if ((ret == kIOReturnSuccess) && (reserved->statistics)) { - /* - * Stash the normal index value, for the sake of debugging. - */ - reserved->statistics->interruptIndex = inIntIndex; - - /* - * We need to hook the interrupt information up to the provider so that it - * can find the statistics for this interrupt when desired. The provider is - * responsible for maintaining the reporter for a particular interrupt, and - * needs a handle on the statistics so that it can request that the reporter - * be updated as needed. Errors are considered "soft" for the moment (it - * will either panic, or fail in a way such that we can still service the - * interrupt). - */ - provider->addInterruptStatistics(reserved->statistics, inIntIndex); - - /* - * Add the statistics object to the global list of statistics objects; this - * is an aid to debugging (we can trivially find statistics for all eligible - * interrupts, and dump them; potentially helpful if the system is wedged - * due to interrupt activity). - */ - interruptAccountingDataAddToList(reserved->statistics); - } - - return (ret); + ret = provider->registerInterrupt(inIntIndex, this, intHandler); + + /* + * Add statistics to the provider. The setWorkLoop convention should ensure + * that we always go down the unregister path before we register (outside of + * init()), so we don't have to worry that we will invoke addInterruptStatistics + * erroneously. + */ + if ((ret == kIOReturnSuccess) && (reserved->statistics)) { + /* + * Stash the normal index value, for the sake of debugging. + */ + reserved->statistics->interruptIndex = inIntIndex; + + /* + * We need to hook the interrupt information up to the provider so that it + * can find the statistics for this interrupt when desired. The provider is + * responsible for maintaining the reporter for a particular interrupt, and + * needs a handle on the statistics so that it can request that the reporter + * be updated as needed. Errors are considered "soft" for the moment (it + * will either panic, or fail in a way such that we can still service the + * interrupt). + */ + provider->addInterruptStatistics(reserved->statistics, inIntIndex); + + /* + * Add the statistics object to the global list of statistics objects; this + * is an aid to debugging (we can trivially find statistics for all eligible + * interrupts, and dump them; potentially helpful if the system is wedged + * due to interrupt activity). + */ + interruptAccountingDataAddToList(reserved->statistics); + } + + return ret; } void IOInterruptEventSource::unregisterInterruptHandler(IOService *inProvider, - int inIntIndex) + int inIntIndex) { - if (reserved->statistics) { - interruptAccountingDataRemoveFromList(reserved->statistics); - provider->removeInterruptStatistics(reserved->statistics->interruptIndex); - } + if (reserved->statistics) { + interruptAccountingDataRemoveFromList(reserved->statistics); + provider->removeInterruptStatistics(reserved->statistics->interruptIndex); + } - provider->unregisterInterrupt(inIntIndex); + provider->unregisterInterrupt(inIntIndex); } -IOInterruptEventSource * +OSSharedPtr IOInterruptEventSource::interruptEventSource(OSObject *inOwner, - Action inAction, - IOService *inProvider, - int inIntIndex) + Action inAction, + IOService *inProvider, + int inIntIndex) { - IOInterruptEventSource *me = new IOInterruptEventSource; + OSSharedPtr me = OSMakeShared(); - if (me && !me->init(inOwner, inAction, inProvider, inIntIndex)) { - me->release(); - return 0; - } + if (me && !me->init(inOwner, inAction, inProvider, inIntIndex)) { + return nullptr; + } - return me; + return me; } -IOInterruptEventSource * +OSSharedPtr IOInterruptEventSource::interruptEventSource(OSObject *inOwner, - IOService *inProvider, - int inIntIndex, - ActionBlock inAction) + IOService *inProvider, + int inIntIndex, + ActionBlock inAction) { - IOInterruptEventSource * ies; - ies = IOInterruptEventSource::interruptEventSource(inOwner, (Action) NULL, inProvider, inIntIndex); - if (ies) ies->setActionBlock((IOEventSource::ActionBlock) inAction); + OSSharedPtr ies; + ies = IOInterruptEventSource::interruptEventSource(inOwner, (Action) NULL, inProvider, inIntIndex); + if (ies) { + ies->setActionBlock((IOEventSource::ActionBlock) inAction); + } - return ies; + return ies; } -void IOInterruptEventSource::free() +void +IOInterruptEventSource::free() { - if (provider && intIndex >= 0) - unregisterInterruptHandler(provider, intIndex); + if (provider && intIndex >= 0) { + unregisterInterruptHandler(provider, intIndex); + } - if (reserved) { - if (reserved->statistics) { - IODelete(reserved->statistics, IOInterruptAccountingData, 1); - } + if (reserved) { + if (reserved->statistics) { + IODelete(reserved->statistics, IOInterruptAccountingData, 1); + } - IODelete(reserved, ExpansionData, 1); - } + IODelete(reserved, ExpansionData, 1); + } - super::free(); + super::free(); } -void IOInterruptEventSource::enable() +void +IOInterruptEventSource::enable() { - if (provider && intIndex >= 0) { - provider->enableInterrupt(intIndex); - explicitDisable = false; - enabled = true; - } + if (provider && intIndex >= 0) { + provider->enableInterrupt(intIndex); + explicitDisable = false; + enabled = true; + } } -void IOInterruptEventSource::disable() +void +IOInterruptEventSource::disable() { - if (provider && intIndex >= 0) { - provider->disableInterrupt(intIndex); - explicitDisable = true; - enabled = false; - } + if (provider && intIndex >= 0) { + provider->disableInterrupt(intIndex); + explicitDisable = true; + enabled = false; + } } -void IOInterruptEventSource::setWorkLoop(IOWorkLoop *inWorkLoop) +void +IOInterruptEventSource::setWorkLoop(IOWorkLoop *inWorkLoop) { - if (inWorkLoop) super::setWorkLoop(inWorkLoop); + if (inWorkLoop) { + super::setWorkLoop(inWorkLoop); + } - if (provider) { - if (!inWorkLoop) { - if (intIndex >= 0) { - /* - * It isn't necessarily safe to wait until free() to unregister the interrupt; - * our provider may disappear. - */ - unregisterInterruptHandler(provider, intIndex); - intIndex = ~intIndex; - } - } else if ((intIndex < 0) && (kIOReturnSuccess == registerInterruptHandler(provider, ~intIndex))) { - intIndex = ~intIndex; + if (provider) { + if (!inWorkLoop) { + if (intIndex >= 0) { + /* + * It isn't necessarily safe to wait until free() to unregister the interrupt; + * our provider may disappear. + */ + unregisterInterruptHandler(provider, intIndex); + intIndex = ~intIndex; + } + } else if ((intIndex < 0) && (kIOReturnSuccess == registerInterruptHandler(provider, ~intIndex))) { + intIndex = ~intIndex; + } } - } - if (!inWorkLoop) super::setWorkLoop(inWorkLoop); + if (!inWorkLoop) { + super::setWorkLoop(inWorkLoop); + } } -const IOService *IOInterruptEventSource::getProvider() const +const IOService * +IOInterruptEventSource::getProvider() const { - return provider; + return provider; } -int IOInterruptEventSource::getIntIndex() const +int +IOInterruptEventSource::getIntIndex() const { - return intIndex; + return intIndex; } -bool IOInterruptEventSource::getAutoDisable() const +bool +IOInterruptEventSource::getAutoDisable() const { - return autoDisable; + return autoDisable; } -bool IOInterruptEventSource::checkForWork() +bool +IOInterruptEventSource::checkForWork() { - uint64_t startSystemTime = 0; - uint64_t endSystemTime = 0; - uint64_t startCPUTime = 0; - uint64_t endCPUTime = 0; - unsigned int cacheProdCount = producerCount; - int numInts = cacheProdCount - consumerCount; - IOInterruptEventAction intAction = (IOInterruptEventAction) action; - ActionBlock intActionBlock = (ActionBlock) actionBlock; + uint64_t startSystemTime = 0; + uint64_t endSystemTime = 0; + uint64_t startCPUTime = 0; + uint64_t endCPUTime = 0; + unsigned int cacheProdCount = producerCount; + int numInts = cacheProdCount - consumerCount; + IOEventSource::Action intAction = action; + ActionBlock intActionBlock = (ActionBlock) actionBlock; + void *address; bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; - - IOStatisticsCheckForWork(); - - if ( numInts > 0 ) - { - if (trace) + + if (kActionBlock & flags) { + address = ptrauth_nop_cast(void *, _Block_get_invoke_fn((struct Block_layout *)intActionBlock)); + } else { + address = ptrauth_nop_cast(void *, intAction); + } + + IOStatisticsCheckForWork(); + + if (numInts > 0) { + if (trace) { IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION), - VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner), - VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); + VM_KERNEL_ADDRHIDE(address), + VM_KERNEL_ADDRHIDE(owner), + VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); + } if (reserved->statistics) { if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelSystemTimeIndex)) { @@ -336,8 +366,11 @@ bool IOInterruptEventSource::checkForWork() } // Call the handler - if (kActionBlock & flags) (intActionBlock)(this, numInts); - else (*intAction)(owner, this, numInts); + if (kActionBlock & flags) { + (intActionBlock)(this, numInts); + } else { + ((IOInterruptEventAction)intAction)(owner, this, numInts); + } if (reserved->statistics) { if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelCountIndex)) { @@ -354,23 +387,25 @@ bool IOInterruptEventSource::checkForWork() IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelSystemTimeIndex], endSystemTime - startSystemTime); } } - - if (trace) + + if (trace) { IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION), - VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner), - VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); - + VM_KERNEL_ADDRHIDE(address), + VM_KERNEL_ADDRHIDE(owner), + VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); + } + consumerCount = cacheProdCount; - if (autoDisable && !explicitDisable) + if (autoDisable && !explicitDisable) { enable(); - } - - else if ( numInts < 0 ) - { - if (trace) + } + } else if (numInts < 0) { + if (trace) { IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION), - VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner), - VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); + VM_KERNEL_ADDRHIDE(address), + VM_KERNEL_ADDRHIDE(owner), + VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); + } if (reserved->statistics) { if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelSystemTimeIndex)) { @@ -381,10 +416,13 @@ bool IOInterruptEventSource::checkForWork() startCPUTime = thread_get_runtime_self(); } } - + // Call the handler - if (kActionBlock & flags) (intActionBlock)(this, numInts); - else (*intAction)(owner, this, numInts); + if (kActionBlock & flags) { + (intActionBlock)(this, numInts); + } else { + ((IOInterruptEventAction)intAction)(owner, this, numInts); + } if (reserved->statistics) { if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelCountIndex)) { @@ -401,80 +439,114 @@ bool IOInterruptEventSource::checkForWork() IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelSystemTimeIndex], endSystemTime - startSystemTime); } } - - if (trace) + + if (trace) { IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION), - VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner), - VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); - + VM_KERNEL_ADDRHIDE(address), + VM_KERNEL_ADDRHIDE(owner), + VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop)); + } + consumerCount = cacheProdCount; - if (autoDisable && !explicitDisable) + if (autoDisable && !explicitDisable) { enable(); + } } - - return false; + + return false; } -void IOInterruptEventSource::normalInterruptOccurred - (void */*refcon*/, IOService */*prov*/, int /*source*/) +void +IOInterruptEventSource::normalInterruptOccurred +(void */*refcon*/, IOService */*prov*/, int /*source*/) { bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; - - IOStatisticsInterrupt(); - producerCount++; - - if (trace) - IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); - - if (reserved->statistics) { - if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { - IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); - } - } - - signalWorkAvailable(); - - if (trace) - IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); + + IOStatisticsInterrupt(); + producerCount++; + + if (trace) { + IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); + } + + if (reserved->statistics) { + if (reserved->statistics->enablePrimaryTimestamp) { + reserved->statistics->primaryTimestamp = mach_absolute_time(); + } + if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { + IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); + } + } + + signalWorkAvailable(); + + if (trace) { + IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); + } } -void IOInterruptEventSource::disableInterruptOccurred - (void */*refcon*/, IOService *prov, int source) +void +IOInterruptEventSource::disableInterruptOccurred +(void */*refcon*/, IOService *prov, int source) { bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false; - - prov->disableInterrupt(source); /* disable the interrupt */ - - IOStatisticsInterrupt(); - producerCount++; - - if (trace) - IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); - - if (reserved->statistics) { - if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { - IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); - } - } - - signalWorkAvailable(); - - if (trace) - IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); + + prov->disableInterrupt(source); /* disable the interrupt */ + + IOStatisticsInterrupt(); + producerCount++; + + if (trace) { + IOTimeStampStartConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); + } + + if (reserved->statistics) { + if (reserved->statistics->enablePrimaryTimestamp) { + reserved->statistics->primaryTimestamp = mach_absolute_time(); + } + if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingFirstLevelCountIndex)) { + IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingFirstLevelCountIndex], 1); + } + } + + signalWorkAvailable(); + + if (trace) { + IOTimeStampEndConstant(IODBG_INTES(IOINTES_SEMA), VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(owner)); + } } -void IOInterruptEventSource::interruptOccurred - (void *refcon, IOService *prov, int source) +void +IOInterruptEventSource::interruptOccurred +(void *_refcon, IOService *prov, int source) { - if (autoDisable && prov) - disableInterruptOccurred(refcon, prov, source); - else - normalInterruptOccurred(refcon, prov, source); + if (autoDisable && prov) { + disableInterruptOccurred(_refcon, prov, source); + } else { + normalInterruptOccurred(_refcon, prov, source); + } } -IOReturn IOInterruptEventSource::warmCPU - (uint64_t abstime) +IOReturn +IOInterruptEventSource::warmCPU +(uint64_t abstime) { - return ml_interrupt_prewarm(abstime); } + +void +IOInterruptEventSource::enablePrimaryInterruptTimestamp(bool enable) +{ + if (reserved->statistics) { + reserved->statistics->enablePrimaryTimestamp = enable; + } +} + +uint64_t +IOInterruptEventSource::getPrimaryInterruptTimestamp() +{ + if (reserved->statistics && reserved->statistics->enablePrimaryTimestamp) { + return reserved->statistics->primaryTimestamp; + } + return -1ULL; +}