summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-03 17:38:22 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-03 17:38:22 +0100
commit5703176d6e9680c32caac1de2d6bdb84cdc72c96 (patch)
treefbd82ede58241407326bde3fff0648610b4d058b /src
parente37c57106eabfda8c2dfb8a2605514ab5cf8f904 (diff)
parent1a14863e7e88a4694105071987dbafed27a263b2 (diff)
Merge pull request #1764 from ssahani/jiffies-1
(V2) networkd: bridge convert to jiffies
Diffstat (limited to 'src')
-rw-r--r--src/basic/time-util.c14
-rw-r--r--src/basic/time-util.h2
-rw-r--r--src/network/networkd-netdev-bridge.c7
3 files changed, 20 insertions, 3 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 9dc280efc6..e629d91cb2 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1122,3 +1122,17 @@ time_t mktime_or_timegm(struct tm *tm, bool utc) {
struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc) {
return utc ? gmtime_r(t, tm) : localtime_r(t, tm);
}
+
+unsigned long usec_to_jiffies(usec_t u) {
+ static thread_local unsigned long hz = 0;
+ long r;
+
+ if (hz == 0) {
+ r = sysconf(_SC_CLK_TCK);
+
+ assert(r > 0);
+ hz = (unsigned long) r;
+ }
+
+ return DIV_ROUND_UP(u , USEC_PER_SEC / hz);
+}
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 417376ea96..925bf18eb2 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -121,3 +121,5 @@ int get_timezone(char **timezone);
time_t mktime_or_timegm(struct tm *tm, bool utc);
struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc);
+
+unsigned long usec_to_jiffies(usec_t usec);
diff --git a/src/network/networkd-netdev-bridge.c b/src/network/networkd-netdev-bridge.c
index 2eeb86a683..57c58d83b4 100644
--- a/src/network/networkd-netdev-bridge.c
+++ b/src/network/networkd-netdev-bridge.c
@@ -72,20 +72,21 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
+ /* convert to jiffes */
if (b->forward_delay > 0) {
- r = sd_netlink_message_append_u32(req, IFLA_BR_FORWARD_DELAY, b->forward_delay / USEC_PER_SEC);
+ r = sd_netlink_message_append_u32(req, IFLA_BR_FORWARD_DELAY, usec_to_jiffies(b->forward_delay));
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_FORWARD_DELAY attribute: %m");
}
if (b->hello_time > 0) {
- r = sd_netlink_message_append_u32(req, IFLA_BR_HELLO_TIME, b->hello_time / USEC_PER_SEC );
+ r = sd_netlink_message_append_u32(req, IFLA_BR_HELLO_TIME, usec_to_jiffies(b->hello_time));
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_HELLO_TIME attribute: %m");
}
if (b->max_age > 0) {
- r = sd_netlink_message_append_u32(req, IFLA_BR_MAX_AGE, b->max_age / USEC_PER_SEC);
+ r = sd_netlink_message_append_u32(req, IFLA_BR_MAX_AGE, usec_to_jiffies(b->max_age));
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BR_MAX_AGE attribute: %m");
}