1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * SET CLOCK migration tests 4 * 5 * Copyright IBM Corp. 2022 6 * 7 * Authors: 8 * Nico Boehr <nrb@linux.ibm.com> 9 */ 10 11 #include <libcflat.h> 12 #include <migrate.h> 13 #include <asm/time.h> 14 test_sck_migration(void)15static void test_sck_migration(void) 16 { 17 uint64_t now_before_set = 0, now_after_set = 0, now_after_migration, time_to_set, time_to_advance; 18 int cc; 19 20 stckf(&now_before_set); 21 22 /* Advance the clock by a lot more than we might ever need to migrate (600s) */ 23 time_to_advance = (600ULL * 1000000) << STCK_SHIFT_US; 24 time_to_set = now_before_set + time_to_advance; 25 26 cc = sck(&time_to_set); 27 report(!cc, "setting clock succeeded"); 28 29 /* Check the clock is running after being set */ 30 cc = stckf(&now_after_set); 31 report(!cc, "clock running after set"); 32 report(now_after_set >= time_to_set, "TOD clock value is larger than what has been set"); 33 34 migrate_once(); 35 36 cc = stckf(&now_after_migration); 37 report(!cc, "clock still set"); 38 39 /* 40 * The architectural requirement for the TOD clock is that it doesn't move backwards after 41 * migration. Implementations can just migrate the guest TOD value or do something more 42 * sophisticated (e.g. slowly adjust to the host TOD). 43 */ 44 report(now_after_migration >= time_to_set, "TOD clock value did not jump backwards"); 45 } 46 main(void)47int main(void) 48 { 49 report_prefix_push("migration-sck"); 50 51 test_sck_migration(); 52 report_prefix_pop(); 53 return report_summary(); 54 } 55