Skip to content

Commit

Permalink
clkmgr: Update threshold for chrony offset
Browse files Browse the repository at this point in the history
Signed-off-by: Lai Peter Jun Ann <[email protected]>
  • Loading branch information
Lai Peter Jun Ann committed Jan 9, 2025
1 parent 595a750 commit 78882c9
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 5 deletions.
3 changes: 3 additions & 0 deletions clkmgr/client/clockmanager_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ bool clkmgr_c_subscribe(clkmgr_c_client_ptr client_ptr,
newsub.define_threshold(clkmgr::thresholdGMOffset,
sub.threshold[Clkmgr_thresholdGMOffset].upper_limit,
sub.threshold[Clkmgr_thresholdGMOffset].lower_limit);
newsub.chrony_define_threshold(clkmgr::thresholdChronyOffset,
sub.chrony_threshold[Clkmgr_thresholdGMOffset].upper_limit,
sub.chrony_threshold[Clkmgr_thresholdGMOffset].lower_limit);
newsub.set_composite_event_mask(sub.composite_event_mask);
ret = static_cast<clkmgr::ClockManager *>(client_ptr)->clkmgr_subscribe(newsub,
state);
Expand Down
2 changes: 1 addition & 1 deletion clkmgr/client/notification_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage)
sizeof(client_ptp_data->gm_identity));
if(proxy_data.chrony_offset != client_ptp_data->chrony_offset) {
client_ptp_data->chrony_offset = proxy_data.chrony_offset;
if(currentClientState->get_eventSub().in_range(thresholdGMOffset,
if(currentClientState->get_eventSub().chrony_in_range(thresholdChronyOffset,
client_ptp_data->chrony_offset)) {
if(!(client_ptp_data->chrony_offset_in_range)) {
client_ptp_data->chrony_offset_in_range = true;
Expand Down
2 changes: 1 addition & 1 deletion clkmgr/client/subscribe_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer)
memcpy(clkmgrCurrentState->gm_identity, client_data->gm_identity,
sizeof(client_data->gm_identity));
client_data->chrony_offset = data.chrony_offset;
if(currentClientState->get_eventSub().in_range(thresholdGMOffset,
if(currentClientState->get_eventSub().chrony_in_range(thresholdChronyOffset,
client_data->chrony_offset))
client_data->chrony_offset_in_range = true;
client_data->chrony_reference_id = data.chrony_reference_id;
Expand Down
23 changes: 23 additions & 0 deletions clkmgr/common/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void ClkMgrSubscription::set_ClkMgrSubscription(const ClkMgrSubscription &n)
m_event_mask = n.m_event_mask;
m_composite_event_mask = n.m_composite_event_mask;
m_threshold = n.m_threshold;
m_threshold_chrony = n.m_threshold_chrony;
}

void ClkMgrSubscription::set_event_mask(uint32_t event_mask)
Expand Down Expand Up @@ -69,3 +70,25 @@ bool ClkMgrSubscription::in_range(ThresholdIndex index, int32_t value) const
value > m_threshold[index].lower_limit &&
value < m_threshold[index].upper_limit;
}

bool ClkMgrSubscription::chrony_define_threshold(ThresholdIndex index, int32_t upper,
int32_t lower)
{
m_threshold_chrony[index].upper_limit = upper;
m_threshold_chrony[index].lower_limit = lower;
return true;
}

bool ClkMgrSubscription::chrony_get_threshold(ThresholdIndex index, int32_t &upper,
int32_t &lower)
{
upper = m_threshold_chrony[index].upper_limit;
lower = m_threshold_chrony[index].lower_limit;
return true;
}

bool ClkMgrSubscription::chrony_in_range(ThresholdIndex index, int32_t value) const
{
return value > m_threshold_chrony[index].lower_limit &&
value < m_threshold_chrony[index].upper_limit;
}
3 changes: 2 additions & 1 deletion clkmgr/common/types.m4
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ cnst(uint8_t,THRESHOLD_MAX,8)
*/
enum Nm(ThresholdIndex) sz(`: uint8_t '){
Nm(thresholdGMOffset), /**< threshold for primary-secondary clock offset */
Nm(thresholdLast) /**< Last threshold */
Nm(thresholdLast), /**< Last threshold */
Nm(thresholdChronyOffset) /**< threshold for chrony clock offset */
};

/**
Expand Down
1 change: 1 addition & 0 deletions clkmgr/pub/clkmgr/clockmanager_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct clkmgr_c_subscription {
uint32_t event_mask; /**< Events subscription mask */
uint32_t composite_event_mask; /**< Composite events mask */
struct Clkmgr_Threshold threshold[CLKMGR_THRESHOLD_MAX]; /**< Limits */
struct Clkmgr_Threshold chrony_threshold[CLKMGR_THRESHOLD_MAX]; /**< Limits */
};

/** Pointer to the client structure */
Expand Down
27 changes: 27 additions & 0 deletions clkmgr/pub/clkmgr/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ClkMgrSubscription
uint32_t m_event_mask; /**< Event subscription mask */
uint32_t m_composite_event_mask; /**< Composite event mask */
std::array<Threshold, THRESHOLD_MAX> m_threshold; /**< Upper & lower limits */
std::array<Threshold, THRESHOLD_MAX> m_threshold_chrony; /**< Upper & lower limits */

public:
ClkMgrSubscription() noexcept;
Expand Down Expand Up @@ -91,6 +92,32 @@ class ClkMgrSubscription
* @return Return true if value is within the threshold, and false otherwise
*/
bool in_range(ThresholdIndex index, int32_t value) const;

/**
* Define the upper and lower limits of a specific event
* @param[in] index Index of the event according to ThresholdIndex enum
* @param[in] upper Upper limit
* @param[in] lower Lower limit
* @return true on success, false on failure
*/
bool chrony_define_threshold(ThresholdIndex index, int32_t upper, int32_t lower);

/**
* get the upper and lower limits of a specific event
* @param[in] index Index of the event according to ThresholdIndex enum
* @param[out] upper Upper limit
* @param[out] lower Lower limit
* @return true on success, false on failure
*/
bool chrony_get_threshold(ThresholdIndex index, int32_t &upper, int32_t &lower);

/**
* Check whether a given value is within predefined threshold
* @param[in] index Index of the event according to ThresholdIndex enum
* @param[in] value Current value
* @return Return true if value is within the threshold, and false otherwise
*/
bool chrony_in_range(ThresholdIndex index, int32_t value) const;
};

__CLKMGR_NAMESPACE_END
Expand Down
24 changes: 23 additions & 1 deletion clkmgr/sample/clkmgr_c_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ int main(int argc, char *argv[])
Clkmgr_eventSyncedToGM | Clkmgr_eventASCapable);
subscription.threshold[Clkmgr_thresholdGMOffset].upper_limit = 100000;
subscription.threshold[Clkmgr_thresholdGMOffset].lower_limit = -100000;
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].upper_limit = 100000;
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].lower_limit = -100000;

while ((option = getopt(argc, argv, "s:c:u:l:i:t:h")) != -1) {
while ((option = getopt(argc, argv, "s:c:u:l:i:t:m:n:h")) != -1) {
switch (option) {
case 's':
subscription.event_mask = strtoul(optarg, NULL, 0);;
Expand All @@ -75,6 +77,14 @@ int main(int argc, char *argv[])
case 't':
timeout = strtol(optarg, NULL, 10);
break;
case 'm':
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].upper_limit =
strtol(optarg, NULL, 10);
break;
case 'n':
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].lower_limit =
strtol(optarg, NULL, 10);
break;
case 'h':
printf("Usage of %s :\n"
"Options:\n"
Expand All @@ -95,12 +105,18 @@ int main(int argc, char *argv[])
" Default: %d ns\n"
" -i idle time (s)\n"
" Default: %d s\n"
" -m chrony gm offset upper limit (ns)\n"
" Default: %d ns\n"
" -n chrony gm offset lower limit (ns)\n"
" Default: %d ns\n"
" -t timeout in waiting notification event (s)\n"
" Default: %d s\n",
argv[0], subscription.event_mask,
subscription.composite_event_mask,
subscription.threshold[Clkmgr_thresholdGMOffset].upper_limit,
subscription.threshold[Clkmgr_thresholdGMOffset].lower_limit,
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].upper_limit,
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].lower_limit,
idle_time, timeout);
return EXIT_SUCCESS;
default:
Expand All @@ -123,12 +139,18 @@ int main(int argc, char *argv[])
" Default: %d ns\n"
" -i idle time (s)\n"
" Default: %d s\n"
" -m chrony gm offset upper limit (ns)\n"
" Default: %d ns\n"
" -n chrony gm offset lower limit (ns)\n"
" Default: %d ns\n"
" -t timeout in waiting notification event (s)\n"
" Default: %d s\n",
argv[0], subscription.event_mask,
subscription.composite_event_mask,
subscription.threshold[Clkmgr_thresholdGMOffset].upper_limit,
subscription.threshold[Clkmgr_thresholdGMOffset].lower_limit,
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].upper_limit,
subscription.chrony_threshold[Clkmgr_thresholdGMOffset].lower_limit,
idle_time, timeout);
return EXIT_FAILURE;
}
Expand Down
18 changes: 17 additions & 1 deletion clkmgr/sample/clkmgr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ int main(int argc, char *argv[])
Event_state eventState = {};
int32_t gmOffsetLowerLimit = -100000;
int32_t gmOffsetUpperLimit = 100000;
int32_t chronyGmOffsetLowerLimit = -100000;
int32_t chronyGmOffsetUpperLimit = 100000;
int ret = EXIT_SUCCESS;
uint32_t idleTime = 1;
uint32_t timeout = 10;
Expand All @@ -66,7 +68,7 @@ int main(int argc, char *argv[])
(eventGMOffset | eventSyncedToGM | eventASCapable)
};

while ((option = getopt(argc, argv, "s:c:u:l:i:t:h")) != -1) {
while ((option = getopt(argc, argv, "s:c:u:l:i:t:n:m:h")) != -1) {
switch (option) {
case 's':
event2Sub = std::stoul(optarg, nullptr, 0);
Expand All @@ -86,6 +88,12 @@ int main(int argc, char *argv[])
case 't':
timeout = std::stoi(optarg);
break;
case 'm':
chronyGmOffsetUpperLimit = std::stoi(optarg);
break;
case 'n':
chronyGmOffsetLowerLimit = std::stoi(optarg);
break;
case 'h':
std::cout << "Usage of " << argv[0] << " :\n"
"Options:\n"
Expand Down Expand Up @@ -129,6 +137,10 @@ int main(int argc, char *argv[])
" Default: " << gmOffsetLowerLimit << " ns\n"
" -i idle time (s)\n"
" Default: " << idleTime << " s\n"
" -m chrony offset upper limit (ns)\n"
" Default: " << std::dec << chronyGmOffsetUpperLimit << " ns\n"
" -n chrony offset lower limit (ns)\n"
" Default: " << chronyGmOffsetLowerLimit << " ns\n"
" -t timeout in waiting notification event (s)\n"
" Default: " << timeout << " s\n";
return EXIT_FAILURE;
Expand Down Expand Up @@ -162,13 +174,17 @@ int main(int argc, char *argv[])
subscription.set_event_mask(event2Sub);
subscription.define_threshold(thresholdGMOffset, gmOffsetUpperLimit,
gmOffsetLowerLimit);
subscription.chrony_define_threshold(thresholdChronyOffset, chronyGmOffsetUpperLimit,
chronyGmOffsetLowerLimit);
subscription.set_composite_event_mask(composite_event);
std::cout << "[clkmgr] set subscribe event : 0x"
<< std::hex << subscription.get_event_mask() << "\n";
std::cout << "[clkmgr] set composite event : 0x"
<< std::hex << subscription.get_composite_event_mask() << "\n";
std::cout << "GM Offset upper limit: " << std::dec << gmOffsetUpperLimit << " ns\n";
std::cout << "GM Offset lower limit: " << std::dec << gmOffsetLowerLimit << " ns\n\n";
std::cout << "Chrony Offset upper limit: " << std::dec << chronyGmOffsetUpperLimit << " ns\n";
std::cout << "Chrony Offset lower limit: " << std::dec << chronyGmOffsetLowerLimit << " ns\n\n";

if (!cm.clkmgr_subscribe(subscription, eventState)) {
std::cerr << "[clkmgr] Failure in subscribing to clkmgr Proxy !!!\n";
Expand Down

0 comments on commit 78882c9

Please sign in to comment.