Skip to content

Commit

Permalink
SWPTP-1386: clockfeed 12/12: document clock feed
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Dec 19, 2023
1 parent 2c3ca2a commit bb1c7e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/include/sfptpd_clockfeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ void sfptpd_clockfeed_stats_end_period(struct sfptpd_clockfeed *module,
*/
#define SFPTPD_CLOCKFEED_MSG_SYNC_EVENT SFPTPD_CLOCKFEED_MSG(5)

#endif

#endif /* _SFPTPD_CLOCKFEED_MODULE_H */
22 changes: 19 additions & 3 deletions src/sfptpd_clockfeed.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static const struct sfptpd_stats_collection_defn clockfeed_stats_defns[] =
#define CLOCKFEED_MSG(x) SFPTPD_CLOCKFEED_MSG(x)

/* Add a clock source.
* It is an synchronous message.
* It is a synchronous message.
*/
#define CLOCKFEED_MSG_ADD_CLOCK CLOCKFEED_MSG(1)
struct clockfeed_add_clock {
Expand All @@ -96,7 +96,7 @@ struct clockfeed_add_clock {
};

/* Remove a clock source.
* It is an synchronous message.
* It is a synchronous message.
*/
#define CLOCKFEED_MSG_REMOVE_CLOCK CLOCKFEED_MSG(2)
struct clockfeed_remove_clock {
Expand Down Expand Up @@ -128,6 +128,11 @@ struct clockfeed_unsubscribe {
*/
#define CLOCKFEED_MSG_SYNC_EVENT SFPTPD_CLOCKFEED_MSG_SYNC_EVENT

/* Next message code to be allocated. Avoid overlapping with above
* message code that is defined in the header file.
*/
#define CLOCKFEED_MSG_NEXT_UNALLOCATED CLOCKFEED_MSG(6)

/* Union of all clock feed messages
* @hdr Standard message header
* @u Union of message payloads
Expand Down Expand Up @@ -315,6 +320,17 @@ static void clockfeed_reap_zombies(struct sfptpd_clockfeed *module,
}
}

/* This is the key function of the clock feed component. Periodically sample
* all clock differences (against the system clock) for all interesting clocks.
* These may have different cadences configured (internally - this is not used
* at present).
*
* Snapshots of the clocks are stored in a lock-free circular buffer
* structure for consumption in another thread via helper functions. Typically
* only the last snapshot available will be consumed but additional samples
* are present to help avoid losing samples through contention and in case
* future consumers can benefit from out-of-date history.
*/
static void clockfeed_on_timer(void *user_context, unsigned int id)
{
struct sfptpd_clockfeed *clockfeed = (struct sfptpd_clockfeed *)user_context;
Expand Down Expand Up @@ -750,7 +766,7 @@ struct sfptpd_clockfeed *sfptpd_clockfeed_create(struct sfptpd_thread **threadre
goto fail;
}

/* Create the service thread- the thread start up routine will
/* Create the service thread - the thread start up routine will
* carry out the rest of the initialisation. */
rc = sfptpd_thread_create("clocks", &clockfeed_thread_ops, clockfeed, threadret);
if (rc != 0) {
Expand Down

0 comments on commit bb1c7e9

Please sign in to comment.