2 * Copyright (c) 2012-2016 Apple Inc. All Rights Reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * AUTH: Cyril & Soren (Core OS)
32 * DATE: 2012-2013 (Copyright Apple Inc.)
33 * DESC: IOReporting interfaces for I/O Kit drivers
37 #ifndef _IOKERNEL_REPORTERS_H_
38 #define _IOKERNEL_REPORTERS_H_
40 #include <machine/limits.h>
42 #include <libkern/c++/OSPtr.h>
43 #include <IOKit/IOLib.h>
44 #include <IOKit/IOService.h>
45 #include <IOKit/IOLocks.h>
46 #include <IOKit/IOBufferMemoryDescriptor.h>
48 #include <IOKit/IOReportTypes.h>
49 #include <IOKit/IOKernelReportStructs.h>
51 #include <libkern/c++/OSPtr.h>
53 typedef OSDictionary IOReportLegendEntry
;
55 /*******************************
56 * TOC: this file contains
58 * 2a. IOReporter class declaration (public & non-public members)
59 * 2b. static IOReporter methods unrelated to the class
60 * 3. IOReporter subclass declarations (public & non-public members)
61 * 4. IOReportLegend class declaration
62 *******************************/
67 * IOReporting is a mechanism for I/O Kit drivers to gather statistics
68 * (or other information) and make it available to various "observers,"
69 * which are generally in user space. Requests for information come
70 * through two new IOService methods: ::configureReport(...) and
71 * ::updateReport(...). While not required (see IOReportTypes.h), drivers
72 * will generally use IOReporter subclass instances to track the requested
73 * information and respond to IOReporting requests. Drivers can use these
74 * classes to track information, either all the time or between "enable"
75 * and "disable" calls to IOService::configureReport().
77 * Available information is organized into "channels." A channel is
78 * uniquely identified by both driver (registry) ID and a 64-bit channel
79 * ID. One way drivers can advertise their channels is by publishing
80 * "legends" in the I/O Kit registry. In addition to collecting
81 * information and responding to queries, IOReporter objects can produce
82 * legend entries describing their channels. The IOReportLegend class
83 * helps manage legend entries from multiple reporter objects as well
84 * as with grouping channels logically for observers.
86 * An important basic constraint of the current implementation is that
87 * all channels reported by a particular reporter instance must share all
88 * traits except channel ID and name. Specifically, the channel type
89 * (including report class, categories, & size) and units. Additionally,
90 * IOHistogramReporter currently only supports one channel at a time.
92 * Currently, ::{configure/update}Report() can be called any time between
93 * when a driver calls registerService() and when free() is called on
94 * your driver. 12960947 tracks improvements / recommendations for
95 * correctly handling these calls during termination.
98 * IOReporting only imposes concurrent access constraints when multiple
99 * threads are accessing the same object. Three levels of constraint apply
100 * depending on a method's purpose:
101 * 1. Allocation/Teardown - same-instance concurrency UNSAFE, MAY BLOCK
102 * 2. Configuration - same-instance concurrency SAFE, MAY BLOCK
103 * 3. Update - same-instance concurrency SAFE, WILL NOT BLOCK
105 * Configuration requires memory management which can block and must
106 * be invoked with interrupts ENABLED (for example, NOT in the interrupt
107 * context NOR with a spin lock -- like IOSimpleLock -- held).
109 * Updates can be performed with interrupts disabled, but clients should
110 * take into account that IOReporters' non-blocking currenency is achieved
111 * with IOSimpleLockLockDisable/UnlockEnableInterrupts(): that is, by
112 * disabling interrupts and taking a spin lock. While IOReporting will
113 * never hold a lock beyond a call into it, some time may be spent within
114 * the call spin-waiting for the lock. Clients holding their own
115 * spin locks should carefully consider the impact of IOReporting's
116 * (small) additional latency before calling it while holding a spin lock.
118 * The documentation for each method indicates any concurrency guarantees.
122 /*********************************/
123 /*** 2a. IOReporter Base Class ***/
124 /*********************************/
126 class IOReporter
: public OSObject
128 OSDeclareDefaultStructors(IOReporter
);
131 /*! @function IOReporter::init
132 * @abstract base init() method, called by subclass initWith() methods
134 * @param reportingService - IOService associated with all channels
135 * @param channelType - type info for all channels (element_idx = 0)
136 * @param unit - description applied for all channels
137 * @result true on success, false otherwise
140 * init() establishes the parameters of all channels for this reporter
141 * instance. Any channels added via addChannel() will be of this type
142 * and have this unit.
144 * IOReporter clients should use the static <subclass>::with() methods
145 * below to obtain fully-initialized reporter instances. ::free()
146 * expects ::init() to have completed successfully. On failure, any
147 * allocations are cleaned up.
149 * Locking: same-instance concurrency UNSAFE
151 virtual bool init(IOService
*reportingService
,
152 IOReportChannelType channelType
,
157 /*! @function IOReporter::addChannel
158 * @abstract add an additional, similar channel to the reporter
160 * @param channelID - identifier for the channel to be added
161 * @param channelName - an optional human-readble name for the channel
162 * @result appropriate IOReturn code
165 * The reporter will allocate memory to track a new channel with the
166 * provided ID and name (if any). Its other traits (type, etc) will
167 * be those provided when the reporter was initialized. If no channel
168 * name is provided and the channelID consists solely of ASCII bytes,
169 * those bytes (ignoring any NUL bytes) will be used as the
170 * human-readable channel name in user space. The IOREPORT_MAKEID()
171 * macro in IOReportTypes.h can be used to create ASCII channel IDs.
173 * Locking: same-instance concurrency SAFE, MAY BLOCK
175 IOReturn
addChannel(uint64_t channelID
, const char *channelName
= NULL
);
177 /*! @function IOReporter::createLegend
178 * @abstract create a legend entry represending this reporter's channels
179 * @result An IOReportLegendEntry object or NULL on failure.
181 * All channels added to the reporter will be represented
182 * in the resulting legend entry.
184 * Legends must be published togethar as an array under the
185 * kIOReportLegendKey in the I/O Kit registry. The IOReportLegend
186 * class can be used to properly combine legend entries from multiple
187 * reporters as well as to put channels into groups of interest to
188 * observers. When published, individual legend entries share
189 * characteristics such as group and sub-group. Multiple IOReporter
190 * instances are required to produce independent legend entries which
191 * can then be published with different characteristics.
193 * Drivers wishing to publish legends should do so as part of their
194 * ::start() routine. As superclasses *may* have installed legend
195 * entries, any existing existing legend should be retrieved and
196 * IOReportLegend used to merge it with the new entries.
198 * Recommendations for best practices are forthcoming.
200 * Instead of calling createLegend on your reporter object and then
201 * appending it manually to IOReportLegend, one may prefer to call
202 * IOReportLegend::appendReporterLegend which creates and appends a
203 * reporter's IOReportLegendEntry in a single call.
205 * Locking: same-instance concurrency SAFE, MAY BLOCK
207 OSPtr
<IOReportLegendEntry
> createLegend(void);
209 /*! @function IOReporter::configureReport
210 * @abstract track IOService::configureReport(), provide sizing info
212 * @param channelList - channels to configure
213 * @param action - enable/disable/size, etc (see IOReportTypes.h)
214 * @param result - *incremented* for kIOReportGetDimensions
215 * @param destination - action-specific default destination
216 * @result appropriate IOReturn code
219 * Any time a reporting driver's ::configureReport method is invoked,
220 * this method should be invoked on each IOReporter that is being
221 * used by that driver to report channels in channelList.
223 * Any channels in channelList which are not tracked by this reporter
224 * are ignored. ::configureReport(kIOReportGetDimensions) expects
225 * the full size of all channels, including any reported by
226 * superclasses. It is valid to call this routine on multiple
227 * reporter objects in succession and they will increment 'result'
228 * to provide the correct total.
230 * In the initial release, this routine is only required to calculate
231 * the response to kIOReportGetDimensions, but in the future it will
232 * will enable functionality like "triggered polling" via
233 * kIOReportNotifyHubOnChange. Internally, it is already keeping
234 * track of the number of times each channel has been enabled and
235 * disabled. 13073064 tracks adding a method to see whether any
236 * channels are currently being observed.
238 * The static IOReporter::configureAllReports() will call this method
239 * on multiple reporters grouped in an OSSet.
241 * Locking: same-instance concurrency SAFE, MAY BLOCK
243 IOReturn
configureReport(IOReportChannelList
*channelList
,
244 IOReportConfigureAction action
,
248 /*! @function IOReporter::updateReport
249 * @abstract Produce standard reply to IOService::updateReport()
251 * @param channelList - channels to update
252 * @param action - copy/trace data (see IOReportTypes.h)
253 * @param result - action-specific return value (e.g. size of data)
254 * @param destination - destination for this update (action-specific)
255 * @result appropriate IOReturn code
258 * This method searches channelList for channels tracked by this
259 * reporter, writes the corresponding data into 'destination', and
260 * updates 'result'. It should be possible to pass a given set of
261 * IOService::updateReport() arguments to any and all reporters as
262 * well as to super::updateReport() and get the right result.
264 * The static IOReporter::updateAllReports() will call this method
265 * on an OSSet of reporters.
267 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
269 IOReturn
updateReport(IOReportChannelList
*channelList
,
270 IOReportConfigureAction action
,
274 /*! @function IOReporter::free
275 * @abstract Releases the object and all its resources.
278 * ::free() [called on last ->release()] assumes that init() [called
279 * by static ::with() methods] has completed successfully.
281 * Locking: same-instance concurrency UNSAFE
283 virtual void free(void) APPLE_KEXT_OVERRIDE
;
285 /*! @function IOReporter::init
286 * @abstract Initialize global state
289 * ::initialize() [called during IOStartIOKit] initializes all global
290 * state for IOReporter objects.
293 static void initialize(void);
296 /*********************************/
297 /*** 2b. Useful Static Methods ***/
298 /*********************************/
300 /* The following static functions are intended to simplify the management
301 * of multiple reporters. They may be superseded in the future by an
302 * IOReportManager class.
305 /*! @function IOReporter::configureAllReports
306 * @abstract call configureReport() on multiple IOReporter objects
308 * @param reporters - OSSet of IOReporter objects
309 * @param channelList - full list of channels to configure
310 * @param action - enable/disable/size, etc
311 * @param result - action-specific returned value
312 * @param destination - action-specific default destination
313 * @result success if all objects successfully complete
314 * IOReporter::configureReport()
317 * The OSSet must only contain IOReporter instances. The presence
318 * of non-IOReporter instances will cause this function to return
319 * kIOReturnBadArgument. If any reporter returns an error, the
320 * function will immediately return that error.
322 * Per the IOReporter::configureReport() documentation, each
323 * reporter will search channelList for channels it is reporting
324 * and provide a partial response.
326 static IOReturn
configureAllReports(OSSet
*reporters
,
327 IOReportChannelList
*channelList
,
328 IOReportConfigureAction action
,
331 // FIXME: just put the function (inline-ish) here?
333 /*! @function IOReporter::updateAllReports
334 * @abstract call updateReport() on multiple IOReporter objects
336 * @param reporters - OSSet of IOReporter objects
337 * @param channelList - full list of channels to update
338 * @param action - type/style of update
339 * @param result - returned details about what was updated
340 * @param destination - destination for this update (action-specific)
341 * @result IOReturn code
343 * The OSSet must only contain IOReporter instances. The presence
344 * of non-IOReporter instances will cause this function to return
345 * kIOReturnBadArgument. If any reporter returns an error, the
346 * function will immediately return that error.
348 * Per the IOReporter::configureReport() documentation, each
349 * reporter will search channelList for channels it is reporting
350 * and provide a partial response.
352 static IOReturn
updateAllReports(OSSet
*reporters
,
353 IOReportChannelList
*channelList
,
354 IOReportConfigureAction action
,
357 // FIXME: just put the function (inline-ish) here?
360 /* Protected (subclass-only) Methods
362 * General subclassing is not encouraged as we intend to improve
363 * internal interfaces. If you need something that might require
364 * a subclass, please file a bug against IOReporting/X and we will
367 * One important concept for sub-classes (not clients) is that report
368 * data is stored in IOReportElement structures (see IOReportTypes.h).
372 /*! @function IOReporter::lockReporterConfig
373 * @function IOReporter::unlockReporterConfig
374 * @abstract prevent concurrent reconfiguration of a reporter
377 * lockReporterConfig() takes a mutex-based lock intended to prevent
378 * concurrent access to the reporter's configuration. It is not
379 * intended to prevent updates to the reporter's data. As long as
380 * all other requirements are met, it is safe to simultaneously hold
381 * both the configuration and data locks on a single reporter.
383 * lockReporterConfig() is used by routines such as addChannel().
384 * See also lockReporter() and ::handle*Swap*() below.
386 void lockReporterConfig(void);
387 void unlockReporterConfig(void);
389 /*! @function IOReporter::lockReporter
390 * @function IOReporter::unlockReporter
391 * @abstract prevent concurrent access to a reporter's data
394 * This method grabs a lock intended to control access the reporter's
395 * reporting data. Sub-classes maninupating internal report values
396 * must make sure the reporter is locked (usually by the most generic
397 * public interface) before calling getElementValues(),
398 * copyElementValues(), or setElementValues().
400 * Subclasses should ensure that this lock is taken exactly once
401 * before directly accessing reporter data. For example,
402 * [virtual] IOFooReporter::handleSetFoo(.) {
403 * // assert(lock_held)
404 * getElementValues(1..)
405 * getElementValues(3..)
406 * getElementValues(5..)
408 * setElementValues(6..)
410 * IOFooReporter::setFoo(.) { // not virtual
416 * IOReporter::handle*() use lockReporter() similarly. For example,
417 * the lock is taken by IOReporter::updateReport() and is already
418 * held by the time any ::updateChannelValues() methods are called.
420 * Subclasses cannot call this routine if the lock is already held.
421 * That's why IOReporting generally only calls it from non-virtual
422 * public methods. In particular, this method should not be called
423 * it from ::handle*() methods which exist to allow override after
426 * Because lockReporter() uses a spin lock, it is SAFE to use in the
427 * interrupt context. For the same reason, however, it is UNSAFE
428 * to perform any blocking blocking operations (including memory
429 * allocations) while holding this lock.
431 void lockReporter(void);
432 void unlockReporter(void);
436 * The ::handle*Swap* functions allow subclasses to safely reconfigure
437 * their internal state. A non-virtual function handles locking
438 * and invokes the functions in order:
439 * - lockReporterConfig() // protecting instance vars but not content
440 * - prepare / allocate buffers of the new size
441 * - if error, bail (unlocking, of course)
443 * - lockReporter() // protecting data / blocking updates
444 * - swap: preserve continuing data / install new buffers
447 * - deallocate now-unused buffers
448 * - unlockReporterConfig()
450 /*! @function IOReporter::handleSwapPrepare
451 * @abstract allocate memory in preparation for an instance variable swap
453 * @param newNChannels target number of channels
454 * @result IOReturn code
457 * ::handleSwapPrepare() is responsible for allocating appropriately-
458 * sized buffers (based on the new number of channels) and storing
459 * them in _swap* instance variables. If returning and error, it
460 * must deallocate any buffers and set to NULL any _swap* variables.
462 * Locking: The caller must ensure that the *config* lock is HELD but
463 * that the reporter (data) lock is *NOT HELD*.
465 virtual IOReturn
handleSwapPrepare(int newNChannels
);
467 /*! @function IOReporter::handleAddChannelSwap
468 * @abstract update primary instance variables with new buffers
470 * @param channel_id ID of channel being added
471 * @param symChannelName optional channel name, in an allocated object
472 * @result IOReturn code
475 * handlAddChannelSwap() replaces the primary instance variables
476 * with buffers allocated in handlePrepareSwap(). It copies the the
477 * existing data into the appropriate portion of the new buffers.
478 * Because it is specific to adding one channel, it assumes that the
479 * target number of channels is one greater than the current value
482 * IOReporter::handleAddChannelSwap() increments _nElements and
483 * _nChannels. To ensure that these variables describe the current
484 * buffers throughout ::handle*Swap(), subclasses overriding this
485 * method should call super::handleAddChannelSwap() after swapping
486 * their own instance variables.
488 * If returning an error, all implementations should leave their
489 * instance variables as they found them (*unswapped*). That ensures
490 * handleSwapCleanup() cleans up the unused buffers regardless of
491 * whether the swap was complete.
493 * Pseudo-code incorporating these suggestions:
494 * res = <err>; swapComplete = false;
495 * if (<unexpected>) goto finish
496 * tmpBuf = _primaryBuf; _primaryBuf = _swapBuf; _swapBuf = _primaryBuf;
498 * swapComplete = true;
499 * res = super::handle*Swap()
502 * if (res && swapComplete) // unswap
504 * Locking: The caller must ensure that BOTH the configuration and
505 * reporter (data) locks are HELD.
507 virtual IOReturn
handleAddChannelSwap(uint64_t channel_id
,
508 const OSSymbol
*symChannelName
);
510 /*! @function IOReporter::handleSwapCleanup
511 * @abstract release and forget unused buffers
513 * @param swapNChannels channel-relative size of the _swap buffers
516 * ::handleSwapCleanup() is responsible for deallocating the buffers
517 * no longer used after a swap. It must always be called if
518 * SwapPrepare() completes successfully. Because bufers may be
519 * swapped in and out of existance, the _swap* variables may be
520 * NULL and should be set to NULL when complete.
522 * Locking: The caller must ensure that the *config* lock is HELD but
523 * that the reporter (data) lock is *NOT HELD*.
525 virtual void handleSwapCleanup(int swapNChannels
);
527 /*! @function IOReporter::handleConfigureReport
528 * @abstract override vector for IOReporter::configureReport()
529 * [parameters and result should exactly match]
532 * The public base class method takes the reporter lock, calls this
533 * function, and then drops the lock. Subclasses should not call
534 * this function directly.
536 virtual IOReturn
handleConfigureReport(IOReportChannelList
*channelList
,
537 IOReportConfigureAction action
,
541 /*! @function IOReporter::handleUpdateReport
542 * @abstract override vector for IOReporter::updateReport()
543 * [parameters and result should exactly match]
546 * The public base class method takes the reporter lock, calls this
547 * function, and then drops the lock. Subclasses should not call
548 * this function directly.
550 * This function may be overriden but the common case should be to
551 * simply update reporter's specific values by overriding
552 * IOReporter::updateChannelValues().
554 virtual IOReturn
handleUpdateReport(IOReportChannelList
*channelList
,
555 IOReportConfigureAction action
,
559 /* @function IOReporter::handleCreateLegend
560 * @abstract override vector for IOReporter::createLegend()
561 * [parameters and result should exactly match]
564 * The public base class method takes the reporter lock, calls this
565 * function, and then drops the lock. Subclasses should not call
566 * this function directly.
568 virtual OSPtr
<IOReportLegendEntry
> handleCreateLegend(void);
570 /*! @function IOReporter::updateChannelValues
571 * @abstract update channel values for IOReporter::updateReport()
573 * @param channel_index - logical (internal) index of the channel
574 * @result appropriate IOReturn code
577 * Internal reporter method to allow a subclass to update channel
578 * data when updateReport() is called. This routine handles the
579 * common case of a subclass needing to refresh state in response
580 * to IOReporter::updateReport(). It saves the complexity of
581 * parsing the full parameters to IOReporter::updateReport().
583 * The IOReporter base class implementation does not do anything
584 * except return success.
586 * Locking: IOReporter::updateReport() takes the reporter lock,
587 * determines the indices involved, calls this function, and
588 * then proceeds to provide values to the caller. If subclasses
589 * need to call this routine directly, they must ensure that
590 * the reporter (data) lock is held: see
591 * IOReporter::lockReporter().
593 virtual IOReturn
updateChannelValues(int channel_index
);
596 /*! @function IOReporter::updateReportChannel
597 * @abstract Internal method to extract channel data to a destination
599 * @param channel_index - offset into internal elements array
600 * @param nElements - incremented by the number of IOReportElements added
601 * @param destination - pointer to the destination buffer
602 * @result IOReturn code
605 * updateReportChannel() is used to extract a single channel's
606 * data to the updateReport() destination.
608 * Locking: Caller must ensure that the reporter (data) lock is held.
610 IOReturn
updateReportChannel(int channel_index
,
612 IOBufferMemoryDescriptor
*destination
);
615 /*! @function IOReporter::setElementValues
616 * @abstract Atomically update a specific member of _elements[].
618 * @param element_index - index of the _element in internal array
619 * @param values - IORepoterElementValues to replace those at _elements[idx]
620 * @param record_time - optional mach_absolute_time to be used for metadata
621 * @result IOReturn code
624 * element_index can be obtained from getFirstElementIndex(). If
625 * record_time is not provided, IOReporter::setElementValues() will
626 * fetch the current mach_absolute_time. If the current time is
627 * already known, it is more efficient to pass it along.
629 * Locking: Caller must ensure that the reporter (data) lock is held.
631 virtual IOReturn
setElementValues(int element_index
,
632 IOReportElementValues
*values
,
633 uint64_t record_time
= 0);
635 /*! @function IOReporter::getElementValues
636 * @abstract Internal method to directly access the values of an element
638 * @param element_index - index of the _element in internal array
639 * @result A pointer to the element values requested or NULL on failure
641 * @discussion Locking: Caller must ensure that the reporter (data) lock is held.
642 * The returned pointer is only valid until unlockReporter() is called.
644 virtual const IOReportElementValues
* getElementValues(int element_index
);
646 /*! @function IOReporter::getFirstElementIndex
647 * @abstract Returns the first element index for a channel
649 * @param channel_id - ID of the channel
650 * @param element_index - pointer to the returned element_index
651 * @result appropriate IOReturn code
654 * For efficiently and thread-safely reading _elements
656 * Locking: Caller must ensure that the reporter (data) lock is held.
658 virtual IOReturn
getFirstElementIndex(uint64_t channel_id
,
661 /*! @function IOReporter::getChannelIndex
662 * @abstract Returns the index of a channel from internal data structures
664 * @param channel_id - ID of the channel
665 * @param channel_index - pointer to the returned element_index
666 * @result appropriate IOReturn code
669 * For efficiently and thread-safely reading channels
671 * Locking: Caller must ensure that the reporter (data) lock is held.
673 virtual IOReturn
getChannelIndex(uint64_t channel_id
,
676 /*! @function IOReporter::getChannelIndices
677 * @abstract Returns the index of a channel and its corresponding
678 * first element index from internal data structure
680 * @param channel_id - ID of the channel
681 * @param channel_index - pointer to the returned channel_index
682 * @param element_index - pointer to the returned element_index
683 * @result appropriate IOReturn code
686 * For efficiently and thread-safely reading channel elements.
687 * It is commonly useful to get access to both channel and element
688 * indices togther. This convenience method allows sub-classes to
689 * get both indices simultaneously.
691 * Locking: Caller must ensure that the reporter (data) lock is held.
693 virtual IOReturn
getChannelIndices(uint64_t channel_id
,
697 /*! @function IOReporter::copyElementValues
698 * @abstract Copies the values of an internal element to *elementValues
700 * @param element_index - Index of the element to return values from
701 * @param elementValues - For returning the content of element values
702 * @result Returns the content of an element
705 * For efficiently and thread-safely reading _elements.
706 * May need to find the index of the element first.
708 * Locking: Caller must ensure that the reporter (data) lock is held.
710 virtual IOReturn
copyElementValues(int element_index
,
711 IOReportElementValues
*elementValues
);
715 /*! @function IOReporter::copyChannelIDs
716 * @abstract return an an OSArray of the reporter's
719 * @result An OSArray of the repoter's channel ID's as OSNumbers
722 * This method is an internal helper function used to prepare a
723 * legend entry. It encapsulates the channel IDs in OSNumbers and
724 * aggregates them in an OSArray used when building the IOReportLegend
726 * Locking: Caller must ensure that the reporter (data) lock is held.
728 OSPtr
<OSArray
> copyChannelIDs(void);
730 /*! @function IOReporter::legendWith
731 * @abstract Internal method to help create legend entries
733 * @param channelIDs - OSArray of OSNumber(uint64_t) channels IDs.
734 * @param channelNames - parrallel OSArray of OSSymbol(rich names)
735 * @param channelType - the type of all channels in this legend
736 * @param unit - The unit for the quantity recorded by this reporter object
738 * @result An IOReportLegendEntry object or NULL on failure
741 * This static method is the main legend creation function. It is called by
742 * IOReporter sub-classes and is responsible for building an
743 * IOReportLegendEntry corresponding to this reporter object.
744 * This legend entry may be extended by the sub-class of IOReporter if
747 * Locking: SAFE to call concurrently (no static globals), MAY BLOCK
749 static OSPtr
<IOReportLegendEntry
> legendWith(OSArray
*channelIDs
,
750 OSArray
*channelNames
,
751 IOReportChannelType channelType
,
754 // protected instance variables (want to get rid of these)
756 IOReportChannelType _channelType
;
757 uint64_t _driver_id
; // driver reporting data
759 // IOHistogramReporter accesses these; need to re-do its instantiation
760 IOReportElement
*_elements
;
761 int *_enableCounts
; // refcount kIOReportEnable/Disable
762 uint16_t _channelDimension
;// Max channel size
764 int _nChannels
; // Total Channels in this reporter
765 OSPtr
<OSArray
> _channelNames
;
767 // MUST be protected because check is a macro!
768 bool _reporterIsLocked
;
769 bool _reporterConfigIsLocked
;
771 // Required for swapping inside addChannel
772 IOReportElement
*_swapElements
;
773 int *_swapEnableCounts
;
775 // private instance variables
779 int _enabled
;// 'enabled' if _enabled > 0
782 IOInterruptState _interruptState
;
783 IOSimpleLock
*_reporterLock
;
787 /************************************/
788 /***** 3. IOReporter Subclasses *****/
789 /************************************/
792 * @class IOSimpleReporter
793 * @abstract Report simple integers
795 * Each IOSimpleReporter can have an arbitrary number of channels,
796 * each publishing a single integer value at any given time.
799 class IOSimpleReporter
: public IOReporter
801 OSDeclareDefaultStructors(IOSimpleReporter
);
805 /*! @function IOSimpleReporter::with
806 * @abstract create an initialized simple reporter
808 * @param reportingService - IOService associated with all channels
809 * @param categories - The category in which the report should be classified
810 * @param unit - The unit for the quantity recorded by the reporter object
811 * @result On success, an instance of IOSimpleReporter, else NULL
814 * Creates an instance of IOSimpleReporter object
816 * Locking: SAFE to call concurrently (no static globals), MAY BLOCK.
818 static OSPtr
<IOSimpleReporter
> with(IOService
*reportingService
,
819 IOReportCategories categories
,
822 /*! @function IOSimpleReporter::setValue
823 * @abstract Thread safely set a channel's value
825 * @param channel_id - ID of the channel for which the value needs to be set
826 * @param value - New channel value
827 * @result Appropriate IOReturn code
830 * Updates the value of a channel to the provided value.
832 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
834 IOReturn
setValue(uint64_t channel_id
,
837 /*! @function IOSimpleReporter::incrementValue
838 * @abstract Thread safely increment a channel's value by a given amount
840 * @param channel_id - ID of the channel for which the value needs to be incremented
841 * @param increment - Amount to be added to the current channel value
842 * @result Appropriate IOReturn code
844 * Increments the value of the channel ID by the provided amount.
846 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
848 IOReturn
incrementValue(uint64_t channel_id
,
851 /*! @function IOSimpleReporter::getValue
852 * @abstract Thread safely access a channel value
854 * @param channel_id - ID of the channel to get a value from
855 * @result Returns the current value stored in the channel
857 * Accessor method to a channel's current stored value
859 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
861 int64_t getValue(uint64_t channel_id
);
865 /*! @function IOSimpleReporter::initWith
866 * @abstract instance method implementation called by IOSimpleReporter::with
869 * See description of parameters above
871 * Locking: same-instance concurrency UNSAFE
873 virtual bool initWith(IOService
*reportingService
,
874 IOReportCategories categories
,
883 * @class IOStateReporter
884 * @abstract Report state machine data
886 * Each IOStateReporter can report information for an arbitrary number
887 * of similar state machines. All must have the same number of states.
889 class IOStateReporter
: public IOReporter
891 OSDeclareDefaultStructors(IOStateReporter
);
895 /*! @function IOStateReporter::with
896 * @abstract State reporter static creation method
898 * @param reportingService - The I/O Kit service for this reporter's channels
899 * @param categories - The categories for this reporter's channels
900 * @param nstates - Maximum number of states for this reporter's channels
901 * @param unit - optional parameter if using override/increment...()
902 * @result on success, an IOStateReporter instance, else NULL
905 * Creates an instance of IOStateReporter. The default time scale
906 * is the current system's notion of mach_absolute_time(). Using a
907 * non-default time scale requires the use of
908 * override/incrementChannelState() instead of setState().
909 * setState() always updates using mach_absolute_time().
911 * Locking: SAFE to call concurrently (no static globals), MAY BLOCK
913 static OSPtr
<IOStateReporter
> with(IOService
*reportingService
,
914 IOReportCategories categories
,
916 IOReportUnit unit
= kIOReportUnitHWTicks
);
918 /*! @function IOStateReporter::setStateID
919 * @abstract Assign a non-default ID to a state
921 * @param channel_id - ID of channel containing the state in question
922 * @param state_index - index of state to give an ID: [0..(nstates-1)]
923 * @param state_id - 64-bit state ID, for ASCII, use IOREPORT_MAKEID
925 * @result Appropriate IOReturn code
928 * By default, IOStateReporter identifies its channel states by
929 * numbering them from 0 to <nstates - 1>. If setStateID is not
930 * called to customize the state IDs, the numbered states will be
931 * kept throughout the life of the object and it is safe to reference
932 * those states by their indices. Otherwise, after setStateID() has
933 * been called, the ordering of states is no longer guaranteed and
934 * the client must reference states by their assigned state ID.
936 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
938 IOReturn
setStateID(uint64_t channel_id
,
942 /*! @function IOStateReporter::setChannelState
943 * @abstract Updates the current state of a channel to a new state
945 * @param channel_id - ID of the channel which is updated to a new state
946 * @param new_state_id - ID of the target state for this channel
947 * @param last_intransition - deprecated: time of most recent entry
948 * @param prev_state_residency - deprecated: time spent in previous state
949 * @result Appropriate IOReturn code
952 * setChannelState() updates the amount of time spent in the previous
953 * state (if any) and increments the number of transitions into the
954 * new state. It also sets the target state's last transition time to
955 * the current time and enables internal time-keeping for the channel.
956 * In this mode, calls like getStateResidencyTime() and updateReport()
957 * automatically update a channel's time in state.
959 * new_state_id identifies the target state as initialized
960 * (0..<nstates-1>) or as configured by setStateID().
962 * Drivers wishing to compute and report their own time in state
963 * should use incrementChannelState() or overrideChannelState(). It
964 * is not currently possible for a driver to synchronize with the
965 * automatic time-keeping enabled by setChannelState(). The
966 * 4-argument version of setChannelState() is thus impossible to
967 * use correctly. In the future, there may be a setChannelState()
968 * which accepts a last_intransition parameter and uses it to
969 * automatically calculate time in state (ERs -> IOReporting / X).
971 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
973 IOReturn
setChannelState(uint64_t channel_id
,
974 uint64_t new_state_id
,
975 uint64_t last_intransition
,
976 uint64_t prev_state_residency
) __deprecated
;
978 /*! @function IOStateReporter::setChannelState
979 * @abstract Updates the current state of a channel to a new state
981 * @param channel_id - ID of the channel which is updated to a new state
982 * @param new_state_id - ID of the target state for this channel
983 * @result Appropriate IOReturn code
986 * setChannelState() updates the amount of time spent in the previous
987 * state (if any) and increments the number of transitions into the
988 * new state. It also sets the target state's last transition time to
989 * the current time and enables internal time-keeping for the channel.
990 * In this mode, calls like getStateResidencyTime() and updateReport()
991 * automatically update a channel's time in state.
993 * new_state_id identifies the target state as initialized
994 * (0..<nstates-1>) or as configured by setStateID().
996 * Drivers wishing to compute and report their own time in state
997 * should use incrementChannelState() or overrideChannelState(). It
998 * is not currently possible for a driver to synchronize with the
999 * automatic time-keeping enabled by setChannelState(). The
1000 * 4-argument version of setChannelState() is thus impossible to
1001 * use correctly. In the future, there may be a setChannelState()
1002 * which accepts a last_intransition parameter and uses it to
1003 * automatically calculate time in state (ERs -> IOReporting / X).
1005 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1007 IOReturn
setChannelState(uint64_t channel_id
,
1008 uint64_t new_state_id
);
1011 /*! @function IOStateReporter::setState
1012 * @abstract Updates state for single channel reporters
1014 * @param new_state_id - New state for the channel
1015 * @result Appropriate IOReturn code.
1018 * setState() is a convenience method for single-channel state
1019 * reporter instances. An error will be returned if the reporter
1020 * in question has more than one channel.
1022 * See further discussion at setChannelState().
1024 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1026 IOReturn
setState(uint64_t new_state_id
);
1028 /*! @function IOStateReporter::setState
1029 * @abstract Updates state for single channel reporters
1031 * @param new_state_id - New state for the channel
1032 * @param last_intransition - deprecated: time of most recent entry
1033 * @param prev_state_residency - deprecated: spent in previous state
1034 * @result Appropriate IOReturn code.
1037 * setState() is a convenience method for single-channel state
1038 * reporter instances. An error will be returned if the reporter
1039 * in question has more than one channel.
1041 * See further discussion at setChannelState().
1043 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1045 IOReturn
setState(uint64_t new_state_id
,
1046 uint64_t last_intransition
,
1047 uint64_t prev_state_residency
) __deprecated
;
1049 /*! @function IOStateReporter::overrideChannelState
1050 * @abstract Overrides state data for a channel with passed arguments
1052 * @param channel_id - ID of the channel which state is to be updated
1053 * @param state_id - state id for the channel
1054 * @param time_in_state - time used as new total time in state
1055 * @param intransitions - total number of transitions into state
1056 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1057 * @result Appropriate IOReturn code
1060 * overrideChannelState() sets a particular state's time in state
1061 * and transition count to the values provided. The optional
1062 * last_intransition records the last time the channel transitioned
1063 * into the given state. Passing 0 for time_in_state and
1064 * intransitions will force the current values to 0. Passing 0
1065 * for last_intransition for all states will disable the notion
1066 * of a channel's "current state."
1068 * The most recent last_intransition (amongst all states in a channel)
1069 * logically determines the current state. If last_intransition is
1070 * not provided for any state, the channel will not report a current
1071 * For consistent results, it is important to either never specify
1072 * last_intransition or to always specify it.
1074 * There is currently a bug in determining current state (13423273).
1075 * The IOReportMacros.h macros only update the state's metadata
1076 * timestamp and libIOReport only looks at the metadata timestamps
1077 * to determine the current state. Until that bug is fixed, whichever
1078 * state is updated most recently will be considered the "current"
1079 * state by libIOReport.
1081 * ::setState()'s automatic "time in state" updates are not supported
1082 * when using overrideChannelState(). Clients must not use
1083 * overrideChannelState() on any channel that has ::setState() called
1084 * on it. Unlike with ::setState(), clients using
1085 * overrideChannelState() are responsible for ensuring that data is
1086 * up to date for updateReport() calls. The correct way to do this
1087 * is for a driver's ::updateReport() method to push the most up to
1088 * date values into the reporters before calling
1089 * super::updateReport().
1091 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1093 IOReturn
overrideChannelState(uint64_t channel_id
,
1095 uint64_t time_in_state
,
1096 uint64_t intransitions
,
1097 uint64_t last_intransition
= 0);
1099 /*! @function IOStateReporter::incrementChannelState
1100 * @abstract Updates state data for a channel with passed arguments
1102 * @param channel_id - ID of the channel which state is to be updated
1103 * @param state_id - state id for the channel
1104 * @param time_in_state - time to be accumulated for time in state
1105 * @param intransitions - number of transitions into state to be added
1106 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1107 * @result Appropriate IOReturn code
1110 * incrementChannelState() adds time_in_state and intransitions
1111 * to the current values stored for a particular state. If provided,
1112 * last_intransition overwrites the time the state was most recently
1113 * entered. Passing 0 for time_in_state and intransitions will have
1114 * no effect. Passing 0 for last_intransition for all states will
1115 * disable the notion of a channel's "current state."
1117 * The most recent last_intransition (amongst all states in a channel)
1118 * logically determines the current state. If last_intransition is
1119 * not provided for any state, the channel will not report a current
1120 * For consistent results, it is important to either never specify
1121 * last_intransition or to always specify it.
1123 * There is currently a bug in determining current state (13423273).
1124 * The IOReportMacros.h macros only update the state's metadata
1125 * timestamp and libIOReport only looks at the metadata timestamps
1126 * to determine the current state. Until that bug is fixed, whichever
1127 * state is updated most recently will be considered the "current"
1128 * state by libIOReport.
1130 * ::setState()'s automatic "time in state" updates are not supported
1131 * when using incrementChannelState(). Clients must not use
1132 * incrementChannelState() on any channel that has ::setState()
1133 * called on it. Unlike with ::setState(), clients using
1134 * incrementChannelState() are responsible for ensuring that data
1135 * is up to date for updateReport() calls. The correct way to do
1136 * this is for a driver's ::updateReport() method to push the most
1137 * up to date values into the reporters before calling
1138 * super::updateReport().
1140 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1142 IOReturn
incrementChannelState(uint64_t channel_id
,
1144 uint64_t time_in_state
,
1145 uint64_t intransitions
,
1146 uint64_t last_intransition
= 0);
1148 /*! @function IOStateReporter::setStateByIndices
1149 * @abstract update a channel state without validating channel_id
1151 * @param channel_index - 0..<nChannels>, available from getChannelIndex()
1152 * @param new_state_index - New state (by index) for the channel
1153 * @result Appropriate IOReturn code
1156 * Similar to setState(), setStateByIndices() sets a channel's state
1157 * without searching for the channel or state IDs. It will perform
1158 * bounds checking, but relies on the caller to properly indicate
1159 * the indices of the channel and state. Clients can rely on channels
1160 * being added to IOStateReporter in order: the first channel will
1161 * have index 0, the second index 1, etc. Like ::setState(),
1162 * "time in state" calculations are handled automatically.
1164 * setStateByIndices() is faster than than setChannelState(), but
1165 * it should only be used where the latter's performance overhead
1166 * might be a problem. For example, many channels in a single
1167 * reporter and high-frequency state changes.
1169 * Drivers wishing to compute and report their own time in state
1170 * should use incrementChannelState() or overrideChannelState(). It
1171 * is not currently possible for a driver to synchronize with the
1172 * automatic time-keeping enabled by setStateByIndices(). The
1173 * 4-argument version of setChannelState() is thus impossible to
1174 * use correctly. In the future, there may be a setChannelState()
1175 * which accepts a last_intransition parameter and uses it to
1176 * automatically calculate time in state (ERs -> IOReporting / X).
1178 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1180 IOReturn
setStateByIndices(int channel_index
,
1181 int new_state_index
);
1183 /*! @function IOStateReporter::setStateByIndices
1184 * @abstract update a channel state without validating channel_id
1186 * @param channel_index - 0..<nChannels>, available from getChannelIndex()
1187 * @param new_state_index - New state (by index) for the channel
1188 * @param last_intransition - deprecated: time of most recent entry
1189 * @param prev_state_residency - deprecated: time spent in previous state
1190 * @result Appropriate IOReturn code
1193 * Similar to setState(), setStateByIndices() sets a channel's state
1194 * without searching for the channel or state IDs. It will perform
1195 * bounds checking, but relies on the caller to properly indicate
1196 * the indices of the channel and state. Clients can rely on channels
1197 * being added to IOStateReporter in order: the first channel will
1198 * have index 0, the second index 1, etc. Like ::setState(),
1199 * "time in state" calculations are handled automatically.
1201 * setStateByIndices() is faster than than setChannelState(), but
1202 * it should only be used where the latter's performance overhead
1203 * might be a problem. For example, many channels in a single
1204 * reporter and high-frequency state changes.
1206 * Drivers wishing to compute and report their own time in state
1207 * should use incrementChannelState() or overrideChannelState(). It
1208 * is not currently possible for a driver to synchronize with the
1209 * automatic time-keeping enabled by setStateByIndices(). The
1210 * 4-argument version of setChannelState() is thus impossible to
1211 * use correctly. In the future, there may be a setChannelState()
1212 * which accepts a last_intransition parameter and uses it to
1213 * automatically calculate time in state (ERs -> IOReporting / X).
1215 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1217 IOReturn
setStateByIndices(int channel_index
,
1218 int new_state_index
,
1219 uint64_t last_intransition
,
1220 uint64_t prev_state_residency
) __deprecated
;
1222 /*! @function IOStateReporter::getStateInTransitions
1223 * @abstract Accessor method for count of transitions into state
1225 * @param channel_id - ID of the channel
1226 * @param state_id - State of the channel
1227 * @result Count of transitions into the requested state.
1230 * Some clients may need to consume internally the data aggregated by the
1231 * reporter object. This method allows a client to retrieve the count of
1232 * transitions into the requested state for the channel_id.
1234 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1236 uint64_t getStateInTransitions(uint64_t channel_id
,
1239 /*! @function IOStateReporter::getStateResidencyTime
1240 * @abstract Accessor method for time spent in a given state
1242 * @param channel_id - ID of the channel
1243 * @param state_id - State of the channel
1244 * @result Absolute time spent in specified state
1247 * Some clients may need to consume internally the data aggregated
1248 * by the by the reporter object. This method allows a client to
1249 * retrieve the absolute time a particular channel recorded as spent
1250 * in a specified state.
1252 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1254 uint64_t getStateResidencyTime(uint64_t channel_id
,
1257 /*! @function IOStateReporter::getStateLastTransitionTime
1258 * @abstract Accessor method for last time a transition occured
1260 * @param channel_id - ID of the channel
1261 * @param state_id - State of the channel
1262 * @result Absolute time for when the last transition occured
1265 * Some clients may need to consume internally the data aggregated
1266 * by the by the reporter object. This method allows a client to
1267 * retrieve the absolute time stamp for when the last transition into
1268 * a specific state was recorded.
1270 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1272 uint64_t getStateLastTransitionTime(uint64_t channel_id
, uint64_t state_id
);
1274 /*! @function [DEPRECATED] IOStateReporter::getStateLastChannelUpdateTime
1275 * @abstract Deprecated accessor for last time a channel was auto-updated
1277 * @param channel_id - ID of the channel
1278 * @result Absolute time for last time the channel was updated
1281 * If a channel has had ::setState() called on it, calls such as
1282 * getStateResidencyTime() or updateReport() will update time in the
1283 * current state and update an internal "last channel update time."
1284 * Because clients have no way to interlock with those methods, there
1285 * is no sensible way to use this method and it will be removed in
1288 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1290 uint64_t getStateLastChannelUpdateTime(uint64_t channel_id
) __deprecated
;
1292 /*! @function IOStateReporter::free
1293 * @abstract Releases the object and all its resources.
1296 * ::free() assumes that init() has completed. Clients should use
1297 * the static ::with() methods to obtain fully-initialized reporter
1300 * Locking: same-instance concurrency UNSAFE
1302 virtual void free(void) APPLE_KEXT_OVERRIDE
;
1306 /*! @function IOStateReporter::initWith
1307 * @abstract Instance method implementation called by ::with
1310 * See description of parameters above
1312 virtual bool initWith(IOService
*reportingService
,
1313 IOReportCategories categories
,
1314 int16_t nstates
, IOReportUnit unit
);
1317 /*! @function IOStateReporter::handleSwapPrepare
1318 * @abstract _swap* = <IOStateReporter-specific per-channel buffers>
1319 * [see IOReporter::handle*Swap* for more info]
1321 virtual IOReturn
handleSwapPrepare(int newNChannels
) APPLE_KEXT_OVERRIDE
;
1324 * @function IOStateReporter::handleAddChannelSwap
1325 * @abstract swap in IOStateReporter's variables
1327 virtual IOReturn
handleAddChannelSwap(uint64_t channel_id
,
1328 const OSSymbol
*symChannelName
) APPLE_KEXT_OVERRIDE
;
1331 * @function IOStateReporter::handleSwapCleanup
1332 * @abstract clean up unused buffers in _swap*
1334 virtual void handleSwapCleanup(int swapNChannels
) APPLE_KEXT_OVERRIDE
;
1336 /*! @function IOStateReporter::updateChannelValues
1337 * @abstract Update accounting of time spent in current state
1339 * @param channel_index - internal index of the channel
1340 * @result appropriate IOReturn code
1343 * Internal State reporter method to account for the time spent in
1344 * the current state when updateReport() is called on the reporter's
1347 * Locking: Caller must ensure that the reporter (data) lock is held.
1349 virtual IOReturn
updateChannelValues(int channel_index
) APPLE_KEXT_OVERRIDE
;
1351 /*! @function IOStateReporter::setStateByIndices
1352 * @abstract update a channel state without validating channel_id
1354 * @param channel_index - 0..<nChannels>, available from getChannelIndex()
1355 * @param new_state_index - New state for the channel
1356 * @param last_intransition - to remove: time of most recent entry
1357 * @param prev_state_residency - to remove: time spent in previous state
1358 * @result Appropriate IOReturn code
1361 * Locked version of IOReporter::setStateByIndices(). This method may be
1362 * overriden by sub-classes.
1364 * Locking: Caller must ensure that the reporter (data) lock is held.
1366 virtual IOReturn
handleSetStateByIndices(int channel_index
,
1367 int new_state_index
,
1368 uint64_t last_intransition
,
1369 uint64_t prev_state_residency
);
1371 /*! @function IOStateReporter::setStateID
1372 * @abstract Assign a non-default ID to a state
1374 * @param channel_id - ID of channel containing the state in question
1375 * @param state_index - index of state to give an ID: [0..(nstates-1)]
1376 * @param state_id - 64-bit state ID, for ASCII, use IOREPORT_MAKEID
1378 * @result Appropriate IOReturn code
1381 * Locked version of IOReporter::setStateID(). This method may be
1382 * overriden by sub-classes
1384 * Locking: Caller must ensure that the reporter (data) lock is held.
1386 virtual IOReturn
handleSetStateID(uint64_t channel_id
,
1390 /*! @function IOStateReporter::handleOverrideChannelStateByIndices
1391 * @abstract Overrides state data for a channel with passed arguments
1393 * @param channel_index - index of the channel which state is to be updated
1394 * @param state_index - index of the state id for the channel
1395 * @param time_in_state - time used as new total time in state
1396 * @param intransitions - total number of transitions into state
1397 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1398 * @result Appropriate IOReturn code
1401 * Locked version of IOReporter::overrideChannelState(). This method
1402 * may be overriden by sub-classes.
1404 * Locking: Caller must ensure that the reporter (data) lock is held.
1406 virtual IOReturn
handleOverrideChannelStateByIndices(int channel_index
,
1408 uint64_t time_in_state
,
1409 uint64_t intransitions
,
1410 uint64_t last_intransition
= 0);
1412 /*! @function IOStateReporter::handleIncrementChannelStateByIndices
1413 * @abstract Updates state data for a channel with passed arguments
1415 * @param channel_index - index of the channel which state is to be updated
1416 * @param state_index - index of the state id for the channel
1417 * @param time_in_state - time used as new total time in state
1418 * @param intransitions - total number of transitions into state
1419 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1420 * @result Appropriate IOReturn code
1423 * Locked version of IOReporter::incrementChannelState(). This method
1424 * may be overriden by sub-classes.
1426 * Locking: Caller must ensure that the reporter (data) lock is held.
1428 virtual IOReturn
handleIncrementChannelStateByIndices(int channel_index
,
1430 uint64_t time_in_state
,
1431 uint64_t intransitions
,
1432 uint64_t last_intransition
= 0);
1435 int *_currentStates
; // current states (per chonnel)
1436 uint64_t *_lastUpdateTimes
; // most recent auto-update
1438 // Required for swapping inside addChannel
1439 int *_swapCurrentStates
;
1440 uint64_t *_swapLastUpdateTimes
;
1442 enum valueSelector
{
1447 uint64_t _getStateValue(uint64_t channel_id
,
1449 enum valueSelector value
);
1451 IOReturn
_getStateIndices(uint64_t channel_id
,
1459 * @class IOHistogramReporter
1460 * @abstract Report histograms of values
1462 * Each IOHistogramReporter can report one histogram representing
1463 * how a given value has changed over time.
1465 class IOHistogramReporter
: public IOReporter
1467 OSDeclareDefaultStructors(IOHistogramReporter
);
1470 /*! @function IOHistogramReporter::with
1471 * @abstract Initializes the IOHistogramReporter instance variables and data structures
1473 * @param reportingService - The I/O Kit service for this reporter's channels
1474 * @param categories - The categories in which the report should be classified
1475 * @param channelID - uint64_t channel identifier
1476 * @param channelName - rich channel name as char*
1477 * @param unit - The unit for the quantity recorded by the reporter object
1478 * @param nSegments - Number of segments to be extracted from the config data structure
1479 * @param config - Histograms require the caller to pass a configuration by segments
1480 * @result an instance of the IOSimpleReporter object or NULL on error
1483 * Creates an instance of histogram reporter object.
1485 * FIXME: need more explanation of the config
1487 * IOHistogramReporter currently only supports a single channel.
1491 static OSPtr
<IOHistogramReporter
> with(IOService
*reportingService
,
1492 IOReportCategories categories
,
1494 const char *channelName
,
1497 IOHistogramSegmentConfig
*config
);
1499 /*! @function IOHistogramReporter::addChannel
1500 * @abstract Override IOReporter::addChannel(*) to return an error
1502 * @result kIOReturnUnsupported - doesn't support adding channels
1505 addChannel(__unused
uint64_t channelID
, __unused
const char *channelName
= NULL
)
1507 return kIOReturnUnsupported
;
1510 /*! @function IOHistogramReporter::overrideBucketValues
1511 * @abstract Override values of a bucket at specified index
1513 * @param index - index of bucket to override
1514 * @param bucket_hits - new bucket hits count
1515 * @param bucket_min - new bucket minimum value
1516 * @param bucket_max - new bucket maximum value
1517 * @param bucket_sum - new bucket sum
1518 * @result Appropriate IOReturn code
1521 * Replaces data in the bucket at the specified index with the data pointed
1522 * to by bucket. No sanity check is performed on the data. If the index
1523 * is out of bounds, kIOReturnBadArgument is returned.
1525 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1528 IOReturn
overrideBucketValues(unsigned int index
,
1529 uint64_t bucket_hits
,
1532 int64_t bucket_sum
);
1534 /*! @function IOHistogramReporter::tallyValue
1535 * @abstract Add a new value to the histogram
1537 * @param value - new value to add to the histogram
1538 * @result the index of the affected bucket, or -1 on error
1541 * The histogram reporter determines in which bucket the value
1542 * falls and increments it. The lowest and highest buckets
1543 * extend to negative and positive infinity, respectively.
1545 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1547 int tallyValue(int64_t value
);
1549 /*! @function IOHistogramReporter::free
1550 * @abstract Releases the object and all its resources.
1553 * ::free() assumes that init() has completed. Clients should use
1554 * the static ::with() methods to obtain fully-initialized reporter
1557 * Locking: same-instance concurrency UNSAFE
1559 virtual void free(void) APPLE_KEXT_OVERRIDE
;
1563 /*! @function IOHistogramReporter::initWith
1564 * @abstract instance method implementation called by ::with
1567 * See description of parameters above
1569 virtual bool initWith(IOService
*reportingService
,
1570 IOReportCategories categories
,
1572 const OSSymbol
*channelName
,
1575 IOHistogramSegmentConfig
*config
);
1577 /*! @function IOHistogramReporter::handleCreateLegend
1578 * @abstract Builds an IOReporting legend entry representing the channels of this reporter.
1580 * @result An IOReportLegendEntry or NULL on failure
1583 * The returned legend entry may be appended to kIOReportLegendKey
1584 * to be published by the caller in the IORegistry. See the
1585 * IOReportLegend class for more details.
1587 * Locking: same-instance concurrency SAFE, MAY BLOCK
1589 OSPtr
<IOReportLegendEntry
> handleCreateLegend(void) APPLE_KEXT_OVERRIDE
;
1595 int64_t *_bucketBounds
;
1597 IOHistogramSegmentConfig
*_histogramSegmentsConfig
;
1601 /***********************************/
1602 /***** 4. IOReportLegend Class *****/
1603 /***********************************/
1606 * @class IOReportLegend
1607 * @abstract combine legend entries into a complete legend
1609 * IOReportLegend adds metadata to legend entries and combines them
1610 * into a single OSArray that can be published under the
1611 * kIOReportLegendKey property in the I/O Kit registry.
1613 class IOReportLegend
: public OSObject
1615 OSDeclareDefaultStructors(IOReportLegend
);
1618 /*! @function IOReportLegend::with
1619 * @abstract Create an instance of IOReportLegend
1621 * @param legend - OSArray of the legend possibly already present in registry
1622 * @result an instance of IOReportLegend, or NULL on failure
1625 * An IOReporting legend (an OSArray of legend entries) may be already
1626 * present in the IORegistry. Thus the recommended way to publish
1627 * new entries is to append to any existing array as follows:
1628 * 1. call getProperty(kIOReportLegendKey) to get an existing legend.
1631 * - OSDynamicCast to OSArray
1632 * - and pass it to ::with()
1633 * IOReportLegend *legendMaker = IOReportLegend::with(legend);
1634 * The provided array is retained by IOReportLegend.
1636 * 2b. If no legend already exists in the registry, pass NULL
1637 * IOReportLegend *legend = IOReportLegend::with(NULL);
1638 * This latter invocation will cause IOReportLegend to create a new
1639 * array internally (also holding one reference).
1641 * At the cost of some registry churn, the static
1642 * IOReportLegend::addReporterLegend() will handle the above, removing
1643 * the need for any direct use of the IOReportLegend class.
1645 static OSPtr
<IOReportLegend
> with(OSArray
*legend
);
1647 /*! @function IOReportLegend::addLegendEntry
1648 * @abstract Add a new legend entry
1650 * @param legendEntry - entry to be added to the internal legend array
1651 * @param groupName - primary group name for this entry
1652 * @param subGroupName - secondary group name for this entry
1653 * @result appropriate IOReturn code
1656 * The entry will be retained as an element of the internal array.
1657 * Legend entries are available from reporter objects. Entries
1658 * represent some number of channels with similar properties (such
1659 * as group and sub-group). Multiple legend entries with the same
1660 * group names will be aggregated in user space.
1662 * Drivers that instantiate their reporter objects in response to
1663 * IOService::configureReport(kIOReportDisable) will need to create
1664 * temporary reporter objects for the purpose of creating their
1665 * legend entries. User-space legends are tracked by 12836893.
1667 IOReturn
addLegendEntry(IOReportLegendEntry
*legendEntry
,
1668 const char *groupName
,
1669 const char *subGroupName
);
1671 /*! @function IOReportLegend::addReporterLegend
1672 * @abstract Add a legend entry from a reporter object
1674 * @param reporter - IOReporter to use to extract and append the legend
1675 * @param groupName - primary group name for this entry
1676 * @param subGroupName - secondary group name for this entry
1677 * @result appropriate IOReturn code
1680 * An IOReportLegendEntry will be created internally to this method from
1681 * the IOReporter object passed in argument. The entry will be released
1682 * internally after being appended to the IOReportLegend object.
1683 * Legend entries are available from reporter objects. Entries
1684 * represent some number of channels with similar properties (such
1685 * as group and sub-group). Multiple legend entries with the same
1686 * group names will be aggregated in user space.
1688 * Drivers that instantiate their reporter objects in response to
1689 * IOService::configureReport(kIOReportDisable) will need to create
1690 * temporary reporter objects for the purpose of creating their
1691 * legend entries. User-space legends are tracked by 12836893.
1693 * Locking: same-reportingService and same-IORLegend concurrency UNSAFE
1695 IOReturn
addReporterLegend(IOReporter
*reporter
,
1696 const char *groupName
,
1697 const char *subGroupName
);
1699 /*! @function IOReportLegend::addReporterLegend
1700 * @abstract Add a legend entry from a reporter object
1702 * @param reportingService - IOService data provider into the reporter object
1703 * @param reporter - IOReporter to use to extract and append the legend
1704 * @param groupName - primary group name for this entry
1705 * @param subGroupName - secondary group name for this entry
1706 * @result appropriate IOReturn code
1709 * An IOReportLegendEntry will be created internally to this method from
1710 * the IOReporter object passed in argument. The entry will be released
1711 * internally after being appended to the IOReportLegend object.
1712 * Legend entries are available from reporter objects. Entries
1713 * represent some number of channels with similar properties (such
1714 * as group and sub-group). Multiple legend entries with the same
1715 * group names will be aggregated in user space.
1717 * Drivers that instantiate their reporter objects in response to
1718 * IOService::configureReport(kIOReportDisable) will need to create
1719 * temporary reporter objects for the purpose of creating their
1720 * legend entries. User-space legends are tracked by 12836893.
1722 * The static version of addReporterLegend adds the reporter's legend
1723 * directly to reportingService's kIOReportLegendKey. It is not
1724 * possible to safely update kIOReportLegendKey from multiple threads.
1726 * Locking: same-reportingService and same-IORLegend concurrency UNSAFE
1728 static IOReturn
addReporterLegend(IOService
*reportingService
,
1729 IOReporter
*reporter
,
1730 const char *groupName
,
1731 const char *subGroupName
);
1733 /*! @function IOReportLegend::getLegend
1734 * @abstract Accessor method to get the legend array
1736 * @result Returns the OSObject holding the legend to be published by the driver
1738 * This array will include all legend entries added to the object.
1740 OSArray
* getLegend(void);
1742 /*! @function IOReportLegend::free
1743 * @abstract Frees the IOReportLegend object
1746 * ::free() cleans up the reporter and anything it allocated.
1748 * ::free() releases the internal array (which was either passed
1749 * to ::with() or created as a result of ::with(NULL)). Assuming
1750 * the caller extracted the array with getLegend() and published it
1751 * in the I/O Kit registry, its ownership will now be with the
1754 void free(void) APPLE_KEXT_OVERRIDE
;
1762 OSPtr
<OSArray
> _reportLegend
;
1764 IOReturn
initWith(OSArray
*legend
);
1766 /*! @function IOReportLegend::organizeLegend
1767 * @abstract Sets up the legend entry, organizing it with group and sub-group names
1769 * @param groupName - Primary group name
1770 * @param subGroupName - Secondary group name
1771 * @result IOReturn code
1773 IOReturn
organizeLegend(IOReportLegendEntry
*legendEntry
,
1774 const OSSymbol
*groupName
,
1775 const OSSymbol
*subGroupName
);
1777 // FUTURE POSSIBILITY (NOT IMPLEMENTED!)
1778 /*! @function IOReportLegend::createReporters
1779 * @abstract Creates as many IOReporter objects as the legend contains
1781 * @param legend - OSArray legend object containing the description of all reporters
1782 * the driver is able to address
1783 * @param reporter - OSSet of reporter objects created by this call
1784 * @result IOReturn code kIOReturnSuccess if successful
1787 * NOT SUPPORTED at the time of writing
1788 * Convenience method to create all the driver's reporter objects from a legend.
1789 * Can be used when a legend is made public through the IORegistry but IOReporter
1790 * objects have not yet been created to save memory, waiting for observers.
1791 * Upon a call to configureReport via the IOService method, a driver could
1792 * create all reporter objects on the fly using this function.
1794 // For Future IOReporterManager...
1795 // static IOReturn createReporters(requestedChannels, legend);
1798 #endif /* ! _IOKERNEL_REPORTERS_H_ */