Changeset 51304dde in rtems

May 4, 2015, 5:59:39 PM (5 years ago)
Ian Lepore <ian@…>
5, master
Ian Lepore <ian@…> (05/04/15 17:59:39)
Sebastian Huber <sebastian.huber@…> (10/12/17 05:04:09)

timecounter: Merge FreeBSD change r282424

Implement a mechanism for making changes in the kernel<->driver PPS interface without breaking ABI or API compatibility with existing drivers.

The existing data structures used to communicate between the kernel and
driver portions of PPS processing contain no spare/padding fields and no
flags field or other straightforward mechanism for communicating changes
in the structures or behaviors of the code. This makes it difficult to
MFC new features added to the PPS facility. ABI compatibility is
important; out-of-tree drivers in module form are known to exist. (Note
that the existing api_version field in the pps_params structure must
contain the value mandated by RFC 2783 and any RFCs that come along after.)

These changes introduce a pair of abi-version fields which are filled in
by the driver and the kernel respectively to indicate the interface
version. The driver sets its version field before calling the new
pps_init_abi() function. That lets the kernel know how much of the
pps_state structure is understood by the driver and it can avoid using
newer fields at the end of the structure that it knows about if the driver
is a lower version. The kernel fills in its version field during the init
call, letting the driver know what features and data the kernel supports.

To implement the new version information in a way that is backwards
compatible with code from before these changes, the high bit of the
lightly-used 'kcmode' field is repurposed as a flag bit that indicates the
driver is aware of the abi versioning scheme. Basically if this bit is
clear that indicates a "version 0" driver and if it is set the driver_abi
field indicates the version.

These changes also move the recently-added 'mtx' field of pps_state from
the middle to the end of the structure, and make the kernel code that uses
this field conditional on the driver being abi version 1 or higher. It
changes the only driver currently supplying the mtx field, usb_serial, to
use pps_init_abi().

Reviewed by: hselasky@

Update #3175.

2 edited


  • cpukit/score/include/sys/timepps.h

    r0aef6fb r51304dde  
    136136struct mtx;
     138#define KCMODE_EDGEMASK         0x03
     139#define KCMODE_ABIFLAG          0x80000000 /* Internal use: abi-aware driver. */
     141#define PPS_ABI_VERSION         1
     143#define PPSFLAG_MTX_SPIN        0x01    /* Driver mtx is MTX_SPIN type. */
    138145struct pps_state {
    139146        /* Capture information. */
    142149        unsigned        capgen;
    143150        unsigned        capcount;
    145         /* pointer to mutex protecting this state, if any */
    146         struct mtx      *mtx;
    148152        /* State information. */
    154158        struct timecounter *ppstc;
    155159        unsigned        ppscount[3];
     160        /*
     161         * The following fields are valid if the driver calls pps_init_abi().
     162         */
     163        uint16_t        driver_abi;     /* Driver sets before pps_init_abi(). */
     164        uint16_t        kernel_abi;     /* Kernel sets during pps_init_abi(). */
     165        struct mtx      *driver_mtx;    /* Optional, valid if non-NULL. */
     166        uint32_t        flags;
    159170void pps_event(struct pps_state *pps, int event);
    160171void pps_init(struct pps_state *pps);
     172void pps_init_abi(struct pps_state *pps);
    161173int pps_ioctl(unsigned long cmd, caddr_t data, struct pps_state *pps);
    162174void hardpps(struct timespec *tsp, long nsec);
  • cpukit/score/src/kern_tc.c

    r0aef6fb r51304dde  
    17141714                while (aseq == pps->ppsinfo.assert_sequence &&
    17151715                    cseq == pps->ppsinfo.clear_sequence) {
    1716                         if (pps->mtx != NULL)
    1717                                 err = msleep(pps, pps->mtx, PCATCH, "ppsfch", timo);
    1718                         else
     1716                        if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
     1717                                if (pps->flags & PPSFLAG_MTX_SPIN) {
     1718                                        err = msleep_spin(pps, pps->driver_mtx,
     1719                                            "ppsfch", timo);
     1720                                } else {
     1721                                        err = msleep(pps, pps->driver_mtx, PCATCH,
     1722                                            "ppsfch", timo);
     1723                                }
     1724                        } else {
    17191725                                err = tsleep(pps, PCATCH, "ppsfch", timo);
     1726                        }
    17201727                        if (err == EWOULDBLOCK && fapi->timeout.tv_sec == -1) {
    17211728                                continue;
Note: See TracChangeset for help on using the changeset viewer.