Whamcloud - gitweb
LU-17011 utils: monotonic clock in lfs mirror 52/51852/4
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 2 Aug 2023 10:31:57 +0000 (13:31 +0300)
committerOleg Drokin <green@whamcloud.com>
Thu, 31 Aug 2023 06:37:27 +0000 (06:37 +0000)
use monotonic clocks instead of realtime to avoid affecting
bandwidth or hanging the transfer if the clock is changed.

Test-Parameters: trivial
Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: I58cf327d235448e93fa2ed63cefdf4dd01306e71
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51852
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/lfs.c

index 5b41dcd..92de965 100644 (file)
@@ -865,7 +865,7 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int),
                }
        }
 
-       clock_gettime(CLOCK_REALTIME, &start_time);
+       clock_gettime(CLOCK_MONOTONIC, &start_time);
        now = last_bw_print = start_time;
 
        while (1) {
@@ -930,7 +930,7 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int),
                        if (bandwidth_bytes_sec == 0)
                                continue;
 
-                       clock_gettime(CLOCK_REALTIME, &now);
+                       clock_gettime(CLOCK_MONOTONIC, &now);
                        diff = timespec_sub(&start_time, &now);
                        write_target = ((bandwidth_bytes_sec * diff.tv_sec) +
                                ((bandwidth_bytes_sec *
@@ -950,7 +950,7 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int),
                                        NSEC_PER_SEC / bandwidth_bytes_sec;
 
                                do {
-                                       rc = clock_nanosleep(CLOCK_REALTIME, 0,
+                                       rc = clock_nanosleep(CLOCK_MONOTONIC, 0,
                                                             &delay, &delay);
                                } while (rc < 0 && errno == EINTR);
 
@@ -965,7 +965,7 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int),
                        }
                }
 
-               clock_gettime(CLOCK_REALTIME, &now);
+               clock_gettime(CLOCK_MONOTONIC, &now);
                if (stats_interval_sec && (write_bytes != file_size_bytes) &&
                        (now.tv_sec >= last_bw_print.tv_sec +
                        stats_interval_sec)) {
@@ -981,7 +981,7 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int),
 
        /* Output at least one log, regardless of stats_interval */
        if (stats_interval_sec) {
-               clock_gettime(CLOCK_REALTIME, &now);
+               clock_gettime(CLOCK_MONOTONIC, &now);
                stats_log(&now, &start_time, read_bytes, write_bytes,
                          file_size_bytes);
        }