access_tracking_perf_test.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * access_tracking_perf_test
  4. *
  5. * Copyright (C) 2021, Google, Inc.
  6. *
  7. * This test measures the performance effects of KVM's access tracking.
  8. * Access tracking is driven by the MMU notifiers test_young, clear_young, and
  9. * clear_flush_young. These notifiers do not have a direct userspace API,
  10. * however the clear_young notifier can be triggered either by
  11. * 1. marking a pages as idle in /sys/kernel/mm/page_idle/bitmap OR
  12. * 2. adding a new MGLRU generation using the lru_gen debugfs file.
  13. * This test leverages page_idle to enable access tracking on guest memory
  14. * unless MGLRU is enabled, in which case MGLRU is used.
  15. *
  16. * To measure performance this test runs a VM with a configurable number of
  17. * vCPUs that each touch every page in disjoint regions of memory. Performance
  18. * is measured in the time it takes all vCPUs to finish touching their
  19. * predefined region.
  20. *
  21. * Note that a deterministic correctness test of access tracking is not possible
  22. * by using page_idle or MGLRU aging as it exists today. This is for a few
  23. * reasons:
  24. *
  25. * 1. page_idle and MGLRU only issue clear_young notifiers, which lack a TLB flush.
  26. * This means subsequent guest accesses are not guaranteed to see page table
  27. * updates made by KVM until some time in the future.
  28. *
  29. * 2. page_idle only operates on LRU pages. Newly allocated pages are not
  30. * immediately allocated to LRU lists. Instead they are held in a "pagevec",
  31. * which is drained to LRU lists some time in the future. There is no
  32. * userspace API to force this drain to occur.
  33. *
  34. * These limitations are worked around in this test by using a large enough
  35. * region of memory for each vCPU such that the number of translations cached in
  36. * the TLB and the number of pages held in pagevecs are a small fraction of the
  37. * overall workload. And if either of those conditions are not true (for example
  38. * in nesting, where TLB size is unlimited) this test will print a warning
  39. * rather than silently passing.
  40. */
  41. #include <inttypes.h>
  42. #include <limits.h>
  43. #include <pthread.h>
  44. #include <sys/mman.h>
  45. #include <sys/types.h>
  46. #include <sys/stat.h>
  47. #include "kvm_util.h"
  48. #include "test_util.h"
  49. #include "memstress.h"
  50. #include "guest_modes.h"
  51. #include "processor.h"
  52. #include "ucall_common.h"
  53. #include "cgroup_util.h"
  54. #include "lru_gen_util.h"
  55. static const char *TEST_MEMCG_NAME = "access_tracking_perf_test";
  56. /* Global variable used to synchronize all of the vCPU threads. */
  57. static int iteration;
  58. /* The cgroup memory controller root. Needed for lru_gen-based aging. */
  59. char cgroup_root[PATH_MAX];
  60. /* Defines what vCPU threads should do during a given iteration. */
  61. static enum {
  62. /* Run the vCPU to access all its memory. */
  63. ITERATION_ACCESS_MEMORY,
  64. /* Mark the vCPU's memory idle in page_idle. */
  65. ITERATION_MARK_IDLE,
  66. } iteration_work;
  67. /* The iteration that was last completed by each vCPU. */
  68. static int vcpu_last_completed_iteration[KVM_MAX_VCPUS];
  69. /* Whether to overlap the regions of memory vCPUs access. */
  70. static bool overlap_memory_access;
  71. /*
  72. * If the test should only warn if there are too many idle pages (i.e., it is
  73. * expected).
  74. * -1: Not yet set.
  75. * 0: We do not expect too many idle pages, so FAIL if too many idle pages.
  76. * 1: Having too many idle pages is expected, so merely print a warning if
  77. * too many idle pages are found.
  78. */
  79. static int idle_pages_warn_only = -1;
  80. /* Whether or not to use MGLRU instead of page_idle for access tracking */
  81. static bool use_lru_gen;
  82. /* Total number of pages to expect in the memcg after touching everything */
  83. static long test_pages;
  84. /* Last generation we found the pages in */
  85. static int lru_gen_last_gen = -1;
  86. struct test_params {
  87. /* The backing source for the region of memory. */
  88. enum vm_mem_backing_src_type backing_src;
  89. /* The amount of memory to allocate for each vCPU. */
  90. uint64_t vcpu_memory_bytes;
  91. /* The number of vCPUs to create in the VM. */
  92. int nr_vcpus;
  93. };
  94. static uint64_t pread_uint64(int fd, const char *filename, uint64_t index)
  95. {
  96. uint64_t value;
  97. off_t offset = index * sizeof(value);
  98. TEST_ASSERT(pread(fd, &value, sizeof(value), offset) == sizeof(value),
  99. "pread from %s offset 0x%" PRIx64 " failed!",
  100. filename, offset);
  101. return value;
  102. }
  103. #define PAGEMAP_PRESENT (1ULL << 63)
  104. #define PAGEMAP_PFN_MASK ((1ULL << 55) - 1)
  105. static uint64_t lookup_pfn(int pagemap_fd, struct kvm_vm *vm, uint64_t gva)
  106. {
  107. uint64_t hva = (uint64_t) addr_gva2hva(vm, gva);
  108. uint64_t entry;
  109. uint64_t pfn;
  110. entry = pread_uint64(pagemap_fd, "pagemap", hva / getpagesize());
  111. if (!(entry & PAGEMAP_PRESENT))
  112. return 0;
  113. pfn = entry & PAGEMAP_PFN_MASK;
  114. __TEST_REQUIRE(pfn, "Looking up PFNs requires CAP_SYS_ADMIN");
  115. return pfn;
  116. }
  117. static bool is_page_idle(int page_idle_fd, uint64_t pfn)
  118. {
  119. uint64_t bits = pread_uint64(page_idle_fd, "page_idle", pfn / 64);
  120. return !!((bits >> (pfn % 64)) & 1);
  121. }
  122. static void mark_page_idle(int page_idle_fd, uint64_t pfn)
  123. {
  124. uint64_t bits = 1ULL << (pfn % 64);
  125. TEST_ASSERT(pwrite(page_idle_fd, &bits, 8, 8 * (pfn / 64)) == 8,
  126. "Set page_idle bits for PFN 0x%" PRIx64, pfn);
  127. }
  128. static void too_many_idle_pages(long idle_pages, long total_pages, int vcpu_idx)
  129. {
  130. char prefix[18] = {};
  131. if (vcpu_idx >= 0)
  132. snprintf(prefix, 18, "vCPU%d: ", vcpu_idx);
  133. TEST_ASSERT(idle_pages_warn_only,
  134. "%sToo many pages still idle (%lu out of %lu)",
  135. prefix, idle_pages, total_pages);
  136. printf("WARNING: %sToo many pages still idle (%lu out of %lu), "
  137. "this will affect performance results.\n",
  138. prefix, idle_pages, total_pages);
  139. }
  140. static void pageidle_mark_vcpu_memory_idle(struct kvm_vm *vm,
  141. struct memstress_vcpu_args *vcpu_args)
  142. {
  143. int vcpu_idx = vcpu_args->vcpu_idx;
  144. uint64_t base_gva = vcpu_args->gva;
  145. uint64_t pages = vcpu_args->pages;
  146. uint64_t page;
  147. uint64_t still_idle = 0;
  148. uint64_t no_pfn = 0;
  149. int page_idle_fd;
  150. int pagemap_fd;
  151. /* If vCPUs are using an overlapping region, let vCPU 0 mark it idle. */
  152. if (overlap_memory_access && vcpu_idx)
  153. return;
  154. page_idle_fd = open("/sys/kernel/mm/page_idle/bitmap", O_RDWR);
  155. TEST_ASSERT(page_idle_fd > 0, "Failed to open page_idle.");
  156. pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
  157. TEST_ASSERT(pagemap_fd > 0, "Failed to open pagemap.");
  158. for (page = 0; page < pages; page++) {
  159. uint64_t gva = base_gva + page * memstress_args.guest_page_size;
  160. uint64_t pfn = lookup_pfn(pagemap_fd, vm, gva);
  161. if (!pfn) {
  162. no_pfn++;
  163. continue;
  164. }
  165. if (is_page_idle(page_idle_fd, pfn)) {
  166. still_idle++;
  167. continue;
  168. }
  169. mark_page_idle(page_idle_fd, pfn);
  170. }
  171. /*
  172. * Assumption: Less than 1% of pages are going to be swapped out from
  173. * under us during this test.
  174. */
  175. TEST_ASSERT(no_pfn < pages / 100,
  176. "vCPU %d: No PFN for %" PRIu64 " out of %" PRIu64 " pages.",
  177. vcpu_idx, no_pfn, pages);
  178. /*
  179. * Check that at least 90% of memory has been marked idle (the rest
  180. * might not be marked idle because the pages have not yet made it to an
  181. * LRU list or the translations are still cached in the TLB). 90% is
  182. * arbitrary; high enough that we ensure most memory access went through
  183. * access tracking but low enough as to not make the test too brittle
  184. * over time and across architectures.
  185. */
  186. if (still_idle >= pages / 10)
  187. too_many_idle_pages(still_idle, pages,
  188. overlap_memory_access ? -1 : vcpu_idx);
  189. close(page_idle_fd);
  190. close(pagemap_fd);
  191. }
  192. int find_generation(struct memcg_stats *stats, long total_pages)
  193. {
  194. /*
  195. * For finding the generation that contains our pages, use the same
  196. * 90% threshold that page_idle uses.
  197. */
  198. int gen = lru_gen_find_generation(stats, total_pages * 9 / 10);
  199. if (gen >= 0)
  200. return gen;
  201. if (!idle_pages_warn_only) {
  202. TEST_FAIL("Could not find a generation with 90%% of guest memory (%ld pages).",
  203. total_pages * 9 / 10);
  204. return gen;
  205. }
  206. /*
  207. * We couldn't find a generation with 90% of guest memory, which can
  208. * happen if access tracking is unreliable. Simply look for a majority
  209. * of pages.
  210. */
  211. puts("WARNING: Couldn't find a generation with 90% of guest memory. "
  212. "Performance results may not be accurate.");
  213. gen = lru_gen_find_generation(stats, total_pages / 2);
  214. TEST_ASSERT(gen >= 0,
  215. "Could not find a generation with 50%% of guest memory (%ld pages).",
  216. total_pages / 2);
  217. return gen;
  218. }
  219. static void lru_gen_mark_memory_idle(struct kvm_vm *vm)
  220. {
  221. struct timespec ts_start;
  222. struct timespec ts_elapsed;
  223. struct memcg_stats stats;
  224. int new_gen;
  225. /* Make a new generation */
  226. clock_gettime(CLOCK_MONOTONIC, &ts_start);
  227. lru_gen_do_aging(&stats, TEST_MEMCG_NAME);
  228. ts_elapsed = timespec_elapsed(ts_start);
  229. /* Check the generation again */
  230. new_gen = find_generation(&stats, test_pages);
  231. /*
  232. * This function should only be invoked with newly-accessed pages,
  233. * so pages should always move to a newer generation.
  234. */
  235. if (new_gen <= lru_gen_last_gen) {
  236. /* We did not move to a newer generation. */
  237. long idle_pages = lru_gen_sum_memcg_stats_for_gen(lru_gen_last_gen,
  238. &stats);
  239. too_many_idle_pages(min_t(long, idle_pages, test_pages),
  240. test_pages, -1);
  241. }
  242. pr_info("%-30s: %ld.%09lds\n",
  243. "Mark memory idle (lru_gen)", ts_elapsed.tv_sec,
  244. ts_elapsed.tv_nsec);
  245. lru_gen_last_gen = new_gen;
  246. }
  247. static void assert_ucall(struct kvm_vcpu *vcpu, uint64_t expected_ucall)
  248. {
  249. struct ucall uc;
  250. uint64_t actual_ucall = get_ucall(vcpu, &uc);
  251. TEST_ASSERT(expected_ucall == actual_ucall,
  252. "Guest exited unexpectedly (expected ucall %" PRIu64
  253. ", got %" PRIu64 ")",
  254. expected_ucall, actual_ucall);
  255. }
  256. static bool spin_wait_for_next_iteration(int *current_iteration)
  257. {
  258. int last_iteration = *current_iteration;
  259. do {
  260. if (READ_ONCE(memstress_args.stop_vcpus))
  261. return false;
  262. *current_iteration = READ_ONCE(iteration);
  263. } while (last_iteration == *current_iteration);
  264. return true;
  265. }
  266. static void vcpu_thread_main(struct memstress_vcpu_args *vcpu_args)
  267. {
  268. struct kvm_vcpu *vcpu = vcpu_args->vcpu;
  269. struct kvm_vm *vm = memstress_args.vm;
  270. int vcpu_idx = vcpu_args->vcpu_idx;
  271. int current_iteration = 0;
  272. while (spin_wait_for_next_iteration(&current_iteration)) {
  273. switch (READ_ONCE(iteration_work)) {
  274. case ITERATION_ACCESS_MEMORY:
  275. vcpu_run(vcpu);
  276. assert_ucall(vcpu, UCALL_SYNC);
  277. break;
  278. case ITERATION_MARK_IDLE:
  279. pageidle_mark_vcpu_memory_idle(vm, vcpu_args);
  280. break;
  281. }
  282. vcpu_last_completed_iteration[vcpu_idx] = current_iteration;
  283. }
  284. }
  285. static void spin_wait_for_vcpu(int vcpu_idx, int target_iteration)
  286. {
  287. while (READ_ONCE(vcpu_last_completed_iteration[vcpu_idx]) !=
  288. target_iteration) {
  289. continue;
  290. }
  291. }
  292. /* The type of memory accesses to perform in the VM. */
  293. enum access_type {
  294. ACCESS_READ,
  295. ACCESS_WRITE,
  296. };
  297. static void run_iteration(struct kvm_vm *vm, int nr_vcpus, const char *description)
  298. {
  299. struct timespec ts_start;
  300. struct timespec ts_elapsed;
  301. int next_iteration, i;
  302. /* Kick off the vCPUs by incrementing iteration. */
  303. next_iteration = ++iteration;
  304. clock_gettime(CLOCK_MONOTONIC, &ts_start);
  305. /* Wait for all vCPUs to finish the iteration. */
  306. for (i = 0; i < nr_vcpus; i++)
  307. spin_wait_for_vcpu(i, next_iteration);
  308. ts_elapsed = timespec_elapsed(ts_start);
  309. pr_info("%-30s: %ld.%09lds\n",
  310. description, ts_elapsed.tv_sec, ts_elapsed.tv_nsec);
  311. }
  312. static void access_memory(struct kvm_vm *vm, int nr_vcpus,
  313. enum access_type access, const char *description)
  314. {
  315. memstress_set_write_percent(vm, (access == ACCESS_READ) ? 0 : 100);
  316. iteration_work = ITERATION_ACCESS_MEMORY;
  317. run_iteration(vm, nr_vcpus, description);
  318. }
  319. static void mark_memory_idle(struct kvm_vm *vm, int nr_vcpus)
  320. {
  321. if (use_lru_gen)
  322. return lru_gen_mark_memory_idle(vm);
  323. /*
  324. * Even though this parallelizes the work across vCPUs, this is still a
  325. * very slow operation because page_idle forces the test to mark one pfn
  326. * at a time and the clear_young notifier may serialize on the KVM MMU
  327. * lock.
  328. */
  329. pr_debug("Marking VM memory idle (slow)...\n");
  330. iteration_work = ITERATION_MARK_IDLE;
  331. run_iteration(vm, nr_vcpus, "Mark memory idle (page_idle)");
  332. }
  333. static void run_test(enum vm_guest_mode mode, void *arg)
  334. {
  335. struct test_params *params = arg;
  336. struct kvm_vm *vm;
  337. int nr_vcpus = params->nr_vcpus;
  338. vm = memstress_create_vm(mode, nr_vcpus, params->vcpu_memory_bytes, 1,
  339. params->backing_src, !overlap_memory_access);
  340. /*
  341. * If guest_page_size is larger than the host's page size, the
  342. * guest (memstress) will only fault in a subset of the host's pages.
  343. */
  344. test_pages = params->nr_vcpus * params->vcpu_memory_bytes /
  345. max(memstress_args.guest_page_size,
  346. (uint64_t)getpagesize());
  347. memstress_start_vcpu_threads(nr_vcpus, vcpu_thread_main);
  348. pr_info("\n");
  349. access_memory(vm, nr_vcpus, ACCESS_WRITE, "Populating memory");
  350. if (use_lru_gen) {
  351. struct memcg_stats stats;
  352. /*
  353. * Do a page table scan now. Following initial population, aging
  354. * may not cause the pages to move to a newer generation. Do
  355. * an aging pass now so that future aging passes always move
  356. * pages to a newer generation.
  357. */
  358. printf("Initial aging pass (lru_gen)\n");
  359. lru_gen_do_aging(&stats, TEST_MEMCG_NAME);
  360. TEST_ASSERT(lru_gen_sum_memcg_stats(&stats) >= test_pages,
  361. "Not all pages accounted for (looking for %ld). "
  362. "Was the memcg set up correctly?", test_pages);
  363. access_memory(vm, nr_vcpus, ACCESS_WRITE, "Re-populating memory");
  364. lru_gen_read_memcg_stats(&stats, TEST_MEMCG_NAME);
  365. lru_gen_last_gen = find_generation(&stats, test_pages);
  366. }
  367. /* As a control, read and write to the populated memory first. */
  368. access_memory(vm, nr_vcpus, ACCESS_WRITE, "Writing to populated memory");
  369. access_memory(vm, nr_vcpus, ACCESS_READ, "Reading from populated memory");
  370. /* Repeat on memory that has been marked as idle. */
  371. mark_memory_idle(vm, nr_vcpus);
  372. access_memory(vm, nr_vcpus, ACCESS_WRITE, "Writing to idle memory");
  373. mark_memory_idle(vm, nr_vcpus);
  374. access_memory(vm, nr_vcpus, ACCESS_READ, "Reading from idle memory");
  375. memstress_join_vcpu_threads(nr_vcpus);
  376. memstress_destroy_vm(vm);
  377. }
  378. static int access_tracking_unreliable(void)
  379. {
  380. #ifdef __x86_64__
  381. /*
  382. * When running nested, the TLB size may be effectively unlimited (for
  383. * example, this is the case when running on KVM L0), and KVM doesn't
  384. * explicitly flush the TLB when aging SPTEs. As a result, more pages
  385. * are cached and the guest won't see the "idle" bit cleared.
  386. */
  387. if (this_cpu_has(X86_FEATURE_HYPERVISOR)) {
  388. puts("Skipping idle page count sanity check, because the test is run nested");
  389. return 1;
  390. }
  391. #endif
  392. /*
  393. * When NUMA balancing is enabled, guest memory will be unmapped to get
  394. * NUMA faults, dropping the Accessed bits.
  395. */
  396. if (is_numa_balancing_enabled()) {
  397. puts("Skipping idle page count sanity check, because NUMA balancing is enabled");
  398. return 1;
  399. }
  400. return 0;
  401. }
  402. static int run_test_for_each_guest_mode(const char *cgroup, void *arg)
  403. {
  404. for_each_guest_mode(run_test, arg);
  405. return 0;
  406. }
  407. static void help(char *name)
  408. {
  409. puts("");
  410. printf("usage: %s [-h] [-m mode] [-b vcpu_bytes] [-v vcpus] [-o] [-s mem_type]\n",
  411. name);
  412. puts("");
  413. printf(" -h: Display this help message.");
  414. guest_modes_help();
  415. printf(" -b: specify the size of the memory region which should be\n"
  416. " dirtied by each vCPU. e.g. 10M or 3G.\n"
  417. " (default: 1G)\n");
  418. printf(" -v: specify the number of vCPUs to run.\n");
  419. printf(" -o: Overlap guest memory accesses instead of partitioning\n"
  420. " them into a separate region of memory for each vCPU.\n");
  421. printf(" -w: Control whether the test warns or fails if more than 10%%\n"
  422. " of pages are still seen as idle/old after accessing guest\n"
  423. " memory. >0 == warn only, 0 == fail, <0 == auto. For auto\n"
  424. " mode, the test fails by default, but switches to warn only\n"
  425. " if NUMA balancing is enabled or the test detects it's running\n"
  426. " in a VM.\n");
  427. backing_src_help("-s");
  428. puts("");
  429. exit(0);
  430. }
  431. void destroy_cgroup(char *cg)
  432. {
  433. printf("Destroying cgroup: %s\n", cg);
  434. }
  435. int main(int argc, char *argv[])
  436. {
  437. struct test_params params = {
  438. .backing_src = DEFAULT_VM_MEM_SRC,
  439. .vcpu_memory_bytes = DEFAULT_PER_VCPU_MEM_SIZE,
  440. .nr_vcpus = 1,
  441. };
  442. char *new_cg = NULL;
  443. int page_idle_fd;
  444. int opt;
  445. guest_modes_append_default();
  446. while ((opt = getopt(argc, argv, "hm:b:v:os:w:")) != -1) {
  447. switch (opt) {
  448. case 'm':
  449. guest_modes_cmdline(optarg);
  450. break;
  451. case 'b':
  452. params.vcpu_memory_bytes = parse_size(optarg);
  453. break;
  454. case 'v':
  455. params.nr_vcpus = atoi_positive("Number of vCPUs", optarg);
  456. break;
  457. case 'o':
  458. overlap_memory_access = true;
  459. break;
  460. case 's':
  461. params.backing_src = parse_backing_src_type(optarg);
  462. break;
  463. case 'w':
  464. idle_pages_warn_only =
  465. atoi_non_negative("Idle pages warning",
  466. optarg);
  467. break;
  468. case 'h':
  469. default:
  470. help(argv[0]);
  471. break;
  472. }
  473. }
  474. if (idle_pages_warn_only == -1)
  475. idle_pages_warn_only = access_tracking_unreliable();
  476. if (lru_gen_usable()) {
  477. bool cg_created = true;
  478. int ret;
  479. puts("Using lru_gen for aging");
  480. use_lru_gen = true;
  481. if (cg_find_controller_root(cgroup_root, sizeof(cgroup_root), "memory"))
  482. ksft_exit_skip("Cannot find memory cgroup controller\n");
  483. new_cg = cg_name(cgroup_root, TEST_MEMCG_NAME);
  484. printf("Creating cgroup: %s\n", new_cg);
  485. if (cg_create(new_cg)) {
  486. if (errno == EEXIST) {
  487. printf("Found existing cgroup");
  488. cg_created = false;
  489. } else {
  490. ksft_exit_skip("could not create new cgroup: %s\n", new_cg);
  491. }
  492. }
  493. /*
  494. * This will fork off a new process to run the test within
  495. * a new memcg, so we need to properly propagate the return
  496. * value up.
  497. */
  498. ret = cg_run(new_cg, &run_test_for_each_guest_mode, &params);
  499. if (cg_created)
  500. cg_destroy(new_cg);
  501. if (ret < 0)
  502. TEST_FAIL("child did not spawn or was abnormally killed");
  503. if (ret)
  504. return ret;
  505. } else {
  506. page_idle_fd = __open_path_or_exit("/sys/kernel/mm/page_idle/bitmap", O_RDWR,
  507. "Is CONFIG_IDLE_PAGE_TRACKING enabled?");
  508. close(page_idle_fd);
  509. puts("Using page_idle for aging");
  510. run_test_for_each_guest_mode(NULL, &params);
  511. }
  512. return 0;
  513. }