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 <IOKit/IOLib.h>
43 #include <IOKit/IOService.h>
44 #include <IOKit/IOLocks.h>
45 #include <IOKit/IOBufferMemoryDescriptor.h>
47 #include <IOKit/IOReportTypes.h>
48 #include <IOKit/IOKernelReportStructs.h>
50 typedef OSDictionary IOReportLegendEntry
;
52 /*******************************
53 * TOC: this file contains
55 * 2a. IOReporter class declaration (public & non-public members)
56 * 2b. static IOReporter methods unrelated to the class
57 * 3. IOReporter subclass declarations (public & non-public members)
58 * 4. IOReportLegend class declaration
59 *******************************/
64 * IOReporting is a mechanism for I/O Kit drivers to gather statistics
65 * (or other information) and make it available to various "observers,"
66 * which are generally in user space. Requests for information come
67 * through two new IOService methods: ::configureReport(...) and
68 * ::updateReport(...). While not required (see IOReportTypes.h), drivers
69 * will generally use IOReporter subclass instances to track the requested
70 * information and respond to IOReporting requests. Drivers can use these
71 * classes to track information, either all the time or between "enable"
72 * and "disable" calls to IOService::configureReport().
74 * Available information is organized into "channels." A channel is
75 * uniquely identified by both driver (registry) ID and a 64-bit channel
76 * ID. One way drivers can advertise their channels is by publishing
77 * "legends" in the I/O Kit registry. In addition to collecting
78 * information and responding to queries, IOReporter objects can produce
79 * legend entries describing their channels. The IOReportLegend class
80 * helps manage legend entries from multiple reporter objects as well
81 * as with grouping channels logically for observers.
83 * An important basic constraint of the current implementation is that
84 * all channels reported by a particular reporter instance must share all
85 * traits except channel ID and name. Specifically, the channel type
86 * (including report class, categories, & size) and units. Additionally,
87 * IOHistogramReporter currently only supports one channel at a time.
89 * Currently, ::{configure/update}Report() can be called any time between
90 * when a driver calls registerService() and when free() is called on
91 * your driver. 12960947 tracks improvements / recommendations for
92 * correctly handling these calls during termination.
95 * IOReporting only imposes concurrent access constraints when multiple
96 * threads are accessing the same object. Three levels of constraint apply
97 * depending on a method's purpose:
98 * 1. Allocation/Teardown - same-instance concurrency UNSAFE, MAY BLOCK
99 * 2. Configuration - same-instance concurrency SAFE, MAY BLOCK
100 * 3. Update - same-instance concurrency SAFE, WILL NOT BLOCK
102 * Configuration requires memory management which can block and must
103 * be invoked with interrupts ENABLED (for example, NOT in the interrupt
104 * context NOR with a spin lock -- like IOSimpleLock -- held).
106 * Updates can be performed with interrupts disabled, but clients should
107 * take into account that IOReporters' non-blocking currenency is achieved
108 * with IOSimpleLockLockDisable/UnlockEnableInterrupts(): that is, by
109 * disabling interrupts and taking a spin lock. While IOReporting will
110 * never hold a lock beyond a call into it, some time may be spent within
111 * the call spin-waiting for the lock. Clients holding their own
112 * spin locks should carefully consider the impact of IOReporting's
113 * (small) additional latency before calling it while holding a spin lock.
115 * The documentation for each method indicates any concurrency guarantees.
119 /*********************************/
120 /*** 2a. IOReporter Base Class ***/
121 /*********************************/
123 class IOReporter
: public OSObject
125 OSDeclareDefaultStructors(IOReporter
);
128 /*! @function IOReporter::init
129 * @abstract base init() method, called by subclass initWith() methods
131 * @param reportingService - IOService associated with all channels
132 * @param channelType - type info for all channels (element_idx = 0)
133 * @param unit - description applied for all channels
134 * @result true on success, false otherwise
137 * init() establishes the parameters of all channels for this reporter
138 * instance. Any channels added via addChannel() will be of this type
139 * and have this unit.
141 * IOReporter clients should use the static <subclass>::with() methods
142 * below to obtain fully-initialized reporter instances. ::free()
143 * expects ::init() to have completed successfully. On failure, any
144 * allocations are cleaned up.
146 * Locking: same-instance concurrency UNSAFE
148 virtual bool init(IOService
*reportingService
,
149 IOReportChannelType channelType
,
154 /*! @function IOReporter::addChannel
155 * @abstract add an additional, similar channel to the reporter
157 * @param channelID - identifier for the channel to be added
158 * @param channelName - an optional human-readble name for the channel
159 * @result appropriate IOReturn code
162 * The reporter will allocate memory to track a new channel with the
163 * provided ID and name (if any). Its other traits (type, etc) will
164 * be those provided when the reporter was initialized. If no channel
165 * name is provided and the channelID consists solely of ASCII bytes,
166 * those bytes (ignoring any NUL bytes) will be used as the
167 * human-readable channel name in user space. The IOREPORT_MAKEID()
168 * macro in IOReportTypes.h can be used to create ASCII channel IDs.
170 * Locking: same-instance concurrency SAFE, MAY BLOCK
172 IOReturn
addChannel(uint64_t channelID
, const char *channelName
= NULL
);
174 /*! @function IOReporter::createLegend
175 * @abstract create a legend entry represending this reporter's channels
176 * @result An IOReportLegendEntry object or NULL on failure.
178 * All channels added to the reporter will be represented
179 * in the resulting legend entry.
181 * Legends must be published togethar as an array under the
182 * kIOReportLegendKey in the I/O Kit registry. The IOReportLegend
183 * class can be used to properly combine legend entries from multiple
184 * reporters as well as to put channels into groups of interest to
185 * observers. When published, individual legend entries share
186 * characteristics such as group and sub-group. Multiple IOReporter
187 * instances are required to produce independent legend entries which
188 * can then be published with different characteristics.
190 * Drivers wishing to publish legends should do so as part of their
191 * ::start() routine. As superclasses *may* have installed legend
192 * entries, any existing existing legend should be retrieved and
193 * IOReportLegend used to merge it with the new entries.
195 * Recommendations for best practices are forthcoming.
197 * Instead of calling createLegend on your reporter object and then
198 * appending it manually to IOReportLegend, one may prefer to call
199 * IOReportLegend::appendReporterLegend which creates and appends a
200 * reporter's IOReportLegendEntry in a single call.
202 * Locking: same-instance concurrency SAFE, MAY BLOCK
204 IOReportLegendEntry
* createLegend(void);
206 /*! @function IOReporter::configureReport
207 * @abstract track IOService::configureReport(), provide sizing info
209 * @param channelList - channels to configure
210 * @param action - enable/disable/size, etc (see IOReportTypes.h)
211 * @param result - *incremented* for kIOReportGetDimensions
212 * @param destination - action-specific default destination
213 * @result appropriate IOReturn code
216 * Any time a reporting driver's ::configureReport method is invoked,
217 * this method should be invoked on each IOReporter that is being
218 * used by that driver to report channels in channelList.
220 * Any channels in channelList which are not tracked by this reporter
221 * are ignored. ::configureReport(kIOReportGetDimensions) expects
222 * the full size of all channels, including any reported by
223 * superclasses. It is valid to call this routine on multiple
224 * reporter objects in succession and they will increment 'result'
225 * to provide the correct total.
227 * In the initial release, this routine is only required to calculate
228 * the response to kIOReportGetDimensions, but in the future it will
229 * will enable functionality like "triggered polling" via
230 * kIOReportNotifyHubOnChange. Internally, it is already keeping
231 * track of the number of times each channel has been enabled and
232 * disabled. 13073064 tracks adding a method to see whether any
233 * channels are currently being observed.
235 * The static IOReporter::configureAllReports() will call this method
236 * on multiple reporters grouped in an OSSet.
238 * Locking: same-instance concurrency SAFE, MAY BLOCK
240 IOReturn
configureReport(IOReportChannelList
*channelList
,
241 IOReportConfigureAction action
,
245 /*! @function IOReporter::updateReport
246 * @abstract Produce standard reply to IOService::updateReport()
248 * @param channelList - channels to update
249 * @param action - copy/trace data (see IOReportTypes.h)
250 * @param result - action-specific return value (e.g. size of data)
251 * @param destination - destination for this update (action-specific)
252 * @result appropriate IOReturn code
255 * This method searches channelList for channels tracked by this
256 * reporter, writes the corresponding data into 'destination', and
257 * updates 'result'. It should be possible to pass a given set of
258 * IOService::updateReport() arguments to any and all reporters as
259 * well as to super::updateReport() and get the right result.
261 * The static IOReporter::updateAllReports() will call this method
262 * on an OSSet of reporters.
264 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
266 IOReturn
updateReport(IOReportChannelList
*channelList
,
267 IOReportConfigureAction action
,
271 /*! @function IOReporter::free
272 * @abstract Releases the object and all its resources.
275 * ::free() [called on last ->release()] assumes that init() [called
276 * by static ::with() methods] has completed successfully.
278 * Locking: same-instance concurrency UNSAFE
280 virtual void free(void) APPLE_KEXT_OVERRIDE
;
283 /*********************************/
284 /*** 2b. Useful Static Methods ***/
285 /*********************************/
287 /* The following static functions are intended to simplify the management
288 * of multiple reporters. They may be superseded in the future by an
289 * IOReportManager class.
292 /*! @function IOReporter::configureAllReports
293 * @abstract call configureReport() on multiple IOReporter objects
295 * @param reporters - OSSet of IOReporter objects
296 * @param channelList - full list of channels to configure
297 * @param action - enable/disable/size, etc
298 * @param result - action-specific returned value
299 * @param destination - action-specific default destination
300 * @result success if all objects successfully complete
301 * IOReporter::configureReport()
304 * The OSSet must only contain IOReporter instances. The presence
305 * of non-IOReporter instances will cause this function to return
306 * kIOReturnBadArgument. If any reporter returns an error, the
307 * function will immediately return that error.
309 * Per the IOReporter::configureReport() documentation, each
310 * reporter will search channelList for channels it is reporting
311 * and provide a partial response.
313 static IOReturn
configureAllReports(OSSet
*reporters
,
314 IOReportChannelList
*channelList
,
315 IOReportConfigureAction action
,
318 // FIXME: just put the function (inline-ish) here?
320 /*! @function IOReporter::updateAllReports
321 * @abstract call updateReport() on multiple IOReporter objects
323 * @param reporters - OSSet of IOReporter objects
324 * @param channelList - full list of channels to update
325 * @param action - type/style of update
326 * @param result - returned details about what was updated
327 * @param destination - destination for this update (action-specific)
328 * @result IOReturn code
330 * The OSSet must only contain IOReporter instances. The presence
331 * of non-IOReporter instances will cause this function to return
332 * kIOReturnBadArgument. If any reporter returns an error, the
333 * function will immediately return that error.
335 * Per the IOReporter::configureReport() documentation, each
336 * reporter will search channelList for channels it is reporting
337 * and provide a partial response.
339 static IOReturn
updateAllReports(OSSet
*reporters
,
340 IOReportChannelList
*channelList
,
341 IOReportConfigureAction action
,
344 // FIXME: just put the function (inline-ish) here?
347 /* Protected (subclass-only) Methods
349 * General subclassing is not encouraged as we intend to improve
350 * internal interfaces. If you need something that might require
351 * a subclass, please file a bug against IOReporting/X and we will
354 * One important concept for sub-classes (not clients) is that report
355 * data is stored in IOReportElement structures (see IOReportTypes.h).
359 /*! @function IOReporter::lockReporterConfig
360 * @function IOReporter::unlockReporterConfig
361 * @abstract prevent concurrent reconfiguration of a reporter
364 * lockReporterConfig() takes a mutex-based lock intended to prevent
365 * concurrent access to the reporter's configuration. It is not
366 * intended to prevent updates to the reporter's data. As long as
367 * all other requirements are met, it is safe to simultaneously hold
368 * both the configuration and data locks on a single reporter.
370 * lockReporterConfig() is used by routines such as addChannel().
371 * See also lockReporter() and ::handle*Swap*() below.
373 void lockReporterConfig(void);
374 void unlockReporterConfig(void);
376 /*! @function IOReporter::lockReporter
377 * @function IOReporter::unlockReporter
378 * @abstract prevent concurrent access to a reporter's data
381 * This method grabs a lock intended to control access the reporter's
382 * reporting data. Sub-classes maninupating internal report values
383 * must make sure the reporter is locked (usually by the most generic
384 * public interface) before calling getElementValues(),
385 * copyElementValues(), or setElementValues().
387 * Subclasses should ensure that this lock is taken exactly once
388 * before directly accessing reporter data. For example,
389 * [virtual] IOFooReporter::handleSetFoo(.) {
390 * // assert(lock_held)
391 * getElementValues(1..)
392 * getElementValues(3..)
393 * getElementValues(5..)
395 * setElementValues(6..)
397 * IOFooReporter::setFoo(.) { // not virtual
403 * IOReporter::handle*() use lockReporter() similarly. For example,
404 * the lock is taken by IOReporter::updateReport() and is already
405 * held by the time any ::updateChannelValues() methods are called.
407 * Subclasses cannot call this routine if the lock is already held.
408 * That's why IOReporting generally only calls it from non-virtual
409 * public methods. In particular, this method should not be called
410 * it from ::handle*() methods which exist to allow override after
413 * Because lockReporter() uses a spin lock, it is SAFE to use in the
414 * interrupt context. For the same reason, however, it is UNSAFE
415 * to perform any blocking blocking operations (including memory
416 * allocations) while holding this lock.
418 void lockReporter(void);
419 void unlockReporter(void);
423 * The ::handle*Swap* functions allow subclasses to safely reconfigure
424 * their internal state. A non-virtual function handles locking
425 * and invokes the functions in order:
426 * - lockReporterConfig() // protecting instance vars but not content
427 * - prepare / allocate buffers of the new size
428 * - if error, bail (unlocking, of course)
430 * - lockReporter() // protecting data / blocking updates
431 * - swap: preserve continuing data / install new buffers
434 * - deallocate now-unused buffers
435 * - unlockReporterConfig()
437 /*! @function IOReporter::handleSwapPrepare
438 * @abstract allocate memory in preparation for an instance variable swap
440 * @param newNChannels target number of channels
441 * @result IOReturn code
444 * ::handleSwapPrepare() is responsible for allocating appropriately-
445 * sized buffers (based on the new number of channels) and storing
446 * them in _swap* instance variables. If returning and error, it
447 * must deallocate any buffers and set to NULL any _swap* variables.
449 * Locking: The caller must ensure that the *config* lock is HELD but
450 * that the reporter (data) lock is *NOT HELD*.
452 virtual IOReturn
handleSwapPrepare(int newNChannels
);
454 /*! @function IOReporter::handleAddChannelSwap
455 * @abstract update primary instance variables with new buffers
457 * @param channel_id ID of channel being added
458 * @param symChannelName optional channel name, in an allocated object
459 * @result IOReturn code
462 * handlAddChannelSwap() replaces the primary instance variables
463 * with buffers allocated in handlePrepareSwap(). It copies the the
464 * existing data into the appropriate portion of the new buffers.
465 * Because it is specific to adding one channel, it assumes that the
466 * target number of channels is one greater than the current value
469 * IOReporter::handleAddChannelSwap() increments _nElements and
470 * _nChannels. To ensure that these variables describe the current
471 * buffers throughout ::handle*Swap(), subclasses overriding this
472 * method should call super::handleAddChannelSwap() after swapping
473 * their own instance variables.
475 * If returning an error, all implementations should leave their
476 * instance variables as they found them (*unswapped*). That ensures
477 * handleSwapCleanup() cleans up the unused buffers regardless of
478 * whether the swap was complete.
480 * Pseudo-code incorporating these suggestions:
481 * res = <err>; swapComplete = false;
482 * if (<unexpected>) goto finish
483 * tmpBuf = _primaryBuf; _primaryBuf = _swapBuf; _swapBuf = _primaryBuf;
485 * swapComplete = true;
486 * res = super::handle*Swap()
489 * if (res && swapComplete) // unswap
491 * Locking: The caller must ensure that BOTH the configuration and
492 * reporter (data) locks are HELD.
494 virtual IOReturn
handleAddChannelSwap(uint64_t channel_id
,
495 const OSSymbol
*symChannelName
);
497 /*! @function IOReporter::handleSwapCleanup
498 * @abstract release and forget unused buffers
500 * @param swapNChannels channel-relative size of the _swap buffers
503 * ::handleSwapCleanup() is responsible for deallocating the buffers
504 * no longer used after a swap. It must always be called if
505 * SwapPrepare() completes successfully. Because bufers may be
506 * swapped in and out of existance, the _swap* variables may be
507 * NULL and should be set to NULL when complete.
509 * Locking: The caller must ensure that the *config* lock is HELD but
510 * that the reporter (data) lock is *NOT HELD*.
512 virtual void handleSwapCleanup(int swapNChannels
);
514 /*! @function IOReporter::handleConfigureReport
515 * @abstract override vector for IOReporter::configureReport()
516 * [parameters and result should exactly match]
519 * The public base class method takes the reporter lock, calls this
520 * function, and then drops the lock. Subclasses should not call
521 * this function directly.
523 virtual IOReturn
handleConfigureReport(IOReportChannelList
*channelList
,
524 IOReportConfigureAction action
,
528 /*! @function IOReporter::handleUpdateReport
529 * @abstract override vector for IOReporter::updateReport()
530 * [parameters and result should exactly match]
533 * The public base class method takes the reporter lock, calls this
534 * function, and then drops the lock. Subclasses should not call
535 * this function directly.
537 * This function may be overriden but the common case should be to
538 * simply update reporter's specific values by overriding
539 * IOReporter::updateChannelValues().
541 virtual IOReturn
handleUpdateReport(IOReportChannelList
*channelList
,
542 IOReportConfigureAction action
,
546 /* @function IOReporter::handleCreateLegend
547 * @abstract override vector for IOReporter::createLegend()
548 * [parameters and result should exactly match]
551 * The public base class method takes the reporter lock, calls this
552 * function, and then drops the lock. Subclasses should not call
553 * this function directly.
555 virtual IOReportLegendEntry
* handleCreateLegend(void);
557 /*! @function IOReporter::updateChannelValues
558 * @abstract update channel values for IOReporter::updateReport()
560 * @param channel_index - logical (internal) index of the channel
561 * @result appropriate IOReturn code
564 * Internal reporter method to allow a subclass to update channel
565 * data when updateReport() is called. This routine handles the
566 * common case of a subclass needing to refresh state in response
567 * to IOReporter::updateReport(). It saves the complexity of
568 * parsing the full parameters to IOReporter::updateReport().
570 * The IOReporter base class implementation does not do anything
571 * except return success.
573 * Locking: IOReporter::updateReport() takes the reporter lock,
574 * determines the indices involved, calls this function, and
575 * then proceeds to provide values to the caller. If subclasses
576 * need to call this routine directly, they must ensure that
577 * the reporter (data) lock is held: see
578 * IOReporter::lockReporter().
580 virtual IOReturn
updateChannelValues(int channel_index
);
583 /*! @function IOReporter::updateReportChannel
584 * @abstract Internal method to extract channel data to a destination
586 * @param channel_index - offset into internal elements array
587 * @param nElements - incremented by the number of IOReportElements added
588 * @param destination - pointer to the destination buffer
589 * @result IOReturn code
592 * updateReportChannel() is used to extract a single channel's
593 * data to the updateReport() destination.
595 * Locking: Caller must ensure that the reporter (data) lock is held.
597 IOReturn
updateReportChannel(int channel_index
,
599 IOBufferMemoryDescriptor
*destination
);
602 /*! @function IOReporter::setElementValues
603 * @abstract Atomically update a specific member of _elements[].
605 * @param element_index - index of the _element in internal array
606 * @param values - IORepoterElementValues to replace those at _elements[idx]
607 * @param record_time - optional mach_absolute_time to be used for metadata
608 * @result IOReturn code
611 * element_index can be obtained from getFirstElementIndex(). If
612 * record_time is not provided, IOReporter::setElementValues() will
613 * fetch the current mach_absolute_time. If the current time is
614 * already known, it is more efficient to pass it along.
616 * Locking: Caller must ensure that the reporter (data) lock is held.
618 virtual IOReturn
setElementValues(int element_index
,
619 IOReportElementValues
*values
,
620 uint64_t record_time
= 0);
622 /*! @function IOReporter::getElementValues
623 * @abstract Internal method to directly access the values of an element
625 * @param element_index - index of the _element in internal array
626 * @result A pointer to the element values requested or NULL on failure
628 * @discussion Locking: Caller must ensure that the reporter (data) lock is held.
629 * The returned pointer is only valid until unlockReporter() is called.
631 virtual const IOReportElementValues
* getElementValues(int element_index
);
633 /*! @function IOReporter::getFirstElementIndex
634 * @abstract Returns the first element index for a channel
636 * @param channel_id - ID of the channel
637 * @param element_index - pointer to the returned element_index
638 * @result appropriate IOReturn code
641 * For efficiently and thread-safely reading _elements
643 * Locking: Caller must ensure that the reporter (data) lock is held.
645 virtual IOReturn
getFirstElementIndex(uint64_t channel_id
,
648 /*! @function IOReporter::getChannelIndex
649 * @abstract Returns the index of a channel from internal data structures
651 * @param channel_id - ID of the channel
652 * @param channel_index - pointer to the returned element_index
653 * @result appropriate IOReturn code
656 * For efficiently and thread-safely reading channels
658 * Locking: Caller must ensure that the reporter (data) lock is held.
660 virtual IOReturn
getChannelIndex(uint64_t channel_id
,
663 /*! @function IOReporter::getChannelIndices
664 * @abstract Returns the index of a channel and its corresponding
665 * first element index from internal data structure
667 * @param channel_id - ID of the channel
668 * @param channel_index - pointer to the returned channel_index
669 * @param element_index - pointer to the returned element_index
670 * @result appropriate IOReturn code
673 * For efficiently and thread-safely reading channel elements.
674 * It is commonly useful to get access to both channel and element
675 * indices togther. This convenience method allows sub-classes to
676 * get both indices simultaneously.
678 * Locking: Caller must ensure that the reporter (data) lock is held.
680 virtual IOReturn
getChannelIndices(uint64_t channel_id
,
684 /*! @function IOReporter::copyElementValues
685 * @abstract Copies the values of an internal element to *elementValues
687 * @param element_index - Index of the element to return values from
688 * @param elementValues - For returning the content of element values
689 * @result Returns the content of an element
692 * For efficiently and thread-safely reading _elements.
693 * May need to find the index of the element first.
695 * Locking: Caller must ensure that the reporter (data) lock is held.
697 virtual IOReturn
copyElementValues(int element_index
,
698 IOReportElementValues
*elementValues
);
702 /*! @function IOReporter::copyChannelIDs
703 * @abstract return an an OSArray of the reporter's
706 * @result An OSArray of the repoter's channel ID's as OSNumbers
709 * This method is an internal helper function used to prepare a
710 * legend entry. It encapsulates the channel IDs in OSNumbers and
711 * aggregates them in an OSArray used when building the IOReportLegend
713 * Locking: Caller must ensure that the reporter (data) lock is held.
715 OSArray
* copyChannelIDs(void);
717 /*! @function IOReporter::legendWith
718 * @abstract Internal method to help create legend entries
720 * @param channelIDs - OSArray of OSNumber(uint64_t) channels IDs.
721 * @param channelNames - parrallel OSArray of OSSymbol(rich names)
722 * @param channelType - the type of all channels in this legend
723 * @param unit - The unit for the quantity recorded by this reporter object
725 * @result An IOReportLegendEntry object or NULL on failure
728 * This static method is the main legend creation function. It is called by
729 * IOReporter sub-classes and is responsible for building an
730 * IOReportLegendEntry corresponding to this reporter object.
731 * This legend entry may be extended by the sub-class of IOReporter if
734 * Locking: SAFE to call concurrently (no static globals), MAY BLOCK
736 static IOReportLegendEntry
* legendWith(OSArray
*channelIDs
,
737 OSArray
*channelNames
,
738 IOReportChannelType channelType
,
741 // protected instance variables (want to get rid of these)
743 IOReportChannelType _channelType
;
744 uint64_t _driver_id
; // driver reporting data
746 // IOHistogramReporter accesses these; need to re-do its instantiation
747 IOReportElement
*_elements
;
748 int *_enableCounts
; // refcount kIOReportEnable/Disable
749 uint16_t _channelDimension
;// Max channel size
751 int _nChannels
; // Total Channels in this reporter
752 OSArray
*_channelNames
;
754 // MUST be protected because check is a macro!
755 bool _reporterIsLocked
;
756 bool _reporterConfigIsLocked
;
758 // Required for swapping inside addChannel
759 IOReportElement
*_swapElements
;
760 int *_swapEnableCounts
;
762 // private instance variables
766 int _enabled
;// 'enabled' if _enabled > 0
769 IOInterruptState _interruptState
;
770 IOSimpleLock
*_reporterLock
;
774 /************************************/
775 /***** 3. IOReporter Subclasses *****/
776 /************************************/
779 * @class IOSimpleReporter
780 * @abstract Report simple integers
782 * Each IOSimpleReporter can have an arbitrary number of channels,
783 * each publishing a single integer value at any given time.
786 class IOSimpleReporter
: public IOReporter
788 OSDeclareDefaultStructors(IOSimpleReporter
);
792 /*! @function IOSimpleReporter::with
793 * @abstract create an initialized simple reporter
795 * @param reportingService - IOService associated with all channels
796 * @param categories - The category in which the report should be classified
797 * @param unit - The unit for the quantity recorded by the reporter object
798 * @result On success, an instance of IOSimpleReporter, else NULL
801 * Creates an instance of IOSimpleReporter object
803 * Locking: SAFE to call concurrently (no static globals), MAY BLOCK.
805 static IOSimpleReporter
* with(IOService
*reportingService
,
806 IOReportCategories categories
,
809 /*! @function IOSimpleReporter::setValue
810 * @abstract Thread safely set a channel's value
812 * @param channel_id - ID of the channel for which the value needs to be set
813 * @param value - New channel value
814 * @result Appropriate IOReturn code
817 * Updates the value of a channel to the provided value.
819 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
821 IOReturn
setValue(uint64_t channel_id
,
824 /*! @function IOSimpleReporter::incrementValue
825 * @abstract Thread safely increment a channel's value by a given amount
827 * @param channel_id - ID of the channel for which the value needs to be incremented
828 * @param increment - Amount to be added to the current channel value
829 * @result Appropriate IOReturn code
831 * Increments the value of the channel ID by the provided amount.
833 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
835 IOReturn
incrementValue(uint64_t channel_id
,
838 /*! @function IOSimpleReporter::getValue
839 * @abstract Thread safely access a channel value
841 * @param channel_id - ID of the channel to get a value from
842 * @result Returns the current value stored in the channel
844 * Accessor method to a channel's current stored value
846 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
848 int64_t getValue(uint64_t channel_id
);
852 /*! @function IOSimpleReporter::initWith
853 * @abstract instance method implementation called by IOSimpleReporter::with
856 * See description of parameters above
858 * Locking: same-instance concurrency UNSAFE
860 virtual bool initWith(IOService
*reportingService
,
861 IOReportCategories categories
,
870 * @class IOStateReporter
871 * @abstract Report state machine data
873 * Each IOStateReporter can report information for an arbitrary number
874 * of similar state machines. All must have the same number of states.
876 class IOStateReporter
: public IOReporter
878 OSDeclareDefaultStructors(IOStateReporter
);
882 /*! @function IOStateReporter::with
883 * @abstract State reporter static creation method
885 * @param reportingService - The I/O Kit service for this reporter's channels
886 * @param categories - The categories for this reporter's channels
887 * @param nstates - Maximum number of states for this reporter's channels
888 * @param unit - optional parameter if using override/increment...()
889 * @result on success, an IOStateReporter instance, else NULL
892 * Creates an instance of IOStateReporter. The default time scale
893 * is the current system's notion of mach_absolute_time(). Using a
894 * non-default time scale requires the use of
895 * override/incrementChannelState() instead of setState().
896 * setState() always updates using mach_absolute_time().
898 * Locking: SAFE to call concurrently (no static globals), MAY BLOCK
900 static IOStateReporter
* with(IOService
*reportingService
,
901 IOReportCategories categories
,
903 IOReportUnit unit
= kIOReportUnitHWTicks
);
905 /*! @function IOStateReporter::setStateID
906 * @abstract Assign a non-default ID to a state
908 * @param channel_id - ID of channel containing the state in question
909 * @param state_index - index of state to give an ID: [0..(nstates-1)]
910 * @param state_id - 64-bit state ID, for ASCII, use IOREPORT_MAKEID
912 * @result Appropriate IOReturn code
915 * By default, IOStateReporter identifies its channel states by
916 * numbering them from 0 to <nstates - 1>. If setStateID is not
917 * called to customize the state IDs, the numbered states will be
918 * kept throughout the life of the object and it is safe to reference
919 * those states by their indices. Otherwise, after setStateID() has
920 * been called, the ordering of states is no longer guaranteed and
921 * the client must reference states by their assigned state ID.
923 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
925 IOReturn
setStateID(uint64_t channel_id
,
929 /*! @function IOStateReporter::setChannelState
930 * @abstract Updates the current state of a channel to a new state
932 * @param channel_id - ID of the channel which is updated to a new state
933 * @param new_state_id - ID of the target state for this channel
934 * @param last_intransition - deprecated: time of most recent entry
935 * @param prev_state_residency - deprecated: time spent in previous state
936 * @result Appropriate IOReturn code
939 * setChannelState() updates the amount of time spent in the previous
940 * state (if any) and increments the number of transitions into the
941 * new state. It also sets the target state's last transition time to
942 * the current time and enables internal time-keeping for the channel.
943 * In this mode, calls like getStateResidencyTime() and updateReport()
944 * automatically update a channel's time in state.
946 * new_state_id identifies the target state as initialized
947 * (0..<nstates-1>) or as configured by setStateID().
949 * Drivers wishing to compute and report their own time in state
950 * should use incrementChannelState() or overrideChannelState(). It
951 * is not currently possible for a driver to synchronize with the
952 * automatic time-keeping enabled by setChannelState(). The
953 * 4-argument version of setChannelState() is thus impossible to
954 * use correctly. In the future, there may be a setChannelState()
955 * which accepts a last_intransition parameter and uses it to
956 * automatically calculate time in state (ERs -> IOReporting / X).
958 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
960 IOReturn
setChannelState(uint64_t channel_id
,
961 uint64_t new_state_id
,
962 uint64_t last_intransition
,
963 uint64_t prev_state_residency
) __deprecated
;
965 /*! @function IOStateReporter::setChannelState
966 * @abstract Updates the current state of a channel to a new state
968 * @param channel_id - ID of the channel which is updated to a new state
969 * @param new_state_id - ID of the target state for this channel
970 * @result Appropriate IOReturn code
973 * setChannelState() updates the amount of time spent in the previous
974 * state (if any) and increments the number of transitions into the
975 * new state. It also sets the target state's last transition time to
976 * the current time and enables internal time-keeping for the channel.
977 * In this mode, calls like getStateResidencyTime() and updateReport()
978 * automatically update a channel's time in state.
980 * new_state_id identifies the target state as initialized
981 * (0..<nstates-1>) or as configured by setStateID().
983 * Drivers wishing to compute and report their own time in state
984 * should use incrementChannelState() or overrideChannelState(). It
985 * is not currently possible for a driver to synchronize with the
986 * automatic time-keeping enabled by setChannelState(). The
987 * 4-argument version of setChannelState() is thus impossible to
988 * use correctly. In the future, there may be a setChannelState()
989 * which accepts a last_intransition parameter and uses it to
990 * automatically calculate time in state (ERs -> IOReporting / X).
992 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
994 IOReturn
setChannelState(uint64_t channel_id
,
995 uint64_t new_state_id
);
998 /*! @function IOStateReporter::setState
999 * @abstract Updates state for single channel reporters
1001 * @param new_state_id - New state for the channel
1002 * @result Appropriate IOReturn code.
1005 * setState() is a convenience method for single-channel state
1006 * reporter instances. An error will be returned if the reporter
1007 * in question has more than one channel.
1009 * See further discussion at setChannelState().
1011 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1013 IOReturn
setState(uint64_t new_state_id
);
1015 /*! @function IOStateReporter::setState
1016 * @abstract Updates state for single channel reporters
1018 * @param new_state_id - New state for the channel
1019 * @param last_intransition - deprecated: time of most recent entry
1020 * @param prev_state_residency - deprecated: spent in previous state
1021 * @result Appropriate IOReturn code.
1024 * setState() is a convenience method for single-channel state
1025 * reporter instances. An error will be returned if the reporter
1026 * in question has more than one channel.
1028 * See further discussion at setChannelState().
1030 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1032 IOReturn
setState(uint64_t new_state_id
,
1033 uint64_t last_intransition
,
1034 uint64_t prev_state_residency
) __deprecated
;
1036 /*! @function IOStateReporter::overrideChannelState
1037 * @abstract Overrides state data for a channel with passed arguments
1039 * @param channel_id - ID of the channel which state is to be updated
1040 * @param state_id - state id for the channel
1041 * @param time_in_state - time used as new total time in state
1042 * @param intransitions - total number of transitions into state
1043 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1044 * @result Appropriate IOReturn code
1047 * overrideChannelState() sets a particular state's time in state
1048 * and transition count to the values provided. The optional
1049 * last_intransition records the last time the channel transitioned
1050 * into the given state. Passing 0 for time_in_state and
1051 * intransitions will force the current values to 0. Passing 0
1052 * for last_intransition for all states will disable the notion
1053 * of a channel's "current state."
1055 * The most recent last_intransition (amongst all states in a channel)
1056 * logically determines the current state. If last_intransition is
1057 * not provided for any state, the channel will not report a current
1058 * For consistent results, it is important to either never specify
1059 * last_intransition or to always specify it.
1061 * There is currently a bug in determining current state (13423273).
1062 * The IOReportMacros.h macros only update the state's metadata
1063 * timestamp and libIOReport only looks at the metadata timestamps
1064 * to determine the current state. Until that bug is fixed, whichever
1065 * state is updated most recently will be considered the "current"
1066 * state by libIOReport.
1068 * ::setState()'s automatic "time in state" updates are not supported
1069 * when using overrideChannelState(). Clients must not use
1070 * overrideChannelState() on any channel that has ::setState() called
1071 * on it. Unlike with ::setState(), clients using
1072 * overrideChannelState() are responsible for ensuring that data is
1073 * up to date for updateReport() calls. The correct way to do this
1074 * is for a driver's ::updateReport() method to push the most up to
1075 * date values into the reporters before calling
1076 * super::updateReport().
1078 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1080 IOReturn
overrideChannelState(uint64_t channel_id
,
1082 uint64_t time_in_state
,
1083 uint64_t intransitions
,
1084 uint64_t last_intransition
= 0);
1086 /*! @function IOStateReporter::incrementChannelState
1087 * @abstract Updates state data for a channel with passed arguments
1089 * @param channel_id - ID of the channel which state is to be updated
1090 * @param state_id - state id for the channel
1091 * @param time_in_state - time to be accumulated for time in state
1092 * @param intransitions - number of transitions into state to be added
1093 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1094 * @result Appropriate IOReturn code
1097 * incrementChannelState() adds time_in_state and intransitions
1098 * to the current values stored for a particular state. If provided,
1099 * last_intransition overwrites the time the state was most recently
1100 * entered. Passing 0 for time_in_state and intransitions will have
1101 * no effect. Passing 0 for last_intransition for all states will
1102 * disable the notion of a channel's "current state."
1104 * The most recent last_intransition (amongst all states in a channel)
1105 * logically determines the current state. If last_intransition is
1106 * not provided for any state, the channel will not report a current
1107 * For consistent results, it is important to either never specify
1108 * last_intransition or to always specify it.
1110 * There is currently a bug in determining current state (13423273).
1111 * The IOReportMacros.h macros only update the state's metadata
1112 * timestamp and libIOReport only looks at the metadata timestamps
1113 * to determine the current state. Until that bug is fixed, whichever
1114 * state is updated most recently will be considered the "current"
1115 * state by libIOReport.
1117 * ::setState()'s automatic "time in state" updates are not supported
1118 * when using incrementChannelState(). Clients must not use
1119 * incrementChannelState() on any channel that has ::setState()
1120 * called on it. Unlike with ::setState(), clients using
1121 * incrementChannelState() are responsible for ensuring that data
1122 * is up to date for updateReport() calls. The correct way to do
1123 * this is for a driver's ::updateReport() method to push the most
1124 * up to date values into the reporters before calling
1125 * super::updateReport().
1127 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1129 IOReturn
incrementChannelState(uint64_t channel_id
,
1131 uint64_t time_in_state
,
1132 uint64_t intransitions
,
1133 uint64_t last_intransition
= 0);
1135 /*! @function IOStateReporter::setStateByIndices
1136 * @abstract update a channel state without validating channel_id
1138 * @param channel_index - 0..<nChannels>, available from getChannelIndex()
1139 * @param new_state_index - New state (by index) for the channel
1140 * @result Appropriate IOReturn code
1143 * Similar to setState(), setStateByIndices() sets a channel's state
1144 * without searching for the channel or state IDs. It will perform
1145 * bounds checking, but relies on the caller to properly indicate
1146 * the indices of the channel and state. Clients can rely on channels
1147 * being added to IOStateReporter in order: the first channel will
1148 * have index 0, the second index 1, etc. Like ::setState(),
1149 * "time in state" calculations are handled automatically.
1151 * setStateByIndices() is faster than than setChannelState(), but
1152 * it should only be used where the latter's performance overhead
1153 * might be a problem. For example, many channels in a single
1154 * reporter and high-frequency state changes.
1156 * Drivers wishing to compute and report their own time in state
1157 * should use incrementChannelState() or overrideChannelState(). It
1158 * is not currently possible for a driver to synchronize with the
1159 * automatic time-keeping enabled by setStateByIndices(). The
1160 * 4-argument version of setChannelState() is thus impossible to
1161 * use correctly. In the future, there may be a setChannelState()
1162 * which accepts a last_intransition parameter and uses it to
1163 * automatically calculate time in state (ERs -> IOReporting / X).
1165 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1167 IOReturn
setStateByIndices(int channel_index
,
1168 int new_state_index
);
1170 /*! @function IOStateReporter::setStateByIndices
1171 * @abstract update a channel state without validating channel_id
1173 * @param channel_index - 0..<nChannels>, available from getChannelIndex()
1174 * @param new_state_index - New state (by index) for the channel
1175 * @param last_intransition - deprecated: time of most recent entry
1176 * @param prev_state_residency - deprecated: time spent in previous state
1177 * @result Appropriate IOReturn code
1180 * Similar to setState(), setStateByIndices() sets a channel's state
1181 * without searching for the channel or state IDs. It will perform
1182 * bounds checking, but relies on the caller to properly indicate
1183 * the indices of the channel and state. Clients can rely on channels
1184 * being added to IOStateReporter in order: the first channel will
1185 * have index 0, the second index 1, etc. Like ::setState(),
1186 * "time in state" calculations are handled automatically.
1188 * setStateByIndices() is faster than than setChannelState(), but
1189 * it should only be used where the latter's performance overhead
1190 * might be a problem. For example, many channels in a single
1191 * reporter and high-frequency state changes.
1193 * Drivers wishing to compute and report their own time in state
1194 * should use incrementChannelState() or overrideChannelState(). It
1195 * is not currently possible for a driver to synchronize with the
1196 * automatic time-keeping enabled by setStateByIndices(). The
1197 * 4-argument version of setChannelState() is thus impossible to
1198 * use correctly. In the future, there may be a setChannelState()
1199 * which accepts a last_intransition parameter and uses it to
1200 * automatically calculate time in state (ERs -> IOReporting / X).
1202 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1204 IOReturn
setStateByIndices(int channel_index
,
1205 int new_state_index
,
1206 uint64_t last_intransition
,
1207 uint64_t prev_state_residency
) __deprecated
;
1209 /*! @function IOStateReporter::getStateInTransitions
1210 * @abstract Accessor method for count of transitions into state
1212 * @param channel_id - ID of the channel
1213 * @param state_id - State of the channel
1214 * @result Count of transitions into the requested state.
1217 * Some clients may need to consume internally the data aggregated by the
1218 * reporter object. This method allows a client to retrieve the count of
1219 * transitions into the requested state for the channel_id.
1221 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1223 uint64_t getStateInTransitions(uint64_t channel_id
,
1226 /*! @function IOStateReporter::getStateResidencyTime
1227 * @abstract Accessor method for time spent in a given state
1229 * @param channel_id - ID of the channel
1230 * @param state_id - State of the channel
1231 * @result Absolute time spent in specified state
1234 * Some clients may need to consume internally the data aggregated
1235 * by the by the reporter object. This method allows a client to
1236 * retrieve the absolute time a particular channel recorded as spent
1237 * in a specified state.
1239 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1241 uint64_t getStateResidencyTime(uint64_t channel_id
,
1244 /*! @function IOStateReporter::getStateLastTransitionTime
1245 * @abstract Accessor method for last time a transition occured
1247 * @param channel_id - ID of the channel
1248 * @param state_id - State of the channel
1249 * @result Absolute time for when the last transition occured
1252 * Some clients may need to consume internally the data aggregated
1253 * by the by the reporter object. This method allows a client to
1254 * retrieve the absolute time stamp for when the last transition into
1255 * a specific state was recorded.
1257 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1259 uint64_t getStateLastTransitionTime(uint64_t channel_id
, uint64_t state_id
);
1261 /*! @function [DEPRECATED] IOStateReporter::getStateLastChannelUpdateTime
1262 * @abstract Deprecated accessor for last time a channel was auto-updated
1264 * @param channel_id - ID of the channel
1265 * @result Absolute time for last time the channel was updated
1268 * If a channel has had ::setState() called on it, calls such as
1269 * getStateResidencyTime() or updateReport() will update time in the
1270 * current state and update an internal "last channel update time."
1271 * Because clients have no way to interlock with those methods, there
1272 * is no sensible way to use this method and it will be removed in
1275 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1277 uint64_t getStateLastChannelUpdateTime(uint64_t channel_id
) __deprecated
;
1279 /*! @function IOStateReporter::free
1280 * @abstract Releases the object and all its resources.
1283 * ::free() assumes that init() has completed. Clients should use
1284 * the static ::with() methods to obtain fully-initialized reporter
1287 * Locking: same-instance concurrency UNSAFE
1289 virtual void free(void) APPLE_KEXT_OVERRIDE
;
1293 /*! @function IOStateReporter::initWith
1294 * @abstract Instance method implementation called by ::with
1297 * See description of parameters above
1299 virtual bool initWith(IOService
*reportingService
,
1300 IOReportCategories categories
,
1301 int16_t nstates
, IOReportUnit unit
);
1304 /*! @function IOStateReporter::handleSwapPrepare
1305 * @abstract _swap* = <IOStateReporter-specific per-channel buffers>
1306 * [see IOReporter::handle*Swap* for more info]
1308 virtual IOReturn
handleSwapPrepare(int newNChannels
) APPLE_KEXT_OVERRIDE
;
1311 * @function IOStateReporter::handleAddChannelSwap
1312 * @abstract swap in IOStateReporter's variables
1314 virtual IOReturn
handleAddChannelSwap(uint64_t channel_id
,
1315 const OSSymbol
*symChannelName
) APPLE_KEXT_OVERRIDE
;
1318 * @function IOStateReporter::handleSwapCleanup
1319 * @abstract clean up unused buffers in _swap*
1321 virtual void handleSwapCleanup(int swapNChannels
) APPLE_KEXT_OVERRIDE
;
1323 /*! @function IOStateReporter::updateChannelValues
1324 * @abstract Update accounting of time spent in current state
1326 * @param channel_index - internal index of the channel
1327 * @result appropriate IOReturn code
1330 * Internal State reporter method to account for the time spent in
1331 * the current state when updateReport() is called on the reporter's
1334 * Locking: Caller must ensure that the reporter (data) lock is held.
1336 virtual IOReturn
updateChannelValues(int channel_index
) APPLE_KEXT_OVERRIDE
;
1338 /*! @function IOStateReporter::setStateByIndices
1339 * @abstract update a channel state without validating channel_id
1341 * @param channel_index - 0..<nChannels>, available from getChannelIndex()
1342 * @param new_state_index - New state for the channel
1343 * @param last_intransition - to remove: time of most recent entry
1344 * @param prev_state_residency - to remove: time spent in previous state
1345 * @result Appropriate IOReturn code
1348 * Locked version of IOReporter::setStateByIndices(). This method may be
1349 * overriden by sub-classes.
1351 * Locking: Caller must ensure that the reporter (data) lock is held.
1353 virtual IOReturn
handleSetStateByIndices(int channel_index
,
1354 int new_state_index
,
1355 uint64_t last_intransition
,
1356 uint64_t prev_state_residency
);
1358 /*! @function IOStateReporter::setStateID
1359 * @abstract Assign a non-default ID to a state
1361 * @param channel_id - ID of channel containing the state in question
1362 * @param state_index - index of state to give an ID: [0..(nstates-1)]
1363 * @param state_id - 64-bit state ID, for ASCII, use IOREPORT_MAKEID
1365 * @result Appropriate IOReturn code
1368 * Locked version of IOReporter::setStateID(). This method may be
1369 * overriden by sub-classes
1371 * Locking: Caller must ensure that the reporter (data) lock is held.
1373 virtual IOReturn
handleSetStateID(uint64_t channel_id
,
1377 /*! @function IOStateReporter::handleOverrideChannelStateByIndices
1378 * @abstract Overrides state data for a channel with passed arguments
1380 * @param channel_index - index of the channel which state is to be updated
1381 * @param state_index - index of the state id for the channel
1382 * @param time_in_state - time used as new total time in state
1383 * @param intransitions - total number of transitions into state
1384 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1385 * @result Appropriate IOReturn code
1388 * Locked version of IOReporter::overrideChannelState(). This method
1389 * may be overriden by sub-classes.
1391 * Locking: Caller must ensure that the reporter (data) lock is held.
1393 virtual IOReturn
handleOverrideChannelStateByIndices(int channel_index
,
1395 uint64_t time_in_state
,
1396 uint64_t intransitions
,
1397 uint64_t last_intransition
= 0);
1399 /*! @function IOStateReporter::handleIncrementChannelStateByIndices
1400 * @abstract Updates state data for a channel with passed arguments
1402 * @param channel_index - index of the channel which state is to be updated
1403 * @param state_index - index of the state id for the channel
1404 * @param time_in_state - time used as new total time in state
1405 * @param intransitions - total number of transitions into state
1406 * @param last_intransition - mach_absolute_time of most recent entry (opt)
1407 * @result Appropriate IOReturn code
1410 * Locked version of IOReporter::incrementChannelState(). This method
1411 * may be overriden by sub-classes.
1413 * Locking: Caller must ensure that the reporter (data) lock is held.
1415 virtual IOReturn
handleIncrementChannelStateByIndices(int channel_index
,
1417 uint64_t time_in_state
,
1418 uint64_t intransitions
,
1419 uint64_t last_intransition
= 0);
1422 int *_currentStates
; // current states (per chonnel)
1423 uint64_t *_lastUpdateTimes
; // most recent auto-update
1425 // Required for swapping inside addChannel
1426 int *_swapCurrentStates
;
1427 uint64_t *_swapLastUpdateTimes
;
1429 enum valueSelector
{
1434 uint64_t _getStateValue(uint64_t channel_id
,
1436 enum valueSelector value
);
1438 IOReturn
_getStateIndices(uint64_t channel_id
,
1446 * @class IOHistogramReporter
1447 * @abstract Report histograms of values
1449 * Each IOHistogramReporter can report one histogram representing
1450 * how a given value has changed over time.
1452 class IOHistogramReporter
: public IOReporter
1454 OSDeclareDefaultStructors(IOHistogramReporter
);
1457 /*! @function IOHistogramReporter::with
1458 * @abstract Initializes the IOHistogramReporter instance variables and data structures
1460 * @param reportingService - The I/O Kit service for this reporter's channels
1461 * @param categories - The categories in which the report should be classified
1462 * @param channelID - uint64_t channel identifier
1463 * @param channelName - rich channel name as char*
1464 * @param unit - The unit for the quantity recorded by the reporter object
1465 * @param nSegments - Number of segments to be extracted from the config data structure
1466 * @param config - Histograms require the caller to pass a configuration by segments
1467 * @result an instance of the IOSimpleReporter object or NULL on error
1470 * Creates an instance of histogram reporter object.
1472 * FIXME: need more explanation of the config
1474 * IOHistogramReporter currently only supports a single channel.
1478 static IOHistogramReporter
* with(IOService
*reportingService
,
1479 IOReportCategories categories
,
1481 const char *channelName
,
1484 IOHistogramSegmentConfig
*config
);
1486 /*! @function IOHistogramReporter::addChannel
1487 * @abstract Override IOReporter::addChannel(*) to return an error
1489 * @result kIOReturnUnsupported - doesn't support adding channels
1492 addChannel(__unused
uint64_t channelID
, __unused
const char *channelName
= NULL
)
1494 return kIOReturnUnsupported
;
1497 /*! @function IOHistogramReporter::overrideBucketValues
1498 * @abstract Override values of a bucket at specified index
1500 * @param index - index of bucket to override
1501 * @param bucket_hits - new bucket hits count
1502 * @param bucket_min - new bucket minimum value
1503 * @param bucket_max - new bucket maximum value
1504 * @param bucket_sum - new bucket sum
1505 * @result Appropriate IOReturn code
1508 * Replaces data in the bucket at the specified index with the data pointed
1509 * to by bucket. No sanity check is performed on the data. If the index
1510 * is out of bounds, kIOReturnBadArgument is returned.
1512 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1515 IOReturn
overrideBucketValues(unsigned int index
,
1516 uint64_t bucket_hits
,
1519 int64_t bucket_sum
);
1521 /*! @function IOHistogramReporter::tallyValue
1522 * @abstract Add a new value to the histogram
1524 * @param value - new value to add to the histogram
1525 * @result the index of the affected bucket, or -1 on error
1528 * The histogram reporter determines in which bucket the value
1529 * falls and increments it. The lowest and highest buckets
1530 * extend to negative and positive infinity, respectively.
1532 * Locking: same-instance concurrency SAFE, WILL NOT BLOCK
1534 int tallyValue(int64_t value
);
1536 /*! @function IOHistogramReporter::free
1537 * @abstract Releases the object and all its resources.
1540 * ::free() assumes that init() has completed. Clients should use
1541 * the static ::with() methods to obtain fully-initialized reporter
1544 * Locking: same-instance concurrency UNSAFE
1546 virtual void free(void) APPLE_KEXT_OVERRIDE
;
1550 /*! @function IOHistogramReporter::initWith
1551 * @abstract instance method implementation called by ::with
1554 * See description of parameters above
1556 virtual bool initWith(IOService
*reportingService
,
1557 IOReportCategories categories
,
1559 const OSSymbol
*channelName
,
1562 IOHistogramSegmentConfig
*config
);
1564 /*! @function IOHistogramReporter::handleCreateLegend
1565 * @abstract Builds an IOReporting legend entry representing the channels of this reporter.
1567 * @result An IOReportLegendEntry or NULL on failure
1570 * The returned legend entry may be appended to kIOReportLegendKey
1571 * to be published by the caller in the IORegistry. See the
1572 * IOReportLegend class for more details.
1574 * Locking: same-instance concurrency SAFE, MAY BLOCK
1576 IOReportLegendEntry
* handleCreateLegend(void) APPLE_KEXT_OVERRIDE
;
1582 int64_t *_bucketBounds
;
1584 IOHistogramSegmentConfig
*_histogramSegmentsConfig
;
1588 /***********************************/
1589 /***** 4. IOReportLegend Class *****/
1590 /***********************************/
1593 * @class IOReportLegend
1594 * @abstract combine legend entries into a complete legend
1596 * IOReportLegend adds metadata to legend entries and combines them
1597 * into a single OSArray that can be published under the
1598 * kIOReportLegendKey property in the I/O Kit registry.
1600 class IOReportLegend
: public OSObject
1602 OSDeclareDefaultStructors(IOReportLegend
);
1605 /*! @function IOReportLegend::with
1606 * @abstract Create an instance of IOReportLegend
1608 * @param legend - OSArray of the legend possibly already present in registry
1609 * @result an instance of IOReportLegend, or NULL on failure
1612 * An IOReporting legend (an OSArray of legend entries) may be already
1613 * present in the IORegistry. Thus the recommended way to publish
1614 * new entries is to append to any existing array as follows:
1615 * 1. call getProperty(kIOReportLegendKey) to get an existing legend.
1618 * - OSDynamicCast to OSArray
1619 * - and pass it to ::with()
1620 * IOReportLegend *legendMaker = IOReportLegend::with(legend);
1621 * The provided array is retained by IOReportLegend.
1623 * 2b. If no legend already exists in the registry, pass NULL
1624 * IOReportLegend *legend = IOReportLegend::with(NULL);
1625 * This latter invocation will cause IOReportLegend to create a new
1626 * array internally (also holding one reference).
1628 * At the cost of some registry churn, the static
1629 * IOReportLegend::addReporterLegend() will handle the above, removing
1630 * the need for any direct use of the IOReportLegend class.
1632 static IOReportLegend
* with(OSArray
*legend
);
1634 /*! @function IOReportLegend::addLegendEntry
1635 * @abstract Add a new legend entry
1637 * @param legendEntry - entry to be added to the internal legend array
1638 * @param groupName - primary group name for this entry
1639 * @param subGroupName - secondary group name for this entry
1640 * @result appropriate IOReturn code
1643 * The entry will be retained as an element of the internal array.
1644 * Legend entries are available from reporter objects. Entries
1645 * represent some number of channels with similar properties (such
1646 * as group and sub-group). Multiple legend entries with the same
1647 * group names will be aggregated in user space.
1649 * Drivers that instantiate their reporter objects in response to
1650 * IOService::configureReport(kIOReportDisable) will need to create
1651 * temporary reporter objects for the purpose of creating their
1652 * legend entries. User-space legends are tracked by 12836893.
1654 IOReturn
addLegendEntry(IOReportLegendEntry
*legendEntry
,
1655 const char *groupName
,
1656 const char *subGroupName
);
1658 /*! @function IOReportLegend::addReporterLegend
1659 * @abstract Add a legend entry from a reporter object
1661 * @param reporter - IOReporter to use to extract and append the legend
1662 * @param groupName - primary group name for this entry
1663 * @param subGroupName - secondary group name for this entry
1664 * @result appropriate IOReturn code
1667 * An IOReportLegendEntry will be created internally to this method from
1668 * the IOReporter object passed in argument. The entry will be released
1669 * internally after being appended to the IOReportLegend object.
1670 * Legend entries are available from reporter objects. Entries
1671 * represent some number of channels with similar properties (such
1672 * as group and sub-group). Multiple legend entries with the same
1673 * group names will be aggregated in user space.
1675 * Drivers that instantiate their reporter objects in response to
1676 * IOService::configureReport(kIOReportDisable) will need to create
1677 * temporary reporter objects for the purpose of creating their
1678 * legend entries. User-space legends are tracked by 12836893.
1680 * Locking: same-reportingService and same-IORLegend concurrency UNSAFE
1682 IOReturn
addReporterLegend(IOReporter
*reporter
,
1683 const char *groupName
,
1684 const char *subGroupName
);
1686 /*! @function IOReportLegend::addReporterLegend
1687 * @abstract Add a legend entry from a reporter object
1689 * @param reportingService - IOService data provider into the reporter object
1690 * @param reporter - IOReporter to use to extract and append the legend
1691 * @param groupName - primary group name for this entry
1692 * @param subGroupName - secondary group name for this entry
1693 * @result appropriate IOReturn code
1696 * An IOReportLegendEntry will be created internally to this method from
1697 * the IOReporter object passed in argument. The entry will be released
1698 * internally after being appended to the IOReportLegend object.
1699 * Legend entries are available from reporter objects. Entries
1700 * represent some number of channels with similar properties (such
1701 * as group and sub-group). Multiple legend entries with the same
1702 * group names will be aggregated in user space.
1704 * Drivers that instantiate their reporter objects in response to
1705 * IOService::configureReport(kIOReportDisable) will need to create
1706 * temporary reporter objects for the purpose of creating their
1707 * legend entries. User-space legends are tracked by 12836893.
1709 * The static version of addReporterLegend adds the reporter's legend
1710 * directly to reportingService's kIOReportLegendKey. It is not
1711 * possible to safely update kIOReportLegendKey from multiple threads.
1713 * Locking: same-reportingService and same-IORLegend concurrency UNSAFE
1715 static IOReturn
addReporterLegend(IOService
*reportingService
,
1716 IOReporter
*reporter
,
1717 const char *groupName
,
1718 const char *subGroupName
);
1720 /*! @function IOReportLegend::getLegend
1721 * @abstract Accessor method to get the legend array
1723 * @result Returns the OSObject holding the legend to be published by the driver
1725 * This array will include all legend entries added to the object.
1727 OSArray
* getLegend(void);
1729 /*! @function IOReportLegend::free
1730 * @abstract Frees the IOReportLegend object
1733 * ::free() cleans up the reporter and anything it allocated.
1735 * ::free() releases the internal array (which was either passed
1736 * to ::with() or created as a result of ::with(NULL)). Assuming
1737 * the caller extracted the array with getLegend() and published it
1738 * in the I/O Kit registry, its ownership will now be with the
1741 void free(void) APPLE_KEXT_OVERRIDE
;
1749 OSArray
*_reportLegend
;
1751 IOReturn
initWith(OSArray
*legend
);
1753 /*! @function IOReportLegend::organizeLegend
1754 * @abstract Sets up the legend entry, organizing it with group and sub-group names
1756 * @param groupName - Primary group name
1757 * @param subGroupName - Secondary group name
1758 * @result IOReturn code
1760 IOReturn
organizeLegend(IOReportLegendEntry
*legendEntry
,
1761 const OSSymbol
*groupName
,
1762 const OSSymbol
*subGroupName
);
1764 // FUTURE POSSIBILITY (NOT IMPLEMENTED!)
1765 /*! @function IOReportLegend::createReporters
1766 * @abstract Creates as many IOReporter objects as the legend contains
1768 * @param legend - OSArray legend object containing the description of all reporters
1769 * the driver is able to address
1770 * @param reporter - OSSet of reporter objects created by this call
1771 * @result IOReturn code kIOReturnSuccess if successful
1774 * NOT SUPPORTED at the time of writing
1775 * Convenience method to create all the driver's reporter objects from a legend.
1776 * Can be used when a legend is made public through the IORegistry but IOReporter
1777 * objects have not yet been created to save memory, waiting for observers.
1778 * Upon a call to configureReport via the IOService method, a driver could
1779 * create all reporter objects on the fly using this function.
1781 // For Future IOReporterManager...
1782 // static IOReturn createReporters(requestedChannels, legend);
1785 #endif /* ! _IOKERNEL_REPORTERS_H_ */