DCI Statistics


Contents


Introduction

The maintenance of statistics such as "packets transmitted" for a network interface can greatly assist the system administrator (or user) in a variety of circumstances.

Traditionally, support for such statistics gathering has been irregular and generally limited to direct screen printing. This specification provides a more controlled method of presenting statistics to the user, and permits a single generic display program to cope with all compliant modules.

The following characterise the intentions of this interface specification:

  • Plus points

    • Simplicity of implementation
    • Single generic statistics display program
    • No essential central information that needs frequent updating
    • Information is for presentation to humans primarily
    • Atomic operations without any latching mechanisms
    • Well-behaved with multiple gatherers
    • Well-behaved if a supplier unexpectedly disappears
    • Virtually stateless communication

  • Minus points

    • Not re-entrant - callbacks or user mode code only
    • Restrictive string model
    • Polled interface, rather than event driven
    • Only simple flat structure to statistics
    • Only really suitable for human display


Technical Details

Basics of operation

A piece of software that wishes to offer statistics is termed a "supplier". A piece of software that obtains statistics from a supplier and presents them to the user is termed a "gatherer", and the operation it performs is often referred to as "enumerating the statistics". There are typically more suppliers than gatherers in a system.

As part of its normal operations, a supplier maintains a set of statistics. A gatherer, typically upon user invocation, enumerates the available suppliers, enumerates the statistics supplied by each supplier and then presents this information to the user. More dynamic presentation is also possible. A supplier is passive (other than its normal operations), whilst the gatherer actively seeks out the information to be presented.

The first stage of enumeration (determining what suppliers are present) is performed with a service call (Service_StatisticEnumerate), and the second stage (determining what statistics are available and their values) is performed through a SWI whose SWI number is obtained during the first stage of enumeration (StatisticsProvider_Statistics). This SWI number is used for all stages of operation apart from enumeration itself.

Each statistic has a number of different pieces of information associated with it, forming its description, and a value. The description provides the necessary information to access and manipulate the value, including the number of bytes of storage required for the value, it's type, format and desired presentation. The data types supported are boolean, integer and string. An unused data type also provides for padding.

Descriptions and statistics are read in ranges from a lower statistic number to an upper statistic number, inclusive. The first statistic of any supplier is zero. The highest statistic number of a supplier is obtained when the SWI number for a supplier is obtained. A range is always processed atomically by the supplier, ensuring consistent values and presentation to a gatherer when so required. A supplier indicates the volatility of its statistics and typically attempts to group statistics into ranges of the same volatility.

Enumerating suppliers

The list of available suppliers is determined with a single service call, Service_StatisticEnumerate.

On receiving this service, each supplier allocates a small structure from the RMA, initializes it and links it into the linked list whose head is pointed to by R0. Whether the supplier adds an entry at the head or tail of the list does not matter, although it is recommended that the entries be added to the head for simplicity. If a gatherer requires any specific order, then it should explicitly sort the suppliers list itself. A gatherer should not cache SWI values across invocations of suppliers, as a module might choose a dynamic SWI numbering scheme if it offers multiple effective suppliers.

Statistics Provider Structure

In C, this structure is defined as follows:

typedef struct spctl
{
    struct spctl       *next;           /* Next structure in list */
    unsigned int        i_version;      /* Interface version */
    unsigned long       features;       /* Combination of SF_ values */
    unsigned int        swinumber;      /* The SWI SA_DESCRIBE/SA_READ use */
    unsigned int        max_stat;       /* Highest stat number (inclusive) */
    unsigned int        type;           /* Acorn assigned supplier type */
    unsigned int        s_version;      /* Supplier version */
    char               *module;         /* Module name (short one) */
    char               *title;          /* Title string - short */
    char               *description;    /* Descriptive string - long */
    unsigned char       reset[8];       /* Unique for each invocation */
} dci4_spctl;

OffsetNameContents
+0nextThis field is used to construct the linked list of suppliers for the enumeration operation. A value of zero indicates the end of the list.
+4i_versionThe DCI4 Statistic Interface version that the supplier is implemented against.
+8featuresA bitset of flags defining optional aspects of a supplier. No features are currently defined and the the value must be set to 0.
+12swinumberThe SWI number through which all other communication with the supplier is performed.
+16max_statThe highest statistic number, inclusive, that the supplier provides. This implies a supplier must always supply at least one statistic.
+20type

This field is available to provide some classification of suppliers. It is the only centrally administered resource in this specification, and its use is optional. The currently defined values are as follows:

ValueNameMeaning
0SPT_GENERAL_SUPPLIERUse this if no other suitable type
1SPT_NETWORK_PROTOCOLA DCI4 protocol module
2SPT_NETWORK_DRIVERA DCI4 device driver module
3SPT_MBUF_MANAGERThe DCI4 mbuf manager module

+24s_versionThis is the version number of the supplier module itself (as opposed to the version number of an interface it conforms to). It is provided for the convenience of the user.
+28moduleThis is the supplier's module title (as opposed to its help string).
+32titleThis is a short descriptive string to identify the supplier to the user. The gatherer only contracts to print at least the first twenty characters of this string.
+36descriptionThis is a longer description of the supplier that should convey it's purpose to the user. The gatherer only contracts to print at least the first fifty characters of this string.
+40resetThis 8 byte field is initialised with a unique value each time the supplier is initialised. It permits the gatherer to spot a supplier that has just re-initialised. The time and date at which the supplier initialises are recommended values to write here. The gatherer performs an 8 byte equality test and otherwise assumes no further format information about these bytes.

When a gatherer has finished interacting with a supplier, it should free the allocated structures back into the RMA.

Describing and obtaining statistics

Apart from the enumeration phase, all communication with a supplier is performed through the single SWI number obtained during the enumeration phase (described as StatisticsProvider_Statistics).

SA_DESCRIBE (0) obtains descriptions of statistics, whilst SA_READ (1) obtains the actual values of statistics. It is necessary for first obtain the description of a statistic before reading it, as the description is the only way the gatherer can obtain the size of the statistic value and know how much buffer space to allocate.

In essence, both these actions enumerate information about a range of statistics into the buffer supplied. This is performed atomically, where necessary, by the supplier. In both cases, the operation starts from the first statistic and proceeds in steps of one and stops once the last statistic has been processed. Output is placed into the buffer supplied. If this buffer is not big enough for the requested range of statistics, then processing will stop when it is no longer possible to write all the necessary information for a statistic (i.e. if the buffer supplied is not big enough, the number of unused bytes will be less than the size of a statistic description). Return values of the number of statistics processed and the number of bytes of the buffer used are returned. The buffer must be word aligned in memory.

Statistic Description Structure

Each statistic is described with a fixed sized buffer, described in C as follows:

typedef struct stdesc
{
    unsigned int            type;           /* ST_ series */
    unsigned int            format;         /* SxF_ series */
    unsigned int            presentation;   /* SxP_ series */
    unsigned int            size;           /* Measured in bytes */
    unsigned int            volatility;     /* SV_ series */
    char                   *name;           /* String is static */
    unsigned int            name_tag;       /* See specification */
    unsigned int            spare;          /* Unused. Always zero */
} dci4_stdesc;

OffsetNameContents
+0type

This defines the type of statistic. Possible values are:

ValueNameMeaning
0ST_UNUSEDST_UNUSED is used by a supplier to reserve a statistic number. Such a statistic always has a value occupying zero bytes, and hence can always be enumerated, no matter how many bytes are left in the called supplied buffer. A statistic with a type of ST_UNUSED should always be skipped over when printing and enumerating - none of the fields beyond the type and size fields are valid for unused statistics.
1ST_BOOLEANST_BOOLEAN values are single bit boolean values. A variety of different presentation methods may be selected by the supplier in order to maximise coherence between the description and the presentation of a boolean value. Only the least significant bit of a boolean type has a defined value.
2ST_STRINGST_STRING values are string values. Currently, strings are defined using a zero byte as a terminator character {future versions may well introduce counted length strings as well). A supplier is required to be able to place an upper length value on all strings so that sufficient space may be allocated within the caller supplied buffer for the SA_READ operation.
3ST_INTEGER8ST_INTEGER8 is an 8-bit (byte) quantity.
4ST_INTEGER16ST_INTEGER8 is an 16-bit (half-word) quantity.
5ST_INTEGER32ST_INTEGER8 is an 32-bit (word) quantity.
6ST_INTEGER64ST_INTEGER8 is an 64-bit (double-word) quantity.
7ST_ADDRESSST_ADDRESS values are addresses given in a protocol-specific format. A variety of different forms of address are possible. The presentation formats available for this type are presently undefined. This type of statistic is only supported by 1.01 of the DCI statistics format.
8ST_TIMEST_TIME values are time values given in a variety of formats. The presentation methods presented allow for times to be specified in a number of ways. This type of statistic is only supported by 1.01 of the DCI statistics format.

+4format

This field contains a value indicating the format of the value. The range of values is specific to each type (all the integer types share a common set of formats and presentations for convenience). Depending upon the type in question, this value may be an enumeration, a bitset of flags or a combination of both (none of the currently defined formats mix enumeration and flag bitsets). See below for the meanings of the formats,

+8presentation

This field dictates how the supplier would like the value to be presented. A gatherer may choose to ignore this value, but only at the risk of presenting the user with incoherent information. See below for the meaning of the presentations.

+12sizeThis is the number of bytes the statistic wishes reserved in the buffer for an SA_READ operation. It is always a multiple of four bytes. It is sometimes larger than the actual value necessary.
+16volatility

This field indicates how volatile a statistic is. The three possible values are:

ValueNameMeaning
0SV_STATICConstant per invocation
1SV_VARIABLEUnlikely to have changed in 5 minutes
2SV_VOLATILECan change very rapidly

+20nameThis fields points at the name of the statistic. It is a short descriptive string that the gatherer contracts to display at least the first twenty characters of. The string itself is static, zero byte terminated and contained with the supplier module.
+24name_tag

This value, together with the information contained in the dci4_spctl structure and a ISV/IHV supplied data file permit the gatherer to obtain a description of a statistic. The precise mechanism has yet to be determined. Must be zero.

+28spareThis field is reserved for future use and must be zero.

The format and presentation vary with the statistic types.

Statistic typeNameFormat and presentation
0ST_UNUSEDThere is no format or presentation defined for the ST_UNUSED type.
1ST_BOOLEAN

Format:

ValueNameMeaning
0SBF_NORMALThe value supplied is 0 if boolean 'false' and any other value for boolean 'true'.
1SBF_INVERTEDThe boolean state is inverted, 0 if boolean 'true' and any other value for boolean 'false'.

Presentation:

ValueNameMeaning
0SBP_ON_OFFThe strings 'on' and 'off' will be used.
1SBP_YES_NOThe strings 'yes' and 'no' will be used.
2SBP_TRUE_FALSEThe strings 'true' and 'false' will be used.
3SBP_ALWAYS_NEVERThe strings 'always' and 'never' will be used.
4SBP_ONE_ZEROThe strings '1' and '0' will be used.

2ST_STRING

Format:

ValueNameMeaning
0SSF_ZEROTERMThis is the only defined format, indicating that the string is zero-terminated.

Presentation:

ValueNameMeaning
0SSP_LITERALThe string should be presented as supplied.

3-6ST_INTEGER#

Format:

Bit(s)NameMeaning
0SIF_UNSIGNEDSet:The value is unsigned
Clear:The value is signed
1SIF_BIGENDIANSet:The value is supplied as big-endian
Clear:The value is supplied as little-endian
2-31Reserved, must be zero

Presentation:

ValueNameMeaning
0SIP_HEXADECIMALThe value should be presented as a hexadecimal number.
1SIP_DECIMALThe value should be presented as a decimal number.
2SIP_DOTTEDThe value should be presented separating every octet with a '.' character. This was intended for use for addresses; it has been superseded by the ST_ADDRESS type.

7ST_ADDRESS

Format:

ValueNameMeaning
0SAF_ETHERNETThe value is a 6 byte MAC address.
1SAF_IPThe value is a 4 byte IP address.
2SAF_ECONETThe value is a 2 byte (net.station) address.

Presentation:

ValueNameMeaning
0SAP_NORMALThere is only this presentation type.

7ST_TIME

Format:

ValueNameMeaning
0STF_5BYTEThe value is a standard 5 bytes format (8 bytes, top 3 bytes ignored), measured in centiseconds since 00:00 1st January 1900.
1STF_CTIMEThe value is a C time() value, measured in seconds since 00:00 1st January 1970.
2STF_MONOTONICThe value is a centisecond value, used by OS_ReadMonotonicTime, measured in seconds since the system started.

Presentation:

ValueNameMeaning
0STP_ABSOLUTEThe values are absolute and should be presented as time values from their reference base.
1STP_RELATIVEThe values are relative to the current time, and the reference base should be ignored. For example, a value of 250 in format STF_MONOTONIC might be presented as '2.50 seconds'.

Ensuring statistic atomicity

The supplier is required to perform each read request atomically. This means a gatherer can rely upon a read operation producing consistent statistics, but it cannot be certain quite when in time these statistics apply to: in some cases, statistics are virtually always out of date by the time the gatherer obtains and uses them.

The simplistic approach to ensuring an atomic read operation is to perform the entire action with interrupts disabled. This, however, has an undesirable effect on interrupt latency for suppliers with many or complex statistics and is not recommended.

The suggested method is a three buffer scheme. One buffer holds the accumulated statistics, the second holds the increments (deltas) being generated "live", and the third is either entirely full of zero values, or there is an active read operation in progress and it holds a previous set of increments that are currently being added (merged) into the accumulated values.

Two pointers are maintained. One for the "live" buffer and the other for the "merge" buffer. The operation that is necessary to perform atomically is the swapping of these two pointer values.

The overall structure suggested is as follows:

start thread of control (ie SWI)

    enter mutex (eg disable interrupts)

        temp := buffer pointer 1
        buffer pointer 1 := buffer pointer 2
        buffer pointer 2 := temp

    exit mutex (and ensure interrupts enabled)

    add values from buffer pointer 2 into the accumulated values

    zero the memory described by buffer pointer 2

end thread of control (ie SWI)

This maximises the usefulness of the non re-entrancy requirement and requires ONLY the swapping of the buffer pointers to be performed atomically. All other operations can proceed with interrupts enabled. This minimal critical region is the prime motivation behind this scheme.

Handling dynamic statistics

Some applications of the statistic interface will require a single RISC OS module to behave as multiple suppliers. For example, a device driver module that controls multiple interfaces might well wish to provide an overall set of statistics, and then an instance of a set of statistics per interface controlled.

A separate SWI number is required for each 'effective supplier'. This is not normally a problem, as very few modules approach the limit of the 64 separate SWIs allocated. Gatherers are expected to obtain SWI numbers through the enumeration method supplied, and should be capable of handling dynamic SWI number assignment. For example, a device driver may choose SWIs 63, 62 and 61 for units 0, 1 and 2, respectively. If a gatherer were to attempt to 'cache' these SWI numbers across invocations of the device driver, then it might not correctly cater for the addition or removal of interfaces.


Services


Service_StatisticEnumerate
(Service &A1)

Enumerate providers of extended DCI statistics
On entry
R0=Pointer to the head of the enumeration chain
R1=Reason code (&A1)
On exit
R0=New pointer to the head of the enumeration chain containing all the statistic providers
Use

This service call is used to enumerate the statistic providers which are currently active. Each supplier should allocate a block in the RMA containing the Statistics Provider Structure and fill in the details of its provider. It should then update the next pointer to point to the supplied head of the chain, and return the new pointer in R1. It must not claim the service.

Statistics gatherers will use this information to decide what to display, and call the supplied SWI number as appropriate. Initially the statistics provider will supply the pointer in R0 as 0 when the service is issued.

Related SWIs
StatisticsProvider_Statistics

SWI calls


StatisticsProvider_Statistics
(SWI StatisticsProvider+&0)

Obtain statistics from a statistics provider
On entry
R0=SA_DESCRIBE (0) or SA_READ (1) depending on the operation required
R1=First statistic, inclusive
R2=Last statistic, inclusive
R3=First byte of buffer in memory
R4=Number of bytes in buffer
On exit
R0-4preserved
R5=Number of statistics processed
R6=Number of bytes of buffer used
Interrupts
Interrupts are undefined
Fast interrupts are undefined
Processor mode
Processor is in undefined mode
Re-entrancy
Not defined
Use

This SWI is used to obtain a description of the statistics provided by a supplier, or the actual values of those statitics. It is expected that it be called at least twice, once to read the descriptions of the statistics, and then future times to read the values of those statistics.

When the operation requested is SA_DESCRIBE (0), the statistics buffer supplied in R1 should be filled with structures as described in Statistic Description Structure.

When the operation requested is SA_READ (1), the statistics buffer supplied in R1 should be filled with the values corresponding to those that would be described if SA_DESCRIBE (0) had been requested. Each statistics has a length as defined by the Statistic Description Structure.

If the buffer is filled before all statistics are written, the SWI should exit with as much data as would fit into the buffer written and appropriate values in R5 and R6 on exit. Statistics gatherers may recognise this condition and provide extended buffers.

Related services
Service_StatisticEnumerate

Document information

Maintainer(s):
Charles Ferguson <gerph@gerph.org>
History:
RevisionDateAuthorChanges
123 Sep 1994Borris
  • Tried to get the basic ideas into a coherent document.
225 Sep 1994Borris
  • Changed precise details of register updating on return from some of the swi operations.
3Oct 1994Borris
  • Listened to feedback from reviewers.
  • Adjust underlying model and streamlined most aspects.
  • Added details of suggested scheme for atomic sampling.
  • This issue not widely distributed.
47 Nov 1994Borris
  • Tided up and checked consistency with reference header file.
  • Added correct service call number.
  • Added comments about effective suppliers and dynamic SWI number possibilities.
  • name_tag as being outstanding added.
528 Apr 2003Gerph
  • Added ST_TIME and ST_ADDRESS types.
608 Aug 2020GerphRestructure as PRM-in-XML
  • Exported from Impression, and converted to PRM-in-XML structured format.
  • Restructured document to match PRM structure and style.
  • Added note that the features field is not currently defined and should be 0.
Disclaimer:

Copyright (C) 1994 ANT Limited., PO BOX 300, Cambridge, England. All rights reserved.

Redistribution and use in source code and executable binary forms are permitted provided that: (1) source distributions retain this entire copyright notice and comment, and (2) distributions including executable binaries contain the following acknowledgement:

``This product includes software developed by ANT Limited and its contributors. Copyright (C) ANT Limited 1994.''

and also in the documentation and other materials provided with the distribution and in all advertising materials mentioning features or use of this software. Neither the name of ANT Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

NOT INTENDED FOR USE IN LIFE CRITICAL APPLICATIONS.