Changeset 7e1a9ac in rtems

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

timecounter: Synchronize with FreeBSD

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@

1 edited


  • cpukit/score/src/kern_tc.c

    rcb6fde65 r7e1a9ac  
    3737#endif /* __rtems__ */
    3838#include <sys/cdefs.h>
    39 __FBSDID("$FreeBSD r280012 2015-03-14T23:16:12Z$");
     39__FBSDID("$FreeBSD r282424 2015-05-04T17:59:39Z$");
    4141#include "opt_compat.h"
    15751575 */
     1578 *  Return true if the driver is aware of the abi version extensions in the
     1579 *  pps_state structure, and it supports at least the given abi version number.
     1580 */
     1581static inline int
     1582abi_aware(struct pps_state *pps, int vers)
     1585        return ((pps->kcmode & KCMODE_ABIFLAG) && pps->driver_abi >= vers);
    15771588static int
    15781589pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
    16041615                while (aseq == pps->ppsinfo.assert_sequence &&
    16051616                    cseq == pps->ppsinfo.clear_sequence) {
    1606                         if (pps->mtx != NULL)
    1607                                 err = msleep(pps, pps->mtx, PCATCH, "ppsfch", timo);
    1608                         else
     1617                        if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
     1618                                if (pps->flags & PPSFLAG_MTX_SPIN) {
     1619                                        err = msleep_spin(pps, pps->driver_mtx,
     1620                                            "ppsfch", timo);
     1621                                } else {
     1622                                        err = msleep(pps, pps->driver_mtx, PCATCH,
     1623                                            "ppsfch", timo);
     1624                                }
     1625                        } else {
    16091626                                err = tsleep(pps, PCATCH, "ppsfch", timo);
     1627                        }
    16101628                        if (err == EWOULDBLOCK && fapi->timeout.tv_sec == -1) {
    16111629                                continue;
    16971715                if (kapi->edge & ~pps->ppscap)
    16981716                        return (EINVAL);
    1699                 pps->kcmode = kapi->edge;
     1717                pps->kcmode = (kapi->edge & KCMODE_EDGEMASK) |
     1718                    (pps->kcmode & KCMODE_ABIFLAG);
    17001719                return (0);
    17181737        pps->ppscap |= PPS_TSCLK_MASK;
     1739        pps->kcmode &= ~KCMODE_ABIFLAG;
     1743pps_init_abi(struct pps_state *pps)
     1746        pps_init(pps);
     1747        if (pps->driver_abi > 0) {
     1748                pps->kcmode |= KCMODE_ABIFLAG;
     1749                pps->kernel_abi = PPS_ABI_VERSION;
     1750        }
Note: See TracChangeset for help on using the changeset viewer.