diff options
author | Richard Braun <rbraun@sceen.net> | 2019-05-22 21:59:19 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2019-05-22 21:59:19 +0200 |
commit | 5bc2263b54a89e28dd5092c807a86cd3c078e4d3 (patch) | |
tree | ad399e98a6d46bad25543a4f8680335f3abb1bf8 | |
parent | c45d94a590d778c26dc78386c41231fed9df1b14 (diff) |
Add a log print function type for information reporting
This type allows the use of either printf-based or log-based functions
when reporting information.
-rw-r--r-- | kern/kernel.c | 3 | ||||
-rw-r--r-- | kern/kmem.c | 72 | ||||
-rw-r--r-- | kern/kmem.h | 7 | ||||
-rw-r--r-- | kern/log.h | 11 | ||||
-rw-r--r-- | kern/printf.c | 46 | ||||
-rw-r--r-- | kern/printf.h | 8 | ||||
-rw-r--r-- | kern/syscnt.c | 12 | ||||
-rw-r--r-- | kern/syscnt.h | 5 | ||||
-rw-r--r-- | kern/task.c | 35 | ||||
-rw-r--r-- | kern/task.h | 5 | ||||
-rw-r--r-- | test/test_mutex.c | 6 | ||||
-rw-r--r-- | test/test_mutex_pi.c | 4 | ||||
-rw-r--r-- | test/test_sref_dirty_zeroes.c | 9 | ||||
-rw-r--r-- | test/test_sref_noref.c | 7 | ||||
-rw-r--r-- | test/test_sref_weakref.c | 11 | ||||
-rw-r--r-- | vm/vm_map.c | 25 | ||||
-rw-r--r-- | vm/vm_map.h | 5 | ||||
-rw-r--r-- | vm/vm_page.c | 39 | ||||
-rw-r--r-- | vm/vm_page.h | 3 |
19 files changed, 180 insertions, 133 deletions
diff --git a/kern/kernel.c b/kern/kernel.c index 418793d7..98184e26 100644 --- a/kern/kernel.c +++ b/kern/kernel.c @@ -17,6 +17,7 @@ #include <kern/init.h> #include <kern/kernel.h> +#include <kern/log.h> #include <kern/thread.h> #include <machine/cpu.h> #include <test/test.h> @@ -28,7 +29,7 @@ kernel_main(void) assert(!cpu_intr_enabled()); init_setup(); - vm_page_log_info(); + vm_page_info(log_info); #ifdef CONFIG_TEST_MODULE test_setup(); diff --git a/kern/kmem.c b/kern/kmem.c index bd2e1d56..f5c74a96 100644 --- a/kern/kmem.c +++ b/kern/kmem.c @@ -51,6 +51,7 @@ #include <kern/init.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/log2.h> #include <kern/kmem.h> #include <kern/kmem_i.h> @@ -449,7 +450,7 @@ kmem_cache_error(struct kmem_cache *cache, void *buf, int error, void *arg) { struct kmem_buftag *buftag; - printf("kmem: error: cache: %s, buffer: %p\n", cache->name, buf); + printf_ln("kmem: error: cache: %s, buffer: %p", cache->name, buf); switch(error) { case KMEM_ERR_INVALID: @@ -1107,7 +1108,7 @@ fast_free: } void -kmem_cache_info(struct kmem_cache *cache) +kmem_cache_info(struct kmem_cache *cache, log_print_fn_t print_fn) { char flags_str[64]; @@ -1117,28 +1118,23 @@ kmem_cache_info(struct kmem_cache *cache) mutex_lock(&cache->lock); - printf("kmem: flags: 0x%x%s\n" - "kmem: obj_size: %zu\n" - "kmem: align: %zu\n" - "kmem: buf_size: %zu\n" - "kmem: bufctl_dist: %zu\n" - "kmem: slab_size: %zu\n" - "kmem: color_max: %zu\n" - "kmem: bufs_per_slab: %lu\n" - "kmem: nr_objs: %lu\n" - "kmem: nr_bufs: %lu\n" - "kmem: nr_slabs: %lu\n" - "kmem: nr_free_slabs: %lu\n" - "kmem: buftag_dist: %zu\n" - "kmem: redzone_pad: %zu\n", - cache->flags, flags_str, cache->obj_size, - cache->align, cache->buf_size, cache->bufctl_dist, - cache->slab_size, cache->color_max, cache->bufs_per_slab, - cache->nr_objs, cache->nr_bufs, cache->nr_slabs, - cache->nr_free_slabs, cache->buftag_dist, cache->redzone_pad); + print_fn("kmem: flags: 0x%x%s", cache->flags, flags_str); + print_fn("kmem: obj_size: %zu", cache->obj_size); + print_fn("kmem: align: %zu", cache->align); + print_fn("kmem: buf_size: %zu", cache->buf_size); + print_fn("kmem: bufctl_dist: %zu", cache->bufctl_dist); + print_fn("kmem: slab_size: %zu", cache->slab_size); + print_fn("kmem: color_max: %zu", cache->color_max); + print_fn("kmem: bufs_per_slab: %lu", cache->bufs_per_slab); + print_fn("kmem: nr_objs: %lu", cache->nr_objs); + print_fn("kmem: nr_bufs: %lu", cache->nr_bufs); + print_fn("kmem: nr_slabs: %lu", cache->nr_slabs); + print_fn("kmem: nr_free_slabs: %lu", cache->nr_free_slabs); + print_fn("kmem: buftag_dist: %zu", cache->buftag_dist); + print_fn("kmem: redzone_pad: %zu", cache->redzone_pad); #ifdef KMEM_USE_CPU_LAYER - printf("kmem: cpu_pool_size: %d\n", cache->cpu_pool_type->array_size); + print_fn("kmem: cpu_pool_size: %d", cache->cpu_pool_type->array_size); #endif /* KMEM_USE_CPU_LAYER */ mutex_unlock(&cache->lock); @@ -1175,16 +1171,16 @@ kmem_shell_info(struct shell *shell, int argc, char **argv) (void)shell; if (argc < 2) { - kmem_info(); + kmem_info(printf_ln); } else { cache = kmem_lookup_cache(argv[1]); if (cache == NULL) { - printf("kmem: info: invalid argument\n"); + printf_ln("kmem: info: invalid argument"); return; } - kmem_cache_info(cache); + kmem_cache_info(cache, printf_ln); } } @@ -1383,7 +1379,7 @@ kmem_free(void *ptr, size_t size) } void -kmem_info(void) +kmem_info(log_print_fn_t print_fn) { size_t total_reclaim, total_reclaim_physical, total_reclaim_virtual; size_t total, total_physical, total_virtual; @@ -1397,10 +1393,10 @@ kmem_info(void) total_reclaim_physical = 0; total_reclaim_virtual = 0; - printf("kmem: cache obj slab bufs objs bufs " - " total reclaimable\n" - "kmem: name size size /slab usage count " - " memory memory\n"); + print_fn("kmem: cache obj slab bufs objs bufs " + " total reclaimable"); + print_fn("kmem: name size size /slab usage count " + " memory memory"); mutex_lock(&kmem_cache_list_lock); @@ -1420,18 +1416,18 @@ kmem_info(void) total_reclaim_physical += mem_reclaim; } - printf("kmem: %-19s %6zu %3zuk %4lu %6lu %6lu %7zuk %10zuk\n", - cache->name, cache->obj_size, cache->slab_size >> 10, - cache->bufs_per_slab, cache->nr_objs, cache->nr_bufs, - mem_usage, mem_reclaim); + print_fn("kmem: %-19s %6zu %3zuk %4lu %6lu %6lu %7zuk %10zuk", + cache->name, cache->obj_size, cache->slab_size >> 10, + cache->bufs_per_slab, cache->nr_objs, cache->nr_bufs, + mem_usage, mem_reclaim); mutex_unlock(&cache->lock); } mutex_unlock(&kmem_cache_list_lock); - printf("total: %zuk (phys: %zuk virt: %zuk), " - "reclaim: %zuk (phys: %zuk virt: %zuk)\n", - total, total_physical, total_virtual, - total_reclaim, total_reclaim_physical, total_reclaim_virtual); + print_fn("total: %zuk (phys: %zuk virt: %zuk), " + "reclaim: %zuk (phys: %zuk virt: %zuk)", + total, total_physical, total_virtual, + total_reclaim, total_reclaim_physical, total_reclaim_virtual); } diff --git a/kern/kmem.h b/kern/kmem.h index 3a3afb54..aee1dac2 100644 --- a/kern/kmem.h +++ b/kern/kmem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2014 Richard Braun. + * Copyright (c) 2010-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include <stddef.h> #include <kern/init.h> +#include <kern/log.h> /* * Object cache. @@ -76,7 +77,7 @@ void kmem_cache_free(struct kmem_cache *cache, void *obj); * * If cache is NULL, this function displays all managed caches. */ -void kmem_cache_info(struct kmem_cache *cache); +void kmem_cache_info(struct kmem_cache *cache, log_print_fn_t print_fn); /* * Allocate size bytes of uninitialized memory. @@ -98,7 +99,7 @@ void kmem_free(void *ptr, size_t size); /* * Display global kernel memory information. */ -void kmem_info(void); +void kmem_info(log_print_fn_t print_fn); /* * This init operation provides : @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Richard Braun. + * Copyright (c) 2017-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,6 +38,15 @@ enum { }; /* + * Type for function pointers that may be used as either a log function + * or printf. + * + * One call to a log print function produces a single log line, with a + * newline character. + */ +typedef int (*log_print_fn_t)(const char *format, ...); + +/* * Generate a message and send it to the log thread. * * The arguments and return value are similar to printf(), with diff --git a/kern/printf.c b/kern/printf.c index 29267a6e..8ef3e863 100644 --- a/kern/printf.c +++ b/kern/printf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, 2013 Richard Braun. + * Copyright (c) 2010-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,20 @@ static char printf_buffer[PRINTF_BUFSIZE]; static struct spinlock printf_lock; +static int +vprintf_common(const char *format, va_list ap) +{ + int length; + + length = fmt_vsnprintf(printf_buffer, sizeof(printf_buffer), format, ap); + + for (char *ptr = printf_buffer; *ptr != '\0'; ptr++) { + console_putchar(*ptr); + } + + return length; +} + int printf(const char *format, ...) { @@ -50,16 +64,36 @@ vprintf(const char *format, va_list ap) { unsigned long flags; int length; - char *ptr; spinlock_lock_intr_save(&printf_lock, &flags); + length = vprintf_common(format, ap); + spinlock_unlock_intr_restore(&printf_lock, flags); - length = fmt_vsnprintf(printf_buffer, sizeof(printf_buffer), format, ap); + return length; +} - for (ptr = printf_buffer; *ptr != '\0'; ptr++) { - console_putchar(*ptr); - } +int +printf_ln(const char *format, ...) +{ + va_list ap; + int length; + + va_start(ap, format); + length = vprintf_ln(format, ap); + va_end(ap); + + return length; +} + +int +vprintf_ln(const char *format, va_list ap) +{ + unsigned long flags; + int length; + spinlock_lock_intr_save(&printf_lock, &flags); + length = vprintf_common(format, ap); + console_putchar('\n'); spinlock_unlock_intr_restore(&printf_lock, flags); return length; diff --git a/kern/printf.h b/kern/printf.h index eba5562b..e5e5f1b5 100644 --- a/kern/printf.h +++ b/kern/printf.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Richard Braun. + * Copyright (c) 2010-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,12 @@ int printf(const char *format, ...) int vprintf(const char *format, va_list ap) __attribute__((format(printf, 1, 0))); +int printf_ln(const char *format, ...) + __attribute__((format(printf, 1, 2))); + +int vprintf_ln(const char *format, va_list ap) + __attribute__((format(printf, 1, 0))); + /* * This init operation provides : * - printf is usable diff --git a/kern/syscnt.c b/kern/syscnt.c index 1fd3cf06..93ca75f8 100644 --- a/kern/syscnt.c +++ b/kern/syscnt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2017 Richard Braun. + * Copyright (c) 2014-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,12 +15,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <stddef.h> #include <stdio.h> #include <string.h> #include <kern/atomic.h> #include <kern/init.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/mutex.h> #include <kern/shell.h> #include <kern/spinlock.h> @@ -43,7 +45,7 @@ syscnt_shell_info(struct shell *shell, int argc, char **argv) (void)shell; prefix = (argc >= 2) ? argv[1] : NULL; - syscnt_info(prefix); + syscnt_info(prefix, printf_ln); } static struct shell_cmd syscnt_shell_cmds[] = { @@ -96,7 +98,7 @@ syscnt_register(struct syscnt *syscnt, const char *name) } void -syscnt_info(const char *prefix) +syscnt_info(const char *prefix, log_print_fn_t print_fn) { struct syscnt *syscnt; size_t length, prefix_length; @@ -118,8 +120,8 @@ syscnt_info(const char *prefix) value = syscnt_read(syscnt); - printf("syscnt: %40s %20llu\n", syscnt->name, - (unsigned long long)value); + print_fn("syscnt: %40s %20llu", syscnt->name, + (unsigned long long)value); } mutex_unlock(&syscnt_lock); diff --git a/kern/syscnt.h b/kern/syscnt.h index 167be099..ee9c930d 100644 --- a/kern/syscnt.h +++ b/kern/syscnt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2017 Richard Braun. + * Copyright (c) 2014-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #include <kern/atomic.h> #include <kern/init.h> +#include <kern/log.h> #include <kern/macros.h> #include <kern/spinlock.h> @@ -125,7 +126,7 @@ syscnt_dec(struct syscnt *syscnt) * A prefix can be used to filter the output, where only counters with the * given prefix are displayed. If NULL, all counters are reported. */ -void syscnt_info(const char *prefix); +void syscnt_info(const char *prefix, log_print_fn_t print_fn); /* * This init operation provides : diff --git a/kern/task.c b/kern/task.c index ebdb021e..00cfb3a0 100644 --- a/kern/task.c +++ b/kern/task.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Richard Braun. + * Copyright (c) 2012-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #include <kern/init.h> #include <kern/kmem.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/macros.h> #include <kern/shell.h> #include <kern/spinlock.h> @@ -70,7 +71,7 @@ task_shell_info(struct shell *shell, int argc, char *argv[]) (void)shell; if (argc == 1) { - task_info(NULL); + task_info(NULL, printf_ln); return; } else { task = task_lookup(argv[1]); @@ -80,14 +81,14 @@ task_shell_info(struct shell *shell, int argc, char *argv[]) goto error; } - task_info(task); + task_info(task, printf_ln); task_unref(task); } return; error: - printf("task: info: %s\n", strerror(error)); + printf_ln("task: info: %s", strerror(error)); } static struct shell_cmd task_shell_cmds[] = { @@ -227,7 +228,7 @@ task_lookup_thread(struct task *task, const char *name) } void -task_info(struct task *task) +task_info(struct task *task, log_print_fn_t print_fn) { struct thread *thread; @@ -235,7 +236,7 @@ task_info(struct task *task) spinlock_lock(&task_list_lock); list_for_each_entry(&task_list, task, node) { - task_info(task); + task_info(task, print_fn); } spinlock_unlock(&task_list_lock); @@ -245,7 +246,7 @@ task_info(struct task *task) spinlock_lock(&task->lock); - printf("task: name: %s, threads:\n", task->name); + print_fn("task: name: %s, threads:", task->name); /* * Don't grab any lock when accessing threads, so that the function @@ -256,16 +257,16 @@ task_info(struct task *task) * TODO Handle tasks and threads names modifications. */ list_for_each_entry(&task->threads, thread, task_node) { - printf(TASK_INFO_ADDR_FMT " %c %8s:" TASK_INFO_ADDR_FMT - " %.2s:%02hu %02u %s\n", - (unsigned long)thread, - thread_state_to_chr(thread_state(thread)), - thread_wchan_desc(thread), - (unsigned long)thread_wchan_addr(thread), - thread_sched_class_to_str(thread_user_sched_class(thread)), - thread_user_priority(thread), - thread_real_global_priority(thread), - thread_name(thread)); + print_fn(TASK_INFO_ADDR_FMT " %c %8s:" TASK_INFO_ADDR_FMT + " %.2s:%02hu %02u %s", + (unsigned long)thread, + thread_state_to_chr(thread_state(thread)), + thread_wchan_desc(thread), + (unsigned long)thread_wchan_addr(thread), + thread_sched_class_to_str(thread_user_sched_class(thread)), + thread_user_priority(thread), + thread_real_global_priority(thread), + thread_name(thread)); } spinlock_unlock(&task->lock); diff --git a/kern/task.h b/kern/task.h index 12e29ac8..d4f84c5c 100644 --- a/kern/task.h +++ b/kern/task.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Richard Braun. + * Copyright (c) 2012-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include <kern/atomic.h> #include <kern/init.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/spinlock.h> #include <kern/thread.h> #include <vm/vm_map.h> @@ -116,7 +117,7 @@ struct thread * task_lookup_thread(struct task *task, const char *name); * * If task is NULL, this function displays all tasks. */ -void task_info(struct task *task); +void task_info(struct task *task, log_print_fn_t print_fn); /* * This init operation provides : diff --git a/test/test_mutex.c b/test/test_mutex.c index 49691cf9..365c25d3 100644 --- a/test/test_mutex.c +++ b/test/test_mutex.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Richard Braun. + * Copyright (c) 2017-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -154,9 +154,9 @@ test_report_syscnt(struct timer *timer) uint64_t time; #ifdef CONFIG_MUTEX_PI - syscnt_info("rtmutex"); + syscnt_info("rtmutex", log_info); #else /* CONFIG_MUTEX_PI */ - syscnt_info("mutex"); + syscnt_info("mutex", log_info); #endif /* CONFIG_MUTEX_PI */ time = timer_get_time(timer) + clock_ticks_from_ms(TEST_REPORT_INTERVAL); diff --git a/test/test_mutex_pi.c b/test/test_mutex_pi.c index 5ddcfa70..ebe8ea97 100644 --- a/test/test_mutex_pi.c +++ b/test/test_mutex_pi.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Richard Braun. + * Copyright (c) 2017-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -312,7 +312,7 @@ test_manage_b(void *arg) } printf("b:%u ", i); - syscnt_info("thread_boosts"); + syscnt_info("thread_boosts", log_info); } } diff --git a/test/test_sref_dirty_zeroes.c b/test/test_sref_dirty_zeroes.c index 53183358..3a88fd02 100644 --- a/test/test_sref_dirty_zeroes.c +++ b/test/test_sref_dirty_zeroes.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Richard Braun. + * Copyright (c) 2014-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include <kern/error.h> #include <kern/init.h> #include <kern/kmem.h> +#include <kern/log.h> #include <kern/macros.h> #include <kern/mutex.h> #include <kern/panic.h> @@ -69,9 +70,9 @@ test_inc(void *arg) } printf("counter global value: %lu\n", test_counter.value); - syscnt_info("sref_epoch"); - syscnt_info("sref_dirty_zero"); - syscnt_info("sref_true_zero"); + syscnt_info("sref_epoch", log_info); + syscnt_info("sref_dirty_zero", log_info); + syscnt_info("sref_true_zero", log_info); } } diff --git a/test/test_sref_noref.c b/test/test_sref_noref.c index e82d14c3..3fcbfb13 100644 --- a/test/test_sref_noref.c +++ b/test/test_sref_noref.c @@ -41,6 +41,7 @@ #include <kern/init.h> #include <kern/error.h> #include <kern/kmem.h> +#include <kern/log.h> #include <kern/macros.h> #include <kern/mutex.h> #include <kern/panic.h> @@ -106,9 +107,9 @@ test_obj_noref(struct sref_counter *counter) obj = structof(counter, struct test_obj, ref_counter); vm_kmem_free(obj, sizeof(*obj)); printf("0 references, page released\n"); - syscnt_info("sref_epoch"); - syscnt_info("sref_dirty_zero"); - syscnt_info("sref_true_zero"); + syscnt_info("sref_epoch", log_info); + syscnt_info("sref_dirty_zero", log_info); + syscnt_info("sref_true_zero", log_info); } static void diff --git a/test/test_sref_weakref.c b/test/test_sref_weakref.c index d1d44071..6b9f1a4d 100644 --- a/test/test_sref_weakref.c +++ b/test/test_sref_weakref.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Richard Braun. + * Copyright (c) 2017-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,7 @@ #include <kern/error.h> #include <kern/init.h> +#include <kern/log.h> #include <kern/macros.h> #include <kern/sref.h> #include <kern/syscnt.h> @@ -74,10 +75,10 @@ test_run(void *arg) for (j = 0; j < 0x20000000; j++); printf("run: iterations: %lu\n", i); - syscnt_info("sref_epoch"); - syscnt_info("sref_dirty_zero"); - syscnt_info("sref_revive"); - syscnt_info("sref_true_zero"); + syscnt_info("sref_epoch", log_info); + syscnt_info("sref_dirty_zero", log_info); + syscnt_info("sref_revive", log_info); + syscnt_info("sref_true_zero", log_info); } } diff --git a/vm/vm_map.c b/vm/vm_map.c index 03bc7165..42725d9c 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -29,6 +29,7 @@ #include <kern/init.h> #include <kern/kmem.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/macros.h> #include <kern/mutex.h> #include <kern/panic.h> @@ -713,13 +714,13 @@ vm_map_shell_info(struct shell *shell, int argc, char **argv) goto error; } - vm_map_info(task_get_vm_map(task)); + vm_map_info(task_get_vm_map(task), printf_ln); } return; error: - printf("vm_map: info: invalid arguments\n"); + printf_ln("vm_map: info: invalid arguments"); } static struct shell_cmd vm_map_shell_cmds[] = { @@ -803,7 +804,7 @@ error_map: } void -vm_map_info(struct vm_map *map) +vm_map_info(struct vm_map *map, log_print_fn_t print_fn) { struct vm_map_entry *entry; const char *type, *name; @@ -816,10 +817,10 @@ vm_map_info(struct vm_map *map) mutex_lock(&map->lock); - printf("vm_map: %s: %016lx-%016lx\n" - "vm_map: start end " - "size offset flags type\n", name, - (unsigned long)map->start, (unsigned long)map->end); + print_fn("vm_map: %s: %016lx-%016lx" + "vm_map: start end " + "size offset flags type\n", name, + (unsigned long)map->start, (unsigned long)map->end); list_for_each_entry(&map->entry_list, entry, list_node) { if (entry->object == NULL) { @@ -828,13 +829,13 @@ vm_map_info(struct vm_map *map) type = "object"; } - printf("vm_map: %016lx %016lx %8luk %08llx %08x %s\n", - (unsigned long)entry->start, (unsigned long)entry->end, - (unsigned long)(entry->end - entry->start) >> 10, - (unsigned long long)entry->offset, entry->flags, type); + print_fn("vm_map: %016lx %016lx %8luk %08llx %08x %s", + (unsigned long)entry->start, (unsigned long)entry->end, + (unsigned long)(entry->end - entry->start) >> 10, + (unsigned long long)entry->offset, entry->flags, type); } - printf("vm_map: total: %zuk\n", map->size >> 10); + print_fn("vm_map: total: %zuk", map->size >> 10); mutex_unlock(&map->lock); } diff --git a/vm/vm_map.h b/vm/vm_map.h index dc6514bd..4e925722 100644 --- a/vm/vm_map.h +++ b/vm/vm_map.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2017 Richard Braun. + * Copyright (c) 2011-2019 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ #include <kern/init.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/mutex.h> #include <kern/rbtree.h> #include <machine/pmap.h> @@ -120,7 +121,7 @@ int vm_map_create(struct vm_map **mapp); /* * Display information about a memory map. */ -void vm_map_info(struct vm_map *map); +void vm_map_info(struct vm_map *map, log_print_fn_t print_fn); /* * This init operation provides : diff --git a/vm/vm_page.c b/vm/vm_page.c index beccfabd..b1df194b 100644 --- a/vm/vm_page.c +++ b/vm/vm_page.c @@ -643,37 +643,16 @@ vm_page_bootalloc(size_t size) panic("vm_page: no physical memory available"); } -static void -vm_page_info_common(int (*print_fn)(const char *format, ...)) -{ - struct vm_page_zone *zone; - unsigned long pages; - unsigned int i; - - for (i = 0; i < vm_page_zones_size; i++) { - zone = &vm_page_zones[i]; - pages = (unsigned long)(zone->pages_end - zone->pages); - print_fn("vm_page: %s: pages: %lu (%luM), free: %lu (%luM)\n", - vm_page_zone_name(i), pages, pages >> (20 - PAGE_SHIFT), - zone->nr_free_pages, zone->nr_free_pages >> (20 - PAGE_SHIFT)); - } -} - #ifdef CONFIG_SHELL static void -vm_page_info(void) -{ - vm_page_info_common(printf); -} - -static void vm_page_shell_info(struct shell *shell, int argc, char **argv) { (void)shell; (void)argc; (void)argv; - vm_page_info(); + + vm_page_info(printf_ln); } static struct shell_cmd vm_page_shell_cmds[] = { @@ -854,7 +833,17 @@ vm_page_zone_name(unsigned int zone_index) } void -vm_page_log_info(void) +vm_page_info(log_print_fn_t print_fn) { - vm_page_info_common(log_info); + struct vm_page_zone *zone; + unsigned long pages; + unsigned int i; + + for (i = 0; i < vm_page_zones_size; i++) { + zone = &vm_page_zones[i]; + pages = (unsigned long)(zone->pages_end - zone->pages); + print_fn("vm_page: %s: pages: %lu (%luM), free: %lu (%luM)", + vm_page_zone_name(i), pages, pages >> (20 - PAGE_SHIFT), + zone->nr_free_pages, zone->nr_free_pages >> (20 - PAGE_SHIFT)); + } } diff --git a/vm/vm_page.h b/vm/vm_page.h index 4f2aaf93..7865d16a 100644 --- a/vm/vm_page.h +++ b/vm/vm_page.h @@ -33,6 +33,7 @@ #include <kern/atomic.h> #include <kern/init.h> #include <kern/list.h> +#include <kern/log.h> #include <kern/log2.h> #include <kern/macros.h> #include <machine/page.h> @@ -230,7 +231,7 @@ const char * vm_page_zone_name(unsigned int zone_index); /* * Log information about physical pages. */ -void vm_page_log_info(void); +void vm_page_info(log_print_fn_t print_fn); static inline bool vm_page_referenced(const struct vm_page *page) |